Skip to content

Commit

Permalink
[time slider control] fix Time slider control needs to better sync wi…
Browse files Browse the repository at this point in the history
…th dashboard time range (#199544)

Closes #199227

PR subscribes to reload$ and adjusts timeslider when parent reloads.

---------

Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 36be994)
  • Loading branch information
nreese committed Nov 12, 2024
1 parent 367d479 commit 4755732
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { TimeRange } from '@kbn/es-query';
import { i18n } from '@kbn/i18n';
import { apiHasParentApi, apiPublishesTimeRange } from '@kbn/presentation-publishing';
import moment from 'moment';
import { BehaviorSubject, skip } from 'rxjs';
import { BehaviorSubject, Subscription, skip } from 'rxjs';
import { apiPublishesReload } from '@kbn/presentation-publishing/interfaces/fetch/publishes_reload';
import { getTimeRangeMeta, getTimezone, TimeRangeMeta } from './get_time_range_meta';
import { getMomentTimezone } from './time_utils';

Expand All @@ -26,6 +27,13 @@ export function initTimeRangeSubscription(controlGroupApi: unknown) {
timeRangeMeta$.next(getTimeRangeMeta(timeRange));
});

let reloadSubscription: undefined | Subscription;
if (apiHasParentApi(controlGroupApi) && apiPublishesReload(controlGroupApi.parentApi)) {
reloadSubscription = controlGroupApi.parentApi.reload$.subscribe(() => {
timeRangeMeta$.next(getTimeRangeMeta(timeRange$.value));
});
}

return {
timeRangeMeta$,
formatDate: (epoch: number) => {
Expand All @@ -35,6 +43,7 @@ export function initTimeRangeSubscription(controlGroupApi: unknown) {
.format(timeRangeMeta$.value.format);
},
cleanupTimeRangeSubscription: () => {
reloadSubscription?.unsubscribe();
timeRangeSubscription.unsubscribe();
},
};
Expand Down

0 comments on commit 4755732

Please sign in to comment.