| | |
| | | import AddButton from '../../_base/components/add-button' |
| | | import Item from './class-item' |
| | | import type { Topic } from '@/app/components/workflow/nodes/question-classifier/types' |
| | | import type { ValueSelector, Var } from '@/app/components/workflow/types' |
| | | |
| | | const i18nPrefix = 'workflow.nodes.questionClassifiers' |
| | | |
| | | type Props = { |
| | | nodeId: string |
| | | id: string |
| | | list: Topic[] |
| | | onChange: (list: Topic[]) => void |
| | | readonly?: boolean |
| | | filterVar: (payload: Var, valueSelector: ValueSelector) => boolean |
| | | } |
| | | |
| | | const ClassList: FC<Props> = ({ |
| | | nodeId, |
| | | id, |
| | | list, |
| | | onChange, |
| | | readonly, |
| | | filterVar, |
| | | }) => { |
| | | const { t } = useTranslation() |
| | | const { handleEdgeDeleteByDeleteBranch } = useEdgesInteractions() |
| | |
| | | |
| | | const handleRemoveClass = useCallback((index: number) => { |
| | | return () => { |
| | | handleEdgeDeleteByDeleteBranch(nodeId, list[index].id) |
| | | handleEdgeDeleteByDeleteBranch(id, list[index].id) |
| | | const newList = produce(list, (draft) => { |
| | | draft.splice(index, 1) |
| | | }) |
| | | onChange(newList) |
| | | } |
| | | }, [list, onChange, handleEdgeDeleteByDeleteBranch, nodeId]) |
| | | }, [list, onChange, handleEdgeDeleteByDeleteBranch, id]) |
| | | |
| | | // Todo Remove; edit topic name |
| | | return ( |
| | |
| | | list.map((item, index) => { |
| | | return ( |
| | | <Item |
| | | nodeId={nodeId} |
| | | key={list[index].id} |
| | | key={index} |
| | | payload={item} |
| | | onChange={handleClassChange(index)} |
| | | onRemove={handleRemoveClass(index)} |
| | | index={index + 1} |
| | | readonly={readonly} |
| | | filterVar={filterVar} |
| | | /> |
| | | ) |
| | | }) |