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";
15 import { columns as projectPanelColumns } from "../../views/project-panel/project-panel";
16 import { columns as favoritePanelColumns } from "../../views/favorite-panel/favorite-panel";
18 export type SidePanelState = SidePanelItem[];
20 export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
21 if (state.length === 0) {
24 return sidePanelActions.match(action, {
25 TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId =>
26 state.map(it => ({...it, open: itemId === it.id && it.open === false})),
27 TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
28 const sidePanel = _.cloneDeep(state);
29 resetSidePanelActivity(sidePanel);
30 sidePanel.forEach(it => {
31 if (it.id === itemId) {
37 RESET_SIDE_PANEL_ACTIVITY: () => {
38 const sidePanel = _.cloneDeep(state);
39 resetSidePanelActivity(sidePanel);
47 export enum SidePanelIdentifiers {
48 PROJECTS = "Projects",
49 SHARED_WITH_ME = "SharedWithMe",
50 WORKFLOWS = "Workflows",
51 RECENT_OPEN = "RecentOpen",
52 FAVORITES = "Favourites",
56 export const sidePanelData = [
58 id: SidePanelIdentifiers.PROJECTS,
65 activeAction: (dispatch: Dispatch, uuid: string) => {
66 dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(uuid));
67 dispatch(push(getProjectUrl(uuid)));
68 dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
69 dispatch(projectPanelActions.RESET_PAGINATION());
70 dispatch(projectPanelActions.REQUEST_ITEMS());
74 id: SidePanelIdentifiers.SHARED_WITH_ME,
75 name: "Shared with me",
80 id: SidePanelIdentifiers.WORKFLOWS,
86 id: SidePanelIdentifiers.RECENT_OPEN,
92 id: SidePanelIdentifiers.FAVORITES,
96 activeAction: (dispatch: Dispatch) => {
97 dispatch(push("/favorites"));
98 dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }))
99 dispatch(favoritePanelActions.RESET_PAGINATION());
100 dispatch(favoritePanelActions.REQUEST_ITEMS());
104 id: SidePanelIdentifiers.TRASH,
111 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
112 for (const t of sidePanel) {