Wizard: Fix nav status icon

Status icon rendered only when the step was previously visited, this caused problems with imported blueprints.

How to reproduce a bug:
1. import a blueprint with invalid hostname
2. skip to Review

Current behaviour:
- the Create blueprint button is disabled, but there is no indication of error next to the Hostname step in navigation

After fix:
- the error status should be rendered next to the Hostname nav item
This commit is contained in:
regexowl 2025-02-11 15:24:04 +01:00 committed by Klara Simickova
parent cbaf3ad99a
commit 87d6c57174
2 changed files with 25 additions and 14 deletions

View file

@ -282,16 +282,14 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => {
);
// Only this code is different from the original
const status =
(step.isVisited && step.id !== activeStep?.id && step.status) ||
'default';
const status = (step.id !== activeStep.id && step.status) || 'default';
return (
<WizardNavItem
key={step.id}
id={step.id}
content={step.name}
isCurrent={activeStep?.id === step.id}
isCurrent={activeStep.id === step.id}
isDisabled={
step.isDisabled ||
(isVisitRequired && !step.isVisited && !hasVisitedNextStep)

View file

@ -4,7 +4,10 @@ import { UNIQUE_VALIDATION_DELAY } from '../../../constants';
import { useLazyGetBlueprintsQuery } from '../../../store/backendApi';
import { useAppSelector } from '../../../store/hooks';
import { BlueprintsResponse } from '../../../store/imageBuilderApi';
import { useShowActivationKeyQuery } from '../../../store/rhsmApi';
import {
useListActivationKeysQuery,
useShowActivationKeyQuery,
} from '../../../store/rhsmApi';
import {
selectBlueprintId,
selectBlueprintName,
@ -78,14 +81,24 @@ export function useRegistrationValidation(): StepValidation {
const registrationType = useAppSelector(selectRegistrationType);
const activationKey = useAppSelector(selectActivationKey);
const { isFetching, isError } = useShowActivationKeyQuery(
{ name: activationKey! },
{
skip: !activationKey,
}
);
const {
isUninitialized,
isFetching: isFetchingKeys,
isError: isErrorKeys,
} = useListActivationKeysQuery();
const { isFetching: isFetchingKeyInfo, isError: isErrorKeyInfo } =
useShowActivationKeyQuery(
{ name: activationKey! },
{
skip: !activationKey,
}
);
if (registrationType !== 'register-later' && !activationKey) {
if (isUninitialized || isFetchingKeys || !isErrorKeys) {
return { errors: {}, disabledNext: false };
}
return {
errors: { activationKey: 'No activation key selected' },
disabledNext: true,
@ -95,7 +108,7 @@ export function useRegistrationValidation(): StepValidation {
if (
registrationType !== 'register-later' &&
activationKey &&
(isFetching || isError)
(isFetchingKeyInfo || isErrorKeyInfo)
) {
return {
errors: { activationKey: 'Invalid activation key' },
@ -404,13 +417,13 @@ export function useDetailsValidation(): StepValidation {
}, [blueprintId, name, setUniqueName, trigger, nameValid]);
let nameError = '';
if (!nameValid) {
if (name && !nameValid) {
nameError = 'Invalid blueprint name';
} else if (uniqueName === false) {
nameError = 'Blueprint with this name already exists';
} else if (!blueprintId && uniqueName === null) {
// Hack to keep the error message from flickering in create mode
nameError = 'default';
return { errors: { name: '' }, disabledNext: false };
}
return {