Repository navigation
Fix 85553 rbr carousel sorting #86477
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
Changes from all commits
5baad9d
bcc6300
16085b4
84eef2a
bd41784
93f3b3a
f494c87
e618e2e
1949c90
977fd9a
eed9e5a
beefefb
90a470b
84831a4
9400b6e
5196596
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 |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ import { | |
| import type {SortableColumnName} from '@libs/ReportUtils'; | ||
| import {compareValues, getColumnsToShow, getTableMinWidth, isTransactionAmountTooLong, isTransactionTaxAmountTooLong} from '@libs/SearchUIUtils'; | ||
| import {getPendingSubmitFollowUpAction} from '@libs/telemetry/submitFollowUpAction'; | ||
| import {compareByRBR} from '@libs/TransactionPreviewUtils'; | ||
| import {getTransactionPendingAction, isTransactionPendingDelete, shouldShowExpenseBreakdown} from '@libs/TransactionUtils'; | ||
| import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear'; | ||
| import isReportOpenInSuperWideRHP from '@navigation/helpers/isReportOpenInSuperWideRHP'; | ||
|
|
@@ -179,6 +180,7 @@ function MoneyRequestReportTransactionList({ | |
| const [nonPersonalAndWorkspaceCards] = useOnyx(ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST); | ||
| const [cardList] = useOnyx(ONYXKEYS.CARD_LIST); | ||
| const [draftTransactionIDs] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, {selector: validTransactionDraftIDsSelector}); | ||
| const [allTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); | ||
|
|
||
| const shouldShowGroupedTransactions = isExpenseReport(report) && !isIOUReport(report); | ||
|
|
||
|
|
@@ -284,12 +286,32 @@ function MoneyRequestReportTransactionList({ | |
| }); | ||
|
|
||
| const {sortBy, sortOrder} = sortConfig; | ||
| const isDefaultSort = sortBy === CONST.SEARCH.TABLE_COLUMNS.DATE && sortOrder === CONST.SEARCH.SORT_ORDER.ASC; | ||
|
|
||
| // Convert reportActions array to a record keyed by reportActionID for compareByRBR | ||
| const reportActionsMap = useMemo(() => Object.fromEntries(reportActions.map((ra) => [ra.reportActionID, ra])), [reportActions]); | ||
|
|
||
| const sortedTransactions: TransactionWithOptionalHighlight[] = useMemo(() => { | ||
| return [...transactions].sort((a, b) => | ||
| compareValues(getTransactionSortValue(a, sortBy, report, policy), getTransactionSortValue(b, sortBy, report, policy), sortOrder, sortBy, localeCompare, true), | ||
| ); | ||
| }, [sortBy, sortOrder, transactions, localeCompare, report, policy]); | ||
| return [...transactions].sort((a, b) => { | ||
| // When on default sort (Date/ASC), prioritize RBR-flagged transactions | ||
| if (isDefaultSort && allTransactionViolations) { | ||
|
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. ❌ CONSISTENCY-3The RBR-aware sort comparator logic (violation lookup + Extract a shared Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
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. This makes sense, repeated code should be extracted to a shared utility function in
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. @abelhailefen Mind addressing this valid refactoring concern ?
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. This is important, we should use the existing logic 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 RBR prioritization is currently gated by Useful? React with 👍 / 👎.
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.
This is expected. |
||
| const rbrComparison = compareByRBR( | ||
| a, | ||
| b, | ||
| allTransactionViolations, | ||
| currentUserDetails?.login ?? '', | ||
| currentUserDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID, | ||
| report, | ||
| policy, | ||
| reportActionsMap, | ||
| ); | ||
| if (rbrComparison !== 0) { | ||
| return rbrComparison; | ||
| } | ||
| } | ||
| return compareValues(getTransactionSortValue(a, sortBy, report, policy), getTransactionSortValue(b, sortBy, report, policy), sortOrder, sortBy, localeCompare, true); | ||
| }); | ||
| }, [sortBy, sortOrder, transactions, localeCompare, report, policy, isDefaultSort, allTransactionViolations, currentUserDetails?.login, currentUserDetails?.accountID, reportActionsMap]); | ||
|
|
||
| const resolvedTransactions = useMemo(() => resolveTransactionCardFields(sortedTransactions, cardList, translate), [sortedTransactions, cardList, translate]); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import type {OnyxEntry} from 'react-native-onyx'; | |
| import type {CurrencyListActionsContextType} from '@hooks/useCurrencyList'; | ||
| import CONST from '@src/CONST'; | ||
| import type {TranslationPaths} from '@src/languages/types'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type * as OnyxTypes from '@src/types/onyx'; | ||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
|
|
@@ -457,6 +458,108 @@ function createTransactionPreviewConditionals({ | |
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Lightweight check for whether a transaction has any RBR (Red Brick Road) indicator. | ||
| * Evaluates transaction-level signals (violations, hold, missing fields, receipt errors, | ||
| * report action errors, and DEW submit failures) with proper context for dismissed | ||
| * violations and report settlement/approval status. | ||
| * | ||
| * This logic mirrors the `shouldShowRBR` computation in `createTransactionPreviewConditionals`. | ||
| */ | ||
| function transactionHasRBR( | ||
| transaction: OnyxEntry<OnyxTypes.Transaction>, | ||
| violations: OnyxTypes.TransactionViolations, | ||
| currentUserEmail: string, | ||
| currentUserAccountID: number, | ||
| iouReport: OnyxEntry<OnyxTypes.Report>, | ||
| policy: OnyxEntry<OnyxTypes.Policy>, | ||
| reportActions?: OnyxTypes.ReportActions, | ||
| ): boolean { | ||
| if (!transaction) { | ||
| return false; | ||
| } | ||
|
|
||
| // Check for non-dismissed violation-type or warning-type violations | ||
| if ( | ||
| hasViolation(transaction, violations, currentUserEmail, currentUserAccountID, iouReport, policy, true) || | ||
| hasWarningTypeViolation(transaction, violations, currentUserEmail, currentUserAccountID, iouReport, policy) | ||
| ) { | ||
|
Comment on lines
+482
to
+486
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.
Useful? React with 👍 / 👎. |
||
| return true; | ||
| } | ||
|
|
||
| // Check for notice-type violations (only on paid group policies) | ||
| if (hasNoticeTypeViolation(transaction, violations, currentUserEmail, currentUserAccountID, iouReport, policy, true) && isPaidGroupPolicyUtil(iouReport)) { | ||
| return true; | ||
| } | ||
|
|
||
| // Check for distance-request modified-amount violations (type VIOLATION or NOTICE) | ||
| if ( | ||
| isDistanceRequest(transaction) && | ||
| violations?.some( | ||
| (violation) => violation.name === CONST.VIOLATIONS.MODIFIED_AMOUNT && (violation.type === CONST.VIOLATION_TYPES.VIOLATION || violation.type === CONST.VIOLATION_TYPES.NOTICE), | ||
| ) | ||
| ) { | ||
| return true; | ||
| } | ||
|
|
||
| // Check if transaction is on hold — only counts as RBR when the report | ||
| // is not fully settled and not fully approved (matching createTransactionPreviewConditionals) | ||
| const isSettlementOrApprovalPartial = !!iouReport?.pendingFields?.partial; | ||
| const isFullySettled = isSettled(iouReport?.reportID) && !isSettlementOrApprovalPartial; | ||
| const isFullyApproved = isReportApproved({report: iouReport}) && !isSettlementOrApprovalPartial; | ||
| if (!isFullySettled && !isFullyApproved && isOnHold(transaction)) { | ||
| return true; | ||
| } | ||
|
|
||
| // Check if transaction has missing required fields (uses hasMissingSmartscanFields | ||
| // which guards against distance requests and receipts being scanned) | ||
| if (hasMissingSmartscanFields(transaction, iouReport)) { | ||
| return true; | ||
| } | ||
|
|
||
| // Check if transaction has receipt error | ||
| if (hasReceiptError(transaction)) { | ||
| return true; | ||
| } | ||
|
|
||
| // Check for report action errors associated with this transaction | ||
| if (hasActionWithErrorsForTransaction(iouReport?.reportID, transaction, reportActions)) { | ||
| return true; | ||
| } | ||
|
|
||
| // Check for DEW submit failures | ||
| if (hasDynamicExternalWorkflow(policy) && !!getMostRecentActiveDEWSubmitFailedAction(reportActions)) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Compare two transactions by their RBR (Red Brick Road) status. | ||
| * Transactions with RBR indicators are sorted before those without. | ||
| * Returns 0 when both transactions have the same RBR status. | ||
| */ | ||
| function compareByRBR( | ||
| a: OnyxTypes.Transaction, | ||
| b: OnyxTypes.Transaction, | ||
| violations: Record<string, OnyxTypes.TransactionViolations | undefined> | undefined, | ||
| currentUserEmail: string, | ||
| currentUserAccountID: number, | ||
| iouReport: OnyxEntry<OnyxTypes.Report>, | ||
| policy: OnyxEntry<OnyxTypes.Policy>, | ||
| reportActions?: OnyxTypes.ReportActions, | ||
| ): number { | ||
| const aViolations = violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${a.transactionID}`] ?? []; | ||
| const bViolations = violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${b.transactionID}`] ?? []; | ||
| const aHasRBR = transactionHasRBR(a, aViolations, currentUserEmail, currentUserAccountID, iouReport, policy, reportActions); | ||
| const bHasRBR = transactionHasRBR(b, bViolations, currentUserEmail, currentUserAccountID, iouReport, policy, reportActions); | ||
| if (aHasRBR === bHasRBR) { | ||
| return 0; | ||
| } | ||
| return aHasRBR ? -1 : 1; | ||
| } | ||
|
|
||
| export { | ||
| getReviewNavigationRoute, | ||
| getIOUPayerAndReceiver, | ||
|
|
@@ -465,5 +568,7 @@ export { | |
| getViolationTranslatePath, | ||
| getUniqueActionErrorsForTransaction, | ||
| formatLastFourPAN, | ||
| transactionHasRBR, | ||
| compareByRBR, | ||
| }; | ||
| export type {TranslationPathOrText}; | ||
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.
❌ PERF-11
useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS)subscribes to the entire transaction violations collection without a selector. This component will re-render whenever any transaction violation changes across the entire app, not just those belonging to the transactions in this report.Consider using a selector that filters to only the relevant transaction IDs, or compute violations per-transaction inside the
useMemousing the transaction IDs already available from thetransactionsprop.Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
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.
✅ This is fine, we want to rerender whenever any violation changes across the app, not just those belonging to the transactions in this report.