Skip to content

Commit

Permalink
feat: highlight the nodes that the workflow passes through #918 (#1423)
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
cike8899 authored Jul 8, 2024
1 parent c889ef6 commit f5dc94f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion web/src/interfaces/database/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type DSLComponents = Record<string, IOperator>;
export interface DSL {
components: DSLComponents;
history: any[];
path?: string[];
path?: string[][];
answer?: any[];
graph?: IGraph;
messages: Message[];
Expand Down
31 changes: 29 additions & 2 deletions web/src/pages/flow/canvas/edge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from 'reactflow';
import useGraphStore from '../../store';

import { useFetchFlow } from '@/hooks/flow-hooks';
import { useMemo } from 'react';
import styles from './index.less';

Expand All @@ -17,6 +18,8 @@ export function ButtonEdge({
targetY,
sourcePosition,
targetPosition,
source,
target,
style = {},
markerEnd,
selected,
Expand All @@ -32,19 +35,43 @@ export function ButtonEdge({
});

const selectedStyle = useMemo(() => {
return selected ? { strokeWidth: 1, stroke: '#1677ff' } : {};
return selected ? { strokeWidth: 2, stroke: '#1677ff' } : {};
}, [selected]);

const onEdgeClick = () => {
deleteEdgeById(id);
};

// highlight the nodes that the workflow passes through
const { data: flowDetail } = useFetchFlow();
const graphPath = useMemo(() => {
// TODO: this will be called multiple times
const path = flowDetail.dsl.path ?? [];
// The second to last
const previousGraphPath: string[] = path.at(-2) ?? [];
let graphPath: string[] = path.at(-1) ?? [];
// The last of the second to last article
const previousLatestElement = previousGraphPath.at(-1);
if (previousGraphPath.length > 0 && previousLatestElement) {
graphPath = [previousLatestElement, ...graphPath];
}
return graphPath;
}, [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' };
}
return {};
}, [source, target, graphPath]);

return (
<>
<BaseEdge
path={edgePath}
markerEnd={markerEnd}
style={{ ...style, ...selectedStyle }}
style={{ ...style, ...selectedStyle, ...highlightStyle }}
/>
<EdgeLabelRenderer>
<div
Expand Down

0 comments on commit f5dc94f

Please sign in to comment.