-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] Single Metric Viewer: Fix zoom on forecast selection. #55685
Conversation
Pinging @elastic/ml-ui (:ml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and LGTM
💚 Build SucceededTo update your PR or re-run it, just comment with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally and it worked fine 🎉
LGTM
@@ -213,6 +218,11 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan | |||
|
|||
const boundsMinMs = bounds?.min?.valueOf(); | |||
const boundsMaxMs = bounds?.max?.valueOf(); | |||
|
|||
const [selectedForecastIdProp, setSelectedForecastIdProp] = useState<string | undefined>( | |||
appState?.mlTimeSeriesExplorer?.forecastId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why the init value is not selectedForecastId
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I wanted to make sure it gets the initial value from the URL/appState. selectedForecastId
could be undefined
if isJobChange
is true
.
/** | ||
* Returns field names that don't have a selection yet. | ||
*/ | ||
getFieldNamesWithEmptyValues = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need in an arrow function, could be a method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole file has a mix of styles, I'll keep it like that since the "surrounding" functions have a similar style :)
/** | ||
* Checks if all entity control dropdowns have a selection. | ||
*/ | ||
arePartitioningFieldsProvided = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need in an arrow function, could be a method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole file has a mix of styles, I'll keep it like that since the "surrounding" functions have a similar style :)
@@ -221,6 +231,9 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan | |||
selectedJob !== undefined && | |||
selectedForecastId !== undefined | |||
) { | |||
if (selectedForecastIdProp !== selectedForecastId) { | |||
setSelectedForecastIdProp(undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this state update will cause the re-render, then you call getForecastDateRange
with selectedForecastId
and update the state again. Is it necessary?
And why don't you update the appState instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit fiddly but it's the way I was able to fix it without a major rewrite of the inner workings of timeseriesexplorer.js
:). The combination of selectedForecastId
(source of truth in the URL) and selectedForecastIdProp
allows me track if a forecast update was completed. Otherwise multiple independent useEffect
s would just trigger a bunch of rerenders and we cannot tell within timeseriesexplorer.js
if we got everything we need for a forecast update.
The main pain point is that the inner charts still trigger a programmatic zoom update and with the current code there's no way to tell if that was triggered by a user or by another update. Fixing this would have required a much larger refactor.
@@ -282,6 +282,11 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan | |||
return null; | |||
} | |||
|
|||
const zoomProp: AppStateZoom | undefined = | |||
typeof selectedForecastId === 'string' && selectedForecastIdProp === undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does zoom prop always depend on the forecast id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to the comment above. The combination of selectedForecastId
and selectedForecastIdProp
allows us to decide wheter to pass on zoomProp
as undefined
. If it's undefined
, the timeseriesexplorer.js
will recalculate the zoom which in turn moves it to the desired location to span half the forecast and have the existing section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…5685) Fixes adjusting the focus chart zoom range when a forecast gets selected. The code is cleaned up so appStateHandler to set the zoom range in the url is only called in one place within contextChartSelected().
…5685) Fixes adjusting the focus chart zoom range when a forecast gets selected. The code is cleaned up so appStateHandler to set the zoom range in the url is only called in one place within contextChartSelected().
Summary
Part of #52986.
Fixes adjusting the focus chart zoom range when a forecast gets selected. The code is cleaned up so
appStateHandler
to set the zoom range in the url is only called in one place withincontextChartSelected()
.Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n supportDocumentation was added for features that require explanation or tutorialsUnit or functional tests were updated or added to match the most common scenariosThis was checked for keyboard-only and screenreader accessibilityFor maintainers