1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React, { ReactElement } from 'react'
6 import { connect } from 'react-redux'
7 import { ProjectsIcon, ProcessIcon, FavoriteIcon, ShareMeIcon, TrashIcon, PublicFavoriteIcon, GroupsIcon, ResourceIcon } from 'components/icon/icon'
8 import { TerminalIcon } from 'components/icon/icon'
9 import { IconButton, List, ListItem, Tooltip } from '@material-ui/core'
10 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles'
11 import { ArvadosTheme } from 'common/custom-theme'
12 import { navigateTo, navigateToInstanceTypes } from 'store/navigation/navigation-action'
13 import { RootState } from 'store/store'
14 import { Dispatch } from 'redux'
16 navigateToSharedWithMe,
17 navigateToPublicFavorites,
20 navigateToAllProcesses,
22 } from 'store/navigation/navigation-action'
23 import { navigateToUserVirtualMachines } from 'store/navigation/navigation-action'
24 import { RouterAction } from 'react-router-redux'
25 import { User } from 'models/user'
27 type CssRules = 'button' | 'unselected' | 'selected'
29 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
34 marginLeft: '-0.6rem',
38 color: theme.customs.colors.grey600,
41 color: theme.palette.primary.main,
45 enum SidePanelCollapsedCategory {
46 PROJECTS = 'Home Projects',
47 FAVORITES = 'My Favorites',
48 PUBLIC_FAVORITES = 'Public Favorites',
49 SHARED_WITH_ME = 'Shared with me',
50 ALL_PROCESSES = 'All Processes',
51 INSTANCE_TYPES = 'Instance Types',
52 SHELL_ACCESS = 'Shell Access',
57 type TCollapsedCategory = {
58 name: SidePanelCollapsedCategory
60 navTarget: RouterAction | ''
63 const sidePanelCollapsedCategories: TCollapsedCategory[] = [
65 name: SidePanelCollapsedCategory.PROJECTS,
66 icon: <ProjectsIcon />,
70 name: SidePanelCollapsedCategory.FAVORITES,
71 icon: <FavoriteIcon />,
72 navTarget: navigateToFavorites,
75 name: SidePanelCollapsedCategory.PUBLIC_FAVORITES,
76 icon: <PublicFavoriteIcon />,
77 navTarget: navigateToPublicFavorites,
80 name: SidePanelCollapsedCategory.SHARED_WITH_ME,
81 icon: <ShareMeIcon />,
82 navTarget: navigateToSharedWithMe,
85 name: SidePanelCollapsedCategory.ALL_PROCESSES,
86 icon: <ProcessIcon />,
87 navTarget: navigateToAllProcesses,
90 name: SidePanelCollapsedCategory.INSTANCE_TYPES,
91 icon: <ResourceIcon />,
92 navTarget: navigateToInstanceTypes,
95 name: SidePanelCollapsedCategory.SHELL_ACCESS,
96 icon: <TerminalIcon />,
97 navTarget: navigateToUserVirtualMachines,
100 name: SidePanelCollapsedCategory.GROUPS,
101 icon: <GroupsIcon style={{marginLeft: '2px', scale: '85%'}}/>,
102 navTarget: navigateToGroups,
105 name: SidePanelCollapsedCategory.TRASH,
107 navTarget: navigateToTrash,
111 type SidePanelCollapsedProps = {
113 selectedPath: string;
114 navToHome: (uuid: string) => void;
115 navTo: (navTarget: RouterAction | '') => void;
118 const mapStateToProps = ({auth, properties }: RootState) => {
121 selectedPath: properties.breadcrumbs
122 ? properties.breadcrumbs[0].label !== 'Virtual Machines'
123 ? properties.breadcrumbs[0].label
124 : SidePanelCollapsedCategory.SHELL_ACCESS
125 : SidePanelCollapsedCategory.PROJECTS,
129 const mapDispatchToProps = (dispatch: Dispatch) => {
131 navToHome: (navTarget) => dispatch<any>(navigateTo(navTarget)),
132 navTo: (navTarget) => dispatch<any>(navTarget),
136 export const SidePanelCollapsed = withStyles(styles)(
137 connect(mapStateToProps, mapDispatchToProps)(({ classes, user, selectedPath, navToHome, navTo }: WithStyles & SidePanelCollapsedProps) => {
139 const handleClick = (cat: TCollapsedCategory) => {
140 if (cat.name === SidePanelCollapsedCategory.PROJECTS) navToHome(user.uuid)
141 else navTo(cat.navTarget)
144 const { button, unselected, selected } = classes
146 <List data-cy='side-panel-collapsed'>
147 {sidePanelCollapsedCategories.map((cat) => (
150 data-cy={`collapsed-${cat.name.toLowerCase().replace(/\s+/g, '-')}`}
151 onClick={() => handleClick(cat)}
154 className={selectedPath === cat.name ? selected : unselected}
158 <IconButton className={button}>{cat.icon}</IconButton>