17782: Fixes 'no-mixed-operators' compile warnings.
[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 React from 'react';
6 import { connect } from 'react-redux';
7 import { openProjectPropertiesDialog } from 'store/details-panel/details-panel-action';
8 import { ProjectIcon, RenameIcon, FilterGroupIcon } 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 import { GroupClass } from "models/group";
22
23 export class ProjectDetails extends DetailsData<ProjectResource> {
24     getIcon(className?: string) {
25         if (this.item.groupClass === GroupClass.FILTER) {
26             return <FilterGroupIcon className={className} />;
27         }
28         return <ProjectIcon className={className} />;
29     }
30
31     getDetails() {
32         return <ProjectDetailsComponent project={this.item} />;
33     }
34 }
35
36 type CssRules = 'tag' | 'editIcon';
37
38 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
39     tag: {
40         marginRight: theme.spacing.unit,
41         marginBottom: theme.spacing.unit
42     },
43     editIcon: {
44         fontSize: '1.125rem',
45         cursor: 'pointer'
46     }
47 });
48
49 interface ProjectDetailsComponentDataProps {
50     project: ProjectResource;
51 }
52
53 interface ProjectDetailsComponentActionProps {
54     onClick: () => void;
55 }
56
57 const mapDispatchToProps = (dispatch: Dispatch) => ({
58     onClick: () => dispatch<any>(openProjectPropertiesDialog()),
59 });
60
61 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
62
63 const ProjectDetailsComponent = connect(null, mapDispatchToProps)(
64     withStyles(styles)(
65         ({ classes, project, onClick }: ProjectDetailsComponentProps) => <div>
66             <DetailsAttribute label='Type' value={project.groupClass === GroupClass.FILTER ? 'Filter group' : resourceLabel(ResourceKind.PROJECT)} />
67             <DetailsAttribute label='Owner' linkToUuid={project.ownerUuid}
68                 uuidEnhancer={(uuid: string) => <ResourceOwnerWithName uuid={uuid} />} />
69             <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
70             <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
71             <DetailsAttribute label='UUID' linkToUuid={project.uuid} value={project.uuid} />
72             <DetailsAttribute label='Description'>
73                 {project.description ?
74                     <RichTextEditorLink
75                         title={`Description of ${project.name}`}
76                         content={project.description}
77                         label='Show full description' />
78                     : '---'
79                 }
80             </DetailsAttribute>
81             <DetailsAttribute label='Properties'>
82                 {project.groupClass !== GroupClass.FILTER ?
83                     <div onClick={onClick}>
84                         <RenameIcon className={classes.editIcon} />
85                     </div>
86                     : ''
87                 }
88             </DetailsAttribute>
89             {
90                 Object.keys(project.properties).map(k =>
91                     Array.isArray(project.properties[k])
92                     ? project.properties[k].map((v: string) =>
93                         getPropertyChip(k, v, undefined, classes.tag))
94                     : getPropertyChip(k, project.properties[k], undefined, classes.tag)
95                 )
96             }
97         </div>
98     ));