Skip to content

Commit 1e14b54

Browse files
Cristhianzlcarlosrcoelho
authored andcommitted
feat: Add stopNodeId tracking for improved validation and edge control (#9867)
✨ (flowSidebarComponent/index.tsx): Remove unnecessary console.log statement ♻️ (flowStore.ts): Refactor useFlowStore to include a stopNodeId property and setter function for better state management and flow control. Co-authored-by: Carlos Coelho <80289056+carlosrcoelho@users.noreply.github.com>
1 parent 020ff24 commit 1e14b54

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/frontend/src/pages/FlowPage/components/flowSidebarComponent/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,17 +545,17 @@ export function FlowSidebarComponent({ isLoading }: FlowSidebarComponentProps) {
545545

546546
const filterDescription =
547547
getFilterComponent !== ""
548-
? (baseData[category][component]?.display_name ?? "")
549-
: (filterType?.type ?? "");
548+
? baseData[category][component]?.display_name ?? ""
549+
: filterType?.type ?? "";
550550

551551
const filterName =
552552
getFilterComponent !== ""
553553
? "Component"
554554
: filterType
555-
? filterType.source
556-
? "Input"
557-
: "Output"
558-
: "";
555+
? filterType.source
556+
? "Input"
557+
: "Output"
558+
: "";
559559

560560
const resetFilters = useCallback(() => {
561561
setFilterEdge([]);

src/frontend/src/stores/flowStore.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
687687
nodesToValidate = downstream.nodes;
688688
edgesToValidate = downstream.edges;
689689
} else if (stopNodeId) {
690+
get().setStopNodeId(stopNodeId);
690691
const upstream = getConnectedSubgraph(
691692
stopNodeId,
692693
get().nodes,
@@ -696,6 +697,9 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
696697
nodesToValidate = upstream.nodes;
697698
edgesToValidate = upstream.edges;
698699
}
700+
if (!stopNodeId) {
701+
get().setStopNodeId(undefined);
702+
}
699703

700704
for (const edge of edgesToValidate) {
701705
const errorsEdge = validateEdge(edge, nodesToValidate, edgesToValidate);
@@ -820,6 +824,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
820824
get().updateBuildStatus([vertexBuildData.id], status);
821825
}
822826
}
827+
823828
await buildFlowVerticesWithFallback({
824829
session,
825830
input_value,
@@ -829,7 +834,6 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
829834
stopNodeId,
830835
onGetOrderSuccess: () => {},
831836
onBuildComplete: (allNodesValid) => {
832-
const _nodeId = startNodeId || stopNodeId;
833837
if (!silent) {
834838
if (allNodesValid) {
835839
get().setBuildInfo({ success: true });
@@ -911,10 +915,12 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
911915
},
912916
updateEdgesRunningByNodes: (ids: string[], running: boolean) => {
913917
const edges = get().edges;
918+
914919
const newEdges = edges.map((edge) => {
915920
if (
916921
edge.data?.sourceHandle &&
917-
ids.includes(edge.data.sourceHandle.id ?? "")
922+
ids.includes(edge.data.sourceHandle.id ?? "") &&
923+
edge.data.sourceHandle.id !== get().stopNodeId
918924
) {
919925
edge.animated = running;
920926
edge.className = running ? "running" : "";
@@ -938,7 +944,6 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
938944
resolve();
939945
});
940946
},
941-
942947
updateVerticesBuild: (
943948
vertices: {
944949
verticesIds: string[];
@@ -1095,6 +1100,10 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
10951100
set({ newChatOnPlayground: newChat });
10961101
},
10971102
newChatOnPlayground: false,
1103+
stopNodeId: undefined,
1104+
setStopNodeId: (nodeId: string | undefined) => {
1105+
set({ stopNodeId: nodeId });
1106+
},
10981107
}));
10991108

11001109
export default useFlowStore;

src/frontend/src/types/zustand/flow/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,6 @@ export type FlowStoreType = {
293293
setHelperLineEnabled: (helperLineEnabled: boolean) => void;
294294
newChatOnPlayground: boolean;
295295
setNewChatOnPlayground: (newChat: boolean) => void;
296+
stopNodeId: string | undefined;
297+
setStopNodeId: (nodeId: string | undefined) => void;
296298
};

0 commit comments

Comments
 (0)