X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c90e813adcec89899d9db95843295a84fb058c3e..4fe47dee802ef6491649317f335a8558f9f75c40:/src/store/side-panel/side-panel-reducer.ts diff --git a/src/store/side-panel/side-panel-reducer.ts b/src/store/side-panel/side-panel-reducer.ts index 8051017c..66c22896 100644 --- a/src/store/side-panel/side-panel-reducer.ts +++ b/src/store/side-panel/side-panel-reducer.ts @@ -2,83 +2,106 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as _ from "lodash"; - -import actions, { SidePanelAction } from './side-panel-action'; -import { SidePanelItem } from '../../components/side-panel/side-panel'; +import { sidePanelActions, SidePanelAction } from './side-panel-action'; +import { SidePanelItem } from '~/components/side-panel/side-panel'; +import { ProjectsIcon, ShareMeIcon, WorkflowIcon, RecentIcon, FavoriteIcon, TrashIcon } from "~/components/icon/icon"; +import { Dispatch } from "redux"; +import { push } from "react-router-redux"; +import { favoritePanelActions } from "../favorite-panel/favorite-panel-action"; +import { projectPanelActions } from "../project-panel/project-panel-action"; +import { projectActions } from "../project/project-action"; +import { getProjectUrl } from "../../models/project"; +import { columns as projectPanelColumns } from "../../views/project-panel/project-panel"; +import { columns as favoritePanelColumns } from "../../views/favorite-panel/favorite-panel"; export type SidePanelState = SidePanelItem[]; -const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => { - if (state.length === 0) { - return sidePanelData; - } else { - return actions.match(action, { - TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId => state.map(it => itemId === it.id && it.open === false ? {...it, open: true} : {...it, open: false}), - TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => { - const sidePanel = _.cloneDeep(state); - resetSidePanelActivity(sidePanel); - sidePanel.map(it => { - if (it.id === itemId) { - it.active = true; - } - }); - return sidePanel; - }, - RESET_SIDE_PANEL_ACTIVITY: () => { - const sidePanel = _.cloneDeep(state); - resetSidePanelActivity(sidePanel); - return sidePanel; - }, - default: () => state - }); - } +export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => { + return sidePanelActions.match(action, { + TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId => + state.map(it => ({...it, open: itemId === it.id && it.open === false})), + default: () => state + }); }; +export enum SidePanelIdentifiers { + PROJECTS = "Projects", + SHARED_WITH_ME = "SharedWithMe", + WORKFLOWS = "Workflows", + RECENT_OPEN = "RecentOpen", + FAVORITES = "Favourites", + TRASH = "Trash" +} + export const sidePanelData = [ { - id: "1", + id: SidePanelIdentifiers.PROJECTS, name: "Projects", - icon: "fas fa-th fa-fw", + url: "/projects", + icon: ProjectsIcon, open: false, active: false, + margin: true, + openAble: true, + activeAction: (dispatch: Dispatch, uuid: string) => { + dispatch(push(getProjectUrl(uuid))); + dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(uuid)); + dispatch(projectPanelActions.SET_COLUMNS({ columns: projectPanelColumns })); + dispatch(projectPanelActions.RESET_PAGINATION()); + dispatch(projectPanelActions.REQUEST_ITEMS()); + } }, { - id: "2", + id: SidePanelIdentifiers.SHARED_WITH_ME, name: "Shared with me", - icon: "fas fa-users fa-fw", + url: "/shared", + icon: ShareMeIcon, active: false, + activeAction: (dispatch: Dispatch) => { + dispatch(push("/shared")); + } }, { - id: "3", + id: SidePanelIdentifiers.WORKFLOWS, name: "Workflows", - icon: "fas fa-cogs fa-fw", + url: "/workflows", + icon: WorkflowIcon, active: false, + activeAction: (dispatch: Dispatch) => { + dispatch(push("/workflows")); + } }, { - id: "4", + id: SidePanelIdentifiers.RECENT_OPEN, name: "Recent open", - icon: "icon-time fa-fw", + url: "/recent", + icon: RecentIcon, active: false, + activeAction: (dispatch: Dispatch) => { + dispatch(push("/recent")); + } }, { - id: "5", + id: SidePanelIdentifiers.FAVORITES, name: "Favorites", - icon: "fas fa-star fa-fw", + url: "/favorites", + icon: FavoriteIcon, active: false, + activeAction: (dispatch: Dispatch) => { + dispatch(push("/favorites")); + dispatch(favoritePanelActions.SET_COLUMNS({ columns: favoritePanelColumns })); + dispatch(favoritePanelActions.RESET_PAGINATION()); + dispatch(favoritePanelActions.REQUEST_ITEMS()); + } }, { - id: "6", + id: SidePanelIdentifiers.TRASH, name: "Trash", - icon: "fas fa-trash-alt fa-fw", + url: "/trash", + icon: TrashIcon, active: false, + activeAction: (dispatch: Dispatch) => { + dispatch(push("/trash")); + } } ]; - -function resetSidePanelActivity(sidePanel: SidePanelItem[]) { - for (const t of sidePanel) { - t.active = false; - } -} - -export default sidePanelReducer;