9f01fa2a1d67c8c3bd7c320b90934241b3cac9b6
[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     return actions.match(action, {
14         TOGGLE_SIDE_PANEL_ITEM_OPEN: () => {
15             const sidePanel = _.cloneDeep(state);
16             sidePanel[0].open = !sidePanel[0].open;
17             return sidePanel;
18         },
19         TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
20             const sidePanel = _.cloneDeep(state);
21             resetSidePanelActivity(sidePanel);
22             sidePanel.map(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 export const sidePanelData = [
39     {
40         id: "1",
41         name: "Projects",
42         icon: "fas fa-th fa-fw",
43         open: false,
44         active: false,
45     },
46     {
47         id: "2",
48         name: "Shared with me",
49         icon: "fas fa-users fa-fw",
50         active: false,
51     },
52     {
53         id: "3",
54         name: "Workflows",
55         icon: "fas fa-cogs fa-fw",
56         active: false,
57     },
58     {
59         id: "4",
60         name: "Recent open",
61         icon: "icon-time fa-fw",
62         active: false,
63     },
64     {
65         id: "5",
66         name: "Favorites",
67         icon: "fas fa-star fa-fw",
68         active: false,
69     },
70     {
71         id: "6",
72         name: "Trash",
73         icon: "fas fa-trash-alt fa-fw",
74         active: false,
75     }
76 ];
77
78 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
79     for (const t of sidePanel) {
80         t.active = false;
81     }
82 }
83
84 export default sidePanelReducer;