1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

fix: add strategy bug when strategySplittedButton flag is on (#4071)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

Fixes 2 bugs after the recent strategy improvements v2 changes:
- When creating a strategy the `groupId` param of the Gradual Rollout
strategy now populates the groupId (when using default strategy, the
groupId will only be overwritten when it is an empty string ) with the
feature name (as it was before)

- When editing/setting a default strategy for an environment the
`groupId` param should be an empty string, but editable.

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
andreas-unleash 2023-06-23 10:31:29 +03:00 committed by GitHub
parent 175b103b12
commit c81de4a5bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

@ -33,7 +33,7 @@ import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
import useQueryParams from 'hooks/useQueryParams';
import useProject from 'hooks/api/getters/useProject/useProject';
import { useSegments } from 'hooks/api/getters/useSegments/useSegments';
import { DEFAULT_STRATEGY } from '../../../project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/EditDefaultStrategy';
import { DEFAULT_STRATEGY } from 'component/project/Project/ProjectSettings/ProjectDefaultStrategySettings/ProjectEnvironment/ProjectEnvironmentDefaultStrategy/EditDefaultStrategy';
export const FeatureStrategyCreate = () => {
const projectId = useRequiredPathParam('projectId');
@ -101,11 +101,19 @@ export const FeatureStrategyCreate = () => {
useEffect(() => {
if (shouldUseDefaultStrategy) {
setStrategy((defaultStrategy as any) || DEFAULT_STRATEGY);
const strategyTemplate = defaultStrategy || DEFAULT_STRATEGY;
if (strategyTemplate.parameters?.groupId === '' && featureId) {
strategyTemplate.parameters.groupId = featureId;
}
setStrategy(strategyTemplate as any);
} else if (strategyDefinition) {
setStrategy(createFeatureStrategy(featureId, strategyDefinition));
}
}, [featureId, strategyDefinition, shouldUseDefaultStrategy]);
}, [
featureId,
JSON.stringify(strategyDefinition),
shouldUseDefaultStrategy,
]);
const onAddStrategy = async (payload: IFeatureStrategyPayload) => {
await addStrategyToFeature(

View File

@ -14,8 +14,9 @@ import {
import { StickinessSelect } from './StickinessSelect/StickinessSelect';
import { useDefaultProjectSettings } from 'hooks/useDefaultProjectSettings';
import Loader from '../../../common/Loader/Loader';
import { useMemo } from 'react';
import { useEffect, useMemo } from 'react';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
import { useLocation } from 'react-router';
interface IFlexibleStrategyProps {
parameters: IFeatureStrategyParameters;
@ -31,7 +32,9 @@ const FlexibleStrategy = ({
}: IFlexibleStrategyProps) => {
const projectId = useRequiredPathParam('projectId');
const { defaultStickiness, loading } = useDefaultProjectSettings(projectId);
const { pathname } = useLocation();
const isDefaultStrategyEdit = pathname.includes('default-strategy');
const onUpdate = (field: string) => (newValue: string) => {
updateParameter(field, newValue);
};
@ -57,6 +60,12 @@ const FlexibleStrategy = ({
onUpdate('stickiness')(stickiness);
}
useEffect(() => {
if (isDefaultStrategyEdit) {
onUpdate('groupId')('');
}
}, [isDefaultStrategyEdit]);
if (loading) {
return <Loader />;
}