|
|
|
@ -1,6 +1,6 @@
|
|
|
|
'use client'
|
|
|
|
'use client'
|
|
|
|
import type { FC } from 'react'
|
|
|
|
import type { FC } from 'react'
|
|
|
|
import React, { useCallback } from 'react'
|
|
|
|
import React, { useCallback, useState } from 'react'
|
|
|
|
import produce from 'immer'
|
|
|
|
import produce from 'immer'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useEdgesInteractions } from '../../../hooks'
|
|
|
|
import { useEdgesInteractions } from '../../../hooks'
|
|
|
|
@ -8,6 +8,10 @@ import AddButton from '../../_base/components/add-button'
|
|
|
|
import Item from './class-item'
|
|
|
|
import Item from './class-item'
|
|
|
|
import type { Topic } from '@/app/components/workflow/nodes/question-classifier/types'
|
|
|
|
import type { Topic } from '@/app/components/workflow/nodes/question-classifier/types'
|
|
|
|
import type { ValueSelector, Var } from '@/app/components/workflow/types'
|
|
|
|
import type { ValueSelector, Var } from '@/app/components/workflow/types'
|
|
|
|
|
|
|
|
import { ReactSortable } from 'react-sortablejs'
|
|
|
|
|
|
|
|
import { noop } from 'lodash-es'
|
|
|
|
|
|
|
|
import { RiDraggable } from '@remixicon/react'
|
|
|
|
|
|
|
|
import cn from '@/utils/classnames'
|
|
|
|
|
|
|
|
|
|
|
|
const i18nPrefix = 'workflow.nodes.questionClassifiers'
|
|
|
|
const i18nPrefix = 'workflow.nodes.questionClassifiers'
|
|
|
|
|
|
|
|
|
|
|
|
@ -17,6 +21,7 @@ type Props = {
|
|
|
|
onChange: (list: Topic[]) => void
|
|
|
|
onChange: (list: Topic[]) => void
|
|
|
|
readonly?: boolean
|
|
|
|
readonly?: boolean
|
|
|
|
filterVar: (payload: Var, valueSelector: ValueSelector) => boolean
|
|
|
|
filterVar: (payload: Var, valueSelector: ValueSelector) => boolean
|
|
|
|
|
|
|
|
handleSortTopic?: (newTopics: (Topic & { id: string })[]) => void
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const ClassList: FC<Props> = ({
|
|
|
|
const ClassList: FC<Props> = ({
|
|
|
|
@ -25,6 +30,7 @@ const ClassList: FC<Props> = ({
|
|
|
|
onChange,
|
|
|
|
onChange,
|
|
|
|
readonly,
|
|
|
|
readonly,
|
|
|
|
filterVar,
|
|
|
|
filterVar,
|
|
|
|
|
|
|
|
handleSortTopic = noop,
|
|
|
|
}) => {
|
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { handleEdgeDeleteByDeleteBranch } = useEdgesInteractions()
|
|
|
|
const { handleEdgeDeleteByDeleteBranch } = useEdgesInteractions()
|
|
|
|
@ -55,22 +61,46 @@ const ClassList: FC<Props> = ({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [list, onChange, handleEdgeDeleteByDeleteBranch, nodeId])
|
|
|
|
}, [list, onChange, handleEdgeDeleteByDeleteBranch, nodeId])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [willDeleteCaseId, setWillDeleteCaseId] = useState('')
|
|
|
|
|
|
|
|
const topicCount = list.length
|
|
|
|
|
|
|
|
const handleSideWidth = 3
|
|
|
|
// Todo Remove; edit topic name
|
|
|
|
// Todo Remove; edit topic name
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className='space-y-2'>
|
|
|
|
<ReactSortable
|
|
|
|
|
|
|
|
list={list.map(item => ({ ...item }))}
|
|
|
|
|
|
|
|
setList={handleSortTopic}
|
|
|
|
|
|
|
|
handle='.handle'
|
|
|
|
|
|
|
|
ghostClass='bg-components-panel-bg'
|
|
|
|
|
|
|
|
animation={150}
|
|
|
|
|
|
|
|
disabled={readonly}
|
|
|
|
|
|
|
|
className='space-y-2'
|
|
|
|
|
|
|
|
>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
list.map((item, index) => {
|
|
|
|
list.map((item, index) => {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Item
|
|
|
|
<div key={item.id}
|
|
|
|
nodeId={nodeId}
|
|
|
|
className={cn(
|
|
|
|
key={list[index].id}
|
|
|
|
'group relative rounded-[10px] bg-components-panel-bg',
|
|
|
|
payload={item}
|
|
|
|
willDeleteCaseId === item.id && 'bg-state-destructive-hover',
|
|
|
|
onChange={handleClassChange(index)}
|
|
|
|
`-ml-${handleSideWidth} min-h-[40px] px-0 py-0`,
|
|
|
|
onRemove={handleRemoveClass(index)}
|
|
|
|
)}>
|
|
|
|
index={index + 1}
|
|
|
|
<RiDraggable className={cn(
|
|
|
|
readonly={readonly}
|
|
|
|
'handle absolute left-0 top-3 hidden h-3 w-3 cursor-pointer text-text-quaternary',
|
|
|
|
filterVar={filterVar}
|
|
|
|
topicCount > 1 && 'group-hover:block',
|
|
|
|
/>
|
|
|
|
)} />
|
|
|
|
|
|
|
|
<div className={`ml-${handleSideWidth}`}>
|
|
|
|
|
|
|
|
<Item
|
|
|
|
|
|
|
|
nodeId={nodeId}
|
|
|
|
|
|
|
|
key={list[index].id}
|
|
|
|
|
|
|
|
payload={item}
|
|
|
|
|
|
|
|
onChange={handleClassChange(index)}
|
|
|
|
|
|
|
|
onRemove={handleRemoveClass(index)}
|
|
|
|
|
|
|
|
index={index + 1}
|
|
|
|
|
|
|
|
readonly={readonly}
|
|
|
|
|
|
|
|
filterVar={filterVar}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -81,7 +111,7 @@ const ClassList: FC<Props> = ({
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</ReactSortable>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default React.memo(ClassList)
|
|
|
|
export default React.memo(ClassList)
|
|
|
|
|