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

Dashboard: Fix plugin dashboard save as button #55197

Merged
merged 3 commits into from Sep 22, 2022
Merged

Dashboard: Fix plugin dashboard save as button #55197

merged 3 commits into from Sep 22, 2022

Conversation

lpskdl
Copy link
Contributor

@lpskdl lpskdl commented Sep 14, 2022

What this PR does / why we need it:
Render the SaveDashboardErrorProxy component only when error is not yet handled.

Screen.Recording.2022-09-14.at.22.13.32.mov

Which issue(s) this PR fixes:

Fixes #54735

@lpskdl lpskdl added this to the 9.1.6 milestone Sep 14, 2022
@lpskdl lpskdl requested review from ryantxu, ashharrison90 and a team September 14, 2022 20:21
@lpskdl lpskdl self-assigned this Sep 14, 2022
@lpskdl lpskdl requested review from joshhunt, axelavargas and ivanortegaalba and removed request for a team September 14, 2022 20:21
@lpskdl lpskdl added backport v9.1.x Bot will automatically open backport PR and removed backport v9.0.x labels Sep 15, 2022
@xlson xlson modified the milestones: 9.1.6, 9.1.7 Sep 20, 2022
@@ -126,7 +126,7 @@ export const SaveDashboardDrawer = ({ dashboard, onDismiss, onSaveSuccess, isCop
);
};

if (state.error && isFetchError(state.error)) {
if (state.error && isFetchError(state.error) && !state.error.isHandled) {
Copy link
Contributor

Choose a reason for hiding this comment

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

That's neat 🧉

)
);

return { rerender, mockDashboard, store };
Copy link
Contributor

Choose a reason for hiding this comment

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

setup() is doing too many things: creating a dashboard mock and returning it, configuring store and returning it, and rendering a component and returning it. I think it would be better to have mockDashboard as a part of a single describe() or even inside a single test whenever it's needed.
The configuration of the store can also just happen as a separate thing once for the whole test module.

mockPost.mockClear();
});

it("renders SaveDashboardErrorProxy if there's an error and it not yet handled", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are never actually looking for the name SaveDashboardErrorProxy in the test and it will have to be changed here if the component is changed, maybe it's better to just say "renders a corresponding modal if there's an error..."

expect(screen.getByRole('button', { name: /save as/i })).toBeInTheDocument();
expect(screen.getByRole('button', { name: /overwrite/i })).toBeInTheDocument();

rerender(
Copy link
Contributor

Choose a reason for hiding this comment

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

From here down it's confusing what is happening, as it seems to be a different test: "renders a corresponding Save new modal if there's an error that has already been handled".

@grafanabot
Copy link
Contributor

Copy link
Contributor

@polibb polibb left a comment

Choose a reason for hiding this comment

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

Great initiative with the test 🥳

@lpskdl lpskdl merged commit 383602a into main Sep 22, 2022
@lpskdl lpskdl deleted the lpskdl/54735 branch September 22, 2022 07:14
@grafanabot
Copy link
Contributor

The backport to v9.1.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-55197-to-v9.1.x origin/v9.1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x 383602a850b9c546fece58c40bd158e6e45e6484
# Push it to GitHub
git push --set-upstream origin backport-55197-to-v9.1.x
git switch main
# Remove the local backport branch
git branch -D backport-55197-to-v9.1.x

Then, create a pull request where the base branch is v9.1.x and the compare/head branch is backport-55197-to-v9.1.x.

lpskdl added a commit that referenced this pull request Sep 22, 2022
* render SaveDashboardErrorProxy only when error is not yet handled

* improve dashbaoard drawer test

(cherry picked from commit 383602a)
lpskdl added a commit that referenced this pull request Sep 22, 2022
* render SaveDashboardErrorProxy only when error is not yet handled

* improve dashbaoard drawer test

(cherry picked from commit 383602a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Plugin Dashboard Save As button not working for versioning
4 participants