Skip to content

Commit

Permalink
fix: Distance rates - Order of distance rates is not preserved after …
Browse files Browse the repository at this point in the history
…clearing cache and restarting.

Signed-off-by: Krishna Gupta <[email protected]>
  • Loading branch information
Krishna2323 committed Jun 12, 2024
1 parent 8d11d0b commit 32137bb
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,20 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps)

const distanceRatesList = useMemo<RateForList[]>(
() =>
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: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
})),
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: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
})),
[customUnit?.attributes?.unit, customUnitRates, selectedDistanceRates, translate],
);

Expand Down

0 comments on commit 32137bb

Please sign in to comment.