Skip to content

Commit

Permalink
fix: project settings flag limit not properly set (#5317)
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
nunogois committed Nov 10, 2023
1 parent 180c0dc commit 15f77f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
26 changes: 12 additions & 14 deletions frontend/src/component/project/Project/ProjectForm/ProjectForm.tsx
Expand Up @@ -184,8 +184,8 @@ const ProjectForm: React.FC<IProjectForm> = ({
}
/>
<ConditionallyRender
condition={mode === 'Edit' && Boolean(setFeatureLimit)}
show={
condition={mode === 'Edit'}
show={() => (
<>
<Box
sx={{
Expand All @@ -202,17 +202,15 @@ const ProjectForm: React.FC<IProjectForm> = ({
Leave it empty if you don’t want to add a limit
</StyledSubtitle>
<StyledInputContainer>
{featureLimit && setFeatureLimit && (
<StyledInput
label={'Limit'}
name='value'
type={'number'}
value={featureLimit}
onChange={(e) =>
setFeatureLimit(e.target.value)
}
/>
)}
<StyledInput
label={'Limit'}
name='value'
type={'number'}
value={featureLimit!}
onChange={(e) =>
setFeatureLimit!(e.target.value)
}
/>
<ConditionallyRender
condition={
featureCount !== undefined &&
Expand All @@ -226,7 +224,7 @@ const ProjectForm: React.FC<IProjectForm> = ({
/>
</StyledInputContainer>
</>
}
)}
/>
<ConditionallyRender
condition={mode === 'Create' && isEnterprise()}
Expand Down
Expand Up @@ -82,7 +82,7 @@ const useProjectForm = (

const getFeatureLimitAsNumber = () => {
if (featureLimit === '') {
return undefined;
return null;
}
return Number(featureLimit);
};
Expand Down
4 changes: 3 additions & 1 deletion src/lib/db/project-store.ts
Expand Up @@ -244,8 +244,9 @@ class ProjectStore implements IProjectStore {
const settingsRow = await this.db(SETTINGS_TABLE)
.insert({
project: project.id,
project_mode: project.mode,
default_stickiness: project.defaultStickiness,
feature_limit: project.featureLimit,
project_mode: project.mode,
})
.returning('*');
return this.mapRow({ ...row[0], ...settingsRow[0] });
Expand All @@ -265,6 +266,7 @@ class ProjectStore implements IProjectStore {
await this.db(TABLE)
.where({ id: data.id })
.update(this.fieldToRow(data));

if (
data.defaultStickiness !== undefined ||
data.featureLimit !== undefined
Expand Down

0 comments on commit 15f77f5

Please sign in to comment.