1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: default segments should only be selected when using default stra… (#4040)

This commit is contained in:
Jaanus Sellin 2023-06-21 15:38:47 +03:00 committed by GitHub
parent 197df96ff4
commit 3763e1b24d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,7 @@ export const FeatureStrategyCreate = () => {
const featureId = useRequiredPathParam('featureId'); const featureId = useRequiredPathParam('featureId');
const environmentId = useRequiredQueryParam('environmentId'); const environmentId = useRequiredQueryParam('environmentId');
const strategyName = useRequiredQueryParam('strategyName'); const strategyName = useRequiredQueryParam('strategyName');
const useDefaultStrategy: boolean = JSON.parse( const shouldUseDefaultStrategy: boolean = JSON.parse(
useQueryParams().get('defaultStrategy') || 'false' useQueryParams().get('defaultStrategy') || 'false'
); );
const { project } = useProject(projectId); const { project } = useProject(projectId);
@ -56,7 +56,9 @@ export const FeatureStrategyCreate = () => {
const [strategy, setStrategy] = useState<Partial<IFeatureStrategy>>({}); const [strategy, setStrategy] = useState<Partial<IFeatureStrategy>>({});
const [segments, setSegments] = useState<ISegment[]>(strategySegments); const [segments, setSegments] = useState<ISegment[]>(
shouldUseDefaultStrategy ? strategySegments : []
);
const { strategyDefinition } = useStrategy(strategyName); const { strategyDefinition } = useStrategy(strategyName);
const errors = useFormErrors(); const errors = useFormErrors();
@ -98,12 +100,12 @@ export const FeatureStrategyCreate = () => {
}, [feature.name]); }, [feature.name]);
useEffect(() => { useEffect(() => {
if (useDefaultStrategy) { if (shouldUseDefaultStrategy) {
setStrategy((defaultStrategy as any) || DEFAULT_STRATEGY); setStrategy((defaultStrategy as any) || DEFAULT_STRATEGY);
} else if (strategyDefinition) { } else if (strategyDefinition) {
setStrategy(createFeatureStrategy(featureId, strategyDefinition)); setStrategy(createFeatureStrategy(featureId, strategyDefinition));
} }
}, [featureId, strategyDefinition, useDefaultStrategy]); }, [featureId, strategyDefinition, shouldUseDefaultStrategy]);
const onAddStrategy = async (payload: IFeatureStrategyPayload) => { const onAddStrategy = async (payload: IFeatureStrategyPayload) => {
await addStrategyToFeature( await addStrategyToFeature(