Add properties inside projects and create modal to manage.
[arvados-workbench2.git] / src / views-components / details-panel / project-details.tsx
index 18affbacfd0698e6ea3f5eef3b071f6eede3827f..e995291026ce19188ad6ecefa60806e958e1aaa3 100644 (file)
@@ -3,7 +3,10 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { ProjectIcon } from '~/components/icon/icon';
+import { Dispatch } from 'redux';
+import { connect } from 'react-redux';
+import { openProjectPropertiesDialog } from '~/store/details-panel/details-panel-action';
+import { ProjectIcon, RenameIcon } from '~/components/icon/icon';
 import { ProjectResource } from '~/models/project';
 import { formatDate } from '~/common/formatters';
 import { ResourceKind } from '~/models/resource';
@@ -11,32 +14,76 @@ import { resourceLabel } from '~/common/labels';
 import { DetailsData } from "./details-data";
 import { DetailsAttribute } from "~/components/details-attribute/details-attribute";
 import { RichTextEditorLink } from '~/components/rich-text-editor-link/rich-text-editor-link';
+import { withStyles, StyleRulesCallback, Chip, WithStyles } from '@material-ui/core';
+import { ArvadosTheme } from '~/common/custom-theme';
 
 export class ProjectDetails extends DetailsData<ProjectResource> {
-
     getIcon(className?: string) {
         return <ProjectIcon className={className} />;
     }
 
     getDetails() {
-        return <div>
-            <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROJECT)} />
-            {/* Missing attr */}
-            <DetailsAttribute label='Size' value='---' />
-            <DetailsAttribute label='Owner' value={this.item.ownerUuid} lowercaseValue={true} />
-            <DetailsAttribute label='Last modified' value={formatDate(this.item.modifiedAt)} />
-            <DetailsAttribute label='Created at' value={formatDate(this.item.createdAt)} />
-            {/* Missing attr */}
-            {/*<DetailsAttribute label='File size' value='1.4 GB' />*/}
-            <DetailsAttribute label='Description'>
-                {this.item.description ?
-                    <RichTextEditorLink
-                        title={`Description of ${this.item.name}`}
-                        content={this.item.description}
-                        label='Show full description' />
-                    : '---'
-                }
-            </DetailsAttribute>
-        </div>;
+        return <ProjectDetailsComponent project={this.item} />;
+    }
+}
+
+type CssRules = 'tag' | 'editIcon';
+
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+    tag: {
+        marginRight: theme.spacing.unit,
+        marginBottom: theme.spacing.unit
+    },
+    editIcon: {
+        fontSize: '1.125rem',
+        cursor: 'pointer'
     }
+});
+
+
+interface ProjectDetailsComponentDataProps {
+    project: ProjectResource;
+}
+
+interface ProjectDetailsComponentActionProps {
+    onClick: () => void;
 }
+
+const mapDispatchToProps = (dispatch: Dispatch): ProjectDetailsComponentActionProps => ({
+    onClick: () => dispatch<any>(openProjectPropertiesDialog())
+});
+
+type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
+
+const ProjectDetailsComponent = connect(null, mapDispatchToProps)(
+    withStyles(styles)(
+        ({ classes, project, onClick }: ProjectDetailsComponentProps) => <div>
+            <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROJECT)} />
+                {/* Missing attr */}
+                <DetailsAttribute label='Size' value='---' />
+                <DetailsAttribute label='Owner' value={project.ownerUuid} lowercaseValue={true} />
+                <DetailsAttribute label='Last modified' value={formatDate(project.modifiedAt)} />
+                <DetailsAttribute label='Created at' value={formatDate(project.createdAt)} />
+                {/* Missing attr */}
+                {/*<DetailsAttribute label='File size' value='1.4 GB' />*/}
+                <DetailsAttribute label='Description'>
+                    {project.description ?
+                        <RichTextEditorLink
+                            title={`Description of ${project.name}`}
+                            content={project.description}
+                            label='Show full description' />
+                        : '---'
+                    }
+                </DetailsAttribute>
+                <DetailsAttribute label='Properties'>
+                    <div onClick={onClick}>
+                        <RenameIcon className={classes.editIcon} />
+                    </div>
+                </DetailsAttribute>
+                {
+                    Object.keys(project.properties).map(k => {
+                        return <Chip key={k} className={classes.tag} label={`${k}: ${project.properties[k]}`} />;
+                    })
+                }
+        </div>
+));
\ No newline at end of file