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, openUserContextMenu } 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';
38 | 'contextMenuSection'
43 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
51 color: theme.palette.primary.main,
55 color: theme.palette.grey['600'],
68 marginRight: '0.8rem',
72 flexDirection: 'column',
73 transition: 'height 0.3s ease',
78 justifyContent: 'space-between',
87 margin: 'auto 0 0.5rem 0.3rem',
88 color: theme.palette.text.primary,
95 color: theme.palette.text.primary,
100 alignItems: 'center',
116 const mapStateToProps = (state: RootState) => {
117 const currentRoute = state.router.location?.pathname.split('/') || [];
118 const currentItemUuid = currentRoute[currentRoute.length - 1];
119 const currentResource = getResource(currentItemUuid)(state.resources);
120 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(state.resources);
121 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
124 isAdmin: state.auth.user?.isAdmin,
130 const mapDispatchToProps = (dispatch: Dispatch) => ({
131 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: any, isAdmin: boolean) => {
132 event.stopPropagation();
133 // When viewing the contents of a filter group, all contents should be treated as read only.
134 let readOnly = false;
135 if (resource.groupClass === 'filter') {
138 const menuKind = dispatch<any>(resourceUuidToContextMenuKind(resource.uuid, readOnly));
139 if (menuKind === ContextMenuKind.ROOT_PROJECT) {
140 dispatch<any>(openUserContextMenu(event, resource as UserResource));
141 } else if (menuKind && resource) {
143 openContextMenu(event, {
146 ownerUuid: resource.ownerUuid,
147 isTrashed: 'isTrashed' in resource ? resource.isTrashed : false,
151 isFrozen: !!resource.frozenByUuid,
152 description: resource.description,
153 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
154 properties: 'properties' in resource ? resource.properties : {},
161 type DetailsCardProps = WithStyles<CssRules> & {
162 currentResource: ProjectResource | UserResource;
163 frozenByFullName?: string;
165 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
168 type UserCardProps = WithStyles<CssRules> & {
169 currentResource: UserResource;
171 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
174 type ProjectCardProps = WithStyles<CssRules> & {
175 currentResource: ProjectResource;
176 frozenByFullName: string | undefined;
178 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
181 export const ProjectDetailsCard = connect(
185 withStyles(styles)((props: DetailsCardProps) => {
186 const { classes, currentResource, frozenByFullName, handleContextMenu, isAdmin } = props;
187 switch (currentResource.kind as string) {
188 case ResourceKind.USER:
192 currentResource={currentResource as UserResource}
194 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
197 case ResourceKind.PROJECT:
201 currentResource={currentResource as ProjectResource}
202 frozenByFullName={frozenByFullName}
204 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
213 const UserCard: React.FC<UserCardProps> = ({ classes, currentResource, handleContextMenu, isAdmin }) => {
214 const { fullName, uuid } = currentResource as UserResource & { fullName: string };
217 <Card className={classes.root}>
219 className={classes.cardHeader}
221 <section className={classes.nameContainer}>
231 <section className={classes.contextMenuSection}>
232 {!currentResource.isActive && (
234 <UserResourceAccountStatus uuid={uuid} />
242 aria-label='More options'
243 onClick={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
255 const ProjectCard: React.FC<ProjectCardProps> = ({ classes, currentResource, frozenByFullName, handleContextMenu, isAdmin }) => {
256 const { name, description } = currentResource as ProjectResource;
257 const [showDescription, setShowDescription] = React.useState(false);
259 const toggleDescription = () => {
260 setShowDescription(!showDescription);
264 <Card className={classes.root}>
266 className={classes.cardHeader}
268 <section className={classes.namePlate}>
272 style={{ marginRight: '1rem' }}
277 className={classes.faveIcon}
278 resourceUuid={currentResource.uuid}
281 className={classes.faveIcon}
282 resourceUuid={currentResource.uuid}
284 {!!frozenByFullName && (
286 className={classes.frozenIcon}
287 title={<span>Project was frozen by {frozenByFullName}</span>}
289 <FreezeIcon style={{ fontSize: 'inherit' }} />
295 <section className={classes.contextMenuSection}>
301 aria-label='More options'
302 onClick={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
310 <CardContent className={classes.cardContent}>
311 <section className={classes.subHeader}>
312 <section className={classes.chipSection}>
313 <Typography component='div'>
314 {typeof currentResource.properties === 'object' &&
315 Object.keys(currentResource.properties).map((k) =>
316 Array.isArray(currentResource.properties[k])
317 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
318 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)
322 <section className={classes.descriptionLabel}>
325 className={classes.showMore}
326 onClick={toggleDescription}
328 {!showDescription ? "Show full description" : "Hide full description"}
331 <Typography className={classes.noDescription}>no description available</Typography>
335 <Collapse in={showDescription} timeout='auto'>
337 <Typography className={classes.description}>