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';
27 import { setSelectedResourceUuid } from 'store/selected-resource/selected-resource-actions';
28 import { deselectAllOthers } from 'store/multiselect/multiselect-actions';
32 | 'cardHeaderContainer'
43 | 'accountStatusSection'
47 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
59 color: theme.palette.grey['600'],
67 cardHeaderContainer: {
71 justifyContent: 'space-between',
75 padding: '0.2rem 0.4rem 0.2rem 1rem',
81 paddingBottom: '0.5rem',
85 flexDirection: 'column',
86 marginTop: '-1.75rem',
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 accountStatusSection: {
113 flexDirection: 'row',
114 alignItems: 'center',
127 const mapStateToProps = ({ auth, selectedResourceUuid, resources, properties }: RootState) => {
128 const currentResource = getResource(properties.currentRouteUuid)(resources);
129 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(resources);
130 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
131 const isSelected = selectedResourceUuid === properties.currentRouteUuid;
134 isAdmin: auth.user?.isAdmin,
141 const mapDispatchToProps = (dispatch: Dispatch) => ({
142 handleCardClick: (uuid: string) => {
143 dispatch<any>(loadDetailsPanel(uuid));
144 dispatch<any>(setSelectedResourceUuid(uuid));
145 dispatch<any>(deselectAllOthers(uuid));
147 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: any, isAdmin: boolean) => {
148 event.stopPropagation();
149 // When viewing the contents of a filter group, all contents should be treated as read only.
150 let readOnly = false;
151 if (resource.groupClass === 'filter') {
154 let menuKind = dispatch<any>(resourceUuidToContextMenuKind(resource.uuid, readOnly));
155 if (menuKind === ContextMenuKind.ROOT_PROJECT) {
156 menuKind = ContextMenuKind.USER_DETAILS;
158 if (menuKind && resource) {
160 openContextMenu(event, {
163 ownerUuid: resource.ownerUuid,
164 isTrashed: 'isTrashed' in resource ? resource.isTrashed : false,
168 isFrozen: !!resource.frozenByUuid,
169 description: resource.description,
170 storageClassesDesired: (resource as CollectionResource).storageClassesDesired,
171 properties: 'properties' in resource ? resource.properties : {},
178 type DetailsCardProps = WithStyles<CssRules> & {
179 currentResource: ProjectResource | UserResource;
180 frozenByFullName?: string;
183 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
184 handleCardClick: (resource: any) => void;
187 type UserCardProps = WithStyles<CssRules> & {
188 currentResource: UserResource;
191 handleContextMenu: (event: React.MouseEvent<HTMLElement>, resource: ContextMenuResource, isAdmin: boolean) => void;
192 handleCardClick: (resource: any) => void;
195 type ProjectCardProps = WithStyles<CssRules> & {
196 currentResource: ProjectResource;
197 frozenByFullName: string | undefined;
200 handleCardClick: (resource: any) => void;
203 export const ProjectDetailsCard = connect(
207 withStyles(styles)((props: DetailsCardProps) => {
208 const { classes, currentResource, frozenByFullName, handleContextMenu, handleCardClick, isAdmin, isSelected } = props;
209 if (!currentResource) {
212 switch (currentResource.kind as string) {
213 case ResourceKind.USER:
217 currentResource={currentResource as UserResource}
219 isSelected={isSelected}
220 handleContextMenu={(ev) => handleContextMenu(ev, currentResource as any, isAdmin)}
221 handleCardClick={handleCardClick}
224 case ResourceKind.PROJECT:
228 currentResource={currentResource as ProjectResource}
229 frozenByFullName={frozenByFullName}
231 isSelected={isSelected}
232 handleCardClick={handleCardClick}
241 const UserCard: React.FC<UserCardProps> = ({ classes, currentResource, handleCardClick, isSelected }) => {
242 const { fullName, uuid } = currentResource as UserResource & { fullName: string };
246 className={classes.root}
247 onClick={() => handleCardClick(uuid)}
248 data-cy='user-details-card'
253 className={classes.cardHeaderContainer}
256 className={classes.cardHeader}
258 <section className={classes.userNameContainer}>
265 <section className={classes.accountStatusSection}>
266 {!currentResource.isActive && (
268 <UserResourceAccountStatus uuid={uuid} />
275 {isSelected && <MultiselectToolbar />}
281 const ProjectCard: React.FC<ProjectCardProps> = ({ classes, currentResource, frozenByFullName, handleCardClick, isSelected }) => {
282 const { name, description, uuid } = currentResource as ProjectResource;
283 const [showDescription, setShowDescription] = React.useState(false);
284 const [showProperties, setShowProperties] = React.useState(false);
286 const toggleDescription = () => {
287 setShowDescription(!showDescription);
290 const toggleProperties = () => {
291 setShowProperties(!showProperties);
296 className={classes.root}
297 onClick={() => handleCardClick(uuid)}
298 data-cy='project-details-card'
303 className={classes.cardHeaderContainer}
306 className={classes.cardHeader}
308 <section className={classes.nameSection}>
309 <section className={classes.namePlate}>
312 style={{ marginRight: '1rem' }}
317 className={classes.faveIcon}
318 resourceUuid={currentResource.uuid}
321 className={classes.faveIcon}
322 resourceUuid={currentResource.uuid}
324 {!!frozenByFullName && (
326 className={classes.frozenIcon}
328 title={<span>Project was frozen by {frozenByFullName}</span>}
330 <FreezeIcon style={{ fontSize: 'inherit' }} />
337 {isSelected && <MultiselectToolbar />}
339 <section onClick={(ev) => ev.stopPropagation()}>
342 onClick={toggleDescription}
343 className={classes.descriptionToggle}
345 <ExpandChevronRight expanded={showDescription} />
346 <section className={classes.showMore}>
350 collapsedHeight='1.25rem'
353 className={classes.description}
354 data-cy='project-description'
363 className={classes.noDescription}
364 data-cy='no-description'
366 no description available
369 {typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0 ? (
371 onClick={toggleProperties}
372 className={classes.descriptionToggle}
374 <ExpandChevronRight expanded={showProperties} />
375 <section className={classes.showMore}>
379 collapsedHeight='35px'
382 className={classes.description}
383 data-cy='project-description'
385 <CardContent className={classes.cardContent}>
386 <Typography component='div'>
387 {Object.keys(currentResource.properties).map((k) =>
388 Array.isArray(currentResource.properties[k])
389 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
390 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)