From 405a695ac4d0a2879f8925c298bcaac4217f5634 Mon Sep 17 00:00:00 2001 From: Mateusz Titz Date: Fri, 27 Sep 2024 10:25:48 +0200 Subject: [PATCH] Simplify generating backTo param in Search --- src/components/Search/index.tsx | 4 ++-- src/components/SelectionList/Search/ReportListItem.tsx | 2 +- src/components/SelectionList/types.ts | 4 ---- src/libs/SearchUtils.ts | 7 +++---- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index d9c8f751ac70..b415d91b7ab4 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -227,7 +227,7 @@ function Search({queryJSON}: SearchProps) { } const ListItem = SearchUtils.getListItem(type, status); - const data = SearchUtils.getSections(type, status, searchResults.data, searchResults.search, queryJSON.inputQuery); + const data = SearchUtils.getSections(type, status, searchResults.data, searchResults.search); const sortedData = SearchUtils.getSortedSections(type, status, data, sortBy, sortOrder); const sortedSelectedData = sortedData.map((item) => mapToItemWithSelectionInfo(item, selectedTransactions, canSelectMultiple)); @@ -294,7 +294,7 @@ function Search({queryJSON}: SearchProps) { SearchActions.createTransactionThread(hash, item.transactionID, reportID, item.moneyRequestReportActionID); } - const backTo = ROUTES.SEARCH_CENTRAL_PANE.getRoute({query: queryJSON.inputQuery}); + const backTo = Navigation.getActiveRoute(); if (SearchUtils.isReportActionListItemType(item)) { const reportActionID = item.reportActionID; diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index 63705bda90f1..2c23c3ede4c5 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -84,7 +84,7 @@ function ReportListItem({ }; const openReportInRHP = (transactionItem: TransactionListItemType) => { - const backTo = ROUTES.SEARCH_CENTRAL_PANE.getRoute({query: reportItem.currentSearchQuery}); + const backTo = Navigation.getActiveRoute(); Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: transactionItem.transactionThreadReportID, backTo})); }; diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index 3fa901073e0e..b0d657b202c6 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -1,6 +1,5 @@ import type {MutableRefObject, ReactElement, ReactNode} from 'react'; import type {GestureResponderEvent, InputModeOptions, LayoutChangeEvent, SectionListData, StyleProp, TextInput, TextStyle, ViewStyle} from 'react-native'; -import type {SearchQueryString} from '@components/Search/types'; import type {BrickRoad} from '@libs/WorkspacesSettingsUtils'; // eslint-disable-next-line no-restricted-imports import type CursorStyles from '@styles/utils/cursor/types'; @@ -236,9 +235,6 @@ type ReportListItemType = ListItem & /** List of transactions that belong to this report */ transactions: TransactionListItemType[]; - - /** The current search query that was used to display these report items */ - currentSearchQuery: SearchQueryString; }; type ListItemProps = CommonListItemProps & { diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index fa50fbc0ce47..703c4df5a29c 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -250,7 +250,7 @@ function getIOUReportName(data: OnyxTypes.SearchResults['data'], reportItem: Sea return reportItem.reportName; } -function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search'], currentSearchQuery: SearchQueryString): ReportListItemType[] { +function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']): ReportListItemType[] { const shouldShowMerchant = getShouldShowMerchant(data); const doesDataContainAPastYearTransaction = shouldShowYear(data); @@ -269,7 +269,6 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx from: data.personalDetailsList?.[reportItem.accountID ?? -1], to: reportItem.managerID ? data.personalDetailsList?.[reportItem.managerID] : emptyPersonalDetails, transactions, - currentSearchQuery, reportName: isIOUReport ? getIOUReportName(data, reportItem) : reportItem.reportName, }; } else if (isTransactionEntry(key)) { @@ -318,14 +317,14 @@ function getListItem(type: SearchDataTypes, status: SearchStatus): ListItemType< return ReportListItem; } -function getSections(type: SearchDataTypes, status: SearchStatus, data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search'], currentSearchQuery: SearchQueryString) { +function getSections(type: SearchDataTypes, status: SearchStatus, data: OnyxTypes.SearchResults['data'], metadata: OnyxTypes.SearchResults['search']) { if (type === CONST.SEARCH.DATA_TYPES.CHAT) { return getReportActionsSections(data); } if (status === CONST.SEARCH.STATUS.EXPENSE.ALL) { return getTransactionsSections(data, metadata); } - return getReportSections(data, metadata, currentSearchQuery); + return getReportSections(data, metadata); } function getSortedSections(type: SearchDataTypes, status: SearchStatus, data: ListItemDataType, sortBy?: SearchColumnType, sortOrder?: SortOrder) {