improve attributes and dt-factory, modify side-panel, main-app-bar and icons
[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 import { IconTypes } from "../../components/icon/icon";
10
11 export type SidePanelState = SidePanelItem[];
12
13 const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
14     if (state.length === 0) {
15         return sidePanelData;
16     } else {
17         return actions.match(action, {
18             TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId => state.map(it => itemId === it.id && it.open === false ? {...it, open: true} : {...it, open: false}),
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
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: IconTypes.INBOX,
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: IconTypes.PEOPLE,
62         active: false,
63     },
64     {
65         id: SidePanelIdentifiers.Workflows,
66         name: "Workflows",
67         icon: IconTypes.CODE,
68         active: false,
69     },
70     {
71         id: SidePanelIdentifiers.RecentOpen,
72         name: "Recent open",
73         icon: IconTypes.ACCESS_TIME,
74         active: false,
75     },
76     {
77         id: SidePanelIdentifiers.Favourites,
78         name: "Favorites",
79         icon: IconTypes.STAR,
80         active: false,
81     },
82     {
83         id: SidePanelIdentifiers.Trash,
84         name: "Trash",
85         icon: IconTypes.DELETE,
86         active: false,
87     }
88 ];
89
90 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
91     for (const t of sidePanel) {
92         t.active = false;
93     }
94 }
95
96 export default sidePanelReducer;