//
// SPDX-License-Identifier: AGPL-3.0
-import * as _ from "lodash";
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";
export type SidePanelState = SidePanelItem[];
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
- });
- }
+ 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 =>
+ state.map(it => ({...it, active: it.id === itemId})),
+ RESET_SIDE_PANEL_ACTIVITY: () =>
+ state.map(it => ({...it, active: false })),
+ default: () => state
+ });
};
export enum SidePanelIdentifiers {
active: false,
}
];
-
-function resetSidePanelActivity(sidePanel: SidePanelItem[]) {
- for (const t of sidePanel) {
- t.active = false;
- }
-}