From d448db9a04e06b185b4e5265012b11117158395c Mon Sep 17 00:00:00 2001 From: Michal Gold Date: Sun, 16 Mar 2025 13:53:43 +0200 Subject: [PATCH] Wizard: Refactor Minimum Size input in File system step to use new component This commit refactors the Minimun size field by replacing HookValidatedInput with the new ValidatedInputAndTextArea component. It fixes a bug where the error icon remained visible after the user cleared the value in the field. --- src/Components/CreateImageWizard/ValidatedInput.tsx | 9 +++++++++ .../steps/FileSystem/FileSystemTable.tsx | 5 +++-- .../CreateImageWizard/utilities/useValidation.tsx | 5 ++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Components/CreateImageWizard/ValidatedInput.tsx b/src/Components/CreateImageWizard/ValidatedInput.tsx index 22172e4b..1ac9d4cb 100644 --- a/src/Components/CreateImageWizard/ValidatedInput.tsx +++ b/src/Components/CreateImageWizard/ValidatedInput.tsx @@ -48,6 +48,7 @@ type ValidationInputProp = TextInputProps & value: string ) => void; isRequired?: boolean; + warning?: string; }; type ErrorMessageProps = { @@ -66,6 +67,7 @@ export const ValidatedInputAndTextArea = ({ ariaLabel, inputType = 'textInput', isRequired, + warning = undefined, }: ValidationInputProp) => { const errorMessage = stepValidation.errors[fieldName] || ''; const hasError = errorMessage !== ''; @@ -108,6 +110,13 @@ export const ValidatedInputAndTextArea = ({ data-testid={dataTestId} /> )} + {warning !== undefined && warning !== '' && ( + + + {warning} + + + )} {hasError && } ); diff --git a/src/Components/CreateImageWizard/steps/FileSystem/FileSystemTable.tsx b/src/Components/CreateImageWizard/steps/FileSystem/FileSystemTable.tsx index 0d946511..656b1d60 100644 --- a/src/Components/CreateImageWizard/steps/FileSystem/FileSystemTable.tsx +++ b/src/Components/CreateImageWizard/steps/FileSystem/FileSystemTable.tsx @@ -33,7 +33,7 @@ import { selectPartitions, } from '../../../../store/wizardSlice'; import { useFilesystemValidation } from '../../utilities/useValidation'; -import { HookValidatedInput } from '../../ValidatedInput'; +import { ValidatedInputAndTextArea } from '../../ValidatedInput'; export const FileSystemContext = React.createContext(true); @@ -253,7 +253,7 @@ const MinimumSize = ({ partition }: MinimumSizePropTypes) => { const stepValidation = useFilesystemValidation(); return ( - { ouiaId="size" stepValidation={stepValidation} fieldName={`min-size-${partition.id}`} + placeholder="File system" onChange={(event, minSize) => { if (minSize === '' || /^\d+$/.test(minSize)) { dispatch( diff --git a/src/Components/CreateImageWizard/utilities/useValidation.tsx b/src/Components/CreateImageWizard/utilities/useValidation.tsx index dbf13f46..b226d388 100644 --- a/src/Components/CreateImageWizard/utilities/useValidation.tsx +++ b/src/Components/CreateImageWizard/utilities/useValidation.tsx @@ -166,7 +166,10 @@ export function useFilesystemValidation(): StepValidation { const duplicates = getDuplicateMountPoints(partitions); for (const partition of partitions) { - if (!isMountpointMinSizeValid(partition.min_size)) { + if (partition.min_size === '') { + errors[`min-size-${partition.id}`] = 'partition size is required'; + disabledNext = true; + } else if (!isMountpointMinSizeValid(partition.min_size)) { errors[`min-size-${partition.id}`] = 'Must be larger than 0'; disabledNext = true; }