diff --git a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_create_drilldown/flyout_create_drilldown.tsx b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_create_drilldown/flyout_create_drilldown.tsx index c8715c9e3b416..582133890a4bc 100644 --- a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_create_drilldown/flyout_create_drilldown.tsx +++ b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_create_drilldown/flyout_create_drilldown.tsx @@ -88,6 +88,10 @@ export class FlyoutCreateDrilldownAction implements Action { closed$.next(true); handle.close(); }; + const closeFlyout = () => { + close(); + }; + const triggers = [ ...ensureNestedTriggers(embeddable.supportedTriggers()), CONTEXT_MENU_TRIGGER, @@ -111,11 +115,11 @@ export class FlyoutCreateDrilldownAction implements Action { ); // Close flyout on application change. - core.application.currentAppId$.pipe(takeUntil(closed$), skip(1), take(1)).subscribe(() => { - close(); - }); + core.application.currentAppId$ + .pipe(takeUntil(closed$), skip(1), take(1)) + .subscribe(closeFlyout); - // Close flyout on dashboard switch to "view" mode. + // Close flyout on dashboard switch to "view" mode or on embeddable destroy. embeddable .getInput$() .pipe( @@ -125,8 +129,6 @@ export class FlyoutCreateDrilldownAction implements Action { filter((mode) => mode !== ViewMode.EDIT), take(1) ) - .subscribe(() => { - close(); - }); + .subscribe({ next: closeFlyout, complete: closeFlyout }); } } diff --git a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_edit_drilldown/flyout_edit_drilldown.tsx b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_edit_drilldown/flyout_edit_drilldown.tsx index 44bfbb26421c6..f7cd8981451ea 100644 --- a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_edit_drilldown/flyout_edit_drilldown.tsx +++ b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/actions/flyout_edit_drilldown/flyout_edit_drilldown.tsx @@ -67,6 +67,10 @@ export class FlyoutEditDrilldownAction implements Action { closed$.next(true); handle.close(); }; + const closeFlyout = () => { + close(); + }; + const handle = core.overlays.openFlyout( toMountPoint( { ); // Close flyout on application change. - core.application.currentAppId$.pipe(takeUntil(closed$), skip(1), take(1)).subscribe(() => { - close(); - }); + core.application.currentAppId$ + .pipe(takeUntil(closed$), skip(1), take(1)) + .subscribe(closeFlyout); - // Close flyout on dashboard switch to "view" mode. + // Close flyout on dashboard switch to "view" mode or on embeddable destroy. embeddable .getInput$() .pipe( @@ -99,8 +103,6 @@ export class FlyoutEditDrilldownAction implements Action { filter((mode) => mode !== ViewMode.EDIT), take(1) ) - .subscribe(() => { - close(); - }); + .subscribe({ next: closeFlyout, complete: closeFlyout }); } }