Skip to content

Commit baed2e5

Browse files
committed
Provide Node Manager
1 parent d97b96e commit baed2e5

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/providers/ComponentSpecProvider.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
import { type ReactNode, useCallback, useMemo, useRef, useState } from "react";
1+
import {
2+
type ReactNode,
3+
useCallback,
4+
useEffect,
5+
useMemo,
6+
useRef,
7+
useState,
8+
} from "react";
29

310
import { type UndoRedo, useUndoRedo } from "@/hooks/useUndoRedo";
11+
import { NodeManager } from "@/nodeManager";
412
import { loadPipelineByName } from "@/services/pipelineService";
513
import { USER_PIPELINES_LIST_NAME } from "@/utils/constants";
614
import { prepareComponentRefForEditor } from "@/utils/prepareComponentRefForEditor";
@@ -44,6 +52,7 @@ interface ComponentSpecContextType {
4452
taskStatusMap: Map<string, string>;
4553
setTaskStatusMap: (taskStatusMap: Map<string, string>) => void;
4654
undoRedo: UndoRedo;
55+
nodeManager: NodeManager;
4756
}
4857

4958
const ComponentSpecContext = createRequiredContext<ComponentSpecContextType>(
@@ -59,6 +68,7 @@ export const ComponentSpecProvider = ({
5968
readOnly?: boolean;
6069
children: ReactNode;
6170
}) => {
71+
const [nodeManager] = useState(() => new NodeManager());
6272
const [componentSpec, setComponentSpec] = useState<ComponentSpec>(
6373
spec ?? EMPTY_GRAPH_COMPONENT_SPEC,
6474
);
@@ -152,6 +162,10 @@ export const ComponentSpecProvider = ({
152162
}));
153163
}, []);
154164

165+
useEffect(() => {
166+
nodeManager.syncWithComponentSpec(componentSpec);
167+
}, [componentSpec, nodeManager]);
168+
155169
const value = useMemo(
156170
() => ({
157171
componentSpec,
@@ -167,6 +181,7 @@ export const ComponentSpecProvider = ({
167181
updateGraphSpec,
168182
setTaskStatusMap,
169183
undoRedo,
184+
nodeManager,
170185
}),
171186
[
172187
componentSpec,
@@ -182,6 +197,7 @@ export const ComponentSpecProvider = ({
182197
updateGraphSpec,
183198
setTaskStatusMap,
184199
undoRedo,
200+
nodeManager,
185201
],
186202
);
187203

0 commit comments

Comments
 (0)