mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 10:40:07 -04:00
[Dashboard] Fix for controls selections causing multiple fetches (#224761)
Prevents Dashboard from firing two requests when a Control change is made.
This commit is contained in:
parent
2de5294819
commit
b0d7180ff8
3 changed files with 18 additions and 4 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
import type { DataViewFieldBase, DataViewBase, TimeRange, Filter } from '@kbn/es-query';
|
||||
import { buildExistsFilter, disableFilter, pinFilter, toggleFilterNegated } from '@kbn/es-query';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { BehaviorSubject, Observable } from 'rxjs';
|
||||
import { newSession$ } from './new_session';
|
||||
|
||||
describe('newSession$', () => {
|
||||
|
@ -56,6 +56,21 @@ describe('newSession$', () => {
|
|||
subscription.unsubscribe();
|
||||
});
|
||||
|
||||
test('should fire on filter change when reload has not yet been called', async () => {
|
||||
const reloadApi = { ...api, reload$: new Observable<void>() };
|
||||
filters$.next([existsFilter]);
|
||||
|
||||
let count = 0;
|
||||
const subscription = newSession$(reloadApi).subscribe(() => {
|
||||
count++;
|
||||
});
|
||||
|
||||
filters$.next([toggleFilterNegated(existsFilter)]);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
expect(count).toBe(1);
|
||||
subscription.unsubscribe();
|
||||
});
|
||||
|
||||
test('should not fire on disabled filter change', async () => {
|
||||
const disabledFilter = disableFilter(existsFilter);
|
||||
filters$.next([disabledFilter]);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
import { COMPARE_ALL_OPTIONS, Filter, TimeRange, onlyDisabledFiltersChanged } from '@kbn/es-query';
|
||||
import { combineLatest, distinctUntilChanged, Observable, skip } from 'rxjs';
|
||||
import { combineLatest, distinctUntilChanged, Observable, skip, startWith } from 'rxjs';
|
||||
import { apiPublishesSettings } from '@kbn/presentation-containers/interfaces/publishes_settings';
|
||||
import { apiPublishesReload, apiPublishesUnifiedSearch } from '@kbn/presentation-publishing';
|
||||
import { areTimesEqual } from '../unified_search_manager';
|
||||
|
@ -61,7 +61,7 @@ export function newSession$(api: unknown) {
|
|||
}
|
||||
|
||||
if (apiPublishesReload(api)) {
|
||||
observables.push(api.reload$);
|
||||
observables.push(api.reload$.pipe(startWith(undefined)));
|
||||
}
|
||||
|
||||
return combineLatest(observables).pipe(skip(1));
|
||||
|
|
|
@ -145,7 +145,6 @@ export function initializeUnifiedSearchManager(
|
|||
}
|
||||
)
|
||||
);
|
||||
controlGroupSubscriptions.add(controlGroupFilters$.subscribe(() => panelsReload$.next()));
|
||||
controlGroupSubscriptions.add(
|
||||
controlGroupTimeslice$.subscribe((timeslice) => {
|
||||
if (timeslice !== timeslice$.value) timeslice$.next(timeslice);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue