Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 Wizard - Foundations #1531

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/Components/CreateImageWizardV2/CreateImageWizard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,3 @@ ul.pf-m-plain {
padding-left: 0;
margin-left: 0;
}

button.pf-v5-c-menu-toggle {
max-width: 100%;
}
119 changes: 18 additions & 101 deletions src/Components/CreateImageWizardV2/CreateImageWizard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React from 'react';

import {
Button,
Expand All @@ -9,58 +9,23 @@ import {
} from '@patternfly/react-core';
import { useNavigate } from 'react-router-dom';

import {
EnvironmentStateType,
filterEnvironment,
hasUserSelectedAtLeastOneEnv,
useGetAllowedTargets,
} from './steps/ImageOutput/Environment';
import ImageOutputStep from './steps/ImageOutput/ImageOutput';
import ReviewStep from './steps/Review/ReviewStep';

import { RHEL_9, X86_64 } from '../../constants';
import { useAppDispatch } from '../../store/hooks';
import './CreateImageWizard.scss';
import { ArchitectureItem, Distributions } from '../../store/imageBuilderApi';
import { initializeWizard } from '../../store/wizardSlice';
import { resolveRelPath } from '../../Utilities/path';
import { ImageBuilderHeader } from '../sharedComponents/ImageBuilderHeader';

/**
* @return true if the array in prevAllowedTargets is equivalent to the array
* allowedTargets, false otherwise
*/
const isIdenticalToPrev = (
prevAllowedTargets: string[],
allowedTargets: string[]
) => {
let identicalToPrev = true;
if (allowedTargets.length === prevAllowedTargets.length) {
allowedTargets.forEach((elem) => {
if (!prevAllowedTargets.includes(elem)) {
identicalToPrev = false;
}
});
} else {
identicalToPrev = false;
}
return identicalToPrev;
};

type CustomWizardFooterPropType = {
isNextDisabled: boolean;
disableNext: boolean;
};
/**
* The custom wizard footer is only switching the order of the buttons compared
* to the default wizard footer from the PF5 library.
*/
const CustomWizardFooter = ({ isNextDisabled }: CustomWizardFooterPropType) => {

export const CustomWizardFooter = ({
disableNext: disableNext,
}: CustomWizardFooterPropType) => {
const { goToNextStep, goToPrevStep, close } = useWizardContext();
return (
<WizardFooterWrapper>
<Button
variant="primary"
onClick={goToNextStep}
isDisabled={isNextDisabled}
>
<Button variant="primary" onClick={goToNextStep} isDisabled={disableNext}>
Next
</Button>
<Button variant="secondary" onClick={goToPrevStep}>
Expand All @@ -75,41 +40,11 @@ const CustomWizardFooter = ({ isNextDisabled }: CustomWizardFooterPropType) => {

const CreateImageWizard = () => {
const navigate = useNavigate();
// Image output step states
const [release, setRelease] = useState<Distributions>(RHEL_9);
const [arch, setArch] = useState<ArchitectureItem['arch']>(X86_64);
const {
data: allowedTargets,
isFetching,
isSuccess,
isError,
} = useGetAllowedTargets({
architecture: arch,
release: release,
});
const [environment, setEnvironment] = useState<EnvironmentStateType>(
filterEnvironment(
{
aws: { selected: false, authorized: false },
azure: { selected: false, authorized: false },
gcp: { selected: false, authorized: false },
oci: { selected: false, authorized: false },
'vsphere-ova': { selected: false, authorized: false },
vsphere: { selected: false, authorized: false },
'guest-image': { selected: false, authorized: false },
'image-installer': { selected: false, authorized: false },
wsl: { selected: false, authorized: false },
},
allowedTargets
)
);
// Update of the environment when the architecture and release are changed.
// This pattern prevents the usage of a useEffect See https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
const [prevAllowedTargets, setPrevAllowedTargets] = useState(allowedTargets);
if (!isIdenticalToPrev(prevAllowedTargets, allowedTargets)) {
setPrevAllowedTargets(allowedTargets);
setEnvironment(filterEnvironment(environment, allowedTargets));
}
const dispatch = useAppDispatch();

// Ensure the wizard starts with a fresh initial state
dispatch(initializeWizard);

return (
<>
<ImageBuilderHeader />
Expand All @@ -118,31 +53,13 @@ const CreateImageWizard = () => {
<WizardStep
name="Image output"
id="step-image-output"
footer={
<CustomWizardFooter
isNextDisabled={!hasUserSelectedAtLeastOneEnv(environment)}
/>
}
>
<ImageOutputStep
release={release}
setRelease={setRelease}
arch={arch}
setArch={setArch}
environment={environment}
setEnvironment={setEnvironment}
isFetching={isFetching}
isError={isError}
isSuccess={isSuccess}
/>
</WizardStep>
footer={<CustomWizardFooter disableNext={false} />}
></WizardStep>
<WizardStep
name="Review"
id="step-review"
footer={<CustomWizardFooter isNextDisabled={true} />}
>
<ReviewStep release={release} arch={arch} />
</WizardStep>
footer={<CustomWizardFooter disableNext={true} />}
></WizardStep>
</Wizard>
</section>
</>
Expand Down

This file was deleted.

This file was deleted.

Loading
Loading