Add favorite panel
[arvados.git] / src / store / side-panel / side-panel-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as _ from "lodash";
6 import { sidePanelActions, SidePanelAction } from './side-panel-action';
7 import { SidePanelItem } from '../../components/side-panel/side-panel';
8 import { ProjectsIcon, ShareMeIcon, WorkflowIcon, RecentIcon, FavoriteIcon, TrashIcon } from "../../components/icon/icon";
9
10 export type SidePanelState = SidePanelItem[];
11
12 export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
13     if (state.length === 0) {
14         return sidePanelData;
15     } else {
16         return sidePanelActions.match(action, {
17             TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId =>
18                 state.map(it => ({...it, open: itemId === it.id && it.open === false})),
19             TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
20                 const sidePanel = _.cloneDeep(state);
21                 resetSidePanelActivity(sidePanel);
22                 sidePanel.forEach(it => {
23                     if (it.id === itemId) {
24                         it.active = true;
25                     }
26                 });
27                 return sidePanel;
28             },
29             RESET_SIDE_PANEL_ACTIVITY: () => {
30                 const sidePanel = _.cloneDeep(state);
31                 resetSidePanelActivity(sidePanel);
32                 return sidePanel;
33             },
34             default: () => state
35         });
36     }
37 };
38
39 export enum SidePanelIdentifiers {
40     Projects = "Projects",
41     SharedWithMe = "SharedWithMe",
42     Workflows = "Workflows",
43     RecentOpen = "RecentOpen",
44     Favourites = "Favourites",
45     Trash = "Trash"
46 }
47
48 export const sidePanelData = [
49     {
50         id: SidePanelIdentifiers.Projects,
51         name: "Projects",
52         icon: ProjectsIcon,
53         open: false,
54         active: false,
55         margin: true,
56         openAble: true
57     },
58     {
59         id: SidePanelIdentifiers.SharedWithMe,
60         name: "Shared with me",
61         icon: ShareMeIcon,
62         active: false,
63     },
64     {
65         id: SidePanelIdentifiers.Workflows,
66         name: "Workflows",
67         icon: WorkflowIcon,
68         active: false,
69     },
70     {
71         id: SidePanelIdentifiers.RecentOpen,
72         name: "Recent open",
73         icon: RecentIcon,
74         active: false,
75     },
76     {
77         id: SidePanelIdentifiers.Favourites,
78         name: "Favorites",
79         icon: FavoriteIcon,
80         active: false,
81         path: '/favorites'
82     },
83     {
84         id: SidePanelIdentifiers.Trash,
85         name: "Trash",
86         icon: TrashIcon,
87         active: false,
88     }
89 ];
90
91 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
92     for (const t of sidePanel) {
93         t.active = false;
94     }
95 }