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

feat: refactor notices provider to useQuery #992

Merged
merged 8 commits into from
Mar 5, 2024

Conversation

brobro10000
Copy link
Member

@brobro10000 brobro10000 commented Mar 4, 2024

Refactors the NoticesProvider context to the loader. It conditionally checks whether the loader should include the API call to retrieve notices from platform-plugin-notices before it adds it to the rootLoader to be called.

The redirect is done directly within the fetch call. The reason for the implementation is to prevent the momentary render of the learner portal before redirect.

For all changes

  • Ensure adequate tests are in place (or reviewed existing tests cover changes)

Only if submitting a visual change

  • Ensure to attach screenshots
  • Ensure to have UX team confirm screenshots

Copy link

codecov bot commented Mar 4, 2024

Codecov Report

Attention: Patch coverage is 82.60870% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 81.25%. Comparing base (9cef120) to head (1fa97bc).

Files Patch % Lines
src/components/app/routes/data/queries/notices.js 0.00% 2 Missing ⚠️
...app/routes/data/queries/ensureEnterpriseAppData.js 75.00% 1 Missing ⚠️
src/utils/queryKeyFactory.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@                        Coverage Diff                         @@
##           feat/react-query-route-loaders     #992      +/-   ##
==================================================================
+ Coverage                           81.15%   81.25%   +0.09%     
==================================================================
  Files                                 372      371       -1     
  Lines                                7776     7773       -3     
  Branches                             1889     1888       -1     
==================================================================
+ Hits                                 6311     6316       +5     
+ Misses                               1407     1401       -6     
+ Partials                               58       56       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brobro10000 brobro10000 force-pushed the hu/ent-8475 branch 2 times, most recently from 387c003 to 73b84ed Compare March 5, 2024 16:14
src/components/app/Root.jsx Outdated Show resolved Hide resolved
@@ -364,6 +365,33 @@ export async function fetchSubscriptions(enterpriseUuid) {
};
}

// Notices
export const fetchNotices = async () => {
const authenticatedUser = getAuthenticatedUser();
Copy link
Member

Choose a reason for hiding this comment

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

[question] Is this check on whether the user is authenticated necessary given we shouldn't be getting to this code path for unauthenticated users? For example, all the route loaders have

const authenticatedUser = await ensureAuthenticatedUser(requestUrl, params);
// User is not authenticated, so we can't do anything in this loader.
if (!authenticatedUser) {
  return null;
}

...to shortcut the execution of the remainder of the loader function given the rest of the loader function would fail without authentication.

Given that, could we always assume users are authenticated within this function?

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 call out, I used the existing notices API without changing it so a lot of these nits are around the original implementation. Fixing it up now 👍🏽

src/components/app/routes/data/services.js Outdated Show resolved Hide resolved
src/components/app/routes/data/services.js Outdated Show resolved Hide resolved
Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

LGTM, once the lint issue is resolved (i.e., getAuthenticatedUser is imported but unused). Edit: looks like it was taken care of as I commented 😄

@brobro10000 brobro10000 merged commit 0c905a5 into feat/react-query-route-loaders Mar 5, 2024
7 checks passed
@brobro10000 brobro10000 deleted the hu/ent-8475 branch March 5, 2024 17:03
adamstankiewicz pushed a commit that referenced this pull request Mar 6, 2024
* feat: refactor notices provider to useQuery

* chore: merge fix

* chore: cleanup

* fix: redirects without momentary render

* fix: debugging

* chore: Testing and cleanup

* chore: PR feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants