mirror of
https://github.com/langgenius/dify.git
synced 2026-04-13 22:57:26 +08:00
feat: template transform panel content
This commit is contained in:
parent
db7dccf349
commit
17e8c91267
@ -46,9 +46,9 @@ const Page: FC = () => {
|
||||
/*
|
||||
* TODO: for debug.
|
||||
* 2 directAnswer 3: llm 5: questionClassifier
|
||||
* 7 Code
|
||||
* 7 Code, 8 TemplateTransform
|
||||
*/
|
||||
selectedNodeId='7'
|
||||
selectedNodeId='8'
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@ -1,15 +1,12 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import React from 'react'
|
||||
import type { CodeLanguage } from '../../../code/types'
|
||||
import Base from './base'
|
||||
|
||||
type Props = {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
title: JSX.Element
|
||||
codeLanguage: string
|
||||
onCodeLanguageChange: (codeLanguage: CodeLanguage) => void
|
||||
}
|
||||
|
||||
const CodeEditor: FC<Props> = ({
|
||||
|
||||
@ -57,8 +57,6 @@ const Panel: FC = () => {
|
||||
}
|
||||
value={inputs.code}
|
||||
onChange={handleCodeChange}
|
||||
codeLanguage={inputs.code_language}
|
||||
onCodeLanguageChange={handleCodeLanguageChange}
|
||||
/>
|
||||
<Split />
|
||||
</div>
|
||||
|
||||
18
web/app/components/workflow/nodes/template-transform/mock.ts
Normal file
18
web/app/components/workflow/nodes/template-transform/mock.ts
Normal file
@ -0,0 +1,18 @@
|
||||
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")',
|
||||
}
|
||||
@ -1,8 +1,59 @@
|
||||
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 { t } = useTranslation()
|
||||
const readOnly = false
|
||||
|
||||
const {
|
||||
inputs,
|
||||
handleVarListChange,
|
||||
handleAddVariable,
|
||||
handleCodeChange,
|
||||
} = useConfig(mockData)
|
||||
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>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
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 = {
|
||||
code: {
|
||||
inputVars: 'Input Variables',
|
||||
},
|
||||
templateTransform: {
|
||||
inputVars: 'Input Variables',
|
||||
code: 'Code',
|
||||
outputVars: {
|
||||
output: 'Transformed content',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,13 @@ const translation = {
|
||||
code: {
|
||||
inputVars: '输入变量',
|
||||
},
|
||||
templateTransform: {
|
||||
inputVars: '输入变量',
|
||||
code: '代码',
|
||||
outputVars: {
|
||||
output: '转换后内容',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user