From c2203b1706178b03dca89376f4cef84ccd882538 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Tue, 19 Nov 2019 14:04:59 -0300 Subject: [PATCH] 15069: Fixes bug on advanced search UI disallowing duplicate tags. When the user added properties with the same key as a search criteria, the UI used to list them all, because the form saves them as a FieldArray and they were being pushed to the array when clicking on the Add button. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/store/search-bar/search-bar-actions.ts | 5 ----- .../search-bar-advanced-properties-view.tsx | 16 +++++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts index 8e9e755d..4b745a4d 100644 --- a/src/store/search-bar/search-bar-actions.ts +++ b/src/store/search-bar/search-bar-actions.ts @@ -388,11 +388,6 @@ export const resetAdvancedFormProperty = (propertyField: string) => dispatch(untouch(SEARCH_BAR_ADVANCED_FORM_NAME, propertyField)); }; -export const updateAdvancedFormProperties = (propertyValue: PropertyValue) => - (dispatch: Dispatch) => { - dispatch(arrayPush(SEARCH_BAR_ADVANCED_FORM_NAME, 'properties', propertyValue)); - }; - export const moveUp = () => (dispatch: Dispatch) => { dispatch(searchBarActions.MOVE_UP()); 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 0d7972f8..eb049b76 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 @@ -11,8 +11,7 @@ import { RootState } from '~/store/store'; import { SEARCH_BAR_ADVANCED_FORM_NAME, changeAdvancedFormProperty, - resetAdvancedFormProperty, - updateAdvancedFormProperties + resetAdvancedFormProperty } from '~/store/search-bar/search-bar-actions'; import { PropertyValue } from '~/models/search-bar'; import { ArvadosTheme } from '~/common/custom-theme'; @@ -46,7 +45,7 @@ interface SearchBarAdvancedPropertiesViewDataProps { interface SearchBarAdvancedPropertiesViewActionProps { setProps: () => void; - addProp: (propertyValues: PropertyValue) => void; + setProp: (propertyValues: PropertyValue, properties: PropertyValue[]) => void; getAllFields: (propertyValues: PropertyValue[]) => PropertyValue[] | []; } @@ -65,8 +64,11 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({ setProps: (propertyValues: PropertyValue[]) => { dispatch(changeAdvancedFormProperty('properties', propertyValues)); }, - addProp: (propertyValue: PropertyValue) => { - dispatch(updateAdvancedFormProperties(propertyValue)); + setProp: (propertyValue: PropertyValue, properties: PropertyValue[]) => { + dispatch(changeAdvancedFormProperty( + 'properties', + [...properties.filter(e => e.keyID! !== propertyValue.keyID!), propertyValue] + )); dispatch(resetAdvancedFormProperty('key')); dispatch(resetAdvancedFormProperty('value')); dispatch(resetAdvancedFormProperty('keyID')); @@ -81,7 +83,7 @@ export const SearchBarAdvancedPropertiesView = compose( connectVocabulary, connect(mapStateToProps, mapDispatchToProps))( withStyles(styles)( - ({ classes, fields, propertyValues, setProps, addProp, getAllFields, vocabulary }: SearchBarAdvancedPropertiesViewProps) => + ({ classes, fields, propertyValues, setProps, setProp, getAllFields, vocabulary }: SearchBarAdvancedPropertiesViewProps) => Properties @@ -91,7 +93,7 @@ export const SearchBarAdvancedPropertiesView = compose( -