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

fix: default strategy screen not loading when no default strategy (#3840)

<!-- 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>
This commit is contained in:
andreas-unleash 2023-05-23 15:34:37 +03:00 committed by GitHub
parent f7006642a6
commit 2a3f743daa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,15 @@ import { ProjectDefaultStrategyForm } from './ProjectDefaultStrategyForm';
import { CreateFeatureStrategySchema } from 'openapi'; import { CreateFeatureStrategySchema } from 'openapi';
import useProject from 'hooks/api/getters/useProject/useProject'; import useProject from 'hooks/api/getters/useProject/useProject';
const DEFAULT_STRATEGY = {
name: 'flexibleRollout',
constraints: [],
parameters: {
rollout: '100%',
stickiness: 'default',
groupId: '',
},
};
const EditDefaultStrategy = () => { const EditDefaultStrategy = () => {
const projectId = useRequiredPathParam('projectId'); const projectId = useRequiredPathParam('projectId');
const environmentId = useRequiredQueryParam('environmentId'); const environmentId = useRequiredQueryParam('environmentId');
@ -32,11 +41,11 @@ const EditDefaultStrategy = () => {
const [defaultStrategy, setDefaultStrategy] = useState< const [defaultStrategy, setDefaultStrategy] = useState<
CreateFeatureStrategySchema | undefined CreateFeatureStrategySchema | undefined
>(strategy); >(strategy || DEFAULT_STRATEGY);
const [segments, setSegments] = useState<ISegment[]>([]); const [segments, setSegments] = useState<ISegment[]>([]);
const { updateDefaultStrategy, loading } = useProjectApi(); const { updateDefaultStrategy, loading } = useProjectApi();
const { strategyDefinition } = useStrategy(strategy?.name); const { strategyDefinition } = useStrategy(defaultStrategy?.name);
const { setToastData, setToastApiError } = useToast(); const { setToastData, setToastApiError } = useToast();
const errors = useFormErrors(); const errors = useFormErrors();
const { uiConfig } = useUiConfig(); const { uiConfig } = useUiConfig();
@ -105,11 +114,10 @@ const EditDefaultStrategy = () => {
} }
if (!defaultStrategy) return null; if (!defaultStrategy) return null;
return ( return (
<FormTemplate <FormTemplate
modal modal
title={formatStrategyName(strategy?.name ?? '')} title={formatStrategyName(defaultStrategy?.name ?? '')}
description={projectDefaultStrategyHelp} description={projectDefaultStrategyHelp}
documentationLink={projectDefaultStrategyDocsLink} documentationLink={projectDefaultStrategyDocsLink}
documentationLinkLabel={projectDefaultStrategyDocsLinkLabel} documentationLinkLabel={projectDefaultStrategyDocsLinkLabel}