1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { connect } from 'react-redux';
7 import { ProjectIcon, RenameIcon, FilterGroupIcon } from 'components/icon/icon';
8 import { ProjectResource } from 'models/project';
9 import { formatDate } from 'common/formatters';
10 import { ResourceKind } from 'models/resource';
11 import { resourceLabel } from 'common/labels';
12 import { DetailsData } from "./details-data";
13 import { DetailsAttribute } from "components/details-attribute/details-attribute";
14 import { RichTextEditorLink } from 'components/rich-text-editor-link/rich-text-editor-link';
15 import { CustomStyleRulesCallback } from 'common/custom-theme';
16 import { Button } from '@mui/material';
17 import { WithStyles } from '@mui/styles';
18 import withStyles from '@mui/styles/withStyles';
19 import { ArvadosTheme } from 'common/custom-theme';
20 import { Dispatch } from 'redux';
21 import { getPropertyChip } from '../resource-properties-form/property-chip';
22 import { ResourceWithName } from '../data-explorer/renderers';
23 import { GroupClass } from "models/group";
24 import { openProjectUpdateDialog, ProjectUpdateFormDialogData } from 'store/projects/project-update-actions';
25 import { RootState } from 'store/store';
26 import { ResourcesState } from 'store/resources/resources';
27 import { resourceIsFrozen } from 'common/frozen-resources';
29 export class ProjectDetails extends DetailsData<ProjectResource> {
30 getIcon(className?: string) {
31 if (this.item.groupClass === GroupClass.FILTER) {
32 return <FilterGroupIcon className={className} />;
34 return <ProjectIcon className={className} />;
38 return <ProjectDetailsComponent project={this.item} />;
42 type CssRules = 'tag' | 'editIcon' | 'editButton';
44 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
46 marginRight: theme.spacing(0.5),
47 marginBottom: theme.spacing(0.5),
50 paddingRight: theme.spacing(0.5),
55 padding: '2px 10px 2px 5px',
60 interface ProjectDetailsComponentDataProps {
61 project: ProjectResource;
64 interface ProjectDetailsComponentActionProps {
65 onClick: (prj: ProjectUpdateFormDialogData) => () => void;
68 const mapStateToProps = (state: RootState): { resources: ResourcesState } => {
70 resources: state.resources
74 const mapDispatchToProps = (dispatch: Dispatch) => ({
75 onClick: (prj: ProjectUpdateFormDialogData) =>
76 () => dispatch<any>(openProjectUpdateDialog(prj)),
79 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
81 const ProjectDetailsComponent = connect(mapStateToProps, mapDispatchToProps)(
83 ({ classes, project, resources, onClick }: ProjectDetailsComponentProps & { resources: ResourcesState }) => <div>
84 {project.groupClass !== GroupClass.FILTER ?
85 <Button onClick={onClick({
88 description: project.description,
89 properties: project.properties,
91 disabled={resourceIsFrozen(project, resources)}
92 className={classes.editButton} variant='contained'
93 data-cy='details-panel-edit-btn' color='primary' size='small'>
94 <RenameIcon className={classes.editIcon} /> Edit
98 <DetailsAttribute label='Type' value={project.groupClass === GroupClass.FILTER ? 'Filter group' : resourceLabel(ResourceKind.PROJECT)} />
99 <DetailsAttribute label='UUID' linkToUuid={project.uuid} value={project.uuid} />
100 <DetailsAttribute label='Owner' linkToUuid={project.ownerUuid}
101 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
102 <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
103 <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
104 <DetailsAttribute label='Last modified by' linkToUuid={project.modifiedByUserUuid}
105 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
106 <DetailsAttribute label='Description'>
107 {project.description ?
109 title={`Description of ${project.name}`}
110 content={project.description}
111 label='Show full description' />
115 <DetailsAttribute label='Properties' />
117 Object.keys(project.properties).map(k =>
118 Array.isArray(project.properties[k])
119 ? project.properties[k].map((v: string) =>
120 getPropertyChip(k, v, undefined, classes.tag))
121 : getPropertyChip(k, project.properties[k], undefined, classes.tag)