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',
130 const mapStateToProps = ({auth, selectedResourceUuid, resources, properties}: RootState) => {
131 const currentResource = getResource(properties.currentRouteUuid)(resources);
132 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(resources);
133 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
134 const isSelected = selectedResourceUuid === properties.currentRouteUuid;
137 isAdmin: auth.user?.isAdmin,
144 const mapDispatchToProps = (dispatch: Dispatch) => ({
145 handleCardClick: (uuid: string) => {
146 dispatch<any>(loadDetailsPanel(uuid));
148 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: any, isAdmin: boolean) => {
149 event.stopPropagation();
150 // When viewing the contents of a filter group, all contents should be treated as read only.
151 let readOnly = false;
152 if (resource.groupClass === 'filter') {
155 let menuKind = dispatch<any>(resourceUuidToContextMenuKind(resource.uuid, readOnly));
156 if (menuKind === ContextMenuKind.ROOT_PROJECT) {
157 menuKind = ContextMenuKind.USER_DETAILS;
159 if (menuKind && resource) {
161 openContextMenu(event, {
164 ownerUuid: resource.ownerUuid,
165 isTrashed: 'isTrashed' in resource ? resource.isTrashed : false,
169 isFrozen: !!resource.frozenByUuid,
170 description: resource.description,
171 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
172 properties: 'properties' in resource ? resource.properties : {},
179 type DetailsCardProps = WithStyles<CssRules> & {
180 currentResource: ProjectResource | UserResource;
181 frozenByFullName?: string;
184 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
185 handleCardClick: (resource: any) => void;
188 type UserCardProps = WithStyles<CssRules> & {
189 currentResource: UserResource;
192 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
193 handleCardClick: (resource: any) => void;
196 type ProjectCardProps = WithStyles<CssRules> & {
197 currentResource: ProjectResource;
198 frozenByFullName: string | undefined;
201 handleCardClick: (resource: any) => void;
204 export const ProjectDetailsCard = connect(
208 withStyles(styles)((props: DetailsCardProps) => {
209 const { classes, currentResource, frozenByFullName, handleContextMenu, handleCardClick, isAdmin, isSelected } = props;
210 if (!currentResource) {
213 switch (currentResource.kind as string) {
214 case ResourceKind.USER:
218 currentResource={currentResource as UserResource}
220 isSelected={isSelected}
221 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
222 handleCardClick={handleCardClick}
225 case ResourceKind.PROJECT:
229 currentResource={currentResource as ProjectResource}
230 frozenByFullName={frozenByFullName}
232 isSelected={isSelected}
233 handleCardClick={handleCardClick}
242 const UserCard: React.FC<UserCardProps> = ({ classes, currentResource, handleContextMenu, handleCardClick, isAdmin, isSelected }) => {
243 const { fullName, uuid } = currentResource as UserResource & { fullName: string };
247 className={classNames(classes.root, isSelected ? classes.selected : '')}
248 onClick={() => handleCardClick(uuid)}
249 data-cy='user-details-card'
252 className={classes.cardHeader}
254 <section className={classes.userNameContainer}>
264 <section className={classes.contextMenuSection}>
265 {!currentResource.isActive && (
267 <UserResourceAccountStatus uuid={uuid} />
275 aria-label='More options'
277 onClick={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
289 const ProjectCard: React.FC<ProjectCardProps> = ({ classes, currentResource, frozenByFullName, handleCardClick, isSelected }) => {
290 const { name, description, uuid } = currentResource as ProjectResource;
291 const [showDescription, setShowDescription] = React.useState(false);
292 const [showProperties, setShowProperties] = React.useState(false);
294 const toggleDescription = () => {
295 setShowDescription(!showDescription);
298 const toggleProperties = () => {
299 setShowProperties(!showProperties);
304 className={classNames(classes.root, isSelected ? classes.selected : '')}
305 onClick={() => handleCardClick(uuid)}
306 data-cy='project-details-card'
309 className={classes.cardHeader}
311 <section className={classes.nameSection}>
312 <section className={classes.namePlate}>
316 style={{ marginRight: '1rem' }}
321 className={classes.faveIcon}
322 resourceUuid={currentResource.uuid}
325 className={classes.faveIcon}
326 resourceUuid={currentResource.uuid}
328 {!!frozenByFullName && (
330 className={classes.frozenIcon}
332 title={<span>Project was frozen by {frozenByFullName}</span>}
334 <FreezeIcon style={{ fontSize: 'inherit' }} />
341 <section className={classes.toolbarSection}>
342 {isSelected && <MultiselectToolbar />}
346 <section onClick={(ev) => ev.stopPropagation()}>
349 onClick={toggleDescription}
350 className={classes.descriptionToggle}
352 <ExpandChevronRight expanded={showDescription} />
353 <section className={classes.showMore}>
357 collapsedHeight='1.25rem'
360 className={classes.description}
361 data-cy='project-description'
370 className={classes.noDescription}
371 data-cy='no-description'
373 no description available
376 {typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0 ? (
378 onClick={toggleProperties}
379 className={classes.descriptionToggle}
381 <ExpandChevronRight expanded={showProperties} />
382 <section className={classes.showMore}>
386 collapsedHeight='35px'
389 className={classes.description}
390 data-cy='project-description'
392 <CardContent className={classes.cardContent}>
393 <Typography component='div'>
394 {Object.keys(currentResource.properties).map((k) =>
395 Array.isArray(currentResource.properties[k])
396 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
397 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)