balibabu
commited on
Commit
·
09aa395
1
Parent(s):
ccccbdd
fix: fixed the issue of error when opening the canvas #918 (#1520)
Browse files### What problem does this PR solve?
fix: fixed the issue of error when opening the canvas #918
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
web/src/pages/flow/canvas/edge/index.tsx
CHANGED
|
@@ -6,8 +6,7 @@ import {
|
|
| 6 |
} from 'reactflow';
|
| 7 |
import useGraphStore from '../../store';
|
| 8 |
|
| 9 |
-
import {
|
| 10 |
-
import { useQueryClient } from '@tanstack/react-query';
|
| 11 |
import { useMemo } from 'react';
|
| 12 |
import styles from './index.less';
|
| 13 |
|
|
@@ -44,12 +43,13 @@ export function ButtonEdge({
|
|
| 44 |
};
|
| 45 |
|
| 46 |
// highlight the nodes that the workflow passes through
|
| 47 |
-
const queryClient = useQueryClient();
|
| 48 |
-
const flowDetail = queryClient.getQueryData<IFlow>(['flowDetail']);
|
|
|
|
| 49 |
|
| 50 |
const graphPath = useMemo(() => {
|
| 51 |
// TODO: this will be called multiple times
|
| 52 |
-
const path = flowDetail?.dsl
|
| 53 |
// The second to last
|
| 54 |
const previousGraphPath: string[] = path.at(-2) ?? [];
|
| 55 |
let graphPath: string[] = path.at(-1) ?? [];
|
|
@@ -59,12 +59,16 @@ export function ButtonEdge({
|
|
| 59 |
graphPath = [previousLatestElement, ...graphPath];
|
| 60 |
}
|
| 61 |
return graphPath;
|
| 62 |
-
}, [flowDetail?.
|
| 63 |
|
| 64 |
const highlightStyle = useMemo(() => {
|
| 65 |
const idx = graphPath.findIndex((x) => x === source);
|
| 66 |
-
if (idx !== -1
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
}
|
| 69 |
return {};
|
| 70 |
}, [source, target, graphPath]);
|
|
|
|
| 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 |
|
|
|
|
| 43 |
};
|
| 44 |
|
| 45 |
// highlight the nodes that the workflow passes through
|
| 46 |
+
// const queryClient = useQueryClient();
|
| 47 |
+
// const flowDetail = queryClient.getQueryData<IFlow>(['flowDetail']);
|
| 48 |
+
const { data: flowDetail } = useFetchFlow();
|
| 49 |
|
| 50 |
const graphPath = useMemo(() => {
|
| 51 |
// TODO: this will be called multiple times
|
| 52 |
+
const path = flowDetail?.dsl?.path ?? [];
|
| 53 |
// The second to last
|
| 54 |
const previousGraphPath: string[] = path.at(-2) ?? [];
|
| 55 |
let graphPath: string[] = path.at(-1) ?? [];
|
|
|
|
| 59 |
graphPath = [previousLatestElement, ...graphPath];
|
| 60 |
}
|
| 61 |
return graphPath;
|
| 62 |
+
}, [flowDetail.dsl?.path]);
|
| 63 |
|
| 64 |
const highlightStyle = useMemo(() => {
|
| 65 |
const idx = graphPath.findIndex((x) => x === source);
|
| 66 |
+
if (idx !== -1) {
|
| 67 |
+
// The set of elements following source
|
| 68 |
+
const slicedGraphPath = graphPath.slice(idx + 1);
|
| 69 |
+
if (slicedGraphPath.some((x) => x === target)) {
|
| 70 |
+
return { strokeWidth: 2, stroke: 'red' };
|
| 71 |
+
}
|
| 72 |
}
|
| 73 |
return {};
|
| 74 |
}, [source, target, graphPath]);
|