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