Skip to content

Commit e95727d

Browse files
carlosmiceliOSBotify
authored andcommitted
Merge pull request #71180 from ishpaul777/revert-70814-mkzie2-issue/70400
Revert "remove inline selector for transaction key" (cherry picked from commit cb9b228) (cherry-picked to staging by roryabraham)
1 parent 358bbdc commit e95727d

15 files changed

+121
-119
lines changed

src/components/ReportActionItem/TransactionPreview/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import type {TransactionDuplicateNavigatorParamList} from '@navigation/types';
2121
import {clearWalletTermsError} from '@userActions/PaymentMethods';
2222
import {clearIOUError} from '@userActions/Report';
2323
import CONST from '@src/CONST';
24-
import useTransactionsByID from '@src/hooks/useTransactionsByID';
2524
import ONYXKEYS from '@src/ONYXKEYS';
2625
import SCREENS from '@src/SCREENS';
2726
import {isEmptyObject} from '@src/types/utils/EmptyObject';
@@ -58,7 +57,14 @@ function TransactionPreview(props: TransactionPreviewProps) {
5857

5958
// Get transaction violations for given transaction id from onyx, find duplicated transactions violations and get duplicates
6059
const allDuplicateIDs = useMemo(() => violations?.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)?.data?.duplicates ?? [], [violations]);
61-
const [allDuplicates] = useTransactionsByID(allDuplicateIDs);
60+
const [allDuplicates] = useOnyx(
61+
ONYXKEYS.COLLECTION.TRANSACTION,
62+
{
63+
selector: (allTransactions) => allDuplicateIDs.map((id) => allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]),
64+
canBeMissing: true,
65+
},
66+
[allDuplicateIDs],
67+
);
6268
const duplicates = useMemo(() => removeSettledAndApprovedTransactions(allDuplicates ?? []), [allDuplicates]);
6369
const sessionAccountID = session?.accountID;
6470
const areThereDuplicates = allDuplicateIDs.length > 0 && duplicates.length > 0 && allDuplicateIDs.length === duplicates.length;

src/hooks/useReportTransactions.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {useCallback} from 'react';
2-
import type {OnyxCollection} from 'react-native-onyx';
31
import ONYXKEYS from '@src/ONYXKEYS';
42
import type {Transaction} from '@src/types/onyx';
53
import getEmptyArray from '@src/types/utils/getEmptyArray';
@@ -9,25 +7,16 @@ import useOnyx from './useOnyx';
97
* Hook to get all transactions for a specific report
108
*/
119
function useReportTransactions(reportID: string | undefined): Transaction[] {
12-
const reportTransactionsSelector = useCallback(
13-
(transactions: OnyxCollection<Transaction>) => {
10+
const [reportTransactions = getEmptyArray<Transaction>()] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
11+
selector: (transactions) => {
1412
if (!transactions || !reportID) {
1513
return [];
1614
}
1715

1816
return Object.values(transactions).filter((transaction): transaction is Transaction => !!transaction && transaction.reportID === reportID);
1917
},
20-
[reportID],
21-
);
22-
23-
const [reportTransactions = getEmptyArray<Transaction>()] = useOnyx(
24-
ONYXKEYS.COLLECTION.TRANSACTION,
25-
{
26-
selector: reportTransactionsSelector,
27-
canBeMissing: true,
28-
},
29-
[reportTransactionsSelector],
30-
);
18+
canBeMissing: true,
19+
});
3120

3221
return reportTransactions;
3322
}

src/hooks/useTransactionsByID.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/hooks/useTripTransactions.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import {useCallback} from 'react';
2-
import type {OnyxCollection} from 'react-native-onyx';
31
import ONYXKEYS from '@src/ONYXKEYS';
42
import type {Transaction} from '@src/types/onyx';
53
import getEmptyArray from '@src/types/utils/getEmptyArray';
@@ -21,27 +19,19 @@ function useTripTransactions(reportID: string | undefined): Transaction[] {
2119
Object.values(reports ?? {})
2220
.filter((report) => report && report.chatReportID === reportID)
2321
.map((report) => report?.reportID),
24-
canBeMissing: true,
2522
});
26-
27-
const tripTransactionsSelector = useCallback(
28-
(transactions: OnyxCollection<Transaction>) => {
29-
if (!tripTransactionReportIDs.length) {
30-
return [];
31-
}
32-
33-
return Object.values(transactions ?? {}).filter((transaction): transaction is Transaction => !!transaction && tripTransactionReportIDs.includes(transaction.reportID));
34-
},
35-
[tripTransactionReportIDs],
36-
);
37-
3823
const [tripTransactions = getEmptyArray<Transaction>()] = useOnyx(
3924
ONYXKEYS.COLLECTION.TRANSACTION,
4025
{
41-
selector: tripTransactionsSelector,
42-
canBeMissing: true,
26+
selector: (transactions) => {
27+
if (!tripTransactionReportIDs.length) {
28+
return [];
29+
}
30+
31+
return Object.values(transactions ?? {}).filter((transaction): transaction is Transaction => !!transaction && tripTransactionReportIDs.includes(transaction.reportID));
32+
},
4333
},
44-
[tripTransactionsSelector],
34+
[tripTransactionReportIDs],
4535
);
4636
return tripTransactions;
4737
}

src/pages/AddUnreportedExpense.tsx

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
1+
import React, {useEffect, useMemo, useRef, useState} from 'react';
22
import {InteractionManager} from 'react-native';
33
import type {OnyxCollection} from 'react-native-onyx';
44
import EmptyStateComponent from '@components/EmptyStateComponent';
@@ -56,39 +56,32 @@ function AddUnreportedExpense({route}: AddUnreportedExpensePageType) {
5656
const session = useSession();
5757
const shouldShowUnreportedTransactionsSkeletons = isLoadingUnreportedTransactions && hasMoreUnreportedTransactionsResults && !isOffline;
5858

59-
const getUnreportedTransactions = useCallback(
60-
(transactions: OnyxCollection<Transaction>) => {
61-
if (!transactions) {
62-
return [];
59+
function getUnreportedTransactions(transactions: OnyxCollection<Transaction>) {
60+
if (!transactions) {
61+
return [];
62+
}
63+
return Object.values(transactions || {}).filter((item) => {
64+
const isUnreported = item?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID || item?.reportID === '';
65+
if (!isUnreported) {
66+
return false;
6367
}
64-
return Object.values(transactions || {}).filter((item) => {
65-
const isUnreported = item?.reportID === CONST.REPORT.UNREPORTED_REPORT_ID || item?.reportID === '';
66-
if (!isUnreported) {
67-
return false;
68-
}
69-
70-
if (isPerDiemRequest(item)) {
71-
// Only show per diem expenses if the target workspace has per diem enabled and the per diem expense was created in the same workspace
72-
const workspacePerDiemUnit = getPerDiemCustomUnit(policy);
73-
const perDiemCustomUnitID = item?.comment?.customUnit?.customUnitID;
74-
75-
return canSubmitPerDiemExpenseFromWorkspace(policy) && (!perDiemCustomUnitID || perDiemCustomUnitID === workspacePerDiemUnit?.customUnitID);
76-
}
77-
78-
return true;
79-
});
80-
},
81-
[policy],
82-
);
8368

84-
const [transactions = getEmptyArray<Transaction>()] = useOnyx(
85-
ONYXKEYS.COLLECTION.TRANSACTION,
86-
{
87-
selector: getUnreportedTransactions,
88-
canBeMissing: true,
89-
},
90-
[getUnreportedTransactions],
91-
);
69+
if (isPerDiemRequest(item)) {
70+
// Only show per diem expenses if the target workspace has per diem enabled and the per diem expense was created in the same workspace
71+
const workspacePerDiemUnit = getPerDiemCustomUnit(policy);
72+
const perDiemCustomUnitID = item?.comment?.customUnit?.customUnitID;
73+
74+
return canSubmitPerDiemExpenseFromWorkspace(policy) && (!perDiemCustomUnitID || perDiemCustomUnitID === workspacePerDiemUnit?.customUnitID);
75+
}
76+
77+
return true;
78+
});
79+
}
80+
81+
const [transactions = getEmptyArray<Transaction>()] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
82+
selector: (_transactions) => getUnreportedTransactions(_transactions),
83+
canBeMissing: true,
84+
});
9285

9386
const fetchMoreUnreportedTransactions = () => {
9487
if (!hasMoreUnreportedTransactionsResults || isLoadingUnreportedTransactions) {

src/pages/Search/EmptySearchView.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import variables from '@styles/variables';
4242
import CONST from '@src/CONST';
4343
import ONYXKEYS from '@src/ONYXKEYS';
4444
import ROUTES from '@src/ROUTES';
45-
import type {IntroSelected, PersonalDetails, Policy, Transaction} from '@src/types/onyx';
45+
import type {IntroSelected, PersonalDetails, Policy} from '@src/types/onyx';
4646
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
4747

4848
type EmptySearchViewProps = {
@@ -129,9 +129,6 @@ function EmptySearchView({similarSearchHash, type, groupBy, hasResults}: EmptySe
129129
);
130130
}
131131

132-
const hasTransactionsSelector = (transactions: OnyxCollection<Transaction>) =>
133-
Object.values(transactions ?? {}).filter((transaction) => transaction?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length > 0;
134-
135132
function EmptySearchViewContent({
136133
similarSearchHash,
137134
type,
@@ -156,7 +153,7 @@ function EmptySearchViewContent({
156153

157154
const [hasTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {
158155
canBeMissing: true,
159-
selector: hasTransactionsSelector,
156+
selector: (transactions) => Object.values(transactions ?? {}).filter((transaction) => transaction?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE).length > 0,
160157
});
161158
const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {selector: tryNewDotOnyxSelector, canBeMissing: true});
162159

src/pages/TransactionDuplicate/Confirmation.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import useLocalize from '@hooks/useLocalize';
1717
import useOnyx from '@hooks/useOnyx';
1818
import useReviewDuplicatesNavigation from '@hooks/useReviewDuplicatesNavigation';
1919
import useThemeStyles from '@hooks/useThemeStyles';
20-
import useTransactionsByID from '@hooks/useTransactionsByID';
2120
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
2221
import Navigation from '@libs/Navigation/Navigation';
2322
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
@@ -53,7 +52,14 @@ function Confirmation() {
5352
() => transactionViolations?.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)?.data?.duplicates ?? [],
5453
[transactionViolations],
5554
);
56-
const [allDuplicates] = useTransactionsByID(allDuplicateIDs);
55+
const [allDuplicates] = useOnyx(
56+
ONYXKEYS.COLLECTION.TRANSACTION,
57+
{
58+
selector: (allTransactions) => allDuplicateIDs.map((id) => allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]),
59+
canBeMissing: true,
60+
},
61+
[allDuplicateIDs],
62+
);
5763

5864
const compareResult = TransactionUtils.compareDuplicateTransactionFields(transaction, allDuplicates, reviewDuplicates?.reportID);
5965
const {goBack} = useReviewDuplicatesNavigation(Object.keys(compareResult.change ?? {}), 'confirmation', route.params.threadReportID, route.params.backTo);
@@ -63,8 +69,14 @@ function Confirmation() {
6369
const reportAction = Object.values(reportActions ?? {}).find(
6470
(action) => ReportActionsUtils.isMoneyRequestAction(action) && ReportActionsUtils.getOriginalMessage(action)?.IOUTransactionID === reviewDuplicates?.transactionID,
6571
);
66-
67-
const [duplicates] = useTransactionsByID(reviewDuplicates?.duplicates ?? []);
72+
const [duplicates] = useOnyx(
73+
ONYXKEYS.COLLECTION.TRANSACTION,
74+
{
75+
selector: (allTransactions) => reviewDuplicates?.duplicates.map((id) => allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]),
76+
canBeMissing: true,
77+
},
78+
[reviewDuplicates?.duplicates],
79+
);
6880
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`, {canBeMissing: true});
6981
const transactionsMergeParams = useMemo(
7082
() => TransactionUtils.buildMergeDuplicatesParams(reviewDuplicates, duplicates ?? [], newTransaction),

src/pages/TransactionDuplicate/DuplicateTransactionItem.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ type DuplicateTransactionItemProps = {
2121
policies: OnyxCollection<Policy>;
2222
};
2323

24-
const linkedTransactionRouteErrorSelector = (transaction: OnyxEntry<Transaction>) => transaction?.errorFields?.route ?? null;
25-
2624
function DuplicateTransactionItem({transaction, index, allReports, policies}: DuplicateTransactionItemProps) {
2725
const styles = useThemeStyles();
2826
const [userWalletTierName] = useOnyx(ONYXKEYS.USER_WALLET, {selector: (wallet) => wallet?.tierName, canBeMissing: false});
@@ -52,7 +50,7 @@ function DuplicateTransactionItem({transaction, index, allReports, policies}: Du
5250

5351
const [linkedTransactionRouteError] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${isMoneyRequestAction(action) && getOriginalMessage(action)?.IOUTransactionID}`, {
5452
canBeMissing: true,
55-
selector: linkedTransactionRouteErrorSelector,
53+
selector: (transactionItem) => transactionItem?.errorFields?.route ?? null,
5654
});
5755

5856
const contextValue = useMemo(() => ({shouldOpenReportInRHP: true}), []);

src/pages/TransactionDuplicate/ReviewBillable.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import ScreenWrapper from '@components/ScreenWrapper';
55
import useLocalize from '@hooks/useLocalize';
66
import useOnyx from '@hooks/useOnyx';
77
import useReviewDuplicatesNavigation from '@hooks/useReviewDuplicatesNavigation';
8-
import useTransactionsByID from '@hooks/useTransactionsByID';
98
import {setReviewDuplicatesKey} from '@libs/actions/Transaction';
109
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
1110
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
@@ -30,8 +29,14 @@ function ReviewBillable() {
3029
() => transactionViolations?.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)?.data?.duplicates ?? [],
3130
[transactionViolations],
3231
);
33-
34-
const [allDuplicates] = useTransactionsByID(allDuplicateIDs);
32+
const [allDuplicates] = useOnyx(
33+
ONYXKEYS.COLLECTION.TRANSACTION,
34+
{
35+
selector: (allTransactions) => allDuplicateIDs.map((id) => allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]),
36+
canBeMissing: true,
37+
},
38+
[allDuplicateIDs],
39+
);
3540
const compareResult = compareDuplicateTransactionFields(transaction, allDuplicates, reviewDuplicates?.reportID);
3641
const stepNames = Object.keys(compareResult.change ?? {}).map((key, index) => (index + 1).toString());
3742
const {currentScreenIndex, goBack, navigateToNextScreen} = useReviewDuplicatesNavigation(

src/pages/TransactionDuplicate/ReviewCategory.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import ScreenWrapper from '@components/ScreenWrapper';
55
import useLocalize from '@hooks/useLocalize';
66
import useOnyx from '@hooks/useOnyx';
77
import useReviewDuplicatesNavigation from '@hooks/useReviewDuplicatesNavigation';
8-
import useTransactionsByID from '@hooks/useTransactionsByID';
98
import {setReviewDuplicatesKey} from '@libs/actions/Transaction';
109
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
1110
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
@@ -30,7 +29,14 @@ function ReviewCategory() {
3029
() => transactionViolations?.find((violation) => violation.name === CONST.VIOLATIONS.DUPLICATED_TRANSACTION)?.data?.duplicates ?? [],
3130
[transactionViolations],
3231
);
33-
const [allDuplicates] = useTransactionsByID(allDuplicateIDs);
32+
const [allDuplicates] = useOnyx(
33+
ONYXKEYS.COLLECTION.TRANSACTION,
34+
{
35+
selector: (allTransactions) => allDuplicateIDs.map((id) => allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${id}`]),
36+
canBeMissing: true,
37+
},
38+
[allDuplicateIDs],
39+
);
3440

3541
const compareResult = compareDuplicateTransactionFields(transaction, allDuplicates, reviewDuplicates?.reportID);
3642
const stepNames = Object.keys(compareResult.change ?? {}).map((key, index) => (index + 1).toString());

0 commit comments

Comments
 (0)