Skip to content

Commit

Permalink
feat: Use environment feature state instead of fetching feature states (
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Aug 12, 2024
1 parent 3c46a31 commit b1d49a6
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions frontend/common/stores/feature-list-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,6 @@ import { getFeatureStates } from 'common/services/useFeatureState'
import { getSegments } from 'common/services/useSegment'
let createdFirstFeature = false
const PAGE_SIZE = 50
function recursivePageGet(url, parentRes) {
return data.get(url).then((res) => {
let response
if (parentRes) {
response = {
...parentRes,
results: parentRes.results.concat(res.results),
}
} else {
response = res
}
if (res.next) {
return recursivePageGet(res.next, response)
}
return Promise.resolve(response)
})
}

const convertSegmentOverrideToFeatureState = (
override,
Expand Down Expand Up @@ -129,15 +112,15 @@ const controller = {
.then(() =>
Promise.all([
data.get(`${Project.api}projects/${projectId}/features/`),
data.get(
`${Project.api}environments/${environmentId}/featurestates/`,
),
]).then(([features, environmentFeatures]) => {
]).then(([features]) => {
const environmentFeatures = features.results.map((v) => ({
...v.environment_feature_state,
feature: v.id,
}))
store.model = {
features: features.results,
keyedEnvironmentFeatures:
environmentFeatures &&
_.keyBy(environmentFeatures.results, 'feature'),
environmentFeatures && _.keyBy(environmentFeatures, 'feature'),
}
store.model.lastSaved = new Date().valueOf()
store.saved({ createdFlag: flag.name })
Expand Down Expand Up @@ -863,16 +846,17 @@ const controller = {

return Promise.all([
data.get(featuresEndpoint),
recursivePageGet(
`${Project.api}environments/${environmentId}/featurestates/?page_size=${PAGE_SIZE}`,
),
feature
? data.get(
`${Project.api}projects/${projectId}/features/${feature}/`,
)
: Promise.resolve(),
])
.then(([features, environmentFeatures, feature]) => {
.then(([features, feature]) => {
const environmentFeatures = features.results.map((v) => ({
...v.environment_feature_state,
feature: v.id,
}))
if (store.filter !== filter) {
//The filter has been changed since, ignore the api response. This will be resolved when moving to RTK.
return
Expand Down Expand Up @@ -904,9 +888,10 @@ const controller = {

store.model = {
features: features.results.map(controller.parseFlag),
keyedEnvironmentFeatures:
environmentFeatures.results &&
_.keyBy(environmentFeatures.results, 'feature'),
keyedEnvironmentFeatures: _.keyBy(
environmentFeatures,
'feature',
),
}
store.loaded()
})
Expand Down

0 comments on commit b1d49a6

Please sign in to comment.