diff --git a/web/app/components/workflow/nodes/_base/components/editor/code-editor/index.tsx b/web/app/components/workflow/nodes/_base/components/editor/code-editor/index.tsx index 0342902b1b..1073ce536a 100644 --- a/web/app/components/workflow/nodes/_base/components/editor/code-editor/index.tsx +++ b/web/app/components/workflow/nodes/_base/components/editor/code-editor/index.tsx @@ -7,12 +7,13 @@ import { CodeLanguage } from '@/app/components/workflow/nodes/code/types' import './style.css' type Props = { - value: string - onChange: (value: string) => void + value?: string | object + onChange?: (value: string) => void title: JSX.Element language: CodeLanguage headerRight?: JSX.Element readOnly?: boolean + isJSONStringifyBeauty?: boolean } const languageMap = { @@ -22,12 +23,13 @@ const languageMap = { } const CodeEditor: FC = ({ - value, - onChange, + value = '', + onChange = () => { }, title, headerRight, language, readOnly, + isJSONStringifyBeauty, }) => { const [isFocus, setIsFocus] = React.useState(false) @@ -64,11 +66,22 @@ const CodeEditor: FC = ({ }) } + const outPutValue = (() => { + if (!isJSONStringifyBeauty) + return value as string + try { + return JSON.stringify(value as object, null, 2) + } + catch (e) { + return value as string + } + })() + return (
= ({ // language={language === CodeLanguage.javascript ? 'javascript' : 'python'} language={languageMap[language] || 'javascript'} theme={isFocus ? 'focus-theme' : 'blur-theme'} - value={value} + value={outPutValue} onChange={handleEditorChange} // https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IEditorOptions.html options={{ diff --git a/web/app/components/workflow/run/result-panel.tsx b/web/app/components/workflow/run/result-panel.tsx index 94e00878c6..09e90de51e 100644 --- a/web/app/components/workflow/run/result-panel.tsx +++ b/web/app/components/workflow/run/result-panel.tsx @@ -48,16 +48,16 @@ const ResultPanel: FC = ({ readOnly title={
INPUT
} language={CodeLanguage.json} - value={JSON.stringify(inputs)} - onChange={() => {}} + value={inputs} + isJSONStringifyBeauty /> {process_data && ( PROCESS DATA
} language={CodeLanguage.json} - value={JSON.stringify(process_data)} - onChange={() => {}} + value={process_data} + isJSONStringifyBeauty /> )} {(outputs || status === 'running') && ( @@ -65,13 +65,13 @@ const ResultPanel: FC = ({ readOnly title={
OUTPUT
} language={CodeLanguage.json} - value={JSON.stringify(outputs)} - onChange={() => {}} + value={outputs} + isJSONStringifyBeauty /> )}
-
+