From f6669f3c7b2184ae4175e43f05cd6ea972624145 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Thu, 30 Jan 2020 17:15:26 -0300 Subject: [PATCH] 15781: Renders multi-value properties as multiple chips. Also, adds support for single-value property deletion. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../collection-panel-action.ts | 14 ++++++++++++-- .../collection-panel/collection-panel.tsx | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/store/collection-panel/collection-panel-action.ts b/src/store/collection-panel/collection-panel-action.ts index 540b8c6a..122fc5e3 100644 --- a/src/store/collection-panel/collection-panel-action.ts +++ b/src/store/collection-panel/collection-panel-action.ts @@ -75,13 +75,23 @@ export const navigateToProcess = (uuid: string) => } }; -export const deleteCollectionTag = (key: string) => +export const deleteCollectionTag = (key: string, value: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const item = getState().collectionPanel.item; const uuid = item ? item.uuid : ''; try { if (item) { - delete item.properties[key]; + if (Array.isArray(item.properties[key])) { + item.properties[key] = item.properties[key].filter((v: string) => v !== value); + if (item.properties[key].length === 1) { + item.properties[key] = item.properties[key][0]; + } else if (item.properties[key].length === 0) { + delete item.properties[key]; + } + } else if (item.properties[key] === value) { + delete item.properties[key]; + } + const updatedCollection = await services.collectionService.update( uuid, { properties: {...item.properties} diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx index b92557f9..cc918808 100644 --- a/src/views/collection-panel/collection-panel.tsx +++ b/src/views/collection-panel/collection-panel.tsx @@ -128,10 +128,10 @@ export const CollectionPanel = withStyles(styles)( {Object.keys(item.properties).map(k => - + Array.isArray(item.properties[k]) + ? item.properties[k].map((v: string) => + getPropertyChip(k, v, this.handleDelete, classes.tag)) + : getPropertyChip(k, item.properties[k], this.handleDelete, classes.tag) )} @@ -166,8 +166,8 @@ export const CollectionPanel = withStyles(styles)( kind: SnackbarKind.SUCCESS })) - handleDelete = (key: string) => () => { - this.props.dispatch(deleteCollectionTag(key)); + handleDelete = (key: string, value: string) => () => { + this.props.dispatch(deleteCollectionTag(key, value)); } openCollectionDetails = () => { @@ -184,3 +184,10 @@ export const CollectionPanel = withStyles(styles)( } ) ); + +const getPropertyChip = (k:string, v:string, handleDelete:any, className:string) => + ; + -- 2.30.2