From 5a17c640fd25214e43712dcee56c730ebde2aba1 Mon Sep 17 00:00:00 2001 From: Devon Thomson Date: Thu, 6 Oct 2022 15:57:00 -0300 Subject: [PATCH] [Dashboard] [Controls] Skip First Reload (#142868) * Skip first reload of dashboard controls to ensure only the filters from control group initialization are applied --- .../application/embeddable/dashboard_container.tsx | 12 ++++++++---- .../application/lib/dashboard_control_group.ts | 9 ++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/plugins/dashboard/public/application/embeddable/dashboard_container.tsx b/src/plugins/dashboard/public/application/embeddable/dashboard_container.tsx index 036c77fc6257c..d8c66155d8b30 100644 --- a/src/plugins/dashboard/public/application/embeddable/dashboard_container.tsx +++ b/src/plugins/dashboard/public/application/embeddable/dashboard_container.tsx @@ -153,13 +153,17 @@ export class DashboardContainer extends Container { + this.controlGroup.untilReady().then(() => { + if (!this.controlGroup || isErrorEmbeddable(this.controlGroup)) return; + syncDashboardControlGroup({ + dashboardContainer: this, + controlGroup: this.controlGroup, + }).then((result) => { if (!result) return; const { onDestroyControlGroup } = result; this.onDestroyControlGroup = onDestroyControlGroup; - } - ); + }); + }); } this.subscriptions.add( diff --git a/src/plugins/dashboard/public/application/lib/dashboard_control_group.ts b/src/plugins/dashboard/public/application/lib/dashboard_control_group.ts index 4f44d0cf250d1..edca78a373132 100644 --- a/src/plugins/dashboard/public/application/lib/dashboard_control_group.ts +++ b/src/plugins/dashboard/public/application/lib/dashboard_control_group.ts @@ -10,7 +10,7 @@ import _ from 'lodash'; import { Subscription } from 'rxjs'; import deepEqual from 'fast-deep-equal'; import { compareFilters, COMPARE_ALL_OPTIONS, type Filter } from '@kbn/es-query'; -import { debounceTime, distinctUntilChanged, distinctUntilKeyChanged } from 'rxjs/operators'; +import { debounceTime, distinctUntilChanged, distinctUntilKeyChanged, skip } from 'rxjs/operators'; import { ControlGroupInput, @@ -140,11 +140,10 @@ export const syncDashboardControlGroup = async ({ .pipe( distinctUntilChanged(({ filters: filtersA }, { filters: filtersB }) => compareAllFilters(filtersA, filtersB) - ) + ), + skip(1) // skip first filter output because it will have been applied in initialize ) - .subscribe(() => { - dashboardContainer.updateInput({ lastReloadRequestTime: Date.now() }); - }) + .subscribe(() => dashboardContainer.updateInput({ lastReloadRequestTime: Date.now() })) ); subscriptions.add(