Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import MenuItem from '@components/MenuItem';
import Modal from '@components/Modal';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import openSearchReport from '@components/Search/openSearchReport';
import {useSearchContext} from '@components/Search/SearchContext';
import type {SearchColumnType, SortOrder} from '@components/Search/types';
import Text from '@components/Text';
Expand Down Expand Up @@ -49,7 +50,6 @@ import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import MoneyRequestReportTableHeader from './MoneyRequestReportTableHeader';
Expand Down Expand Up @@ -266,7 +266,7 @@ function MoneyRequestReportTransactionList({
if (reportIDToNavigate) {
markReportIDAsExpense(reportIDToNavigate);
}
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute(routeParams));
openSearchReport(routeParams.reportID, backTo);
});
},
[report, reportActions, sortedTransactions, markReportIDAsExpense],
Expand Down
7 changes: 5 additions & 2 deletions src/components/Navigation/TopBar.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import React, {useContext} from 'react';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import LoadingBar from '@components/LoadingBar';
import {PressableWithoutFeedback} from '@components/Pressable';
import SearchButton from '@components/Search/SearchRouter/SearchButton';
import HelpButton from '@components/SidePanel/HelpComponents/HelpButton';
import Text from '@components/Text';
import {WideRHPContext} from '@components/WideRHPContextProvider';
import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -32,6 +33,8 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector, canBeMissing: true});
const shouldShowLoadingBarForReports = useLoadingBarVisibility();
const isAnonymousUser = isAnonymousUserUtil(session);
const {wideRHPRouteKeys} = useContext(WideRHPContext);
const isWideRhpVisible = !!wideRHPRouteKeys.length;

const displaySignIn = isAnonymousUser;
const displaySearch = !isAnonymousUser && shouldDisplaySearch;
Expand Down Expand Up @@ -68,7 +71,7 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB
{shouldDisplayHelpButton && <HelpButton />}
{displaySearch && <SearchButton />}
</View>
<LoadingBar shouldShow={shouldShowLoadingBarForReports || shouldShowLoadingBar} />
<LoadingBar shouldShow={!isWideRhpVisible && (shouldShowLoadingBarForReports || shouldShowLoadingBar)} />
</View>
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import type {SearchTransaction} from '@src/types/onyx/SearchResults';
import type {TransactionViolation} from '@src/types/onyx/TransactionViolation';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import arraysEqual from '@src/utils/arraysEqual';
import openSearchReport from './openSearchReport';
import {useSearchContext} from './SearchContext';
import SearchList from './SearchList';
import {SearchScopeProvider} from './SearchScopeProvider';
Expand Down Expand Up @@ -710,7 +711,7 @@ function Search({
setOptimisticDataForTransactionThreadPreview(item, transactionPreviewData);
}

requestAnimationFrame(() => Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo})));
openSearchReport(reportID, backTo);
},
[isMobileSelectionModeEnabled, toggleTransaction, hash, queryJSON, handleSearch, searchKey, markReportIDAsExpense],
);
Expand Down
6 changes: 6 additions & 0 deletions src/components/Search/openSearchReport/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Navigation from '@libs/Navigation/Navigation';
import ROUTES from '@src/ROUTES';

export default function openSearchReport(reportID: string | undefined, backTo: string) {
requestAnimationFrame(() => Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo})));
}
17 changes: 17 additions & 0 deletions src/components/Search/openSearchReport/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {CommonActions} from '@react-navigation/native';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
import NAVIGATORS from '@src/NAVIGATORS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';

// The search report screen is preloaded before navigating to avoid lag when opening the page. If the content is rendered in the background and then navigated, the opening experience is smoother.
export default function openSearchReport(reportID: string | undefined, backTo: string) {
navigationRef.dispatch({
...CommonActions.preload(NAVIGATORS.RIGHT_MODAL_NAVIGATOR, {
name: SCREENS.RIGHT_MODAL.SEARCH_REPORT,
params: {reportID, backTo},
}),
target: navigationRef.getRootState().key,
});
requestAnimationFrame(() => Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo})));
}
3 changes: 2 additions & 1 deletion src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type DotLottieAnimation from '@components/LottieAnimations/types';
import type {MenuItemWithLink} from '@components/MenuItemList';
import type {MultiSelectItem} from '@components/Search/FilterDropdowns/MultiSelectPopup';
import type {SingleSelectItem} from '@components/Search/FilterDropdowns/SingleSelectPopup';
import openSearchReport from '@components/Search/openSearchReport';
import type {
SearchAction,
SearchColumnType,
Expand Down Expand Up @@ -1278,7 +1279,7 @@ function createAndOpenSearchTransactionThread(item: TransactionListItemType, has
}

if (shouldNavigate) {
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: transactionThreadReport?.reportID, backTo}));
openSearchReport(transactionThreadReport?.reportID, backTo);
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import openSearchReport from '@components/Search/openSearchReport';
import ChatListItem from '@components/SelectionListWithSections/ChatListItem';
import TransactionGroupListItem from '@components/SelectionListWithSections/Search/TransactionGroupListItem';
import TransactionListItem from '@components/SelectionListWithSections/Search/TransactionListItem';
Expand All @@ -12,7 +13,6 @@ import type {
TransactionReportGroupListItemType,
TransactionWithdrawalIDGroupListItemType,
} from '@components/SelectionListWithSections/types';
import Navigation from '@navigation/Navigation';
// eslint-disable-next-line no-restricted-syntax
import type * as ReportUserActions from '@userActions/Report';
import {createTransactionThreadReport} from '@userActions/Report';
Expand All @@ -25,7 +25,6 @@ import IntlStore from '@src/languages/IntlStore';
import type {CardFeedForDisplay} from '@src/libs/CardFeedUtils';
import * as SearchUIUtils from '@src/libs/SearchUIUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import type {Connections} from '@src/types/onyx/Policy';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
Expand All @@ -45,6 +44,7 @@ jest.mock('@userActions/Search', () => ({
...jest.requireActual<typeof SearchUtils>('@userActions/Search'),
updateSearchResultsWithTransactionThreadReportID: jest.fn(),
}));
jest.mock('@components/Search/openSearchReport', () => jest.fn());

const adminAccountID = 18439984;
const adminEmail = 'admin@policy.com';
Expand Down Expand Up @@ -2807,12 +2807,12 @@ describe('SearchUIUtils', () => {

test('Should not navigate if shouldNavigate = false', () => {
SearchUIUtils.createAndOpenSearchTransactionThread(transactionListItem, hash, backTo, undefined, false);
expect(Navigation.navigate).not.toHaveBeenCalled();
expect(openSearchReport).not.toHaveBeenCalled();
});

test('Should handle navigation if shouldNavigate = true', () => {
SearchUIUtils.createAndOpenSearchTransactionThread(transactionListItem, hash, backTo, undefined, true);
expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.SEARCH_REPORT.getRoute({reportID: threadReportID, backTo}));
expect(openSearchReport).toHaveBeenCalledWith(threadReportID, backTo);
});
});

Expand Down