Skip to content

Commit

Permalink
fix: allow for empty groupId in form (#7798)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
Tymek authored Aug 7, 2024
1 parent ff9b729 commit 4daede8
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -82,17 +82,17 @@ const FlexibleStrategy = ({
return parseParameterString(parameters.stickiness);
}, [loading, defaultStickiness, parameters.stickiness]);

const groupId = useMemo(() => {
useEffect(() => {
if (!parameters.groupId && !loading) {
if (isDefaultStrategyEdit || !featureId) {
updateParameter('groupId', '');
} else {
updateParameter('groupId', featureId);
}
}
}, [isDefaultStrategyEdit, featureId, loading]);

return parseParameterString(parameters.groupId);
}, [parameters.groupId, isDefaultStrategyEdit, featureId, loading]);
const groupId = parseParameterString(parameters.groupId);

if (loading) {
return <Loader />;
Expand Down Expand Up @@ -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'))}
Expand Down

0 comments on commit 4daede8

Please sign in to comment.