Skip to content

Commit

Permalink
feat: Scheduled segment overrides (#4805)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Dec 3, 2024
1 parent e17f92d commit bb7849c
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 89 deletions.
11 changes: 7 additions & 4 deletions frontend/web/components/base/forms/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,24 @@ export const Button: FC<ButtonType> = ({
const hasPlan = feature ? Utils.getPlansPermission(feature) : true
return href || !hasPlan ? (
<a
onClick={rest.onClick as React.MouseEventHandler}
onClick={!hasPlan ? undefined : (rest.onClick as React.MouseEventHandler)}
className={cn(className, themeClassNames[theme], sizeClassNames[size])}
target={target}
target={!hasPlan ? '_blank' : target}
href={hasPlan ? href : Constants.getUpgradeUrl()}
rel='noreferrer'
>
{!!iconLeft && (
{!!iconLeft && !!hasPlan && (
<Icon
fill={iconLeftColour ? Constants.colours[iconLeftColour] : undefined}
className='me-2'
name={iconLeft}
width={iconSize}
/>
)}
{children}
<div className='d-flex align-items-center gap-2'>
{children}
{!hasPlan && <PlanBasedBanner feature={feature} theme={'badge'} />}
</div>
{!!iconRight && (
<Icon
fill={
Expand Down
211 changes: 126 additions & 85 deletions frontend/web/components/modals/CreateFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,80 +957,87 @@ const CreateFlag = class extends Component {
this.save(editFeatureSettings, isSaving)
}

const saveFeatureSegments = saveFeatureWithValidation(() => {
this.setState({ segmentsChanged: false })
const saveFeatureSegments = saveFeatureWithValidation(
(schedule) => {
this.setState({ segmentsChanged: false })

if (is4Eyes && isVersioned && !identity) {
openModal2(
this.props.changeRequest
? 'Update Change Request'
: 'New Change Request',
<ChangeRequestModal
showAssignees={is4Eyes}
changeRequest={this.props.changeRequest}
onSave={({
approvals,
description,
live_from,
title,
}) => {
closeModal2()
this.save(
(
projectId,
environmentId,
flag,
projectFlag,
environmentFlag,
segmentOverrides,
) => {
createChangeRequest(
if ((is4Eyes || schedule) && isVersioned && !identity) {
openModal2(
this.props.changeRequest
? 'Update Change Request'
: schedule
? 'Schedule Segment Overrides Update'
: 'New Change Request',
<ChangeRequestModal
showAssignees={is4Eyes}
changeRequest={this.props.changeRequest}
onSave={({
approvals,
description,
live_from,
title,
}) => {
closeModal2()
this.save(
(
projectId,
environmentId,
flag,
projectFlag,
environmentFlag,
segmentOverrides,
{
approvals,
description,
featureStateId:
this.props.changeRequest &&
this.props.changeRequest.feature_states[0].id,
id:
this.props.changeRequest &&
this.props.changeRequest.id,
live_from,
multivariate_options: this.props
.multivariate_options
? this.props.multivariate_options.map((v) => {
const matching =
this.state.multivariate_options.find(
(m) =>
m.id ===
v.multivariate_feature_option,
)
return {
...v,
percentage_allocation:
matching.default_percentage_allocation,
}
})
: this.state.multivariate_options,
title,
},
!is4Eyes,
'SEGMENT',
)
},
)
}}
/>,
)
} else {
this.save(editFeatureSegments, isSaving)
}
})
) => {
createChangeRequest(
projectId,
environmentId,
flag,
projectFlag,
environmentFlag,
segmentOverrides,
{
approvals,
description,
featureStateId:
this.props.changeRequest &&
this.props.changeRequest.feature_states[0]
.id,
id:
this.props.changeRequest &&
this.props.changeRequest.id,
live_from,
multivariate_options: this.props
.multivariate_options
? this.props.multivariate_options.map(
(v) => {
const matching =
this.state.multivariate_options.find(
(m) =>
m.id ===
v.multivariate_feature_option,
)
return {
...v,
percentage_allocation:
matching.default_percentage_allocation,
}
},
)
: this.state.multivariate_options,
title,
},
!is4Eyes,
'SEGMENT',
)
},
)
}}
/>,
)
} else {
this.save(editFeatureSegments, isSaving)
}
},
)

const onCreateFeature = saveFeatureWithValidation(() => {
this.save(createFlag, isSaving)
Expand Down Expand Up @@ -1485,24 +1492,58 @@ const CreateFlag = class extends Component {
Constants.environmentPermissions(
'Manage segment overrides',
),
<Button
onClick={
saveFeatureSegments
}
type='button'
data-test='update-feature-segments-btn'
id='update-feature-segments-btn'
disabled={
isSaving ||
!name ||
invalid ||
!manageSegmentsOverrides
}
>
{isSaving
? 'Updating'
: 'Update Segment Overrides'}
</Button>,
<>
{!is4Eyes &&
isVersioned && (
<>
<Button
feature='SCHEDULE_FLAGS'
theme='secondary'
onClick={() =>
saveFeatureSegments(
true,
)
}
className='mr-2'
type='button'
data-test='create-change-request'
id='create-change-request-btn'
disabled={
isSaving ||
!name ||
invalid ||
!savePermission
}
>
{isSaving
? existingChangeRequest
? 'Updating Change Request'
: 'Scheduling Update'
: existingChangeRequest
? 'Update Change Request'
: 'Schedule Update'}
</Button>
</>
)}
<Button
onClick={
saveFeatureSegments
}
type='button'
data-test='update-feature-segments-btn'
id='update-feature-segments-btn'
disabled={
isSaving ||
!name ||
invalid ||
!manageSegmentsOverrides
}
>
{isSaving
? 'Updating'
: 'Update Segment Overrides'}
</Button>
</>,
)
}}
</Permission>
Expand Down

0 comments on commit bb7849c

Please sign in to comment.