Commit 8ae46a8a authored by StyleZhang's avatar StyleZhang

fix

parent 97530776
...@@ -80,7 +80,7 @@ export const useWorkflow = () => { ...@@ -80,7 +80,7 @@ export const useWorkflow = () => {
if (appId) { if (appId) {
const features = featuresStore!.getState().features const features = featuresStore!.getState().features
const nodes = produce(getNodes(), (draft) => { const producedNodes = produce(getNodes(), (draft) => {
draft.forEach((node) => { draft.forEach((node) => {
Object.keys(node.data).forEach((key) => { Object.keys(node.data).forEach((key) => {
if (key.startsWith('_')) if (key.startsWith('_'))
...@@ -88,12 +88,17 @@ export const useWorkflow = () => { ...@@ -88,12 +88,17 @@ export const useWorkflow = () => {
}) })
}) })
}) })
const producedEdges = produce(edges, (draft) => {
draft.forEach((edge) => {
delete edge.data
})
})
syncWorkflowDraft({ syncWorkflowDraft({
url: `/apps/${appId}/workflows/draft`, url: `/apps/${appId}/workflows/draft`,
params: { params: {
graph: { graph: {
nodes, nodes: producedNodes,
edges, edges: producedEdges,
viewport: getViewport(), viewport: getViewport(),
}, },
features: { features: {
...@@ -599,6 +604,26 @@ export const useWorkflow = () => { ...@@ -599,6 +604,26 @@ export const useWorkflow = () => {
setEdges(newEdges) setEdges(newEdges)
}, [store]) }, [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 handleEdgeDelete = useCallback(() => {
const { runningStatus } = useStore.getState() const { runningStatus } = useStore.getState()
...@@ -670,6 +695,7 @@ export const useWorkflow = () => { ...@@ -670,6 +695,7 @@ export const useWorkflow = () => {
handleEdgeEnter, handleEdgeEnter,
handleEdgeLeave, handleEdgeLeave,
handleEdgeDeleteByDeleteBranch,
handleEdgeDelete, handleEdgeDelete,
handleEdgesChange, handleEdgesChange,
......
...@@ -3,6 +3,7 @@ import type { FC } from 'react' ...@@ -3,6 +3,7 @@ import type { FC } from 'react'
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import produce from 'immer' import produce from 'immer'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useWorkflow } from '../../../hooks'
import AddButton from '../../_base/components/add-button' 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'
...@@ -10,15 +11,18 @@ import type { Topic } from '@/app/components/workflow/nodes/question-classifier/ ...@@ -10,15 +11,18 @@ import type { Topic } from '@/app/components/workflow/nodes/question-classifier/
const i18nPrefix = 'workflow.nodes.questionClassifiers' const i18nPrefix = 'workflow.nodes.questionClassifiers'
type Props = { type Props = {
id: string
list: Topic[] list: Topic[]
onChange: (list: Topic[]) => void onChange: (list: Topic[]) => void
} }
const ClassList: FC<Props> = ({ const ClassList: FC<Props> = ({
id,
list, list,
onChange, onChange,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { handleEdgeDeleteByDeleteBranch } = useWorkflow()
const handleClassChange = useCallback((index: number) => { const handleClassChange = useCallback((index: number) => {
return (value: Topic) => { return (value: Topic) => {
...@@ -34,16 +38,17 @@ const ClassList: FC<Props> = ({ ...@@ -34,16 +38,17 @@ const ClassList: FC<Props> = ({
draft.push({ id: `${Date.now()}`, name: '' }) draft.push({ id: `${Date.now()}`, name: '' })
}) })
onChange(newList) onChange(newList)
}, [list, onChange, t]) }, [list, onChange])
const handleRemoveClass = useCallback((index: number) => { const handleRemoveClass = useCallback((index: number) => {
return () => { return () => {
handleEdgeDeleteByDeleteBranch(id, list[index].id)
const newList = produce(list, (draft) => { const newList = produce(list, (draft) => {
draft.splice(index, 1) draft.splice(index, 1)
}) })
onChange(newList) onChange(newList)
} }
}, [list, onChange]) }, [list, onChange, handleEdgeDeleteByDeleteBranch, id])
// Todo Remove; edit topic name // Todo Remove; edit topic name
return ( return (
......
...@@ -72,6 +72,7 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({ ...@@ -72,6 +72,7 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
title={t(`${i18nPrefix}.class`)} title={t(`${i18nPrefix}.class`)}
> >
<ClassList <ClassList
id={id}
list={inputs.classes} list={inputs.classes}
onChange={handleTopicsChange} /> onChange={handleTopicsChange} />
</Field> </Field>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment