From: Lucas Di Pentima Date: Mon, 18 Nov 2019 12:58:18 +0000 (-0300) Subject: 15069: Use properties' key/value ids on search when possible. X-Git-Tag: 2.0.0~28^2~8 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/c1afdcdfebdb6cb34eb9533345e23789519917df 15069: Use properties' key/value ids on search when possible. Also, properly reset key/value fields on the advanced search UI every time a new property is added to the search expression. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/models/search-bar.ts b/src/models/search-bar.ts index effaeed4..2d181b37 100644 --- a/src/models/search-bar.ts +++ b/src/models/search-bar.ts @@ -19,5 +19,7 @@ export type SearchBarAdvanceFormData = { export interface PropertyValue { key: string; + keyID?: string; value: string; + valueID?: string; } diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts index d9238ef2..c4a2d45f 100644 --- a/src/store/search-bar/search-bar-actions.ts +++ b/src/store/search-bar/search-bar-actions.ts @@ -5,7 +5,7 @@ import { ofType, unionize, UnionOf } from "~/common/unionize"; import { GroupContentsResource, GroupContentsResourcePrefix } from '~/services/groups-service/groups-service'; import { Dispatch } from 'redux'; -import { arrayPush, change, initialize } from 'redux-form'; +import { arrayPush, change, initialize, untouch } from 'redux-form'; import { RootState } from '~/store/store'; import { initUserProject, treePickerActions } from '~/store/tree-picker/tree-picker-actions'; import { ServiceRepository } from '~/services/services'; @@ -268,7 +268,7 @@ export const getQueryFromAdvancedData = (data: SearchBarAdvanceFormData, prevDat dateFrom: data.dateFrom, dateTo: data.dateTo, }; - (data.properties || []).forEach(p => fo[`prop-"${p.key}"`] = `"${p.value}"`); + (data.properties || []).forEach(p => fo[`prop-"${p.keyID || p.key}"`] = `"${p.valueID || p.value}"`); return fo; }; @@ -281,7 +281,7 @@ export const getQueryFromAdvancedData = (data: SearchBarAdvanceFormData, prevDat ['to', 'dateTo'] ]; _.union(data.properties, prevData ? prevData.properties : []) - .forEach(p => keyMap.push([`has:"${p.key}"`, `prop-"${p.key}"`])); + .forEach(p => keyMap.push([`has:"${p.keyID || p.key}"`, `prop-"${p.keyID || p.key}"`])); if (prevData) { const obj = getModifiedKeysValues(flatData(data), flatData(prevData)); @@ -366,9 +366,15 @@ export const initAdvanceFormProjectsTree = () => dispatch(initUserProject(SEARCH_BAR_ADVANCE_FORM_PICKER_ID)); }; -export const changeAdvanceFormProperty = (property: string, value: PropertyValue[] | string = '') => +export const changeAdvanceFormProperty = (propertyField: string, value: PropertyValue[] | string = '') => (dispatch: Dispatch) => { - dispatch(change(SEARCH_BAR_ADVANCE_FORM_NAME, property, value)); + dispatch(change(SEARCH_BAR_ADVANCE_FORM_NAME, propertyField, value)); + }; + +export const resetAdvanceFormProperty = (propertyField: string) => + (dispatch: Dispatch) => { + dispatch(change(SEARCH_BAR_ADVANCE_FORM_NAME, propertyField, null)); + dispatch(untouch(SEARCH_BAR_ADVANCE_FORM_NAME, propertyField)); }; export const updateAdvanceFormProperties = (propertyValues: PropertyValue) => 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 d4044f95..9bb6ad90 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,6 +11,7 @@ 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'; @@ -53,7 +54,7 @@ type SearchBarAdvancedPropertiesViewProps = SearchBarAdvancedPropertiesViewDataP const selector = formValueSelector(SEARCH_BAR_ADVANCE_FORM_NAME); const mapStateToProps = (state: RootState) => { return { - propertyValues: selector(state, 'key', 'value') + propertyValues: selector(state, 'key', 'value', 'keyID', 'valueID') }; }; @@ -63,8 +64,10 @@ const mapDispatchToProps = (dispatch: Dispatch) => ({ }, addProp: (propertyValues: PropertyValue) => { dispatch(updateAdvanceFormProperties(propertyValues)); - dispatch(changeAdvanceFormProperty('key')); - dispatch(changeAdvanceFormProperty('value')); + dispatch(resetAdvanceFormProperty('key')); + dispatch(resetAdvanceFormProperty('value')); + dispatch(resetAdvanceFormProperty('keyID')); + dispatch(resetAdvanceFormProperty('valueID')); }, getAllFields: (fields: any) => { return fields.getAll() || [];