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

PublicDashboard: Add RTK Query with loading and error state. Add MSW dependency for testing. #55518

Merged
merged 6 commits into from Sep 22, 2022

Conversation

juanicabanas
Copy link
Contributor

@juanicabanas juanicabanas commented Sep 20, 2022

What this PR does / why we need it:

  • Loading and error state added for PubDash modal.
  • Save button logic modified in order to force user to click on switch
  • Pubdash subcomponents created with delegated responsibilities
  • New tests added with MSW library.

Which issue(s) this PR fixes:
Fixes: https://github.com/grafana/grafana-enterprise/issues/4457

Special notes for your reviewer:

Fetch Loading state:
image

Save Loading state:
image

@juanicabanas juanicabanas requested review from joshhunt and a team as code owners September 20, 2022 19:28
@juanicabanas juanicabanas requested review from dprokop and JoaoSilvaGrafana and removed request for a team September 20, 2022 19:28
@juanicabanas juanicabanas changed the title msw, rtk query added PubDash: Rtk Query api added with loading and error state. msw dependency added for testing Sep 20, 2022
@juanicabanas juanicabanas added this to the 9.2.0 milestone Sep 20, 2022
@grafanabot
Copy link
Contributor

@grafanabot
Copy link
Contributor

Copy link
Contributor

@evictorero evictorero left a comment

Choose a reason for hiding this comment

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

Great work! The refactor is great and I love the new state functionality 🤩
I have tested it and it works as expected.
Left some nit comments.

@grafanabot
Copy link
Contributor

@evictorero evictorero changed the title PubDash: Rtk Query api added with loading and error state. msw dependency added for testing PublicDashboard: Rtk Query api added with loading and error state. msw dependency added for testing Sep 21, 2022
@juanicabanas juanicabanas changed the title PublicDashboard: Rtk Query api added with loading and error state. msw dependency added for testing PublicDashboard: Add RTK Query with loading and error state. Add MSW dependency for testing. Sep 21, 2022
@grafanabot
Copy link
Contributor

publicDashboardEnabled: data.isEnabled,
});
},
invalidatesTags: ['Config'],
Copy link
Contributor

Choose a reason for hiding this comment

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

So this means calling the saveConfig endpoint invalidates the cached results for the getConfig endpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly, because getConfig has 'Config' tag

<Checkbox
label="Your entire dashboard will be public"
value={acknowledgements.public}
data-testid={selectors.WillBePublicCheckbox}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍 I like how were keeping all our selectors separate

let mockDashboard: DashboardModel;
let mockPanel: PanelModel;

beforeAll(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was everything in here needed to be able to render ShareModal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's right

import { ShareModal } from '../ShareModal';

const server = setupServer(
rest.get('/api/dashboards/uid/:uId/public-config', (req, res, ctx) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this mocked api specifically for RTK? Or would it still work if we're not using RTK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it would still work without using RTK Query. MSW is a library which intercepts the request in the network layer, so it's agnostic about how you make that request.
However, it's recommended to use this library for RTK Query and I couldn't find another way of mocking the requests

}),
});

export const { useGetConfigQuery, useSaveConfigMutation } = publicDashboardApi;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we simplify the names to useGetConfig and useSaveConfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this is something that is added automatically by RTK Query.

Copy link
Contributor

@owensmallwood owensmallwood 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 how you wrote your tests. I definitely learned a few things from reading through them. Tested it out and had no issues. Left a few comments, mostly just trying to get clarification for myself. Awesome work 🥳

@dsotirakis dsotirakis modified the milestones: 9.2.0, 9.2.0-beta1 Sep 22, 2022
@juanicabanas juanicabanas merged commit c7419de into main Sep 22, 2022
@juanicabanas juanicabanas deleted the juanicabanas/pubdash-state branch September 22, 2022 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants