Skip to content

Commit

Permalink
fix(ui): Make all usage of CustomEditor dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
daryllimyt committed Dec 3, 2024
1 parent f2d99e9 commit 2dc85dc
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 59 deletions.
24 changes: 7 additions & 17 deletions frontend/src/app/registry/actions/edit/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"use client"

import React from "react"
import dynamic from "next/dynamic"
import { useRouter, useSearchParams } from "next/navigation"
import {
RegistryActionUpdate,
TemplateAction_Output,
TemplateActionDefinition,
} from "@/client"
import { zodResolver } from "@hookform/resolvers/zod"
import { type EditorProps } from "@monaco-editor/react"
import { AlertTriangleIcon, ArrowLeftIcon, Loader2 } from "lucide-react"
import { Controller, useForm } from "react-hook-form"
import YAML from "yaml"
Expand All @@ -30,15 +28,9 @@ import { Button } from "@/components/ui/button"
import { Form, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { DynamicCustomEditor } from "@/components/editor/dynamic"
import { CenteredSpinner } from "@/components/loading/spinner"

let CustomEditor: React.ComponentType<EditorProps> | undefined
if (typeof window !== "undefined") {
CustomEditor = dynamic(() => import("@/components/editor/editor"), {
ssr: false,
})
}

export default function EditActionPage() {
const searchParams = useSearchParams()
const origin = searchParams.get("origin")
Expand Down Expand Up @@ -224,14 +216,12 @@ function EditTemplateActionForm({
Edit the action template in YAML. Changes will be reflected
in workflows immediately.
</span>
{CustomEditor && (
<CustomEditor
className="h-96 w-full"
defaultLanguage="yaml"
value={field.value}
onChange={field.onChange}
/>
)}
<DynamicCustomEditor
className="h-96 w-full"
defaultLanguage="yaml"
value={field.value}
onChange={field.onChange}
/>
{error && (
<FormMessage className="flex items-center space-x-1">
<AlertTriangleIcon className="size-4 fill-red-500 stroke-white" />
Expand Down
36 changes: 13 additions & 23 deletions frontend/src/app/registry/actions/new/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"use client"

import React from "react"
import dynamic from "next/dynamic"
import { useRouter, useSearchParams } from "next/navigation"
import { TemplateAction_Output, TemplateActionDefinition } from "@/client"
import { zodResolver } from "@hookform/resolvers/zod"
import { type EditorProps } from "@monaco-editor/react"
import { AlertTriangleIcon, ArrowLeftIcon, Loader2 } from "lucide-react"
import { Controller, useForm } from "react-hook-form"
import YAML from "yaml"
Expand All @@ -30,15 +28,9 @@ import { Button } from "@/components/ui/button"
import { Form, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { DynamicCustomEditor } from "@/components/editor/dynamic"
import { CenteredSpinner } from "@/components/loading/spinner"

let CustomEditor: React.ComponentType<EditorProps> | undefined
if (typeof window !== "undefined") {
CustomEditor = dynamic(() => import("@/components/editor/editor"), {
ssr: false,
})
}

export default function NewActionPage() {
const searchParams = useSearchParams()
const origin = searchParams.get("origin")
Expand Down Expand Up @@ -214,20 +206,18 @@ function NewTemplateActionForm({
<span className="text-xs text-muted-foreground">
Edit the action template in YAML.
</span>
{CustomEditor && (
<Controller
name="definition"
control={methods.control}
render={({ field }) => (
<CustomEditor
className="h-96 w-full"
defaultLanguage="yaml"
value={field.value}
onChange={field.onChange}
/>
)}
/>
)}
<Controller
name="definition"
control={methods.control}
render={({ field }) => (
<DynamicCustomEditor
className="h-96 w-full"
defaultLanguage="yaml"
value={field.value}
onChange={field.onChange}
/>
)}
/>
{error && (
<FormMessage className="flex items-center space-x-1">
<AlertTriangleIcon className="size-4 fill-red-500 stroke-white" />
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/components/editor/dynamic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use client"

import dynamic from "next/dynamic"

import { type CustomEditorProps } from "@/components/editor/editor"
import { CenteredSpinner } from "@/components/loading/spinner"

let DynamicCustomEditor: React.ComponentType<CustomEditorProps>
if (typeof window !== "undefined") {
DynamicCustomEditor = dynamic(() => import("@/components/editor/editor"), {
ssr: false,
loading: () => <CenteredSpinner />,
})
} else {
const EmptyEditor = (props: CustomEditorProps) => <></>
EmptyEditor.displayName = "EmptyEditor"
DynamicCustomEditor = EmptyEditor
}

export { DynamicCustomEditor }
14 changes: 8 additions & 6 deletions frontend/src/components/editor/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,20 @@ interface ISuggestController {
}
}

export interface CustomEditorProps extends EditorProps {
className?: string
onKeyDown?: () => void
workspaceId?: string
workflowId?: string | null
}

export function CustomEditor({
className,
onKeyDown,
workspaceId,
workflowId,
...props
}: EditorProps & {
className?: string
onKeyDown?: () => void
workspaceId?: string
workflowId?: string | null
}) {
}: CustomEditorProps) {
const completionDisposableRef = useRef<IDisposable | null>(null)
const hoverDisposableRef = useRef<IDisposable | null>(null)
const tokenizerDisposableRef = useRef<IDisposable | null>(null)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/nav/workbench-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import {
TooltipTrigger,
} from "@/components/ui/tooltip"
import { toast } from "@/components/ui/use-toast"
import { CustomEditor } from "@/components/editor"
import { DynamicCustomEditor } from "@/components/editor/dynamic"

export function WorkbenchNav() {
const {
Expand Down Expand Up @@ -469,7 +469,7 @@ function WorkflowManualTrigger({
render={({ field }) => (
<FormItem>
<FormControl>
<CustomEditor
<DynamicCustomEditor
className="size-full h-36"
defaultLanguage="yaml"
value={field.value}
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/workbench/panel/action-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import {
TooltipTrigger,
} from "@/components/ui/tooltip"
import { CopyButton } from "@/components/copy-button"
import { CustomEditor } from "@/components/editor"
import { DynamicCustomEditor } from "@/components/editor/dynamic"
import { getIcon } from "@/components/icons"
import { JSONSchemaTable } from "@/components/jsonschema-table"
import { CenteredSpinner } from "@/components/loading/spinner"
Expand Down Expand Up @@ -536,7 +536,7 @@ export function ActionPanel({
name="inputs"
control={methods.control}
render={({ field }) => (
<CustomEditor
<DynamicCustomEditor
className="h-72 w-full"
value={field.value}
onChange={field.onChange}
Expand Down Expand Up @@ -609,7 +609,7 @@ export function ActionPanel({
name="control_flow.run_if"
control={methods.control}
render={({ field }) => (
<CustomEditor
<DynamicCustomEditor
className="h-24 w-full"
defaultLanguage="yaml"
value={field.value}
Expand Down Expand Up @@ -652,7 +652,7 @@ export function ActionPanel({
name="control_flow.for_each"
control={methods.control}
render={({ field }) => (
<CustomEditor
<DynamicCustomEditor
className="h-24 w-full"
defaultLanguage="yaml"
value={field.value}
Expand Down Expand Up @@ -693,7 +693,7 @@ export function ActionPanel({
name="control_flow.options"
control={methods.control}
render={({ field }) => (
<CustomEditor
<DynamicCustomEditor
className="h-24 w-full"
defaultLanguage="yaml"
value={field.value}
Expand Down Expand Up @@ -752,7 +752,7 @@ export function ActionPanel({
name="control_flow.retry_policy"
control={methods.control}
render={({ field }) => (
<CustomEditor
<DynamicCustomEditor
className="h-24 w-full"
defaultLanguage="yaml"
value={field.value}
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/workbench/panel/workflow-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { Textarea } from "@/components/ui/textarea"
import { toast } from "@/components/ui/use-toast"
import { CopyButton } from "@/components/copy-button"
import { CustomEditor } from "@/components/editor"
import { DynamicCustomEditor } from "@/components/editor/dynamic"

const workflowConfigFormSchema = z.object({
title: z.string(),
Expand Down Expand Up @@ -348,7 +348,7 @@ export function WorkflowPanel({
name="config"
control={methods.control}
render={({ field }) => (
<CustomEditor
<DynamicCustomEditor
className="h-48 w-full"
defaultLanguage="yaml"
value={field.value}
Expand Down Expand Up @@ -405,7 +405,7 @@ export function WorkflowPanel({
name="expects"
control={methods.control}
render={({ field }) => (
<CustomEditor
<DynamicCustomEditor
className="h-48 w-full"
defaultLanguage="yaml"
value={field.value}
Expand Down Expand Up @@ -455,7 +455,7 @@ export function WorkflowPanel({
name="returns"
control={methods.control}
render={({ field }) => (
<CustomEditor
<DynamicCustomEditor
className="h-48 w-full"
defaultLanguage="yaml"
value={field.value}
Expand Down Expand Up @@ -508,7 +508,7 @@ export function WorkflowPanel({
name="static_inputs"
control={methods.control}
render={({ field }) => (
<CustomEditor
<DynamicCustomEditor
className="h-48 w-full"
defaultLanguage="yaml"
value={field.value}
Expand Down

0 comments on commit 2dc85dc

Please sign in to comment.