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, Grid } 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 { FreezeIcon } from 'components/icon/icon';
18 import { Resource } from 'models/resource';
19 import { ContextMenuResource } from 'store/context-menu/context-menu-actions';
20 import { openContextMenu, resourceUuidToContextMenuKind } from 'store/context-menu/context-menu-actions';
21 import { CollectionResource } from 'models/collection';
22 import { ContextMenuKind } from 'views-components/context-menu/context-menu';
23 import { Dispatch } from 'redux';
24 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
25 import { ExpandChevronRight } from 'components/expand-chevron-right/expand-chevron-right';
26 import { MultiselectToolbar } from 'components/multiselect-toolbar/MultiselectToolbar';
30 | 'cardHeaderContainer'
41 | 'accountStatusSection'
46 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
52 border: '2px solid transparent',
56 background: 'linear-gradient(to right, black, transparent)',
57 backgroundClip: 'text',
61 color: theme.palette.grey['600'],
68 cardHeaderContainer: {
72 justifyContent: 'space-between',
76 padding: '0.2rem 0.4rem 0.1rem 1rem',
82 paddingBottom: '0.5rem',
86 flexDirection: 'column',
87 marginTop: '-1.75rem',
93 justifyContent: 'space-between',
100 paddingBottom: '0.5rem',
104 margin: 'auto 0 0.5rem 0.3rem',
105 color: theme.palette.text.primary,
109 marginLeft: '0.3rem',
112 color: theme.palette.text.primary,
114 accountStatusSection: {
116 flexDirection: 'row',
117 alignItems: 'center',
122 paddingBottom: '-1rem',
134 const mapStateToProps = ({ auth, selectedResourceUuid, resources, properties }: RootState) => {
135 const currentResource = getResource(properties.currentRouteUuid)(resources);
136 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(resources);
137 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
138 const isSelected = selectedResourceUuid === properties.currentRouteUuid;
141 isAdmin: auth.user?.isAdmin,
148 const mapDispatchToProps = (dispatch: Dispatch) => ({
149 handleCardClick: (uuid: string) => {
150 dispatch<any>(loadDetailsPanel(uuid));
152 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: any, isAdmin: boolean) => {
153 event.stopPropagation();
154 // When viewing the contents of a filter group, all contents should be treated as read only.
155 let readOnly = false;
156 if (resource.groupClass === 'filter') {
159 let menuKind = dispatch<any>(resourceUuidToContextMenuKind(resource.uuid, readOnly));
160 if (menuKind === ContextMenuKind.ROOT_PROJECT) {
161 menuKind = ContextMenuKind.USER_DETAILS;
163 if (menuKind && resource) {
165 openContextMenu(event, {
168 ownerUuid: resource.ownerUuid,
169 isTrashed: 'isTrashed' in resource ? resource.isTrashed : false,
173 isFrozen: !!resource.frozenByUuid,
174 description: resource.description,
175 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
176 properties: 'properties' in resource ? resource.properties : {},
183 type DetailsCardProps = WithStyles<CssRules> & {
184 currentResource: ProjectResource | UserResource;
185 frozenByFullName?: string;
188 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
189 handleCardClick: (resource: any) => void;
192 type UserCardProps = WithStyles<CssRules> & {
193 currentResource: UserResource;
196 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
197 handleCardClick: (resource: any) => void;
200 type ProjectCardProps = WithStyles<CssRules> & {
201 currentResource: ProjectResource;
202 frozenByFullName: string | undefined;
205 handleCardClick: (resource: any) => void;
208 export const ProjectDetailsCard = connect(
212 withStyles(styles)((props: DetailsCardProps) => {
213 const { classes, currentResource, frozenByFullName, handleContextMenu, handleCardClick, isAdmin, isSelected } = props;
214 if (!currentResource) {
217 switch (currentResource.kind as string) {
218 case ResourceKind.USER:
222 currentResource={currentResource as UserResource}
224 isSelected={isSelected}
225 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
226 handleCardClick={handleCardClick}
229 case ResourceKind.PROJECT:
233 currentResource={currentResource as ProjectResource}
234 frozenByFullName={frozenByFullName}
236 isSelected={isSelected}
237 handleCardClick={handleCardClick}
246 const UserCard: React.FC<UserCardProps> = ({ classes, currentResource, handleContextMenu, handleCardClick, isAdmin, isSelected }) => {
247 const { fullName, uuid } = currentResource as UserResource & { fullName: string };
251 className={classes.root}
252 onClick={() => handleCardClick(uuid)}
253 data-cy='user-details-card'
258 className={classes.cardHeaderContainer}
261 className={classes.cardHeader}
263 <section className={classes.userNameContainer}>
270 <section className={classes.accountStatusSection}>
271 {!currentResource.isActive && (
273 <UserResourceAccountStatus uuid={uuid} />
280 {isSelected && <MultiselectToolbar />}
286 const ProjectCard: React.FC<ProjectCardProps> = ({ classes, currentResource, frozenByFullName, handleCardClick, isSelected }) => {
287 const { name, description, uuid } = currentResource as ProjectResource;
288 const [showDescription, setShowDescription] = React.useState(false);
289 const [showProperties, setShowProperties] = React.useState(false);
291 const toggleDescription = () => {
292 setShowDescription(!showDescription);
295 const toggleProperties = () => {
296 setShowProperties(!showProperties);
301 className={classes.root}
302 onClick={() => handleCardClick(uuid)}
303 data-cy='project-details-card'
308 className={classes.cardHeaderContainer}
311 className={classes.cardHeader}
313 <section className={classes.nameSection}>
314 <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 {isSelected && <MultiselectToolbar />}
344 <section onClick={(ev) => ev.stopPropagation()}>
347 onClick={toggleDescription}
348 className={classes.descriptionToggle}
350 <ExpandChevronRight expanded={showDescription} />
351 <section className={classes.showMore}>
355 collapsedHeight='1.25rem'
358 className={classes.description}
359 data-cy='project-description'
368 className={classes.noDescription}
369 data-cy='no-description'
371 no description available
374 {typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0 ? (
376 onClick={toggleProperties}
377 className={classes.descriptionToggle}
379 <ExpandChevronRight expanded={showProperties} />
380 <section className={classes.showMore}>
384 collapsedHeight='35px'
387 className={classes.description}
388 data-cy='project-description'
390 <CardContent className={classes.cardContent}>
391 <Typography component='div'>
392 {Object.keys(currentResource.properties).map((k) =>
393 Array.isArray(currentResource.properties[k])
394 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
395 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)