Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.16] [time slider control] fix Time slider control needs to better sync with dashboard time range (#199544) #199831

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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