// SPDX-License-Identifier: AGPL-3.0
import * as _ from "lodash";
-
-import actions, { SidePanelAction } from './side-panel-action';
+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 { dataExplorerActions } from "../data-explorer/data-explorer-action";
+import { Dispatch } from "react-redux";
+import { FAVORITE_PANEL_ID } from "../../views/favorite-panel/favorite-panel";
+import { push } from "react-router-redux";
export type SidePanelState = SidePanelItem[];
-const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
- return actions.match(action, {
- TOGGLE_SIDE_PANEL_ITEM_OPEN: () => {
- const sidePanel = _.cloneDeep(state);
- sidePanel[0].open = !sidePanel[0].open;
- return sidePanel;
- },
- TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
- const sidePanel = _.cloneDeep(state);
- resetSidePanelActivity(sidePanel);
- sidePanel.map(it => {
- if (it.id === itemId) {
- it.active = true;
- }
- });
- resetProjectsCollapse(sidePanel);
- return sidePanel;
- },
- default: () => state
- });
+export const sidePanelReducer = (state: SidePanelState = sidePanelData, action: SidePanelAction) => {
+ if (state.length === 0) {
+ return sidePanelData;
+ } else {
+ return sidePanelActions.match(action, {
+ TOGGLE_SIDE_PANEL_ITEM_OPEN: itemId =>
+ state.map(it => ({...it, open: itemId === it.id && it.open === false})),
+ TOGGLE_SIDE_PANEL_ITEM_ACTIVE: itemId => {
+ const sidePanel = _.cloneDeep(state);
+ resetSidePanelActivity(sidePanel);
+ sidePanel.forEach(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 enum SidePanelIdentifiers {
+ Projects = "Projects",
+ SharedWithMe = "SharedWithMe",
+ Workflows = "Workflows",
+ RecentOpen = "RecentOpen",
+ Favourites = "Favourites",
+ Trash = "Trash"
+}
+
export const sidePanelData = [
{
- id: "1",
+ id: SidePanelIdentifiers.Projects,
name: "Projects",
- icon: "fas fa-th fa-fw",
+ icon: ProjectsIcon,
open: false,
active: false,
+ margin: true,
+ openAble: true
},
{
- id: "2",
+ id: SidePanelIdentifiers.SharedWithMe,
name: "Shared with me",
- icon: "fas fa-users fa-fw",
+ icon: ShareMeIcon,
active: false,
},
{
- id: "3",
+ id: SidePanelIdentifiers.Workflows,
name: "Workflows",
- icon: "fas fa-cogs fa-fw",
+ icon: WorkflowIcon,
active: false,
},
{
- id: "4",
+ id: SidePanelIdentifiers.RecentOpen,
name: "Recent open",
- icon: "icon-time fa-fw",
+ icon: RecentIcon,
active: false,
},
{
- id: "5",
+ id: SidePanelIdentifiers.Favourites,
name: "Favorites",
- icon: "fas fa-star fa-fw",
+ icon: FavoriteIcon,
active: false,
+ activeAction: (dispatch: Dispatch) => {
+ dispatch(push("/favorites"));
+ dispatch(dataExplorerActions.RESET_PAGINATION({id: FAVORITE_PANEL_ID}));
+ dispatch(dataExplorerActions.REQUEST_ITEMS({id: FAVORITE_PANEL_ID}));
+ }
},
{
- id: "6",
+ id: SidePanelIdentifiers.Trash,
name: "Trash",
- icon: "fas fa-trash-alt fa-fw",
+ icon: TrashIcon,
active: false,
}
];
t.active = false;
}
}
-
-function resetProjectsCollapse(sidePanel: SidePanelItem[]) {
- if (!sidePanel[0].active) {
- sidePanel[0].open = false;
- }
-}
-
-export default sidePanelReducer;