feat: Add V2 of header actions slot - #682
Conversation
Introduce a v2 version of LearningHeaderActionsSlot that always mounts, wrapping the existing v1 slot (HeaderNotificationsSlot and LearningHelpSlot) which stays gated behind showUserDropdown. This preserves the v1 slot API contract for existing plugin consumers while allowing new plugins to attach to v2 unconditionally. Note: HeaderNotificationsSlot/LearningHelpSlot remain hidden when showUserDropdown is false. Fully decoupling them from showUserDropdown requires deprecating v1 first, and is left for a follow-up once the DEPR lands.
|
Thanks for the pull request, @ChrisChV! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #682 +/- ##
==========================================
+ Coverage 73.07% 74.56% +1.49%
==========================================
Files 60 61 +1
Lines 520 523 +3
Branches 110 110
==========================================
+ Hits 380 390 +10
+ Misses 137 130 -7
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
arbrandes
left a comment
There was a problem hiding this comment.
Looks great, for the most part! Just a couple of change requests and a few non-blocking nits.
| {authenticatedUser && ( | ||
| <> | ||
| <LearningHeaderActionsSlot /> | ||
| <AuthenticatedUserDropdown | ||
| username={authenticatedUser.username} | ||
| /> | ||
| <LearningHeaderActionsSlot showUserDropdown={showUserDropdown} /> | ||
| {showUserDropdown && ( | ||
| <AuthenticatedUserDropdown | ||
| username={authenticatedUser.username} | ||
| /> | ||
| )} | ||
| </> | ||
| )} |
There was a problem hiding this comment.
v2 should render for anonymous users.
Hoist the slot out of the authenticatedUser guard, folding the gate into the prop it passes down. Rename that prop while you are there (v2/index.jsx:6): it no longer tracks the dropdown, only whether v1's default contents render.
| {authenticatedUser && ( | |
| <> | |
| <LearningHeaderActionsSlot /> | |
| <AuthenticatedUserDropdown | |
| username={authenticatedUser.username} | |
| /> | |
| <LearningHeaderActionsSlot showUserDropdown={showUserDropdown} /> | |
| {showUserDropdown && ( | |
| <AuthenticatedUserDropdown | |
| username={authenticatedUser.username} | |
| /> | |
| )} | |
| </> | |
| )} | |
| <LearningHeaderActionsSlot showDefaultActions={showUserDropdown && !!authenticatedUser} /> | |
| {authenticatedUser && showUserDropdown && ( | |
| <AuthenticatedUserDropdown | |
| username={authenticatedUser.username} | |
| /> | |
| )} |
Default output stays identical in all four combinations of the two flags, and .v2 plugins gain the anonymous header.
Anonymous learners do reach this header: frontend-app-learning authenticates no route, and GoalUnsubscribe.jsx, its only caller passing showUserDropdown={false}, is explicitly anonymous-friendly. PageNotFound.jsx and CourseAccessErrorPage.jsx likewise.
| - **Notification Tray** (via `HeaderNotificationsSlot`) — Rendered before the help link | ||
| - **Help Link** (via `LearningHelpSlot`) | ||
|
|
||
| > **Note:** This slot is only rendered when `showUserDropdown` is `true`. To render content regardless of `showUserDropdown`, use the parent [`v2` slot](../v2/). |
There was a problem hiding this comment.
v1's docs omit the authenticatedUser gate.
v1 stays gated on both flags, so "only rendered when showUserDropdown is true" needs "and a user is authenticated" here, in LearningHeaderActionsSlot/README.md:6, and in the hierarchy diagram at HeaderNotificationsSlot/README.md:31. v2's own "always renders" wording becomes accurate once the change to LearningHeader.jsx lands.
| it('hides the user dropdown and the header actions when showUserDropdown is false', () => { | ||
| render(<Header showUserDropdown={false} />); | ||
|
|
||
| expect(screen.queryByText(authenticatedUser.username)).not.toBeInTheDocument(); | ||
| expect(screen.queryByText('Help')).not.toBeInTheDocument(); | ||
| }); |
There was a problem hiding this comment.
This test passes unchanged on master.
I ran it against the base files and all three cases pass, so it guards pre-existing hiding behavior and covers no new path. Add a case with a widget configured on .v2 and showUserDropdown={false}, asserting the widget appears, plus one for the anonymous case. That needs a mergeConfig({ pluginSlots: { ... } }) setup, which this repo has no precedent for.
| ### Learning Header | ||
| * [`org.openedx.frontend.layout.header_learning_course_info.v1`](./CourseInfoSlot/) | ||
| * [`org.openedx.frontend.layout.learning_header_actions.v1`](./LearningHeaderActionsSlot/) | ||
| * [`org.openedx.frontend.layout.learning_header_actions.v1`](./LearningHeaderActionsSlot/v1/) |
There was a problem hiding this comment.
v1 is not marked deprecated.
Two lines, here and in v1/README.md, and the DEPR (#681) defers it to a follow-up. Worth doing here so the index does not present both versions as equal choices.
There was a problem hiding this comment.
@arbrandes The OEP-21, indicates that it is only marked as deprecated after the plan is approved. That's the reason why I didn't include it. I want to confirm whether you think we should still include it.
| LearningHeaderActionsSlot.defaultProps = { | ||
| showUserDropdown: true, | ||
| }; |
There was a problem hiding this comment.
Nit: use a destructuring default instead. React 18.3 deprecates defaultProps on function components, and DesktopSecondaryMenuSlot/v2 declares propTypes only.
| <PluginSlot | ||
| id="org.openedx.frontend.layout.learning_header_actions.v2" | ||
| > |
There was a problem hiding this comment.
Nit: pluginProps={{ showUserDropdown }}, as DesktopSecondaryMenuSlot/v2 does for menu. Addable later without a version bump.
| Notifications appear before secondary menu items (e.g., "New", "Help") | ||
|
|
||
| 2. **Learning Header** — via `org.openedx.frontend.layout.learning_header_actions.v1` | ||
| 2. **Learning Header** — via `org.openedx.frontend.layout.learning_header_actions.v2` (nests `.v1` — see [LearningHeaderActionsSlot](../LearningHeaderActionsSlot/v2/)) |
There was a problem hiding this comment.
Nit: reads as a direct parent, which it is for the desktop entry above but not here. The parenthetical and the diagram below get it right, so this is cosmetic.
The
showUserDropdownprop gated both theLearningHeaderActionsSlotand theAuthenticatedUserDropdown, making it impossible to hide the user dropdown without also hiding all the action items, and impossible for third-party plugins attached to that slot to render independently of the user dropdown's visibility.This PR introduces a new
org.openedx.frontend.layout.learning_header_actions.v2slot:v2always renders, regardless ofshowUserDropdown. Use this slot ID for new plugin configurations that should render even whenshowUserDropdownisfalse.v2wraps the existingv1slot (notifications tray + help link), which keeps its original behavior unchanged — only rendered whenshowUserDropdownistrue— preserving backwards compatibility for existing consumers ofv1.This PR does not change any default, out-of-the-box visual behavior. With no custom plugin configuration,
the header looks and behaves exactly as it does on
main, including withshowUserDropdown={false}.The only thing this PR unlocks is the ability for plugin authors to opt into
.v2so their own widgets renderindependently of
showUserDropdown.A follow-up DEPR ticket will propose removing
v1once its default content (notifications tray + help link) can move intov2unconditionally.Supporting information
Testing instructions
mainbranch, runnpm ci && npm run build.npm install "../path/to/this/repo" --legacy-peer-deps.frontend-app-learning/env.config.jsxto setshowUserDropdown: false:frontend-app-learning/module.config.js:mainchecked out on this repo. Confirm that withshowUserDropdown: false, the user dropdown, notifications, and "Help" link are hidden (pre-PR behavior).npm run build