mirror of https://github.com/langgenius/dify.git
fix
This commit is contained in:
parent
9753077661
commit
8ae46a8a14
|
|
@ -80,7 +80,7 @@ export const useWorkflow = () => {
|
|||
|
||||
if (appId) {
|
||||
const features = featuresStore!.getState().features
|
||||
const nodes = produce(getNodes(), (draft) => {
|
||||
const producedNodes = produce(getNodes(), (draft) => {
|
||||
draft.forEach((node) => {
|
||||
Object.keys(node.data).forEach((key) => {
|
||||
if (key.startsWith('_'))
|
||||
|
|
@ -88,12 +88,17 @@ export const useWorkflow = () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
const producedEdges = produce(edges, (draft) => {
|
||||
draft.forEach((edge) => {
|
||||
delete edge.data
|
||||
})
|
||||
})
|
||||
syncWorkflowDraft({
|
||||
url: `/apps/${appId}/workflows/draft`,
|
||||
params: {
|
||||
graph: {
|
||||
nodes,
|
||||
edges,
|
||||
nodes: producedNodes,
|
||||
edges: producedEdges,
|
||||
viewport: getViewport(),
|
||||
},
|
||||
features: {
|
||||
|
|
@ -599,6 +604,26 @@ export const useWorkflow = () => {
|
|||
setEdges(newEdges)
|
||||
}, [store])
|
||||
|
||||
const handleEdgeDeleteByDeleteBranch = useCallback((nodeId: string, branchId: string) => {
|
||||
const { runningStatus } = useStore.getState()
|
||||
|
||||
if (runningStatus)
|
||||
return
|
||||
|
||||
const {
|
||||
edges,
|
||||
setEdges,
|
||||
} = store.getState()
|
||||
const newEdges = produce(edges, (draft) => {
|
||||
const index = draft.findIndex(edge => edge.source === nodeId && edge.sourceHandle === branchId)
|
||||
|
||||
if (index > -1)
|
||||
draft.splice(index, 1)
|
||||
})
|
||||
setEdges(newEdges)
|
||||
handleSyncWorkflowDraft()
|
||||
}, [store, handleSyncWorkflowDraft])
|
||||
|
||||
const handleEdgeDelete = useCallback(() => {
|
||||
const { runningStatus } = useStore.getState()
|
||||
|
||||
|
|
@ -670,6 +695,7 @@ export const useWorkflow = () => {
|
|||
|
||||
handleEdgeEnter,
|
||||
handleEdgeLeave,
|
||||
handleEdgeDeleteByDeleteBranch,
|
||||
handleEdgeDelete,
|
||||
handleEdgesChange,
|
||||
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
|
|||
title={t(`${i18nPrefix}.class`)}
|
||||
>
|
||||
<ClassList
|
||||
id={id}
|
||||
list={inputs.classes}
|
||||
onChange={handleTopicsChange} />
|
||||
</Field>
|
||||
|
|
|
|||
Loading…
Reference in New Issue