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: converted notification redux structure to context API #598

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sundasnoreen12
Copy link
Collaborator

@sundasnoreen12 sundasnoreen12 commented Oct 1, 2024

https://2u-internal.atlassian.net/browse/INF-1603

Purpose
The purpose of converting the notification architecture from Redux to the Context API is to eliminate duplicated providers and stores, streamlining the structure and improving efficiency in managing state across the application.

Description
We have refactored the state management of the notification tray, transitioning from Redux to the Context API as the central store. This involved replacing all dispatch calls in the reducer with direct API calls, and managing server data through the Context provider. This change centralizes state management and resolves the issue of duplicate providers.

We have introduced a new waffle flag, “notifications.enable_new_notification_view,” in the backend as part of PR #35569.

All changes related to the Context API have been organized in a new folder named “new-notifications,” while the existing Redux architecture remains intact in the “Notifications” folder. This approach allows us to test the Context API structure by enabling the waffle flag on the staging environment. Once testing is complete, we plan to remove the Redux-related notifications folder and exclusively utilize the new notifications folder that incorporates the Context API changes.

Test

I conducted testing on the local machine by enabling these waffle flags and following the instructions outlined in the document found here:

  1. notifications.enable_new_notification_view
  2. notifications.show_notifications_tray
  3. notifications.enable_notification

Note: I have made updates specifically for the Learning Header for now. Since the Discussion MFE uses the Learning Header, I tested the notification tray locally on that implementation.

Copy link
Member

@awais-ansari awais-ansari left a comment

Choose a reason for hiding this comment

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

Create a context folder and move all the context there.

src/common/context.js Outdated Show resolved Hide resolved
src/new-notifications/data/hook.js Outdated Show resolved Hide resolved
src/new-notifications/data/hook.js Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 89.56522% with 36 lines in your changes missing coverage. Please review.

Project coverage is 78.00%. Comparing base (01e5f14) to head (f7f52f3).
Report is 28 commits behind head on master.

Files with missing lines Patch % Lines
src/new-notifications/tours/data/hooks.js 56.25% 14 Missing ⚠️
src/new-notifications/index.jsx 88.23% 5 Missing and 1 partial ⚠️
src/new-notifications/data/hook.js 95.00% 3 Missing ⚠️
src/new-notifications/tours/data/api.js 57.14% 3 Missing ⚠️
src/new-notifications/utils.js 88.88% 3 Missing ⚠️
.../learning-header/New-AuthenticatedUserDropdown.jsx 93.33% 2 Missing ⚠️
src/new-notifications/tours/constants.js 0.00% 2 Missing ⚠️
src/learning-header/AuthenticatedUserDropdown.jsx 66.66% 1 Missing ⚠️
src/new-notifications/NotificationSections.jsx 97.22% 1 Missing ⚠️
src/new-notifications/tours/NotificationTour.jsx 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #598      +/-   ##
==========================================
+ Coverage   72.47%   78.00%   +5.53%     
==========================================
  Files          52       74      +22     
  Lines         821     1205     +384     
  Branches      169      253      +84     
==========================================
+ Hits          595      940     +345     
- Misses        216      254      +38     
- Partials       10       11       +1     

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

@@ -70,6 +71,10 @@ const AuthenticatedUserDropdown = (props) => {
careersMenuItem = '';
}

if (isNewNotificationViewEnabled) {
Copy link
Member

Choose a reason for hiding this comment

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

is there a reason why this condition can't be further up in LearningHeader.jsx?

Copy link
Collaborator Author

@sundasnoreen12 sundasnoreen12 Oct 9, 2024

Choose a reason for hiding this comment

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

The value of isNewNotificationViewEnabled is derived from the count API, which is called in AuthenticatedUserDropdown for the Redux structure and in NewAuthenticatedUserDropdown for the Context API structure. Moving this condition up to LearningHeader.jsx would mean calling the count API for both Redux and Context API structures in the same file. To maintain separation between the two architectures, it's more efficient to keep the current structure until we fully transition away from Redux. Does that make sense?

Copy link
Member

Choose a reason for hiding this comment

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

Ahh, that does make sense, I didn't catch that the Context API was the reason for writing it this way. Does this mean that there will eventually be a follow-up ticket to remove the old AuthenticatedUserDropdown and/or Redux, or is that a hope for eventual future work?

email={authenticatedUser.email}
/>
<>
<AuthenticatedUserDropdown
Copy link
Member

Choose a reason for hiding this comment

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

Connected to my previous question in AuthenticatedUserDropdown.jsx, presenting both AuthenticatedUserDropdown and NewAuthenticatedUserDropdown here makes it look like both should be rendered. Even if this is all temporary and the plan is to remove the old dropdown, I think it'd make sense to keep the if (isNewNotificationViewEnabled) condition here where it clearly demonstrates the repercussions of that boolean.

Copy link
Collaborator Author

@sundasnoreen12 sundasnoreen12 Oct 9, 2024

Choose a reason for hiding this comment

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

Explanation in the above comment

Copy link
Member

@jsnwesson jsnwesson left a comment

Choose a reason for hiding this comment

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

One thing I'd suggest is that I noticed the test files for NotificationRowItem, NotificationSections, and NotificationTabs start with a lowercase letter, but that's probably more of a nit pick than something that would affect the tests passing/failing.

Otherwise, this looks okay to me!

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.

4 participants