1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as _ from "lodash";
7 import actions, { SidePanelAction } from './side-panel-action';
8 import { SidePanelItem } from '../../components/side-panel/side-panel';
9 import { IconTypes } from "../../components/icon/icon";
11 export type SidePanelState = SidePanelItem[];
13 const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
14 if (state.length === 0) {
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);
23 if (it.id === itemId) {
29 RESET_SIDE_PANEL_ACTIVITY: () => {
30 const sidePanel = _.cloneDeep(state);
31 resetSidePanelActivity(sidePanel);
39 export enum SidePanelIdentifiers {
40 Projects = "Projects",
41 SharedWithMe = "SharedWithMe",
42 Workflows = "Workflows",
43 RecentOpen = "RecentOpen",
44 Favourites = "Favourites",
48 export const sidePanelData = [
50 id: SidePanelIdentifiers.Projects,
52 icon: IconTypes.INBOX,
59 id: SidePanelIdentifiers.SharedWithMe,
60 name: "Shared with me",
61 icon: IconTypes.PEOPLE,
65 id: SidePanelIdentifiers.Workflows,
71 id: SidePanelIdentifiers.RecentOpen,
73 icon: IconTypes.ACCESS_TIME,
77 id: SidePanelIdentifiers.Favourites,
83 id: SidePanelIdentifiers.Trash,
85 icon: IconTypes.DELETE,
90 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
91 for (const t of sidePanel) {
96 export default sidePanelReducer;