Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/providers/ComponentSpecProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { type ReactNode, useCallback, useMemo, useRef, useState } from "react";
import {
type ReactNode,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";

import { type UndoRedo, useUndoRedo } from "@/hooks/useUndoRedo";
import { NodeManager } from "@/nodeManager";
import { loadPipelineByName } from "@/services/pipelineService";
import { USER_PIPELINES_LIST_NAME } from "@/utils/constants";
import { prepareComponentRefForEditor } from "@/utils/prepareComponentRefForEditor";
Expand Down Expand Up @@ -56,6 +64,8 @@ interface ComponentSpecContextType {
navigateBack: () => void;
navigateToPath: (targetPath: string[]) => void;
canNavigateBack: boolean;

nodeManager: NodeManager;
}

const ComponentSpecContext = createRequiredContext<ComponentSpecContextType>(
Expand All @@ -71,6 +81,7 @@ export const ComponentSpecProvider = ({
readOnly?: boolean;
children: ReactNode;
}) => {
const [nodeManager] = useState(() => new NodeManager());
const [componentSpec, setComponentSpec] = useState<ComponentSpec>(
spec ?? EMPTY_GRAPH_COMPONENT_SPEC,
);
Expand Down Expand Up @@ -214,6 +225,10 @@ export const ComponentSpecProvider = ({

const canNavigateBack = currentSubgraphPath.length > 1;

useEffect(() => {
nodeManager.syncWithComponentSpec(componentSpec);
}, [componentSpec, nodeManager]);

const value = useMemo(
() => ({
componentSpec,
Expand All @@ -237,6 +252,8 @@ export const ComponentSpecProvider = ({
navigateBack,
navigateToPath,
canNavigateBack,

nodeManager,
}),
[
componentSpec,
Expand All @@ -260,6 +277,8 @@ export const ComponentSpecProvider = ({
navigateBack,
navigateToPath,
canNavigateBack,

nodeManager,
],
);

Expand Down