From 84a3a4cb61cf7bdce999b1abb771f6e2c9b9e757 Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Wed, 7 Jun 2023 15:35:20 +0300 Subject: [PATCH] fix: remove unneseccary constraint validation request (#3914) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes over-validating constraint ## About the changes Closes # [1-949](https://linear.app/unleash/issue/1-949/fix-overvalidating-constraint) ### Important files ## Discussion points --------- Signed-off-by: andreas-unleash --- .../useConstraintsValidation.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/hooks/api/getters/useConstraintsValidation/useConstraintsValidation.ts b/frontend/src/hooks/api/getters/useConstraintsValidation/useConstraintsValidation.ts index 944404d4e3..c3e759119d 100644 --- a/frontend/src/hooks/api/getters/useConstraintsValidation/useConstraintsValidation.ts +++ b/frontend/src/hooks/api/getters/useConstraintsValidation/useConstraintsValidation.ts @@ -16,9 +16,18 @@ export const useConstraintsValidation = ( return; } - const validationRequests = constraints.map(constraint => { - return validateConstraint(constraint); - }); + const validationRequests = constraints + .filter(constraint => { + const hasValues = + Array.isArray(constraint.values) && + constraint.values.length > 0; + const hasValue = Boolean(constraint.value); + + return hasValues || hasValue; + }) + .map(constraint => { + return validateConstraint(constraint); + }); Promise.all(validationRequests) .then(() => setValid(true))