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'
42 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
51 color: theme.palette.grey['600'],
60 cardHeaderContainer: {
65 justifyContent: 'space-between',
69 padding: '0.2rem 0.4rem 0.2rem 1rem',
75 marginTop: '-0.25rem',
76 paddingBottom: '0.5rem',
80 flexDirection: 'column',
82 paddingLeft: '0.1rem',
98 margin: 'auto 0 1rem 0.3rem',
99 color: theme.palette.text.primary,
103 marginLeft: '0.3rem',
105 color: theme.palette.text.primary,
113 alignItems: 'center',
117 marginBottom: '-1rem',
120 marginRight: '0.75rem',
121 marginBottom: '0.5rem',
126 marginBottom: '-0.85rem',
129 marginRight: '-0.5rem',
133 const mapStateToProps = ({ auth, selectedResourceUuid, resources, properties }: RootState) => {
134 const currentResource = getResource(properties.currentRouteUuid)(resources);
135 const frozenByUser = currentResource && getResource((currentResource as ProjectResource).frozenByUuid as string)(resources);
136 const frozenByFullName = frozenByUser && (frozenByUser as Resource & { fullName: string }).fullName;
137 const isSelected = selectedResourceUuid === properties.currentRouteUuid;
140 isAdmin: auth.user?.isAdmin,
147 const mapDispatchToProps = (dispatch: Dispatch) => ({
148 handleCardClick: (uuid: string) => {
149 dispatch<any>(loadDetailsPanel(uuid));
150 dispatch<any>(setSelectedResourceUuid(uuid));
151 dispatch<any>(deselectAllOthers(uuid));
155 type ProjectCardProps = WithStyles<CssRules> & {
156 currentResource: ProjectResource;
157 frozenByFullName: string | undefined;
160 handleCardClick: (resource: any) => void;
163 export const ProjectCard = connect(
167 withStyles(styles)((props: ProjectCardProps) => {
168 const { classes, currentResource, frozenByFullName, handleCardClick, isSelected } = props;
169 const { name, description, uuid } = currentResource as ProjectResource;
170 const [showDescription, setShowDescription] = React.useState(false);
171 const [showProperties, setShowProperties] = React.useState(false);
173 const toggleDescription = () => {
174 setShowDescription(!showDescription);
177 const toggleProperties = () => {
178 setShowProperties(!showProperties);
183 className={classes.root}
184 onClick={() => handleCardClick(uuid)}
185 data-cy='project-details-card'
190 className={classes.cardHeaderContainer}
193 className={classes.cardHeader}
195 <section className={classes.nameSection}>
196 <section className={classes.namePlate}>
199 style={{ marginRight: '1rem' }}
204 className={classes.faveIcon}
205 resourceUuid={currentResource.uuid}
208 className={classes.faveIcon}
209 resourceUuid={currentResource.uuid}
211 {!!frozenByFullName && (
213 className={classes.frozenIcon}
215 title={<span>Project was frozen by {frozenByFullName}</span>}
217 <FreezeIcon style={{ fontSize: 'inherit' }} />
223 data-cy='no-description'
224 className={classes.noDescription}
226 no description available
232 {isSelected && <MultiselectToolbar injectedStyles={classes.toolbarStyles} />}
234 <section onClick={(ev) => ev.stopPropagation()}>
237 onClick={toggleDescription}
238 className={classes.descriptionToggle}
239 data-cy='toggle-description'
241 <ExpandChevronRight expanded={showDescription} />
242 <section className={classes.showMore}>
246 collapsedHeight='1.25rem'
249 className={classes.description}
250 data-cy='project-description'
251 //dangerouslySetInnerHTML is ok here only if description is sanitized,
252 //which it is before it is loaded into the redux store
253 dangerouslySetInnerHTML={{ __html: description }}
261 {typeof currentResource.properties === 'object' && Object.keys(currentResource.properties).length > 0 ? (
263 onClick={toggleProperties}
264 className={classes.descriptionToggle}
267 className={classes.chipToggle}
268 data-cy='toggle-chips'
270 <ExpandChevronRight expanded={showProperties} />
272 <section className={classes.showMore}>
276 collapsedHeight='35px'
279 className={classes.description}
280 data-cy='project-description'
282 <CardContent className={classes.cardContent}>
285 className={classes.chipSection}
287 {Object.keys(currentResource.properties).map((k) =>
288 Array.isArray(currentResource.properties[k])
289 ? currentResource.properties[k].map((v: string) => getPropertyChip(k, v, undefined, classes.tag))
290 : getPropertyChip(k, currentResource.properties[k], undefined, classes.tag)