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

[ML] Single Metric Viewer: Fix zoom on forecast selection. #55685

Merged
merged 3 commits into from
Jan 23, 2020

Conversation

walterra
Copy link
Contributor

@walterra walterra commented Jan 23, 2020

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 within contextChartSelected().

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@walterra walterra added bug Fixes for quality problems that affect the customer experience regression :ml Feature:Anomaly Detection ML anomaly detection v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.7.0 v7.6.0 labels Jan 23, 2020
@walterra walterra requested a review from a team as a code owner January 23, 2020 11:56
@walterra walterra self-assigned this Jan 23, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@walterra walterra mentioned this pull request Jan 23, 2020
21 tasks
Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@pheyos pheyos left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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 = () => {
Copy link
Contributor

@darnautov darnautov Jan 23, 2020

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

Copy link
Contributor Author

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 = () => {
Copy link
Contributor

@darnautov darnautov Jan 23, 2020

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

Copy link
Contributor Author

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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 useEffects 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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@walterra walterra merged commit a4cf4f4 into elastic:master Jan 23, 2020
@walterra walterra deleted the ml-fix-forecast-zoom branch January 23, 2020 16:16
walterra added a commit to walterra/kibana that referenced this pull request Jan 23, 2020
…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().
walterra added a commit to walterra/kibana that referenced this pull request Jan 23, 2020
…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().
walterra added a commit that referenced this pull request Jan 23, 2020
…55722)

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().
walterra added a commit that referenced this pull request Jan 23, 2020
…55721)

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().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Anomaly Detection ML anomaly detection :ml regression release_note:skip Skip the PR/issue when compiling release notes v7.6.0 v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants