1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { sidePanelActions, SidePanelAction } from './side-panel-action';
6 import { SidePanelItem } from '~/components/side-panel/side-panel';
7 import { ProjectsIcon, ShareMeIcon, WorkflowIcon, RecentIcon, FavoriteIcon, TrashIcon } from "~/components/icon/icon";
8 import { Dispatch } from "redux";
9 import { push } from "react-router-redux";
10 import { favoritePanelActions } from "../favorite-panel/favorite-panel-action";
11 import { projectPanelActions } from "../project-panel/project-panel-action";
12 import { projectActions } from "../project/project-action";
13 import { getProjectUrl } from "../../models/project";
14 import { columns as projectPanelColumns } from "../../views/project-panel/project-panel";
15 import { columns as favoritePanelColumns } from "../../views/favorite-panel/favorite-panel";
17 export type SidePanelState = SidePanelItem[];
19 export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
20 return sidePanelActions.match(action, {
21 TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId =>
22 state.map(it => ({...it, open: itemId === it.id && it.open === false})),
23 TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId =>
24 state.map(it => ({...it, active: it.id === itemId})),
25 RESET_SIDE_PANEL_ACTIVITY: () =>
26 state.map(it => ({...it, active: false })),
31 export enum SidePanelIdentifiers {
32 PROJECTS = "Projects",
33 SHARED_WITH_ME = "SharedWithMe",
34 WORKFLOWS = "Workflows",
35 RECENT_OPEN = "RecentOpen",
36 FAVORITES = "Favourites",
40 export const sidePanelData = [
42 id: SidePanelIdentifiers.PROJECTS,
49 activeAction: (dispatch: Dispatch, uuid: string) => {
50 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(uuid));
51 dispatch(push(getProjectUrl(uuid)));
52 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
53 dispatch(projectPanelActions.RESET_PAGINATION());
54 dispatch(projectPanelActions.REQUEST_ITEMS());
58 id: SidePanelIdentifiers.SHARED_WITH_ME,
59 name: "Shared with me",
64 id: SidePanelIdentifiers.WORKFLOWS,
70 id: SidePanelIdentifiers.RECENT_OPEN,
76 id: SidePanelIdentifiers.FAVORITES,
80 activeAction: (dispatch: Dispatch) => {
81 dispatch(push("/favorites"));
82 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
83 dispatch(favoritePanelActions.RESET_PAGINATION());
84 dispatch(favoritePanelActions.REQUEST_ITEMS());
88 id: SidePanelIdentifiers.TRASH,