1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as _ from "lodash";
6 import { sidePanelActions, SidePanelAction } from './side-panel-action';
7 import { SidePanelItem } from '../../components/side-panel/side-panel';
8 import { ProjectsIcon, ShareMeIcon, WorkflowIcon, RecentIcon, FavoriteIcon, TrashIcon } from "../../components/icon/icon";
10 export type SidePanelState = SidePanelItem[];
12 export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
13 if (state.length === 0) {
16 return sidePanelActions.match(action, {
17 TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId =>
18 state.map(it => ({...it, open: itemId === it.id && it.open === false})),
19 TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
20 const sidePanel = _.cloneDeep(state);
21 resetSidePanelActivity(sidePanel);
22 sidePanel.forEach(it => {
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,
59 id: SidePanelIdentifiers.SharedWithMe,
60 name: "Shared with me",
65 id: SidePanelIdentifiers.Workflows,
71 id: SidePanelIdentifiers.RecentOpen,
77 id: SidePanelIdentifiers.Favourites,
84 id: SidePanelIdentifiers.Trash,
91 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
92 for (const t of sidePanel) {