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';
25 import classNames from 'classnames';
26 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
41 | 'contextMenuSection'
46 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
52 border: '2px solid transparent',
55 border: '2px solid #ccc',
58 color: theme.palette.primary.main,
62 color: theme.palette.grey['600'],
75 marginRight: '0.8rem',
79 flexDirection: 'column',
80 transition: 'height 0.3s ease',
85 justifyContent: 'space-between',
94 margin: 'auto 0 0.5rem 0.3rem',
95 color: theme.palette.text.primary,
100 marginTop: '0.57rem',
102 color: theme.palette.text.primary,
104 contextMenuSection: {
106 flexDirection: 'row',
107 alignItems: 'center',
123 const mapStateToProps = (state: RootState) => {
124 const currentRoute = state.router.location?.pathname.split('/') || [];
125 const currentItemUuid = currentRoute[currentRoute.length - 1];
126 const currentResource = getResource(currentItemUuid)(state.resources);
127 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(state.resources);
128 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
129 const isSelected = currentItemUuid === state.detailsPanel.resourceUuid && state.detailsPanel.isOpened === true;
132 isAdmin: state.auth.user?.isAdmin,
139 const mapDispatchToProps = (dispatch: Dispatch) => ({
140 handleCardClick: (uuid: string) => {
141 dispatch<any>(loadDetailsPanel(uuid));
143 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: any, isAdmin: boolean) => {
144 event.stopPropagation();
145 // When viewing the contents of a filter group, all contents should be treated as read only.
146 let readOnly = false;
147 if (resource.groupClass === 'filter') {
150 const menuKind = dispatch<any>(resourceUuidToContextMenuKind(resource.uuid, readOnly));
151 if (menuKind === ContextMenuKind.ROOT_PROJECT) {
152 dispatch<any>(openUserContextMenu(event, resource as UserResource));
153 } else if (menuKind && resource) {
155 openContextMenu(event, {
158 ownerUuid: resource.ownerUuid,
159 isTrashed: 'isTrashed' in resource ? resource.isTrashed : false,
163 isFrozen: !!resource.frozenByUuid,
164 description: resource.description,
165 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
166 properties: 'properties' in resource ? resource.properties : {},
173 type DetailsCardProps = WithStyles<CssRules> & {
174 currentResource: ProjectResource | UserResource;
175 frozenByFullName?: string;
178 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
179 handleCardClick: (resource: any) => void;
182 type UserCardProps = WithStyles<CssRules> & {
183 currentResource: UserResource;
186 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
187 handleCardClick: (resource: any) => void;
190 type ProjectCardProps = WithStyles<CssRules> & {
191 currentResource: ProjectResource;
192 frozenByFullName: string | undefined;
195 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
196 handleCardClick: (resource: any) => void;
199 export const ProjectDetailsCard = connect(
203 withStyles(styles)((props: DetailsCardProps) => {
204 const { classes, currentResource, frozenByFullName, handleContextMenu, handleCardClick, isAdmin, isSelected } = props;
205 switch (currentResource.kind as string) {
206 case ResourceKind.USER:
210 currentResource={currentResource as UserResource}
212 isSelected={isSelected}
213 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
214 handleCardClick={handleCardClick}
217 case ResourceKind.PROJECT:
221 currentResource={currentResource as ProjectResource}
222 frozenByFullName={frozenByFullName}
224 isSelected={isSelected}
225 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
226 handleCardClick={handleCardClick}
235 const UserCard: React.FC<UserCardProps> = ({ classes, currentResource, handleContextMenu, handleCardClick, isAdmin, isSelected }) => {
236 const { fullName, uuid } = currentResource as UserResource & { fullName: string };
239 <Card className={classNames(classes.root, isSelected ? classes.selected : '')} onClick={()=>handleCardClick(uuid)}>
241 className={classes.cardHeader}
243 <section className={classes.nameContainer}>
253 <section className={classes.contextMenuSection}>
254 {!currentResource.isActive && (
256 <UserResourceAccountStatus uuid={uuid} />
264 aria-label='More options'
265 onClick={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
277 const ProjectCard: React.FC<ProjectCardProps> = ({ classes, currentResource, frozenByFullName, handleContextMenu, handleCardClick, isAdmin, isSelected }) => {
278 const { name, description, uuid } = currentResource as ProjectResource;
279 const [showDescription, setShowDescription] = React.useState(false);
281 const toggleDescription = () => {
282 setShowDescription(!showDescription);
286 <Card className={classNames(classes.root, isSelected ? classes.selected : '')} onClick={()=>handleCardClick(uuid)}>
288 className={classes.cardHeader}
290 <section className={classes.namePlate}>
294 style={{ marginRight: '1rem' }}
299 className={classes.faveIcon}
300 resourceUuid={currentResource.uuid}
303 className={classes.faveIcon}
304 resourceUuid={currentResource.uuid}
306 {!!frozenByFullName && (
308 className={classes.frozenIcon}
309 title={<span>Project was frozen by {frozenByFullName}</span>}
311 <FreezeIcon style={{ fontSize: 'inherit' }} />
317 <section className={classes.contextMenuSection}>
323 aria-label='More options'
324 onClick={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
332 <CardContent className={classes.cardContent}>
333 <section className={classes.subHeader}>
334 <section className={classes.chipSection}>
335 <Typography component='div'>
336 {typeof currentResource.properties === 'object' &&
337 Object.keys(currentResource.properties).map((k) =>
338 Array.isArray(currentResource.properties[k])
339 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
340 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)
344 <section className={classes.descriptionLabel} onClick={(ev)=>ev.stopPropagation()}>
347 className={classes.showMore}
348 onClick={toggleDescription}
350 {!showDescription ? "Show full description" : "Hide full description"}
353 <Typography className={classes.noDescription}>no description available</Typography>
357 <Collapse in={showDescription} timeout='auto'>
358 <section onClick={(ev)=>ev.stopPropagation()}>
359 <Typography className={classes.description}>