From e6aa4bdbd6dbfe6546e00056962bedeb1d5cea4c Mon Sep 17 00:00:00 2001 From: kyle-ssg Date: Fri, 3 May 2024 11:19:45 +0100 Subject: [PATCH] update feature segment priorities when creating a version --- frontend/common/services/useFeatureVersion.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/frontend/common/services/useFeatureVersion.ts b/frontend/common/services/useFeatureVersion.ts index 625d93a29fda..bb08e7185a86 100644 --- a/frontend/common/services/useFeatureVersion.ts +++ b/frontend/common/services/useFeatureVersion.ts @@ -10,6 +10,7 @@ import { import { deleteFeatureSegment } from './useFeatureSegment' import transformCorePaging from 'common/transformCorePaging' import Utils from 'common/utils/utils' +import { updateSegmentPriorities } from './useSegmentPriority' export const featureVersionService = service .enhanceEndpoints({ addTagTypes: ['FeatureVersion'] }) @@ -34,9 +35,28 @@ export const featureVersionService = service featureId: query.featureId, sha: versionRes.data.uuid, }) + + //Step 3: Update feature segment priorities before saving feature states + const prioritiesToUpdate = query.featureStates + .filter((v) => !v.toRemove && !!v.feature_segment) + .map((v) => { + const matchingFeatureSegment = currentFeatureStates?.data?.find( + (currentFeatureState) => + v.feature_segment?.segment === + currentFeatureState.feature_segment?.segment, + ) + return { + id: matchingFeatureSegment!.feature_segment!.id!, + priority: v.feature_segment!.priority, + } + }) + if (prioritiesToUpdate.length) { + await updateSegmentPriorities(getStore(), prioritiesToUpdate) + } + const res = await Promise.all( query.featureStates.map((featureState) => { - // Step 3: update, create or delete feature states from the new version + // Step 4: update, create or delete feature states from the new version const matchingVersionState = currentFeatureStates.data.find( (feature) => { return ( @@ -117,7 +137,8 @@ export const featureVersionService = service })), error: res.find((v) => !!v.error)?.error, } - // Step 4: Publish the feature version + + // Step 5: Publish the feature version if (!query.skipPublish) { await publishFeatureVersion(getStore(), { environmentId: query.environmentId,