Skip to content

Commit

Permalink
fix: default strategy screen not loading when no default strategy (#3840
Browse files Browse the repository at this point in the history
)

<!-- 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 a bug where default strategy would not edit 
## 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 # 1-953

<!-- (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>
  • Loading branch information
andreas-unleash committed May 23, 2023
1 parent f700664 commit 2a3f743
Showing 1 changed file with 12 additions and 4 deletions.
Expand Up @@ -20,6 +20,15 @@ import { ProjectDefaultStrategyForm } from './ProjectDefaultStrategyForm';
import { CreateFeatureStrategySchema } from 'openapi';
import useProject from 'hooks/api/getters/useProject/useProject';

const DEFAULT_STRATEGY = {
name: 'flexibleRollout',
constraints: [],
parameters: {
rollout: '100%',
stickiness: 'default',
groupId: '',
},
};
const EditDefaultStrategy = () => {
const projectId = useRequiredPathParam('projectId');
const environmentId = useRequiredQueryParam('environmentId');
Expand All @@ -32,11 +41,11 @@ const EditDefaultStrategy = () => {

const [defaultStrategy, setDefaultStrategy] = useState<
CreateFeatureStrategySchema | undefined
>(strategy);
>(strategy || DEFAULT_STRATEGY);

const [segments, setSegments] = useState<ISegment[]>([]);
const { updateDefaultStrategy, loading } = useProjectApi();
const { strategyDefinition } = useStrategy(strategy?.name);
const { strategyDefinition } = useStrategy(defaultStrategy?.name);
const { setToastData, setToastApiError } = useToast();
const errors = useFormErrors();
const { uiConfig } = useUiConfig();
Expand Down Expand Up @@ -105,11 +114,10 @@ const EditDefaultStrategy = () => {
}

if (!defaultStrategy) return null;

return (
<FormTemplate
modal
title={formatStrategyName(strategy?.name ?? '')}
title={formatStrategyName(defaultStrategy?.name ?? '')}
description={projectDefaultStrategyHelp}
documentationLink={projectDefaultStrategyDocsLink}
documentationLinkLabel={projectDefaultStrategyDocsLinkLabel}
Expand Down

0 comments on commit 2a3f743

Please sign in to comment.