Skip to content

Add PlatformContext to replace build-time hook switching#4508

Draft
kingsleyzissou wants to merge 4 commits into
osbuild:mainfrom
kingsleyzissou:feature/platform-context
Draft

Add PlatformContext to replace build-time hook switching#4508
kingsleyzissou wants to merge 4 commits into
osbuild:mainfrom
kingsleyzissou:feature/platform-context

Conversation

@kingsleyzissou
Copy link
Copy Markdown
Collaborator

@kingsleyzissou kingsleyzissou commented Jun 4, 2026

Summary

Introduce a PlatformContext / usePlatform() abstraction so components access RTK Query hooks, feature flags, and API references through a
runtime context rather than build-time barrel file switching. This is the foundation for eliminating the IS_ON_PREMISE environment variable and
ternary-based import logic.

Changes

  • Add PlatformContext, usePlatform() hook, and PlatformProvider with a fail-fast null guard that throws if the provider is missing
  • Define PlatformHooks type contract with queries, mutations, env, and api namespaces, and implement hostedPlatform and
    onPremPlatform static objects satisfying the contract
  • Wrap AppEntry (hosted) and AppCockpit (on-prem) with PlatformProvider at the application boundary
  • Migrate ~35 component and hook files from direct barrel imports to usePlatform().queries / .mutations / .api destructuring
  • Update test utilities (renderWithRedux, renderLandingPage, wizard helpers) with PlatformProvider wrapping, selecting the correct
    platform from preloadedState.env.isOnPremise

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.07%. Comparing base (9680d34) to head (d0eb769).
⚠️ Report is 7 commits behind head on main.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4508      +/-   ##
==========================================
+ Coverage   75.36%   76.07%   +0.71%     
==========================================
  Files         230      226       -4     
  Lines        7453     7203     -250     
  Branches     2770     2661     -109     
==========================================
- Hits         5617     5480     -137     
+ Misses       1578     1482      -96     
+ Partials      258      241      -17     
Files with missing lines Coverage Δ
src/context/platform/index.ts 100.00% <100.00%> (ø)

... and 13 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9680d34...d0eb769. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Provide the React context plumbing that entry points use to inject
the correct platform hooks at runtime instead of relying on
build-time environment variable switching.
@kingsleyzissou kingsleyzissou force-pushed the feature/platform-context branch from d0eb769 to 11b08cd Compare June 5, 2026 17:12
Define the PlatformHooks type contract with queries, mutations, env,
and api sections, then wire up hostedPlatform and onPremPlatform as
static objects satisfying the contract. Uses per-field type casts
where on-prem base query types diverge from hosted.
@kingsleyzissou kingsleyzissou force-pushed the feature/platform-context branch from 11b08cd to 6791896 Compare June 5, 2026 17:21
AppEntry and AppCockpit now inject their respective platform objects
into the React tree so all descendants can access the correct hooks
via usePlatform() instead of build-time switching.
@kingsleyzissou kingsleyzissou force-pushed the feature/platform-context branch from 6791896 to 5f055b0 Compare June 5, 2026 17:56
Move 35 component and hook files from importing platform-switched
hooks directly from barrel files to destructuring them from
usePlatform(), preparing for barrel file cleanup.
@kingsleyzissou kingsleyzissou force-pushed the feature/platform-context branch from 5f055b0 to 5dfc2a2 Compare June 5, 2026 17:59
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.

1 participant