15067: Creates PropertyChipComponent to be used where tags need listing.
[arvados-workbench2.git] / src / views / collection-panel / collection-panel.tsx
index 87768e640714a7acb306e0e3705b4c9760047a67..28ae2f05eddd1e70c83868ef03b341c16a204e87 100644 (file)
@@ -5,9 +5,8 @@
 import * as React from 'react';
 import {
     StyleRulesCallback, WithStyles, withStyles, Card,
-    CardHeader, IconButton, CardContent, Grid, Chip, Tooltip
+    CardHeader, IconButton, CardContent, Grid, Tooltip
 } from '@material-ui/core';
-import { compose } from "redux";
 import { connect, DispatchProp } from "react-redux";
 import { RouteComponentProps } from 'react-router';
 import { ArvadosTheme } from '~/common/custom-theme';
@@ -25,10 +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';
-import { connectVocabulary, VocabularyProp } from '~/views-components/resource-properties-form/property-field-common';
-import { getTagValueLabel, getTagKeyLabel } from '~/models/vocabulary';
+import { PropertyChipComponent } from '~/views-components/resource-properties-form/property-chip';
 
 type CssRules = 'card' | 'iconHeader' | 'tag' | 'label' | 'value' | 'link';
 
@@ -68,19 +65,16 @@ interface CollectionPanelDataProps {
 type CollectionPanelProps = CollectionPanelDataProps & DispatchProp
     & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
 
-export const CollectionPanel = compose(
-    connectVocabulary,
-    withStyles(styles))(
-        connect((state: RootState, props: RouteComponentProps<{ id: string }> & VocabularyProp) => {
+export const CollectionPanel = withStyles(styles)(
+        connect((state: RootState, props: RouteComponentProps<{ id: string }>) => {
             const item = getResource(props.match.params.id)(state.resources);
             const data = getResourceData(props.match.params.id)(state.resourcesData);
-            const vocabulary = props.vocabulary;
-            return { item, data, vocabulary };
+            return { item, data };
         })(
-        class extends React.Component<CollectionPanelProps & VocabularyProp> {
+        class extends React.Component<CollectionPanelProps> {
 
             render() {
-                const { classes, item, data, dispatch, vocabulary } = this.props;
+                const { classes, item, data, dispatch } = this.props;
                 return item
                     ? <>
                         <Card className={classes.card}>
@@ -136,14 +130,12 @@ export const CollectionPanel = compose(
                                         <CollectionTagForm />
                                     </Grid>
                                     <Grid item xs={12}>
-                                        {Object.keys(item.properties).map(k => {
-                                            const label = `${getTagKeyLabel(k, vocabulary)}: ${getTagValueLabel(k, item.properties[k], vocabulary)}`;
-                                            return <CopyToClipboard key={k} text={label} onCopy={() => this.onCopy("Copied")}>
-                                                <Chip className={classes.tag}
-                                                    onDelete={this.handleDelete(k)}
-                                                    label={label} />
-                                            </CopyToClipboard>;
-                                        })}
+                                        {Object.keys(item.properties).map(k =>
+                                            <PropertyChipComponent
+                                                key={k} className={classes.tag}
+                                                onDelete={this.handleDelete(k)}
+                                                propKey={k} propValue={item.properties[k]} />
+                                        )}
                                     </Grid>
                                 </Grid>
                             </CardContent>