mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 01:08:59 +08:00
feat: delete the edge on the classification node anchor when the anch… (#1297)
### What problem does this PR solve? feat: delete the edge on the classification node anchor when the anchor is connected to other nodes #918 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
fbb8cbfc67
commit
5a1e01d96f
@ -19,6 +19,7 @@ import { create } from 'zustand';
|
|||||||
import { devtools } from 'zustand/middleware';
|
import { devtools } from 'zustand/middleware';
|
||||||
import { Operator } from './constant';
|
import { Operator } from './constant';
|
||||||
import { NodeData } from './interface';
|
import { NodeData } from './interface';
|
||||||
|
import { getOperatorTypeFromId } from './utils';
|
||||||
|
|
||||||
export type RFState = {
|
export type RFState = {
|
||||||
nodes: Node<NodeData>[];
|
nodes: Node<NodeData>[];
|
||||||
@ -35,6 +36,7 @@ export type RFState = {
|
|||||||
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;
|
||||||
|
deletePreviousEdgeOfClassificationNode: (connection: Connection) => void;
|
||||||
duplicateNode: (id: string) => void;
|
duplicateNode: (id: string) => void;
|
||||||
deleteEdge: () => void;
|
deleteEdge: () => void;
|
||||||
deleteEdgeById: (id: string) => void;
|
deleteEdgeById: (id: string) => void;
|
||||||
@ -66,6 +68,7 @@ const useGraphStore = create<RFState>()(
|
|||||||
set({
|
set({
|
||||||
edges: addEdge(connection, get().edges),
|
edges: addEdge(connection, get().edges),
|
||||||
});
|
});
|
||||||
|
get().deletePreviousEdgeOfClassificationNode(connection);
|
||||||
},
|
},
|
||||||
onSelectionChange: ({ nodes, edges }: OnSelectionChangeParams) => {
|
onSelectionChange: ({ nodes, edges }: OnSelectionChangeParams) => {
|
||||||
set({
|
set({
|
||||||
@ -90,6 +93,23 @@ const useGraphStore = create<RFState>()(
|
|||||||
edges: addEdge(connection, get().edges),
|
edges: addEdge(connection, get().edges),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
deletePreviousEdgeOfClassificationNode: (connection: Connection) => {
|
||||||
|
// Delete the edge on the classification node anchor when the anchor is connected to other nodes
|
||||||
|
const { edges } = get();
|
||||||
|
if (getOperatorTypeFromId(connection.source) === Operator.Categorize) {
|
||||||
|
const previousEdge = edges.find(
|
||||||
|
(x) =>
|
||||||
|
x.source === connection.source &&
|
||||||
|
x.sourceHandle === connection.sourceHandle &&
|
||||||
|
x.target !== connection.target,
|
||||||
|
);
|
||||||
|
if (previousEdge) {
|
||||||
|
set({
|
||||||
|
edges: edges.filter((edge) => edge !== previousEdge),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
// addOnlyOneEdgeBetweenTwoNodes: (connection: Connection) => {
|
// addOnlyOneEdgeBetweenTwoNodes: (connection: Connection) => {
|
||||||
|
|
||||||
// },
|
// },
|
||||||
|
@ -167,13 +167,13 @@ export const buildDslComponentsByGraph = (
|
|||||||
return components;
|
return components;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getOperatorType = (id: string | null) => {
|
export const getOperatorTypeFromId = (id: string | null) => {
|
||||||
return id?.split(':')[0] as Operator | undefined;
|
return id?.split(':')[0] as Operator | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
// restricted lines cannot be connected successfully.
|
// restricted lines cannot be connected successfully.
|
||||||
export const isValidConnection = (connection: Connection) => {
|
export const isValidConnection = (connection: Connection) => {
|
||||||
return RestrictedUpstreamMap[
|
return RestrictedUpstreamMap[
|
||||||
getOperatorType(connection.source) as Operator
|
getOperatorTypeFromId(connection.source) as Operator
|
||||||
]?.every((x) => x !== getOperatorType(connection.target));
|
]?.every((x) => x !== getOperatorTypeFromId(connection.target));
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user