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";
9 import { Dispatch } from "redux";
10 import { push } from "react-router-redux";
11 import { favoritePanelActions } from "../favorite-panel/favorite-panel-action";
13 export type SidePanelState = SidePanelItem[];
15 export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
16 if (state.length === 0) {
19 return sidePanelActions.match(action, {
20 TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId =>
21 state.map(it => ({...it, open: itemId === it.id && it.open === false})),
22 TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
23 const sidePanel = _.cloneDeep(state);
24 resetSidePanelActivity(sidePanel);
25 sidePanel.forEach(it => {
26 if (it.id === itemId) {
32 RESET_SIDE_PANEL_ACTIVITY: () => {
33 const sidePanel = _.cloneDeep(state);
34 resetSidePanelActivity(sidePanel);
42 export enum SidePanelIdentifiers {
43 PROJECTS = "Projects",
44 SHARED_WITH_ME = "SharedWithMe",
45 WORKFLOWS = "Workflows",
46 RECENT_OPEN = "RecentOpen",
47 FAVORITES = "Favourites",
51 export const sidePanelData = [
53 id: SidePanelIdentifiers.PROJECTS,
62 id: SidePanelIdentifiers.SHARED_WITH_ME,
63 name: "Shared with me",
68 id: SidePanelIdentifiers.WORKFLOWS,
74 id: SidePanelIdentifiers.RECENT_OPEN,
80 id: SidePanelIdentifiers.FAVORITES,
84 activeAction: (dispatch: Dispatch) => {
85 dispatch(push("/favorites"));
86 dispatch(favoritePanelActions.RESET_PAGINATION());
87 dispatch(favoritePanelActions.REQUEST_ITEMS());
91 id: SidePanelIdentifiers.TRASH,
98 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
99 for (const t of sidePanel) {