17098: Removes unnecessary prop.
[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
21 export class ProjectDetails extends DetailsData<ProjectResource> {
22     getIcon(className?: string) {
23         return <ProjectIcon className={className} />;
24     }
25
26     getDetails() {
27         return <ProjectDetailsComponent project={this.item} />;
28     }
29 }
30
31 type CssRules = 'tag' | 'editIcon';
32
33 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
34     tag: {
35         marginRight: theme.spacing.unit,
36         marginBottom: theme.spacing.unit
37     },
38     editIcon: {
39         fontSize: '1.125rem',
40         cursor: 'pointer'
41     }
42 });
43
44 interface ProjectDetailsComponentDataProps {
45     project: ProjectResource;
46 }
47
48 interface ProjectDetailsComponentActionProps {
49     onClick: () => void;
50 }
51
52 const mapDispatchToProps = (dispatch: Dispatch) => ({
53     onClick: () => dispatch<any>(openProjectPropertiesDialog()),
54 });
55
56 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
57
58 const ProjectDetailsComponent = connect(null, mapDispatchToProps)(
59     withStyles(styles)(
60         ({ classes, project, onClick }: ProjectDetailsComponentProps) => <div>
61             <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROJECT)} />
62             <DetailsAttribute label='Owner' linkToUuid={project.ownerUuid} lowercaseValue={true} />
63             <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
64             <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
65             <DetailsAttribute label='Project UUID' linkToUuid={project.uuid} value={project.uuid} />
66             <DetailsAttribute label='Description'>
67                 {project.description ?
68                     <RichTextEditorLink
69                         title={`Description of ${project.name}`}
70                         content={project.description}
71                         label='Show full description' />
72                     : '---'
73                 }
74             </DetailsAttribute>
75             <DetailsAttribute label='Properties'>
76                 <div onClick={onClick}>
77                     <RenameIcon className={classes.editIcon} />
78                 </div>
79             </DetailsAttribute>
80             {
81                 Object.keys(project.properties).map(k =>
82                     Array.isArray(project.properties[k])
83                     ? project.properties[k].map((v: string) =>
84                         getPropertyChip(k, v, undefined, classes.tag))
85                     : getPropertyChip(k, project.properties[k], undefined, classes.tag)
86                 )
87             }
88         </div>
89     ));