1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-27 01:19:00 +02: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:
Jaanus Sellin 2025-05-14 15:01:11 +03:00 committed by GitHub
parent 26a1156959
commit a0e4f08507
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 (