Skip to content

ROX-30334: Rely on context instead of redux for usePermissions hook#16182

Merged
dvail merged 5 commits intomasterfrom
dv/ROX-30334-use-context-for-user-permissions
Jul 31, 2025
Merged

ROX-30334: Rely on context instead of redux for usePermissions hook#16182
dvail merged 5 commits intomasterfrom
dv/ROX-30334-use-context-for-user-permissions

Conversation

@dvail
Copy link
Copy Markdown
Contributor

@dvail dvail commented Jul 28, 2025

Description

This replaces the direct usage of redux selectors in the usePermissions() hook with a call to a context instead. A context provider is added at the top level of the application that will use redux and sagas to handle permissions as they were previously handled in the usePermissions() hook.

This will allow us to easily have a separate context provider in the OCP plugin that has user permission information without needing to integrate with redux.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

Smoke test and manual verification that mypermissions endpoint is only ever called once when navigating around the application.

CI e2e tests should be sufficient to catch edge cases.

@dvail
Copy link
Copy Markdown
Contributor Author

dvail commented Jul 28, 2025

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Jul 28, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@rhacs-bot
Copy link
Copy Markdown
Contributor

rhacs-bot commented Jul 28, 2025

Images are ready for the commit at 4c6195f.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.9.x-341-g4c6195f63c.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.71%. Comparing base (cd5279e) to head (4c6195f).
⚠️ Report is 30 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #16182      +/-   ##
==========================================
- Coverage   48.71%   48.71%   -0.01%     
==========================================
  Files        2606     2606              
  Lines      191771   191771              
==========================================
- Hits        93418    93415       -3     
- Misses      91024    91025       +1     
- Partials     7329     7331       +2     
Flag Coverage Δ
go-unit-tests 48.71% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dvail dvail force-pushed the dv/ROX-29844-add-configuration-of-base-url-and-e2e-requests branch from 5ecd4b9 to 1c986d8 Compare July 28, 2025 18:51
@dvail dvail force-pushed the dv/ROX-30334-use-context-for-user-permissions branch from e2497b3 to 286e5b2 Compare July 28, 2025 18:51
@dvail dvail marked this pull request as ready for review July 28, 2025 18:57
@dvail dvail requested a review from a team as a code owner July 28, 2025 18:57
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @dvail - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `ui/apps/platform/src/Containers/ReduxUserPermissionProvider.tsx:18` </location>
<code_context>
+});
+
+export default function ReduxUserPermissionProvider({ children }: { children: React.ReactNode }) {
+    const { userRolePermissions, isLoadingPermissions } = useSelector(stateSelector);
+
+    return (
</code_context>

<issue_to_address>
No memoization for context value may cause unnecessary re-renders.

Consider using `useMemo` to memoize the context value and prevent unnecessary re-renders of consumers, especially if the provider wraps large parts of the app.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@sachaudh sachaudh left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏼 Minor comments about thoughts and suggestions.

@dvail dvail force-pushed the dv/ROX-29844-add-configuration-of-base-url-and-e2e-requests branch from b57a431 to 323f0cf Compare July 29, 2025 12:22
@dvail dvail requested a review from a team as a code owner July 29, 2025 12:22
@dvail dvail force-pushed the dv/ROX-30334-use-context-for-user-permissions branch from 286e5b2 to 4c6195f Compare July 29, 2025 12:22
Base automatically changed from dv/ROX-29844-add-configuration-of-base-url-and-e2e-requests to master July 31, 2025 11:54
@dvail dvail merged commit 8527b9e into master Jul 31, 2025
100 of 101 checks passed
@dvail dvail deleted the dv/ROX-30334-use-context-for-user-permissions branch July 31, 2025 16: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.

3 participants