Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add filters to the query preview request #1292

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 4 additions & 2 deletions packages/x-components/src/views/home/Home.vue
Original file line number Diff line number Diff line change
@@ -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: 'summer dress',
filters: ['categoryIds:5b612edb5', 'brand:marni']
},
{
query: 'woven hat'
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -62,7 +62,8 @@
extraParams: {
...this.params,
...this.queryPreviewInfo.extraParams
}
},
filters: this.queryPreviewInfo.filters
};
}

CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -35,8 +35,8 @@
<script lang="ts">
import Vue from 'vue';
import { Component, Prop, Inject, Watch } from 'vue-property-decorator';
import { SearchRequest, Result, Filter } from '@empathyco/x-types';
import { deepEqual, Dictionary } from '@empathyco/x-utils';
import { SearchRequest, Result } 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,21 @@
feature: this.queryFeature,
location: this.location
});
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;
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
}, {} as Record<string, Filter[]>);

return {
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
query: this.queryPreviewInfo.query,
rows: this.config.maxItemsToRequest,
extraParams: { ...this.params, ...this.queryPreviewInfo.extraParams },
filters: filters,
...(origin && { origin })
};
}
Original file line number Diff line number Diff line change
@@ -17,7 +17,8 @@ export const queriesPreviewXStoreModule: QueriesPreviewXStoreModule = {
queriesPreview: {},
selectedQueryPreview: {
query: '',
extraParams: undefined
extraParams: undefined,
filters: undefined
},
params: {}
}),
Original file line number Diff line number Diff line change
@@ -34,6 +34,8 @@ export interface QueryPreviewInfo {
query: string;
/** The extra params to perform the search. */
extraParams?: Dictionary<unknown>;
/** 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. */