debian-image-builder-frontend/src/Components/CreateImageWizardV2/EditImageWizard.tsx
lucasgarfield 61b23216f4 V2 Wizard: OpenSCAP edit tests
Edit mode is now fully tested and working for OpenSCAP profiles. A
handler for the PUT request was added and the fixtures were updated to
support this.

`EditImageWizard.tsx`: Previously we dispatched `initializeWizard()`
while waiting for the blueprintDetails to load. This meant that the
state was incorrect (empty) while the blueprintDetails request was
in flight.

`requestMapper.tsx`: Correctly populate state in edit mode if the
blueprint contains a custom file system – previously custom mountpoints
were dropped and automatic mode was selected.

`spyOnRequest()`: Differentiate between request types (e.g. GET, PUT)
for the same endpoint.
2024-04-30 15:13:50 +02:00

45 lines
1.2 KiB
TypeScript

import React, { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import CreateImageWizard from './CreateImageWizard';
import { mapRequestToState } from './utilities/requestMapper';
import { useAppDispatch } from '../../store/hooks';
import { useGetBlueprintQuery } from '../../store/imageBuilderApi';
import { loadWizardState } from '../../store/wizardSlice';
import { resolveRelPath } from '../../Utilities/path';
type EditImageWizardProps = {
blueprintId: string;
};
const EditImageWizard = ({ blueprintId }: EditImageWizardProps) => {
const dispatch = useAppDispatch();
const navigate = useNavigate();
const {
data: blueprintDetails,
error,
isSuccess,
} = useGetBlueprintQuery({
id: blueprintId,
});
useEffect(() => {
if (blueprintId && blueprintDetails) {
const editBlueprintState = mapRequestToState(blueprintDetails);
dispatch(loadWizardState(editBlueprintState));
}
}, [blueprintId, blueprintDetails, dispatch]);
useEffect(() => {
// redirect to the main page if the composeId is invalid
if (error) {
navigate(resolveRelPath(''));
}
}, [error, navigate]);
return isSuccess ? <CreateImageWizard isEdit /> : undefined;
};
export default EditImageWizard;