mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-14 06:26:00 +08:00
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)
### 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)
This commit is contained in:
parent
c8523dc6fd
commit
5a36866cf2
@ -78,9 +78,11 @@ const buildCategorizeObjectFromList = (list: Array<ICategorizeItem>) => {
|
|||||||
export const useHandleFormValuesChange = ({
|
export const useHandleFormValuesChange = ({
|
||||||
onValuesChange,
|
onValuesChange,
|
||||||
form,
|
form,
|
||||||
node,
|
nodeId,
|
||||||
}: IOperatorForm) => {
|
}: IOperatorForm) => {
|
||||||
const edges = useGraphStore((state) => state.edges);
|
const edges = useGraphStore((state) => state.edges);
|
||||||
|
const getNode = useGraphStore((state) => state.getNode);
|
||||||
|
const node = getNode(nodeId);
|
||||||
|
|
||||||
const handleValuesChange = useCallback(
|
const handleValuesChange = useCallback(
|
||||||
(changedValues: any, values: any) => {
|
(changedValues: any, values: any) => {
|
||||||
@ -94,12 +96,13 @@ export const useHandleFormValuesChange = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const items = buildCategorizeListFromObject(
|
||||||
|
get(node, 'data.form.category_description', {}),
|
||||||
|
edges,
|
||||||
|
node,
|
||||||
|
);
|
||||||
form?.setFieldsValue({
|
form?.setFieldsValue({
|
||||||
items: buildCategorizeListFromObject(
|
items,
|
||||||
get(node, 'data.form.category_description', {}),
|
|
||||||
edges,
|
|
||||||
node,
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
}, [form, node, edges]);
|
}, [form, node, edges]);
|
||||||
|
|
||||||
@ -107,19 +110,29 @@ export const useHandleFormValuesChange = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const useHandleToSelectChange = (nodeId?: string) => {
|
export const useHandleToSelectChange = (nodeId?: string) => {
|
||||||
const { addEdge } = useGraphStore((state) => state);
|
const { addEdge, deleteEdgeBySourceAndSourceHandle } = useGraphStore(
|
||||||
|
(state) => state,
|
||||||
|
);
|
||||||
const handleSelectChange = useCallback(
|
const handleSelectChange = useCallback(
|
||||||
(name?: string) => (value?: string) => {
|
(name?: string) => (value?: string) => {
|
||||||
if (nodeId && value && name) {
|
if (nodeId && name) {
|
||||||
addEdge({
|
if (value) {
|
||||||
source: nodeId,
|
addEdge({
|
||||||
target: value,
|
source: nodeId,
|
||||||
sourceHandle: name,
|
target: value,
|
||||||
targetHandle: null,
|
sourceHandle: name,
|
||||||
});
|
targetHandle: null,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// clear selected value
|
||||||
|
deleteEdgeBySourceAndSourceHandle({
|
||||||
|
source: nodeId,
|
||||||
|
sourceHandle: name,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[addEdge, nodeId],
|
[addEdge, nodeId, deleteEdgeBySourceAndSourceHandle],
|
||||||
);
|
);
|
||||||
|
|
||||||
return { handleSelectChange };
|
return { handleSelectChange };
|
||||||
|
@ -10,7 +10,7 @@ const CategorizeForm = ({ form, onValuesChange, node }: IOperatorForm) => {
|
|||||||
const { t } = useTranslate('flow');
|
const { t } = useTranslate('flow');
|
||||||
const { handleValuesChange } = useHandleFormValuesChange({
|
const { handleValuesChange } = useHandleFormValuesChange({
|
||||||
form,
|
form,
|
||||||
node,
|
nodeId: node?.id,
|
||||||
onValuesChange,
|
onValuesChange,
|
||||||
});
|
});
|
||||||
useSetLlmSetting(form);
|
useSetLlmSetting(form);
|
||||||
|
@ -101,13 +101,7 @@ export const CategorizeAnchorPointPositions = [
|
|||||||
// key is the source of the edge, value is the target of the edge
|
// key is the source of the edge, value is the target of the edge
|
||||||
// no connection lines are allowed between key and value
|
// no connection lines are allowed between key and value
|
||||||
export const RestrictedUpstreamMap = {
|
export const RestrictedUpstreamMap = {
|
||||||
[Operator.Begin]: [
|
[Operator.Begin]: [],
|
||||||
Operator.Begin,
|
|
||||||
Operator.Answer,
|
|
||||||
Operator.Categorize,
|
|
||||||
Operator.Generate,
|
|
||||||
Operator.Retrieval,
|
|
||||||
],
|
|
||||||
[Operator.Categorize]: [Operator.Begin, Operator.Categorize, Operator.Answer],
|
[Operator.Categorize]: [Operator.Begin, Operator.Categorize, Operator.Answer],
|
||||||
[Operator.Answer]: [],
|
[Operator.Answer]: [],
|
||||||
[Operator.Retrieval]: [],
|
[Operator.Retrieval]: [],
|
||||||
|
@ -10,6 +10,7 @@ export interface IOperatorForm {
|
|||||||
onValuesChange?(changedValues: any, values: any): void;
|
onValuesChange?(changedValues: any, values: any): void;
|
||||||
form?: FormInstance;
|
form?: FormInstance;
|
||||||
node?: Node<NodeData>;
|
node?: Node<NodeData>;
|
||||||
|
nodeId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IBeginForm {
|
export interface IBeginForm {
|
||||||
|
@ -37,7 +37,7 @@ export const dsl = {
|
|||||||
graph: {
|
graph: {
|
||||||
nodes: [
|
nodes: [
|
||||||
{
|
{
|
||||||
id: 'begin',
|
id: 'Begin',
|
||||||
type: 'beginNode',
|
type: 'beginNode',
|
||||||
position: {
|
position: {
|
||||||
x: 50,
|
x: 50,
|
||||||
|
@ -35,7 +35,7 @@ export type RFState = {
|
|||||||
updateNodeForm: (nodeId: string, values: any) => void;
|
updateNodeForm: (nodeId: string, values: any) => void;
|
||||||
onSelectionChange: OnSelectionChangeFunc;
|
onSelectionChange: OnSelectionChangeFunc;
|
||||||
addNode: (nodes: Node) => void;
|
addNode: (nodes: Node) => void;
|
||||||
getNode: (id: string) => Node | undefined;
|
getNode: (id?: string) => Node | undefined;
|
||||||
addEdge: (connection: Connection) => void;
|
addEdge: (connection: Connection) => void;
|
||||||
getEdge: (id: string) => Edge | undefined;
|
getEdge: (id: string) => Edge | undefined;
|
||||||
deletePreviousEdgeOfClassificationNode: (connection: Connection) => void;
|
deletePreviousEdgeOfClassificationNode: (connection: Connection) => void;
|
||||||
@ -43,7 +43,7 @@ export type RFState = {
|
|||||||
deleteEdge: () => void;
|
deleteEdge: () => void;
|
||||||
deleteEdgeById: (id: string) => void;
|
deleteEdgeById: (id: string) => void;
|
||||||
deleteNodeById: (id: string) => void;
|
deleteNodeById: (id: string) => void;
|
||||||
deleteEdgeBySourceAndTarget: (source: string, target: string) => void;
|
deleteEdgeBySourceAndSourceHandle: (connection: Partial<Connection>) => void;
|
||||||
findNodeByName: (operatorName: Operator) => Node | undefined;
|
findNodeByName: (operatorName: Operator) => Node | undefined;
|
||||||
updateMutableNodeFormItem: (id: string, field: string, value: any) => void;
|
updateMutableNodeFormItem: (id: string, field: string, value: any) => void;
|
||||||
};
|
};
|
||||||
@ -87,7 +87,7 @@ const useGraphStore = create<RFState>()(
|
|||||||
addNode: (node: Node) => {
|
addNode: (node: Node) => {
|
||||||
set({ nodes: get().nodes.concat(node) });
|
set({ nodes: get().nodes.concat(node) });
|
||||||
},
|
},
|
||||||
getNode: (id: string) => {
|
getNode: (id?: string) => {
|
||||||
return get().nodes.find((x) => x.id === id);
|
return get().nodes.find((x) => x.id === id);
|
||||||
},
|
},
|
||||||
addEdge: (connection: Connection) => {
|
addEdge: (connection: Connection) => {
|
||||||
@ -150,12 +150,17 @@ const useGraphStore = create<RFState>()(
|
|||||||
edges: edges.filter((edge) => edge.id !== id),
|
edges: edges.filter((edge) => edge.id !== id),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
deleteEdgeBySourceAndTarget: (source: string, target: string) => {
|
deleteEdgeBySourceAndSourceHandle: ({
|
||||||
|
source,
|
||||||
|
sourceHandle,
|
||||||
|
}: Partial<Connection>) => {
|
||||||
const { edges } = get();
|
const { edges } = get();
|
||||||
|
const nextEdges = edges.filter(
|
||||||
|
(edge) =>
|
||||||
|
edge.source !== source || edge.sourceHandle !== sourceHandle,
|
||||||
|
);
|
||||||
set({
|
set({
|
||||||
edges: edges.filter(
|
edges: nextEdges,
|
||||||
(edge) => edge.target !== target && edge.source !== source,
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
deleteNodeById: (id: string) => {
|
deleteNodeById: (id: string) => {
|
||||||
|
@ -173,7 +173,8 @@ export const getOperatorTypeFromId = (id: string | null) => {
|
|||||||
|
|
||||||
// restricted lines cannot be connected successfully.
|
// restricted lines cannot be connected successfully.
|
||||||
export const isValidConnection = (connection: Connection) => {
|
export const isValidConnection = (connection: Connection) => {
|
||||||
return RestrictedUpstreamMap[
|
const ret = RestrictedUpstreamMap[
|
||||||
getOperatorTypeFromId(connection.source) as Operator
|
getOperatorTypeFromId(connection.source) as Operator
|
||||||
]?.every((x) => x !== getOperatorTypeFromId(connection.target));
|
]?.every((x) => x !== getOperatorTypeFromId(connection.target));
|
||||||
|
return ret;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user