From 6ced9dcec047ab4e416fc0e690f9bf6c467ff2d2 Mon Sep 17 00:00:00 2001 From: Pedro Igor Date: Tue, 7 Jan 2025 16:10:31 -0300 Subject: [PATCH] Attribute is required only if the corresponding field in the metadata is set Close #36241 Signed-off-by: Pedro Igor --- js/libs/ui-shared/src/user-profile/utils.ts | 29 ++------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/js/libs/ui-shared/src/user-profile/utils.ts b/js/libs/ui-shared/src/user-profile/utils.ts index 4bd0924542f..63a8e908170 100644 --- a/js/libs/ui-shared/src/user-profile/utils.ts +++ b/js/libs/ui-shared/src/user-profile/utils.ts @@ -90,34 +90,9 @@ export function setUserProfileServerError( export function isRequiredAttribute({ required, - validators, }: UserProfileAttributeMetadata): boolean { - // Check if required is true or if the validators include a validation that would make the attribute implicitly required. - return required || hasRequiredValidators(validators); -} - -/** - * Checks whether the given validators include a validation that would make the attribute implicitly required. - */ -function hasRequiredValidators( - validators?: UserProfileAttributeMetadata["validators"], -): boolean { - // If we don't have any validators, the attribute is not required. - if (!validators) { - return false; - } - - // If the 'length' validator is defined and has a minimal length greater than zero the attribute is implicitly required. - // We have to do a lot of defensive coding here, because we don't have type information for the validators. - if ( - "length" in validators && - "min" in validators.length && - typeof validators.length.min === "number" - ) { - return validators.length.min > 0; - } - - return false; + // Check if required is true + return required as boolean; } export function isUserProfileError(error: unknown): error is UserProfileError {