1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { ReactElement } from 'react';
7 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
8 import { ArvadosTheme } from '~/common/custom-theme';
9 import { List, ListItem, ListItemIcon, Collapse } from "@material-ui/core";
10 import { SidePanelRightArrowIcon, IconType } from '../icon/icon';
11 import * as classnames from "classnames";
12 import { ListItemTextIcon } from '../list-item-text-icon/list-item-text-icon';
13 import { Dispatch } from "redux";
15 type CssRules = 'active' | 'row' | 'root' | 'list' | 'iconClose' | 'iconOpen' | 'toggableIconContainer' | 'toggableIcon';
17 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
27 padding: '5px 0px 5px 14px',
34 toggableIconContainer: {
35 color: theme.palette.grey["700"],
43 color: theme.palette.primary.main,
46 transition: 'all 0.1s ease',
49 transition: 'all 0.1s ease',
50 transform: 'rotate(90deg)',
54 export interface SidePanelItem {
62 activeAction?: (dispatch: Dispatch, uuid?: string) => void;
65 interface SidePanelDataProps {
66 toggleOpen: (id: string) => void;
67 toggleActive: (id: string) => void;
68 sidePanelItems: SidePanelItem[];
69 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: SidePanelItem) => void;
72 type SidePanelProps = SidePanelDataProps & WithStyles<CssRules>;
74 export const SidePanel = withStyles(styles)(
75 class extends React.Component<SidePanelProps> {
76 render(): ReactElement<any> {
77 const { classes, toggleOpen, toggleActive, sidePanelItems, children } = this.props;
78 const { root, row, list, toggableIconContainer } = classes;
80 <div className={root}>
82 {sidePanelItems.map(it => (
84 <ListItem button className={list} onClick={() => toggleActive(it.id)}
85 onContextMenu={this.handleRowContextMenu(it)}>
86 <span className={row}>
88 <i onClick={() => toggleOpen(it.id)} className={toggableIconContainer}>
90 className={this.getToggableIconClassNames(it.open, it.active)}>
91 < SidePanelRightArrowIcon/>
95 <ListItemTextIcon icon={it.icon} name={it.name} isActive={it.active}
96 hasMargin={it.margin}/>
100 <Collapse in={it.open} timeout="auto" unmountOnExit>
111 getToggableIconClassNames = (isOpen?: boolean, isActive ?: boolean) => {
112 const { iconOpen, iconClose, active, toggableIcon } = this.props.classes;
113 return classnames(toggableIcon, {
115 [iconClose]: !isOpen,
120 handleRowContextMenu = (item: SidePanelItem) =>
121 (event: React.MouseEvent<HTMLElement>) =>
122 item.openAble ? this.props.onContextMenu(event, item) : null