From 2ea696934be0862711eac74da28ab9a0f89b66ee Mon Sep 17 00:00:00 2001 From: balibabu Date: Mon, 15 Jul 2024 19:17:03 +0800 Subject: [PATCH] fix: fixed the issue of error when opening the canvas #918 (#1520) ### 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 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/web/src/pages/flow/canvas/edge/index.tsx b/web/src/pages/flow/canvas/edge/index.tsx index 9e5bf20d7..9ef5250cf 100644 --- a/web/src/pages/flow/canvas/edge/index.tsx +++ b/web/src/pages/flow/canvas/edge/index.tsx @@ -6,8 +6,7 @@ import { } from 'reactflow'; import useGraphStore from '../../store'; -import { IFlow } from '@/interfaces/database/flow'; -import { useQueryClient } from '@tanstack/react-query'; +import { useFetchFlow } from '@/hooks/flow-hooks'; import { useMemo } from 'react'; import styles from './index.less'; @@ -44,12 +43,13 @@ export function ButtonEdge({ }; // highlight the nodes that the workflow passes through - const queryClient = useQueryClient(); - const flowDetail = queryClient.getQueryData(['flowDetail']); + // const queryClient = useQueryClient(); + // const flowDetail = queryClient.getQueryData(['flowDetail']); + const { data: flowDetail } = useFetchFlow(); const graphPath = useMemo(() => { // TODO: this will be called multiple times - const path = flowDetail?.dsl.path ?? []; + const path = flowDetail?.dsl?.path ?? []; // The second to last const previousGraphPath: string[] = path.at(-2) ?? []; let graphPath: string[] = path.at(-1) ?? []; @@ -59,12 +59,16 @@ export function ButtonEdge({ graphPath = [previousLatestElement, ...graphPath]; } return graphPath; - }, [flowDetail?.dsl.path]); + }, [flowDetail.dsl?.path]); const highlightStyle = useMemo(() => { const idx = graphPath.findIndex((x) => x === source); - if (idx !== -1 && graphPath[idx + 1] === target) { - return { strokeWidth: 2, stroke: 'red' }; + if (idx !== -1) { + // The set of elements following source + const slicedGraphPath = graphPath.slice(idx + 1); + if (slicedGraphPath.some((x) => x === target)) { + return { strokeWidth: 2, stroke: 'red' }; + } } return {}; }, [source, target, graphPath]);