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(chart): chart updates are not retained #23627

Merged

Conversation

justinpark
Copy link
Member

@justinpark justinpark commented Apr 7, 2023

SUMMARY

When a table chart saved on a dashboard and edited from the dashboard, the table reloads in the edit view and the updated option returns to the previous setting.
This bug is a regression of #20498, which reloads the fetchExploreData but always overrides it with the dashboardContext (which retains the original settings).

This hotfix adds the condition of overwrite saving to retrieve the changes from updated exploreFormData.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

  • After:
after--retained-hotfix.mov
  • Before:
before--retained-hotfix.mov

TESTING INSTRUCTIONS

  1. Create a new Table chart
  2. Save and publish the chart to a dashboard
  3. Open the dashboard, and click "Edit" on the chart from the dashboard
  4. Go to "Customize" and uncheck "Cell Bars"
  5. Click save. The Cell Bars option returns to checked after saving.
  6. Exit and go to the "Charts" list in Superset
  7. Open your saved chart from the Charts list directly
  8. Go to "Customize" and uncheck "Cell Bars"
  9. Click save. The Cell Bars option retains the unchecked state

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

cc: @michael-s-molina @ktmud cc: @john-bodley

@codecov
Copy link

codecov bot commented Apr 7, 2023

Codecov Report

Merging #23627 (278ea1b) into master (0bf8907) will increase coverage by 14.37%.
The diff coverage is 33.33%.

❗ Current head 278ea1b differs from pull request most recent head 93a9b4c. Consider uploading reports for the commit 93a9b4c to get more accurate results

@@             Coverage Diff             @@
##           master   #23627       +/-   ##
===========================================
+ Coverage   53.58%   67.96%   +14.37%     
===========================================
  Files        1938     1925       -13     
  Lines       74957    74390      -567     
  Branches     8140     8109       -31     
===========================================
+ Hits        40167    50556    +10389     
+ Misses      32706    21762    -10944     
+ Partials     2084     2072       -12     
Flag Coverage Δ
javascript 54.26% <33.33%> (-0.04%) ⬇️

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

Impacted Files Coverage Δ
...rset-frontend/src/explore/components/SaveModal.tsx 34.78% <0.00%> (-0.31%) ⬇️
superset-frontend/src/pages/Chart/index.tsx 74.00% <100.00%> (+74.00%) ⬆️

... and 381 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@justinpark justinpark force-pushed the fix--chart-settings-not-retained branch from 3db7ce8 to 334c84e Compare April 10, 2023 17:11
@justinpark justinpark force-pushed the fix--chart-settings-not-retained branch 2 times, most recently from c1d6ede to 66537cb Compare April 10, 2023 21:08
expect(fetchMock.calls(exploreApiRoute).length).toBe(1),
);
expect(getByTestId('mock-explore-view-container')).toBeInTheDocument();
expect(store.getActions()).toContainEqual({
Copy link
Member

Choose a reason for hiding this comment

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

@justinpark React Testing Library has a different view on how to write tests. One of its main concerns is accessibility. It differs from Enzyme in the sense that it's more focused on how the user interacts with the app rather then implementation details. Check this quote from their site:

You want to write maintainable tests that give you high confidence that your components are working for your users. As a part of this goal, you want your tests to avoid including implementation details so refactors of your components (changes to implementation but not functionality) don't break your tests and slow you and your team down.

In your case, you could write tests that check if the "Show cell bars" is checked rather then test if an specific Redux action is fired. This will make your tests more durable in a scenario where the implementation details change, such as the redux action name, or the action structure, but the interface, and the way users interact with it, remain the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-s-molina I updated the test code as you suggested. (but using partial rendering since full ChartContainer requires a lot of dependancies)


import { JsonObject } from '@superset-ui/core';

export const getExploreFormData = (overrides: JsonObject = {}) => ({
Copy link
Member

Choose a reason for hiding this comment

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

Really nice improvement to extract the mock.

...overrides,
});

export const getDashboardFormData = (overrides: JsonObject = {}) => ({
Copy link
Member

Choose a reason for hiding this comment

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

Should this be in its own file? Could this be used by another test that is not inside Explore?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I will change this mock function location

Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-s-molina could you review the PR again?

@justinpark justinpark force-pushed the fix--chart-settings-not-retained branch from 66537cb to 2c12c6c Compare April 11, 2023 21:59
@justinpark justinpark force-pushed the fix--chart-settings-not-retained branch from 2c12c6c to e1f439d Compare April 21, 2023 19:12
Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM

@justinpark justinpark force-pushed the fix--chart-settings-not-retained branch from e1f439d to 93a9b4c Compare April 27, 2023 18:11
@justinpark
Copy link
Member Author

@rusackas could you help to stamp this PR to release the blocker?

Copy link
Member

@rusackas rusackas left a comment

Choose a reason for hiding this comment

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

Approving cypress mods as code owner

@john-bodley john-bodley merged commit f5b1711 into apache:master Apr 27, 2023
john-bodley pushed a commit to airbnb/superset-fork that referenced this pull request Apr 27, 2023
sebastianliebscher pushed a commit to sebastianliebscher/superset that referenced this pull request Apr 28, 2023
john-bodley pushed a commit to airbnb/superset-fork that referenced this pull request May 10, 2023
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 3.0.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XL 🚢 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants