Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 @@ -50,6 +49,7 @@ 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);
}
openSearchReport(routeParams.reportID, backTo);
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute(routeParams));
});
},
[report, reportActions, sortedTransactions, markReportIDAsExpense],
Expand Down
7 changes: 2 additions & 5 deletions src/components/Navigation/TopBar.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, {useContext} from 'react';
import React 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 @@ -33,8 +32,6 @@ 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 @@ -71,7 +68,7 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB
{shouldDisplayHelpButton && <HelpButton />}
{displaySearch && <SearchButton />}
</View>
<LoadingBar shouldShow={!isWideRhpVisible && (shouldShowLoadingBarForReports || shouldShowLoadingBar)} />
<LoadingBar shouldShow={shouldShowLoadingBarForReports || shouldShowLoadingBar} />
</View>
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
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 @@ -711,9 +710,9 @@
setOptimisticDataForTransactionThreadPreview(item, transactionPreviewData);
}

openSearchReport(reportID, backTo);
requestAnimationFrame(() => Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo})));
},
[isMobileSelectionModeEnabled, type, toggleTransaction, hash, queryJSON, handleSearch, searchKey, markReportIDAsExpense],

Check warning on line 715 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has an unnecessary dependency: 'type'. Either exclude it or remove the dependency array

Check warning on line 715 in src/components/Search/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useCallback has an unnecessary dependency: 'type'. Either exclude it or remove the dependency array
);

const currentColumns = useMemo(() => {
Expand Down
6 changes: 0 additions & 6 deletions src/components/Search/openSearchReport/index.native.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/components/Search/openSearchReport/index.ts

This file was deleted.

36 changes: 18 additions & 18 deletions src/components/WideRHPContextProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,6 @@ function extractNavigationKeys(state: NavigationState | PartialState<NavigationS
return keys;
}

/**
* Returns the route key of the last visible RHP navigator,
* or undefined if RHP is not currently visible.
*/
function getLastVisibleRHPRouteKey(state: NavigationState): string | undefined {
const lastFullScreenRouteIndex = state.routes.findLastIndex((route) => isFullScreenName(route.name));
const lastRHPRouteIndex = state.routes.findLastIndex((route) => route.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR);

// Both routes have to be present and the RHP have to be after last full screen for it to be visible.
if (lastFullScreenRouteIndex === -1 || lastRHPRouteIndex === -1 || lastFullScreenRouteIndex > lastRHPRouteIndex) {
return undefined;
}

return state?.routes.at(lastRHPRouteIndex)?.key;
}

/**
* Calculates the optimal width for the receipt pane RHP based on window width.
* Ensures the RHP doesn't exceed maximum width and maintains minimum responsive width.
Expand Down Expand Up @@ -115,14 +99,30 @@ function WideRHPContextProvider({children}: React.PropsWithChildren) {
const [expenseReportIDs, setExpenseReportIDs] = useState<Set<string>>(new Set());
const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: expenseReportSelector, canBeMissing: true});

// Return undefined if RHP is not the last route
const lastVisibleRHPRouteKey = useRootNavigationState((state) => {
// Safe handling when navigation is not yet initialized
if (!state) {
return undefined;
}
const lastFullScreenRouteIndex = state?.routes.findLastIndex((route) => isFullScreenName(route.name));
const lastRHPRouteIndex = state?.routes.findLastIndex((route) => route.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR);

// Both routes have to be present and the RHP have to be after last full screen for it to be visible.
if (lastFullScreenRouteIndex === -1 || lastRHPRouteIndex === -1 || lastFullScreenRouteIndex > lastRHPRouteIndex) {
return undefined;
}

return state?.routes.at(lastRHPRouteIndex)?.key;
});

const wideRHPRouteKeys = useMemo(() => {
const rootState = navigationRef.getRootState();

if (!rootState) {
return [];
}

const lastVisibleRHPRouteKey = getLastVisibleRHPRouteKey(rootState);
const lastRHPRoute = rootState.routes.find((route) => route.key === lastVisibleRHPRouteKey);

if (!lastRHPRoute) {
Expand All @@ -133,7 +133,7 @@ function WideRHPContextProvider({children}: React.PropsWithChildren) {
const currentKeys = allWideRHPRouteKeys.filter((key) => lastRHPKeys.has(key));

return currentKeys;
}, [allWideRHPRouteKeys]);
}, [allWideRHPRouteKeys, lastVisibleRHPRouteKey]);

/**
* Determines whether the secondary overlay should be displayed.
Expand Down
3 changes: 1 addition & 2 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ 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 @@ -1313,7 +1312,7 @@ function createAndOpenSearchTransactionThread(item: TransactionListItemType, has
}

if (shouldNavigate) {
openSearchReport(transactionThreadReport?.reportID, backTo);
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: 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,6 +1,5 @@
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 @@ -13,6 +12,7 @@ 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,6 +25,7 @@ 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 @@ -44,7 +45,6 @@ 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 @@ -2876,12 +2876,12 @@ describe('SearchUIUtils', () => {

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

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

Expand Down
Loading