X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cfc5eebd666412870df195559adedeefe4178248..17963753e57340121942857300c41c7852275c4b:/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 5e2acb7584..eb049b7625 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 @@ -3,27 +3,27 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { Dispatch } from 'redux'; +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 { - SEARCH_BAR_ADVANCE_FORM_NAME, - changeAdvanceFormProperty, - updateAdvanceFormProperties +import { + SEARCH_BAR_ADVANCED_FORM_NAME, + changeAdvancedFormProperty, + resetAdvancedFormProperty } from '~/store/search-bar/search-bar-actions'; -import { PropertyValues } from '~/models/search-bar'; +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'; -type CssRules = 'root' | 'label' | 'button'; +type CssRules = 'label' | 'button'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ - root: { - - }, label: { color: theme.palette.grey["500"], fontSize: '0.8125rem', @@ -38,46 +38,52 @@ interface SearchBarAdvancedPropertiesViewDataProps { submitting: boolean; invalid: boolean; pristine: boolean; - propertyValues: PropertyValues; - fields: PropertyValues[]; + propertyValues: PropertyValue; + fields: PropertyValue[]; + vocabulary: Vocabulary; } interface SearchBarAdvancedPropertiesViewActionProps { setProps: () => void; - addProp: (propertyValues: PropertyValues) => void; - getAllFields: (propertyValues: PropertyValues[]) => PropertyValues[] | []; + setProp: (propertyValues: PropertyValue, properties: PropertyValue[]) => void; + getAllFields: (propertyValues: PropertyValue[]) => PropertyValue[] | []; } -type SearchBarAdvancedPropertiesViewProps = SearchBarAdvancedPropertiesViewDataProps - & SearchBarAdvancedPropertiesViewActionProps +type SearchBarAdvancedPropertiesViewProps = SearchBarAdvancedPropertiesViewDataProps + & 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, 'propertyKey', 'propertyValue') + propertyValues: selector(state, 'key', 'value', 'keyID', 'valueID') }; }; const mapDispatchToProps = (dispatch: Dispatch) => ({ - setProps: (propertyValues: PropertyValues[]) => { - dispatch(changeAdvanceFormProperty('properties', propertyValues)); + setProps: (propertyValues: PropertyValue[]) => { + dispatch(changeAdvancedFormProperty('properties', propertyValues)); }, - addProp: (propertyValues: PropertyValues) => { - dispatch(updateAdvanceFormProperties(propertyValues)); - dispatch(changeAdvanceFormProperty('propertyKey')); - dispatch(changeAdvanceFormProperty('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')); + dispatch(resetAdvancedFormProperty('valueID')); }, getAllFields: (fields: any) => { return fields.getAll() || []; } }); -export const SearchBarAdvancedPropertiesView = - connect(mapStateToProps, mapDispatchToProps) - - (withStyles(styles)( - ({ classes, fields, propertyValues, setProps, addProp, getAllFields }: SearchBarAdvancedPropertiesViewProps) => +export const SearchBarAdvancedPropertiesView = compose( + connectVocabulary, + connect(mapStateToProps, mapDispatchToProps))( + withStyles(styles)( + ({ classes, fields, propertyValues, setProps, setProp, getAllFields, vocabulary }: SearchBarAdvancedPropertiesViewProps) => Properties @@ -87,20 +93,21 @@ export const SearchBarAdvancedPropertiesView = - - `${field.propertyKey}: ${field.propertyValue}`} /> + onChange={setProps} + getLabel={(field: PropertyValue) => formatPropertyValue(field, vocabulary)} /> ) -); \ No newline at end of file +);