1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { Card, CardHeader, Typography, CardContent, Tooltip, Collapse, Grid } from '@mui/material';
8 import { WithStyles } from '@mui/styles';
9 import withStyles from '@mui/styles/withStyles';
10 import { ArvadosTheme } from 'common/custom-theme';
11 import { RootState } from 'store/store';
12 import { connect } from 'react-redux';
13 import { getResource } from 'store/resources/resources';
14 import { getPropertyChip } from '../resource-properties-form/property-chip';
15 import { ProjectResource } from 'models/project';
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'
43 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
52 color: theme.palette.grey['600'],
61 cardHeaderContainer: {
66 justifyContent: 'space-between',
77 flexDirection: 'column',
82 paddingRight: '.5rem',
99 margin: 'auto 0 1rem 0.3rem',
100 color: theme.palette.text.primary,
104 marginLeft: '0.3rem',
106 color: theme.palette.text.primary,
109 marginBottom: '.5rem',
112 marginRight: '0.75rem',
113 marginBottom: '0.5rem',
122 marginRight: '-0.5rem',
126 const mapStateToProps = ({ auth, selectedResourceUuid, resources, properties }: RootState) => {
127 const currentResource = getResource(properties.currentRouteUuid)(resources);
128 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(resources);
129 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
130 const isSelected = selectedResourceUuid === properties.currentRouteUuid;
133 isAdmin: auth.user?.isAdmin,
140 const mapDispatchToProps = (dispatch: Dispatch) => ({
141 handleCardClick: (uuid: string) => {
142 dispatch<any>(loadDetailsPanel(uuid));
143 dispatch<any>(setSelectedResourceUuid(uuid));
144 dispatch<any>(deselectAllOthers(uuid));
148 type ProjectCardProps = WithStyles<CssRules> & {
149 currentResource: ProjectResource;
150 frozenByFullName: string | undefined;
153 handleCardClick: (resource: any) => void;
156 export const ProjectCard = connect(
160 withStyles(styles)((props: ProjectCardProps) => {
161 const { classes, currentResource, frozenByFullName, handleCardClick, isSelected } = props;
162 const { name, description, uuid } = currentResource as ProjectResource;
163 const [showDescription, setShowDescription] = React.useState(false);
165 const toggleDescription = () => {
166 setShowDescription(!showDescription);
169 const hasDescription = !!(description && description.length > 0);
170 const hasProperties = (typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0);
171 const expandable = hasDescription || hasProperties;
175 className={classes.root}
176 onClick={() => handleCardClick(uuid)}
177 data-cy='project-details-card'
182 className={classes.cardHeaderContainer}
185 className={classes.cardHeader}
187 <section className={classes.nameSection}>
188 <section className={classes.namePlate}>
191 style={{ marginRight: '1rem' }}
194 {expandable && <span className={classes.descriptionToggle}
195 onClick={toggleDescription}
196 data-cy="toggle-description">
197 <ExpandChevronRight expanded={showDescription} />
202 className={classes.faveIcon}
203 resourceUuid={currentResource.uuid}
206 className={classes.faveIcon}
207 resourceUuid={currentResource.uuid}
209 {!!frozenByFullName && (
211 className={classes.frozenIcon}
213 title={<span>Project was frozen by {frozenByFullName}</span>}
215 <FreezeIcon style={{ fontSize: 'inherit' }} />
218 {!hasDescription && (
220 data-cy='no-description'
221 className={classes.noDescription}
223 no description available
231 {isSelected && <MultiselectToolbar injectedStyles={classes.toolbarStyles} />}
234 {expandable && <Collapse
239 <CardContent className={classes.cardContent}>
241 <section data-cy='project-properties'>
244 className={classes.chipSection}
246 {Object.keys(currentResource.properties).map((k) =>
247 Array.isArray(currentResource.properties[k])
248 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
249 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)
255 <section data-cy='project-description'>
257 className={classes.description}
259 //dangerouslySetInnerHTML is ok here only if description is sanitized,
260 //which it is before it is loaded into the redux store
261 dangerouslySetInnerHTML={{ __html: description }}