Simplify side panel reducer
authorDaniel Kos <daniel.kos@contractors.roche.com>
Fri, 17 Aug 2018 11:39:22 +0000 (13:39 +0200)
committerDaniel Kos <daniel.kos@contractors.roche.com>
Fri, 17 Aug 2018 11:39:22 +0000 (13:39 +0200)
Feature #13986

Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos@contractors.roche.com>

src/store/side-panel/side-panel-reducer.ts

index bda6965e2d7e65597a3cea46690df4e0275ddc8b..5a45d29590f761c48c6f4515105b66d180777b5b 100644 (file)
@@ -2,7 +2,6 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as _ from "lodash";
 import { sidePanelActions, SidePanelAction } from './side-panel-action';
 import { SidePanelItem } from '~/components/side-panel/side-panel';
 import { ProjectsIcon, ShareMeIcon, WorkflowIcon, RecentIcon, FavoriteIcon, TrashIcon } from "~/components/icon/icon";
@@ -18,30 +17,15 @@ import { columns as favoritePanelColumns } from "../../views/favorite-panel/favo
 export type SidePanelState = SidePanelItem[];
 
 export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
-    if (state.length === 0) {
-        return sidePanelData;
-    } else {
-        return sidePanelActions.match(action, {
-            TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId =>
-                state.map(it => ({...it, open: itemId === it.id && it.open === false})),
-            TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
-                const sidePanel = _.cloneDeep(state);
-                resetSidePanelActivity(sidePanel);
-                sidePanel.forEach(it => {
-                    if (it.id === itemId) {
-                        it.active = true;
-                    }
-                });
-                return sidePanel;
-            },
-            RESET_SIDE_PANEL_ACTIVITY: () => {
-                const sidePanel = _.cloneDeep(state);
-                resetSidePanelActivity(sidePanel);
-                return sidePanel;
-            },
-            default: () => state
-        });
-    }
+    return sidePanelActions.match(action, {
+        TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId =>
+            state.map(it => ({...it, open: itemId === it.id && it.open === false})),
+        TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId =>
+            state.map(it => ({...it, active: it.id === itemId})),
+        RESET_SIDE_PANEL_ACTIVITY: () =>
+            state.map(it => ({...it, active: false })),
+        default: () => state
+    });
 };
 
 export enum SidePanelIdentifiers {
@@ -107,9 +91,3 @@ export const sidePanelData = [
         active: false,
     }
 ];
-
-function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
-    for (const t of sidePanel) {
-        t.active = false;
-    }
-}