Skip to content

Commit

Permalink
CELE-17 feat: Add workspace id to redux store state
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsobspinto committed Apr 24, 2024
1 parent 124054a commit f452cc4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -112,7 +115,7 @@ export default function RightComponent() {

<Typography variant="subtitle2">Neurons:</Typography>
<List>
{Array.from(workspace.neurons).map((id) => (
{Array.from(workspace.neurons).map((id, index) => (
<ListItem key={id}>
<ListItemText primary={`Label: ${neurons[id]?.name || "Not found"}`}/>
</ListItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit f452cc4

Please sign in to comment.