@@ -24,9 +24,18 @@ import { EuiCheckboxGroupIdToSelectedMap } from '@elastic/eui/src/components/for
2424import React , { useState , ReactElement } from 'react' ;
2525import ReactDOM from 'react-dom' ;
2626import angular from 'angular' ;
27+ import deepEqual from 'fast-deep-equal' ;
2728
2829import { 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' ;
3039import { History } from 'history' ;
3140import { SavedObjectSaveOpts } from 'src/plugins/saved_objects/public' ;
3241import { 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