From 94f24ce0856c7ecc27f04219d77e49b33919b044 Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Tue, 21 Jan 2025 10:52:27 +0000 Subject: [PATCH] store/cockpitApi: add create blueprint mutation --- .../steps/Review/Footer/CreateDropdown.tsx | 2 +- .../steps/Review/Footer/Footer.tsx | 6 ++---- src/store/backendApi.ts | 4 ++++ src/store/cockpitApi.ts | 20 +++++++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Components/CreateImageWizard/steps/Review/Footer/CreateDropdown.tsx b/src/Components/CreateImageWizard/steps/Review/Footer/CreateDropdown.tsx index 933f364c..da47956d 100644 --- a/src/Components/CreateImageWizard/steps/Review/Footer/CreateDropdown.tsx +++ b/src/Components/CreateImageWizard/steps/Review/Footer/CreateDropdown.tsx @@ -13,12 +13,12 @@ import { import useChrome from '@redhat-cloud-services/frontend-components/useChrome'; import { AMPLITUDE_MODULE_NAME } from '../../../../../constants'; +import { useCreateBlueprintMutation } from '../../../../../store/backendApi'; import { setBlueprintId } from '../../../../../store/BlueprintSlice'; import { useAppDispatch, useAppSelector } from '../../../../../store/hooks'; import { CreateBlueprintRequest, useComposeBlueprintMutation, - useCreateBlueprintMutation, } from '../../../../../store/imageBuilderApi'; import { selectPackages } from '../../../../../store/wizardSlice'; diff --git a/src/Components/CreateImageWizard/steps/Review/Footer/Footer.tsx b/src/Components/CreateImageWizard/steps/Review/Footer/Footer.tsx index 11dfa2c1..f644a113 100644 --- a/src/Components/CreateImageWizard/steps/Review/Footer/Footer.tsx +++ b/src/Components/CreateImageWizard/steps/Review/Footer/Footer.tsx @@ -15,10 +15,8 @@ import { useNavigate, useParams } from 'react-router-dom'; import { CreateSaveAndBuildBtn, CreateSaveButton } from './CreateDropdown'; import { EditSaveAndBuildBtn, EditSaveButton } from './EditDropdown'; -import { - useCreateBlueprintMutation, - useUpdateBlueprintMutation, -} from '../../../../../store/imageBuilderApi'; +import { useCreateBlueprintMutation } from '../../../../../store/backendApi'; +import { useUpdateBlueprintMutation } from '../../../../../store/imageBuilderApi'; import { resolveRelPath } from '../../../../../Utilities/path'; import { mapRequestFromState } from '../../../utilities/requestMapper'; import { useIsBlueprintValid } from '../../../utilities/useValidation'; diff --git a/src/store/backendApi.ts b/src/store/backendApi.ts index 40766f5d..aae3f9f8 100644 --- a/src/store/backendApi.ts +++ b/src/store/backendApi.ts @@ -20,6 +20,10 @@ export const useLazyGetBlueprintsQuery = process.env.IS_ON_PREMISE ? cockpitQueries.useLazyGetBlueprintsQuery : imageBuilderQueries.useLazyGetBlueprintsQuery; +export const useCreateBlueprintMutation = process.env.IS_ON_PREMISE + ? cockpitQueries.useCreateBlueprintMutation + : imageBuilderQueries.useCreateBlueprintMutation; + export const useDeleteBlueprintMutation = process.env.IS_ON_PREMISE ? cockpitQueries.useDeleteBlueprintMutation : imageBuilderQueries.useDeleteBlueprintMutation; diff --git a/src/store/cockpitApi.ts b/src/store/cockpitApi.ts index 0df446f6..ede0ba04 100644 --- a/src/store/cockpitApi.ts +++ b/src/store/cockpitApi.ts @@ -27,6 +27,8 @@ import { GetOscapProfilesApiResponse, GetBlueprintApiResponse, GetBlueprintApiArg, + CreateBlueprintApiResponse, + CreateBlueprintApiArg, } from './imageBuilderApi'; import { mapOnPremToHosted } from '../Components/Blueprints/helpers/onPremToHostedBlueprintMapper'; @@ -183,6 +185,23 @@ export const cockpitApi = emptyCockpitApi.injectEndpoints({ } }, }), + createBlueprint: builder.mutation< + CreateBlueprintApiResponse, + CreateBlueprintApiArg + >({ + queryFn: async () => { + // TODO: actually save the result to file + try { + return { + data: { + id: '', + }, + }; + } catch (error) { + return { error }; + } + }, + }), deleteBlueprint: builder.mutation< DeleteBlueprintApiResponse, DeleteBlueprintApiArg @@ -239,6 +258,7 @@ export const { useGetBlueprintQuery, useGetBlueprintsQuery, useLazyGetBlueprintsQuery, + useCreateBlueprintMutation, useDeleteBlueprintMutation, useGetOscapProfilesQuery, useListSnapshotsByDateMutation,