// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
-import { ReactElement } from 'react';
import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
import { ArvadosTheme } from '~/common/custom-theme';
import { List, ListItem, ListItemIcon, Collapse } from "@material-ui/core";
import * as classnames from "classnames";
import { ListItemTextIcon } from '../list-item-text-icon/list-item-text-icon';
import { Dispatch } from "redux";
+import { RouteComponentProps, withRouter } from "react-router";
type CssRules = 'active' | 'row' | 'root' | 'list' | 'iconClose' | 'iconOpen' | 'toggableIconContainer' | 'toggableIcon';
export interface SidePanelItem {
id: string;
name: string;
+ url: string;
icon: IconType;
- active?: boolean;
open?: boolean;
margin?: boolean;
openAble?: boolean;
onContextMenu: (event: React.MouseEvent<HTMLElement>, item: SidePanelItem) => void;
}
-type SidePanelProps = SidePanelDataProps & WithStyles<CssRules>;
+type SidePanelProps = RouteComponentProps<{}> & SidePanelDataProps & WithStyles<CssRules>;
-export const SidePanel = withStyles(styles)(
+export const SidePanel = withStyles(styles)(withRouter(
class extends React.Component<SidePanelProps> {
- render(): ReactElement<any> {
+ render() {
const { classes, toggleOpen, toggleActive, sidePanelItems, children } = this.props;
const { root, row, list, toggableIconContainer } = classes;
+
+ const path = this.props.location.pathname.split('/');
+ const activeUrl = path.length > 1 ? "/" + path[1] : "/";
return (
<div className={root}>
<List>
- {sidePanelItems.map(it => (
- <span key={it.name}>
+ {sidePanelItems.map(it => {
+ const active = it.url === activeUrl;
+ return <span key={it.name}>
<ListItem button className={list} onClick={() => toggleActive(it.id)}
onContextMenu={this.handleRowContextMenu(it)}>
<span className={row}>
{it.openAble ? (
<i onClick={() => toggleOpen(it.id)} className={toggableIconContainer}>
<ListItemIcon
- className={this.getToggableIconClassNames(it.open, it.active)}>
+ className={this.getToggableIconClassNames(it.open, active)}>
< SidePanelRightArrowIcon/>
</ListItemIcon>
</i>
) : null}
- <ListItemTextIcon icon={it.icon} name={it.name} isActive={it.active}
+ <ListItemTextIcon icon={it.icon} name={it.name} isActive={active}
hasMargin={it.margin}/>
</span>
</ListItem>
{children}
</Collapse>
) : null}
- </span>
- ))}
+ </span>;
+ })}
</List>
</div>
);
(event: React.MouseEvent<HTMLElement>) =>
item.openAble ? this.props.onContextMenu(event, item) : null
}
-);
+));
USER_DETAILS_REQUEST: {},
USER_DETAILS_SUCCESS: ofType<User>()
}, {
- tag: 'type',
- value: 'payload'
- });
+ tag: 'type',
+ value: 'payload'
+});
function setAuthorizationHeader(services: ServiceRepository, token: string) {
services.apiClient.defaults.headers.common = {
import { TreeItemStatus } from "~/components/tree/tree";
import { findTreeItem } from "../project/project-reducer";
import { RootState } from "../store";
-import { Resource, ResourceKind } from "~/models/resource";
+import { ResourceKind } from "~/models/resource";
import { projectPanelActions } from "../project-panel/project-panel-action";
import { getCollectionUrl } from "~/models/collection";
import { getProjectUrl, ProjectResource } from "~/models/project";
export const setProjectItem = (itemId: string, itemMode: ItemMode) =>
(dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- console.log("SetProjectItem!!", itemId);
- debugger;
const { projects, router } = getState();
const treeItem = findTreeItem(projects.items, itemId);
const uuids = ancestors.map(ancestor => ancestor.uuid);
await loadBranch(uuids, dispatch);
dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(SidePanelIdentifiers.PROJECTS));
- dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
uuids.forEach(uuid => {
dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_OPEN(uuid));
});
import { default as unionize, ofType, UnionOf } from "unionize";
export const sidePanelActions = unionize({
- TOGGLE_SIDE_PANEL_ITEM_OPEN: ofType<string>(),
- TOGGLE_SIDE_PANEL_ITEM_ACTIVE: ofType<string>(),
- RESET_SIDE_PANEL_ACTIVITY: ofType<{}>(),
+ TOGGLE_SIDE_PANEL_ITEM_OPEN: ofType<string>()
}, {
tag: 'type',
value: 'payload'
import { ProjectsIcon } from "~/components/icon/icon";
describe('side-panel-reducer', () => {
-
- it('should toggle activity on side-panel', () => {
- const initialState = [
- {
- id: "1",
- name: "Projects",
- icon: ProjectsIcon,
- open: false,
- active: false,
- }
- ];
- const project = [
- {
- id: "1",
- name: "Projects",
- icon: ProjectsIcon,
- open: false,
- active: true,
- }
- ];
-
- const state = sidePanelReducer(initialState, sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(initialState[0].id));
- expect(state).toEqual(project);
- });
-
it('should open side-panel item', () => {
const initialState = [
{
id: "1",
name: "Projects",
+ url: "/projects",
icon: ProjectsIcon,
- open: false,
- active: false,
+ open: false
}
];
const project = [
id: "1",
name: "Projects",
icon: ProjectsIcon,
- open: true,
- active: false,
+ open: true
}
];
const state = sidePanelReducer(initialState, sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_OPEN(initialState[0].id));
expect(state).toEqual(project);
});
-
- it('should remove activity on side-panel item', () => {
- const initialState = [
- {
- id: "1",
- name: "Projects",
- icon: ProjectsIcon,
- open: false,
- active: true,
- }
- ];
- const project = [
- {
- id: "1",
- name: "Projects",
- icon: ProjectsIcon,
- open: false,
- active: false,
- }
- ];
-
- const state = sidePanelReducer(initialState, sidePanelActions.RESET_SIDE_PANEL_ACTIVITY(initialState[0].id));
- expect(state).toEqual(project);
- });
});
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
});
};
{
id: SidePanelIdentifiers.PROJECTS,
name: "Projects",
+ url: "/projects",
icon: ProjectsIcon,
open: false,
active: false,
margin: true,
openAble: true,
activeAction: (dispatch: Dispatch, uuid: string) => {
- dispatch(projectActions.TOGGLE_PROJECT_TREE_ITEM_ACTIVE(uuid));
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: SidePanelIdentifiers.SHARED_WITH_ME,
name: "Shared with me",
+ url: "/shared",
icon: ShareMeIcon,
active: false,
+ activeAction: (dispatch: Dispatch) => {
+ dispatch(push("/shared"));
+ }
},
{
id: SidePanelIdentifiers.WORKFLOWS,
name: "Workflows",
+ url: "/workflows",
icon: WorkflowIcon,
active: false,
+ activeAction: (dispatch: Dispatch) => {
+ dispatch(push("/workflows"));
+ }
},
{
id: SidePanelIdentifiers.RECENT_OPEN,
name: "Recent open",
+ url: "/recent",
icon: RecentIcon,
active: false,
+ activeAction: (dispatch: Dispatch) => {
+ dispatch(push("/recent"));
+ }
},
{
id: SidePanelIdentifiers.FAVORITES,
name: "Favorites",
+ url: "/favorites",
icon: FavoriteIcon,
active: false,
activeAction: (dispatch: Dispatch) => {
{
id: SidePanelIdentifiers.TRASH,
name: "Trash",
+ url: "/trash",
icon: TrashIcon,
active: false,
+ activeAction: (dispatch: Dispatch) => {
+ dispatch(push("/trash"));
+ }
}
];
toggleActive={itemId => {
this.props.dispatch(setProjectItem(itemId, ItemMode.ACTIVE));
this.props.dispatch(loadDetails(itemId, ResourceKind.PROJECT));
- this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
}} />
</SidePanel>
</Drawer>}
default:
this.props.dispatch(loadDetails(item.uuid, ResourceKind.PROJECT));
this.props.dispatch(setProjectItem(item.uuid, ItemMode.ACTIVE));
- this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(SidePanelIdentifiers.PROJECTS));
}
}}
}
toggleSidePanelActive = (itemId: string) => {
- this.props.dispatch(sidePanelActions.TOGGLE_SIDE_PANEL_ITEM_ACTIVE(itemId));
this.props.dispatch(projectActions.RESET_PROJECT_TREE_ACTIVITY(itemId));
const panelItem = this.props.sidePanelItems.find(it => it.id === itemId);