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;
65 interface ProjectDetailsComponentActionProps {
66 onClick: (prj: ProjectUpdateFormDialogData) => () => void;
69 const mapStateToProps = (state: RootState): { resources: ResourcesState } => {
71 resources: state.resources
75 const mapDispatchToProps = (dispatch: Dispatch) => ({
76 onClick: (prj: ProjectUpdateFormDialogData) =>
77 () => dispatch<any>(openProjectUpdateDialog(prj)),
80 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
82 export const ProjectDetailsComponent = connect(mapStateToProps, mapDispatchToProps)(
84 ({ classes, project, resources, onClick, hideEdit }: ProjectDetailsComponentProps & { resources: ResourcesState }) => <div>
85 {project.groupClass !== GroupClass.FILTER && !hideEdit ?
86 <Button onClick={onClick({
89 description: project.description,
90 properties: project.properties,
92 disabled={resourceIsFrozen(project, resources)}
93 className={classes.editButton} variant='contained'
94 data-cy='details-panel-edit-btn' color='primary' size='small'>
95 <RenameIcon className={classes.editIcon} /> Edit
99 <DetailsAttribute label='Type' value={project.groupClass === GroupClass.FILTER ? 'Filter group' : resourceLabel(ResourceKind.PROJECT)} />
100 <DetailsAttribute label='UUID' linkToUuid={project.uuid} value={project.uuid} />
101 <DetailsAttribute label='Owner' linkToUuid={project.ownerUuid}
102 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
103 <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
104 <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
105 <DetailsAttribute label='Last modified by' linkToUuid={project.modifiedByUserUuid}
106 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
107 <DetailsAttribute label='Description'>
108 {project.description ?
110 title={`Description of ${project.name}`}
111 content={project.description}
112 label='Show full description' />
116 <DetailsAttribute label='Properties' />
118 Object.keys(project.properties).map(k =>
119 Array.isArray(project.properties[k])
120 ? project.properties[k].map((v: string) =>
121 getPropertyChip(k, v, undefined, classes.tag))
122 : getPropertyChip(k, project.properties[k], undefined, classes.tag)