Skip to content

Commit b1fcca7

Browse files
context: add hosted and on-prem platform implementations
Wire up the actual RTK Query hooks, feature flags, and API slices into static platform objects that satisfy the PlatformHooks contract, keeping cockpit-specific code contained in onprem.ts. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 19f0494 commit b1fcca7

2 files changed

Lines changed: 163 additions & 0 deletions

File tree

src/context/platform/hosted.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import useChrome from '@redhat-cloud-services/frontend-components/useChrome';
2+
import { useFlag as useUnleashFlag } from '@unleash/proxy-client-react';
3+
4+
import { imageBuilderApi } from '@/store/api/backend/hosted/enhancedImageBuilderApi';
5+
import {
6+
useComposeBlueprintMutation,
7+
useCreateBlueprintMutation,
8+
useDeleteBlueprintMutation,
9+
useGetArchitecturesQuery,
10+
useGetBlueprintComposesQuery,
11+
useGetBlueprintQuery,
12+
useGetBlueprintsQuery,
13+
useGetComposesQuery,
14+
useGetComposeStatusQuery,
15+
useGetDistributionsQuery,
16+
useGetOscapCustomizationsQuery,
17+
useGetOscapProfilesQuery,
18+
useLazyGetBlueprintsQuery,
19+
useLazyGetOscapCustomizationsQuery,
20+
useUpdateBlueprintMutation,
21+
} from '@/store/api/backend/hosted/imageBuilderApi';
22+
import {
23+
contentSourcesApi,
24+
useListSnapshotsByDateMutation,
25+
useSearchRpmMutation,
26+
} from '@/store/api/contentSources/hosted';
27+
28+
import type { PlatformHooks } from './types';
29+
30+
const useHostedGetEnvironment = () => {
31+
const { isBeta, isProd, getEnvironment } = useChrome();
32+
if (isBeta() || getEnvironment() === 'qa') {
33+
return { isBeta: () => true, isProd: isProd };
34+
}
35+
return { isBeta: () => false, isProd: isProd };
36+
};
37+
38+
export const hostedPlatform: PlatformHooks = {
39+
queries: {
40+
// PlatformHooks uses the on-prem type which accepts wider input.
41+
// The hosted version is narrower, but runtime behavior is identical.
42+
useGetArchitecturesQuery:
43+
useGetArchitecturesQuery as unknown as PlatformHooks['queries']['useGetArchitecturesQuery'],
44+
useGetDistributionsQuery:
45+
useGetDistributionsQuery as unknown as PlatformHooks['queries']['useGetDistributionsQuery'],
46+
useGetBlueprintQuery,
47+
useGetBlueprintsQuery,
48+
useLazyGetBlueprintsQuery,
49+
useGetOscapProfilesQuery,
50+
useGetOscapCustomizationsQuery,
51+
useLazyGetOscapCustomizationsQuery,
52+
useGetComposesQuery,
53+
useGetBlueprintComposesQuery,
54+
useGetComposeStatusQuery,
55+
},
56+
mutations: {
57+
useCreateBlueprintMutation,
58+
useUpdateBlueprintMutation,
59+
useDeleteBlueprintMutation,
60+
useComposeBlueprintMutation,
61+
useSearchRpmMutation,
62+
useListSnapshotsByDateMutation,
63+
},
64+
env: {
65+
useFlag: useUnleashFlag,
66+
useGetEnvironment: useHostedGetEnvironment,
67+
},
68+
api: {
69+
backendApi: imageBuilderApi,
70+
contentSourcesApi,
71+
useBackendPrefetch: imageBuilderApi.usePrefetch,
72+
},
73+
};

src/context/platform/onprem.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import {
2+
useComposeBlueprintMutation,
3+
useCreateBlueprintMutation,
4+
useDeleteBlueprintMutation,
5+
useGetArchitecturesQuery,
6+
useGetBlueprintComposesQuery,
7+
useGetBlueprintQuery,
8+
useGetBlueprintsQuery,
9+
useGetComposesQuery,
10+
useGetComposeStatusQuery,
11+
useGetDistributionsQuery,
12+
useGetOscapCustomizationsQuery,
13+
useGetOscapProfilesQuery,
14+
useLazyGetBlueprintsQuery,
15+
useLazyGetOscapCustomizationsQuery,
16+
useUpdateBlueprintMutation,
17+
} from '@/store/api/backend/onprem/composerApi';
18+
import { composerApi } from '@/store/api/backend/onprem/enhancedComposerApi';
19+
import {
20+
contentSourcesApi,
21+
useListSnapshotsByDateMutation,
22+
useSearchRpmMutation,
23+
} from '@/store/api/contentSources/onprem';
24+
25+
import type { PlatformHooks } from './types';
26+
27+
// Feature flag defaults for on-premises — Unleash is not available.
28+
// All flags default to false (default-deny). Add cases here when a
29+
// flag-gated feature needs to be enabled for on-prem users.
30+
export const onPremFlag = (_flag: string): boolean => {
31+
return false;
32+
};
33+
34+
// On-prem environment is static — hoist to avoid allocations per call
35+
const onPremEnv = { isBeta: () => false, isProd: () => true };
36+
37+
// The on-prem hooks use OnPremBaseQuery which is structurally different from
38+
// the hosted FetchBaseQueryError used in PlatformHooks type definitions.
39+
// The runtime behavior is identical, so we cast individual hooks that diverge.
40+
export const onPremPlatform: PlatformHooks = {
41+
queries: {
42+
useGetArchitecturesQuery:
43+
useGetArchitecturesQuery as unknown as PlatformHooks['queries']['useGetArchitecturesQuery'],
44+
useGetDistributionsQuery:
45+
useGetDistributionsQuery as unknown as PlatformHooks['queries']['useGetDistributionsQuery'],
46+
useGetBlueprintQuery:
47+
useGetBlueprintQuery as unknown as PlatformHooks['queries']['useGetBlueprintQuery'],
48+
useGetBlueprintsQuery:
49+
useGetBlueprintsQuery as unknown as PlatformHooks['queries']['useGetBlueprintsQuery'],
50+
useLazyGetBlueprintsQuery:
51+
useLazyGetBlueprintsQuery as unknown as PlatformHooks['queries']['useLazyGetBlueprintsQuery'],
52+
useGetOscapProfilesQuery:
53+
useGetOscapProfilesQuery as unknown as PlatformHooks['queries']['useGetOscapProfilesQuery'],
54+
useGetOscapCustomizationsQuery:
55+
useGetOscapCustomizationsQuery as unknown as PlatformHooks['queries']['useGetOscapCustomizationsQuery'],
56+
useLazyGetOscapCustomizationsQuery:
57+
useLazyGetOscapCustomizationsQuery as unknown as PlatformHooks['queries']['useLazyGetOscapCustomizationsQuery'],
58+
useGetComposesQuery:
59+
useGetComposesQuery as unknown as PlatformHooks['queries']['useGetComposesQuery'],
60+
useGetBlueprintComposesQuery:
61+
useGetBlueprintComposesQuery as unknown as PlatformHooks['queries']['useGetBlueprintComposesQuery'],
62+
useGetComposeStatusQuery:
63+
useGetComposeStatusQuery as unknown as PlatformHooks['queries']['useGetComposeStatusQuery'],
64+
},
65+
mutations: {
66+
useCreateBlueprintMutation:
67+
useCreateBlueprintMutation as unknown as PlatformHooks['mutations']['useCreateBlueprintMutation'],
68+
useUpdateBlueprintMutation:
69+
useUpdateBlueprintMutation as unknown as PlatformHooks['mutations']['useUpdateBlueprintMutation'],
70+
useDeleteBlueprintMutation:
71+
useDeleteBlueprintMutation as unknown as PlatformHooks['mutations']['useDeleteBlueprintMutation'],
72+
useComposeBlueprintMutation:
73+
useComposeBlueprintMutation as unknown as PlatformHooks['mutations']['useComposeBlueprintMutation'],
74+
useSearchRpmMutation:
75+
useSearchRpmMutation as unknown as PlatformHooks['mutations']['useSearchRpmMutation'],
76+
useListSnapshotsByDateMutation:
77+
useListSnapshotsByDateMutation as unknown as PlatformHooks['mutations']['useListSnapshotsByDateMutation'],
78+
},
79+
env: {
80+
useFlag: onPremFlag,
81+
useGetEnvironment: () => onPremEnv,
82+
},
83+
api: {
84+
backendApi: composerApi as unknown as PlatformHooks['api']['backendApi'],
85+
contentSourcesApi:
86+
contentSourcesApi as unknown as PlatformHooks['api']['contentSourcesApi'],
87+
useBackendPrefetch:
88+
composerApi.usePrefetch as unknown as PlatformHooks['api']['useBackendPrefetch'],
89+
},
90+
};

0 commit comments

Comments
 (0)