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';
40 | 'contextMenuSection'
44 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
50 border: '2px solid transparent',
53 border: '2px solid #ccc',
56 color: theme.palette.primary.main,
60 color: theme.palette.grey['600'],
67 padding: '0.2rem 0.4rem 0.1rem 1rem',
73 flexDirection: 'column',
74 marginTop: '-1.75rem',
81 paddingBottom: '0.5rem',
85 margin: 'auto 0 0.5rem 0.3rem',
86 color: theme.palette.text.primary,
93 color: theme.palette.text.primary,
99 paddingTop: '0.25rem',
110 const mapStateToProps = (state: RootState) => {
111 const currentRoute = state.router.location?.pathname.split('/') || [];
112 const currentItemUuid = currentRoute[currentRoute.length - 1];
113 const currentResource = getResource(currentItemUuid)(state.resources);
114 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(state.resources);
115 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
116 const isSelected = currentItemUuid === state.detailsPanel.resourceUuid && state.detailsPanel.isOpened === true;
119 isAdmin: state.auth.user?.isAdmin,
126 const mapDispatchToProps = (dispatch: Dispatch) => ({
127 handleCardClick: (uuid: string) => {
128 dispatch<any>(loadDetailsPanel(uuid));
130 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: any, isAdmin: boolean) => {
131 event.stopPropagation();
132 // When viewing the contents of a filter group, all contents should be treated as read only.
133 let readOnly = false;
134 if (resource.groupClass === 'filter') {
137 let menuKind = dispatch<any>(resourceUuidToContextMenuKind(resource.uuid, readOnly));
138 if (menuKind === ContextMenuKind.ROOT_PROJECT) {
139 menuKind = ContextMenuKind.USER_DETAILS;
141 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;
166 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
167 handleCardClick: (resource: any) => void;
170 type UserCardProps = WithStyles<CssRules> & {
171 currentResource: UserResource;
174 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
175 handleCardClick: (resource: any) => void;
178 type ProjectCardProps = WithStyles<CssRules> & {
179 currentResource: ProjectResource;
180 frozenByFullName: string | undefined;
183 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
184 handleCardClick: (resource: any) => void;
187 export const ProjectDetailsCard = connect(
191 withStyles(styles)((props: DetailsCardProps) => {
192 const { classes, currentResource, frozenByFullName, handleContextMenu, handleCardClick, isAdmin, isSelected } = props;
193 if (!currentResource) {
196 switch (currentResource.kind as string) {
197 case ResourceKind.USER:
201 currentResource={currentResource as UserResource}
203 isSelected={isSelected}
204 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
205 handleCardClick={handleCardClick}
208 case ResourceKind.PROJECT:
212 currentResource={currentResource as ProjectResource}
213 frozenByFullName={frozenByFullName}
215 isSelected={isSelected}
216 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
217 handleCardClick={handleCardClick}
226 const UserCard: React.FC<UserCardProps> = ({ classes, currentResource, handleContextMenu, handleCardClick, isAdmin, isSelected }) => {
227 const { fullName, uuid } = currentResource as UserResource & { fullName: string };
231 className={classNames(classes.root, isSelected ? classes.selected : '')}
232 onClick={() => handleCardClick(uuid)}
233 data-cy='user-details-card'
236 className={classes.cardHeader}
238 <section className={classes.userNameContainer}>
248 <section className={classes.contextMenuSection}>
249 {!currentResource.isActive && (
251 <UserResourceAccountStatus uuid={uuid} />
259 aria-label='More options'
261 onClick={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
273 const ProjectCard: React.FC<ProjectCardProps> = ({ classes, currentResource, frozenByFullName, handleContextMenu, handleCardClick, isAdmin, isSelected }) => {
274 const { name, description, uuid } = currentResource as ProjectResource;
275 const [showDescription, setShowDescription] = React.useState(false);
277 const toggleDescription = () => {
278 setShowDescription(!showDescription);
283 className={classNames(classes.root, isSelected ? classes.selected : '')}
284 onClick={() => handleCardClick(uuid)}
285 data-cy='project-details-card'
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}
310 title={<span>Project was frozen by {frozenByFullName}</span>}
312 <FreezeIcon style={{ fontSize: 'inherit' }} />
318 <section className={classes.contextMenuSection}>
320 className={classes.descriptionLabel}
321 onClick={(ev) => ev.stopPropagation()}
325 className={classes.showMore}
326 onClick={toggleDescription}
327 data-cy='toggle-description'
329 {!showDescription ? 'Show full description' : 'Hide full description'}
333 className={classes.noDescription}
334 data-cy='no-description'
336 no description available
345 aria-label='More options'
346 onClick={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
348 <MoreVerticalIcon data-cy='kebab-icon' />
354 {typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0 && (
355 <CardContent className={classes.cardContent}>
356 <Typography component='div'>
357 {Object.keys(currentResource.properties).map((k) =>
358 Array.isArray(currentResource.properties[k])
359 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
360 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)
369 <section onClick={(ev) => ev.stopPropagation()}>
371 className={classes.description}
372 data-cy='project-description'