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 { dataExplorerActions } from "../data-explorer/data-explorer-action";
10 import { Dispatch } from "redux";
11 import { FAVORITE_PANEL_ID } from "../../views/favorite-panel/favorite-panel";
12 import { push } from "react-router-redux";
14 export type SidePanelState = SidePanelItem[];
16 export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
17 if (state.length === 0) {
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 const sidePanel = _.cloneDeep(state);
25 resetSidePanelActivity(sidePanel);
26 sidePanel.forEach(it => {
27 if (it.id === itemId) {
33 RESET_SIDE_PANEL_ACTIVITY: () => {
34 const sidePanel = _.cloneDeep(state);
35 resetSidePanelActivity(sidePanel);
43 export enum SidePanelIdentifiers {
44 PROJECTS = "Projects",
45 SHARED_WITH_ME = "SharedWithMe",
46 WORKFLOWS = "Workflows",
47 RECENT_OPEN = "RecentOpen",
48 FAVORITES = "Favourites",
52 export const sidePanelData = [
54 id: SidePanelIdentifiers.PROJECTS,
63 id: SidePanelIdentifiers.SHARED_WITH_ME,
64 name: "Shared with me",
69 id: SidePanelIdentifiers.WORKFLOWS,
75 id: SidePanelIdentifiers.RECENT_OPEN,
81 id: SidePanelIdentifiers.FAVORITES,
85 activeAction: (dispatch: Dispatch) => {
86 dispatch(push("/favorites"));
87 dispatch(dataExplorerActions.RESET_PAGINATION({id: FAVORITE_PANEL_ID}));
88 dispatch(dataExplorerActions.REQUEST_ITEMS({id: FAVORITE_PANEL_ID}));
92 id: SidePanelIdentifiers.TRASH,
99 function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
100 for (const t of sidePanel) {