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

fix: project settings flag limit not properly set (#5317)

https://linear.app/unleash/issue/SR-169/ticket-1107-project-feature-flag-limit-is-not-correctly-updated

Fixes #5315, an issue where it would not be possible to set an empty
flag limit.
This also fixes the UI behavior: Before, when the flag limit field was
emptied, it would disappear from the UI.

I'm a bit unsure of the original intent of the `(data.defaultStickiness
!== undefined || data.featureLimit !== undefined)` condition. We're in
an update method, triggered by a PUT endpoint - I think it's safe to
assume that we'll always want to set these values to whatever they come
as, we just need to convert them to `null` in case they are not present
(i.e. `undefined`).
This commit is contained in:
Nuno Góis 2023-11-10 09:57:20 +00:00 committed by GitHub
parent 180c0dceae
commit 15f77f5b8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 16 deletions

View File

@ -184,8 +184,8 @@ const ProjectForm: React.FC<IProjectForm> = ({
} }
/> />
<ConditionallyRender <ConditionallyRender
condition={mode === 'Edit' && Boolean(setFeatureLimit)} condition={mode === 'Edit'}
show={ show={() => (
<> <>
<Box <Box
sx={{ sx={{
@ -202,17 +202,15 @@ const ProjectForm: React.FC<IProjectForm> = ({
Leave it empty if you dont want to add a limit Leave it empty if you dont want to add a limit
</StyledSubtitle> </StyledSubtitle>
<StyledInputContainer> <StyledInputContainer>
{featureLimit && setFeatureLimit && (
<StyledInput <StyledInput
label={'Limit'} label={'Limit'}
name='value' name='value'
type={'number'} type={'number'}
value={featureLimit} value={featureLimit!}
onChange={(e) => onChange={(e) =>
setFeatureLimit(e.target.value) setFeatureLimit!(e.target.value)
} }
/> />
)}
<ConditionallyRender <ConditionallyRender
condition={ condition={
featureCount !== undefined && featureCount !== undefined &&
@ -226,7 +224,7 @@ const ProjectForm: React.FC<IProjectForm> = ({
/> />
</StyledInputContainer> </StyledInputContainer>
</> </>
} )}
/> />
<ConditionallyRender <ConditionallyRender
condition={mode === 'Create' && isEnterprise()} condition={mode === 'Create' && isEnterprise()}

View File

@ -82,7 +82,7 @@ const useProjectForm = (
const getFeatureLimitAsNumber = () => { const getFeatureLimitAsNumber = () => {
if (featureLimit === '') { if (featureLimit === '') {
return undefined; return null;
} }
return Number(featureLimit); return Number(featureLimit);
}; };

View File

@ -244,8 +244,9 @@ class ProjectStore implements IProjectStore {
const settingsRow = await this.db(SETTINGS_TABLE) const settingsRow = await this.db(SETTINGS_TABLE)
.insert({ .insert({
project: project.id, project: project.id,
project_mode: project.mode,
default_stickiness: project.defaultStickiness, default_stickiness: project.defaultStickiness,
feature_limit: project.featureLimit,
project_mode: project.mode,
}) })
.returning('*'); .returning('*');
return this.mapRow({ ...row[0], ...settingsRow[0] }); return this.mapRow({ ...row[0], ...settingsRow[0] });
@ -265,6 +266,7 @@ class ProjectStore implements IProjectStore {
await this.db(TABLE) await this.db(TABLE)
.where({ id: data.id }) .where({ id: data.id })
.update(this.fieldToRow(data)); .update(this.fieldToRow(data));
if ( if (
data.defaultStickiness !== undefined || data.defaultStickiness !== undefined ||
data.featureLimit !== undefined data.featureLimit !== undefined