Skip to content

Commit 9f56267

Browse files
DosantThomThomson
authored andcommitted
[Dashboard] Update Index Patterns when Child Index Patterns Change (#76356)
Added the ability for Dashboard to react to index pattern changes in its children's output.
1 parent 60516e7 commit 9f56267

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

src/plugins/dashboard/public/application/dashboard_app_controller.tsx

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ import { EuiCheckboxGroupIdToSelectedMap } from '@elastic/eui/src/components/for
2424
import React, { useState, ReactElement } from 'react';
2525
import ReactDOM from 'react-dom';
2626
import angular from 'angular';
27+
import deepEqual from 'fast-deep-equal';
2728

2829
import { Observable, pipe, Subscription, merge } from 'rxjs';
29-
import { filter, map, debounceTime, mapTo, startWith, switchMap } from 'rxjs/operators';
30+
import {
31+
filter,
32+
map,
33+
debounceTime,
34+
mapTo,
35+
startWith,
36+
switchMap,
37+
distinctUntilChanged,
38+
} from 'rxjs/operators';
3039
import { History } from 'history';
3140
import { SavedObjectSaveOpts } from 'src/plugins/saved_objects/public';
3241
import { NavigationPublicPluginStart as NavigationStart } from 'src/plugins/navigation/public';
@@ -279,6 +288,12 @@ export class DashboardAppController {
279288
const updateIndexPatternsOperator = pipe(
280289
filter((container: DashboardContainer) => !!container && !isErrorEmbeddable(container)),
281290
map(getDashboardIndexPatterns),
291+
distinctUntilChanged((a, b) =>
292+
deepEqual(
293+
a.map((ip) => ip.id),
294+
b.map((ip) => ip.id)
295+
)
296+
),
282297
// using switchMap for previous task cancellation
283298
switchMap((panelIndexPatterns: IndexPattern[]) => {
284299
return new Observable((observer) => {
@@ -405,17 +420,29 @@ export class DashboardAppController {
405420
) : null;
406421
};
407422

408-
outputSubscription = new Subscription();
409-
outputSubscription.add(
410-
dashboardContainer
411-
.getOutput$()
412-
.pipe(
413-
mapTo(dashboardContainer),
414-
startWith(dashboardContainer), // to trigger initial index pattern update
415-
updateIndexPatternsOperator
423+
outputSubscription = merge(
424+
// output of dashboard container itself
425+
dashboardContainer.getOutput$(),
426+
// plus output of dashboard container children,
427+
// children may change, so make sure we subscribe/unsubscribe with switchMap
428+
dashboardContainer.getOutput$().pipe(
429+
map(() => dashboardContainer!.getChildIds()),
430+
distinctUntilChanged(deepEqual),
431+
switchMap((newChildIds: string[]) =>
432+
merge(
433+
...newChildIds.map((childId) =>
434+
dashboardContainer!.getChild(childId).getOutput$()
435+
)
436+
)
416437
)
417-
.subscribe()
418-
);
438+
)
439+
)
440+
.pipe(
441+
mapTo(dashboardContainer),
442+
startWith(dashboardContainer), // to trigger initial index pattern update
443+
updateIndexPatternsOperator
444+
)
445+
.subscribe();
419446

420447
inputSubscription = dashboardContainer.getInput$().subscribe(() => {
421448
let dirty = false;

0 commit comments

Comments
 (0)