Skip to content

Commit

Permalink
fix: Removing segment overrides whilst adding others (#4709)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Oct 23, 2024
1 parent 3e5e265 commit 05f2bca
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions frontend/common/stores/feature-list-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ const convertSegmentOverrideToFeatureState = (
feature_state_value: override.value,
id: override.id,
live_from: changeRequest?.live_from,
multivariate_feature_state_values:
override.multivariate_options,
multivariate_feature_state_values: override.multivariate_options,
toRemove: override.toRemove,
} as Partial<FeatureState>
}
Expand Down Expand Up @@ -115,7 +114,13 @@ const controller = {
})
.then(() =>
Promise.all([
data.get(`${Project.api}projects/${projectId}/features/?environment=${ProjectStore.getEnvironmentIdFromKey(environmentId)}`),
data.get(
`${
Project.api
}projects/${projectId}/features/?environment=${ProjectStore.getEnvironmentIdFromKey(
environmentId,
)}`,
),
]).then(([features]) => {
const environmentFeatures = features.results.map((v) => ({
...v.environment_feature_state,
Expand Down Expand Up @@ -258,13 +263,9 @@ const controller = {
const segmentOverridesProm = (segmentOverrides || [])
.map((v, i) => () => {
if (v.toRemove) {
return (
v.id
? data.delete(`${Project.api}features/feature-segments/${v.id}/`)
: Promise.resolve()
).then(() => {
segmentOverrides = segmentOverrides.filter((s) => v.id !== s.id)
})
return v.id
? data.delete(`${Project.api}features/feature-segments/${v.id}/`)
: Promise.resolve()
}
if (!v.id) {
const featureFlagId = v.feature
Expand Down Expand Up @@ -328,6 +329,9 @@ const controller = {
API.trackEvent(Constants.events.EDIT_FEATURE)
segmentOverridesProm
.then(() => {
segmentOverrides = segmentOverrides?.filter?.(
(override) => !override.toRemove,
)
if (mode !== 'VALUE') {
prom = Promise.resolve()
} else if (environmentFlag) {
Expand Down Expand Up @@ -860,7 +864,9 @@ const controller = {
? page
: `${Project.api}projects/${projectId}/features/?page=${
page || 1
}&environment=${environment}&page_size=${pageSize || PAGE_SIZE}${filterUrl}`
}&environment=${environment}&page_size=${
pageSize || PAGE_SIZE
}${filterUrl}`
if (store.search) {
featuresEndpoint += `&search=${store.search}`
}
Expand Down Expand Up @@ -959,7 +965,7 @@ const controller = {
},
searchFeatures: _.throttle(
(search, environmentId, projectId, filter, pageSize) => {
store.search = encodeURIComponent(search||'')
store.search = encodeURIComponent(search || '')
controller.getFeatures(
projectId,
environmentId,
Expand Down

0 comments on commit 05f2bca

Please sign in to comment.