diff --git a/src/plugins/discover/public/application/embeddable/search_embeddable.ts b/src/plugins/discover/public/application/embeddable/search_embeddable.ts index 410ab04611ba4..170078076ec6f 100644 --- a/src/plugins/discover/public/application/embeddable/search_embeddable.ts +++ b/src/plugins/discover/public/application/embeddable/search_embeddable.ts @@ -98,7 +98,6 @@ export class SearchEmbeddable private prevTimeRange?: TimeRange; private prevFilters?: Filter[]; private prevQuery?: Query; - private prevSearchSessionId?: string; constructor( { @@ -332,8 +331,7 @@ export class SearchEmbeddable !esFilters.onlyDisabledFiltersChanged(this.input.filters, this.prevFilters) || !_.isEqual(this.prevQuery, this.input.query) || !_.isEqual(this.prevTimeRange, this.input.timeRange) || - !_.isEqual(searchScope.sort, this.input.sort || this.savedSearch.sort) || - this.prevSearchSessionId !== this.input.searchSessionId; + !_.isEqual(searchScope.sort, this.input.sort || this.savedSearch.sort); // If there is column or sort data on the panel, that means the original columns or sort settings have // been overridden in a dashboard. @@ -350,7 +348,6 @@ export class SearchEmbeddable this.prevFilters = this.input.filters; this.prevQuery = this.input.query; this.prevTimeRange = this.input.timeRange; - this.prevSearchSessionId = this.input.searchSessionId; } else if (this.searchScope) { // trigger a digest cycle to make sure non-fetch relevant changes are propagated this.searchScope.$applyAsync(); diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable.test.tsx b/src/plugins/embeddable/public/lib/embeddables/embeddable.test.tsx index 340d851f3eedf..b020006c0c2bb 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable.test.tsx +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable.test.tsx @@ -25,6 +25,7 @@ import { EmbeddableOutput, EmbeddableInput } from './i_embeddable'; import { ViewMode } from '../types'; import { ContactCardEmbeddable } from '../test_samples/embeddables/contact_card/contact_card_embeddable'; import { FilterableEmbeddable } from '../test_samples/embeddables/filterable_embeddable'; +import type { Filter } from '../../../../data/public'; class TestClass { constructor() {} @@ -79,6 +80,20 @@ test('Embeddable reload is called if lastReloadRequest input time changes', asyn expect(hello.reload).toBeCalledTimes(1); }); +test('Embeddable reload is called if lastReloadRequest input time changed and new input is used', async () => { + const hello = new FilterableEmbeddable({ id: '123', filters: [], lastReloadRequestTime: 0 }); + + const aFilter = ({} as unknown) as Filter; + hello.reload = jest.fn(() => { + // when reload is called embeddable already has new input + expect(hello.getInput().filters).toEqual([aFilter]); + }); + + hello.updateInput({ lastReloadRequestTime: 1, filters: [aFilter] }); + + expect(hello.reload).toBeCalledTimes(1); +}); + test('Embeddable reload is not called if lastReloadRequest input time does not change', async () => { const hello = new FilterableEmbeddable({ id: '123', filters: [], lastReloadRequestTime: 1 }); diff --git a/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx b/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx index a558ae6b015ff..c7afc157c1452 100644 --- a/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx +++ b/src/plugins/embeddable/public/lib/embeddables/embeddable.tsx @@ -195,12 +195,13 @@ export abstract class Embeddable< private onResetInput(newInput: TEmbeddableInput) { if (!isEqual(this.input, newInput)) { + const oldLastReloadRequestTime = this.input.lastReloadRequestTime; this.input = newInput; this.input$.next(newInput); this.updateOutput({ title: getPanelTitle(this.input, this.output), } as Partial); - if (this.input.lastReloadRequestTime !== newInput.lastReloadRequestTime) { + if (oldLastReloadRequestTime !== newInput.lastReloadRequestTime) { this.reload(); } } diff --git a/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts b/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts index b352d9fc5cc40..c12a0f0759018 100644 --- a/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts +++ b/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts @@ -100,7 +100,6 @@ export class VisualizeEmbeddable private timeRange?: TimeRange; private query?: Query; private filters?: Filter[]; - private searchSessionId?: string; private visCustomizations?: Pick; private subscriptions: Subscription[] = []; private expression: string = ''; @@ -244,11 +243,6 @@ export class VisualizeEmbeddable dirty = true; } - if (this.searchSessionId !== this.input.searchSessionId) { - this.searchSessionId = this.input.searchSessionId; - dirty = true; - } - if (this.vis.description && this.domNode) { this.domNode.setAttribute('data-description', this.vis.description); } @@ -380,7 +374,7 @@ export class VisualizeEmbeddable query: this.input.query, filters: this.input.filters, }, - searchSessionId: this.searchSessionId, + searchSessionId: this.input.searchSessionId, uiState: this.vis.uiState, inspectorAdapters: this.inspectorAdapters, }; diff --git a/x-pack/plugins/lens/public/editor_frame_service/embeddable/embeddable.tsx b/x-pack/plugins/lens/public/editor_frame_service/embeddable/embeddable.tsx index 7ee0cfd39fba3..10c243a272138 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/embeddable/embeddable.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/embeddable/embeddable.tsx @@ -84,7 +84,6 @@ export class Embeddable timeRange?: TimeRange; query?: Query; filters?: Filter[]; - searchSessionId?: string; lastReloadRequestTime?: number; } = {}; @@ -150,14 +149,12 @@ export class Embeddable if ( !_.isEqual(containerState.timeRange, this.externalSearchContext.timeRange) || !_.isEqual(containerState.query, this.externalSearchContext.query) || - !_.isEqual(cleanedFilters, this.externalSearchContext.filters) || - containerState.searchSessionId !== this.externalSearchContext.searchSessionId + !_.isEqual(cleanedFilters, this.externalSearchContext.filters) ) { this.externalSearchContext = { timeRange: containerState.timeRange, query: containerState.query, lastReloadRequestTime: this.externalSearchContext.lastReloadRequestTime, - searchSessionId: containerState.searchSessionId, filters: cleanedFilters, }; @@ -180,7 +177,7 @@ export class Embeddable ExpressionRenderer={this.expressionRenderer} expression={this.expression || null} searchContext={this.getMergedSearchContext()} - searchSessionId={this.externalSearchContext.searchSessionId} + searchSessionId={this.input.searchSessionId} handleEvent={this.handleEvent} />, domNode