1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { StyleRulesCallback, Card, CardHeader, WithStyles, withStyles, Typography, CardContent, Tooltip, Collapse } from '@material-ui/core';
7 import { ArvadosTheme } from 'common/custom-theme';
8 import { RootState } from 'store/store';
9 import { connect } from 'react-redux';
10 import { getResource } from 'store/resources/resources';
11 import { getPropertyChip } from '../resource-properties-form/property-chip';
12 import { ProjectResource } from 'models/project';
13 import { ResourceKind } from 'models/resource';
14 import { UserResource } from 'models/user';
15 import { UserResourceAccountStatus } from 'views-components/data-explorer/renderers';
16 import { FavoriteStar, PublicFavoriteStar } from 'views-components/favorite-star/favorite-star';
17 import { MoreVerticalIcon, FreezeIcon } from 'components/icon/icon';
18 import { Resource } from 'models/resource';
19 import { IconButton } from '@material-ui/core';
20 import { ContextMenuResource } from 'store/context-menu/context-menu-actions';
21 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
22 import { CollectionResource } from 'models/collection';
23 import { ContextMenuKind } from 'views-components/context-menu/context-menu';
24 import { Dispatch } from 'redux';
25 import classNames from 'classnames';
26 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
27 import { ExpandChevronRight } from 'components/expand-chevron-right/expand-chevron-right';
28 import { MultiselectToolbar } from 'components/multiselect-toolbar/MultiselectToolbar';
43 | 'contextMenuSection'
48 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
54 borderLeft: '2px solid transparent',
57 border: '2pcx solid #ccc',
61 background: 'linear-gradient(to right, black, transparent)',
62 backgroundClip: 'text',
66 color: theme.palette.grey['600'],
73 padding: '0.2rem 0.4rem 0.1rem 1rem',
79 paddingBottom: '0.5rem',
83 flexDirection: 'column',
84 marginTop: '-1.75rem',
90 justifyContent: 'space-between',
97 paddingBottom: '0.5rem',
101 margin: 'auto 0 0.5rem 0.3rem',
102 color: theme.palette.text.primary,
106 marginLeft: '0.3rem',
109 color: theme.palette.text.primary,
111 contextMenuSection: {
113 flexDirection: 'row',
114 alignItems: 'center',
115 paddingTop: '0.25rem',
119 paddingBottom: '-1rem',
131 const mapStateToProps = ({auth, selectedResourceUuid, resources, properties}: RootState) => {
132 const currentResource = getResource(properties.currentRouteUuid)(resources);
133 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(resources);
134 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
135 const isSelected = selectedResourceUuid === properties.currentRouteUuid;
138 isAdmin: auth.user?.isAdmin,
145 const mapDispatchToProps = (dispatch: Dispatch) => ({
146 handleCardClick: (uuid: string) => {
147 dispatch<any>(loadDetailsPanel(uuid));
149 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: any, isAdmin: boolean) => {
150 event.stopPropagation();
151 // When viewing the contents of a filter group, all contents should be treated as read only.
152 let readOnly = false;
153 if (resource.groupClass === 'filter') {
156 let menuKind = dispatch<any>(resourceUuidToContextMenuKind(resource.uuid, readOnly));
157 if (menuKind === ContextMenuKind.ROOT_PROJECT) {
158 menuKind = ContextMenuKind.USER_DETAILS;
160 if (menuKind && resource) {
162 openContextMenu(event, {
165 ownerUuid: resource.ownerUuid,
166 isTrashed: 'isTrashed' in resource ? resource.isTrashed : false,
170 isFrozen: !!resource.frozenByUuid,
171 description: resource.description,
172 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
173 properties: 'properties' in resource ? resource.properties : {},
180 type DetailsCardProps = WithStyles<CssRules> & {
181 currentResource: ProjectResource | UserResource;
182 frozenByFullName?: string;
185 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
186 handleCardClick: (resource: any) => void;
189 type UserCardProps = WithStyles<CssRules> & {
190 currentResource: UserResource;
193 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
194 handleCardClick: (resource: any) => void;
197 type ProjectCardProps = WithStyles<CssRules> & {
198 currentResource: ProjectResource;
199 frozenByFullName: string | undefined;
202 handleCardClick: (resource: any) => void;
205 export const ProjectDetailsCard = connect(
209 withStyles(styles)((props: DetailsCardProps) => {
210 const { classes, currentResource, frozenByFullName, handleContextMenu, handleCardClick, isAdmin, isSelected } = props;
211 if (!currentResource) {
214 switch (currentResource.kind as string) {
215 case ResourceKind.USER:
219 currentResource={currentResource as UserResource}
221 isSelected={isSelected}
222 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
223 handleCardClick={handleCardClick}
226 case ResourceKind.PROJECT:
230 currentResource={currentResource as ProjectResource}
231 frozenByFullName={frozenByFullName}
233 isSelected={isSelected}
234 handleCardClick={handleCardClick}
243 const UserCard: React.FC<UserCardProps> = ({ classes, currentResource, handleContextMenu, handleCardClick, isAdmin, isSelected }) => {
244 const { fullName, uuid } = currentResource as UserResource & { fullName: string };
248 className={classNames(classes.root, isSelected ? classes.selected : '')}
249 onClick={() => handleCardClick(uuid)}
250 data-cy='user-details-card'
253 className={classes.cardHeader}
255 <section className={classes.userNameContainer}>
265 <section className={classes.contextMenuSection}>
266 {!currentResource.isActive && (
268 <UserResourceAccountStatus uuid={uuid} />
276 aria-label='More options'
278 onClick={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
290 const ProjectCard: React.FC<ProjectCardProps> = ({ classes, currentResource, frozenByFullName, handleCardClick, isSelected }) => {
291 const { name, description, uuid } = currentResource as ProjectResource;
292 const [showDescription, setShowDescription] = React.useState(false);
293 const [showProperties, setShowProperties] = React.useState(false);
295 const toggleDescription = () => {
296 setShowDescription(!showDescription);
299 const toggleProperties = () => {
300 setShowProperties(!showProperties);
305 className={classNames(classes.root, isSelected ? classes.selected : '')}
306 onClick={() => handleCardClick(uuid)}
307 data-cy='project-details-card'
310 className={classes.cardHeader}
312 <section className={classes.nameSection}>
313 <section className={classes.namePlate}>
317 style={{ marginRight: '1rem' }}
322 className={classes.faveIcon}
323 resourceUuid={currentResource.uuid}
326 className={classes.faveIcon}
327 resourceUuid={currentResource.uuid}
329 {!!frozenByFullName && (
331 className={classes.frozenIcon}
333 title={<span>Project was frozen by {frozenByFullName}</span>}
335 <FreezeIcon style={{ fontSize: 'inherit' }} />
342 <section className={classes.toolbarSection}>
343 {isSelected && <MultiselectToolbar />}
347 <section onClick={(ev) => ev.stopPropagation()}>
350 onClick={toggleDescription}
351 className={classes.descriptionToggle}
353 <ExpandChevronRight expanded={showDescription} />
354 <section className={classes.showMore}>
358 collapsedHeight='1.25rem'
361 className={classes.description}
362 data-cy='project-description'
371 className={classes.noDescription}
372 data-cy='no-description'
374 no description available
377 {typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0 ? (
379 onClick={toggleProperties}
380 className={classes.descriptionToggle}
382 <ExpandChevronRight expanded={showProperties} />
383 <section className={classes.showMore}>
387 collapsedHeight='35px'
390 className={classes.description}
391 data-cy='project-description'
393 <CardContent className={classes.cardContent}>
394 <Typography component='div'>
395 {Object.keys(currentResource.properties).map((k) =>
396 Array.isArray(currentResource.properties[k])
397 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
398 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)