Add utils for recognizing resource by uuid
[arvados-workbench2.git] / src / store / side-panel / side-panel-reducer.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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";
16
17 export type SidePanelState = SidePanelItem[];
18
19 export const sidePanelReducer = (state: SidePanelState = sidePanelItems, 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         default: () => state
24     });
25 };
26
27 export enum SidePanelId {
28     PROJECTS = "Projects",
29     SHARED_WITH_ME = "SharedWithMe",
30     WORKFLOWS = "Workflows",
31     RECENT_OPEN = "RecentOpen",
32     FAVORITES = "Favourites",
33     TRASH = "Trash"
34 }
35
36 export const sidePanelItems = [
37     {
38         id: SidePanelId.PROJECTS,
39         name: "Projects",
40         url: "/projects",
41         icon: ProjectsIcon,
42         open: false,
43         active: false,
44         margin: true,
45         openAble: true,
46         activeAction: (dispatch: Dispatch, uuid: string) => {
47             dispatch(push(getProjectUrl(uuid)));
48             dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(uuid));
49             dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns }));
50             dispatch(projectPanelActions.RESET_PAGINATION());
51             dispatch(projectPanelActions.REQUEST_ITEMS());
52         }
53     },
54     {
55         id: SidePanelId.SHARED_WITH_ME,
56         name: "Shared with me",
57         url: "/shared",
58         icon: ShareMeIcon,
59         active: false,
60         activeAction: (dispatch: Dispatch) => {
61             dispatch(push("/shared"));
62         }
63     },
64     {
65         id: SidePanelId.WORKFLOWS,
66         name: "Workflows",
67         url: "/workflows",
68         icon: WorkflowIcon,
69         active: false,
70         activeAction: (dispatch: Dispatch) => {
71             dispatch(push("/workflows"));
72         }
73     },
74     {
75         id: SidePanelId.RECENT_OPEN,
76         name: "Recent open",
77         url: "/recent",
78         icon: RecentIcon,
79         active: false,
80         activeAction: (dispatch: Dispatch) => {
81             dispatch(push("/recent"));
82         }
83     },
84     {
85         id: SidePanelId.FAVORITES,
86         name: "Favorites",
87         url: "/favorites",
88         icon: FavoriteIcon,
89         active: false,
90         activeAction: (dispatch: Dispatch) => {
91             dispatch(push("/favorites"));
92             dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns }));
93             dispatch(favoritePanelActions.RESET_PAGINATION());
94             dispatch(favoritePanelActions.REQUEST_ITEMS());
95         }
96     },
97     {
98         id: SidePanelId.TRASH,
99         name: "Trash",
100         url: "/trash",
101         icon: TrashIcon,
102         active: false,
103         activeAction: (dispatch: Dispatch) => {
104             dispatch(push("/trash"));
105         }
106     }
107 ];