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:
parent
26a1156959
commit
a0e4f08507
@ -24,14 +24,6 @@ const useFeatureStrategyApi = () => {
|
|||||||
environmentId: string,
|
environmentId: string,
|
||||||
payload: IFeatureStrategyPayload,
|
payload: IFeatureStrategyPayload,
|
||||||
): Promise<IFeatureStrategy> => {
|
): 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 (addEditStrategyEnabled) {
|
||||||
if (payload.constraints && payload.constraints.length > 0) {
|
if (payload.constraints && payload.constraints.length > 0) {
|
||||||
addToRecentlyUsedConstraints(payload.constraints);
|
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();
|
return result.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -67,14 +67,6 @@ const useFeatureStrategyApi = () => {
|
|||||||
strategyId: string,
|
strategyId: string,
|
||||||
payload: IFeatureStrategyPayload,
|
payload: IFeatureStrategyPayload,
|
||||||
): Promise<void> => {
|
): 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 (addEditStrategyEnabled) {
|
||||||
if (payload.constraints && payload.constraints.length > 0) {
|
if (payload.constraints && payload.constraints.length > 0) {
|
||||||
addToRecentlyUsedConstraints(payload.constraints);
|
addToRecentlyUsedConstraints(payload.constraints);
|
||||||
@ -84,6 +76,14 @@ const useFeatureStrategyApi = () => {
|
|||||||
addToRecentlyUsedSegments(payload.segments);
|
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 (
|
const setStrategiesSortOrder = async (
|
||||||
|
Loading…
Reference in New Issue
Block a user