Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function TransactionListItem<TItem extends ListItem>({
shouldSyncFocus,
columns,
isLoading,
violations,
nonPersonalAndWorkspaceCards,
lastPaymentMethod,
personalPolicyID,
Expand Down Expand Up @@ -84,6 +83,7 @@ function TransactionListItem<TItem extends ListItem>({
const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(transactionItem.reportID)}`);
const [transactionThreadReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionItem?.reportAction?.childReportID}`);
const [transaction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionItem.transactionID)}`);
const [transactionViolationsForRow] = originalUseOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${getNonEmptyStringOnyxID(transactionItem.transactionID)}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! This PR caused a regression: #103624

What happened: Before this PR, Search/index.tsx read violations through the App's useOnyx wrapper (@hooks/useOnyx). On Search, that wrapper falls back to the search snapshot for transactionViolations_. This PR moved the read into each row with originalUseOnyx (the raw useOnyx from react-native-onyx). That hook only reads live Onyx and ignores the snapshot.

Result: In Spend > Expenses, the row shows no violations for an expense whose violations aren't in live Onyx yet (for example, one you haven't opened). The Search API had already returned them in the snapshot. They only appeared after opening the expense, which loads them into live Onyx.

Fix: #103690 keeps the per-row subscription but falls back to the snapshot when live Onyx has no violations for that transaction:

const transactionViolationsForRow = liveTransactionViolations ?? snapshotData?.[transactionViolationsKey];

Takeaway: When you move a Search read from useOnyx to a raw or WithoutSnapshots subscription, check whether that key is snapshot-backed (runtimeConfigured.ts). If it is, keep a snapshot fallback, as this row already does for the policy and chat report.

const parentReportActionSelector = (reportActions: OnyxEntry<ReportActions>): OnyxEntry<ReportAction> => reportActions?.[`${transactionItem?.reportAction?.reportActionID}`];
const [parentReportAction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(transactionItem.reportID)}`, {selector: parentReportActionSelector}, [
transactionItem,
Expand All @@ -103,7 +103,7 @@ function TransactionListItem<TItem extends ListItem>({
const policyForViolations = parentPolicy ?? snapshotPolicy;
const reportForViolations = parentReport ?? snapshotReport;

const onyxViolations = (violations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionItem.transactionID}`] ?? []).filter(
const onyxViolations = (transactionViolationsForRow ?? []).filter(
(violation: TransactionViolation) =>
!isViolationDismissed(transactionItem, violation, currentUserDetails.email ?? '', currentUserDetails.accountID, reportForViolations, policyForViolations) &&
shouldShowViolation(reportForViolations, policyForViolations, violation.name, currentUserDetails.email ?? '', false, transactionItem),
Expand Down
4 changes: 1 addition & 3 deletions src/components/Search/SearchList/ListItem/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ type TransactionListItemProps<TItem extends ListItem> = ListItemProps<TItem> &
/** Whether the item's action is loading */
isLoading?: boolean;
columns?: SearchColumnType[];
violations?: Record<string, TransactionViolations | undefined> | undefined;
policyForMovingExpenses?: Policy;
/** Non-personal and workspace cards for company card display */
nonPersonalAndWorkspaceCards?: CardList;
Expand All @@ -435,7 +434,6 @@ type TransactionGroupListItemProps<TItem extends ListItem> = ListItemProps<TItem
accountID?: number;
columns?: SearchColumnType[];
newTransactionID?: string;
violations?: Record<string, TransactionViolations | undefined> | undefined;
policyForMovingExpenses?: Policy;
/** Non-personal and workspace cards for company card display */
nonPersonalAndWorkspaceCards?: CardList;
Expand All @@ -452,12 +450,12 @@ type TransactionGroupListExpandedProps<TItem extends ListItem> = Pick<
| 'groupBy'
| 'accountID'
| 'isOffline'
| 'violations'
| 'onSelectRow'
| 'nonPersonalAndWorkspaceCards'
| 'onUndelete'
| 'policyForMovingExpenses'
> & {
violations?: Record<string, TransactionViolations | undefined> | undefined;
transactions: TransactionListItemType[];
transactionsVisibleLimit: number;
setTransactionsVisibleLimit: React.Dispatch<React.SetStateAction<number>>;
Expand Down
8 changes: 1 addition & 7 deletions src/components/Search/SearchList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import variables from '@styles/variables';
import type {TransactionPreviewData} from '@userActions/Search';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {CardList, Policy, Transaction, TransactionViolations} from '@src/types/onyx';
import type {CardList, Policy, Transaction} from '@src/types/onyx';
import type {HoldMenuCallback} from '..';
import BaseSearchList from './BaseSearchList';
import type ChatListItem from './ListItem/ChatListItem';
Expand Down Expand Up @@ -118,9 +118,6 @@ type SearchListProps = Pick<FlashListProps<SearchListItem>, 'onScroll' | 'conten

newTransactions?: Transaction[];

/** Violations indexed by transaction ID */
violations?: Record<string, TransactionViolations | undefined> | undefined;

/** Callback to fire when hold menu should be opened */
onHoldMenuOpen?: HoldMenuCallback;

Expand Down Expand Up @@ -217,7 +214,6 @@ function SearchList({
shouldAnimate,
isMobileSelectionModeEnabled,
newTransactions = [],
violations,
onHoldMenuOpen,
nonPersonalAndWorkspaceCards,
selectedTransactions,
Expand Down Expand Up @@ -455,7 +451,6 @@ function SearchList({
personalDetails={personalDetails}
userBillingFundID={userBillingFundID}
isOffline={isOffline}
violations={violations}
nonPersonalAndWorkspaceCards={nonPersonalAndWorkspaceCards}
onFocus={onFocus}
newTransactionID={newTransactionID}
Expand Down Expand Up @@ -485,7 +480,6 @@ function SearchList({
personalDetails,
userBillingFundID,
isOffline,
violations,
lastPaymentMethod,
personalPolicyID,
onHoldMenuOpen,
Expand Down
1 change: 0 additions & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,6 @@ function Search({
}
queryJSON={queryJSON}
columns={columnsToShow}
violations={violations}
onLayout={onLayout}
Comment on lines 1853 to 1856
isMobileSelectionModeEnabled={isMobileSelectionModeEnabled}
shouldAnimate={type === CONST.SEARCH.DATA_TYPES.EXPENSE}
Expand Down
Loading