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
Show file tree
Hide file tree
Changes from 3 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.
Expand Down
6 changes: 4 additions & 2 deletions packages/x-components/src/views/home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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']
lauramargar marked this conversation as resolved.
Show resolved Hide resolved
},
{
query: 'woven hat'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
extraParams: {
...this.params,
...this.queryPreviewInfo.extraParams
}
},
filters: this.queryPreviewInfo.filters
};
}

Expand Down
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -161,11 +162,19 @@
feature: this.queryFeature,
location: this.location
});

const filtersApply = this.queryPreviewInfo.filters?.reduce((filtersList, filterId) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
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: filtersApply,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
filters: filtersApply,
filters,

...(origin && { origin })
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const queriesPreviewXStoreModule: QueriesPreviewXStoreModule = {
queriesPreview: {},
selectedQueryPreview: {
query: '',
extraParams: undefined
extraParams: undefined,
filters: undefined
},
params: {}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down