Skip to content

Commit

Permalink
feat(HMS-3431): add a blueprint build images
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfefer authored and lucasgarfield committed Feb 7, 2024
1 parent 61abf24 commit 13ca8e8
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/Components/ImagesTable/ImagesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const ImagesTable = ({ selectedBlueprint }: ImageTableProps) => {
const {
data: blueprintsComposes,
isSuccess: isBlueprintsSuccess,
isFetching: isFetchingBlueprintsCompose,
isLoading: isLoadingBlueprintsCompose,
isError: isBlueprintsError,
} = useGetBlueprintComposesQuery(
{
Expand All @@ -97,7 +97,7 @@ const ImagesTable = ({ selectedBlueprint }: ImageTableProps) => {
data: composesData,
isSuccess: isComposesSuccess,
isError: isComposesError,
isFetching: isFetchingComposes,
isLoading: isLoadingComposes,
} = useGetComposesQuery(
{
limit: perPage,
Expand All @@ -115,11 +115,11 @@ const ImagesTable = ({ selectedBlueprint }: ImageTableProps) => {
const data = selectedBlueprint ? blueprintsComposes : composesData;
const isSuccess = selectedBlueprint ? isBlueprintsSuccess : isComposesSuccess;
const isError = selectedBlueprint ? isBlueprintsError : isComposesError;
const isFetching = selectedBlueprint
? isFetchingBlueprintsCompose
: isFetchingComposes;
const isLoading = selectedBlueprint
? isLoadingBlueprintsCompose
: isLoadingComposes;

if (isFetching) {
if (isLoading) {
return (
<Bullseye>
<Spinner />
Expand Down
5 changes: 4 additions & 1 deletion src/Components/LandingPage/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export const LandingPage = () => {

return (
<>
<ImageBuilderHeader experimentalFlag={experimentalFlag} />
<ImageBuilderHeader
experimentalFlag={experimentalFlag}
selectedBlueprint={selectedBlueprint}
/>
{edgeParityFlag ? (
<Tabs
className="pf-c-tabs pf-c-page-header pf-c-table"
Expand Down
19 changes: 18 additions & 1 deletion src/Components/sharedComponents/ImageBuilderHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,25 @@ import {
PageHeaderTitle,
} from '@redhat-cloud-services/frontend-components';

import { useComposeBlueprintMutation } from '../../store/imageBuilderApi';
import './ImageBuilderHeader.scss';

type ImageBuilderHeaderPropTypes = {
experimentalFlag?: string | true | undefined;
selectedBlueprint?: string | undefined;
};

export const ImageBuilderHeader = ({
experimentalFlag,
selectedBlueprint,
}: ImageBuilderHeaderPropTypes) => {
const [buildBlueprint, { isLoading: imageBuildLoading }] =
useComposeBlueprintMutation();

const onBuildHandler = async () => {
selectedBlueprint && (await buildBlueprint({ id: selectedBlueprint }));
};

return (
<>
{/*@ts-ignore*/}
Expand Down Expand Up @@ -94,7 +104,14 @@ export const ImageBuilderHeader = ({
<Button>New blueprint</Button>
</FlexItem>
<FlexItem>
<Button isDisabled>Build images</Button>
<Button
ouiaId="build-images-button"
onClick={onBuildHandler}
isDisabled={!selectedBlueprint}
isLoading={imageBuildLoading}
>
Build images
</Button>
</FlexItem>{' '}
</>
)}
Expand Down
35 changes: 34 additions & 1 deletion src/store/enhancedImageBuilderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { addNotification } from '@redhat-cloud-services/frontend-components-noti
import { imageBuilderApi } from './imageBuilderApi';

const enhancedApi = imageBuilderApi.enhanceEndpoints({
addTagTypes: ['Clone', 'Compose', 'Blueprint'],
addTagTypes: ['Clone', 'Compose', 'Blueprint', 'BlueprintComposes'],
endpoints: {
getBlueprints: {
providesTags: () => {
return [{ type: 'Blueprint' }];
},
},
getBlueprintComposes: {
providesTags: () => {
return [{ type: 'BlueprintComposes' }];
},
},
getComposes: {
providesTags: () => {
return [{ type: 'Compose' }];
Expand Down Expand Up @@ -56,6 +61,34 @@ const enhancedApi = imageBuilderApi.enhanceEndpoints({
});
},
},
composeBlueprint: {
invalidatesTags: [{ type: 'Compose' }, { type: 'BlueprintComposes' }],
onQueryStarted: async (_, { dispatch, queryFulfilled }) => {
queryFulfilled
.then(() => {
dispatch(
addNotification({
variant: 'success',
title: 'Blueprint is being built',
})
);
})
.catch((err) => {
let msg = err.error.statusText;
if (err.error.data?.errors[0]?.detail) {
msg = err.error.data?.errors[0]?.detail;
}

dispatch(
addNotification({
variant: 'danger',
title: 'Blueprint could not be built',
description: `Status code ${err.error.status}: ${msg}`,
})
);
});
},
},
composeImage: {
onQueryStarted: async (_, { dispatch, queryFulfilled }) => {
queryFulfilled
Expand Down
15 changes: 15 additions & 0 deletions src/test/Components/Blueprints/Blueprints.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IMAGE_BUILDER_API } from '../../../constants';
import { emptyGetBlueprints } from '../../fixtures/blueprints';
import { server } from '../../mocks/server';
import { renderWithReduxRouter } from '../../testUtils';
import '@testing-library/jest-dom';

import '@testing-library/jest-dom';

Expand Down Expand Up @@ -71,6 +72,20 @@ describe('Blueprints', () => {
await user.click(blueprintRadioBtn);
expect(screen.queryByTestId('images-table')).not.toBeInTheDocument();
});
test('click build image button', async () => {
renderWithReduxRouter('', {});
const nameMatcher = (_, element) =>
element.getAttribute('name') === blueprintNameWithComposes;

const blueprintRadioBtn = await screen.findByRole('radio', {
name: nameMatcher,
});
await user.click(blueprintRadioBtn);
const buildImageBtn = await screen.findByRole('button', {
name: /Build image/i,
});
expect(buildImageBtn).toBeEnabled();
});

describe('filtering', () => {
test('filter blueprints', async () => {
Expand Down
6 changes: 6 additions & 0 deletions src/test/mocks/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ export const handlers = [

return res(ctx.status(200), ctx.json(resp));
}),
rest.post(
`${IMAGE_BUILDER_API}/experimental/blueprint/:id/compose`,
(req, res, ctx) => {
return res(ctx.status(200));
}
),
rest.get(
`${IMAGE_BUILDER_API}/experimental/blueprints/:id/composes`,
(req, res, ctx) => {
Expand Down

0 comments on commit 13ca8e8

Please sign in to comment.