mirror of
https://github.com/langgenius/dify.git
synced 2026-01-06 06:26:00 +00:00
chore: stringify output
This commit is contained in:
@@ -7,12 +7,13 @@ import { CodeLanguage } from '@/app/components/workflow/nodes/code/types'
|
|||||||
import './style.css'
|
import './style.css'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
value: string
|
value?: string | object
|
||||||
onChange: (value: string) => void
|
onChange?: (value: string) => void
|
||||||
title: JSX.Element
|
title: JSX.Element
|
||||||
language: CodeLanguage
|
language: CodeLanguage
|
||||||
headerRight?: JSX.Element
|
headerRight?: JSX.Element
|
||||||
readOnly?: boolean
|
readOnly?: boolean
|
||||||
|
isJSONStringifyBeauty?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const languageMap = {
|
const languageMap = {
|
||||||
@@ -22,12 +23,13 @@ const languageMap = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const CodeEditor: FC<Props> = ({
|
const CodeEditor: FC<Props> = ({
|
||||||
value,
|
value = '',
|
||||||
onChange,
|
onChange = () => { },
|
||||||
title,
|
title,
|
||||||
headerRight,
|
headerRight,
|
||||||
language,
|
language,
|
||||||
readOnly,
|
readOnly,
|
||||||
|
isJSONStringifyBeauty,
|
||||||
}) => {
|
}) => {
|
||||||
const [isFocus, setIsFocus] = React.useState(false)
|
const [isFocus, setIsFocus] = React.useState(false)
|
||||||
|
|
||||||
@@ -64,11 +66,22 @@ const CodeEditor: FC<Props> = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const outPutValue = (() => {
|
||||||
|
if (!isJSONStringifyBeauty)
|
||||||
|
return value as string
|
||||||
|
try {
|
||||||
|
return JSON.stringify(value as object, null, 2)
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
return value as string
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Base
|
<Base
|
||||||
title={title}
|
title={title}
|
||||||
value={value}
|
value={outPutValue}
|
||||||
headerRight={headerRight}
|
headerRight={headerRight}
|
||||||
isFocus={isFocus}
|
isFocus={isFocus}
|
||||||
minHeight={200}
|
minHeight={200}
|
||||||
@@ -79,7 +92,7 @@ const CodeEditor: FC<Props> = ({
|
|||||||
// language={language === CodeLanguage.javascript ? 'javascript' : 'python'}
|
// language={language === CodeLanguage.javascript ? 'javascript' : 'python'}
|
||||||
language={languageMap[language] || 'javascript'}
|
language={languageMap[language] || 'javascript'}
|
||||||
theme={isFocus ? 'focus-theme' : 'blur-theme'}
|
theme={isFocus ? 'focus-theme' : 'blur-theme'}
|
||||||
value={value}
|
value={outPutValue}
|
||||||
onChange={handleEditorChange}
|
onChange={handleEditorChange}
|
||||||
// https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IEditorOptions.html
|
// https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.IEditorOptions.html
|
||||||
options={{
|
options={{
|
||||||
|
|||||||
@@ -48,16 +48,16 @@ const ResultPanel: FC<ResultPanelProps> = ({
|
|||||||
readOnly
|
readOnly
|
||||||
title={<div>INPUT</div>}
|
title={<div>INPUT</div>}
|
||||||
language={CodeLanguage.json}
|
language={CodeLanguage.json}
|
||||||
value={JSON.stringify(inputs)}
|
value={inputs}
|
||||||
onChange={() => {}}
|
isJSONStringifyBeauty
|
||||||
/>
|
/>
|
||||||
{process_data && (
|
{process_data && (
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
readOnly
|
readOnly
|
||||||
title={<div>PROCESS DATA</div>}
|
title={<div>PROCESS DATA</div>}
|
||||||
language={CodeLanguage.json}
|
language={CodeLanguage.json}
|
||||||
value={JSON.stringify(process_data)}
|
value={process_data}
|
||||||
onChange={() => {}}
|
isJSONStringifyBeauty
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{(outputs || status === 'running') && (
|
{(outputs || status === 'running') && (
|
||||||
@@ -65,13 +65,13 @@ const ResultPanel: FC<ResultPanelProps> = ({
|
|||||||
readOnly
|
readOnly
|
||||||
title={<div>OUTPUT</div>}
|
title={<div>OUTPUT</div>}
|
||||||
language={CodeLanguage.json}
|
language={CodeLanguage.json}
|
||||||
value={JSON.stringify(outputs)}
|
value={outputs}
|
||||||
onChange={() => {}}
|
isJSONStringifyBeauty
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='px-4 py-2'>
|
<div className='px-4 py-2'>
|
||||||
<div className='h-[0.5px] bg-black opacity-5'/>
|
<div className='h-[0.5px] bg-black opacity-5' />
|
||||||
</div>
|
</div>
|
||||||
<div className='px-4 py-2'>
|
<div className='px-4 py-2'>
|
||||||
<MetaData
|
<MetaData
|
||||||
|
|||||||
Reference in New Issue
Block a user