15230: Link to other workbenches when double-clicking search results.
[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 { compose } from 'redux';
7 import { connect } from 'react-redux';
8 import { openProjectPropertiesDialog } from '~/store/details-panel/details-panel-action';
9 import { ProjectIcon, RenameIcon } from '~/components/icon/icon';
10 import { ProjectResource } from '~/models/project';
11 import { formatDate } from '~/common/formatters';
12 import { ResourceKind } from '~/models/resource';
13 import { resourceLabel } from '~/common/labels';
14 import { DetailsData } from "./details-data";
15 import { DetailsAttribute } from "~/components/details-attribute/details-attribute";
16 import { RichTextEditorLink } from '~/components/rich-text-editor-link/rich-text-editor-link';
17 import { withStyles, StyleRulesCallback, Chip, WithStyles } from '@material-ui/core';
18 import { ArvadosTheme } from '~/common/custom-theme';
19
20 export class ProjectDetails extends DetailsData<ProjectResource> {
21     getIcon(className?: string) {
22         return <ProjectIcon className={className} />;
23     }
24
25     getDetails() {
26         return <ProjectDetailsComponent project={this.item} />;
27     }
28 }
29
30 type CssRules = 'tag' | 'editIcon';
31
32 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
33     tag: {
34         marginRight: theme.spacing.unit,
35         marginBottom: theme.spacing.unit
36     },
37     editIcon: {
38         fontSize: '1.125rem',
39         cursor: 'pointer'
40     }
41 });
42
43
44 interface ProjectDetailsComponentDataProps {
45     project: ProjectResource;
46 }
47
48 interface ProjectDetailsComponentActionProps {
49     onClick: () => void;
50 }
51
52 const mapDispatchToProps = ({ onClick: openProjectPropertiesDialog });
53
54 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
55
56 const ProjectDetailsComponent = connect(null, mapDispatchToProps)(
57     withStyles(styles)(
58         ({ classes, project, onClick }: ProjectDetailsComponentProps) => <div>
59             <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROJECT)} />
60             {/* Missing attr */}
61             <DetailsAttribute label='Size' value='---' />
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             {/* Missing attr */}
67             {/*<DetailsAttribute label='File size' value='1.4 GB' />*/}
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                     return <Chip key={k} className={classes.tag} label={`${k}: ${project.properties[k]}`} />;
85                 })
86             }
87         </div>
88     ));