4a615506ea35f0cf717f9fdbc22248735833c085
[arvados-workbench2.git] / src / views-components / details-panel / project-details.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { connect } from 'react-redux';
7 import { openProjectPropertiesDialog } from '~/store/details-panel/details-panel-action';
8 import { ProjectIcon, RenameIcon } from '~/components/icon/icon';
9 import { ProjectResource } from '~/models/project';
10 import { formatDate } from '~/common/formatters';
11 import { ResourceKind } from '~/models/resource';
12 import { resourceLabel } from '~/common/labels';
13 import { DetailsData } from "./details-data";
14 import { DetailsAttribute } from "~/components/details-attribute/details-attribute";
15 import { RichTextEditorLink } from '~/components/rich-text-editor-link/rich-text-editor-link';
16 import { withStyles, StyleRulesCallback, WithStyles } 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 { ResourceOwnerWithName } from '../data-explorer/renderers';
21
22 export class ProjectDetails extends DetailsData<ProjectResource> {
23     getIcon(className?: string) {
24         return <ProjectIcon className={className} />;
25     }
26
27     getDetails() {
28         return <ProjectDetailsComponent project={this.item} />;
29     }
30 }
31
32 type CssRules = 'tag' | 'editIcon';
33
34 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
35     tag: {
36         marginRight: theme.spacing.unit,
37         marginBottom: theme.spacing.unit
38     },
39     editIcon: {
40         fontSize: '1.125rem',
41         cursor: 'pointer'
42     }
43 });
44
45 interface ProjectDetailsComponentDataProps {
46     project: ProjectResource;
47 }
48
49 interface ProjectDetailsComponentActionProps {
50     onClick: () => void;
51 }
52
53 const mapDispatchToProps = (dispatch: Dispatch) => ({
54     onClick: () => dispatch<any>(openProjectPropertiesDialog()),
55 });
56
57 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
58
59 const ProjectDetailsComponent = connect(null, mapDispatchToProps)(
60     withStyles(styles)(
61         ({ classes, project, onClick }: ProjectDetailsComponentProps) => <div>
62             <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROJECT)} />
63             <DetailsAttribute label='Group class' value={project.groupClass} />
64             <DetailsAttribute label='Owner' linkToUuid={project.ownerUuid}
65                 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
66             <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
67             <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
68             <DetailsAttribute label='Project UUID' linkToUuid={project.uuid} value={project.uuid} />
69             <DetailsAttribute label='Description'>
70                 {project.description ?
71                     <RichTextEditorLink
72                         title={`Description of ${project.name}`}
73                         content={project.description}
74                         label='Show full description' />
75                     : '---'
76                 }
77             </DetailsAttribute>
78             <DetailsAttribute label='Properties'>
79                 <div onClick={onClick}>
80                     <RenameIcon className={classes.editIcon} />
81                 </div>
82             </DetailsAttribute>
83             {
84                 Object.keys(project.properties).map(k =>
85                     Array.isArray(project.properties[k])
86                     ? project.properties[k].map((v: string) =>
87                         getPropertyChip(k, v, undefined, classes.tag))
88                     : getPropertyChip(k, project.properties[k], undefined, classes.tag)
89                 )
90             }
91         </div>
92     ));