You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,6 +92,53 @@ Imports are enforced alphabetically by ESLint. Group order:
92
92
- Playwright tests for E2E coverage of critical flows
93
93
- The `TZ=UTC` prefix is applied automatically by npm scripts
94
94
95
+
## Platform Context
96
+
97
+
The app runs on two platforms — **hosted** (console.redhat.com) and **on-premises** (Cockpit plugin). Platform-specific hooks, API slices, and utilities are abstracted behind a React context so components never branch on the environment directly.
98
+
99
+
### Architecture
100
+
101
+
| File | Purpose |
102
+
| --- | --- |
103
+
|`src/context/platform/types.ts`|`PlatformHooks` type — the contract for `queries`, `mutations`, `env`, and `api`|
104
+
|`src/context/platform/index.ts`|`PlatformContext`, `PlatformProvider`, and `usePlatform()` hook |
The store barrel files (`src/store/api/backend/index.ts`, `src/store/api/contentSources/index.ts`) no longer contain any `process.env.IS_ON_PREMISE` ternary logic. All platform-switched hooks are now sourced exclusively through `usePlatform()`. The barrels retain only:
111
+
112
+
-**Type re-exports** (hosted as canonical, prefixed on-prem types where they conflict)
113
+
-**Platform-independent hooks** — hosted-only hooks gated at the component/route level (e.g. `useComposeImageMutation`, `useListRepositoriesQuery`)
114
+
-**API slice references** (`imageBuilderApi`, `composerApi`, `contentSourcesApi`) for store setup and `invalidateTags`
115
+
116
+
### Usage
117
+
118
+
Entry points (`src/AppEntry.tsx`, Cockpit bootstrap) wrap the app with `<PlatformProvider value={hostedPlatform}>` or `<PlatformProvider value={onPremPlatform}>`.
119
+
120
+
Consumers destructure the specific hooks they need from `usePlatform()`:
Destructure to the individual hook level — not just `queries`/`mutations`/`api` — so call sites match the original direct-import style and keep diffs minimal.
-**`env`** — `useFlag(flag)` and `useGetEnvironment()`
136
+
-**`api`** — `backendApi` (the RTK API slice for `invalidateTags` etc.), `contentSourcesApi`, `useBackendPrefetch`
137
+
138
+
### Testing
139
+
140
+
Tests use a `mockPlatform` fixture from `src/context/platform/tests/mocks/` and render inside a `PlatformProvider`. When mocking `usePlatform` directly via `vi.mock`, spread `mockPlatform` and override only the hooks under test.
141
+
95
142
## Feature Flags
96
143
97
144
Uses Unleash for feature toggles in the hosted service. Import `useFlag` from `src/Utilities/useGetEnvironment.ts` to check flag status:
0 commit comments