[8.12] [ML] Fixes Single Metric Viewer's zoom settings in URL are not restored if URL specifies a forecast ID (#176969) (#177124)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[ML] Fixes Single Metric Viewer's zoom settings in URL are not
restored if URL specifies a forecast ID
(#176969)](https://github.com/elastic/kibana/pull/176969)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Quynh Nguyen (Quinn) 2024-03-21 09:48:43 -05:00 committed by GitHub
parent ead4055245
commit 7d1cc16f30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -486,9 +486,13 @@ export class TimeSeriesExplorer extends React.Component {
stateUpdate.contextAggregationInterval,
bounds
);
if (
focusRange === undefined ||
this.previousSelectedForecastId !== this.props.selectedForecastId
// If the user's focus range is not defined (i.e. no 'zoom' parameter restored from the appState URL),
// then calculate the default focus range to use
zoom === undefined &&
(focusRange === undefined ||
this.previousSelectedForecastId !== this.props.selectedForecastId)
) {
focusRange = calculateDefaultFocusRange(
autoZoomDuration,