From a0e4f085070ddf6cec94e12fdbecd0d7d17c208d Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Wed, 14 May 2025 15:01:11 +0300 Subject: [PATCH] feat: now updating strategy also saves recents (#9990) The issue was that processing constraints after the API call in updateStrategyOnFeature caused React's state updates to be interrupted before they could be persisted to localStorage, but by moving that processing before the API call, we ensure constraints are saved immediately, regardless of API timing. --- .../useFeatureStrategyApi.ts | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/frontend/src/hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi.ts b/frontend/src/hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi.ts index de1f54aa7c..7df2521bf7 100644 --- a/frontend/src/hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi.ts +++ b/frontend/src/hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi.ts @@ -24,14 +24,6 @@ const useFeatureStrategyApi = () => { environmentId: string, payload: IFeatureStrategyPayload, ): Promise => { - const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies`; - const req = createRequest( - path, - { method: 'POST', body: JSON.stringify(payload) }, - 'addStrategyToFeature', - ); - const result = await makeRequest(req.caller, req.id); - if (addEditStrategyEnabled) { if (payload.constraints && payload.constraints.length > 0) { addToRecentlyUsedConstraints(payload.constraints); @@ -42,6 +34,14 @@ const useFeatureStrategyApi = () => { } } + const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies`; + const req = createRequest( + path, + { method: 'POST', body: JSON.stringify(payload) }, + 'addStrategyToFeature', + ); + const result = await makeRequest(req.caller, req.id); + return result.json(); }; @@ -67,14 +67,6 @@ const useFeatureStrategyApi = () => { strategyId: string, payload: IFeatureStrategyPayload, ): Promise => { - const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies/${strategyId}`; - const req = createRequest( - path, - { method: 'PUT', body: JSON.stringify(payload) }, - 'updateStrategyOnFeature', - ); - await makeRequest(req.caller, req.id); - if (addEditStrategyEnabled) { if (payload.constraints && payload.constraints.length > 0) { addToRecentlyUsedConstraints(payload.constraints); @@ -84,6 +76,14 @@ const useFeatureStrategyApi = () => { addToRecentlyUsedSegments(payload.segments); } } + + const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies/${strategyId}`; + const req = createRequest( + path, + { method: 'PUT', body: JSON.stringify(payload) }, + 'updateStrategyOnFeature', + ); + await makeRequest(req.caller, req.id); }; const setStrategiesSortOrder = async (