17205: Created new renderer for owner name
[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='Owner' linkToUuid={project.ownerUuid}
64                 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} lowercaseValue={true} />
65             <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
66             <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
67             <DetailsAttribute label='Project UUID' linkToUuid={project.uuid} value={project.uuid} />
68             <DetailsAttribute label='Description'>
69                 {project.description ?
70                     <RichTextEditorLink
71                         title={`Description of ${project.name}`}
72                         content={project.description}
73                         label='Show full description' />
74                     : '---'
75                 }
76             </DetailsAttribute>
77             <DetailsAttribute label='Properties'>
78                 <div onClick={onClick}>
79                     <RenameIcon className={classes.editIcon} />
80                 </div>
81             </DetailsAttribute>
82             {
83                 Object.keys(project.properties).map(k =>
84                     Array.isArray(project.properties[k])
85                     ? project.properties[k].map((v: string) =>
86                         getPropertyChip(k, v, undefined, classes.tag))
87                     : getPropertyChip(k, project.properties[k], undefined, classes.tag)
88                 )
89             }
90         </div>
91     ));