X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3015426750f11fdc97d55a29f2a662e2f272f5d4..90aa25eab8c69ff908873edc72293c8feb4847bf:/src/store/side-panel/side-panel-reducer.ts diff --git a/src/store/side-panel/side-panel-reducer.ts b/src/store/side-panel/side-panel-reducer.ts index 96c975306b..9fc5df1510 100644 --- a/src/store/side-panel/side-panel-reducer.ts +++ b/src/store/side-panel/side-panel-reducer.ts @@ -10,25 +10,29 @@ import { SidePanelItem } from '../../components/side-panel/side-panel'; export type SidePanelState = SidePanelItem[]; const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => { - return actions.match(action, { - TOGGLE_SIDE_PANEL_ITEM_OPEN: () => { - const sidePanel = _.cloneDeep(state); - sidePanel[0].open = !sidePanel[0].open; - return sidePanel; - }, - TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => { - const sidePanel = _.cloneDeep(state); - resetSidePanelActivity(sidePanel); - sidePanel.map(it => { - if (it.id === itemId) { - it.active = true; - } - }); - resetProjectsCollapse(sidePanel); - return sidePanel; - }, - default: () => state - }); + if (state.length === 0) { + return sidePanelData; + } else { + return actions.match(action, { + TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId => state.map(it => itemId === it.id && it.open === false ? {...it, open: true} : {...it, open: false}), + TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => { + const sidePanel = _.cloneDeep(state); + resetSidePanelActivity(sidePanel); + sidePanel.map(it => { + if (it.id === itemId) { + it.active = true; + } + }); + return sidePanel; + }, + RESET_SIDE_PANEL_ACTIVITY: () => { + const sidePanel = _.cloneDeep(state); + resetSidePanelActivity(sidePanel); + return sidePanel; + }, + default: () => state + }); + } }; export const sidePanelData = [ @@ -38,6 +42,8 @@ export const sidePanelData = [ icon: "fas fa-th fa-fw", open: false, active: false, + margin: true, + openAble: true }, { id: "2", @@ -77,10 +83,4 @@ function resetSidePanelActivity(sidePanel: SidePanelItem[]) { } } -function resetProjectsCollapse(sidePanel: SidePanelItem[]) { - if (!sidePanel[0].active) { - sidePanel[0].open = false; - } -} - export default sidePanelReducer;