Skip to content

Commit

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

# Backport

This will backport the following commits from `main` to `8.16`:
- [[time slider control] fix Time slider control needs to better sync
with dashboard time range
(#199544)](#199544)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nathan
Reese","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-12T17:01:41Z","message":"[time
slider control] fix Time slider control needs to better sync with
dashboard time range (#199544)\n\nCloses
https://github.com/elastic/kibana/issues/199227\r\n\r\nPR subscribes to
reload$ and adjusts timeslider when parent
reloads.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"36be9947ce18f0601e8ad6d56b601475f6b7f2a5","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Presentation","v9.0.0","backport:version","v8.17.0","v8.16.1"],"title":"[time
slider control] fix Time slider control needs to better sync with
dashboard time
range","number":199544,"url":"https://github.com/elastic/kibana/pull/199544","mergeCommit":{"message":"[time
slider control] fix Time slider control needs to better sync with
dashboard time range (#199544)\n\nCloses
https://github.com/elastic/kibana/issues/199227\r\n\r\nPR subscribes to
reload$ and adjusts timeslider when parent
reloads.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"36be9947ce18f0601e8ad6d56b601475f6b7f2a5"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199544","number":199544,"mergeCommit":{"message":"[time
slider control] fix Time slider control needs to better sync with
dashboard time range (#199544)\n\nCloses
https://github.com/elastic/kibana/issues/199227\r\n\r\nPR subscribes to
reload$ and adjusts timeslider when parent
reloads.\r\n\r\n---------\r\n\r\nCo-authored-by: Elastic Machine
<[email protected]>","sha":"36be9947ce18f0601e8ad6d56b601475f6b7f2a5"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Nathan Reese <[email protected]>
  • Loading branch information
kibanamachine and nreese authored Nov 12, 2024
1 parent 6e35221 commit 40426c7
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 40426c7

Please sign in to comment.