From 7d4cc87a9238f5af40ee1dada364bda6c19372e5 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Thu, 8 Aug 2024 11:04:05 +0300 Subject: [PATCH] fix: allow for empty groupId in form (#7798) (#7802) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `groupId` parameter because of the change in validation wasn't parsed correctly. Intent was to fill it when it is empty, when the form is loaded. By mistake the same logic applies when you manually remove all characters from the text field. ## About the changes Closes # ### Important files ## Discussion points Co-authored-by: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> --- .../FlexibleStrategy/FlexibleStrategy.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frontend/src/component/feature/StrategyTypes/FlexibleStrategy/FlexibleStrategy.tsx b/frontend/src/component/feature/StrategyTypes/FlexibleStrategy/FlexibleStrategy.tsx index d5c50a2d10..1f1b956c2f 100644 --- a/frontend/src/component/feature/StrategyTypes/FlexibleStrategy/FlexibleStrategy.tsx +++ b/frontend/src/component/feature/StrategyTypes/FlexibleStrategy/FlexibleStrategy.tsx @@ -1,4 +1,4 @@ -import { useMemo } from 'react'; +import { useEffect, useMemo } from 'react'; import { Box, styled } from '@mui/material'; import type { IFeatureStrategyParameters } from 'interfaces/strategy'; import RolloutSlider from '../RolloutSlider/RolloutSlider'; @@ -82,7 +82,7 @@ const FlexibleStrategy = ({ return parseParameterString(parameters.stickiness); }, [loading, defaultStickiness, parameters.stickiness]); - const groupId = useMemo(() => { + useEffect(() => { if (!parameters.groupId && !loading) { if (isDefaultStrategyEdit || !featureId) { updateParameter('groupId', ''); @@ -90,9 +90,9 @@ const FlexibleStrategy = ({ updateParameter('groupId', featureId); } } + }, [isDefaultStrategyEdit, featureId, loading]); - return parseParameterString(parameters.groupId); - }, [parameters.groupId, isDefaultStrategyEdit, featureId, loading]); + const groupId = parseParameterString(parameters.groupId); if (loading) { return ; @@ -126,7 +126,10 @@ const FlexibleStrategy = ({ value={groupId} disabled={!editable} onChange={(e) => - updateParameter('groupId', e.target.value) + updateParameter( + 'groupId', + parseParameterString(e.target.value), + ) } data-testid={FLEXIBLE_STRATEGY_GROUP_ID} error={Boolean(errors?.getFormError('groupId'))}