Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

fix: only remove tooltips relating to a single vis #167

Merged
merged 1 commit into from
Aug 6, 2019

Conversation

etr2460
Copy link
Contributor

@etr2460 etr2460 commented Aug 5, 2019

🐛 Bug Fix

When rerendering charts, we were removing all tooltips for every chart from the dom instead of just the one owned by the rerendering chart. This would break pages with multiple nvd3 charts on them (basically all superset dashboards). It can be easily reproed with dashboards with multiple tabs with the following steps:

  1. hover over a chart on tab 1
  2. switch to tab 2
  3. resize the window, then resize it back to the original size
  4. switch back to tab 1
  5. see no more tooltips on the previously hovered chart. other charts will add new tooltips though

I fixed this issue by uniquely identifying charts by the passed in id and applying this id to the tooltips as well. When rerendering or unmounting charts now, if an id was passed in then we only remove the tooltip belonging to that chart. If no ids are passed, then we retain the current behavior.

@etr2460 etr2460 requested a review from a team as a code owner August 5, 2019 23:46
@etr2460 etr2460 force-pushed the erik-ritter--fix-tooltip-removal branch from 5f8ffc7 to 6608b58 Compare August 5, 2019 23:50
@codecov
Copy link

codecov bot commented Aug 5, 2019

Codecov Report

Merging #167 into master will decrease coverage by 0.75%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #167      +/-   ##
==========================================
- Coverage    25.9%   25.14%   -0.76%     
==========================================
  Files           8        8              
  Lines         166      171       +5     
  Branches       10       10              
==========================================
  Hits           43       43              
- Misses        122      127       +5     
  Partials        1        1
Impacted Files Coverage Δ
.../superset-ui-legacy-preset-chart-nvd3/src/utils.js 14.28% <0%> (-0.53%) ⬇️

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 ecd5744...91aaac7. Read the comment docs.

Copy link
Collaborator

@kristw kristw left a comment

Choose a reason for hiding this comment

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

Overall LGTM, have minor comments on some pessimistic edge cases.


function componentWillUnmount() {
hideTooltips(true);
const { id } = this.props; // eslint-disable-line babel/no-invalid-this
if (id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can id be 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to id != null

@@ -254,6 +256,7 @@ function nvd3Vis(element, props) {
const container = element;
container.innerHTML = '';
const activeAnnotationLayers = annotationLayers.filter(layer => layer.show);
const chartId = container.parentElement.id || null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps also check if parentElement is not null.
Also, do we want to prevent accidents if id is 0 which is falsy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@etr2460 etr2460 force-pushed the erik-ritter--fix-tooltip-removal branch 2 times, most recently from 4e7c430 to c360a8d Compare August 6, 2019 19:06
@etr2460 etr2460 force-pushed the erik-ritter--fix-tooltip-removal branch from c360a8d to 91aaac7 Compare August 6, 2019 19:21
@etr2460 etr2460 merged commit 8059485 into master Aug 6, 2019
@delete-merged-branch delete-merged-branch bot deleted the erik-ritter--fix-tooltip-removal branch August 6, 2019 20:05
nytai pushed a commit to preset-io/superset-ui-plugins that referenced this pull request Apr 27, 2020
* build: bump build-config

* test: fix typings in mock data
nytai pushed a commit to preset-io/superset-ui-plugins that referenced this pull request Apr 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants