From 14d8ec514e16b848843d1c227dab44dcf9b5b9c7 Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Mon, 27 Jul 2020 16:20:50 +0200 Subject: [PATCH] improve --- .../application/dashboard_app_controller.tsx | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx index 81eb356cc4353f..2a0e2889575f36 100644 --- a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx +++ b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx @@ -253,20 +253,23 @@ export class DashboardAppController { navActions[TopNavIds.VISUALIZE](); }; + function getDashboardIndexPatterns(container: DashboardContainer): IndexPattern[] { + let panelIndexPatterns: IndexPattern[] = []; + Object.values(container.getChildIds()).forEach((id) => { + const embeddableInstance = container.getChild(id); + if (isErrorEmbeddable(embeddableInstance)) return; + const embeddableIndexPatterns = (embeddableInstance.getOutput() as any).indexPatterns; + if (!embeddableIndexPatterns) return; + panelIndexPatterns.push(...embeddableIndexPatterns); + }); + panelIndexPatterns = uniqBy(panelIndexPatterns, 'id'); + return panelIndexPatterns; + } + const updateIndexPatternsOperator = pipe( filter((container: DashboardContainer) => !!container && !isErrorEmbeddable(container)), - map((container: DashboardContainer) => { - let panelIndexPatterns: IndexPattern[] = []; - Object.values(container!.getChildIds()).forEach((id) => { - const embeddableInstance = container!.getChild(id); - if (isErrorEmbeddable(embeddableInstance)) return; - const embeddableIndexPatterns = (embeddableInstance.getOutput() as any).indexPatterns; - if (!embeddableIndexPatterns) return; - panelIndexPatterns.push(...embeddableIndexPatterns); - }); - panelIndexPatterns = uniqBy(panelIndexPatterns, 'id'); - return panelIndexPatterns; - }), + map(getDashboardIndexPatterns), + // using switchMap for previous task cancellation switchMap((panelIndexPatterns: IndexPattern[]) => { return new Observable((observer) => { if (panelIndexPatterns && panelIndexPatterns.length > 0) { @@ -281,6 +284,7 @@ export class DashboardAppController { $scope.$evalAsync(() => { if (observer.closed) return; $scope.indexPatterns = [defaultIndexPattern as IndexPattern]; + observer.complete(); }); }); }