diff --git a/src/redux/root/query.selectors.ts b/src/redux/root/query.selectors.ts index a8bfdea3fce0fb764905107d9a0406ba0176e3a0..3088b0dacb0ae0051fb11a60a658af927aff4667 100644 --- a/src/redux/root/query.selectors.ts +++ b/src/redux/root/query.selectors.ts @@ -16,25 +16,20 @@ export const queryDataParamsSelector = createSelector( { modelId, backgroundId, position }, activeOverlaysId, ): QueryDataParams => { + const joinedSearchValue = searchValue.join(';'); + const shouldIncludeSearchValue = searchValue.length > ZERO && joinedSearchValue; + + const shouldIncludeOverlaysId = activeOverlaysId.length > ZERO; + const queryDataParams: QueryDataParams = { perfectMatch, modelId, backgroundId, ...position.last, + ...(shouldIncludeSearchValue ? { searchValue: joinedSearchValue } : {}), + ...(shouldIncludeOverlaysId ? { overlaysId: activeOverlaysId.join(',') } : {}), }; - /** prevent searchValueQuery from being empty */ - if (searchValue.length > ZERO) { - const joinedSearchValue = searchValue.join(';'); - if (joinedSearchValue) { - queryDataParams.searchValue = joinedSearchValue; - } - } - - if (activeOverlaysId.length > ZERO) { - queryDataParams.overlaysId = activeOverlaysId.join(','); - } - return queryDataParams; }, );