From 32137bbec3e5a0c89e4803ca15368da71c3525bc Mon Sep 17 00:00:00 2001 From: Krishna Gupta Date: Wed, 12 Jun 2024 12:41:45 +0530 Subject: [PATCH] fix: Distance rates - Order of distance rates is not preserved after clearing cache and restarting. Signed-off-by: Krishna Gupta --- .../distanceRates/PolicyDistanceRatesPage.tsx | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx b/src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx index e659750754a1..da5fbb777306 100644 --- a/src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx +++ b/src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx @@ -100,18 +100,20 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps) const distanceRatesList = useMemo( () => - Object.values(customUnitRates).map((value) => ({ - value: value.customUnitRateID ?? '', - text: `${CurrencyUtils.convertAmountToDisplayString(value.rate, value.currency ?? CONST.CURRENCY.USD)} / ${translate( - `common.${customUnit?.attributes?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES}`, - )}`, - keyForList: value.customUnitRateID ?? '', - isSelected: selectedDistanceRates.find((rate) => rate.customUnitRateID === value.customUnitRateID) !== undefined, - isDisabled: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, - pendingAction: value.pendingAction ?? value.pendingFields?.rate ?? value.pendingFields?.enabled ?? value.pendingFields?.currency, - errors: value.errors ?? undefined, - rightElement: , - })), + Object.values(customUnitRates) + .sort((rateA, rateB) => (rateA?.rate ?? 0) - (rateB?.rate ?? 0)) + .map((value) => ({ + value: value.customUnitRateID ?? '', + text: `${CurrencyUtils.convertAmountToDisplayString(value.rate, value.currency ?? CONST.CURRENCY.USD)} / ${translate( + `common.${customUnit?.attributes?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES}`, + )}`, + keyForList: value.customUnitRateID ?? '', + isSelected: selectedDistanceRates.find((rate) => rate.customUnitRateID === value.customUnitRateID) !== undefined, + isDisabled: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, + pendingAction: value.pendingAction ?? value.pendingFields?.rate ?? value.pendingFields?.enabled ?? value.pendingFields?.currency, + errors: value.errors ?? undefined, + rightElement: , + })), [customUnit?.attributes?.unit, customUnitRates, selectedDistanceRates, translate], );