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

Fix Brand Recommendations animation on second time appearance #1267

Merged
merged 9 commits into from
Sep 12, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
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 { Result, SearchRequest } 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';
import { xComponentMixin } from '../../../components/x-component.mixin';
import { NoElement } from '../../../components/no-element';
import { RequestStatus } from '../../../store';
Expand All @@ -49,6 +47,7 @@
import { createOrigin } from '../../../utils/origin';
import { debounce } from '../../../utils/debounce';
import { DebouncedFunction } from '../../../utils';
import { LIST_ITEMS_KEY, XProvide } from '../../../components';
Copy link
Contributor

Choose a reason for hiding this comment

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

restore this imports as they were before


/**
* Retrieves a preview of the results of a query and exposes them in the default slot,
Expand Down Expand Up @@ -212,6 +211,16 @@
this.emitQueryPreviewRequestUpdated.cancel();
}

/**
* Removes all the QueriesPreview from the state when the component is destroyed.
* This will prevent re-rendering effects when a query is selected and then deleted from the searchbox.
*
* @internal
*/
protected destroyed(): void {
this.$x.emit('QueriesPreviewDestroyedHook');
}
annacv marked this conversation as resolved.
Show resolved Hide resolved

/**
* Cancels the previous request when the debounced function changes (e.g: the debounceTimeMs
* prop changes or there is a request in progress that cancels it).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ export interface QueriesPreviewXEvents {
* Payload: The query whose preview has been removed.
*/
QueryPreviewUnmountedHook: string;
/**
* The component that shows a Query preview has been destroyed.
*/
QueriesPreviewDestroyedHook: void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this event

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const queriesPreviewXStoreModule: QueriesPreviewXStoreModule = {
clearQueryPreview(state, query) {
Vue.delete(state.queriesPreview, query);
},
removeQueriesPreview(state) {
state.queriesPreview = {};
annacv marked this conversation as resolved.
Show resolved Hide resolved
},
setParams(state, params) {
state.params = params;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export interface QueriesPreviewMutations {
* @param query - Query whose entry will be removed.
*/
clearQueryPreview(query: string): void;
/**
* Removes all queries preview from the state.
*
*/
removeQueriesPreview(): void;
/**
* Sets the extra params of the module.
*
Expand Down
11 changes: 11 additions & 0 deletions packages/x-components/src/x-modules/queries-preview/wiring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export const fetchAndSaveQueryPreviewWire = wireDispatch('fetchAndSaveQueryPrevi

export const clearQueryPreviewWire = wireCommit('clearQueryPreview');

/**
* Removes all the queries preview from the state.
*
* @public
*/

export const removesAllQueriesPreviewWire = wireCommit('removeQueriesPreview');

/**
* Sets the queries preview state `params`.
*
Expand All @@ -59,6 +67,9 @@ export const queriesPreviewWiring = createWiring({
QueryPreviewUnmountedHook: {
clearQueryPreviewWire
},
QueriesPreviewDestroyedHook: {
annacv marked this conversation as resolved.
Show resolved Hide resolved
removesAllQueriesPreviewWire
},
ExtraParamsChanged: {
setQueriesPreviewExtraParamsWire
}
Expand Down