From 11d36f4d6ca02fbb818ba0a4635f113a6c511ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Tue, 1 Apr 2025 16:09:13 +0200 Subject: [PATCH] Wizard: show a specific error message when description validation fails Prior to this commit, the wizard showed "Invalid description" when the description was too long. This was rather unhelpful for users. The actual size check happens in validators.ts, but the functions there just return a boolean value, even if they check for multiple criteria. I'm not entirely sure, why the validation functions live in a separate file, so I decided to move this specific condition to useValidation.tsx so the condition, and the relevant user-facing error message can be defined next to each other. --- .../CreateImageWizard/utilities/useValidation.tsx | 9 +++++---- src/Components/CreateImageWizard/validators.ts | 4 ---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Components/CreateImageWizard/utilities/useValidation.tsx b/src/Components/CreateImageWizard/utilities/useValidation.tsx index 4edaedc9..374a1256 100644 --- a/src/Components/CreateImageWizard/utilities/useValidation.tsx +++ b/src/Components/CreateImageWizard/utilities/useValidation.tsx @@ -42,7 +42,6 @@ import { timezones } from '../steps/Timezone/timezonesList'; import { getDuplicateMountPoints, isBlueprintNameValid, - isBlueprintDescriptionValid, isMountpointMinSizeValid, isSnapshotValid, isHostnameValid, @@ -598,9 +597,11 @@ export function useDetailsValidation(): StepValidation { return { errors: { name: '' }, disabledNext: false }; } - const descriptionError = !isBlueprintDescriptionValid(description) - ? 'Invalid description' - : ''; + let descriptionError = ''; + const maxDescriptionLength = 250; + if (description.length > maxDescriptionLength) { + descriptionError = `Description is too long (max ${maxDescriptionLength} characters)`; + } return { errors: { diff --git a/src/Components/CreateImageWizard/validators.ts b/src/Components/CreateImageWizard/validators.ts index eb6cab74..7b7f1e48 100644 --- a/src/Components/CreateImageWizard/validators.ts +++ b/src/Components/CreateImageWizard/validators.ts @@ -48,10 +48,6 @@ export const isSnapshotValid = (dateString: string) => { return !isNaN(date.getTime()) && isSnapshotDateValid(date); }; -export const isBlueprintDescriptionValid = (blueprintDescription: string) => { - return blueprintDescription.length <= 250; -}; - export const isFileSystemConfigValid = (partitions: Partition[]) => { const duplicates = getDuplicateMountPoints(partitions); return duplicates.length === 0;