Creation dialog with redux-form validation
[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 enum SidePanelIdentifiers {
39     Projects = "Projects",
40     SharedWithMe = "SharedWithMe",
41     Workflows = "Workflows",
42     RecentOpen = "RecentOpen",
43     Favourites = "Favourites",
44     Trash = "Trash"
45 }
46
47 export const sidePanelData = [
48     {
49         id: SidePanelIdentifiers.Projects,
50         name: "Projects",
51         icon: "fas fa-th fa-fw",
52         open: false,
53         active: false,
54         margin: true,
55         openAble: true
56     },
57     {
58         id: SidePanelIdentifiers.SharedWithMe,
59         name: "Shared with me",
60         icon: "fas fa-users fa-fw",
61         active: false,
62     },
63     {
64         id: SidePanelIdentifiers.Workflows,
65         name: "Workflows",
66         icon: "fas fa-cogs fa-fw",
67         active: false,
68     },
69     {
70         id: SidePanelIdentifiers.RecentOpen,
71         name: "Recent open",
72         icon: "icon-time fa-fw",
73         active: false,
74     },
75     {
76         id: SidePanelIdentifiers.Favourites,
77         name: "Favorites",
78         icon: "fas fa-star fa-fw",
79         active: false,
80     },
81     {
82         id: SidePanelIdentifiers.Trash,
83         name: "Trash",
84         icon: "fas fa-trash-alt fa-fw",
85         active: false,
86     }
87 ];
88
89 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
90     for (const t of sidePanel) {
91         t.active = false;
92     }
93 }
94
95 export default sidePanelReducer;