From 30cd3a2126eb35bf6f265aa70ea28c5573cee3ef Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 19 Nov 2025 12:27:25 +0800 Subject: [PATCH 1/4] fix more messages are not loaded when reaches the end --- src/components/Search/index.tsx | 54 ++++++------- src/libs/SearchUIUtils.ts | 138 +++++++++++++++++--------------- 2 files changed, 99 insertions(+), 93 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 14e492ac2430..2e641b8e8044 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -399,19 +399,19 @@ function Search({ const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0; const prevIsSearchResultEmpty = usePrevious(isSearchResultsEmpty); - const [data, dataLength] = useMemo(() => { + const [filteredData, filteredDataLength, allLength] = useMemo(() => { if (searchResults === undefined || !isDataLoaded) { - return [[], 0]; + return [[], 0, 0]; } // Group-by option cannot be used for chats or tasks const isChat = type === CONST.SEARCH.DATA_TYPES.CHAT; const isTask = type === CONST.SEARCH.DATA_TYPES.TASK; if (validGroupBy && (isChat || isTask)) { - return [[], 0]; + return [[], 0, 0]; } - const data1 = getSections({ + const [filteredData, allLength] = getSections({ type, data: searchResults.data, currentAccountID: accountID, @@ -424,7 +424,7 @@ function Search({ queryJSON, isActionLoadingSet, }); - return [data1, data1.length]; + return [filteredData, filteredData.length, allLength]; }, [searchKey, exportReportActions, validGroupBy, isDataLoaded, searchResults, type, archivedReportsIdSet, formatPhoneNumber, accountID, queryJSON, email, isActionLoadingSet]); useEffect(() => { @@ -441,7 +441,7 @@ function Search({ return; } - handleSearch({queryJSON, searchKey, offset, shouldCalculateTotals, prevReportsLength: dataLength}); + handleSearch({queryJSON, searchKey, offset, shouldCalculateTotals, prevReportsLength: filteredDataLength}); // We don't need to run the effect on change of isFocused. // eslint-disable-next-line react-compiler/react-compiler @@ -461,7 +461,7 @@ function Search({ } const newTransactionList: SelectedTransactions = {}; if (validGroupBy || type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) { - for (const transactionGroup of data) { + for (const transactionGroup of filteredData) { if (!Object.hasOwn(transactionGroup, 'transactions') || !('transactions' in transactionGroup)) { continue; } @@ -507,7 +507,7 @@ function Search({ } } } else { - for (const transactionItem of data) { + for (const transactionItem of filteredData) { if (!Object.hasOwn(transactionItem, 'transactionID') || !('transactionID' in transactionItem)) { continue; } @@ -555,11 +555,11 @@ function Search({ return; } - setSelectedTransactions(newTransactionList, data); + setSelectedTransactions(newTransactionList, filteredData); isRefreshingSelection.current = true; // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps - }, [data, setSelectedTransactions, areAllMatchingItemsSelected, isFocused, outstandingReportsByPolicyID]); + }, [filteredData, setSelectedTransactions, areAllMatchingItemsSelected, isFocused, outstandingReportsByPolicyID]); useEffect(() => { if (!isSearchResultsEmpty || prevIsSearchResultEmpty) { @@ -589,11 +589,11 @@ function Search({ return; } - if (!data.length || isRefreshingSelection.current) { + if (!filteredData.length || isRefreshingSelection.current) { return; } const areItemsGrouped = !!validGroupBy || type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT; - const flattenedItems = areItemsGrouped ? (data as TransactionGroupListItemType[]).flatMap((item) => item.transactions) : data; + const flattenedItems = areItemsGrouped ? (filteredData as TransactionGroupListItemType[]).flatMap((item) => item.transactions) : filteredData; const areAllItemsSelected = flattenedItems.length === Object.keys(selectedTransactions).length; // If the user has selected all the expenses in their view but there are more expenses matched by the search @@ -602,7 +602,7 @@ function Search({ if (!areAllItemsSelected) { selectAllMatchingItems(false); } - }, [isFocused, data, searchResults?.search?.hasMoreResults, selectedTransactions, selectAllMatchingItems, shouldShowSelectAllMatchingItems, validGroupBy, type]); + }, [isFocused, filteredData, searchResults?.search?.hasMoreResults, selectedTransactions, selectAllMatchingItems, shouldShowSelectAllMatchingItems, validGroupBy, type]); const toggleTransaction = useCallback( (item: SearchListItem, itemTransactions?: TransactionListItemType[]) => { @@ -619,7 +619,7 @@ function Search({ if (isTransactionPendingDelete(item)) { return; } - setSelectedTransactions(prepareTransactionsList(item, selectedTransactions, outstandingReportsByPolicyID), data); + setSelectedTransactions(prepareTransactionsList(item, selectedTransactions, outstandingReportsByPolicyID), filteredData); return; } @@ -631,7 +631,7 @@ function Search({ delete reducedSelectedTransactions[transaction.keyForList]; } - setSelectedTransactions(reducedSelectedTransactions, data); + setSelectedTransactions(reducedSelectedTransactions, filteredData); return; } @@ -644,10 +644,10 @@ function Search({ .map((transactionItem) => mapTransactionItemToSelectedEntry(transactionItem, outstandingReportsByPolicyID)), ), }, - data, + filteredData, ); }, - [data, selectedTransactions, outstandingReportsByPolicyID, setSelectedTransactions], + [filteredData, selectedTransactions, outstandingReportsByPolicyID, setSelectedTransactions], ); const onSelectRow = useCallback( @@ -790,7 +790,7 @@ function Search({ const sortedSelectedData = useMemo( () => - getSortedSections(type, status, data, localeCompare, sortBy, sortOrder, validGroupBy).map((item) => { + getSortedSections(type, status, filteredData, localeCompare, sortBy, sortOrder, validGroupBy).map((item) => { const baseKey = isChat ? `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${(item as ReportActionListItemType).reportActionID}` : `${ONYXKEYS.COLLECTION.TRANSACTION}${(item as TransactionListItemType).transactionID}`; @@ -811,7 +811,7 @@ function Search({ return mapToItemWithAdditionalInfo(item, selectedTransactions, canSelectMultiple, shouldAnimateInHighlight, hash); }), - [type, status, data, sortBy, sortOrder, validGroupBy, isChat, newSearchResultKeys, selectedTransactions, canSelectMultiple, localeCompare, hash], + [type, status, filteredData, sortBy, sortOrder, validGroupBy, isChat, newSearchResultKeys, selectedTransactions, canSelectMultiple, localeCompare, hash], ); useEffect(() => { @@ -829,12 +829,12 @@ function Search({ const fetchMoreResults = useCallback(() => { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems || offset > data.length - CONST.SEARCH.RESULTS_PAGE_SIZE) { + if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems || offset > allLength - CONST.SEARCH.RESULTS_PAGE_SIZE) { return; } setOffset((prev) => prev + CONST.SEARCH.RESULTS_PAGE_SIZE); - }, [isFocused, searchResults?.search?.hasMoreResults, shouldShowLoadingMoreItems, shouldShowLoadingState, offset, data.length]); + }, [isFocused, searchResults?.search?.hasMoreResults, shouldShowLoadingMoreItems, shouldShowLoadingState, offset, allLength]); const toggleAllTransactions = useCallback(() => { const areItemsGrouped = !!validGroupBy || isExpenseReportType; @@ -848,13 +848,13 @@ function Search({ if (areItemsGrouped) { setSelectedTransactions( Object.fromEntries( - (data as TransactionGroupListItemType[]).flatMap((item) => + (filteredData as TransactionGroupListItemType[]).flatMap((item) => item.transactions .filter((t) => !isTransactionPendingDelete(t)) .map((transactionItem) => mapTransactionItemToSelectedEntry(transactionItem, outstandingReportsByPolicyID)), ), ), - data, + filteredData, ); return; @@ -862,13 +862,13 @@ function Search({ setSelectedTransactions( Object.fromEntries( - (data as TransactionListItemType[]) + (filteredData as TransactionListItemType[]) .filter((t) => !isTransactionPendingDelete(t)) .map((transactionItem) => mapTransactionItemToSelectedEntry(transactionItem, outstandingReportsByPolicyID)), ), - data, + filteredData, ); - }, [clearSelectedTransactions, data, validGroupBy, selectedTransactions, setSelectedTransactions, outstandingReportsByPolicyID, isExpenseReportType]); + }, [clearSelectedTransactions, filteredData, validGroupBy, selectedTransactions, setSelectedTransactions, outstandingReportsByPolicyID, isExpenseReportType]); const onLayout = useCallback(() => handleSelectionListScroll(sortedSelectedData, searchListRef.current), [handleSelectionListScroll, sortedSelectedData]); @@ -911,7 +911,7 @@ function Search({ ); } - const visibleDataLength = data.filter((item) => item.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || isOffline).length; + const visibleDataLength = filteredData.filter((item) => item.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || isOffline).length; if (shouldShowEmptyState(isDataLoaded, visibleDataLength, searchResults?.search?.type)) { return ( diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 30ab92ca71b3..a6a8239d54c0 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1016,7 +1016,7 @@ function getTransactionsSections( currentAccountID: number | undefined, currentUserEmail: string, formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], -): TransactionListItemType[] { +): [TransactionListItemType[], number] { const shouldShowMerchant = getShouldShowMerchant(data); const doesDataContainAPastYearTransaction = shouldShowYear(data); const {shouldShowAmountInWideColumn, shouldShowTaxAmountInWideColumn} = getWideAmountIndicators(data); @@ -1101,7 +1101,7 @@ function getTransactionsSections( transactionsSections.push(transactionSection); } } - return transactionsSections; + return [transactionsSections, transactionsSections.length]; } /** @@ -1314,61 +1314,60 @@ function getTaskSections( data: OnyxTypes.SearchResults['data'], formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], archivedReportsIDList?: ArchivedReportsIDSet, -): TaskListItemType[] { - return ( - Object.keys(data) - .filter(isReportEntry) - // Ensure that the reports that were passed are tasks, and not some other - // type of report that was sent as the parent - .filter((key) => isTaskListItemType(data[key] as SearchListItem)) - .map((key) => { - const taskItem = data[key] as SearchTask; - const personalDetails = data.personalDetailsList; - - const assignee = personalDetails?.[taskItem.managerID] ?? emptyPersonalDetails; - const createdBy = personalDetails?.[taskItem.accountID] ?? emptyPersonalDetails; - const formattedAssignee = formatPhoneNumber(getDisplayNameOrDefault(assignee)); - const formattedCreatedBy = formatPhoneNumber(getDisplayNameOrDefault(createdBy)); - - const report = getReportOrDraftReport(taskItem.reportID) ?? taskItem; - const parentReport = getReportOrDraftReport(taskItem.parentReportID); - - const doesDataContainAPastYearTransaction = shouldShowYear(data); - const reportName = StringUtils.lineBreaksToSpaces(Parser.htmlToText(taskItem.reportName)); - const description = StringUtils.lineBreaksToSpaces(Parser.htmlToText(taskItem.description)); - - const result: TaskListItemType = { - ...taskItem, - reportName, - description, - assignee, - formattedAssignee, - createdBy, - formattedCreatedBy, - keyForList: taskItem.reportID, - shouldShowYear: doesDataContainAPastYearTransaction, - }; +): [TaskListItemType[], number] { + const tasks = Object.keys(data) + .filter(isReportEntry) + // Ensure that the reports that were passed are tasks, and not some other + // type of report that was sent as the parent + .filter((key) => isTaskListItemType(data[key] as SearchListItem)) + .map((key) => { + const taskItem = data[key] as SearchTask; + const personalDetails = data.personalDetailsList; + + const assignee = personalDetails?.[taskItem.managerID] ?? emptyPersonalDetails; + const createdBy = personalDetails?.[taskItem.accountID] ?? emptyPersonalDetails; + const formattedAssignee = formatPhoneNumber(getDisplayNameOrDefault(assignee)); + const formattedCreatedBy = formatPhoneNumber(getDisplayNameOrDefault(createdBy)); + + const report = getReportOrDraftReport(taskItem.reportID) ?? taskItem; + const parentReport = getReportOrDraftReport(taskItem.parentReportID); + + const doesDataContainAPastYearTransaction = shouldShowYear(data); + const reportName = StringUtils.lineBreaksToSpaces(Parser.htmlToText(taskItem.reportName)); + const description = StringUtils.lineBreaksToSpaces(Parser.htmlToText(taskItem.description)); + + const result: TaskListItemType = { + ...taskItem, + reportName, + description, + assignee, + formattedAssignee, + createdBy, + formattedCreatedBy, + keyForList: taskItem.reportID, + shouldShowYear: doesDataContainAPastYearTransaction, + }; - if (parentReport && personalDetails) { - // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 - // eslint-disable-next-line @typescript-eslint/no-deprecated - const policy = getPolicy(parentReport.policyID); - const isParentReportArchived = archivedReportsIDList?.has(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${parentReport?.reportID}`); - const parentReportName = getReportName(parentReport, policy, undefined, undefined, undefined, undefined, undefined, isParentReportArchived); - const icons = getIcons(parentReport, personalDetails, null, '', -1, policy, undefined, isParentReportArchived); - const parentReportIcon = icons?.at(0); - - result.parentReportName = parentReportName; - result.parentReportIcon = parentReportIcon; - } + if (parentReport && personalDetails) { + // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 + // eslint-disable-next-line @typescript-eslint/no-deprecated + const policy = getPolicy(parentReport.policyID); + const isParentReportArchived = archivedReportsIDList?.has(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${parentReport?.reportID}`); + const parentReportName = getReportName(parentReport, policy, undefined, undefined, undefined, undefined, undefined, isParentReportArchived); + const icons = getIcons(parentReport, personalDetails, null, '', -1, policy, undefined, isParentReportArchived); + const parentReportIcon = icons?.at(0); + + result.parentReportName = parentReportName; + result.parentReportIcon = parentReportIcon; + } - if (report) { - result.report = report; - } + if (report) { + result.report = report; + } - return result; - }) - ); + return result; + }); + return [tasks, tasks.length]; } /** Creates transaction thread report and navigates to it from the search page */ @@ -1394,7 +1393,7 @@ function createAndOpenSearchTransactionThread(item: TransactionListItemType, has * * Do not use directly, use only via `getSections()` facade. */ -function getReportActionsSections(data: OnyxTypes.SearchResults['data']): ReportActionListItemType[] { +function getReportActionsSections(data: OnyxTypes.SearchResults['data']): [ReportActionListItemType[], number] { const reportActionItems: ReportActionListItemType[] = []; const transactions = Object.keys(data) @@ -1409,10 +1408,13 @@ function getReportActionsSections(data: OnyxTypes.SearchResults['data']): Report .filter(isPolicyEntry) .map((key) => data[key]); + let n = 0; + for (const key in data) { if (isReportActionEntry(key)) { - const reportActions = data[key]; - for (const reportAction of Object.values(reportActions)) { + const reportActions = Object.values(data[key]); + n += reportActions.length; + for (const reportAction of reportActions) { const from = reportAction.accountID ? (data.personalDetailsList?.[reportAction.accountID] ?? emptyPersonalDetails) : emptyPersonalDetails; const report = data[`${ONYXKEYS.COLLECTION.REPORT}${reportAction.reportID}`] ?? {}; const policy = data[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`] ?? {}; @@ -1444,7 +1446,7 @@ function getReportActionsSections(data: OnyxTypes.SearchResults['data']): Report } } } - return reportActionItems; + return [reportActionItems, n]; } /** @@ -1461,7 +1463,7 @@ function getReportSections( formatPhoneNumber: LocaleContextProps['formatPhoneNumber'], isActionLoadingSet: ReadonlySet | undefined, reportActions: Record = {}, -): TransactionGroupListItemType[] { +): [TransactionGroupListItemType[], number] { const shouldShowMerchant = getShouldShowMerchant(data); const doesDataContainAPastYearTransaction = shouldShowYear(data); @@ -1586,7 +1588,8 @@ function getReportSections( } } - return Object.values(reportIDToTransactions); + const reportIDToTransactionsValues = Object.values(reportIDToTransactions); + return [reportIDToTransactionsValues, reportIDToTransactionsValues.length]; } /** @@ -1595,7 +1598,7 @@ function getReportSections( * * Do not use directly, use only via `getSections()` facade. */ -function getMemberSections(data: OnyxTypes.SearchResults['data'], queryJSON: SearchQueryJSON | undefined): TransactionMemberGroupListItemType[] { +function getMemberSections(data: OnyxTypes.SearchResults['data'], queryJSON: SearchQueryJSON | undefined): [TransactionMemberGroupListItemType[], number] { const memberSections: Record = {}; for (const key in data) { @@ -1621,7 +1624,8 @@ function getMemberSections(data: OnyxTypes.SearchResults['data'], queryJSON: Sea } } - return Object.values(memberSections); + const memberSectionsValues = Object.values(memberSections); + return [memberSectionsValues, memberSectionsValues.length]; } /** @@ -1630,7 +1634,7 @@ function getMemberSections(data: OnyxTypes.SearchResults['data'], queryJSON: Sea * * Do not use directly, use only via `getSections()` facade. */ -function getCardSections(data: OnyxTypes.SearchResults['data'], queryJSON: SearchQueryJSON | undefined): TransactionCardGroupListItemType[] { +function getCardSections(data: OnyxTypes.SearchResults['data'], queryJSON: SearchQueryJSON | undefined): [TransactionCardGroupListItemType[], number] { const cardSections: Record = {}; for (const key in data) { @@ -1657,7 +1661,8 @@ function getCardSections(data: OnyxTypes.SearchResults['data'], queryJSON: Searc } } - return Object.values(cardSections); + const cardSectionsValues = Object.values(cardSections); + return [cardSectionsValues, cardSectionsValues.length]; } /** @@ -1666,7 +1671,7 @@ function getCardSections(data: OnyxTypes.SearchResults['data'], queryJSON: Searc * * Do not use directly, use only via `getSections()` facade. */ -function getWithdrawalIDSections(data: OnyxTypes.SearchResults['data'], queryJSON: SearchQueryJSON | undefined): TransactionWithdrawalIDGroupListItemType[] { +function getWithdrawalIDSections(data: OnyxTypes.SearchResults['data'], queryJSON: SearchQueryJSON | undefined): [TransactionWithdrawalIDGroupListItemType[], number] { const withdrawalIDSections: Record = {}; for (const key in data) { @@ -1690,7 +1695,8 @@ function getWithdrawalIDSections(data: OnyxTypes.SearchResults['data'], queryJSO } } - return Object.values(withdrawalIDSections); + const withdrawalIDSectionsValues = Object.values(withdrawalIDSections); + return [withdrawalIDSectionsValues, withdrawalIDSectionsValues.length]; } /** From b567563cd1d82d87bd9e34226e83621defbaf1ef Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 19 Nov 2025 12:41:15 +0800 Subject: [PATCH 2/4] lint --- src/components/Search/index.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 2e641b8e8044..b04ad7102931 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -399,7 +399,7 @@ function Search({ const shouldShowLoadingMoreItems = !shouldShowLoadingState && searchResults?.search?.isLoading && searchResults?.search?.offset > 0; const prevIsSearchResultEmpty = usePrevious(isSearchResultsEmpty); - const [filteredData, filteredDataLength, allLength] = useMemo(() => { + const [filteredData, filteredDataLength, allDataLength] = useMemo(() => { if (searchResults === undefined || !isDataLoaded) { return [[], 0, 0]; } @@ -411,7 +411,7 @@ function Search({ return [[], 0, 0]; } - const [filteredData, allLength] = getSections({ + const [filteredData1, allLength] = getSections({ type, data: searchResults.data, currentAccountID: accountID, @@ -424,7 +424,7 @@ function Search({ queryJSON, isActionLoadingSet, }); - return [filteredData, filteredData.length, allLength]; + return [filteredData1, filteredData1.length, allLength]; }, [searchKey, exportReportActions, validGroupBy, isDataLoaded, searchResults, type, archivedReportsIdSet, formatPhoneNumber, accountID, queryJSON, email, isActionLoadingSet]); useEffect(() => { @@ -829,12 +829,12 @@ function Search({ const fetchMoreResults = useCallback(() => { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems || offset > allLength - CONST.SEARCH.RESULTS_PAGE_SIZE) { + if (!isFocused || !searchResults?.search?.hasMoreResults || shouldShowLoadingState || shouldShowLoadingMoreItems || offset > allDataLength - CONST.SEARCH.RESULTS_PAGE_SIZE) { return; } setOffset((prev) => prev + CONST.SEARCH.RESULTS_PAGE_SIZE); - }, [isFocused, searchResults?.search?.hasMoreResults, shouldShowLoadingMoreItems, shouldShowLoadingState, offset, allLength]); + }, [isFocused, searchResults?.search?.hasMoreResults, shouldShowLoadingMoreItems, shouldShowLoadingState, offset, allDataLength]); const toggleAllTransactions = useCallback(() => { const areItemsGrouped = !!validGroupBy || isExpenseReportType; From 65f7bca0c2e69bff91d3cd45e1b6d2558f401927 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 19 Nov 2025 12:48:38 +0800 Subject: [PATCH 3/4] fix test --- tests/unit/Search/SearchUIUtilsTest.ts | 36 +++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 0dd018053943..c5f68488f45b 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1754,15 +1754,15 @@ describe('SearchUIUtils', () => { describe('Test getSections', () => { it('should return getReportActionsSections result when type is CHAT', () => { - expect( - SearchUIUtils.getSections({ - type: CONST.SEARCH.DATA_TYPES.CHAT, - data: searchResults.data, - currentAccountID: 2074551, - currentUserEmail: '', - formatPhoneNumber, - }), - ).toStrictEqual(reportActionListItems); + const [filteredReportActions, allReportActionsLength] = SearchUIUtils.getSections({ + type: CONST.SEARCH.DATA_TYPES.CHAT, + data: searchResults.data, + currentAccountID: 2074551, + currentUserEmail: '', + formatPhoneNumber, + }); + expect(filteredReportActions).toStrictEqual(reportActionListItems); + expect(allReportActionsLength).toBe(6); }); it('should return getTransactionsSections result when groupBy is undefined', () => { @@ -1773,7 +1773,7 @@ describe('SearchUIUtils', () => { currentAccountID: 20745, currentUserEmail: '', formatPhoneNumber, - }), + })[0], ).toEqual(transactionsListItems); }); @@ -1798,7 +1798,7 @@ describe('SearchUIUtils', () => { currentAccountID: 2074551, currentUserEmail: '', formatPhoneNumber, - }) as TransactionListItemType[]; + })[0] as TransactionListItemType[]; const distanceTransaction = result.find((item) => item.transactionID === distanceTransactionID); @@ -1830,7 +1830,7 @@ describe('SearchUIUtils', () => { currentAccountID: 2074551, currentUserEmail: '', formatPhoneNumber, - }) as TransactionGroupListItemType[]; + })[0] as TransactionGroupListItemType[]; const reportGroup = result.find((group) => group.transactions?.some((transaction) => transaction.transactionID === distanceTransactionID)); @@ -1851,7 +1851,7 @@ describe('SearchUIUtils', () => { currentAccountID: 2074551, currentUserEmail: '', formatPhoneNumber, - }), + })[0], ).toStrictEqual(transactionReportGroupListItems); }); @@ -1890,14 +1890,14 @@ describe('SearchUIUtils', () => { currentAccountID: 2074551, currentUserEmail: '', formatPhoneNumber, - }); + })[0]; const resultReportFirst = SearchUIUtils.getSections({ type: CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT, data: testDataReportFirst, currentAccountID: 2074551, currentUserEmail: '', formatPhoneNumber, - }); + })[0]; expect(resultTransactionFirst).toBeDefined(); expect(Array.isArray(resultTransactionFirst)).toBe(true); @@ -1918,7 +1918,7 @@ describe('SearchUIUtils', () => { currentUserEmail: '', formatPhoneNumber, groupBy: CONST.SEARCH.GROUP_BY.FROM, - }), + })[0], ).toStrictEqual(transactionMemberGroupListItems); }); @@ -1931,7 +1931,7 @@ describe('SearchUIUtils', () => { currentUserEmail: '', formatPhoneNumber, groupBy: CONST.SEARCH.GROUP_BY.CARD, - }), + })[0], ).toStrictEqual(transactionCardGroupListItems); }); @@ -1944,7 +1944,7 @@ describe('SearchUIUtils', () => { currentUserEmail: '', formatPhoneNumber, groupBy: CONST.SEARCH.GROUP_BY.WITHDRAWAL_ID, - }), + })[0], ).toStrictEqual(transactionWithdrawalIDGroupListItems); }); }); From 015e076a60ce012a01741b477b534f1e1cb9d0ac Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 19 Nov 2025 20:11:04 +0800 Subject: [PATCH 4/4] fix type --- .../MoneyRequestReportView/MoneyRequestReportNavigation.tsx | 2 +- .../Search/TransactionGroupListItem.tsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx index 416975a083ac..8e86b92ad90c 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportNavigation.tsx @@ -39,7 +39,7 @@ function MoneyRequestReportNavigation({reportID, shouldDisplayNarrowVersion}: Mo const {type, status, sortBy, sortOrder, groupBy} = lastSearchQuery?.queryJSON ?? {}; let results: Array = []; if (!!type && !!currentSearchResults?.data && !!currentSearchResults?.search) { - const searchData = getSections({ + const [searchData] = getSections({ type, data: currentSearchResults.data, currentAccountID: currentUserDetails.accountID, diff --git a/src/components/SelectionListWithSections/Search/TransactionGroupListItem.tsx b/src/components/SelectionListWithSections/Search/TransactionGroupListItem.tsx index 318f8764bf19..54afb3815608 100644 --- a/src/components/SelectionListWithSections/Search/TransactionGroupListItem.tsx +++ b/src/components/SelectionListWithSections/Search/TransactionGroupListItem.tsx @@ -104,14 +104,14 @@ function TransactionGroupListItem({ if (!transactionsSnapshot?.data) { return []; } - const sectionData = getSections({ + const [sectionData] = getSections({ type: CONST.SEARCH.DATA_TYPES.EXPENSE, data: transactionsSnapshot?.data, currentAccountID: accountID, currentUserEmail: currentUserDetails.email ?? '', formatPhoneNumber, isActionLoadingSet, - }) as TransactionListItemType[]; + }) as [TransactionListItemType[], number]; return sectionData.map((transactionItem) => ({ ...transactionItem, isSelected: selectedTransactionIDsSet.has(transactionItem.transactionID),