new flags in side panel
[arvados-workbench2.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
7 import actions, { SidePanelAction } from './side-panel-action';
8 import { SidePanelItem } from '../../components/side-panel/side-panel';
9
10 export type SidePanelState = SidePanelItem[];
11
12 const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
13     if (state.length === 0) {
14         return sidePanelData;
15     } else {
16         return actions.match(action, {
17             TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId => state.map(it => itemId === it.id && it.open === false ? {...it, open: true} : {...it, open: false}),
18             TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
19                 const sidePanel = _.cloneDeep(state);
20                 resetSidePanelActivity(sidePanel);
21                 sidePanel.map(it => {
22                     if (it.id === itemId) {
23                         it.active = true;
24                     }
25                 });
26                 return sidePanel;
27             },
28             RESET_SIDE_PANEL_ACTIVITY: () => {
29                 const sidePanel = _.cloneDeep(state);
30                 resetSidePanelActivity(sidePanel);
31                 return sidePanel;
32             },
33             default: () => state
34         });
35     }
36 };
37
38 export const sidePanelData = [
39     {
40         id: "1",
41         name: "Projects",
42         icon: "fas fa-th fa-fw",
43         open: false,
44         active: false,
45         margin: true,
46         openAble: true
47     },
48     {
49         id: "2",
50         name: "Shared with me",
51         icon: "fas fa-users fa-fw",
52         active: false,
53     },
54     {
55         id: "3",
56         name: "Workflows",
57         icon: "fas fa-cogs fa-fw",
58         active: false,
59     },
60     {
61         id: "4",
62         name: "Recent open",
63         icon: "icon-time fa-fw",
64         active: false,
65     },
66     {
67         id: "5",
68         name: "Favorites",
69         icon: "fas fa-star fa-fw",
70         active: false,
71     },
72     {
73         id: "6",
74         name: "Trash",
75         icon: "fas fa-trash-alt fa-fw",
76         active: false,
77     }
78 ];
79
80 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
81     for (const t of sidePanel) {
82         t.active = false;
83     }
84 }
85
86 export default sidePanelReducer;