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