Commit 17e8c912 authored by Joel's avatar Joel

feat: template transform panel content

parent db7dccf3
...@@ -46,9 +46,9 @@ const Page: FC = () => { ...@@ -46,9 +46,9 @@ const Page: FC = () => {
/* /*
* TODO: for debug. * TODO: for debug.
* 2 directAnswer 3: llm 5: questionClassifier * 2 directAnswer 3: llm 5: questionClassifier
* 7 Code * 7 Code, 8 TemplateTransform
*/ */
selectedNodeId='7' selectedNodeId='8'
/> />
</div> </div>
) )
......
'use client' 'use client'
import type { FC } from 'react' import type { FC } from 'react'
import React from 'react' import React from 'react'
import type { CodeLanguage } from '../../../code/types'
import Base from './base' import Base from './base'
type Props = { type Props = {
value: string value: string
onChange: (value: string) => void onChange: (value: string) => void
title: JSX.Element title: JSX.Element
codeLanguage: string
onCodeLanguageChange: (codeLanguage: CodeLanguage) => void
} }
const CodeEditor: FC<Props> = ({ const CodeEditor: FC<Props> = ({
......
...@@ -57,8 +57,6 @@ const Panel: FC = () => { ...@@ -57,8 +57,6 @@ const Panel: FC = () => {
} }
value={inputs.code} value={inputs.code}
onChange={handleCodeChange} onChange={handleCodeChange}
codeLanguage={inputs.code_language}
onCodeLanguageChange={handleCodeLanguageChange}
/> />
<Split /> <Split />
</div> </div>
......
import type { TemplateTransformNodeType } from './types'
export const mockData: TemplateTransformNodeType = {
title: 'Test',
desc: 'Test',
type: 'Test',
variables: [
{
variable: 'name',
value_selector: ['aaa', 'name'],
},
{
variable: 'age',
value_selector: ['bbb', 'b', 'c'],
},
],
template: 'print("hello world")',
}
import type { FC } from 'react' import type { FC } from 'react'
import { useTranslation } from 'react-i18next'
import useConfig from './use-config'
import { mockData } from './mock'
import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list'
import AddButton from '@/app/components/base/button/add-button'
import Field from '@/app/components/workflow/nodes/_base/components/field'
import Split from '@/app/components/workflow/nodes/_base/components/split'
import CodeEditor from '@/app/components/workflow/nodes/_base/components/editor/code-editor'
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
const i18nPrefix = 'workflow.nodes.templateTransform'
const Panel: FC = () => { const Panel: FC = () => {
const { t } = useTranslation()
const readOnly = false
const {
inputs,
handleVarListChange,
handleAddVariable,
handleCodeChange,
} = useConfig(mockData)
return ( return (
<div>start panel inputs</div> <div className='mt-2 px-4 space-y-4'>
<Field
title={t(`${i18nPrefix}.inputVars`)}
operations={
<AddButton onClick={handleAddVariable} />
}
>
<VarList
readonly={readOnly}
list={inputs.variables}
onChange={handleVarListChange}
/>
</Field>
<Split />
<CodeEditor
title={
<div>{t(`${i18nPrefix}.code`)}</div>
}
value={inputs.template}
onChange={handleCodeChange}
/>
<Split />
<OutputVars>
<>
<VarItem
name='output'
type='string'
description={t(`${i18nPrefix}.outputVars.output`)}
/>
</>
</OutputVars>
</div>
) )
} }
......
import { useCallback, useState } from 'react'
import useVarList from '../_base/hooks/use-var-list'
import type { TemplateTransformNodeType } from './types'
const useConfig = (initInputs: TemplateTransformNodeType) => {
const [inputs, setInputs] = useState<TemplateTransformNodeType>(initInputs)
const { handleVarListChange, handleAddVariable } = useVarList<TemplateTransformNodeType>({
inputs,
setInputs,
})
const handleCodeChange = useCallback((template: string) => {
setInputs(prev => ({ ...prev, template }))
}, [setInputs])
return {
inputs,
handleVarListChange,
handleAddVariable,
handleCodeChange,
}
}
export default useConfig
...@@ -22,6 +22,13 @@ const translation = { ...@@ -22,6 +22,13 @@ const translation = {
code: { code: {
inputVars: 'Input Variables', inputVars: 'Input Variables',
}, },
templateTransform: {
inputVars: 'Input Variables',
code: 'Code',
outputVars: {
output: 'Transformed content',
},
},
}, },
} }
......
...@@ -21,6 +21,13 @@ const translation = { ...@@ -21,6 +21,13 @@ const translation = {
code: { code: {
inputVars: '输入变量', inputVars: '输入变量',
}, },
templateTransform: {
inputVars: '输入变量',
code: '代码',
outputVars: {
output: '转换后内容',
},
},
}, },
}, },
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment