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";
12 import { projectPanelActions } from "../project-panel/project-panel-action";
13 import { projectActions } from "../project/project-action";
14 import { getProjectUrl } from "../../models/project";
16 export type SidePanelState = SidePanelItem[];
18 export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
19 if (state.length === 0) {
22 return sidePanelActions.match(action, {
23 TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId =>
24 state.map(it => ({...it, open: itemId === it.id && it.open === false})),
25 TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
26 const sidePanel = _.cloneDeep(state);
27 resetSidePanelActivity(sidePanel);
28 sidePanel.forEach(it => {
29 if (it.id === itemId) {
35 RESET_SIDE_PANEL_ACTIVITY: () => {
36 const sidePanel = _.cloneDeep(state);
37 resetSidePanelActivity(sidePanel);
45 export enum SidePanelIdentifiers {
46 PROJECTS = "Projects",
47 SHARED_WITH_ME = "SharedWithMe",
48 WORKFLOWS = "Workflows",
49 RECENT_OPEN = "RecentOpen",
50 FAVORITES = "Favourites",
54 export const sidePanelData = [
56 id: SidePanelIdentifiers.PROJECTS,
63 activeAction: (dispatch: Dispatch, uuid: string) => {
64 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(uuid));
65 dispatch(push(getProjectUrl(uuid)));
66 dispatch(projectPanelActions.RESET_PAGINATION());
67 dispatch(projectPanelActions.REQUEST_ITEMS());
71 id: SidePanelIdentifiers.SHARED_WITH_ME,
72 name: "Shared with me",
77 id: SidePanelIdentifiers.WORKFLOWS,
83 id: SidePanelIdentifiers.RECENT_OPEN,
89 id: SidePanelIdentifiers.FAVORITES,
93 activeAction: (dispatch: Dispatch) => {
94 dispatch(push("/favorites"));
95 dispatch(favoritePanelActions.RESET_PAGINATION());
96 dispatch(favoritePanelActions.REQUEST_ITEMS());
100 id: SidePanelIdentifiers.TRASH,
107 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
108 for (const t of sidePanel) {