-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Refactor: migrate getRate to use usePersonalPolicy hook (part 5) #95334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,6 +210,7 @@ function useReportSelectionActions({ | |
| transactions: targetTransactions, | ||
| allTransactionViolation: transactionViolations, | ||
| allReports, | ||
| personalPolicyOutputCurrency: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${personalPolicyID}`]?.outputCurrency, | ||
|
shubham1206agra marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Inconsistency: hook vs. raw collection lookup for the same value (assuming this was missed, and not planned in upcoming PRs) Most call sites use the personalPolicyOutputCurrency: personalPolicy?.outputCurrency,But personalPolicyOutputCurrency: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${personalPolicyID}`]?.outputCurrency,Why it matters: The whole point of the series is to standardize on Since |
||
| }); | ||
| removeTransaction(transaction.transactionID); | ||
| } | ||
|
|
@@ -234,6 +235,7 @@ function useReportSelectionActions({ | |
| transactions: targetTransactions, | ||
| allTransactionViolation: transactionViolations, | ||
| allReports, | ||
| personalPolicyOutputCurrency: allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${personalPolicyID}`]?.outputCurrency, | ||
| }); | ||
| removeTransaction(transaction.transactionID); | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,6 +147,8 @@ function IOURequestStepUpgrade({ | |
| transactions, | ||
| allTransactionViolation: transactionViolations, | ||
| allReports, | ||
| // Expenses move to the upgraded workspace (newPolicy), whose currency drives any distance calculation, so the personal-policy currency is never read here. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 The comment says the personal currency is "never read here," but that only holds if Why it matters: Behavior is still safe (it degrades to the same fallback that existed pre‑refactor), so there's no regression. But the comment overstates the guarantee. Suggest softening to:
Documentation accuracy only — no code change required. |
||
| personalPolicyOutputCurrency: undefined, | ||
| }); | ||
|
|
||
| clearSelectedTransactions(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,14 +38,15 @@ import getOnyxValue from '../utils/getOnyxValue'; | |
| import {getGlobalFetchMock, getOnyxData} from '../utils/TestHelper'; | ||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 Test coverage gap: the new parameter's behavior is not asserted Both test wrappers were updated to accept and forward the param, but they make it optional and every existing test leaves it // tests/unit/TransactionTest.ts:39-45
personalPolicyOutputCurrency?: string;
function changeTransactionsReport({..., personalPolicyOutputCurrency, ...rest}) {
changeTransactionsReportAction({..., personalPolicyOutputCurrency, ...rest});
}I grepped both suites: there is no test that passes a non‑undefined Why it matters: The migration's whole risk is "does passing the currency explicitly produce the same rate as the old module read?" Without an assertion on that path, a future change to the fallback order in Recommendation: add one focused case — a distance transaction with policy having no |
||
| type LegacyChangeTransactionsReportProps = Omit<Parameters<typeof changeTransactionsReportAction>[0], 'transactions' | 'allTransactionViolation'> & { | ||
| type LegacyChangeTransactionsReportProps = Omit<Parameters<typeof changeTransactionsReportAction>[0], 'transactions' | 'allTransactionViolation' | 'personalPolicyOutputCurrency'> & { | ||
| allTransactions: OnyxCollection<Transaction>; | ||
| transactionViolations: Parameters<typeof changeTransactionsReportAction>[0]['allTransactionViolation']; | ||
| personalPolicyOutputCurrency?: string; | ||
| }; | ||
|
|
||
| function changeTransactionsReport({allTransactions, transactionIDs, transactionViolations, ...rest}: LegacyChangeTransactionsReportProps) { | ||
| function changeTransactionsReport({allTransactions, transactionIDs, transactionViolations, personalPolicyOutputCurrency, ...rest}: LegacyChangeTransactionsReportProps) { | ||
| const transactions = transactionIDs.map((id) => allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]).filter((transaction): transaction is Transaction => !!transaction); | ||
| changeTransactionsReportAction({transactionIDs, transactions, allTransactionViolation: transactionViolations, ...rest}); | ||
| changeTransactionsReportAction({transactionIDs, transactions, allTransactionViolation: transactionViolations, personalPolicyOutputCurrency, ...rest}); | ||
| } | ||
|
|
||
| const topMostReportID = '23423423'; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Redundant
personalPolicyOutputCurrencyin two call sites (correctness‑neutral, but misleading)In
useUndeleteTransactions.tsanduseReportSelectionActions.ts#removeFromReport, the policy passed is already the personal policy, sopolicy?.outputCurrencyresolves first ingetRateandpersonalPolicyOutputCurrencyis dead.Why it matters: It's not a bug, but a future reader will assume
personalPolicyOutputCurrencyis distinct from policy here and may build on that false assumption. It also duplicates the collection lookup in the second case.Consider a short comment (
// policy is already the personal policy; passed for the getRate fallback contract) or dropping it where genuinely redundant. This is a nit — I would not block on it, but it's worth a one‑line clarification for the next maintainer.