From f452cc42664261a6a94383142ac3cac29c418dcf Mon Sep 17 00:00:00 2001 From: afonso Date: Wed, 24 Apr 2024 14:39:19 +0100 Subject: [PATCH] CELE-17 feat: Add workspace id to redux store state --- .../frontend/src/components/RightComponent.tsx | 9 ++++++--- .../src/helpers/initialWorkspacesHelper.ts | 2 +- .../src/layout-manager/layoutManagerFactory.ts | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/applications/visualizer/frontend/src/components/RightComponent.tsx b/applications/visualizer/frontend/src/components/RightComponent.tsx index 2abaeeb2..98d50f5b 100644 --- a/applications/visualizer/frontend/src/components/RightComponent.tsx +++ b/applications/visualizer/frontend/src/components/RightComponent.tsx @@ -8,11 +8,14 @@ import { deactivateNeuron, highlightNeuron, updateViewerSynchronizationStatus } from "../helpers/workspacesHelper.ts"; import {ViewerSynchronizationPair, ViewerType} from "../models.ts"; +import {useSelector} from "react-redux"; export default function RightComponent() { - const {workspaces, currentWorkspaceId, updateWorkspace, datasets, neurons} = useGlobalContext(); - const workspace = workspaces[currentWorkspaceId]; + const {workspaces, updateWorkspace, datasets, neurons} = useGlobalContext(); + const workspaceId = useSelector(state => state.workspaceId); + + const workspace = workspaces[workspaceId]; function withWorkspaceUpdate(modifyWorkspace) { return function (...args) { @@ -112,7 +115,7 @@ export default function RightComponent() { Neurons: - {Array.from(workspace.neurons).map((id) => ( + {Array.from(workspace.neurons).map((id, index) => ( diff --git a/applications/visualizer/frontend/src/helpers/initialWorkspacesHelper.ts b/applications/visualizer/frontend/src/helpers/initialWorkspacesHelper.ts index d1926740..bdc79e4e 100644 --- a/applications/visualizer/frontend/src/helpers/initialWorkspacesHelper.ts +++ b/applications/visualizer/frontend/src/helpers/initialWorkspacesHelper.ts @@ -6,7 +6,7 @@ export const createEmptyWorkspace = (name: string): Workspace => { // Generate a unique ID for the workspace const workspaceId = `workspace-${Date.now()}`; - const {layoutManager, store} = getLayoutManagerAndStore(); + const {layoutManager, store} = getLayoutManagerAndStore(workspaceId); return { id: workspaceId, diff --git a/applications/visualizer/frontend/src/layout-manager/layoutManagerFactory.ts b/applications/visualizer/frontend/src/layout-manager/layoutManagerFactory.ts index fbf05ae6..586abd7e 100644 --- a/applications/visualizer/frontend/src/layout-manager/layoutManagerFactory.ts +++ b/applications/visualizer/frontend/src/layout-manager/layoutManagerFactory.ts @@ -14,6 +14,14 @@ import baseLayout from "./layout.ts"; const storeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; +const workspaceReducer = (state = '', action) => { + switch (action.type) { + case 'SET_WORKSPACE_ID': + return action.payload; + default: + return state; + } +} const initialState = { client: clientInitialState, @@ -24,16 +32,17 @@ const initialState = { const staticReducers = { client: geppettoClientReducer, layout, - widgets + widgets, + workspaceId: workspaceReducer } -const getLayoutManagerAndStore = () => { +const getLayoutManagerAndStore = (workspaceId: string) => { const layoutManager = initLayoutManager(baseLayout, componentMap, undefined, false); const allMiddlewares = [callbacksMiddleware, layoutManager.middleware]; const store = createStore( reducerDecorator(combineReducers({...staticReducers})), - {...initialState}, + {...initialState, workspaceId: workspaceId}, storeEnhancers(applyMiddleware(...allMiddlewares)) ); return {