Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,10 @@ const updateAdjustmentPolicy = async (policy: AdjustmentPolicyData, idx: number)
await reportAdjustmentPolicyAPI.update(newPolicy);
}
const newOrder = idx + 1;
if (oldPolicy?.order !== newOrder) {
await reportAdjustmentPolicyAPI.changeOrder({
report_adjustment_policy_id: policy.id,
order: newOrder,
});
}
await reportAdjustmentPolicyAPI.changeOrder({
report_adjustment_policy_id: policy.id,
order: newOrder,
});
};
const deleteAdjustment = async (deletedPolicyIds: string[]) => {
const deletedAdjustmentIds: string[] = originalAdjustments.value
Expand Down Expand Up @@ -205,12 +203,10 @@ const updateAdjustment = async (adjustment: AdjustmentData, idx: number) => {
await reportAdjustmentAPI.update(newAdjustment);
}
const newOrder = idx + 1;
if (oldAdjustment?.order !== newOrder) {
await reportAdjustmentAPI.changeOrder({
report_adjustment_id: adjustment.id,
order: newOrder,
});
}
await reportAdjustmentAPI.changeOrder({
report_adjustment_id: adjustment.id,
order: newOrder,
});
};

/* Event */
Expand All @@ -222,27 +218,27 @@ const handleSave = async () => {
try {
// CUD Adjustment Policy
const deletedPolicyIds = await deleteAdjustmentPolicy();
const policyPromises = formPolicies.value.map(async (policy, idx) => {
await formPolicies.value.reduce(async (promise, policy, idx) => {
await promise;
if (policy.id.startsWith('rap-')) {
return updateAdjustmentPolicy(policy, idx);
}
return createAdjustmentPolicy(policy, idx);
});
await Promise.all(policyPromises);
}, Promise.resolve());

// CUD Adjustment
await deleteAdjustment(deletedPolicyIds);
const adjustmentPromises = formPolicies.value.flatMap(async (policy) => {
await formPolicies.value.reduce(async (promise, policy) => {
await promise;
const adjustments = formAdjustments.value.filter((adjustment) => adjustment.policyId === policy.id);
return adjustments.map(async (adjustment, idx) => {
return adjustments.reduce(async (adjPromise, adjustment, idx) => {
await adjPromise;
if (adjustment.id.startsWith('ra-')) {
return updateAdjustment(adjustment, idx);
}
return createAdjustment(adjustment, idx);
});
});
const resolvedAdjustments = await Promise.all(adjustmentPromises);
await Promise.all(resolvedAdjustments.flat());
}, Promise.resolve());
Comment on lines +221 to +240
Copy link

Copilot AI Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using reduce to iterate over adjustments for sequential promise resolution may obscure the intent; a for-of loop might provide clearer control flow, making the code easier to understand and maintain.

Copilot uses AI. Check for mistakes.
}, Promise.resolve());
Comment on lines +221 to +241
Copy link

Copilot AI Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using the reduce method for chaining promises can be less intuitive; consider using an explicit for-of loop for sequential processing to improve readability and maintainability.

Copilot uses AI. Check for mistakes.

showSuccessMessage(i18n.t('COST_EXPLORER.ADVANCED_SETTINGS.ALT_S_SAVE_COST_REPORT_ADJUSTMENTS'), '');
} catch (error) {
Expand Down
Loading