balibabu
commited on
Commit
·
38d5a53
1
Parent(s):
4bfd3a5
feat: highlight the nodes that the workflow passes through #918 (#1423)
Browse files### What problem does this PR solve?
feat: highlight the nodes that the workflow passes through #918
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
web/src/interfaces/database/flow.ts
CHANGED
@@ -6,7 +6,7 @@ export type DSLComponents = Record<string, IOperator>;
|
|
6 |
export interface DSL {
|
7 |
components: DSLComponents;
|
8 |
history: any[];
|
9 |
-
path?: string[];
|
10 |
answer?: any[];
|
11 |
graph?: IGraph;
|
12 |
messages: Message[];
|
|
|
6 |
export interface DSL {
|
7 |
components: DSLComponents;
|
8 |
history: any[];
|
9 |
+
path?: string[][];
|
10 |
answer?: any[];
|
11 |
graph?: IGraph;
|
12 |
messages: Message[];
|
web/src/pages/flow/canvas/edge/index.tsx
CHANGED
@@ -6,6 +6,7 @@ import {
|
|
6 |
} from 'reactflow';
|
7 |
import useGraphStore from '../../store';
|
8 |
|
|
|
9 |
import { useMemo } from 'react';
|
10 |
import styles from './index.less';
|
11 |
|
@@ -17,6 +18,8 @@ export function ButtonEdge({
|
|
17 |
targetY,
|
18 |
sourcePosition,
|
19 |
targetPosition,
|
|
|
|
|
20 |
style = {},
|
21 |
markerEnd,
|
22 |
selected,
|
@@ -32,19 +35,43 @@ export function ButtonEdge({
|
|
32 |
});
|
33 |
|
34 |
const selectedStyle = useMemo(() => {
|
35 |
-
return selected ? { strokeWidth:
|
36 |
}, [selected]);
|
37 |
|
38 |
const onEdgeClick = () => {
|
39 |
deleteEdgeById(id);
|
40 |
};
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
return (
|
43 |
<>
|
44 |
<BaseEdge
|
45 |
path={edgePath}
|
46 |
markerEnd={markerEnd}
|
47 |
-
style={{ ...style, ...selectedStyle }}
|
48 |
/>
|
49 |
<EdgeLabelRenderer>
|
50 |
<div
|
|
|
6 |
} from 'reactflow';
|
7 |
import useGraphStore from '../../store';
|
8 |
|
9 |
+
import { useFetchFlow } from '@/hooks/flow-hooks';
|
10 |
import { useMemo } from 'react';
|
11 |
import styles from './index.less';
|
12 |
|
|
|
18 |
targetY,
|
19 |
sourcePosition,
|
20 |
targetPosition,
|
21 |
+
source,
|
22 |
+
target,
|
23 |
style = {},
|
24 |
markerEnd,
|
25 |
selected,
|
|
|
35 |
});
|
36 |
|
37 |
const selectedStyle = useMemo(() => {
|
38 |
+
return selected ? { strokeWidth: 2, stroke: '#1677ff' } : {};
|
39 |
}, [selected]);
|
40 |
|
41 |
const onEdgeClick = () => {
|
42 |
deleteEdgeById(id);
|
43 |
};
|
44 |
|
45 |
+
// highlight the nodes that the workflow passes through
|
46 |
+
const { data: flowDetail } = useFetchFlow();
|
47 |
+
const graphPath = useMemo(() => {
|
48 |
+
// TODO: this will be called multiple times
|
49 |
+
const path = flowDetail.dsl.path ?? [];
|
50 |
+
// The second to last
|
51 |
+
const previousGraphPath: string[] = path.at(-2) ?? [];
|
52 |
+
let graphPath: string[] = path.at(-1) ?? [];
|
53 |
+
// The last of the second to last article
|
54 |
+
const previousLatestElement = previousGraphPath.at(-1);
|
55 |
+
if (previousGraphPath.length > 0 && previousLatestElement) {
|
56 |
+
graphPath = [previousLatestElement, ...graphPath];
|
57 |
+
}
|
58 |
+
return graphPath;
|
59 |
+
}, [flowDetail.dsl.path]);
|
60 |
+
|
61 |
+
const highlightStyle = useMemo(() => {
|
62 |
+
const idx = graphPath.findIndex((x) => x === source);
|
63 |
+
if (idx !== -1 && graphPath[idx + 1] === target) {
|
64 |
+
return { strokeWidth: 2, stroke: 'red' };
|
65 |
+
}
|
66 |
+
return {};
|
67 |
+
}, [source, target, graphPath]);
|
68 |
+
|
69 |
return (
|
70 |
<>
|
71 |
<BaseEdge
|
72 |
path={edgePath}
|
73 |
markerEnd={markerEnd}
|
74 |
+
style={{ ...style, ...selectedStyle, ...highlightStyle }}
|
75 |
/>
|
76 |
<EdgeLabelRenderer>
|
77 |
<div
|