15067: Shows tags labels on project details. Adds copy-on-click feature.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 13 Nov 2019 22:03:37 +0000 (19:03 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Wed, 13 Nov 2019 22:03:37 +0000 (19:03 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

src/views-components/details-panel/project-details.tsx
src/views-components/project-properties-dialog/project-properties-dialog.tsx

index 8f03cc5d66c1355d3c84a0891893d555f18a143f..7db4df7be7d4eb83706fb186928c029ee3a24aae 100644 (file)
@@ -4,6 +4,7 @@
 
 import * as React from 'react';
 import { connect } from 'react-redux';
+import { RootState } from '~/store/store';
 import { openProjectPropertiesDialog } from '~/store/details-panel/details-panel-action';
 import { ProjectIcon, RenameIcon } from '~/components/icon/icon';
 import { ProjectResource } from '~/models/project';
@@ -15,6 +16,11 @@ import { DetailsAttribute } from "~/components/details-attribute/details-attribu
 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';
+import * as CopyToClipboard from 'react-copy-to-clipboard';
+import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
+import { getTagValueLabel, getTagKeyLabel, Vocabulary } from '~/models/vocabulary';
+import { getVocabulary } from "~/store/vocabulary/vocabulary-selectors";
+import { Dispatch } from 'redux';
 
 export class ProjectDetails extends DetailsData<ProjectResource> {
     getIcon(className?: string) {
@@ -42,19 +48,32 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 
 interface ProjectDetailsComponentDataProps {
     project: ProjectResource;
+    vocabulary: Vocabulary;
 }
 
 interface ProjectDetailsComponentActionProps {
     onClick: () => void;
+    onCopy: (message: string) => void;
 }
 
-const mapDispatchToProps = ({ onClick: openProjectPropertiesDialog });
+const mapStateToProps = ({ properties }: RootState) => ({
+    vocabulary: getVocabulary(properties),
+});
+
+const mapDispatchToProps = (dispatch: Dispatch) => ({
+    onClick: () => dispatch<any>(openProjectPropertiesDialog()),
+    onCopy: (message: string) => dispatch(snackbarActions.OPEN_SNACKBAR({
+        message,
+        hideDuration: 2000,
+        kind: SnackbarKind.SUCCESS
+    }))
+});
 
 type ProjectDetailsComponentProps = ProjectDetailsComponentDataProps & ProjectDetailsComponentActionProps & WithStyles<CssRules>;
 
-const ProjectDetailsComponent = connect(null, mapDispatchToProps)(
+const ProjectDetailsComponent = connect(mapStateToProps, mapDispatchToProps)(
     withStyles(styles)(
-        ({ classes, project, onClick }: ProjectDetailsComponentProps) => <div>
+        ({ classes, project, onClick, vocabulary, onCopy }: ProjectDetailsComponentProps) => <div>
             <DetailsAttribute label='Type' value={resourceLabel(ResourceKind.PROJECT)} />
             {/* Missing attr */}
             <DetailsAttribute label='Size' value='---' />
@@ -80,7 +99,12 @@ const ProjectDetailsComponent = connect(null, mapDispatchToProps)(
             </DetailsAttribute>
             {
                 Object.keys(project.properties).map(k => {
-                    return <Chip key={k} className={classes.tag} label={`${k}: ${project.properties[k]}`} />;
+                    const label = `${getTagKeyLabel(k, vocabulary)}: ${getTagValueLabel(k, project.properties[k], vocabulary)}`;
+                    return (
+                        <CopyToClipboard key={k} text={label} onCopy={() => onCopy("Copied")}>
+                            <Chip key={k} className={classes.tag} label={label} />
+                        </CopyToClipboard>
+                    );
                 })
             }
         </div>
index caedd4e6593703970ed47ee047635d924130e496..a071a985417efad9fbc2d5806427808bd9d89e14 100644 (file)
@@ -13,6 +13,10 @@ import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Chip, withSt
 import { ArvadosTheme } from '~/common/custom-theme';
 import { ProjectPropertiesForm } from '~/views-components/project-properties-dialog/project-properties-form';
 import { getResource } from '~/store/resources/resources';
+import * as CopyToClipboard from 'react-copy-to-clipboard';
+import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
+import { getTagValueLabel, getTagKeyLabel, Vocabulary } from '~/models/vocabulary';
+import { getVocabulary } from "~/store/vocabulary/vocabulary-selectors";
 
 type CssRules = 'tag';
 
@@ -25,19 +29,26 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
 
 interface ProjectPropertiesDialogDataProps {
     project: ProjectResource;
+    vocabulary: Vocabulary;
 }
 
 interface ProjectPropertiesDialogActionProps {
     handleDelete: (key: string) => void;
+    onCopy: (message: string) => void;
 }
 
-const mapStateToProps = ({ detailsPanel, resources }: RootState): ProjectPropertiesDialogDataProps => {
-    const project = getResource(detailsPanel.resourceUuid)(resources) as ProjectResource;
-    return { project };
-};
+const mapStateToProps = ({ detailsPanel, resources, properties }: RootState): ProjectPropertiesDialogDataProps => ({
+    project: getResource(detailsPanel.resourceUuid)(resources) as ProjectResource,
+    vocabulary: getVocabulary(properties),
+});
 
 const mapDispatchToProps = (dispatch: Dispatch): ProjectPropertiesDialogActionProps => ({
-    handleDelete: (key: string) => dispatch<any>(deleteProjectProperty(key))
+    handleDelete: (key: string) => dispatch<any>(deleteProjectProperty(key)),
+    onCopy: (message: string) => dispatch(snackbarActions.OPEN_SNACKBAR({
+                message,
+                hideDuration: 2000,
+                kind: SnackbarKind.SUCCESS
+            }))
 });
 
 type ProjectPropertiesDialogProps =  ProjectPropertiesDialogDataProps & ProjectPropertiesDialogActionProps & WithDialogProps<{}> & WithStyles<CssRules>;
@@ -45,7 +56,7 @@ type ProjectPropertiesDialogProps =  ProjectPropertiesDialogDataProps & ProjectP
 export const ProjectPropertiesDialog = connect(mapStateToProps, mapDispatchToProps)(
     withStyles(styles)(
     withDialog(PROJECT_PROPERTIES_DIALOG_NAME)(
-        ({ classes, open, closeDialog, handleDelete, project }: ProjectPropertiesDialogProps) =>
+        ({ classes, open, closeDialog, handleDelete, onCopy, project, vocabulary }: ProjectPropertiesDialogProps) =>
             <Dialog open={open}
                 onClose={closeDialog}
                 fullWidth
@@ -53,11 +64,16 @@ export const ProjectPropertiesDialog = connect(mapStateToProps, mapDispatchToPro
                 <DialogTitle>Properties</DialogTitle>
                 <DialogContent>
                     <ProjectPropertiesForm />
-                    {project && project.properties && 
+                    {project && project.properties &&
                         Object.keys(project.properties).map(k => {
-                            return <Chip key={k} className={classes.tag}
-                                onDelete={() => handleDelete(k)}
-                                label={`${k}: ${project.properties[k]}`} />;
+                            const label = `${getTagKeyLabel(k, vocabulary)}: ${getTagValueLabel(k, project.properties[k], vocabulary)}`;
+                            return (
+                                <CopyToClipboard key={k} text={label} onCopy={() => onCopy("Copied")}>
+                                    <Chip key={k} className={classes.tag}
+                                        onDelete={() => handleDelete(k)}
+                                        label={label} />
+                                </CopyToClipboard>
+                            );
                         })
                     }
                 </DialogContent>