Skip to content

Commit 4df272e

Browse files
committed
refatore: remove getReportNameValuePairs final
1 parent 9284d17 commit 4df272e

32 files changed

Lines changed: 285 additions & 297 deletions

src/components/Attachments/AttachmentCarousel/extractAttachments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function extractAttachments(
2828
parentReportAction?: OnyxEntry<ReportAction>;
2929
reportActions?: OnyxEntry<ReportActions>;
3030
report: OnyxEntry<Report>;
31-
isReportArchived?: boolean;
31+
isReportArchived: boolean | undefined;
3232
},
3333
) {
3434
const targetNote = privateNotes?.[Number(accountID)]?.note ?? '';

src/components/MoneyReportHeader.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,14 +1363,11 @@ function MoneyReportHeader({
13631363
duplicateTransactionViolations,
13641364
iouReport,
13651365
chatIOUReport,
1366-
false,
1367-
undefined,
1368-
undefined,
13691366
isChatIOUReportArchived,
13701367
);
13711368
removeTransaction(transaction.transactionID);
13721369
});
1373-
goBackRoute = getNavigationUrlOnMoneyRequestDelete(transaction.transactionID, requestParentReportAction, iouReport, chatIOUReport, false, isChatIOUReportArchived);
1370+
goBackRoute = getNavigationUrlOnMoneyRequestDelete(transaction.transactionID, requestParentReportAction, iouReport, chatIOUReport, isChatIOUReportArchived, false);
13741371
}
13751372

13761373
if (goBackRoute) {

src/components/MoneyRequestHeader.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,8 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
462462
duplicateTransactionViolations,
463463
iouReport,
464464
chatIOUReport,
465-
true,
466-
undefined,
467-
undefined,
468465
isChatIOUReportArchived,
466+
true,
469467
);
470468
removeTransaction(transaction.transactionID);
471469
}

src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import React, {useEffect} from 'react';
22
import {View} from 'react-native';
33
import PrevNextButtons from '@components/PrevNextButtons';
44
import Text from '@components/Text';
5+
import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet';
56
import useLocalize from '@hooks/useLocalize';
67
import useOnyx from '@hooks/useOnyx';
78
import useThemeStyles from '@hooks/useThemeStyles';
8-
import {selectArchivedReportsIdSet, selectFilteredReportActions} from '@libs/ReportUtils';
9+
import {selectFilteredReportActions} from '@libs/ReportUtils';
910
import {getSections, getSortedSections} from '@libs/SearchUIUtils';
1011
import Navigation from '@navigation/Navigation';
1112
import {saveLastSearchParams} from '@userActions/ReportNavigation';
@@ -31,10 +32,7 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo
3132
selector: selectFilteredReportActions,
3233
});
3334

34-
const [archivedReportsIdSet = new Set<string>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
35-
canBeMissing: true,
36-
selector: selectArchivedReportsIdSet,
37-
});
35+
const archivedReportsIdSet = useArchivedReportsIdSet();
3836

3937
const {type, status, sortBy, sortOrder, groupBy} = lastSearchQuery?.queryJSON ?? {};
4038
let results: Array<string | undefined> = [];

src/components/ReportActionItem/MoneyRequestReceiptView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function MoneyRequestReceiptView({
208208
return;
209209
}
210210
if (parentReportAction) {
211-
cleanUpMoneyRequest(transaction?.transactionID ?? linkedTransactionID, parentReportAction, report.reportID, iouReport, chatIOUReport, true, isChatIOUReportArchived);
211+
cleanUpMoneyRequest(transaction?.transactionID ?? linkedTransactionID, parentReportAction, report.reportID, iouReport, chatIOUReport, isChatIOUReportArchived, true);
212212
return;
213213
}
214214
}

src/components/Search/SearchFiltersChatsSelector.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {usePersonalDetails} from '@components/OnyxListItemProvider';
44
import {useOptionsList} from '@components/OptionListContextProvider';
55
import SelectionList from '@components/SelectionListWithSections';
66
import InviteMemberListItem from '@components/SelectionListWithSections/InviteMemberListItem';
7+
import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet';
78
import useDebouncedState from '@hooks/useDebouncedState';
89
import useLocalize from '@hooks/useLocalize';
910
import useOnyx from '@hooks/useOnyx';
@@ -54,14 +55,16 @@ function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreen
5455
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
5556
const cleanSearchTerm = useMemo(() => searchTerm.trim().toLowerCase(), [searchTerm]);
5657
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true});
58+
const archivedReportsIdSet = useArchivedReportsIdSet();
5759

5860
const selectedOptions = useMemo<OptionData[]>(() => {
5961
return selectedReportIDs.map((id) => {
6062
const report = getSelectedOptionData(createOptionFromReport({...reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`], reportID: id}, personalDetails, reportAttributesDerived));
61-
const alternateText = getAlternateText(report, {});
63+
const isReportArchived = archivedReportsIdSet.has(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`);
64+
const alternateText = getAlternateText(report, {}, isReportArchived, {});
6265
return {...report, alternateText};
6366
});
64-
}, [personalDetails, reportAttributesDerived, reports, selectedReportIDs]);
67+
}, [personalDetails, reportAttributesDerived, reports, selectedReportIDs, archivedReportsIdSet]);
6568

6669
const defaultOptions = useMemo(() => {
6770
if (!areOptionsInitialized || !isScreenTransitionEnd) {

src/components/Search/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SearchTableHeader, {getExpenseHeaders} from '@components/SelectionListWit
1111
import type {ReportActionListItemType, SearchListItem, SelectionListHandle, TransactionGroupListItemType, TransactionListItemType} from '@components/SelectionListWithSections/types';
1212
import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
1313
import {WideRHPContext} from '@components/WideRHPContextProvider';
14+
import useArchivedReportsIdSet from '@hooks/useArchivedReportsIdSet';
1415
import useCardFeedsForDisplay from '@hooks/useCardFeedsForDisplay';
1516
import useLocalize from '@hooks/useLocalize';
1617
import useNetwork from '@hooks/useNetwork';
@@ -30,7 +31,7 @@ import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTop
3031
import type {PlatformStackNavigationProp} from '@libs/Navigation/PlatformStackNavigation/types';
3132
import Performance from '@libs/Performance';
3233
import {getIOUActionForTransactionID} from '@libs/ReportActionsUtils';
33-
import {canEditFieldOfMoneyRequest, selectArchivedReportsIdSet, selectFilteredReportActions} from '@libs/ReportUtils';
34+
import {canEditFieldOfMoneyRequest, selectFilteredReportActions} from '@libs/ReportUtils';
3435
import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString} from '@libs/SearchQueryUtils';
3536
import {
3637
createAndOpenSearchTransactionThread,
@@ -272,10 +273,7 @@ function Search({queryJSON, searchResults, onSearchListScroll, contentContainerS
272273
return filtered;
273274
}, [violations, searchResults]);
274275

275-
const [archivedReportsIdSet = new Set<string>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
276-
canBeMissing: true,
277-
selector: selectArchivedReportsIdSet,
278-
});
276+
const archivedReportsIdSet = useArchivedReportsIdSet();
279277

280278
const [exportReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {
281279
canEvict: false,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {isArchivedReport} from '@libs/ReportUtils';
2+
import type {ArchivedReportsIDSet} from '@libs/SearchUIUtils';
3+
import ONYXKEYS from '@src/ONYXKEYS';
4+
import useDeepCompareRef from './useDeepCompareRef';
5+
import useOnyx from './useOnyx';
6+
7+
/**
8+
* Hook that returns a Set of archived report IDs
9+
*/
10+
function useArchivedReportsIdSet(): ArchivedReportsIDSet {
11+
const [archivedReportsIdSet = new Set<string>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
12+
canBeMissing: true,
13+
selector: (all): ArchivedReportsIDSet => {
14+
const ids = new Set<string>();
15+
if (!all) {
16+
return ids;
17+
}
18+
19+
for (const [key, value] of Object.entries(all)) {
20+
if (isArchivedReport(value)) {
21+
ids.add(key);
22+
}
23+
}
24+
return ids;
25+
},
26+
});
27+
28+
return useDeepCompareRef(archivedReportsIdSet) ?? new Set<string>();
29+
}
30+
31+
export default useArchivedReportsIdSet;

src/hooks/useIsReportReadyToDisplay.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {OnyxEntry} from 'react-native-onyx';
33
import {canUserPerformWriteAction} from '@libs/ReportUtils';
44
import type {Report} from '@src/types/onyx';
55

6-
function useIsReportReadyToDisplay(report: OnyxEntry<Report>, reportIDFromRoute: string | undefined, isReportArchived = false) {
6+
function useIsReportReadyToDisplay(report: OnyxEntry<Report>, reportIDFromRoute: string | undefined, isReportArchived: boolean | undefined) {
77
/**
88
* When false the report is not ready to be fully displayed
99
*/

src/hooks/useSelectedTransactionsActions.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ import {
1515
canEditFieldOfMoneyRequest,
1616
canHoldUnholdReportAction,
1717
canUserPerformWriteAction as canUserPerformWriteActionReportUtils,
18-
isArchivedReport,
1918
isInvoiceReport,
2019
isMoneyRequestReport as isMoneyRequestReportUtils,
2120
isTrackExpenseReport,
2221
} from '@libs/ReportUtils';
23-
import type {ArchivedReportsIDSet} from '@libs/SearchUIUtils';
2422
import type {IOUType} from '@src/CONST';
2523
import CONST from '@src/CONST';
2624
import ONYXKEYS from '@src/ONYXKEYS';
2725
import ROUTES from '@src/ROUTES';
2826
import type {Policy, Report, ReportAction, Session, Transaction} from '@src/types/onyx';
27+
import useArchivedReportsIdSet from './useArchivedReportsIdSet';
2928
import useDuplicateTransactionsAndViolations from './useDuplicateTransactionsAndViolations';
3029
import useLocalize from './useLocalize';
3130
import useNetworkWithOfflineStatus from './useNetworkWithOfflineStatus';
@@ -86,22 +85,7 @@ function useSelectedTransactionsActions({
8685
const isTrackExpenseThread = isTrackExpenseReport(report);
8786
const isInvoice = isInvoiceReport(report);
8887

89-
const [archivedReportsIdSet = new Set<string>()] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
90-
canBeMissing: true,
91-
selector: (all): ArchivedReportsIDSet => {
92-
const ids = new Set<string>();
93-
if (!all) {
94-
return ids;
95-
}
96-
97-
for (const [key, value] of Object.entries(all)) {
98-
if (isArchivedReport(value)) {
99-
ids.add(key);
100-
}
101-
}
102-
return ids;
103-
},
104-
});
88+
const archivedReportsIdSet = useArchivedReportsIdSet();
10589

10690
let iouType: IOUType = CONST.IOU.TYPE.SUBMIT;
10791

@@ -141,10 +125,10 @@ function useSelectedTransactionsActions({
141125
duplicateTransactionViolations,
142126
iouReport,
143127
chatReport,
128+
isChatIOUReportArchived,
144129
false,
145130
deletedTransactionIDs,
146131
selectedTransactionIDs,
147-
isChatIOUReportArchived,
148132
);
149133
deletedTransactionIDs.push(transactionID);
150134
if (action.childReportID) {

0 commit comments

Comments
 (0)