From a44644b77426bac2403c5482eaa2766ebdf0a624 Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 16 Oct 2023 15:50:57 +0200 Subject: [PATCH 01/15] bugfix: use facets with selected filters from the response EMP-2427 --- ...tory-queries-with-search-response.action.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index 1e7968525e..9334a9ca8d 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -31,7 +31,7 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ const historyQuery = state.historyQueries[indexOfHistoryQuery]; const isCurrentSessionHistoryQuery = historyQuery.timestamp > state.sessionTimeStampInMs; if (!isCurrentSessionHistoryQuery || historyQuery.totalResults == null || searchResponse) { - const filters = createHistoryQueriesFiltersList(searchResponse.request.filters); + const filters = createHistoryQueriesFiltersList(searchResponse.facets); const newHistoryQueries = state.historyQueries.slice(); newHistoryQueries[indexOfHistoryQuery] = { @@ -46,19 +46,23 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ }; /** - * Take filters from the request and push them into a list. + * Take facets from the response and push the selected filters into a list. * - * @param requestFilters - Filters from the request. + * @param responseFacets - Facets from the response. * * @returns A list of selected filters in the history query. * */ function createHistoryQueriesFiltersList( - requestFilters: InternalSearchResponse['request']['filters'] + responseFacets: InternalSearchResponse['facets'] ): Filter[] { - return requestFilters - ? Object.values(requestFilters).reduce((accFilters, filters) => { - accFilters.push(...filters); + return responseFacets + ? Object.values(responseFacets).reduce((accFilters, facet) => { + facet.filters.forEach(filter => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + return filter.selected ? accFilters.push(filter) : []; + }); return accFilters; }, []) : []; From b47d1cf1e17aebb8d71a09ba7778e2bb75eca13a Mon Sep 17 00:00:00 2001 From: acondal Date: Tue, 17 Oct 2023 12:54:07 +0200 Subject: [PATCH 02/15] chore: fix type EMP-2427 --- .../update-history-queries-with-search-response.action.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index 9334a9ca8d..c7a9439ac1 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -53,14 +53,12 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ * @returns A list of selected filters in the history query. * */ -function createHistoryQueriesFiltersList( +export function createHistoryQueriesFiltersList( responseFacets: InternalSearchResponse['facets'] ): Filter[] { return responseFacets - ? Object.values(responseFacets).reduce((accFilters, facet) => { + ? Object.values(responseFacets).reduce((accFilters: Filter[], facet) => { facet.filters.forEach(filter => { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore return filter.selected ? accFilters.push(filter) : []; }); return accFilters; From 13ac230f3b2c96cb80622abfe9be95b74821cd3e Mon Sep 17 00:00:00 2001 From: acondal Date: Tue, 17 Oct 2023 12:55:04 +0200 Subject: [PATCH 03/15] test: update test to use responseFacets EMP-2427 --- .../store/__tests__/actions.spec.ts | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts index 5a31795317..30a343d671 100644 --- a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts +++ b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts @@ -16,6 +16,9 @@ import { HistoryQueriesMutations, HistoryQueriesState } from '../types'; +import { InternalSearchResponse } from '../../../search/index'; +// eslint-disable-next-line max-len +import { createHistoryQueriesFiltersList } from '../actions/update-history-queries-with-search-response.action'; import { resetHistoryQueriesStateWith } from './utils'; describe('testing history queries module actions', () => { @@ -279,12 +282,31 @@ describe('testing history queries module actions', () => { const requestFilters: Record = { categoryPaths: [ { - id: 'categoryIds:c018019b6', + id: 'categoryIds:66dd06d9f', selected: true, modelName: 'HierarchicalFilter' } ] }; + const responseFacets: InternalSearchResponse['facets'] = [ + { + filters: [ + { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + facetId: 'categoryPaths', + id: 'categoryIds:66dd06d9f', + label: 'suede', + modelName: 'HierarchicalFilter', + selected: true, + totalResults: 2 + } + ], + id: 'categoryPaths', + label: 'categoryPaths', + modelName: 'HierarchicalFacet' + } + ]; let gato: HistoryQuery, perro: HistoryQuery; beforeEach(() => { @@ -369,9 +391,9 @@ describe('testing history queries module actions', () => { }); // eslint-disable-next-line max-len - it('updates a history query if search response change because a filter is selected', async () => { + it('updates a history query when the search response changes because a filter is selected', async () => { gato.totalResults = 50; - const selectedFilters = Object.values(requestFilters)[0]; + const selectedFilters = createHistoryQueriesFiltersList(responseFacets); resetStateWith({ historyQueries: [gato, perro] }); await store.dispatch('updateHistoryQueriesWithSearchResponse', { request: { @@ -380,6 +402,7 @@ describe('testing history queries module actions', () => { filters: requestFilters }, status: 'success', + facets: responseFacets, results, totalResults }); From 014e1dfcddae4ca40e7edfc12d718b61c51ec0ce Mon Sep 17 00:00:00 2001 From: acondal Date: Tue, 17 Oct 2023 13:44:22 +0200 Subject: [PATCH 04/15] chore: update function to avoid undefined EMP-2427 --- .../update-history-queries-with-search-response.action.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index c7a9439ac1..a997c039b1 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -56,7 +56,7 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ export function createHistoryQueriesFiltersList( responseFacets: InternalSearchResponse['facets'] ): Filter[] { - return responseFacets + return responseFacets && responseFacets !== undefined ? Object.values(responseFacets).reduce((accFilters: Filter[], facet) => { facet.filters.forEach(filter => { return filter.selected ? accFilters.push(filter) : []; From 8e8f8e7a0f07bef2b2ba2fc7fb8dac2732751faa Mon Sep 17 00:00:00 2001 From: acondal Date: Tue, 17 Oct 2023 15:57:32 +0200 Subject: [PATCH 05/15] chore: rollback update function to avoid undefined EMP-2427 --- .../update-history-queries-with-search-response.action.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index a997c039b1..c7a9439ac1 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -56,7 +56,7 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ export function createHistoryQueriesFiltersList( responseFacets: InternalSearchResponse['facets'] ): Filter[] { - return responseFacets && responseFacets !== undefined + return responseFacets ? Object.values(responseFacets).reduce((accFilters: Filter[], facet) => { facet.filters.forEach(filter => { return filter.selected ? accFilters.push(filter) : []; From e0e34ac8b4b723d38e8b37b5036d125d80349896 Mon Sep 17 00:00:00 2001 From: acondal Date: Wed, 18 Oct 2023 13:15:17 +0200 Subject: [PATCH 06/15] fix: PR fixes EMP-2427 --- .../store/__tests__/actions.spec.ts | 4 +-- ...ory-queries-with-search-response.action.ts | 30 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts index 30a343d671..a7df2f929f 100644 --- a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts +++ b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts @@ -18,7 +18,7 @@ import { } from '../types'; import { InternalSearchResponse } from '../../../search/index'; // eslint-disable-next-line max-len -import { createHistoryQueriesFiltersList } from '../actions/update-history-queries-with-search-response.action'; +import { getHistoryQueriesFiltersList } from '../actions/update-history-queries-with-search-response.action'; import { resetHistoryQueriesStateWith } from './utils'; describe('testing history queries module actions', () => { @@ -393,7 +393,7 @@ describe('testing history queries module actions', () => { // eslint-disable-next-line max-len it('updates a history query when the search response changes because a filter is selected', async () => { gato.totalResults = 50; - const selectedFilters = createHistoryQueriesFiltersList(responseFacets); + const selectedFilters = getHistoryQueriesFiltersList(responseFacets, requestFilters); resetStateWith({ historyQueries: [gato, perro] }); await store.dispatch('updateHistoryQueriesWithSearchResponse', { request: { diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index c7a9439ac1..7a87337b74 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -31,7 +31,10 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ const historyQuery = state.historyQueries[indexOfHistoryQuery]; const isCurrentSessionHistoryQuery = historyQuery.timestamp > state.sessionTimeStampInMs; if (!isCurrentSessionHistoryQuery || historyQuery.totalResults == null || searchResponse) { - const filters = createHistoryQueriesFiltersList(searchResponse.facets); + const filters = getHistoryQueriesFiltersList( + searchResponse.facets, + searchResponse.request.filters + ); const newHistoryQueries = state.historyQueries.slice(); newHistoryQueries[indexOfHistoryQuery] = { @@ -46,21 +49,30 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ }; /** - * Take facets from the response and push the selected filters into a list. + * Creates a selected filters list by comparing request filters and response facets. + * Uses the 'filter.id' to match and merge the objects in a single one with all the keys. * * @param responseFacets - Facets from the response. + * @param requestFilters - Filters from the request. * * @returns A list of selected filters in the history query. * */ -export function createHistoryQueriesFiltersList( - responseFacets: InternalSearchResponse['facets'] +export function getHistoryQueriesFiltersList( + responseFacets: InternalSearchResponse['facets'], + requestFilters: InternalSearchResponse['request']['filters'] ): Filter[] { - return responseFacets - ? Object.values(responseFacets).reduce((accFilters: Filter[], facet) => { - facet.filters.forEach(filter => { - return filter.selected ? accFilters.push(filter) : []; - }); + return requestFilters && responseFacets + ? Object.values(requestFilters).reduce((accFilters, filters) => { + responseFacets.map(facet => + facet.filters.forEach(filter => { + filters.forEach(requestFilter => { + if (requestFilter.id === filter.id) { + accFilters.push(Object.assign(requestFilter, filter)); + } + }); + }) + ); return accFilters; }, []) : []; From b672565130c48bfb8530570a226834e64b6bd333 Mon Sep 17 00:00:00 2001 From: acondal Date: Wed, 18 Oct 2023 14:41:57 +0200 Subject: [PATCH 07/15] test: update test with expected selectedFilters object instead of using function EMP-2427 --- .../store/__tests__/actions.spec.ts | 15 ++++++++++++--- ...history-queries-with-search-response.action.ts | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts index a7df2f929f..62dae07317 100644 --- a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts +++ b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts @@ -17,8 +17,6 @@ import { HistoryQueriesState } from '../types'; import { InternalSearchResponse } from '../../../search/index'; -// eslint-disable-next-line max-len -import { getHistoryQueriesFiltersList } from '../actions/update-history-queries-with-search-response.action'; import { resetHistoryQueriesStateWith } from './utils'; describe('testing history queries module actions', () => { @@ -288,6 +286,18 @@ describe('testing history queries module actions', () => { } ] }; + const selectedFilters: Filter[] = [ + { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + facetId: 'categoryPaths', + id: 'categoryIds:66dd06d9f', + label: 'suede', + modelName: 'HierarchicalFilter', + selected: true, + totalResults: 2 + } + ]; const responseFacets: InternalSearchResponse['facets'] = [ { filters: [ @@ -393,7 +403,6 @@ describe('testing history queries module actions', () => { // eslint-disable-next-line max-len it('updates a history query when the search response changes because a filter is selected', async () => { gato.totalResults = 50; - const selectedFilters = getHistoryQueriesFiltersList(responseFacets, requestFilters); resetStateWith({ historyQueries: [gato, perro] }); await store.dispatch('updateHistoryQueriesWithSearchResponse', { request: { diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index 7a87337b74..e1c4a9b1cd 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -58,7 +58,7 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ * @returns A list of selected filters in the history query. * */ -export function getHistoryQueriesFiltersList( +function getHistoryQueriesFiltersList( responseFacets: InternalSearchResponse['facets'], requestFilters: InternalSearchResponse['request']['filters'] ): Filter[] { From 93d4c4755520f54c26bc9592cb0d0af4e326bdf2 Mon Sep 17 00:00:00 2001 From: acondal Date: Wed, 18 Oct 2023 15:37:21 +0200 Subject: [PATCH 08/15] feat: refactor getHistoryQueriesFiltersList EMP-2427 --- ...update-history-queries-with-search-response.action.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index e1c4a9b1cd..08356cf984 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -50,7 +50,7 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ /** * Creates a selected filters list by comparing request filters and response facets. - * Uses the 'filter.id' to match and merge the objects in a single one with all the keys. + * Uses the 'filter.id' to match the response filters inside each facet with the requested filters. * * @param responseFacets - Facets from the response. * @param requestFilters - Filters from the request. @@ -66,11 +66,8 @@ function getHistoryQueriesFiltersList( ? Object.values(requestFilters).reduce((accFilters, filters) => { responseFacets.map(facet => facet.filters.forEach(filter => { - filters.forEach(requestFilter => { - if (requestFilter.id === filter.id) { - accFilters.push(Object.assign(requestFilter, filter)); - } - }); + filters.filter(requestFilter => requestFilter.id === filter.id); + accFilters = filters; }) ); return accFilters; From c0bf51b7b64b2abae6711c7709a64c0b6f8297ca Mon Sep 17 00:00:00 2001 From: acondal Date: Wed, 18 Oct 2023 16:01:39 +0200 Subject: [PATCH 09/15] Revert "feat: refactor getHistoryQueriesFiltersList" This reverts commit 93d4c4755520f54c26bc9592cb0d0af4e326bdf2. --- ...update-history-queries-with-search-response.action.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index 08356cf984..e1c4a9b1cd 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -50,7 +50,7 @@ export const updateHistoryQueriesWithSearchResponse: HistoryQueriesXStoreModule[ /** * Creates a selected filters list by comparing request filters and response facets. - * Uses the 'filter.id' to match the response filters inside each facet with the requested filters. + * Uses the 'filter.id' to match and merge the objects in a single one with all the keys. * * @param responseFacets - Facets from the response. * @param requestFilters - Filters from the request. @@ -66,8 +66,11 @@ function getHistoryQueriesFiltersList( ? Object.values(requestFilters).reduce((accFilters, filters) => { responseFacets.map(facet => facet.filters.forEach(filter => { - filters.filter(requestFilter => requestFilter.id === filter.id); - accFilters = filters; + filters.forEach(requestFilter => { + if (requestFilter.id === filter.id) { + accFilters.push(Object.assign(requestFilter, filter)); + } + }); }) ); return accFilters; From b2cdd3f35ce884ab9fe08734f286e222b625bc37 Mon Sep 17 00:00:00 2001 From: acondal Date: Wed, 18 Oct 2023 16:11:55 +0200 Subject: [PATCH 10/15] feat: refactor getHistoryQueriesFiltersList EMP-2427 --- ...ory-queries-with-search-response.action.ts | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index e1c4a9b1cd..6f4c9f9a20 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -62,18 +62,16 @@ function getHistoryQueriesFiltersList( responseFacets: InternalSearchResponse['facets'], requestFilters: InternalSearchResponse['request']['filters'] ): Filter[] { - return requestFilters && responseFacets - ? Object.values(requestFilters).reduce((accFilters, filters) => { - responseFacets.map(facet => - facet.filters.forEach(filter => { - filters.forEach(requestFilter => { - if (requestFilter.id === filter.id) { - accFilters.push(Object.assign(requestFilter, filter)); - } - }); - }) - ); - return accFilters; - }, []) - : []; + if (!requestFilters || !responseFacets) { + return []; + } + + return Object.values(requestFilters).flatMap(filters => + filters.map(requestFilter => ({ + ...requestFilter, + ...responseFacets + .flatMap(facet => facet.filters) + .find(filter => filter.id === requestFilter.id) + })) + ); } From 953d9f7a3dc10a5e5063e6fe5a9b74634ec4c290 Mon Sep 17 00:00:00 2001 From: anna condal Date: Mon, 23 Oct 2023 09:13:59 +0200 Subject: [PATCH 11/15] Update packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts Co-authored-by: Guillermo Cacheda --- ...ory-queries-with-search-response.action.ts | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index 6f4c9f9a20..6943666f23 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -66,12 +66,22 @@ function getHistoryQueriesFiltersList( return []; } - return Object.values(requestFilters).flatMap(filters => - filters.map(requestFilter => ({ - ...requestFilter, - ...responseFacets - .flatMap(facet => facet.filters) - .find(filter => filter.id === requestFilter.id) - })) - ); + return Object.entries(requestFilters).flatMap(([facetId, facetFilters]) => { + const matchingFacet = + facetId !== '__unknown__' ? responseFacets.find(facet => facet.id === facetId) : null; + + return facetFilters.reduce((accFilters, requestFilter) => { + const matchingFilter = matchingFacet + ? matchingFacet.filters.find(filter => filter.id === requestFilter.id) + : responseFacets + .flatMap(facet => facet.filters) + .find(filter => filter.id === requestFilter.id); + + if (matchingFilter) { + accFilters.push({ ...matchingFilter, ...requestFilter }); + } + + return accFilters; + }, []); + }); } From 2f0a7017cd027bfd1608affc6063b28635a33b4c Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 23 Oct 2023 09:15:53 +0200 Subject: [PATCH 12/15] feat: avoid checking for matches if no filters in the request EMP-2427 --- ...ory-queries-with-search-response.action.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index 6943666f23..56d05e4cb7 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -64,24 +64,24 @@ function getHistoryQueriesFiltersList( ): Filter[] { if (!requestFilters || !responseFacets) { return []; - } - - return Object.entries(requestFilters).flatMap(([facetId, facetFilters]) => { - const matchingFacet = - facetId !== '__unknown__' ? responseFacets.find(facet => facet.id === facetId) : null; + } else { + return Object.entries(requestFilters).flatMap(([facetId, facetFilters]) => { + const matchingFacet = + facetId !== '__unknown__' ? responseFacets.find(facet => facet.id === facetId) : null; - return facetFilters.reduce((accFilters, requestFilter) => { - const matchingFilter = matchingFacet - ? matchingFacet.filters.find(filter => filter.id === requestFilter.id) - : responseFacets - .flatMap(facet => facet.filters) - .find(filter => filter.id === requestFilter.id); + return facetFilters.reduce((accFilters, requestFilter) => { + const matchingFilter = matchingFacet + ? matchingFacet.filters.find(filter => filter.id === requestFilter.id) + : responseFacets + .flatMap(facet => facet.filters) + .find(filter => filter.id === requestFilter.id); - if (matchingFilter) { - accFilters.push({ ...matchingFilter, ...requestFilter }); - } + if (matchingFilter) { + accFilters.push({ ...matchingFilter, ...requestFilter }); + } - return accFilters; - }, []); - }); + return accFilters; + }, []); + }); + } } From 70f864196af7bf6c0d48b315aa4de56ac5cb6af1 Mon Sep 17 00:00:00 2001 From: acondal Date: Mon, 23 Oct 2023 15:48:28 +0200 Subject: [PATCH 13/15] test(history-queries): test history query gets updated although '__unknown__' facet id in the response EMP-2427 --- .../store/__tests__/actions.spec.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts index 62dae07317..8372aaa102 100644 --- a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts +++ b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts @@ -417,5 +417,41 @@ describe('testing history queries module actions', () => { }); expectHistoryQueriesToEqual([{ ...gato, totalResults, selectedFilters }, perro]); }); + + // eslint-disable-next-line max-len + it('updates a history query when the search response changes although the facet id is unknown', async () => { + gato.totalResults = 50; + resetStateWith({ historyQueries: [gato, perro] }); + await store.dispatch('updateHistoryQueriesWithSearchResponse', { + request: { + query: 'gato', + page: 1, + filters: requestFilters + }, + status: 'success', + facets: [ + { + filters: [ + { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + facetId: 'categoryPaths', + id: 'categoryIds:66dd06d9f', + label: 'suede', + modelName: 'HierarchicalFilter', + selected: true, + totalResults: 2 + } + ], + id: '__unknown__', + label: '__unknown-facet__', + modelName: 'HierarchicalFacet' + } + ], + results, + totalResults + }); + expectHistoryQueriesToEqual([{ ...gato, totalResults, selectedFilters }, perro]); + }); }); }); From 7234dca74bc95e8ba162ccecf96c401689bfe25b Mon Sep 17 00:00:00 2001 From: acondal Date: Thu, 26 Oct 2023 10:28:37 +0200 Subject: [PATCH 14/15] feat(history-queries): push only the requestFilter's selected status to the selectedFilters array EMP-2427 --- .../update-history-queries-with-search-response.action.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts index 56d05e4cb7..f8e6800e23 100644 --- a/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts +++ b/packages/x-components/src/x-modules/history-queries/store/actions/update-history-queries-with-search-response.action.ts @@ -77,7 +77,7 @@ function getHistoryQueriesFiltersList( .find(filter => filter.id === requestFilter.id); if (matchingFilter) { - accFilters.push({ ...matchingFilter, ...requestFilter }); + accFilters.push({ ...matchingFilter, selected: requestFilter.selected }); } return accFilters; From 7acbbac34d519f3af180e873f84af0173828f54c Mon Sep 17 00:00:00 2001 From: acondal Date: Thu, 26 Oct 2023 10:31:24 +0200 Subject: [PATCH 15/15] test(history-queries): update requestFilter object to match the test EMP-2427 --- .../store/__tests__/actions.spec.ts | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts index 8372aaa102..a6fa9aec93 100644 --- a/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts +++ b/packages/x-components/src/x-modules/history-queries/store/__tests__/actions.spec.ts @@ -426,28 +426,18 @@ describe('testing history queries module actions', () => { request: { query: 'gato', page: 1, - filters: requestFilters - }, - status: 'success', - facets: [ - { - filters: [ + filters: { + __unknown__: [ { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - facetId: 'categoryPaths', id: 'categoryIds:66dd06d9f', - label: 'suede', - modelName: 'HierarchicalFilter', selected: true, - totalResults: 2 + modelName: 'RawFilter' } - ], - id: '__unknown__', - label: '__unknown-facet__', - modelName: 'HierarchicalFacet' + ] } - ], + }, + status: 'success', + facets: responseFacets, results, totalResults });