Add typescript paths to top level folders
[arvados-workbench2.git] / src / store / side-panel / side-panel-reducer.ts
index 9fc5df1510e37b0f72a86f229c56ca45c0e7c93c..fe0626340d3740695539dd669e3c3ff47debc9bb 100644 (file)
@@ -3,22 +3,26 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as _ from "lodash";
-
-import actions, { SidePanelAction } from './side-panel-action';
-import { SidePanelItem } from '../../components/side-panel/side-panel';
+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";
+import { Dispatch } from "redux";
+import { push } from "react-router-redux";
+import { favoritePanelActions } from "../favorite-panel/favorite-panel-action";
 
 export type SidePanelState = SidePanelItem[];
 
-const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
+export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
     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}),
+        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.map(it => {
+                sidePanel.forEach(it => {
                     if (it.id === itemId) {
                         it.active = true;
                     }
@@ -35,44 +39,58 @@ const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePan
     }
 };
 
+export enum SidePanelIdentifiers {
+    PROJECTS = "Projects",
+    SHARED_WITH_ME = "SharedWithMe",
+    WORKFLOWS = "Workflows",
+    RECENT_OPEN = "RecentOpen",
+    FAVORITES = "Favourites",
+    TRASH = "Trash"
+}
+
 export const sidePanelData = [
     {
-        id: "1",
+        id: SidePanelIdentifiers.PROJECTS,
         name: "Projects",
-        icon: "fas fa-th fa-fw",
+        icon: ProjectsIcon,
         open: false,
         active: false,
         margin: true,
         openAble: true
     },
     {
-        id: "2",
+        id: SidePanelIdentifiers.SHARED_WITH_ME,
         name: "Shared with me",
-        icon: "fas fa-users fa-fw",
+        icon: ShareMeIcon,
         active: false,
     },
     {
-        id: "3",
+        id: SidePanelIdentifiers.WORKFLOWS,
         name: "Workflows",
-        icon: "fas fa-cogs fa-fw",
+        icon: WorkflowIcon,
         active: false,
     },
     {
-        id: "4",
+        id: SidePanelIdentifiers.RECENT_OPEN,
         name: "Recent open",
-        icon: "icon-time fa-fw",
+        icon: RecentIcon,
         active: false,
     },
     {
-        id: "5",
+        id: SidePanelIdentifiers.FAVORITES,
         name: "Favorites",
-        icon: "fas fa-star fa-fw",
+        icon: FavoriteIcon,
         active: false,
+        activeAction: (dispatch: Dispatch) => {
+            dispatch(push("/favorites"));
+            dispatch(favoritePanelActions.RESET_PAGINATION());
+            dispatch(favoritePanelActions.REQUEST_ITEMS());
+        }
     },
     {
-        id: "6",
+        id: SidePanelIdentifiers.TRASH,
         name: "Trash",
-        icon: "fas fa-trash-alt fa-fw",
+        icon: TrashIcon,
         active: false,
     }
 ];
@@ -82,5 +100,3 @@ function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
         t.active = false;
     }
 }
-
-export default sidePanelReducer;