mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									26a1156959
								
							
						
					
					
						commit
						a0e4f08507
					
				| @ -24,14 +24,6 @@ const useFeatureStrategyApi = () => { | ||||
|         environmentId: string, | ||||
|         payload: IFeatureStrategyPayload, | ||||
|     ): Promise<IFeatureStrategy> => { | ||||
|         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<void> => { | ||||
|         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 ( | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user