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'
45 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
54 color: theme.palette.grey['600'],
63 cardHeaderContainer: {
68 justifyContent: 'space-between',
72 padding: '0.2rem 0.4rem 0.2rem 1rem',
78 marginTop: '-0.25rem',
79 paddingBottom: '0.5rem',
83 flexDirection: 'column',
85 paddingLeft: '0.1rem',
101 margin: 'auto 0 1rem 0.3rem',
102 color: theme.palette.text.primary,
106 marginLeft: '0.3rem',
108 color: theme.palette.text.primary,
116 alignItems: 'center',
120 marginBottom: '-1rem',
123 marginRight: '0.75rem',
124 marginBottom: '0.5rem',
129 marginBottom: '-0.85rem',
132 marginRight: '-0.5rem',
136 const mapStateToProps = ({ auth, selectedResourceUuid, resources, properties }: RootState) => {
137 const currentResource = getResource(properties.currentRouteUuid)(resources);
138 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(resources);
139 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
140 const isSelected = selectedResourceUuid === properties.currentRouteUuid;
143 isAdmin: auth.user?.isAdmin,
150 const mapDispatchToProps = (dispatch: Dispatch) => ({
151 handleCardClick: (uuid: string) => {
152 dispatch<any>(loadDetailsPanel(uuid));
153 dispatch<any>(setSelectedResourceUuid(uuid));
154 dispatch<any>(deselectAllOthers(uuid));
158 type ProjectCardProps = WithStyles<CssRules> & {
159 currentResource: ProjectResource;
160 frozenByFullName: string | undefined;
163 handleCardClick: (resource: any) => void;
166 export const ProjectCard = connect(
170 withStyles(styles)((props: ProjectCardProps) => {
171 const { classes, currentResource, frozenByFullName, handleCardClick, isSelected } = props;
172 const { name, description, uuid } = currentResource as ProjectResource;
173 const [showDescription, setShowDescription] = React.useState(false);
174 const [showProperties, setShowProperties] = React.useState(false);
176 const toggleDescription = () => {
177 setShowDescription(!showDescription);
180 const toggleProperties = () => {
181 setShowProperties(!showProperties);
186 className={classes.root}
187 onClick={() => handleCardClick(uuid)}
188 data-cy='project-details-card'
193 className={classes.cardHeaderContainer}
196 className={classes.cardHeader}
198 <section className={classes.nameSection}>
199 <section className={classes.namePlate}>
202 style={{ marginRight: '1rem' }}
207 className={classes.faveIcon}
208 resourceUuid={currentResource.uuid}
211 className={classes.faveIcon}
212 resourceUuid={currentResource.uuid}
214 {!!frozenByFullName && (
216 className={classes.frozenIcon}
218 title={<span>Project was frozen by {frozenByFullName}</span>}
220 <FreezeIcon style={{ fontSize: 'inherit' }} />
226 data-cy='no-description'
227 className={classes.noDescription}
229 no description available
235 {isSelected && <MultiselectToolbar injectedStyles={classes.toolbarStyles} />}
237 <section onClick={(ev) => ev.stopPropagation()}>
240 onClick={toggleDescription}
241 className={classes.descriptionToggle}
242 data-cy='toggle-description'
244 <ExpandChevronRight expanded={showDescription} />
245 <section className={classes.showMore}>
249 collapsedSize='1.25rem'
252 className={classes.description}
253 data-cy='project-description'
254 //dangerouslySetInnerHTML is ok here only if description is sanitized,
255 //which it is before it is loaded into the redux store
256 dangerouslySetInnerHTML={{ __html: description }}
264 {typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0 ? (
266 onClick={toggleProperties}
267 className={classes.descriptionToggle}
270 className={classes.chipToggle}
271 data-cy='toggle-chips'
273 <ExpandChevronRight expanded={showProperties} />
275 <section className={classes.showMore}>
282 className={classes.description}
283 data-cy='project-description'
285 <CardContent className={classes.cardContent}>
288 className={classes.chipSection}
290 {Object.keys(currentResource.properties).map((k) =>
291 Array.isArray(currentResource.properties[k])
292 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
293 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)