From: Lucas Di Pentima Date: Fri, 14 Feb 2020 19:31:44 +0000 (-0300) Subject: 15781: Avoids showing duplicate property 'chips' on search editor. X-Git-Tag: 2.1.0~39^2~2 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/ecd7fabba5f2989ec577c3313dcc82c94f924eae 15781: Avoids showing duplicate property 'chips' on search editor. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- 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( -