store/cockpit: add content sources api
Add a `contentSourcesApi` for the on-prem frontend. We need to add a small workaround and put these endpoints under the `cockpitApi` reducer. since RTK query here, doesn't like splitting out apis when they are fundamentally the same. To workaround this we can will just chain the endpoints so: `emptyCockpitApi` -> `contentSourcesApi` -> `cockpitApi` This allows us to keep the `contentSourcesApi` separate so we can export some of the endpoints so that the `cockpitApi` doesn't become a monolith.
This commit is contained in:
parent
b8ceba2e3e
commit
bc1564eddb
5 changed files with 60 additions and 27 deletions
|
|
@ -35,7 +35,7 @@ import {
|
|||
targetOptions,
|
||||
UNIT_GIB,
|
||||
} from '../../../../constants';
|
||||
import { useListSnapshotsByDateMutation } from '../../../../store/backendApi';
|
||||
import { useListSnapshotsByDateMutation } from '../../../../store/contentSourcesApi';
|
||||
import { useAppSelector } from '../../../../store/hooks';
|
||||
import { useGetSourceListQuery } from '../../../../store/provisioningApi';
|
||||
import { useShowActivationKeyQuery } from '../../../../store/rhsmApi';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import * as cockpitQueries from './cockpit/cockpitApi';
|
||||
import { cockpitApi } from './cockpit/enhancedCockpitApi';
|
||||
import * as sourcesQueries from './service/contentSourcesApi';
|
||||
import { imageBuilderApi } from './service/enhancedImageBuilderApi';
|
||||
import * as serviceQueries from './service/imageBuilderApi';
|
||||
|
||||
|
|
@ -32,10 +31,6 @@ export const useGetOscapProfilesQuery = process.env.IS_ON_PREMISE
|
|||
? cockpitQueries.useGetOscapProfilesQuery
|
||||
: serviceQueries.useGetOscapProfilesQuery;
|
||||
|
||||
export const useListSnapshotsByDateMutation = process.env.IS_ON_PREMISE
|
||||
? cockpitQueries.useListSnapshotsByDateMutation
|
||||
: sourcesQueries.useListSnapshotsByDateMutation;
|
||||
|
||||
export const useComposeBlueprintMutation = process.env.IS_ON_PREMISE
|
||||
? cockpitQueries.useComposeBlueprintMutation
|
||||
: serviceQueries.useComposeBlueprintMutation;
|
||||
|
|
|
|||
|
|
@ -10,14 +10,16 @@ import cockpit from 'cockpit';
|
|||
import { fsinfo } from 'cockpit/fsinfo';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { emptyCockpitApi } from './emptyCockpitApi';
|
||||
// We have to work around RTK query here, since it doesn't like splitting
|
||||
// out the same api into two separate apis. So, instead, we can just
|
||||
// inherit/import the `contentSourcesApi` and build on top of that.
|
||||
// This is fine since all the api endpoints for on-prem should query
|
||||
// the same unix socket. This allows us to split out the code a little
|
||||
// bit so that the `cockpitApi` doesn't become a monolith.
|
||||
import { contentSourcesApi } from './contentSourcesApi';
|
||||
|
||||
import { mapHostedToOnPrem } from '../../Components/Blueprints/helpers/onPremToHostedBlueprintMapper';
|
||||
import { BLUEPRINTS_DIR } from '../../constants';
|
||||
import {
|
||||
ListSnapshotsByDateApiArg,
|
||||
ListSnapshotsByDateApiResponse,
|
||||
} from '../service/contentSourcesApi';
|
||||
import {
|
||||
ComposeBlueprintApiResponse,
|
||||
ComposeBlueprintApiArg,
|
||||
|
|
@ -84,7 +86,7 @@ const readComposes = async (bpID: string) => {
|
|||
return composes;
|
||||
};
|
||||
|
||||
export const cockpitApi = emptyCockpitApi.injectEndpoints({
|
||||
export const cockpitApi = contentSourcesApi.injectEndpoints({
|
||||
endpoints: (builder) => {
|
||||
return {
|
||||
getArchitectures: builder.query<
|
||||
|
|
@ -278,19 +280,6 @@ export const cockpitApi = emptyCockpitApi.injectEndpoints({
|
|||
};
|
||||
},
|
||||
}),
|
||||
// add an empty response for now
|
||||
// just so we can step through the create
|
||||
// image wizard for on prem
|
||||
listSnapshotsByDate: builder.mutation<
|
||||
ListSnapshotsByDateApiResponse,
|
||||
ListSnapshotsByDateApiArg
|
||||
>({
|
||||
queryFn: () => ({
|
||||
data: {
|
||||
data: [],
|
||||
},
|
||||
}),
|
||||
}),
|
||||
composeBlueprint: builder.mutation<
|
||||
ComposeBlueprintApiResponse,
|
||||
ComposeBlueprintApiArg
|
||||
|
|
@ -455,6 +444,10 @@ export const cockpitApi = emptyCockpitApi.injectEndpoints({
|
|||
}),
|
||||
};
|
||||
},
|
||||
// since we are inheriting some endpoints,
|
||||
// we want to make sure that we don't override
|
||||
// any existing endpoints.
|
||||
overrideExisting: 'throw',
|
||||
});
|
||||
|
||||
export const {
|
||||
|
|
@ -465,7 +458,6 @@ export const {
|
|||
useCreateBlueprintMutation,
|
||||
useDeleteBlueprintMutation,
|
||||
useGetOscapProfilesQuery,
|
||||
useListSnapshotsByDateMutation,
|
||||
useComposeBlueprintMutation,
|
||||
useGetComposesQuery,
|
||||
useGetBlueprintComposesQuery,
|
||||
|
|
|
|||
27
src/store/cockpit/contentSourcesApi.ts
Normal file
27
src/store/cockpit/contentSourcesApi.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { emptyCockpitApi } from './emptyCockpitApi';
|
||||
|
||||
import type {
|
||||
ListSnapshotsByDateApiArg,
|
||||
ListSnapshotsByDateApiResponse,
|
||||
} from '../service/contentSourcesApi';
|
||||
|
||||
export const contentSourcesApi = emptyCockpitApi.injectEndpoints({
|
||||
endpoints: (builder) => ({
|
||||
// add an empty response for now
|
||||
// just so we can step through the create
|
||||
// image wizard for on prem
|
||||
listSnapshotsByDate: builder.mutation<
|
||||
ListSnapshotsByDateApiResponse,
|
||||
ListSnapshotsByDateApiArg
|
||||
>({
|
||||
queryFn: () => ({
|
||||
data: {
|
||||
data: [],
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
overrideExisting: false,
|
||||
});
|
||||
|
||||
export const { useListSnapshotsByDateMutation } = contentSourcesApi;
|
||||
|
|
@ -1 +1,20 @@
|
|||
export * from './service/contentSourcesApi';
|
||||
import * as cockpitQueries from './cockpit/contentSourcesApi';
|
||||
import * as serviceQueries from './service/contentSourcesApi';
|
||||
|
||||
export const useListSnapshotsByDateMutation = process.env.IS_ON_PREMISE
|
||||
? cockpitQueries.useListSnapshotsByDateMutation
|
||||
: serviceQueries.useListSnapshotsByDateMutation;
|
||||
|
||||
export const {
|
||||
useListFeaturesQuery,
|
||||
useSearchRpmMutation,
|
||||
useSearchPackageGroupMutation,
|
||||
useListRepositoriesQuery,
|
||||
useCreateRepositoryMutation,
|
||||
useBulkImportRepositoriesMutation,
|
||||
useListRepositoriesRpmsQuery,
|
||||
contentSourcesApi,
|
||||
} = serviceQueries;
|
||||
|
||||
// we need to re-export all the types
|
||||
export type * from './service/contentSourcesApi';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue