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: query preview components allow adding extra params to the request #1270

Merged
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
b116bff
feat: Add extraParams to QueryPreviewInfo type
annacv Jul 31, 2023
b60bbd9
wip: Add new prop to add injected params to the request
annacv Jul 31, 2023
5af7914
feat: Type and doc of injectedParams changed
mariorey Aug 1, 2023
a627cc3
feat: injectedParams are now linked to their query
mariorey Aug 1, 2023
456d207
feat: injectedParams type changed
mariorey Aug 1, 2023
a75a05b
feat: Change structure of injected params
mariorey Aug 1, 2023
1b28629
feat: Change static queries preview for X-components
mariorey Aug 1, 2023
72548f6
test: Add injectedParams test
annacv Aug 1, 2023
ac45301
test: Update query-preview-list.spec.ts test & component types
annacv Aug 1, 2023
cee26fa
doc: Update doc
annacv Aug 3, 2023
8e1a008
wip: create UserAcceptedAQueryPreview XEvent
annacv Aug 3, 2023
a51a00d
wip: create searchQueryPreview action
annacv Aug 3, 2023
af6a719
wip: Delete custom event from queries preview
mariorey Aug 3, 2023
663521e
wip: Add custom event to search module to perform the query preview s…
mariorey Aug 3, 2023
48ce240
wip: save selected query preview & perform a search
annacv Aug 7, 2023
1a9c819
wip: save selected query preview & perform a search
annacv Aug 8, 2023
d7d2896
feature: Add event to add the query to the different components
mariorey Aug 8, 2023
201c7c1
bugfix: Check if request should be performed
mariorey Aug 8, 2023
e95532c
bugfix: Change from sending request to search module to sending param…
mariorey Aug 9, 2023
d0e5983
feature: Related Tags and Next Queries are now working with the Query…
mariorey Aug 9, 2023
7a560e7
Code refactoring
mariorey Aug 9, 2023
f7304ae
feat: replace request getter by a query object & use it in emitters
annacv Aug 10, 2023
4fbae0b
feat: undefined on clear selected query to avoid checking object prop
annacv Aug 10, 2023
9f8711b
feature: Add query preview custom extra params to semantic-queries mo…
mariorey Aug 10, 2023
7226167
bugfix: Add selected Query Preview check to throw the correct event i…
mariorey Aug 10, 2023
25602d4
bugfix: Remove state modifying / States shouldn't be modified directly
mariorey Aug 10, 2023
1de54b3
bugfix: Add UserAcceptedQueryPreview event to search-input.vue. Now U…
mariorey Aug 10, 2023
bc1d3a1
bugfix: Remove unnecessary checks
mariorey Aug 14, 2023
773db9b
bugfix: Add selected Query Preview to search box to correctly perform…
mariorey Aug 15, 2023
f54611e
bugfix: Queries Preview works with UserAcceptedAQuery now
mariorey Aug 16, 2023
07ddc70
bugfix: Delete selectedQueryPreview state from search module
mariorey Aug 16, 2023
2b2a614
bugfix: Remove unnecessary events
mariorey Aug 16, 2023
cea3da7
feat: set debounceInMs in the module config
annacv Aug 17, 2023
57374af
feat: rm debounce
annacv Aug 17, 2023
3a087e0
chore: rm comment
annacv Aug 17, 2023
d12fe0d
chore: rm unused
annacv Aug 17, 2023
dfc7677
feat: rollback keep debounce to ensure search is not being refined
annacv Aug 21, 2023
8afac86
feat: set selected query preview inside modules, rm userAcceptedAQuer…
annacv Aug 21, 2023
0c89eaf
feat: use emitter to reset initial params, set params in search module
annacv Aug 21, 2023
c099e1d
chore: pass queryInfo rellevant info directly to commit
annacv Aug 22, 2023
13c2bd3
feat: change emitter name & update as a queryPreview event instead of…
annacv Aug 22, 2023
a900051
feat: test committing with payload working fine
annacv Aug 22, 2023
ba6f6ed
feat: emitter is needed to setParams in modules as it comes from a ge…
annacv Aug 22, 2023
87a0f24
feat: use selected query preview getter to feed the emiter, test in u…
annacv Aug 22, 2023
593dfc8
feat: use SelectedQueryPreviewChanged emitter in modules
annacv Aug 22, 2023
2572bf7
doc: fix doc to pass build
annacv Aug 22, 2023
b19770a
fix: (feat) Add type to avoid undefined error when no items w/extraPa…
annacv Aug 23, 2023
c4eaa5d
feat: add SelectedQueryPreviewChanged in HistoryQ wiring
annacv Aug 23, 2023
f6752b9
feat: add SelectedQueryPreviewChanged in recommendations wiring
annacv Aug 23, 2023
6d10177
chore: add missed doc
annacv Aug 23, 2023
88cbab6
feat: tests, ok. Use UserAcceptedAQueryPreview & use emitter to updat…
annacv Aug 23, 2023
2e0768b
wip
CachedaCodes Aug 28, 2023
0b203a5
feat: query preview components allow adding extra params to the request
CachedaCodes Aug 29, 2023
9826536
chore: update wirings and tests
CachedaCodes Sep 4, 2023
aaa420b
chore: fix wiring exports
CachedaCodes Sep 4, 2023
2c33b9b
chore: add query preview button and components tests
CachedaCodes Sep 6, 2023
602846b
chore: remove extra params from cortina query preview
CachedaCodes Sep 6, 2023
c116447
chore: unify wiring namings
CachedaCodes Sep 6, 2023
7a97094
chore: use query preview button in home
CachedaCodes Sep 6, 2023
8bb4a94
chore: fix docs warnings
CachedaCodes Sep 7, 2023
fa9bf2c
chore: remove unused getters
CachedaCodes Sep 7, 2023
e49dd4b
chore: fix query preview list test
CachedaCodes Sep 7, 2023
cd8bb29
chore: fix e2e tests
CachedaCodes Sep 7, 2023
092e933
chore: fix PR comments. Fix docs, better object compare and leftover …
CachedaCodes Sep 12, 2023
4051a3d
chore: fix import
CachedaCodes Sep 12, 2023
fdb4966
Merge remote-tracking branch 'origin/main' into feature/EMP-1554-Quer…
CachedaCodes Sep 12, 2023
bf9d6cc
chore: fix merge error
CachedaCodes Sep 12, 2023
7277501
chore: fix of the fixes
CachedaCodes Sep 14, 2023
a96e323
chore: remove sort
CachedaCodes Sep 15, 2023
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
4 changes: 2 additions & 2 deletions packages/x-components/src/plugins/x-emitters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export function registerStoreEmitters(
selector(store.state.x[name], safeGettersProxy);
const emit: (
newValue: XEventPayload<typeof event>,
oldValue: XEventPayload<typeof event>
oldValue?: XEventPayload<typeof event>
) => void = (newValue, oldValue) => {
if (filter(newValue, oldValue)) {
if (filter(newValue, oldValue, store.state.x[name])) {
bus.emit(event, newValue, { ...metadata, moduleName: name, oldValue });
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,19 @@ export interface StateSelector<ReturnType, State extends Dictionary, Getters ext
extends WatchOptions {
selector: SimpleStateSelector<ReturnType, State, Getters>;
/**
* Checks if the value of the selector has changed.
* Asserts if the event should really be emitted taking into account the new and old values and
* the module state.
*
* @remarks
* This function exist because Vue will not stop reactivity propagation if the observed variable
* is an `object`, an `Array`, or the `deep` mode has been enabled.
*
* @param newValue - The new value.
* @param oldValue - The old value.
* @param state - The state of the {@link XModule} where this selector is used.
* @returns True if the value has really changed.
*/
filter?(newValue: ReturnType, oldValue: ReturnType): boolean;
filter?(newValue: ReturnType, oldValue: ReturnType, state: State): boolean;
Copy link
Contributor Author

@CachedaCodes CachedaCodes Aug 29, 2023

Choose a reason for hiding this comment

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

Adding access to the module's state here to be able to filter if the event of the emitter is fired based on the current values of the state.

metadata?: Partial<WireMetadata>;
}

Expand Down
42 changes: 36 additions & 6 deletions packages/x-components/src/views/home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,17 @@
<LocationProvider location="no_results">
<QueryPreviewList
:debounceTimeMs="250"
:queries="queriesToPreview"
#default="{ query, totalResults, results }"
:queriesPreviewInfo="queriesPreviewInfo"
#default="{ queryPreviewInfo, totalResults, results }"
data-test="brand-recommendation"
>
<div class="x-flex x-flex-col x-gap-8 x-mb-16">
<h1 class="x-title2">{{ query }} ({{ totalResults }})</h1>
<QueryPreviewButton
class="x-w-fit x-button-xl x-button-ghost"
:queryPreviewInfo="queryPreviewInfo"
>
{{ `${queryPreviewInfo.query} (${totalResults})` }}
</QueryPreviewButton>
<SlidingPanel :resetOnContentChange="false">
<div class="x-flex x-gap-8">
<Result
Expand Down Expand Up @@ -348,8 +353,8 @@
</h1>
<LocationProvider :location="$x.noResults ? 'no_results' : 'low_results'">
<QueryPreviewList
:queries="queries"
#default="{ query, results }"
:queries-preview-info="queries.map(q => ({ query: q }))"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move this to a property

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but queries comes from the scope slot from SemanticQueries, I can't make it a property. I could move the mapping to a function that receives the queries list.

#default="{ queryPreviewInfo: { query }, results }"
queryFeature="semantics"
>
<div
Expand Down Expand Up @@ -496,6 +501,8 @@
import SemanticQueries from '../../x-modules/semantic-queries/components/semantic-queries.vue';
import SemanticQuery from '../../x-modules/semantic-queries/components/semantic-query.vue';
import { useQueriesPreview } from '../../x-modules/queries-preview/composables/use-queries-preview.composable';
import { QueryPreviewInfo } from '../../x-modules/queries-preview/store/types';
import QueryPreviewButton from '../../x-modules/queries-preview/components/query-preview-button.vue';
import Aside from './aside.vue';
import PredictiveLayer from './predictive-layer.vue';
import Result from './result.vue';
Expand All @@ -507,6 +514,7 @@
infiniteScroll
},
components: {
QueryPreviewButton,
DisplayResultProvider,
FallbackDisclaimer,
QueryPreviewList,
Expand Down Expand Up @@ -615,7 +623,29 @@
}
};

protected queriesToPreview = ['sunglasses', 'handbag', 'earrings', 'jeans', 't-shirt'];
protected queriesPreviewInfo: QueryPreviewInfo[] = [
{
query: 'cortina',
extraParams: { store: 'Gijón' }
},
{
query: 'marni summer dress'
},
{
query: 'woven hat'
},
{
query: 'jeans',
extraParams: { store: 'Gijón' }
},
{
query: 't-shirt'
}
];

protected get queries(): string[] {
return this.queriesPreviewInfo.map(item => item.query);
}
CachedaCodes marked this conversation as resolved.
Show resolved Hide resolved

toggleE2EAdapter(): void {
adapterConfig.e2e = !adapterConfig.e2e;
Expand Down
15 changes: 1 addition & 14 deletions packages/x-components/src/x-installer/api/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { XBus } from '@empathyco/x-bus';
import { DocumentDirection } from '../../plugins/x-plugin.types';
import { XEvent, XEventPayload, XEventsTypes } from '../../wiring/events.types';
import { WireMetadata } from '../../wiring/wiring.types';
import { QueryPreviewInfo } from '../../x-modules/queries-preview/index';

/**
* Interface with the API functions exposes as X
Expand Down Expand Up @@ -126,17 +127,3 @@ export interface SnippetConfig {
* @public
*/
export type NormalisedSnippetConfig = RequiredProperties<SnippetConfig, 'uiLang'>;

/**
* Information to render a query preview with.
*
* @public
*/
export interface QueryPreviewInfo {
/** The query to search for. */
query: string;
/** An optional title for the container. */
title?: string;
/** Any other additional information to render the preview with. */
[extra: string]: unknown;
}
25 changes: 25 additions & 0 deletions packages/x-components/src/x-modules/history-queries/wiring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,34 @@ const wireDispatchWithoutPayload = namespacedWireDispatchWithoutPayload(moduleNa
*/
export const addQueryToHistoryQueries = wireDispatch('addQueryToHistory');

/**
* Saves the selectedQueryPreview query into the history queries.
*
* @public
*/
export const addQueryToHistoryQueriesFromPreview = wireDispatch(
'addQueryToHistory',
({ eventPayload: { query } }) => query
);

/**
* Sets the query of the history queries module. Used for searching into the history queries.
*
* @public
*/
export const setHistoryQueriesQuery = wireCommit('setQuery');

/**
* Sets the query of the history queries module from a selectedQueryPreview's query.
* Used for searching into the history queries.
*
* @public
*/
export const setHistoryQueriesQueryFromPreview = wireCommit(
'setQuery',
({ eventPayload: { query } }) => query
);

/**
* Sets the history queries state `query` from url.
*
Expand Down Expand Up @@ -169,5 +190,9 @@ export const historyQueriesWiring = createWiring({
},
SearchResponseChanged: {
updateHistoryQueriesWithSearchResponse
},
UserAcceptedAQueryPreview: {
setHistoryQueriesQueryFromPreview,
addQueryToHistoryQueriesFromPreview
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ const wireDispatchWithoutPayload = namespacedWireDispatchWithoutPayload(moduleNa
*/
export const setIdentifierResultsQuery = wireDispatch('saveQuery');

/**
* Sets the identifier-results module query from a selectedQueryPreview's query.
*
* @public
*/
export const setIdentifierResultsQueryFromPreview = wireDispatch(
'saveQuery',
({ eventPayload: { query } }) => query
);

/**
* Clears the identifier-results module query.
*
Expand Down Expand Up @@ -127,5 +137,9 @@ export const identifierResultsWiring = createWiring({
},
UserClickedOutOfMainModal: {
clearIdentifierResultsQuery
},
UserAcceptedAQueryPreview: {
setIdentifierResultsQueryFromPreview,
saveIdentifierResultsOriginWire
}
});
24 changes: 24 additions & 0 deletions packages/x-components/src/x-modules/next-queries/wiring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ const wireDispatch: NamespacedWireDispatch<typeof moduleName> = namespacedWireDi
*/
export const setNextQueriesQuery = wireCommit('setQuery');

/**
* Sets the next queries state `query` with a selectedQueryPreview's query.
*
* @public
*/
export const setNextQueriesQueryFromPreview = wireCommit(
'setParams',
({ eventPayload: { query } }) => query
);

/**
* Sets the next queries state `query` from url.
*
Expand All @@ -59,6 +69,16 @@ const setUrlParams = wireDispatch('setUrlParams');
*/
export const setNextQueriesExtraParams = wireCommit('setParams');

/**
* Sets the next queries state `params` with a selectedQueryPreview's extraParams.
*
* @public
*/
export const setNextQueriesExtraParamsFromPreview = wireCommit(
'setParams',
({ eventPayload: { extraParams } }) => extraParams
);

/**
* Requests and stores the next queries.
*
Expand Down Expand Up @@ -129,5 +149,9 @@ export const nextQueriesWiring = createWiring({
},
NextQueryPreviewMountedHook: {
fetchAndSaveNextQueryPreviewWire
},
UserAcceptedAQueryPreview: {
setNextQueriesQueryFromPreview,
setNextQueriesExtraParamsFromPreview
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createWiring } from '../../wiring/wiring.utils';
*/
const moduleName = 'popularSearches';
/**
* WireDispatchfor {@link PopularSearchesXModule}.
* WireDispatch for {@link PopularSearchesXModule}.
*
* @internal
*/
Expand Down
Loading