-
Notifications
You must be signed in to change notification settings - Fork 466
feat: edit versioned change request #6368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: chore/create-flag-migration
Are you sure you want to change the base?
Changes from all commits
924424f
1eccdea
76f0d4a
1b6e719
1316759
bd1c041
c8e5429
7cf7c8b
6f090f5
0a90074
3a47014
1dd143b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ import { useGetMyGroupsQuery } from 'common/services/useMyGroup' | |
| import CreateFeatureModal from 'components/modals/create-feature' | ||
| import AccountStore from 'common/stores/account-store' | ||
| import AppActions from 'common/dispatcher/app-actions' | ||
| import { mergeChangeSets } from 'common/services/useChangeRequest' | ||
| import { getFeatureStates } from 'common/services/useFeatureState' | ||
| import { getStore } from 'common/store' | ||
| import { | ||
| ChangeRequest, | ||
| Environment, | ||
|
|
@@ -156,29 +159,67 @@ const ChangeRequestDetailPage: FC<ChangeRequestPageType> = ({ match }) => { | |
| }) | ||
| } | ||
|
|
||
| const editChangeRequest = ( | ||
| const editChangeRequest = async ( | ||
| projectFlag: ProjectFlag, | ||
| environmentFlag: FeatureState, | ||
| ) => { | ||
| if (!changeRequest) return | ||
|
|
||
| const environment: Environment = ProjectStore.getEnvironment( | ||
| environmentId, | ||
| ) as any | ||
|
|
||
| const isVersioned = !!environment?.use_v2_feature_versioning | ||
| let changedEnvironmentFlag = environmentFlag | ||
|
|
||
| if (isVersioned && changeRequest.change_sets) { | ||
| // Convert the changesets into a feature state | ||
| const currentFeatureStatesResponse = await getFeatureStates(getStore(), { | ||
| environment: environment.id, | ||
| feature: projectFlag.id, | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
| const mergedStates = mergeChangeSets( | ||
| changeRequest.change_sets, | ||
| currentFeatureStatesResponse.data.results, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Missing null check causes crash when API call failsThe |
||
| changeRequest.conflicts, | ||
| ) | ||
| const mergedEnvFlag = mergedStates.find( | ||
| (v) => !v.feature_segment?.segment, | ||
| ) | ||
| if (mergedEnvFlag) { | ||
| changedEnvironmentFlag = { | ||
| ...environmentFlag, | ||
| ...mergedEnvFlag, | ||
| feature_state_value: Utils.featureStateToValue( | ||
| mergedEnvFlag.feature_state_value, | ||
| ), | ||
| } | ||
| } | ||
| } else if (!isVersioned && changeRequest.feature_states?.[0]) { | ||
| changedEnvironmentFlag = { | ||
| ...environmentFlag, | ||
| enabled: changeRequest.feature_states[0].enabled, | ||
| feature_state_value: Utils.featureStateToValue( | ||
| changeRequest.feature_states[0].feature_state_value, | ||
| ), | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Legacy change requests ignored in versioned environmentsThe condition logic creates a gap for legacy change requests. The first branch requires |
||
|
|
||
| openModal( | ||
| 'Edit Change Request', | ||
| <CreateFeatureModal | ||
| history={history} | ||
| environmentId={environmentId} | ||
| projectId={projectId} | ||
| schangeRequest={changeRequest} | ||
| changeRequest={changeRequest} | ||
| projectFlag={projectFlag} | ||
| environmentFlag={changedEnvironmentFlag} | ||
| multivariate_options={ | ||
| changeRequest.feature_states[0].multivariate_feature_state_values | ||
| !isVersioned | ||
| ? changeRequest.feature_states?.[0] | ||
| ?.multivariate_feature_state_values | ||
| : undefined | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Versioned CR edit loses multivariate allocation valuesWhen editing a versioned change request, Additional Locations (1) |
||
| environmentFlag={{ | ||
| ...environmentFlag, | ||
| enabled: changeRequest.feature_states[0].enabled, | ||
| feature_state_value: Utils.featureStateToValue( | ||
| changeRequest.feature_states[0].feature_state_value, | ||
| ), | ||
| }} | ||
| flagId={environmentFlag.id} | ||
| />, | ||
| 'side-modal create-feature-modal', | ||
|
|
@@ -310,7 +351,7 @@ const ChangeRequestDetailPage: FC<ChangeRequestPageType> = ({ match }) => { | |
| scheduledDate={getChangeRequestLiveDate(changeRequest)} | ||
| deleteChangeRequest={deleteChangeRequest} | ||
| editChangeRequest={ | ||
| !isVersioned && !changeRequest?.committed_at | ||
| !changeRequest?.committed_at | ||
| ? () => editChangeRequest(projectFlag, environmentFlag) | ||
| : undefined | ||
| } | ||
|
|
@@ -494,12 +535,13 @@ export const ChangeRequestPageInner: FC<ChangeRequestPageInnerType> = ({ | |
| changeRequest && | ||
| changeRequest.user && | ||
| orgUsers.find((v) => v.id === changeRequest.user) | ||
|
|
||
| const isYours = AccountStore.getUserId() === changeRequest.user | ||
| return ( | ||
| <div> | ||
| <PageTitle | ||
| cta={ | ||
| (!changeRequest.committed_at || isScheduled) && ( | ||
| (!changeRequest.committed_at || isScheduled) && | ||
| isYours && ( | ||
| <Row> | ||
| <Button theme='secondary' onClick={deleteChangeRequest}> | ||
| Delete | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Segment override priorities from changeset are discarded
When editing a versioned change request, segment override priorities from the changeset are set at lines 119 and 166 (
priority: changedFeatureState.feature_segment?.priority || 0), but then immediately overwritten with array indices at lines 185-189. Since the save function atcreate-feature/index.js:604uses the top-levelpriorityproperty forfeature_segment.priority, any priority reordering specified in the original change request will be lost when the edit is saved. The segments also remain in the current live order rather than being sorted by the changeset's intended priorities.Additional Locations (1)
frontend/common/providers/withSegmentOverrides.js#L118-L119