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 { FavoriteStar, PublicFavoriteStar } from 'views-components/favorite-star/favorite-star';
14 import { FreezeIcon } from 'components/icon/icon';
15 import { Resource } from 'models/resource';
16 import { Dispatch } from 'redux';
17 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
18 import { ExpandChevronRight } from 'components/expand-chevron-right/expand-chevron-right';
19 import { MultiselectToolbar } from 'components/multiselect-toolbar/MultiselectToolbar';
20 import { setSelectedResourceUuid } from 'store/selected-resource/selected-resource-actions';
21 import { deselectAllOthers } from 'store/multiselect/multiselect-actions';
25 | 'cardHeaderContainer'
41 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
53 color: theme.palette.grey['600'],
62 cardHeaderContainer: {
67 justifyContent: 'space-between',
71 padding: '0.2rem 0.4rem 0.2rem 1rem',
77 paddingBottom: '0.5rem',
81 flexDirection: 'column',
83 paddingLeft: '0.1rem',
99 margin: 'auto 0 1rem 0.3rem',
100 color: theme.palette.text.primary,
104 marginLeft: '0.3rem',
106 color: theme.palette.text.primary,
110 alignItems: 'center',
114 marginBottom: '-2rem',
117 marginRight: '0.75rem',
118 marginBottom: '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);
164 const [showProperties, setShowProperties] = React.useState(false);
166 const toggleDescription = () => {
167 setShowDescription(!showDescription);
170 const toggleProperties = () => {
171 setShowProperties(!showProperties);
174 const parser = new DOMParser();
178 className={classes.root}
179 onClick={() => handleCardClick(uuid)}
180 data-cy='project-details-card'
185 className={classes.cardHeaderContainer}
188 className={classes.cardHeader}
190 <section className={classes.nameSection}>
191 <section className={classes.namePlate}>
194 style={{ marginRight: '1rem' }}
199 className={classes.faveIcon}
200 resourceUuid={currentResource.uuid}
203 className={classes.faveIcon}
204 resourceUuid={currentResource.uuid}
206 {!!frozenByFullName && (
208 className={classes.frozenIcon}
210 title={<span>Project was frozen by {frozenByFullName}</span>}
212 <FreezeIcon style={{ fontSize: 'inherit' }} />
218 data-cy='no-description'
219 className={classes.noDescription}
221 no description available
227 {isSelected && <MultiselectToolbar />}
229 <section onClick={(ev) => ev.stopPropagation()}>
232 onClick={toggleDescription}
233 className={classes.descriptionToggle}
234 data-cy='toggle-description'
236 <ExpandChevronRight expanded={showDescription} />
237 <section className={classes.showMore}>
241 collapsedHeight='1.25rem'
244 className={classes.description}
245 data-cy='project-description'
246 //dangerouslySetInnerHTML is ok here only if description is sanitized,
247 //which it is before it is loaded into the redux store
248 dangerouslySetInnerHTML={{ __html: parser.parseFromString(description, 'text/html').body.textContent || '' }}
256 {typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0 ? (
258 onClick={toggleProperties}
259 className={classes.descriptionToggle}
262 className={classes.chipToggle}
263 data-cy='toggle-chips'
265 <ExpandChevronRight expanded={showProperties} />
267 <section className={classes.showMore}>
271 collapsedHeight='35px'
274 className={classes.description}
275 data-cy='project-description'
277 <CardContent className={classes.cardContent}>
280 className={classes.chipSection}
282 {Object.keys(currentResource.properties).map((k) =>
283 Array.isArray(currentResource.properties[k])
284 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
285 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)