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: specs swaps correctly reflected in state #901

Merged
merged 3 commits into from
Nov 17, 2020

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Nov 12, 2020

Summary

This PR fixes the wrong state caused by swapping specs props between existing components.

The root cause is the specComponentFactory.
The issue appears in the following situation:

  • we have two components with respective ids A and B
  • this got parsed and stored in our state
  • the consumer switch the ids of the two components: the first component (previously with id A) becomes the one with id B and the second component (previously with id B) becomes A.

Because we are processing these specs sequentially following the React life cycle, the first component calls the following part of the specComponentFactory

if (prevId && prevId !== props.id) {
    removeSpec(prevId);
}
upsertSpec(SpecInstance);

this removes the prevId spec (the A for the first component) and then add the spec B to the store (1).
Then it's time for the second component. The id of the component has changed so it follows the same path as the previous one: removes the spec B (its saved previous id) and then upsert the spec with id A, but the removed spec B is not the old one, but a new one added in the step (1), the new one provided by the first component.

The first time we send anupsertSpec action to the state, the reducer cleans up the specs array. Because of this, it is not needed to call first the removeSpec with the prevId, if that is different from the current one. We still clean and re-add all the specs on upserting.

fix #868

Checklist

  • Unit tests were updated or added to match the most common scenarios

@markov00 markov00 added bug Something isn't working :specs Chart specifications related issue labels Nov 12, 2020
@markov00 markov00 marked this pull request as ready for review November 12, 2020 11:15
@codecov-io
Copy link

codecov-io commented Nov 12, 2020

Codecov Report

Merging #901 (936b5dd) into master (ab1af38) will increase coverage by 0.55%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #901      +/-   ##
==========================================
+ Coverage   69.61%   70.17%   +0.55%     
==========================================
  Files         340      356      +16     
  Lines       10983    10612     -371     
  Branches     2286     2150     -136     
==========================================
- Hits         7646     7447     -199     
+ Misses       3323     3082     -241     
- Partials       14       83      +69     
Flag Coverage Δ
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/state/chart_state.ts 85.50% <ø> (-2.00%) ⬇️
src/state/spec_factory.ts 94.73% <100.00%> (-1.70%) ⬇️
src/utils/dimensions.ts 71.42% <0.00%> (-28.58%) ⬇️
src/chart_types/xy_chart/utils/panel_utils.ts 72.72% <0.00%> (-19.59%) ⬇️
src/utils/data_generators/data_generator.ts 45.45% <0.00%> (-9.10%) ⬇️
...t/state/selectors/compute_small_multiple_scales.ts 86.95% <0.00%> (-8.70%) ⬇️
src/components/portal/utils.ts 21.42% <0.00%> (-7.15%) ⬇️
.../partition_chart/state/selectors/compute_legend.ts 79.06% <0.00%> (-5.72%) ⬇️
...state/selectors/get_internal_is_tooltip_visible.ts 75.00% <0.00%> (-5.00%) ⬇️
...hart/state/selectors/get_elements_at_cursor_pos.ts 90.47% <0.00%> (-4.77%) ⬇️
... and 194 more

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 ab1af38...936b5dd. Read the comment docs.

Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

Changes LGTM, verified the issue is resolved locally.

Screen Recording 2020-11-16 at 08 48 26 AM

src/state/spec_factory.test.tsx Show resolved Hide resolved
Copy link
Contributor

@rshen91 rshen91 left a comment

Choose a reason for hiding this comment

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

Looks great! I really like the additional tests - they make it really clear

@markov00 markov00 merged commit 7fba882 into elastic:master Nov 17, 2020
@markov00 markov00 deleted the 2020_11_11-fix_specs_swap branch November 17, 2020 11:06
markov00 pushed a commit that referenced this pull request Nov 24, 2020
# [24.1.0](v24.0.0...v24.1.0) (2020-11-24)

### Bug Fixes

* **area_charts:** correctly represent baseline with negative data points ([#896](#896)) ([d1243f1](d1243f1))
* **legend:** legend sizes with ordinal data ([#867](#867)) ([7559e0d](7559e0d)), closes [#811](#811)
* render orphan data points on lines and areas ([#900](#900)) ([0be282b](0be282b)), closes [#783](#783)
* specs swaps correctly reflected in state ([#901](#901)) ([7fba882](7fba882))

### Features

* **legend:** allow legend text to be copyable ([#877](#877)) ([9cd3459](9cd3459)), closes [#710](#710)
* allow clearing series colors from memory ([#899](#899)) ([ab1af38](ab1af38))
* merge series domain with the domain of another group ([#912](#912)) ([325b013](325b013))
* small multiples for XY charts (alpha) ([#793](#793)) ([d288208](d288208)), closes [#500](#500) [#500](#500)
@markov00
Copy link
Member Author

🎉 This PR is included in version 24.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Nov 24, 2020
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [24.1.0](elastic/elastic-charts@v24.0.0...v24.1.0) (2020-11-24)

### Bug Fixes

* **area_charts:** correctly represent baseline with negative data points ([opensearch-project#896](elastic/elastic-charts#896)) ([b622fda](elastic/elastic-charts@b622fda))
* **legend:** legend sizes with ordinal data ([opensearch-project#867](elastic/elastic-charts#867)) ([74bcbad](elastic/elastic-charts@74bcbad)), closes [opensearch-project#811](elastic/elastic-charts#811)
* render orphan data points on lines and areas ([opensearch-project#900](elastic/elastic-charts#900)) ([3e2c739](elastic/elastic-charts@3e2c739)), closes [opensearch-project#783](elastic/elastic-charts#783)
* specs swaps correctly reflected in state ([opensearch-project#901](elastic/elastic-charts#901)) ([a94347f](elastic/elastic-charts@a94347f))

### Features

* **legend:** allow legend text to be copyable ([opensearch-project#877](elastic/elastic-charts#877)) ([21a96d3](elastic/elastic-charts@21a96d3)), closes [opensearch-project#710](elastic/elastic-charts#710)
* allow clearing series colors from memory ([opensearch-project#899](elastic/elastic-charts#899)) ([e97f4ab](elastic/elastic-charts@e97f4ab))
* merge series domain with the domain of another group ([opensearch-project#912](elastic/elastic-charts#912)) ([716ad5a](elastic/elastic-charts@716ad5a))
* small multiples for XY charts (alpha) ([opensearch-project#793](elastic/elastic-charts#793)) ([3b88e1c](elastic/elastic-charts@3b88e1c)), closes [opensearch-project#500](elastic/elastic-charts#500) [opensearch-project#500](elastic/elastic-charts#500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Issue released publicly :specs Chart specifications related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[xyChart] When switching the seriesProps, the chart doesn't render first series
4 participants