From 7d4a78e4704f904e5555302b54ee9865c6d3c638 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 3 Dec 2023 20:27:40 +1100 Subject: [PATCH] fix(ui): fix circular dependency --- .../listeners/workflowLoadRequested.ts | 2 +- .../frontend/web/src/features/nodes/store/actions.ts | 5 +++++ .../web/src/features/nodes/store/nodesSlice.ts | 2 +- .../web/src/features/nodes/store/workflowSlice.ts | 12 ++++++------ .../workflowLibrary/hooks/useSaveWorkflow.ts | 2 +- .../workflowLibrary/hooks/useSaveWorkflowAs.ts | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/workflowLoadRequested.ts b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/workflowLoadRequested.ts index 287addf18c..3dff9a906b 100644 --- a/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/workflowLoadRequested.ts +++ b/invokeai/frontend/web/src/app/store/middleware/listenerMiddleware/listeners/workflowLoadRequested.ts @@ -1,7 +1,7 @@ import { logger } from 'app/logging/logger'; import { parseify } from 'common/util/serialize'; import { workflowLoadRequested } from 'features/nodes/store/actions'; -import { workflowLoaded } from 'features/nodes/store/workflowSlice'; +import { workflowLoaded } from 'features/nodes/store/actions'; import { $flow } from 'features/nodes/store/reactFlowInstance'; import { WorkflowMigrationError, diff --git a/invokeai/frontend/web/src/features/nodes/store/actions.ts b/invokeai/frontend/web/src/features/nodes/store/actions.ts index 9952bb300f..6e2e4c9699 100644 --- a/invokeai/frontend/web/src/features/nodes/store/actions.ts +++ b/invokeai/frontend/web/src/features/nodes/store/actions.ts @@ -1,4 +1,5 @@ import { createAction, isAnyOf } from '@reduxjs/toolkit'; +import { WorkflowV2 } from 'features/nodes/types/workflow'; import { Graph } from 'services/api/types'; export const textToImageGraphBuilt = createAction( @@ -25,3 +26,7 @@ export const workflowLoadRequested = createAction<{ export const updateAllNodesRequested = createAction( 'nodes/updateAllNodesRequested' ); + +export const workflowLoaded = createAction( + 'workflow/workflowLoaded' +); diff --git a/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts b/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts index 0a6a2fd86b..12058cd68f 100644 --- a/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts +++ b/invokeai/frontend/web/src/features/nodes/store/nodesSlice.ts @@ -1,5 +1,5 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; -import { workflowLoaded } from 'features/nodes/store/workflowSlice'; +import { workflowLoaded } from 'features/nodes/store/actions'; import { SHARED_NODE_PROPERTIES } from 'features/nodes/types/constants'; import { BoardFieldValue, diff --git a/invokeai/frontend/web/src/features/nodes/store/workflowSlice.ts b/invokeai/frontend/web/src/features/nodes/store/workflowSlice.ts index c2dbbe56ab..9d207b9ca7 100644 --- a/invokeai/frontend/web/src/features/nodes/store/workflowSlice.ts +++ b/invokeai/frontend/web/src/features/nodes/store/workflowSlice.ts @@ -1,8 +1,8 @@ import { PayloadAction, createSlice } from '@reduxjs/toolkit'; +import { workflowLoaded } from 'features/nodes/store/actions'; import { nodeEditorReset, nodesDeleted } from 'features/nodes/store/nodesSlice'; import { WorkflowsState as WorkflowState } from 'features/nodes/store/types'; import { FieldIdentifier } from 'features/nodes/types/field'; -import { WorkflowV2 } from 'features/nodes/types/workflow'; import { cloneDeep, isEqual, uniqBy } from 'lodash-es'; export const initialWorkflowState: WorkflowState = { @@ -62,13 +62,14 @@ const workflowSlice = createSlice({ workflowIDChanged: (state, action: PayloadAction) => { state.id = action.payload; }, - workflowLoaded: (state, action: PayloadAction) => { - const { nodes: _nodes, edges: _edges, ...workflow } = action.payload; - return cloneDeep(workflow); - }, workflowReset: () => cloneDeep(initialWorkflowState), }, extraReducers: (builder) => { + builder.addCase(workflowLoaded, (state, action) => { + const { nodes: _nodes, edges: _edges, ...workflow } = action.payload; + return cloneDeep(workflow); + }); + builder.addCase(nodesDeleted, (state, action) => { action.payload.forEach((node) => { state.exposedFields = state.exposedFields.filter( @@ -92,7 +93,6 @@ export const { workflowVersionChanged, workflowContactChanged, workflowIDChanged, - workflowLoaded, workflowReset, } = workflowSlice.actions; diff --git a/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflow.ts b/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflow.ts index 9867832706..a177706f0d 100644 --- a/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflow.ts +++ b/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflow.ts @@ -1,7 +1,7 @@ import { useAppToaster } from 'app/components/Toaster'; import { useAppDispatch } from 'app/store/storeHooks'; import { useWorkflow } from 'features/nodes/hooks/useWorkflow'; -import { workflowLoaded } from 'features/nodes/store/workflowSlice'; +import { workflowLoaded } from 'features/nodes/store/actions'; import { zWorkflowV2 } from 'features/nodes/types/workflow'; import { getWorkflowCopyName } from 'features/workflowLibrary/util/getWorkflowCopyName'; import { useCallback } from 'react'; diff --git a/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflowAs.ts b/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflowAs.ts index d25d416957..e0b08ed985 100644 --- a/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflowAs.ts +++ b/invokeai/frontend/web/src/features/workflowLibrary/hooks/useSaveWorkflowAs.ts @@ -1,7 +1,7 @@ import { useAppToaster } from 'app/components/Toaster'; import { useAppDispatch } from 'app/store/storeHooks'; import { useWorkflow } from 'features/nodes/hooks/useWorkflow'; -import { workflowLoaded } from 'features/nodes/store/workflowSlice'; +import { workflowLoaded } from 'features/nodes/store/actions'; import { zWorkflowV2 } from 'features/nodes/types/workflow'; import { useCallback } from 'react'; import { useTranslation } from 'react-i18next';