-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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(explore): fix chart save when dashboard deleted #21497
fix(explore): fix chart save when dashboard deleted #21497
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
||
// Get dashboards the slice is added to | ||
export const getSliceDashboards = slice => async dispatch => { | ||
if (slice) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the if
clause is redundant because the try...cache
handled exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention was for the try...catch
clause to just handle request errors or other unexpected errors. The if
clause is there because this function might be called with no slice
param, in the case of a chart that hasn't yet been saved, and I wanted it to return []
in that case as part of normal, non-exception behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is no slice
param, the request will also raise an exception, so the catch
statement alway catches an exception although an invalid input param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, I don't want to send the request at all if there's no slice
param, I just want to return an empty array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you don't want to send a request, you shouldn't call this action. e.g.:
const originalDashboards = this.props.slice ? await this.props.actions.getSliceDashboards(
this.props.slice,
) : [];
just a personal suggestion, optimize it for the future. thanks for the fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, that makes sense, thanks.
if (slice) { | ||
try { | ||
const response = await SupersetClient.get({ | ||
endpoint: `/api/v1/chart/${slice.slice_id}?q=${rison.encode({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits:
endpoint: `/api/v1/chart/${slice.slice_id}?q=${rison.encode({ | |
endpoint: `/api/v1/chart/${slice?.slice_id}?q=${rison.encode({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I check above that slice
is defined, so I don't think this check is necessary.
} | ||
} | ||
|
||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return []
should be removed if remove the if clause
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want to remove the if
clause; returning []
isn't exception behavior (see above).
// Get chart dashboards | ||
let sliceDashboards: number[]; | ||
promise = promise | ||
.then(() => this.props.actions.getSliceDashboards(this.props.slice)) | ||
.then(dashboards => { | ||
sliceDashboards = dashboards; | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits:
// Get chart dashboards | |
let sliceDashboards: number[]; | |
promise = promise | |
.then(() => this.props.actions.getSliceDashboards(this.props.slice)) | |
.then(dashboards => { | |
sliceDashboards = dashboards; | |
}); | |
const originalDashboards = await this.props.actions.getSliceDashboards( | |
this.props.slice, | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I didn't realize this saveOrOverwrite
was now an async
function! I can clean up a lot of these promises now, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually going to leave out turning the promises into await
s because my full PR that included that fix triggered an Explore refresh bug that I think we're going to work on separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixing, left a few comments.
@@ -200,12 +207,14 @@ class SaveModal extends React.Component<SaveModalProps, SaveModalState> { | |||
.then(() => this.props.actions.getDashboard(saveToDashboardId)) | |||
.then((response: { result: DashboardGetResponse }) => { | |||
dashboard = response.result; | |||
const dashboards = new Set<number>(this.props.sliceDashboards); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits:
sliceDashboards = originalDashboards.includes(dashboard.id) ? originalDashboards : [...originalDashboards, dashboard.id],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner, thanks.
/> | ||
</> | ||
} | ||
message={this.state.alert ? this.state.alert : this.props.alert} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message={this.state.alert ? this.state.alert : this.props.alert} | |
message={this.state.alert || this.props.alert} |
/testenv up |
@rusackas Ephemeral environment spinning up at http://54.185.234.75:8080. Credentials are |
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. |
a7a2c90
to
2f39ba4
Compare
/testenv up |
@rusackas Ephemeral environment spinning up at http://54.245.15.56:8080. Credentials are |
2f39ba4
to
6003d73
Compare
6003d73
to
4686dce
Compare
/testenv up |
@jinghua-qa Ephemeral environment spinning up at http://35.162.112.106:8080. Credentials are |
tested in ephemeral env, found 1 issues expect: actual: can.not.save.chart.to.dashboard.mov |
/testenv up |
@michael-s-molina Ephemeral environment spinning up at http://35.91.186.119:8080. Credentials are |
@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? |
Screen.Recording.2022-09-20.at.9.03.01.AM.mov |
I also tested:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Given the priority, I vote for any non-blocking improvements to be made in a follow-up.
@jinghua-qa Can you give a last round of testing before we merge it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/testenv up |
@jinghua-qa Ephemeral environment spinning up at http://34.217.89.134:8080. Credentials are |
LGTM |
Ephemeral environment shutdown and build artifacts deleted. |
(cherry picked from commit 6644a84)
(cherry picked from commit 6644a84)
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. ThePUT /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 theform_data.dashboards
array returned by theGET /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 thePUT
request, which would cause the request to fail. This PR fixes this by getting the chart dashboards with aGET /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:
Before.mov
Saving a chart w/ dashboard deleted after:
Screen.Recording.2022-09-19.at.9.56.50.PM.mov
TESTING INSTRUCTIONS
PUT
request was successful, with no422
error.ADDITIONAL INFORMATION