balibabu
commited on
Commit
·
916a392
1
Parent(s):
054d7ff
feat: fix the problem of form entries being deleted when adding a new line #918 and clear the selection box to delete the corresponding edge (#1301)
Browse files### What problem does this PR solve?
feat: clear the selection box to delete the corresponding edge. #918
feat: fix the problem of form entries being deleted when adding a new
line #918
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
web/src/pages/flow/categorize-form/hooks.ts
CHANGED
@@ -78,9 +78,11 @@ const buildCategorizeObjectFromList = (list: Array<ICategorizeItem>) => {
|
|
78 |
export const useHandleFormValuesChange = ({
|
79 |
onValuesChange,
|
80 |
form,
|
81 |
-
|
82 |
}: IOperatorForm) => {
|
83 |
const edges = useGraphStore((state) => state.edges);
|
|
|
|
|
84 |
|
85 |
const handleValuesChange = useCallback(
|
86 |
(changedValues: any, values: any) => {
|
@@ -94,12 +96,13 @@ export const useHandleFormValuesChange = ({
|
|
94 |
);
|
95 |
|
96 |
useEffect(() => {
|
|
|
|
|
|
|
|
|
|
|
97 |
form?.setFieldsValue({
|
98 |
-
items
|
99 |
-
get(node, 'data.form.category_description', {}),
|
100 |
-
edges,
|
101 |
-
node,
|
102 |
-
),
|
103 |
});
|
104 |
}, [form, node, edges]);
|
105 |
|
@@ -107,19 +110,29 @@ export const useHandleFormValuesChange = ({
|
|
107 |
};
|
108 |
|
109 |
export const useHandleToSelectChange = (nodeId?: string) => {
|
110 |
-
const { addEdge } = useGraphStore(
|
|
|
|
|
111 |
const handleSelectChange = useCallback(
|
112 |
(name?: string) => (value?: string) => {
|
113 |
-
if (nodeId &&
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
}
|
121 |
},
|
122 |
-
[addEdge, nodeId],
|
123 |
);
|
124 |
|
125 |
return { handleSelectChange };
|
|
|
78 |
export const useHandleFormValuesChange = ({
|
79 |
onValuesChange,
|
80 |
form,
|
81 |
+
nodeId,
|
82 |
}: IOperatorForm) => {
|
83 |
const edges = useGraphStore((state) => state.edges);
|
84 |
+
const getNode = useGraphStore((state) => state.getNode);
|
85 |
+
const node = getNode(nodeId);
|
86 |
|
87 |
const handleValuesChange = useCallback(
|
88 |
(changedValues: any, values: any) => {
|
|
|
96 |
);
|
97 |
|
98 |
useEffect(() => {
|
99 |
+
const items = buildCategorizeListFromObject(
|
100 |
+
get(node, 'data.form.category_description', {}),
|
101 |
+
edges,
|
102 |
+
node,
|
103 |
+
);
|
104 |
form?.setFieldsValue({
|
105 |
+
items,
|
|
|
|
|
|
|
|
|
106 |
});
|
107 |
}, [form, node, edges]);
|
108 |
|
|
|
110 |
};
|
111 |
|
112 |
export const useHandleToSelectChange = (nodeId?: string) => {
|
113 |
+
const { addEdge, deleteEdgeBySourceAndSourceHandle } = useGraphStore(
|
114 |
+
(state) => state,
|
115 |
+
);
|
116 |
const handleSelectChange = useCallback(
|
117 |
(name?: string) => (value?: string) => {
|
118 |
+
if (nodeId && name) {
|
119 |
+
if (value) {
|
120 |
+
addEdge({
|
121 |
+
source: nodeId,
|
122 |
+
target: value,
|
123 |
+
sourceHandle: name,
|
124 |
+
targetHandle: null,
|
125 |
+
});
|
126 |
+
} else {
|
127 |
+
// clear selected value
|
128 |
+
deleteEdgeBySourceAndSourceHandle({
|
129 |
+
source: nodeId,
|
130 |
+
sourceHandle: name,
|
131 |
+
});
|
132 |
+
}
|
133 |
}
|
134 |
},
|
135 |
+
[addEdge, nodeId, deleteEdgeBySourceAndSourceHandle],
|
136 |
);
|
137 |
|
138 |
return { handleSelectChange };
|
web/src/pages/flow/categorize-form/index.tsx
CHANGED
@@ -10,7 +10,7 @@ const CategorizeForm = ({ form, onValuesChange, node }: IOperatorForm) => {
|
|
10 |
const { t } = useTranslate('flow');
|
11 |
const { handleValuesChange } = useHandleFormValuesChange({
|
12 |
form,
|
13 |
-
node,
|
14 |
onValuesChange,
|
15 |
});
|
16 |
useSetLlmSetting(form);
|
|
|
10 |
const { t } = useTranslate('flow');
|
11 |
const { handleValuesChange } = useHandleFormValuesChange({
|
12 |
form,
|
13 |
+
nodeId: node?.id,
|
14 |
onValuesChange,
|
15 |
});
|
16 |
useSetLlmSetting(form);
|
web/src/pages/flow/constant.tsx
CHANGED
@@ -101,13 +101,7 @@ export const CategorizeAnchorPointPositions = [
|
|
101 |
// key is the source of the edge, value is the target of the edge
|
102 |
// no connection lines are allowed between key and value
|
103 |
export const RestrictedUpstreamMap = {
|
104 |
-
[Operator.Begin]: [
|
105 |
-
Operator.Begin,
|
106 |
-
Operator.Answer,
|
107 |
-
Operator.Categorize,
|
108 |
-
Operator.Generate,
|
109 |
-
Operator.Retrieval,
|
110 |
-
],
|
111 |
[Operator.Categorize]: [Operator.Begin, Operator.Categorize, Operator.Answer],
|
112 |
[Operator.Answer]: [],
|
113 |
[Operator.Retrieval]: [],
|
|
|
101 |
// key is the source of the edge, value is the target of the edge
|
102 |
// no connection lines are allowed between key and value
|
103 |
export const RestrictedUpstreamMap = {
|
104 |
+
[Operator.Begin]: [],
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
[Operator.Categorize]: [Operator.Begin, Operator.Categorize, Operator.Answer],
|
106 |
[Operator.Answer]: [],
|
107 |
[Operator.Retrieval]: [],
|
web/src/pages/flow/interface.ts
CHANGED
@@ -10,6 +10,7 @@ export interface IOperatorForm {
|
|
10 |
onValuesChange?(changedValues: any, values: any): void;
|
11 |
form?: FormInstance;
|
12 |
node?: Node<NodeData>;
|
|
|
13 |
}
|
14 |
|
15 |
export interface IBeginForm {
|
|
|
10 |
onValuesChange?(changedValues: any, values: any): void;
|
11 |
form?: FormInstance;
|
12 |
node?: Node<NodeData>;
|
13 |
+
nodeId?: string;
|
14 |
}
|
15 |
|
16 |
export interface IBeginForm {
|
web/src/pages/flow/mock.tsx
CHANGED
@@ -37,7 +37,7 @@ export const dsl = {
|
|
37 |
graph: {
|
38 |
nodes: [
|
39 |
{
|
40 |
-
id: '
|
41 |
type: 'beginNode',
|
42 |
position: {
|
43 |
x: 50,
|
|
|
37 |
graph: {
|
38 |
nodes: [
|
39 |
{
|
40 |
+
id: 'Begin',
|
41 |
type: 'beginNode',
|
42 |
position: {
|
43 |
x: 50,
|
web/src/pages/flow/store.ts
CHANGED
@@ -35,7 +35,7 @@ export type RFState = {
|
|
35 |
updateNodeForm: (nodeId: string, values: any) => void;
|
36 |
onSelectionChange: OnSelectionChangeFunc;
|
37 |
addNode: (nodes: Node) => void;
|
38 |
-
getNode: (id
|
39 |
addEdge: (connection: Connection) => void;
|
40 |
getEdge: (id: string) => Edge | undefined;
|
41 |
deletePreviousEdgeOfClassificationNode: (connection: Connection) => void;
|
@@ -43,7 +43,7 @@ export type RFState = {
|
|
43 |
deleteEdge: () => void;
|
44 |
deleteEdgeById: (id: string) => void;
|
45 |
deleteNodeById: (id: string) => void;
|
46 |
-
|
47 |
findNodeByName: (operatorName: Operator) => Node | undefined;
|
48 |
updateMutableNodeFormItem: (id: string, field: string, value: any) => void;
|
49 |
};
|
@@ -87,7 +87,7 @@ const useGraphStore = create<RFState>()(
|
|
87 |
addNode: (node: Node) => {
|
88 |
set({ nodes: get().nodes.concat(node) });
|
89 |
},
|
90 |
-
getNode: (id
|
91 |
return get().nodes.find((x) => x.id === id);
|
92 |
},
|
93 |
addEdge: (connection: Connection) => {
|
@@ -150,12 +150,17 @@ const useGraphStore = create<RFState>()(
|
|
150 |
edges: edges.filter((edge) => edge.id !== id),
|
151 |
});
|
152 |
},
|
153 |
-
|
|
|
|
|
|
|
154 |
const { edges } = get();
|
|
|
|
|
|
|
|
|
155 |
set({
|
156 |
-
edges:
|
157 |
-
(edge) => edge.target !== target && edge.source !== source,
|
158 |
-
),
|
159 |
});
|
160 |
},
|
161 |
deleteNodeById: (id: string) => {
|
|
|
35 |
updateNodeForm: (nodeId: string, values: any) => void;
|
36 |
onSelectionChange: OnSelectionChangeFunc;
|
37 |
addNode: (nodes: Node) => void;
|
38 |
+
getNode: (id?: string) => Node | undefined;
|
39 |
addEdge: (connection: Connection) => void;
|
40 |
getEdge: (id: string) => Edge | undefined;
|
41 |
deletePreviousEdgeOfClassificationNode: (connection: Connection) => void;
|
|
|
43 |
deleteEdge: () => void;
|
44 |
deleteEdgeById: (id: string) => void;
|
45 |
deleteNodeById: (id: string) => void;
|
46 |
+
deleteEdgeBySourceAndSourceHandle: (connection: Partial<Connection>) => void;
|
47 |
findNodeByName: (operatorName: Operator) => Node | undefined;
|
48 |
updateMutableNodeFormItem: (id: string, field: string, value: any) => void;
|
49 |
};
|
|
|
87 |
addNode: (node: Node) => {
|
88 |
set({ nodes: get().nodes.concat(node) });
|
89 |
},
|
90 |
+
getNode: (id?: string) => {
|
91 |
return get().nodes.find((x) => x.id === id);
|
92 |
},
|
93 |
addEdge: (connection: Connection) => {
|
|
|
150 |
edges: edges.filter((edge) => edge.id !== id),
|
151 |
});
|
152 |
},
|
153 |
+
deleteEdgeBySourceAndSourceHandle: ({
|
154 |
+
source,
|
155 |
+
sourceHandle,
|
156 |
+
}: Partial<Connection>) => {
|
157 |
const { edges } = get();
|
158 |
+
const nextEdges = edges.filter(
|
159 |
+
(edge) =>
|
160 |
+
edge.source !== source || edge.sourceHandle !== sourceHandle,
|
161 |
+
);
|
162 |
set({
|
163 |
+
edges: nextEdges,
|
|
|
|
|
164 |
});
|
165 |
},
|
166 |
deleteNodeById: (id: string) => {
|
web/src/pages/flow/utils.ts
CHANGED
@@ -173,7 +173,8 @@ export const getOperatorTypeFromId = (id: string | null) => {
|
|
173 |
|
174 |
// restricted lines cannot be connected successfully.
|
175 |
export const isValidConnection = (connection: Connection) => {
|
176 |
-
|
177 |
getOperatorTypeFromId(connection.source) as Operator
|
178 |
]?.every((x) => x !== getOperatorTypeFromId(connection.target));
|
|
|
179 |
};
|
|
|
173 |
|
174 |
// restricted lines cannot be connected successfully.
|
175 |
export const isValidConnection = (connection: Connection) => {
|
176 |
+
const ret = RestrictedUpstreamMap[
|
177 |
getOperatorTypeFromId(connection.source) as Operator
|
178 |
]?.every((x) => x !== getOperatorTypeFromId(connection.target));
|
179 |
+
return ret;
|
180 |
};
|