From ecd7fabba5f2989ec577c3313dcc82c94f924eae Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Fri, 14 Feb 2020 16:31:44 -0300 Subject: [PATCH] 15781: Avoids showing duplicate property 'chips' on search editor. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../search-bar-advanced-properties-view.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/views-components/search-bar/search-bar-advanced-properties-view.tsx b/src/views-components/search-bar/search-bar-advanced-properties-view.tsx index 8add4b02..f3509a02 100644 --- a/src/views-components/search-bar/search-bar-advanced-properties-view.tsx +++ b/src/views-components/search-bar/search-bar-advanced-properties-view.tsx @@ -20,6 +20,7 @@ import { Chips } from '~/components/chips/chips'; import { formatPropertyValue } from "~/common/formatters"; import { Vocabulary } from '~/models/vocabulary'; import { connectVocabulary } from '../resource-properties-form/property-field-common'; +import * as _ from 'lodash'; type CssRules = 'label' | 'button'; @@ -45,7 +46,7 @@ interface SearchBarAdvancedPropertiesViewDataProps { interface SearchBarAdvancedPropertiesViewActionProps { setProps: () => void; - setProp: (propertyValues: PropertyValue, properties: PropertyValue[]) => void; + addProp: (propertyValues: PropertyValue, properties: PropertyValue[]) => void; getAllFields: (propertyValues: PropertyValue[]) => PropertyValue[] | []; } @@ -64,7 +65,16 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({ setProps: (propertyValues: PropertyValue[]) => { dispatch(changeAdvancedFormProperty('properties', propertyValues)); }, - setProp: (propertyValue: PropertyValue, properties: PropertyValue[]) => { + addProp: (propertyValue: PropertyValue, properties: PropertyValue[]) => { + // Remove potential duplicates + properties = properties.filter(x => ! _.isEqual( + { + key: x.keyID || x.key, + value: x.valueID || x.value + }, { + key: propertyValue.keyID || propertyValue.key, + value: propertyValue.valueID || propertyValue.value + })); dispatch(changeAdvancedFormProperty( 'properties', [...properties, propertyValue] @@ -83,7 +93,7 @@ export const SearchBarAdvancedPropertiesView = compose( connectVocabulary, connect(mapStateToProps, mapDispatchToProps))( withStyles(styles)( - ({ classes, fields, propertyValues, setProps, setProp, getAllFields, vocabulary }: SearchBarAdvancedPropertiesViewProps) => + ({ classes, fields, propertyValues, setProps, addProp, getAllFields, vocabulary }: SearchBarAdvancedPropertiesViewProps) => Properties @@ -93,7 +103,7 @@ export const SearchBarAdvancedPropertiesView = compose( -