store/cockpitApi: get blueprint endpoint

Create a get blueprint endpoint for the on-prem store.
This commit is contained in:
Gianluca Zuccarelli 2025-01-10 12:47:21 +00:00 committed by Sanne Raymaekers
parent 5988c42b6f
commit 34bf64debc
6 changed files with 50 additions and 9 deletions

View file

@ -5,9 +5,9 @@ import { Button, Modal, ModalVariant } from '@patternfly/react-core';
import { BuildImagesButton } from './BuildImagesButton';
import { useGetBlueprintQuery } from '../../store/backendApi';
import { selectSelectedBlueprintId } from '../../store/BlueprintSlice';
import { useAppSelector } from '../../store/hooks';
import { useGetBlueprintQuery } from '../../store/imageBuilderApi';
type blueprintDiffProps = {
// baseVersion is the version of the blueprint to compare the latest version against

View file

@ -19,12 +19,12 @@ import { addNotification } from '@redhat-cloud-services/frontend-components-noti
import { skipToken } from '@reduxjs/toolkit/query';
import { targetOptions } from '../../constants';
import { useGetBlueprintQuery } from '../../store/backendApi';
import { selectSelectedBlueprintId } from '../../store/BlueprintSlice';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import {
ImageTypes,
useComposeBlueprintMutation,
useGetBlueprintQuery,
} from '../../store/imageBuilderApi';
type BuildImagesButtonPropTypes = {

View file

@ -5,8 +5,8 @@ import { useNavigate } from 'react-router-dom';
import CreateImageWizard from './CreateImageWizard';
import { mapRequestToState } from './utilities/requestMapper';
import { useGetBlueprintQuery } from '../../store/backendApi';
import { useAppDispatch } from '../../store/hooks';
import { useGetBlueprintQuery } from '../../store/imageBuilderApi';
import { loadWizardState } from '../../store/wizardSlice';
import { resolveRelPath } from '../../Utilities/path';

View file

@ -1,11 +1,9 @@
import { useEffect, useState } from 'react';
import { UNIQUE_VALIDATION_DELAY } from '../../../constants';
import { useLazyGetBlueprintsQuery } from '../../../store/backendApi';
import { useAppSelector } from '../../../store/hooks';
import {
BlueprintsResponse,
useLazyGetBlueprintsQuery,
} from '../../../store/imageBuilderApi';
import { BlueprintsResponse } from '../../../store/imageBuilderApi';
import { useShowActivationKeyQuery } from '../../../store/rhsmApi';
import {
selectBlueprintId,

View file

@ -1,24 +1,37 @@
import {
useGetArchitecturesQuery as useCockpitGetArchitecturesQuery,
useGetBlueprintQuery as useCockpitGetBlueprintQuery,
useGetBlueprintsQuery as useCockpitGetBlueprintsQuery,
useLazyGetBlueprintsQuery as useCockpitLazyGetBlueprintsQuery,
useDeleteBlueprintMutation as useCockpitDeleteMutation,
} from './cockpitApi';
import { cockpitApi } from './enhancedCockpitApi';
import { imageBuilderApi } from './enhancedImageBuilderApi';
import {
useGetArchitecturesQuery as useImageBuilderGetArchitecturesQuery,
useGetBlueprintQuery as useImageBuilderGetBlueprintQuery,
useGetBlueprintsQuery as useImageBuilderGetBlueprintsQuery,
useLazyGetBlueprintsQuery as useImageBuilderLazyGetBlueprintsQuery,
useDeleteBlueprintMutation as useImageBuilderDeleteMutation,
useGetOscapProfilesQuery as useImageBuilderGetOscapProfilesQuery,
} from './imageBuilderApi';
export const useGetArchitecturesQuery = process.env.IS_ON_PREMISE
? useCockpitGetArchitecturesQuery
: useImageBuilderGetArchitecturesQuery;
export const useGetBlueprintQuery = process.env.IS_ON_PREMISE
? useCockpitGetBlueprintQuery
: useImageBuilderGetBlueprintQuery;
export const useGetBlueprintsQuery = process.env.IS_ON_PREMISE
? useCockpitGetBlueprintsQuery
: useImageBuilderGetBlueprintsQuery;
export const useLazyGetBlueprintsQuery = process.env.IS_ON_PREMISE
? useCockpitLazyGetBlueprintsQuery
: useImageBuilderLazyGetBlueprintsQuery;
export const useDeleteBlueprintMutation = process.env.IS_ON_PREMISE
? useCockpitDeleteMutation
: useImageBuilderDeleteMutation;

View file

@ -19,6 +19,8 @@ import {
DeleteBlueprintApiResponse,
DeleteBlueprintApiArg,
BlueprintItem,
GetBlueprintApiResponse,
GetBlueprintApiArg,
} from './imageBuilderApi';
import { mapOnPremToHosted } from '../Components/Blueprints/helpers/onPremToHostedBlueprintMapper';
@ -70,6 +72,32 @@ export const cockpitApi = emptyCockpitApi.injectEndpoints({
};
},
}),
getBlueprint: builder.query<GetBlueprintApiResponse, GetBlueprintApiArg>({
queryFn: async ({ id, version }) => {
try {
const blueprintsDir = await getBlueprintsPath();
const file = cockpit.file(path.join(blueprintsDir, id));
const contents = await file.read();
const parsed = toml.parse(contents);
file.close();
const blueprint = mapOnPremToHosted(parsed);
return {
data: {
...blueprint,
id,
version,
last_modified_at: Date.now().toString(),
image_requests: [],
},
};
} catch (error) {
return { error };
}
},
}),
getBlueprints: builder.query<
GetBlueprintsApiResponse,
GetBlueprintsApiArg
@ -175,7 +203,9 @@ export const cockpitApi = emptyCockpitApi.injectEndpoints({
});
export const {
useGetBlueprintsQuery,
useDeleteBlueprintMutation,
useGetArchitecturesQuery,
useGetBlueprintQuery,
useGetBlueprintsQuery,
useLazyGetBlueprintsQuery,
useDeleteBlueprintMutation,
} = cockpitApi;