From f179088034915d9520e3d5305e9b8fdc15f6aae5 Mon Sep 17 00:00:00 2001 From: Laura Martinez Garcia Date: Mon, 18 Sep 2023 16:17:46 +0200 Subject: [PATCH 1/4] feat: add filters to the query preview request --- packages/x-components/src/views/home/Home.vue | 6 ++++-- .../components/query-preview-button.vue | 3 ++- .../queries-preview/components/query-preview.vue | 13 +++++++++++-- .../src/x-modules/queries-preview/store/module.ts | 3 ++- .../src/x-modules/queries-preview/store/types.ts | 2 ++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/packages/x-components/src/views/home/Home.vue b/packages/x-components/src/views/home/Home.vue index f47669051f..6b3a0c9df9 100644 --- a/packages/x-components/src/views/home/Home.vue +++ b/packages/x-components/src/views/home/Home.vue @@ -626,10 +626,12 @@ protected queriesPreviewInfo: QueryPreviewInfo[] = [ { query: 'cortina', - extraParams: { store: 'Gijón' } + extraParams: { store: 'Gijón' }, + filters: ['categoryIds:66dd06d9f'] }, { - query: 'marni summer dress' + query: 'marni summer dress', + filters: ['categoryIds:5b612edb5', 'fit:regular'] }, { query: 'woven hat' diff --git a/packages/x-components/src/x-modules/queries-preview/components/query-preview-button.vue b/packages/x-components/src/x-modules/queries-preview/components/query-preview-button.vue index cbd110be42..9f52af291d 100644 --- a/packages/x-components/src/x-modules/queries-preview/components/query-preview-button.vue +++ b/packages/x-components/src/x-modules/queries-preview/components/query-preview-button.vue @@ -62,7 +62,8 @@ extraParams: { ...this.params, ...this.queryPreviewInfo.extraParams - } + }, + filters: this.queryPreviewInfo.filters }; } diff --git a/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue b/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue index c73dae0988..1767237d00 100644 --- a/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue +++ b/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue @@ -36,7 +36,7 @@ import Vue from 'vue'; import { Component, Prop, Inject, Watch } from 'vue-property-decorator'; import { Dictionary } from '@empathyco/x-utils'; - import { SearchRequest, Result } from '@empathyco/x-types'; + import { SearchRequest, Result, Filter } from '@empathyco/x-types'; import { State } from '../../../components/decorators/store.decorators'; import { LIST_ITEMS_KEY } from '../../../components/decorators/injection.consts'; import { XProvide } from '../../../components/decorators/injection.decorators'; @@ -50,6 +50,7 @@ import { createOrigin } from '../../../utils/origin'; import { debounce } from '../../../utils/debounce'; import { DebouncedFunction } from '../../../utils'; + import { createRawFilter } from '../../../__stubs__/index'; /** * Retrieves a preview of the results of a query and exposes them in the default slot, @@ -161,11 +162,19 @@ feature: this.queryFeature, location: this.location }); - + const filtersApply = this.queryPreviewInfo.filters?.reduce((filtersList, filterId) => { + const facetId = filterId.split(':')[0]; + const rawFilter = createRawFilter(filterId); + filtersList[facetId] = filtersList[facetId] + ? filtersList[facetId].concat(rawFilter) + : [rawFilter]; + return filtersList; + }, {} as Record); return { query: this.queryPreviewInfo.query, rows: this.config.maxItemsToRequest, extraParams: { ...this.params, ...this.queryPreviewInfo.extraParams }, + filters: filtersApply, ...(origin && { origin }) }; } diff --git a/packages/x-components/src/x-modules/queries-preview/store/module.ts b/packages/x-components/src/x-modules/queries-preview/store/module.ts index 5a5836ed80..04f6fb377c 100644 --- a/packages/x-components/src/x-modules/queries-preview/store/module.ts +++ b/packages/x-components/src/x-modules/queries-preview/store/module.ts @@ -17,7 +17,8 @@ export const queriesPreviewXStoreModule: QueriesPreviewXStoreModule = { queriesPreview: {}, selectedQueryPreview: { query: '', - extraParams: undefined + extraParams: undefined, + filters: undefined }, params: {} }), diff --git a/packages/x-components/src/x-modules/queries-preview/store/types.ts b/packages/x-components/src/x-modules/queries-preview/store/types.ts index a6fafad0d6..7e562242f8 100644 --- a/packages/x-components/src/x-modules/queries-preview/store/types.ts +++ b/packages/x-components/src/x-modules/queries-preview/store/types.ts @@ -34,6 +34,8 @@ export interface QueryPreviewInfo { query: string; /** The extra params to perform the search. */ extraParams?: Dictionary; + /** The filters to perform the search. */ + filters?: string[]; /** An optional title for the container. */ title?: string; /** Any other additional information to render the preview with. */ From b0569a58b39dec3c6df524b88ef7c5d302f25b3c Mon Sep 17 00:00:00 2001 From: Laura Martinez Garcia Date: Tue, 19 Sep 2023 10:56:14 +0200 Subject: [PATCH 2/4] fix: change import path --- .../src/__stubs__/semantic-queries-stubs.factory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x-components/src/__stubs__/semantic-queries-stubs.factory.ts b/packages/x-components/src/__stubs__/semantic-queries-stubs.factory.ts index 0ca0767968..facc2ad981 100644 --- a/packages/x-components/src/__stubs__/semantic-queries-stubs.factory.ts +++ b/packages/x-components/src/__stubs__/semantic-queries-stubs.factory.ts @@ -1,6 +1,6 @@ import { deepMerge } from '@empathyco/x-deep-merge'; import { SemanticQueriesResponse, SemanticQuery } from '@empathyco/x-types'; -import { DeepPartial } from '@empathyco/x-utils/src/types/utils.types'; +import { DeepPartial } from '@empathyco/x-utils'; /** * Creates a {@link SemanticQuery} stub with the provided options. From f0681286bd555ef451769b26c12f6e8c345693a6 Mon Sep 17 00:00:00 2001 From: lauramargar <114984466+lauramargar@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:49:10 +0200 Subject: [PATCH 3/4] Update packages/x-components/src/views/home/Home.vue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gerardo Vázquez --- packages/x-components/src/views/home/Home.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/x-components/src/views/home/Home.vue b/packages/x-components/src/views/home/Home.vue index 6b3a0c9df9..f2fc5416f1 100644 --- a/packages/x-components/src/views/home/Home.vue +++ b/packages/x-components/src/views/home/Home.vue @@ -630,8 +630,8 @@ filters: ['categoryIds:66dd06d9f'] }, { - query: 'marni summer dress', - filters: ['categoryIds:5b612edb5', 'fit:regular'] + query: 'summer dress', + filters: ['categoryIds:5b612edb5', 'brand:marni'] }, { query: 'woven hat' From bf9e7437ddb5ae722f273d7ad03189840c92aca8 Mon Sep 17 00:00:00 2001 From: Laura Martinez Garcia Date: Wed, 20 Sep 2023 08:26:16 +0200 Subject: [PATCH 4/4] chore: fix pr comments and update tests --- .../__tests__/query-preview.spec.ts | 33 ++++++++++++++++++- .../components/query-preview.vue | 6 ++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts b/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts index 8fabdef16b..18fadcb0e4 100644 --- a/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts +++ b/packages/x-components/src/x-modules/queries-preview/components/__tests__/query-preview.spec.ts @@ -103,7 +103,11 @@ describe('query preview', () => { it('sends the `QueryPreviewRequestUpdated` event', async () => { const { queryPreviewRequestUpdatedSpy, wrapper, updateExtraParams } = renderQueryPreview({ - queryPreviewInfo: { query: 'shoes', extraParams: { directory: 'Magrathea' } } + queryPreviewInfo: { + query: 'shoes', + extraParams: { directory: 'Magrathea' }, + filters: ['fit:regular'] + } }); jest.advanceTimersByTime(0); // Wait for first emission. @@ -112,6 +116,15 @@ describe('query preview', () => { extraParams: { directory: 'Magrathea' }, + filters: { + fit: [ + { + id: 'fit:regular', + modelName: 'RawFilter', + selected: true + } + ] + }, origin: undefined, query: 'shoes', rows: 24 @@ -126,6 +139,15 @@ describe('query preview', () => { extraParams: { directory: 'Magrathea' }, + filters: { + fit: [ + { + id: 'fit:regular', + modelName: 'RawFilter', + selected: true + } + ] + }, origin: 'popular_search:none', query: 'shoes', rows: 24 @@ -139,6 +161,15 @@ describe('query preview', () => { directory: 'Magrathea', store: 'Uganda' }, + filters: { + fit: [ + { + id: 'fit:regular', + modelName: 'RawFilter', + selected: true + } + ] + }, origin: 'popular_search:none', query: 'shoes', rows: 24 diff --git a/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue b/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue index 186668b617..10d7f7dc43 100644 --- a/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue +++ b/packages/x-components/src/x-modules/queries-preview/components/query-preview.vue @@ -162,19 +162,21 @@ feature: this.queryFeature, location: this.location }); - const filtersApply = this.queryPreviewInfo.filters?.reduce((filtersList, filterId) => { + const filters = this.queryPreviewInfo.filters?.reduce((filtersList, filterId) => { const facetId = filterId.split(':')[0]; const rawFilter = createRawFilter(filterId); filtersList[facetId] = filtersList[facetId] ? filtersList[facetId].concat(rawFilter) : [rawFilter]; + return filtersList; }, {} as Record); + return { query: this.queryPreviewInfo.query, rows: this.config.maxItemsToRequest, extraParams: { ...this.params, ...this.queryPreviewInfo.extraParams }, - filters: filtersApply, + filters: filters, ...(origin && { origin }) }; }