mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-06-04 11:24:00 +08:00
### 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)
This commit is contained in:
parent
c889ef6363
commit
f5dc94fc85
@ -6,7 +6,7 @@ export type DSLComponents = Record<string, IOperator>;
|
|||||||
export interface DSL {
|
export interface DSL {
|
||||||
components: DSLComponents;
|
components: DSLComponents;
|
||||||
history: any[];
|
history: any[];
|
||||||
path?: string[];
|
path?: string[][];
|
||||||
answer?: any[];
|
answer?: any[];
|
||||||
graph?: IGraph;
|
graph?: IGraph;
|
||||||
messages: Message[];
|
messages: Message[];
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
} from 'reactflow';
|
} from 'reactflow';
|
||||||
import useGraphStore from '../../store';
|
import useGraphStore from '../../store';
|
||||||
|
|
||||||
|
import { useFetchFlow } from '@/hooks/flow-hooks';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
|
|
||||||
@ -17,6 +18,8 @@ export function ButtonEdge({
|
|||||||
targetY,
|
targetY,
|
||||||
sourcePosition,
|
sourcePosition,
|
||||||
targetPosition,
|
targetPosition,
|
||||||
|
source,
|
||||||
|
target,
|
||||||
style = {},
|
style = {},
|
||||||
markerEnd,
|
markerEnd,
|
||||||
selected,
|
selected,
|
||||||
@ -32,19 +35,43 @@ export function ButtonEdge({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const selectedStyle = useMemo(() => {
|
const selectedStyle = useMemo(() => {
|
||||||
return selected ? { strokeWidth: 1, stroke: '#1677ff' } : {};
|
return selected ? { strokeWidth: 2, stroke: '#1677ff' } : {};
|
||||||
}, [selected]);
|
}, [selected]);
|
||||||
|
|
||||||
const onEdgeClick = () => {
|
const onEdgeClick = () => {
|
||||||
deleteEdgeById(id);
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<BaseEdge
|
<BaseEdge
|
||||||
path={edgePath}
|
path={edgePath}
|
||||||
markerEnd={markerEnd}
|
markerEnd={markerEnd}
|
||||||
style={{ ...style, ...selectedStyle }}
|
style={{ ...style, ...selectedStyle, ...highlightStyle }}
|
||||||
/>
|
/>
|
||||||
<EdgeLabelRenderer>
|
<EdgeLabelRenderer>
|
||||||
<div
|
<div
|
||||||
|
Loading…
x
Reference in New Issue
Block a user