This commit is contained in:
StyleZhang
2024-03-12 13:25:57 +08:00
parent 9753077661
commit 8ae46a8a14
3 changed files with 37 additions and 5 deletions

View File

@ -3,6 +3,7 @@ import type { FC } from 'react'
import React, { useCallback } from 'react'
import produce from 'immer'
import { useTranslation } from 'react-i18next'
import { useWorkflow } from '../../../hooks'
import AddButton from '../../_base/components/add-button'
import Item from './class-item'
import type { Topic } from '@/app/components/workflow/nodes/question-classifier/types'
@ -10,15 +11,18 @@ import type { Topic } from '@/app/components/workflow/nodes/question-classifier/
const i18nPrefix = 'workflow.nodes.questionClassifiers'
type Props = {
id: string
list: Topic[]
onChange: (list: Topic[]) => void
}
const ClassList: FC<Props> = ({
id,
list,
onChange,
}) => {
const { t } = useTranslation()
const { handleEdgeDeleteByDeleteBranch } = useWorkflow()
const handleClassChange = useCallback((index: number) => {
return (value: Topic) => {
@ -34,16 +38,17 @@ const ClassList: FC<Props> = ({
draft.push({ id: `${Date.now()}`, name: '' })
})
onChange(newList)
}, [list, onChange, t])
}, [list, onChange])
const handleRemoveClass = useCallback((index: number) => {
return () => {
handleEdgeDeleteByDeleteBranch(id, list[index].id)
const newList = produce(list, (draft) => {
draft.splice(index, 1)
})
onChange(newList)
}
}, [list, onChange])
}, [list, onChange, handleEdgeDeleteByDeleteBranch, id])
// Todo Remove; edit topic name
return (

View File

@ -72,6 +72,7 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
title={t(`${i18nPrefix}.class`)}
>
<ClassList
id={id}
list={inputs.classes}
onChange={handleTopicsChange} />
</Field>