15766: Clicking on a property chip copies its text to clipboard 15766-copy-property-text
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Tue, 29 Oct 2019 21:33:58 +0000 (17:33 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Tue, 29 Oct 2019 21:33:58 +0000 (17:33 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

src/views/collection-panel/collection-panel.tsx

index 58dd940494d18e5654f005a9277f2ebf64ddb10e..77d91558e5660d5dbd23fd19eb95368c7f42e3c4 100644 (file)
@@ -24,6 +24,8 @@ import { formatFileSize } from "~/common/formatters";
 import { getResourceData } from "~/store/resources-data/resources-data";
 import { ResourceData } from "~/store/resources-data/resources-data-reducer";
 import { openDetailsPanel } from '~/store/details-panel/details-panel-action';
+import * as CopyToClipboard from 'react-copy-to-clipboard';
+import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
 
 type CssRules = 'card' | 'iconHeader' | 'tag' | 'label' | 'value' | 'link';
 
@@ -130,9 +132,12 @@ export const CollectionPanel = withStyles(styles)(
                                     <Grid item xs={12}>
                                         {
                                             Object.keys(item.properties).map(k => {
-                                                return <Chip key={k} className={classes.tag}
-                                                    onDelete={this.handleDelete(k)}
-                                                    label={`${k}: ${item.properties[k]}`} />;
+                                                const label = `${k}: ${item.properties[k]}`;
+                                                return <CopyToClipboard key={k} text={label} onCopy={() => this.onCopy("Copied")}>
+                                                    <Chip className={classes.tag}
+                                                        onDelete={this.handleDelete(k)}
+                                                        label={label} />
+                                                </CopyToClipboard>;
                                             })
                                         }
                                     </Grid>
@@ -161,6 +166,13 @@ export const CollectionPanel = withStyles(styles)(
                 this.props.dispatch<any>(openContextMenu(event, resource));
             }
 
+            onCopy = (message: string) =>
+                this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
+                    message,
+                    hideDuration: 2000,
+                    kind: SnackbarKind.SUCCESS
+                }))
+
             handleDelete = (key: string) => () => {
                 this.props.dispatch<any>(deleteCollectionTag(key));
             }