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: filter query preview #1296

Merged
merged 13 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
29 changes: 28 additions & 1 deletion packages/x-components/src/x-modules/facets/wiring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@ import { createRawFilters } from '../../utils/filters';
import { wireCommit, wireService, wireServiceWithoutPayload } from '../../wiring/wires.factory';
import { filter, mapWire } from '../../wiring/wires.operators';
import { createWiring } from '../../wiring/wiring.utils';
import { XEventPayload } from '../../wiring/index';
import { namespacedWireCommit, XEventPayload } from '../../wiring/index';
import { DefaultFacetsService } from './service/facets.service';

/**
* `facets` {@link XModuleName | XModule name}.
*
* @internal
*/
const moduleName = 'facets';

/**
* WireCommit for {@link SearchXModule}.
*
* @internal
*/
const wireCommitModule = namespacedWireCommit(moduleName);
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved

/**
* Wires factory for {@link DefaultFacetsService}.
*/
Expand Down Expand Up @@ -131,6 +145,16 @@ const clearStickyFilters = filter<XEventPayload<'SearchResponseChanged'>>(
}
);

/**
* Sets the filters of the facets module from a selectedQueryPreview's filters.
*
* @public
*/
export const setSelectedFiltersFromPreview = wireCommitModule(
'setFilters',
({ eventPayload: { filters } }) => (filters ? createRawFilters(filters) : [])
);

/**
* Wiring configuration for the {@link FacetsXModule | facets module}.
*
Expand Down Expand Up @@ -181,5 +205,8 @@ export const facetsWiring = createWiring({
},
SearchResponseChanged: {
clearStickyFilters
},
UserAcceptedAQueryPreview: {
setSelectedFiltersFromPreview
}
});
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
* @internal
*/
protected get events(): Partial<XEventsTypes> {
return { UserAcceptedAQueryPreview: this.fullQueryPreviewInfo };
return {
UserAcceptedAQueryPreview: this.fullQueryPreviewInfo
};
}
}
</script>
Expand Down
12 changes: 12 additions & 0 deletions packages/x-components/src/x-modules/search/wiring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '../../wiring/namespaced-wires.factory';
import { WirePayload } from '../../wiring/wiring.types';
import { createWiring } from '../../wiring/wiring.utils';
import { createRawFilters } from '../../utils/index';
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved
import { InternalSearchRequest } from './types';

/**
Expand Down Expand Up @@ -202,6 +203,16 @@ export const setSearchExtraParamsFromPreview = wireCommit(
({ eventPayload: { extraParams } }) => extraParams
);

/**
* Sets the search state `selectedFilters` with the selectedQueryPreview's filters.
*
* @public
*/
export const setSearchSelectedFiltersFromPreview = wireCommit(
'setSelectedFilters',
({ eventPayload: { filters } }) => (filters ? createRawFilters(filters) : [])
);

/**
* Search wiring.
*
Expand Down Expand Up @@ -265,6 +276,7 @@ export const searchWiring = createWiring({
UserAcceptedAQueryPreview: {
setSearchQueryFromPreview,
setSearchExtraParamsFromPreview,
setSearchSelectedFiltersFromPreview,
saveOriginWire
},
QueryPreviewUnselected: {
Expand Down
14 changes: 13 additions & 1 deletion packages/x-components/src/x-modules/url/wiring.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { namespacedWireCommit } from '../../wiring/namespaced-wires.factory';
import { createWiring } from '../../wiring/wiring.utils';
import { createRawFilters } from '../../utils/index';
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved

/**
* WireCommit for {@link UrlXModule}.
Expand Down Expand Up @@ -63,6 +64,16 @@ export const setUrlParamsFromPreview = wireCommit(
({ eventPayload: { extraParams } }) => extraParams
);

/**
* Sets the filters of the url module from a selectedQueryPreview's filters.
*
* @public
*/
export const setUrlSelectedFiltersFromPreview = wireCommit(
'setFilters',
({ eventPayload: { filters } }) => (filters ? createRawFilters(filters) : [])
);

/**
* Sets the scroll of the url module.
*
Expand Down Expand Up @@ -98,7 +109,8 @@ export const urlWiring = createWiring({
},
UserAcceptedAQueryPreview: {
setUrlQueryFromPreview,
setUrlParamsFromPreview
setUrlParamsFromPreview,
setUrlSelectedFiltersFromPreview
},
UserClearedQuery: {
setUrlQuery
Expand Down
Loading