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 { Dispatch } from 'redux';
20 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
21 import { ExpandChevronRight } from 'components/expand-chevron-right/expand-chevron-right';
22 import { MultiselectToolbar } from 'components/multiselect-toolbar/MultiselectToolbar';
23 import { setSelectedResourceUuid } from 'store/selected-resource/selected-resource-actions';
24 import { deselectAllOthers } from 'store/multiselect/multiselect-actions';
28 | 'cardHeaderContainer'
40 | 'accountStatusSection'
45 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
57 color: theme.palette.grey['600'],
59 padding: '0 0 0.5rem 1rem',
67 cardHeaderContainer: {
71 justifyContent: 'space-between',
75 padding: '0.2rem 0.4rem 0.2rem 1rem',
78 //shows only the first 3 buttons
79 width: '12rem !important',
85 paddingBottom: '0.5rem',
89 flexDirection: 'column',
91 paddingLeft: '0.1rem',
100 flexDirection: 'row',
101 alignItems: 'center',
107 margin: 'auto 0 1rem 0.3rem',
108 color: theme.palette.text.primary,
112 marginLeft: '0.3rem',
114 color: theme.palette.text.primary,
116 accountStatusSection: {
118 flexDirection: 'row',
119 alignItems: 'center',
123 marginBottom: '-2rem',
126 marginRight: '0.75rem',
127 marginBottom: '0.5rem',
135 const mapStateToProps = ({ auth, selectedResourceUuid, resources, properties }: RootState) => {
136 const currentResource = getResource(properties.currentRouteUuid)(resources);
137 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(resources);
138 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
139 const isSelected = selectedResourceUuid === properties.currentRouteUuid;
142 isAdmin: auth.user?.isAdmin,
149 const mapDispatchToProps = (dispatch: Dispatch) => ({
150 handleCardClick: (uuid: string) => {
151 dispatch<any>(loadDetailsPanel(uuid));
152 dispatch<any>(setSelectedResourceUuid(uuid));
153 dispatch<any>(deselectAllOthers(uuid));
158 type DetailsCardProps = WithStyles<CssRules> & {
159 currentResource: ProjectResource | UserResource;
160 frozenByFullName?: string;
163 handleCardClick: (resource: any) => void;
166 type UserCardProps = WithStyles<CssRules> & {
167 currentResource: UserResource;
170 handleCardClick: (resource: any) => void;
173 type ProjectCardProps = WithStyles<CssRules> & {
174 currentResource: ProjectResource;
175 frozenByFullName: string | undefined;
178 handleCardClick: (resource: any) => void;
181 export const ProjectDetailsCard = connect(
185 withStyles(styles)((props: DetailsCardProps) => {
186 const { classes, currentResource, frozenByFullName, handleCardClick, isAdmin, isSelected } = props;
187 if (!currentResource) {
190 switch (currentResource.kind as string) {
191 case ResourceKind.USER:
195 currentResource={currentResource as UserResource}
197 isSelected={isSelected}
198 handleCardClick={handleCardClick}
201 case ResourceKind.PROJECT:
205 currentResource={currentResource as ProjectResource}
206 frozenByFullName={frozenByFullName}
208 isSelected={isSelected}
209 handleCardClick={handleCardClick}
218 const UserCard: React.FC<UserCardProps> = ({ classes, currentResource, handleCardClick, isSelected }) => {
219 const { fullName, uuid } = currentResource as UserResource & { fullName: string };
223 className={classes.root}
224 onClick={() => handleCardClick(uuid)}
225 data-cy='user-details-card'
230 className={classes.cardHeaderContainer}
233 className={classes.cardHeader}
235 <section className={classes.userNameContainer}>
242 <section className={classes.accountStatusSection}>
243 {!currentResource.isActive && (
245 <UserResourceAccountStatus uuid={uuid} />
252 {isSelected && <MultiselectToolbar />}
258 const ProjectCard: React.FC<ProjectCardProps> = ({ classes, currentResource, frozenByFullName, handleCardClick, isSelected }) => {
259 const { name, description, uuid } = currentResource as ProjectResource;
260 const [showDescription, setShowDescription] = React.useState(false);
261 const [showProperties, setShowProperties] = React.useState(false);
263 const toggleDescription = () => {
264 setShowDescription(!showDescription);
267 const toggleProperties = () => {
268 setShowProperties(!showProperties);
273 className={classes.root}
274 onClick={() => handleCardClick(uuid)}
275 data-cy='project-details-card'
280 className={classes.cardHeaderContainer}
283 className={classes.cardHeader}
285 <section className={classes.nameSection}>
286 <section className={classes.namePlate}>
289 style={{ marginRight: '1rem' }}
294 className={classes.faveIcon}
295 resourceUuid={currentResource.uuid}
298 className={classes.faveIcon}
299 resourceUuid={currentResource.uuid}
301 {!!frozenByFullName && (
303 className={classes.frozenIcon}
305 title={<span>Project was frozen by {frozenByFullName}</span>}
307 <FreezeIcon style={{ fontSize: 'inherit' }} />
314 {isSelected && <MultiselectToolbar injectedStyles={classes.projectToolbar} />}
316 <section onClick={(ev) => ev.stopPropagation()}>
319 onClick={toggleDescription}
320 className={classes.descriptionToggle}
322 <ExpandChevronRight expanded={showDescription} />
323 <section className={classes.showMore}>
327 collapsedHeight='1.25rem'
330 className={classes.description}
331 data-cy='project-description'
332 //dangerouslySetInnerHTML is ok here only if description is sanitized,
333 //which it is before it is loaded into the redux store
334 dangerouslySetInnerHTML={{ __html: description }}
341 className={classes.noDescription}
342 data-cy='no-description'
344 no description available
347 {typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0 ? (
349 onClick={toggleProperties}
350 className={classes.descriptionToggle}
352 <ExpandChevronRight expanded={showProperties} />
353 <section className={classes.showMore}>
357 collapsedHeight='35px'
360 className={classes.description}
361 data-cy='project-description'
363 <CardContent className={classes.cardContent}>
364 <Typography component='div' className={classes.chipSection}>
365 {Object.keys(currentResource.properties).map((k) =>
366 Array.isArray(currentResource.properties[k])
367 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
368 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)