Skip to content

Commit e6f53b7

Browse files
committed
Provide Node Manager
1 parent 43a282b commit e6f53b7

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/providers/ComponentSpecProvider.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type ReactNode, useCallback, useMemo, useRef, useState } from "react";
22

33
import { type UndoRedo, useUndoRedo } from "@/hooks/useUndoRedo";
4+
import { NodeManager } from "@/nodeManager";
45
import { loadPipelineByName } from "@/services/pipelineService";
56
import { USER_PIPELINES_LIST_NAME } from "@/utils/constants";
67
import { prepareComponentRefForEditor } from "@/utils/prepareComponentRefForEditor";
@@ -44,6 +45,7 @@ interface ComponentSpecContextType {
4445
taskStatusMap: Map<string, string>;
4546
setTaskStatusMap: (taskStatusMap: Map<string, string>) => void;
4647
undoRedo: UndoRedo;
48+
nodeManager: NodeManager;
4749
}
4850

4951
const ComponentSpecContext = createRequiredContext<ComponentSpecContextType>(
@@ -59,6 +61,7 @@ export const ComponentSpecProvider = ({
5961
readOnly?: boolean;
6062
children: ReactNode;
6163
}) => {
64+
const [nodeManager] = useState(() => new NodeManager());
6265
const [componentSpec, setComponentSpec] = useState<ComponentSpec>(
6366
spec ?? EMPTY_GRAPH_COMPONENT_SPEC,
6467
);
@@ -142,15 +145,25 @@ export const ComponentSpecProvider = ({
142145
[componentSpec, readOnly],
143146
);
144147

145-
const updateGraphSpec = useCallback((newGraphSpec: GraphSpec) => {
146-
setComponentSpec((prevSpec) => ({
147-
...prevSpec,
148-
implementation: {
149-
...prevSpec.implementation,
150-
graph: newGraphSpec,
151-
},
152-
}));
153-
}, []);
148+
const updateGraphSpec = useCallback(
149+
(newGraphSpec: GraphSpec) => {
150+
setComponentSpec((prevSpec) => {
151+
const newSpec = {
152+
...prevSpec,
153+
implementation: {
154+
...prevSpec.implementation,
155+
graph: newGraphSpec,
156+
},
157+
};
158+
159+
// Sync node manager with new spec
160+
nodeManager.syncWithComponentSpec(newSpec);
161+
162+
return newSpec;
163+
});
164+
},
165+
[nodeManager],
166+
);
154167

155168
const value = useMemo(
156169
() => ({
@@ -167,6 +180,7 @@ export const ComponentSpecProvider = ({
167180
updateGraphSpec,
168181
setTaskStatusMap,
169182
undoRedo,
183+
nodeManager,
170184
}),
171185
[
172186
componentSpec,
@@ -182,6 +196,7 @@ export const ComponentSpecProvider = ({
182196
updateGraphSpec,
183197
setTaskStatusMap,
184198
undoRedo,
199+
nodeManager,
185200
],
186201
);
187202

0 commit comments

Comments
 (0)