Repository navigation
Add customUnitRateOutOfDateRange violation for date-bound mileage rates #93555
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
Merged
rlinoz
merged 29 commits into
Expensify:main
from
Krishna2323:krishna/89837-custom-unit-rate-out-of-date-range-violation
Jul 1, 2026
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ce34caf
Add customUnitRateOutOfDateRange violation for date-bound mileage rates
Krishna2323 91d9a9e
Show customUnitRateOutOfDateRange inline on confirmation without bloc…
Krishna2323 cbb254f
remove es translations.
Krishna2323 73d4a52
Sync mileage rate date violation when editing existing distance expenses
Krishna2323 16c1003
Fix mileage rate date validation edge cases from Codex review
Krishna2323 4acd516
fix failing checks.
Krishna2323 fa7a0a6
Fix Jest failures for mileage rate violation changes
Krishna2323 65a4403
fix inline import type specifiers issue.
Krishna2323 2316864
Fix ESLint type issues in useTransactionViolationsTest mock
Krishna2323 bf702c8
Merge branch 'main' into krishna/89837-custom-unit-rate-out-of-date-r…
Krishna2323 1357168
Address PR review feedback for mileage rate out-of-date validation
Krishna2323 12444fa
Deduplicate mileage rate out-of-date range validation logic
Krishna2323 45ab966
fix non-null assertion
Krishna2323 ccf64c0
Mirror track expense violation updates into search snapshots
Krishna2323 9b5ffd7
Merge branch 'main' into krishna/89837-custom-unit-rate-out-of-date-r…
Krishna2323 88dbad6
add translations.
Krishna2323 a14fe38
Fix CI failures from stray beta override and eslint-seatbelt overflow
Krishna2323 83698dc
Merge branch 'Expensify:main' into krishna/89837-custom-unit-rate-out…
Krishna2323 55f7ba8
fix ts check.
Krishna2323 f62b1e6
Show rate-date warnings on tracked self-DM distance expenses
Krishna2323 0245b11
Fix rate-date violation display across all transaction surfaces
Krishna2323 3df4897
fix tests.
Krishna2323 201bb72
Harden self-DM distance violations to avoid false customUnitOutOfPolicy
Krishna2323 24f8340
Optimize distance rate policy lookup to avoid per-row collection scans
Krishna2323 12de1a0
Use getPolicyIDOrDefault for distance rate policy subscription fallback
Krishna2323 86addad
fix eslint.
Krishna2323 bb98306
Merge branch 'main' into krishna/89837-custom-unit-rate-out-of-date-r…
Krishna2323 9b00e84
Thread distanceOriginalPolicy for cross-policy rate violation lookups
Krishna2323 435a62d
Pass current transaction violations from callers for date/rate updates
Krishna2323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,35 @@ | ||
| import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; | ||
| import {getDistanceRateCustomUnit} from '@libs/PolicyUtils'; | ||
| import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; | ||
| import {getPolicyForDistanceRateID, getPolicyIDOrDefault} from '@libs/PolicyUtils'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {Policy} from '@src/types/onyx'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| /** | ||
| * Finds the policy that owns the given customUnitRateID by searching all policies | ||
| * for one whose distance custom unit contains the rate. | ||
| * Finds the policy that owns the given customUnitRateID. | ||
| * Resolves the policy ID via a collection selector (scalar output) and subscribes | ||
| * only to that policy key for reactive updates. | ||
| * | ||
| * @param shouldLookup When false, skips the cross-policy scan (e.g. when the rate is already on the report policy). | ||
| */ | ||
| function useDistanceRateOriginalPolicy(customUnitRateID: string | undefined): OnyxEntry<Policy> { | ||
| const [distanceOriginalPolicy] = useOnyx(ONYXKEYS.COLLECTION.POLICY, { | ||
| selector: (policies: OnyxCollection<Policy>) => { | ||
| if (!customUnitRateID) { | ||
| return undefined; | ||
| } | ||
| return Object.values(policies ?? {}).find((p) => { | ||
| const distanceUnit = getDistanceRateCustomUnit(p); | ||
| return !!distanceUnit?.rates && customUnitRateID in distanceUnit.rates; | ||
| }); | ||
| function useDistanceRateOriginalPolicy(customUnitRateID: string | undefined, shouldLookup = true): OnyxEntry<Policy> { | ||
| const [policyID] = useOnyx( | ||
| ONYXKEYS.COLLECTION.POLICY, | ||
| { | ||
| selector: (policies: OnyxCollection<Policy>) => { | ||
| if (!shouldLookup || !customUnitRateID) { | ||
| return undefined; | ||
| } | ||
| return getPolicyForDistanceRateID(customUnitRateID, policies)?.id; | ||
| }, | ||
| }, | ||
| }); | ||
| [customUnitRateID, shouldLookup], | ||
| ); | ||
|
|
||
| return distanceOriginalPolicy; | ||
| const resolvedPolicyID = getNonEmptyStringOnyxID(policyID); | ||
| const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getPolicyIDOrDefault(resolvedPolicyID)}`); | ||
|
|
||
| return shouldLookup && customUnitRateID && resolvedPolicyID ? policy : undefined; | ||
| } | ||
|
|
||
| export default useDistanceRateOriginalPolicy; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,40 @@ | ||
| import {useMemo} from 'react'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; | ||
| import {getVisibleTransactionViolations} from '@libs/TransactionUtils'; | ||
| import {getDistanceRateCustomUnitRate} from '@libs/PolicyUtils'; | ||
| import {getVisibleTransactionViolations, isDistanceRequest} from '@libs/TransactionUtils'; | ||
| import {syncCustomUnitRateOutOfDateRangeViolation} from '@libs/Violations/ViolationsUtils'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {TransactionViolation, TransactionViolations} from '@src/types/onyx'; | ||
| import type {Policy, TransactionViolation, TransactionViolations} from '@src/types/onyx'; | ||
| import getEmptyArray from '@src/types/utils/getEmptyArray'; | ||
| import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; | ||
| import useDistanceRateOriginalPolicy from './useDistanceRateOriginalPolicy'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| function useTransactionViolations(transactionID?: string, shouldShowRterForSettledReport = true): TransactionViolations { | ||
| function useTransactionViolations(transactionID?: string, shouldShowRterForSettledReport = true, policyOverride?: OnyxEntry<Policy>): TransactionViolations { | ||
| const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionID)}`); | ||
| const [transactionViolations = getEmptyArray<TransactionViolation>()] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`); | ||
| const [iouReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(transaction?.reportID)}`); | ||
| const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`); | ||
| const [reportPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`); | ||
| const customUnitRateID = isDistanceRequest(transaction) ? transaction?.comment?.customUnit?.customUnitRateID : undefined; | ||
| const shouldLookupDistancePolicy = !policyOverride && !!customUnitRateID && !getDistanceRateCustomUnitRate(reportPolicy, customUnitRateID); | ||
| const distanceOriginalPolicy = useDistanceRateOriginalPolicy(customUnitRateID, shouldLookupDistancePolicy); | ||
| const policy = policyOverride ?? distanceOriginalPolicy ?? reportPolicy; | ||
| const currentUserDetails = useCurrentUserPersonalDetails(); | ||
|
|
||
| return useMemo( | ||
| () => | ||
| getVisibleTransactionViolations( | ||
| transaction, | ||
| transactionViolations, | ||
| currentUserDetails.email ?? '', | ||
| currentUserDetails.accountID, | ||
| iouReport, | ||
| policy, | ||
| shouldShowRterForSettledReport, | ||
| ), | ||
| [transaction, transactionViolations, iouReport, policy, shouldShowRterForSettledReport, currentUserDetails.email, currentUserDetails.accountID], | ||
| ); | ||
| return useMemo(() => { | ||
| const syncedViolations = syncCustomUnitRateOutOfDateRangeViolation(transactionViolations, transaction, policy); | ||
|
|
||
| return getVisibleTransactionViolations( | ||
| transaction, | ||
| syncedViolations, | ||
| currentUserDetails.email ?? '', | ||
| currentUserDetails.accountID, | ||
| iouReport, | ||
| policy, | ||
| shouldShowRterForSettledReport, | ||
| ); | ||
| }, [transaction, transactionViolations, iouReport, policy, shouldShowRterForSettledReport, currentUserDetails.email, currentUserDetails.accountID]); | ||
| } | ||
|
|
||
| export default useTransactionViolations; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.