Add typescript paths to top level folders
[arvados-workbench2.git] / src / store / side-panel / side-panel-reducer.ts
index 2bbd6a1182007d4283d081bef8035d1ecc12c9d6..fe0626340d3740695539dd669e3c3ff47debc9bb 100644 (file)
@@ -4,8 +4,11 @@
 
 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";
+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[];
 
@@ -14,11 +17,12 @@ export const sidePanelReducer = (state: SidePanelState = sidePanelData, action:
         return sidePanelData;
     } else {
         return sidePanelActions.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_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;
                     }
@@ -36,17 +40,17 @@ export const sidePanelReducer = (state: SidePanelState = sidePanelData, action:
 };
 
 export enum SidePanelIdentifiers {
-    Projects = "Projects",
-    SharedWithMe = "SharedWithMe",
-    Workflows = "Workflows",
-    RecentOpen = "RecentOpen",
-    Favourites = "Favourites",
-    Trash = "Trash"
+    PROJECTS = "Projects",
+    SHARED_WITH_ME = "SharedWithMe",
+    WORKFLOWS = "Workflows",
+    RECENT_OPEN = "RecentOpen",
+    FAVORITES = "Favourites",
+    TRASH = "Trash"
 }
 
 export const sidePanelData = [
     {
-        id: SidePanelIdentifiers.Projects,
+        id: SidePanelIdentifiers.PROJECTS,
         name: "Projects",
         icon: ProjectsIcon,
         open: false,
@@ -55,31 +59,36 @@ export const sidePanelData = [
         openAble: true
     },
     {
-        id: SidePanelIdentifiers.SharedWithMe,
+        id: SidePanelIdentifiers.SHARED_WITH_ME,
         name: "Shared with me",
         icon: ShareMeIcon,
         active: false,
     },
     {
-        id: SidePanelIdentifiers.Workflows,
+        id: SidePanelIdentifiers.WORKFLOWS,
         name: "Workflows",
         icon: WorkflowIcon,
         active: false,
     },
     {
-        id: SidePanelIdentifiers.RecentOpen,
+        id: SidePanelIdentifiers.RECENT_OPEN,
         name: "Recent open",
         icon: RecentIcon,
         active: false,
     },
     {
-        id: SidePanelIdentifiers.Favourites,
+        id: SidePanelIdentifiers.FAVORITES,
         name: "Favorites",
         icon: FavoriteIcon,
         active: false,
+        activeAction: (dispatch: Dispatch) => {
+            dispatch(push("/favorites"));
+            dispatch(favoritePanelActions.RESET_PAGINATION());
+            dispatch(favoritePanelActions.REQUEST_ITEMS());
+        }
     },
     {
-        id: SidePanelIdentifiers.Trash,
+        id: SidePanelIdentifiers.TRASH,
         name: "Trash",
         icon: TrashIcon,
         active: false,