superset icon indicating copy to clipboard operation
superset copied to clipboard

fix(explore): fix chart save when dashboard deleted

Open codyml opened this issue 2 years ago • 15 comments

SUMMARY

As part of moving Explore to the SPA, #20498 replaced the previous single POST /superset/explore request that was used to save charts with calls to the v1 API. The PUT /api/v1/chart/{id} endpoint responsible for updating the chart required sending the complete list of IDs of dashboards that the chart should be added to in the request body, and this list was previously sourced from the form_data.dashboards array returned by the GET /api/v1/explore endpoint. However, form_data.dashboards is not updated when dashboards are deleted from Superset. As a result, saving a chart that was added to a dashboard when that dashboard was deleted would result in the frontend submitting that dashboard in the PUT request, which would cause the request to fail. This PR fixes this by getting the chart dashboards with a GET /api/v1/chart/{id} request during the explore save process, the results of which are correctly updated when dashboards are deleted.

~Additionally, the Save Chart modal was configured to close immediately upon clicking the "Save chart" button, rather than waiting for requests to complete/fail and showing error messages on fail. This PR also fixes this so errors are displayed correctly.~ This PR now just fixes the broken saving, as the fix for the Save Chart modal closing before error message shows turned out to trigger other Explore display bugs that couldn't be quickly solved for this PR.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Saving a chart w/ dashboard deleted before:

https://user-images.githubusercontent.com/13007381/190811092-42255a80-023b-402b-9caa-78a1572e59d1.mov

Saving a chart w/ dashboard deleted after:

https://user-images.githubusercontent.com/13007381/191150662-10359f79-6151-4803-87f8-f9eee0d5eba6.mov

TESTING INSTRUCTIONS

  • Create a chart, save it to a dashboard, delete the dashboard, then make a change to the chart and attempt to save again. The chart should save correctly and opening the chart from the chart list again should show the saved version. Additionally, verify in the inspector that the PUT request was successful, with no 422 error.

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

codyml avatar Sep 16 '22 21:09 codyml

Codecov Report

Merging #21497 (cb1f6bd) into master (f27e20e) will increase coverage by 0.00%. The diff coverage is 60.00%.

@@           Coverage Diff           @@
##           master   #21497   +/-   ##
=======================================
  Coverage   66.66%   66.67%           
=======================================
  Files        1793     1793           
  Lines       68499    68531   +32     
  Branches     7278     7282    +4     
=======================================
+ Hits        45666    45694   +28     
- Misses      20969    20974    +5     
+ Partials     1864     1863    -1     
Flag Coverage Δ
javascript 52.85% <60.00%> (+0.03%) :arrow_up:

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

Impacted Files Coverage Δ
...set-frontend/src/explore/actions/hydrateExplore.ts 42.10% <ø> (ø)
.../explore/components/ExploreViewContainer/index.jsx 52.74% <ø> (+0.28%) :arrow_up:
...rset-frontend/src/explore/components/SaveModal.tsx 38.53% <14.28%> (-0.52%) :arrow_down:
...t-frontend/src/explore/actions/saveModalActions.js 98.59% <100.00%> (+0.13%) :arrow_up:
...src/dashboard/components/PropertiesModal/index.tsx 61.07% <0.00%> (-0.75%) :arrow_down:
superset-frontend/src/SqlLab/constants.ts 100.00% <0.00%> (ø)
...frontend/src/SqlLab/components/SqlEditor/index.jsx 52.74% <0.00%> (+1.33%) :arrow_up:
...tend/plugins/plugin-chart-table/src/TableChart.tsx 42.07% <0.00%> (+1.61%) :arrow_up:
...et-frontend/src/components/TableSelector/index.tsx 80.00% <0.00%> (+4.00%) :arrow_up:

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

codecov[bot] avatar Sep 16 '22 23:09 codecov[bot]

/testenv up

rusackas avatar Sep 19 '22 16:09 rusackas

@rusackas Ephemeral environment spinning up at http://54.185.234.75:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

github-actions[bot] avatar Sep 19 '22 16:09 github-actions[bot]

There is currently a bug seen on this PR - if you create a new chart from scratch, and then save it without going to a dashboard, the chart vanishes from view, rather than displaying the chart.

rusackas avatar Sep 19 '22 17:09 rusackas

/testenv up

rusackas avatar Sep 19 '22 22:09 rusackas

@rusackas Ephemeral environment spinning up at http://54.245.15.56:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

github-actions[bot] avatar Sep 19 '22 22:09 github-actions[bot]

/testenv up

jinghua-qa avatar Sep 20 '22 02:09 jinghua-qa

@jinghua-qa Ephemeral environment spinning up at http://35.162.112.106:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

github-actions[bot] avatar Sep 20 '22 02:09 github-actions[bot]

tested in ephemeral env, found 1 issues 1, chart can not save to dashboard steps: 1, create a chart 2, save and add to a new dashboard 3, go to dashboard

expect: chart will be save to new dashboard

actual: chart did not save to new dashboard

https://user-images.githubusercontent.com/81597121/191168018-a4f64b62-2dae-4185-aefb-3cfe08e82fa4.mov

jinghua-qa avatar Sep 20 '22 04:09 jinghua-qa

/testenv up

michael-s-molina avatar Sep 20 '22 11:09 michael-s-molina

@michael-s-molina Ephemeral environment spinning up at http://35.91.186.119:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

github-actions[bot] avatar Sep 20 '22 11:09 github-actions[bot]

tested in ephemeral env, found 1 issues 1, chart can not save to dashboard steps: 1, create a chart 2, save and add to a new dashboard 3, go to dashboard

expect: chart will be save to new dashboard

actual: chart did not save to new dashboard

can.not.save.chart.to.dashboard.mov

@jinghua-qa This was the issue that my latest update was hoping to fix, and I could reproduce it in the previous ephemeral environment you created but it looked to be fixed in the latest one @michael-s-molina just spun up. Could you check again in the latest ephemeral env? Maybe the previous one was using an outdated image?

codyml avatar Sep 20 '22 12:09 codyml

tested in ephemeral env, found 1 issues 1, chart can not save to dashboard steps: 1, create a chart 2, save and add to a new dashboard 3, go to dashboard

expect: chart will be save to new dashboard

actual: chart did not save to new dashboard

@jinghua-qa @codyml

  • I first tried to reproduce this locally but I wasn't able to reproduce the problem.
  • Then I tested on the ephemeral environment that was running and I was able to reproduce it. I also noticed that the time the environment was run coincided with a commit from Cody so I wasn't sure if the environment was updated.
  • I spun a new ephemeral environment and I wasn't able to reproduce the problem anymore.

https://user-images.githubusercontent.com/70410625/191253486-8cc5b8bf-226b-4218-9040-6320983ebb67.mov

michael-s-molina avatar Sep 20 '22 12:09 michael-s-molina

I also tested:

  • Saving a chart that referenced a deleted dashboard
  • Save a new chart and check that the chart does not disappear

michael-s-molina avatar Sep 20 '22 12:09 michael-s-molina

@jinghua-qa Can you give a last round of testing before we merge it?

michael-s-molina avatar Sep 20 '22 12:09 michael-s-molina

/testenv up

jinghua-qa avatar Sep 20 '22 19:09 jinghua-qa

@jinghua-qa Ephemeral environment spinning up at http://34.217.89.134:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

github-actions[bot] avatar Sep 20 '22 19:09 github-actions[bot]

LGTM

jinghua-qa avatar Sep 20 '22 19:09 jinghua-qa

Ephemeral environment shutdown and build artifacts deleted.

github-actions[bot] avatar Sep 20 '22 19:09 github-actions[bot]