Skip to content

Commit 03cabab

Browse files
committed
address reviewer comments
1 parent 22933ad commit 03cabab

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

src/components/SelectionList/Search/ReportListItemHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function ReportListItemHeader<TItem extends ListItem>({
182182
reportItem,
183183
() => onSelectRow(reportItem as unknown as TItem),
184184
shouldUseNarrowLayout && !!canSelectMultiple,
185-
snapshot,
185+
snapshot?.data,
186186
lastPaymentMethod,
187187
currentSearchKey,
188188
);

src/components/SelectionList/Search/TransactionListItem.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ function TransactionListItem<TItem extends ListItem>({
8383
);
8484

8585
const handleActionButtonPress = useCallback(() => {
86-
handleActionButtonPressUtil(currentSearchHash, transactionItem, () => onSelectRow(item), shouldUseNarrowLayout && !!canSelectMultiple, snapshot, lastPaymentMethod, currentSearchKey);
86+
handleActionButtonPressUtil(
87+
currentSearchHash,
88+
transactionItem,
89+
() => onSelectRow(item),
90+
shouldUseNarrowLayout && !!canSelectMultiple,
91+
snapshot?.data,
92+
lastPaymentMethod,
93+
currentSearchKey,
94+
);
8795
}, [canSelectMultiple, currentSearchHash, currentSearchKey, item, onSelectRow, shouldUseNarrowLayout, transactionItem, snapshot, lastPaymentMethod]);
8896

8997
const handleCheckboxPress = useCallback(() => {

src/libs/actions/Search.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function handleActionButtonPress(
3232
item: TransactionListItemType | TransactionReportGroupListItemType,
3333
goToItem: () => void,
3434
isInMobileSelectionMode: boolean,
35-
snapshot: OnyxEntry<SearchResults>,
35+
snapshotData: SearchResults['data'] | undefined,
3636
lastPaymentMethod: OnyxEntry<LastPaymentMethod>,
3737
currentSearchKey?: SearchKey,
3838
) {
@@ -42,20 +42,20 @@ function handleActionButtonPress(
4242
const allReportTransactions = (isTransactionGroupListItemType(item) ? item.transactions : [item]) as SearchTransaction[];
4343
const hasHeldExpense = hasHeldExpenses('', allReportTransactions);
4444

45-
if (hasHeldExpense || isInMobileSelectionMode) {
45+
if (hasHeldExpense || isInMobileSelectionMode || !snapshotData) {
4646
goToItem();
4747
return;
4848
}
4949

5050
switch (item.action) {
5151
case CONST.SEARCH.ACTION_TYPES.PAY:
52-
getPayActionCallback(hash, item, goToItem, snapshot, lastPaymentMethod, currentSearchKey);
52+
getPayActionCallback(hash, item, goToItem, snapshotData, lastPaymentMethod, currentSearchKey);
5353
return;
5454
case CONST.SEARCH.ACTION_TYPES.APPROVE:
5555
approveMoneyRequestOnSearch(hash, [item.reportID], transactionID, currentSearchKey);
5656
return;
5757
case CONST.SEARCH.ACTION_TYPES.SUBMIT: {
58-
const policy = (snapshot?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`] ?? {}) as SearchPolicy;
58+
const policy = snapshotData?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`] ?? {};
5959
submitMoneyRequestOnSearch(hash, [item], [policy], transactionID, currentSearchKey);
6060
return;
6161
}
@@ -64,7 +64,7 @@ function handleActionButtonPress(
6464
return;
6565
}
6666

67-
const policy = (snapshot?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`] ?? {}) as Policy;
67+
const policy = (snapshotData?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`] ?? {}) as Policy;
6868
const connectedIntegration = getValidConnectedIntegration(policy);
6969

7070
if (!connectedIntegration) {
@@ -97,7 +97,7 @@ function getPayActionCallback(
9797
hash: number,
9898
item: TransactionListItemType | TransactionReportGroupListItemType,
9999
goToItem: () => void,
100-
snapshot: OnyxEntry<SearchResults>,
100+
snapshotData: SearchResults['data'],
101101
lastPaymentMethod: OnyxEntry<LastPaymentMethod>,
102102
currentSearchKey?: SearchKey,
103103
) {
@@ -108,7 +108,7 @@ function getPayActionCallback(
108108
return;
109109
}
110110

111-
const report = (snapshot?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`] ?? {}) as SearchReport;
111+
const report = snapshotData?.[`${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`] ?? {};
112112
const amount = Math.abs((report?.total ?? 0) - (report?.nonReimbursableTotal ?? 0));
113113
const transactionID = isTransactionListItemType(item) ? [item.transactionID] : undefined;
114114

@@ -117,7 +117,7 @@ function getPayActionCallback(
117117
return;
118118
}
119119

120-
const hasVBBA = !!snapshot?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`]?.achAccount?.bankAccountID;
120+
const hasVBBA = !!snapshotData?.[`${ONYXKEYS.COLLECTION.POLICY}${item.policyID}`]?.achAccount?.bankAccountID;
121121
if (hasVBBA) {
122122
payMoneyRequestOnSearch(hash, [{reportID: item.reportID, amount, paymentType: lastPolicyPaymentMethod}], transactionID, currentSearchKey);
123123
return;

tests/unit/Search/handleActionButtonPressTest.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,19 @@ describe('handleActionButtonPress', () => {
249249

250250
test('Should navigate to item when report has one transaction on hold', () => {
251251
const goToItem = jest.fn(() => {});
252-
handleActionButtonPress(searchHash, mockReportItemWithHold, goToItem, false, mockSnapshotForItem, mockLastPaymentMethod);
252+
handleActionButtonPress(searchHash, mockReportItemWithHold, goToItem, false, mockSnapshotForItem?.data, mockLastPaymentMethod);
253253
expect(goToItem).toHaveBeenCalledTimes(1);
254254
});
255255

256256
test('Should not navigate to item when the hold is removed', () => {
257257
const goToItem = jest.fn(() => {});
258-
handleActionButtonPress(searchHash, updatedMockReportItem, goToItem, false, mockSnapshotForItem, mockLastPaymentMethod);
258+
handleActionButtonPress(searchHash, updatedMockReportItem, goToItem, false, mockSnapshotForItem?.data, mockLastPaymentMethod);
259259
expect(goToItem).toHaveBeenCalledTimes(0);
260260
});
261261

262262
test('Should run goToItem callback when user is in mobile selection mode', () => {
263263
const goToItem = jest.fn(() => {});
264-
handleActionButtonPress(searchHash, updatedMockReportItem, goToItem, true, mockSnapshotForItem, mockLastPaymentMethod);
264+
handleActionButtonPress(searchHash, updatedMockReportItem, goToItem, true, mockSnapshotForItem?.data, mockLastPaymentMethod);
265265
expect(goToItem).toHaveBeenCalledTimes(1);
266266
});
267267
});

0 commit comments

Comments
 (0)