X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/72a55e8c271d97ab084b29022dd087d208188422..ef8180fa2f0b90b1656b1d8c7ef12bc6ea028a0a:/src/views-components/search-bar/search-bar-advanced-properties-view.tsx 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 5076298d..6ebef156 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 @@ -2,25 +2,25 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; +import React from 'react'; import { Dispatch, compose } from 'redux'; import { connect } from 'react-redux'; import { InjectedFormProps, formValueSelector } from 'redux-form'; import { Grid, withStyles, StyleRulesCallback, WithStyles, Button } from '@material-ui/core'; -import { RootState } from '~/store/store'; +import { RootState } from 'store/store'; import { - SEARCH_BAR_ADVANCE_FORM_NAME, - changeAdvanceFormProperty, - resetAdvanceFormProperty, - updateAdvanceFormProperties -} from '~/store/search-bar/search-bar-actions'; -import { PropertyValue } from '~/models/search-bar'; -import { ArvadosTheme } from '~/common/custom-theme'; -import { SearchBarKeyField, SearchBarValueField } from '~/views-components/form-fields/search-bar-form-fields'; -import { Chips } from '~/components/chips/chips'; -import { formatPropertyValue } from "~/common/formatters"; -import { Vocabulary } from '~/models/vocabulary'; + SEARCH_BAR_ADVANCED_FORM_NAME, + changeAdvancedFormProperty, + resetAdvancedFormProperty +} from 'store/search-bar/search-bar-actions'; +import { PropertyValue } from 'models/search-bar'; +import { ArvadosTheme } from 'common/custom-theme'; +import { SearchBarKeyField, SearchBarValueField } from 'views-components/form-fields/search-bar-form-fields'; +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 { isEqual } from 'lodash'; type CssRules = 'label' | 'button'; @@ -46,7 +46,7 @@ interface SearchBarAdvancedPropertiesViewDataProps { interface SearchBarAdvancedPropertiesViewActionProps { setProps: () => void; - addProp: (propertyValues: PropertyValue) => void; + addProp: (propertyValues: PropertyValue, properties: PropertyValue[]) => void; getAllFields: (propertyValues: PropertyValue[]) => PropertyValue[] | []; } @@ -54,7 +54,7 @@ type SearchBarAdvancedPropertiesViewProps = SearchBarAdvancedPropertiesViewDataP & SearchBarAdvancedPropertiesViewActionProps & InjectedFormProps & WithStyles; -const selector = formValueSelector(SEARCH_BAR_ADVANCE_FORM_NAME); +const selector = formValueSelector(SEARCH_BAR_ADVANCED_FORM_NAME); const mapStateToProps = (state: RootState) => { return { propertyValues: selector(state, 'key', 'value', 'keyID', 'valueID') @@ -63,14 +63,26 @@ const mapStateToProps = (state: RootState) => { const mapDispatchToProps = (dispatch: Dispatch) => ({ setProps: (propertyValues: PropertyValue[]) => { - dispatch(changeAdvanceFormProperty('properties', propertyValues)); + dispatch(changeAdvancedFormProperty('properties', propertyValues)); }, - addProp: (propertyValues: PropertyValue) => { - dispatch(updateAdvanceFormProperties(propertyValues)); - dispatch(resetAdvanceFormProperty('key')); - dispatch(resetAdvanceFormProperty('value')); - dispatch(resetAdvanceFormProperty('keyID')); - dispatch(resetAdvanceFormProperty('valueID')); + 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] + )); + dispatch(resetAdvancedFormProperty('key')); + dispatch(resetAdvancedFormProperty('value')); + dispatch(resetAdvancedFormProperty('keyID')); + dispatch(resetAdvancedFormProperty('valueID')); }, getAllFields: (fields: any) => { return fields.getAll() || []; @@ -91,7 +103,7 @@ export const SearchBarAdvancedPropertiesView = compose( -