fix: can set the template value

feat/enchance-prompt-and-code-fe
Joel 10 months ago
parent 525e64467d
commit 4e27d2c35f

@ -134,10 +134,12 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
const [instruction, setInstruction] = useState<string>('') const [instruction, setInstruction] = useState<string>('')
const [ideaOutput, setIdeaOutput] = useState<string>('') const [ideaOutput, setIdeaOutput] = useState<string>('')
const [editorKey, setEditorKey] = useState(`${flowId}-0`)
const handleChooseTemplate = useCallback((key: string) => { const handleChooseTemplate = useCallback((key: string) => {
return () => { return () => {
const template = t(`appDebug.generate.template.${key}.instruction`) const template = t(`appDebug.generate.template.${key}.instruction`)
setInstruction(template) setInstruction(template)
setEditorKey(`${flowId}-${Date.now()}`)
} }
}, [t]) }, [t])
const isValid = () => { const isValid = () => {
@ -318,6 +320,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
<div className='system-sm-semibold-uppercase mb-1.5 text-text-secondary'>{t('appDebug.generate.instruction')}</div> <div className='system-sm-semibold-uppercase mb-1.5 text-text-secondary'>{t('appDebug.generate.instruction')}</div>
{isBasicMode ? ( {isBasicMode ? (
<InstructionEditorInBasic <InstructionEditorInBasic
editorKey={editorKey}
generatorType={GeneratorType.prompt} generatorType={GeneratorType.prompt}
value={instruction} value={instruction}
onChange={setInstruction} onChange={setInstruction}
@ -326,6 +329,7 @@ const GetAutomaticRes: FC<IGetAutomaticResProps> = ({
/> />
) : ( ) : (
<InstructionEditorInWorkflow <InstructionEditorInWorkflow
editorKey={editorKey}
generatorType={GeneratorType.prompt} generatorType={GeneratorType.prompt}
value={instruction} value={instruction}
onChange={setInstruction} onChange={setInstruction}

@ -11,6 +11,7 @@ import { useWorkflowVariableType } from '@/app/components/workflow/hooks'
type Props = { type Props = {
nodeId: string nodeId: string
value: string value: string
editorKey: string
onChange: (text: string) => void onChange: (text: string) => void
generatorType: GeneratorType generatorType: GeneratorType
} }
@ -18,6 +19,7 @@ type Props = {
const InstructionEditorInWorkflow: FC<Props> = ({ const InstructionEditorInWorkflow: FC<Props> = ({
nodeId, nodeId,
value, value,
editorKey,
onChange, onChange,
generatorType, generatorType,
}) => { }) => {
@ -37,6 +39,7 @@ const InstructionEditorInWorkflow: FC<Props> = ({
<InstructionEditor <InstructionEditor
value={value} value={value}
onChange={onChange} onChange={onChange}
editorKey={editorKey}
generatorType={generatorType} generatorType={generatorType}
availableVars={availableVars} availableVars={availableVars}
availableNodes={availableNodes} availableNodes={availableNodes}

@ -10,6 +10,7 @@ import { useTranslation } from 'react-i18next'
import { Type } from '@/app/components/workflow/nodes/llm/types' import { Type } from '@/app/components/workflow/nodes/llm/types'
type Props = { type Props = {
editorKey: string
value: string value: string
onChange: (text: string) => void onChange: (text: string) => void
generatorType: GeneratorType generatorType: GeneratorType
@ -24,6 +25,7 @@ type Props = {
const i18nPrefix = 'appDebug.generate' const i18nPrefix = 'appDebug.generate'
const InstructionEditor: FC<Props> = ({ const InstructionEditor: FC<Props> = ({
editorKey,
generatorType, generatorType,
value, value,
onChange, onChange,
@ -50,7 +52,7 @@ const InstructionEditor: FC<Props> = ({
<div> <div>
<PromptEditor <PromptEditor
wrapperClassName='border !border-components-input-bg-normal bg-components-input-bg-normal hover:!border-components-input-bg-hover rounded-[10px] px-4 pt-3' wrapperClassName='border !border-components-input-bg-normal bg-components-input-bg-normal hover:!border-components-input-bg-hover rounded-[10px] px-4 pt-3'
// key={controlPromptEditorRerenderKey} key={editorKey}
placeholder={placeholder} placeholder={placeholder}
placeholderClassName='px-4 pt-3' placeholderClassName='px-4 pt-3'
className={cn('min-h-[240px] ')} className={cn('min-h-[240px] ')}

@ -75,7 +75,7 @@ export const GetCodeGeneratorResModal: FC<IGetCodeGeneratorResProps> = (
const [ideaOutput, setIdeaOutput] = useState<string>('') const [ideaOutput, setIdeaOutput] = useState<string>('')
const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false) const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false)
const storageKey = `${flowId}-${nodeId}}` const storageKey = `${flowId}-${nodeId}`
const { addVersion, current, currentVersionIndex, setCurrentVersionIndex, versions } = useGenData({ const { addVersion, current, currentVersionIndex, setCurrentVersionIndex, versions } = useGenData({
storageKey, storageKey,
}) })

Loading…
Cancel
Save