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

fix(reactive_chart): fix order of instantiation of onBrushEnd callback #376

Merged
merged 1 commit into from
Sep 16, 2019

Conversation

nickofthyme
Copy link
Collaborator

@nickofthyme nickofthyme commented Sep 13, 2019

Summary

This PR fixes an issue found in SIEM where the onBrushEnd callback triggers a URL change and thus a rerender of the page and Chart components on the page. The workaround solution was to add a 500ms setTimeout to allow time for the state to update before calling the onBrushEnd callback.

The solution as suggested by @FrankHassanabad, is to invoke the onBrushEnd callback following the completion of the setState method.

fixes #360

Screenshot

Notice no console errors when brushing chart and successful update of time range and chart.
Screen Recording 2019-09-12 at 09 45 PM

Additionally, added componentWillUnmount method to ensure window.removeEventListener is called on mouseup event in the case where the Chart is unmounted before this event is called.

Checklist

Wait for setState to finish before calling onBrushEnd, in the event the callback triggers a
rerender.

fixes elastic#360
@nickofthyme nickofthyme added bug Something isn't working :chart Chart element related issue labels Sep 13, 2019
@codecov-io
Copy link

codecov-io commented Sep 13, 2019

Codecov Report

Merging #376 into master will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #376      +/-   ##
==========================================
+ Coverage   98.25%   98.27%   +0.02%     
==========================================
  Files          38       38              
  Lines        2801     2784      -17     
  Branches      661      657       -4     
==========================================
- Hits         2752     2736      -16     
  Misses         44       44              
+ Partials        5        4       -1
Impacted Files Coverage Δ
src/specs/settings.tsx 94.44% <0%> (-0.13%) ⬇️
src/chart_types/xy_chart/store/chart_state.ts 97.6% <0%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb482be...0863aff. Read the comment docs.

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -76,6 +76,10 @@ class Chart extends React.Component<ReactiveChartProps, ReactiveChartState> {
},
};

componentWillUnmount() {
window.removeEventListener('mouseup', this.onEndBrushing);
}
Copy link
Member

Choose a reason for hiding this comment

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

❤️

@nickofthyme nickofthyme merged commit 527d68d into elastic:master Sep 16, 2019
@nickofthyme nickofthyme deleted the fix/on-brush-end-error branch September 16, 2019 14:46
markov00 pushed a commit that referenced this pull request Sep 16, 2019
## [12.0.2](v12.0.1...v12.0.2) (2019-09-16)

### Bug Fixes

* **reactive_chart:** fix order of instantiation of onBruchEnd callback ([#376](#376)) ([527d68d](527d68d)), closes [#360](#360)
@markov00
Copy link
Member

🎉 This PR is included in version 12.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Sep 16, 2019
@markov00 markov00 changed the title fix(reactive_chart): fix order of instantiation of onBruchEnd callback fix(reactive_chart): fix order of instantiation of onBrushEnd callback Sep 23, 2019
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
## [12.0.2](elastic/elastic-charts@v12.0.1...v12.0.2) (2019-09-16)

### Bug Fixes

* **reactive_chart:** fix order of instantiation of onBruchEnd callback ([opensearch-project#376](elastic/elastic-charts#376)) ([42cd1e7](elastic/elastic-charts@42cd1e7)), closes [opensearch-project#360](elastic/elastic-charts#360)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working :chart Chart element related issue released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onBrushEnd should be called after setState is completed
3 participants