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 { withStyles, WithStyles, Button } from '@material-ui/core';
17 import { ArvadosTheme } from 'common/custom-theme';
18 import { Dispatch } from 'redux';
19 import { getPropertyChip } from '../resource-properties-form/property-chip';
20 import { ResourceWithName } from '../data-explorer/renderers';
21 import { GroupClass } from "models/group";
22 import { openProjectUpdateDialog, ProjectUpdateFormDialogData } from 'store/projects/project-update-actions';
23 import { RootState } from 'store/store';
24 import { ResourcesState } from 'store/resources/resources';
25 import { resourceIsFrozen } from 'common/frozen-resources';
27 export class ProjectDetails extends DetailsData<ProjectResource> {
28 getIcon(className?: string) {
29 if (this.item.groupClass === GroupClass.FILTER) {
30 return <FilterGroupIcon className={className} />;
32 return <ProjectIcon className={className} />;
36 return <ProjectDetailsComponent project={this.item} />;
40 type CssRules = 'tag' | 'editIcon' | 'editButton';
42 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
44 marginRight: theme.spacing.unit / 2,
45 marginBottom: theme.spacing.unit / 2,
48 paddingRight: theme.spacing.unit / 2,
53 padding: '2px 10px 2px 5px',
58 interface ProjectDetailsComponentDataProps {
59 project: ProjectResource;
62 interface ProjectDetailsComponentActionProps {
63 onClick: (prj: ProjectUpdateFormDialogData) => () => void;
66 const mapStateToProps = (state: RootState): { resources: ResourcesState } => {
68 resources: state.resources
72 const mapDispatchToProps = (dispatch: Dispatch) => ({
73 onClick: (prj: ProjectUpdateFormDialogData) =>
74 () => dispatch<any>(openProjectUpdateDialog(prj)),
77 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
79 const ProjectDetailsComponent = connect(mapStateToProps, mapDispatchToProps)(
81 ({ classes, project, resources, onClick }: ProjectDetailsComponentProps & { resources: ResourcesState }) => <div>
82 {project.groupClass !== GroupClass.FILTER ?
83 <Button onClick={onClick({
86 description: project.description,
87 properties: project.properties,
89 disabled={resourceIsFrozen(project, resources)}
90 className={classes.editButton} variant='contained'
91 data-cy='details-panel-edit-btn' color='primary' size='small'>
92 <RenameIcon className={classes.editIcon} /> Edit
96 <DetailsAttribute label='Type' value={project.groupClass === GroupClass.FILTER ? 'Filter group' : resourceLabel(ResourceKind.PROJECT)} />
97 <DetailsAttribute label='UUID' linkToUuid={project.uuid} value={project.uuid} />
98 <DetailsAttribute label='Owner' linkToUuid={project.ownerUuid}
99 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
100 <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
101 <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
102 <DetailsAttribute label='Last modified by' linkToUuid={project.modifiedByUserUuid}
103 uuidEnhancer={(uuid: string) => <ResourceWithName uuid={uuid} />} />
104 <DetailsAttribute label='Description'>
105 {project.description ?
107 title={`Description of ${project.name}`}
108 content={project.description}
109 label='Show full description' />
113 <DetailsAttribute label='Properties' />
115 Object.keys(project.properties).map(k =>
116 Array.isArray(project.properties[k])
117 ? project.properties[k].map((v: string) =>
118 getPropertyChip(k, v, undefined, classes.tag))
119 : getPropertyChip(k, project.properties[k], undefined, classes.tag)