Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
31 changes: 18 additions & 13 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type {Screen} from './SCREENS';
import type {CompanyCardFeedWithDomainID} from './types/onyx';
import type {ConnectionName, SageIntacctMappingName} from './types/onyx/Policy';
import type {CustomFieldType} from './types/onyx/PolicyEmployee';
import type AssertTypesNotEqual from './types/utils/AssertTypesNotEqual';

type WorkspaceCompanyCardsAssignCardParams = {
policyID: string;
Expand Down Expand Up @@ -168,8 +167,25 @@ const ROUTES = {
getRoute: ({reportID}: {reportID: string}) => `search/r/${reportID}/reject` as const,
},
TRANSACTION_HOLD_REASON_RHP: 'search/hold',
TRANSACTION_HOLD_REASON_SEARCH: {
route: 'search/hold/search/:backTo?',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why another /search path needed?
Can this just be search/hold/:backTo??

@marufsharifi marufsharifi Feb 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkhutornyi, we need a search-specific route so the background search context survives refresh; otherwise, the app can’t restore the expected Reports > Submit screen and falls back to Expenses (the behavior in #78983). Using search/hold/:backTo? would conflate search and non-search flows, and could remap non-search RHP visits into Search on refresh. Keeping /search/hold/search/:backTo? makes the search relationship explicit and safe

getRoute: (backTo?: string) => {
if (!backTo) {
return 'search/hold/search' as const;
}
return `search/hold/search/${encodeURIComponent(backTo)}` as const;
},
},
SEARCH_REJECT_REASON_RHP: 'search/reject',
MOVE_TRANSACTIONS_SEARCH_RHP: 'search/move-transactions',
MOVE_TRANSACTIONS_SEARCH_RHP: {
route: 'search/move-transactions/search/:backTo?',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Can this just be search/move-transactions/:backTo??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same rationale as hold

getRoute: (backTo?: string) => {
if (!backTo) {
return 'search/move-transactions/search' as const;
}
return `search/move-transactions/search/${encodeURIComponent(backTo)}` as const;
},
},

// This is a utility route used to go to the user's concierge chat, or the sign-in page if the user's not authenticated
CONCIERGE: 'concierge',
Expand Down Expand Up @@ -3950,15 +3966,4 @@ type Route = {

type DynamicRouteSuffix = (typeof DYNAMIC_ROUTES)[keyof typeof DYNAMIC_ROUTES]['path'];

type RoutesValidationError = 'Error: One or more routes defined within `ROUTES` have not correctly used `as const` in their `getRoute` function return value.';

/**
* Represents all routes in the app as a union of literal strings.
*
* If TS throws on this line, it implies that one or more routes defined within `ROUTES` have not correctly used
* `as const` in their `getRoute` function return value.
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type RouteIsPlainString = AssertTypesNotEqual<string, Route, RoutesValidationError>;

export type {Route, DynamicRouteSuffix};
3 changes: 2 additions & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ const SCREENS = {
SAVED_SEARCH_RENAME_RHP: 'Search_Saved_Search_Rename_RHP',
ADVANCED_FILTERS_IN_RHP: 'Search_Advanced_Filters_In_RHP',
TRANSACTION_HOLD_REASON_RHP: 'Search_Transaction_Hold_Reason_RHP',
TRANSACTION_HOLD_REASON_SEARCH: 'Search_Transaction_Hold_Reason_Search',
SEARCH_REJECT_REASON_RHP: 'Search_Reject_Reason_RHP',
TRANSACTIONS_CHANGE_REPORT_SEARCH_RHP: 'Search_Transactions_Change_Report_RHP',
TRANSACTIONS_CHANGE_REPORT_SEARCH_RHP: 'Search_Transactions_Change_Report_Search',
},
SETTINGS: {
ROOT: 'Settings_Root',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ const OPTIONS_PER_SCREEN: Partial<Record<Screen, PlatformStackNavigationOptions>
[SCREENS.SEARCH.TRANSACTION_HOLD_REASON_RHP]: {
animation: Animations.NONE,
},
[SCREENS.SEARCH.TRANSACTION_HOLD_REASON_SEARCH]: {
animation: Animations.NONE,
},
[SCREENS.SEARCH.SEARCH_REJECT_REASON_RHP]: {
animation: Animations.NONE,
},
Expand Down Expand Up @@ -961,6 +964,7 @@ const SearchReportActionsModalStackNavigator = createModalStackNavigator<SearchR
[SCREENS.SEARCH.MONEY_REQUEST_REPORT_HOLD_TRANSACTIONS]: () => require<ReactComponentModule>('../../../../pages/Search/SearchHoldReasonPage').default,
[SCREENS.SEARCH.MONEY_REQUEST_REPORT_REJECT_TRANSACTIONS]: () => require<ReactComponentModule>('../../../../pages/Search/SearchRejectReasonPage').default,
[SCREENS.SEARCH.TRANSACTION_HOLD_REASON_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchHoldReasonPage').default,
[SCREENS.SEARCH.TRANSACTION_HOLD_REASON_SEARCH]: () => require<ReactComponentModule>('../../../../pages/Search/SearchHoldReasonPage').default,
[SCREENS.SEARCH.SEARCH_REJECT_REASON_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchRejectReasonPage').default,
[SCREENS.SEARCH.TRANSACTIONS_CHANGE_REPORT_SEARCH_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchTransactionsChangeReport').default,
});
Expand Down
12 changes: 11 additions & 1 deletion src/libs/Navigation/helpers/getAdaptedStateFromPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {RHP_TO_DOMAIN, RHP_TO_SEARCH, RHP_TO_SETTINGS, RHP_TO_SIDEBAR, RHP_TO_WORKSPACE, RHP_TO_WORKSPACES_LIST} from '@libs/Navigation/linkingConfig/RELATIONS';
import type {NavigationPartialRoute, RootNavigatorParamList} from '@libs/Navigation/types';
import CONST from '@src/CONST';
import {getSearchParamFromPath} from '@src/libs/Url';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand All @@ -21,7 +22,7 @@
import replacePathInNestedState from './replacePathInNestedState';

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 25 in src/libs/Navigation/helpers/getAdaptedStateFromPath.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 25 in src/libs/Navigation/helpers/getAdaptedStateFromPath.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -90,9 +91,18 @@
const routeNameForLookup = getSearchScreenNameForRoute(route);
if (RHP_TO_SEARCH[routeNameForLookup]) {
const paramsFromRoute = getParamsFromRoute(RHP_TO_SEARCH[routeNameForLookup]);
const copiedParams = paramsFromRoute.length > 0 ? pick(route.params, paramsFromRoute) : {};
let queryParam: Record<string, string> = {};
if (route.path) {
const query = getSearchParamFromPath(route.path, 'q');
if (query) {
queryParam = {q: query};
}
}

const searchRoute = {
name: RHP_TO_SEARCH[routeNameForLookup],
params: paramsFromRoute.length > 0 ? pick(route.params, paramsFromRoute) : undefined,
params: Object.keys({...copiedParams, ...queryParam}).length > 0 ? {...copiedParams, ...queryParam} : undefined,
};
return {
name: NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const SEARCH_TO_RHP: Partial<Record<keyof SearchFullscreenNavigatorParamList, st
SCREENS.SEARCH.ADVANCED_FILTERS_STATUS_RHP,
SCREENS.SEARCH.REPORT_VERIFY_ACCOUNT,
SCREENS.SEARCH.TRANSACTION_HOLD_REASON_RHP,
SCREENS.SEARCH.TRANSACTION_HOLD_REASON_SEARCH,
SCREENS.SEARCH.SEARCH_REJECT_REASON_RHP,
SCREENS.SEARCH.TRANSACTIONS_CHANGE_REPORT_SEARCH_RHP,
SCREENS.SEARCH.COLUMNS_RHP,
Expand Down
9 changes: 8 additions & 1 deletion src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1829,8 +1829,15 @@ const config: LinkingOptions<RootNavigatorParamList>['config'] = {
[SCREENS.SEARCH.MONEY_REQUEST_REPORT_HOLD_TRANSACTIONS]: ROUTES.SEARCH_MONEY_REQUEST_REPORT_HOLD_TRANSACTIONS.route,
[SCREENS.SEARCH.MONEY_REQUEST_REPORT_REJECT_TRANSACTIONS]: ROUTES.SEARCH_MONEY_REQUEST_REPORT_REJECT_TRANSACTIONS.route,
[SCREENS.SEARCH.TRANSACTION_HOLD_REASON_RHP]: ROUTES.TRANSACTION_HOLD_REASON_RHP,
[SCREENS.SEARCH.TRANSACTION_HOLD_REASON_SEARCH]: {
path: ROUTES.TRANSACTION_HOLD_REASON_SEARCH.route,
exact: true,
},
[SCREENS.SEARCH.SEARCH_REJECT_REASON_RHP]: ROUTES.SEARCH_REJECT_REASON_RHP,
[SCREENS.SEARCH.TRANSACTIONS_CHANGE_REPORT_SEARCH_RHP]: ROUTES.MOVE_TRANSACTIONS_SEARCH_RHP,
[SCREENS.SEARCH.TRANSACTIONS_CHANGE_REPORT_SEARCH_RHP]: {
path: ROUTES.MOVE_TRANSACTIONS_SEARCH_RHP.route,
exact: true,
},
},
},
[SCREENS.RIGHT_MODAL.SEARCH_ADVANCED_FILTERS]: {
Expand Down
11 changes: 11 additions & 0 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Route} from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import type {ConnectionName} from '@src/types/onyx/Policy';
import type {SaveSearchItem} from '@src/types/onyx/SaveSearch';
Expand Down Expand Up @@ -91,6 +92,7 @@ import {getDecodedCategoryName} from './CategoryUtils';
import {convertToDisplayString} from './CurrencyUtils';
import DateUtils from './DateUtils';
import interceptAnonymousUser from './interceptAnonymousUser';
import isSearchTopmostFullScreenRoute from './Navigation/helpers/isSearchTopmostFullScreenRoute';
import Navigation from './Navigation/Navigation';
import Parser from './Parser';
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
Expand Down Expand Up @@ -4511,6 +4513,14 @@ function getTableMinWidth(columns: SearchColumnType[]) {
return minWidth;
}

function navigateToSearchRHP(route: {route: string; getRoute: (backTo?: string) => Route}, fallbackRoute?: Route) {
if (isSearchTopmostFullScreenRoute()) {
Navigation.navigate(route.getRoute(Navigation.getActiveRoute()));
} else {
Navigation.navigate(fallbackRoute ?? route.getRoute());
}
}

function shouldShowDeleteOption(
selectedTransactions: Record<string, SelectedTransactionInfo>,
currentSearchResults: SearchResults['data'] | undefined,
Expand Down Expand Up @@ -4617,6 +4627,7 @@ export {
getTableMinWidth,
getCustomColumns,
getCustomColumnDefault,
navigateToSearchRHP,
shouldShowDeleteOption,
getToFieldValueForTransaction,
isTodoSearch,
Expand Down
60 changes: 59 additions & 1 deletion src/libs/Url.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import escapeRegExp from 'lodash/escapeRegExp';
import 'react-native-url-polyfill/auto';
import CONST from '@src/CONST';
import type {Route} from '@src/ROUTES';
Expand Down Expand Up @@ -70,6 +71,63 @@ function getSearchParamFromUrl(currentUrl: string, param: string) {
return currentUrl ? new URL(currentUrl).searchParams.get(param) : null;
}

function getSearchParamFromPath(path: string, param: string) {
if (!path) {
return null;
}

const [pathWithoutHash] = path.split('#', 2);
const queryIndex = pathWithoutHash.indexOf('?');

const safeDecode = (value: string) => {
try {
return decodeURIComponent(value);
} catch {
return value;
}
};

const getParamFromQueryString = (queryString: string) => {
if (!queryString) {
return null;
}

const match = queryString.match(new RegExp(`(?:^|&)${escapeRegExp(param)}=([^&]*)`));
const rawValue = match?.[1];

if (!rawValue) {
return null;
}

// Match previous behavior: decode the query value twice and truncate on decoded delimiters.
return safeDecode(safeDecode(rawValue));
};

if (queryIndex !== -1) {
const queryString = pathWithoutHash.slice(queryIndex + 1);
const directParam = getParamFromQueryString(queryString);
if (directParam !== null) {
return directParam;
}
}

// Fallback: extract params from encoded backTo segment (e.g., ".../search/<encoded>/amount")
const encodedBackToMatch = pathWithoutHash.match(/\/search\/([^/]+)/);
const encodedBackTo = encodedBackToMatch?.[1];
if (!encodedBackTo) {
return null;
}

const decodedBackTo = safeDecode(encodedBackTo);
const backToQueryIndex = decodedBackTo.indexOf('?');
if (backToQueryIndex === -1) {
return null;
}

const backToQueryString = decodedBackTo.slice(backToQueryIndex + 1);
return getParamFromQueryString(backToQueryString);
}

type UrlWithParams<TBase extends string> = `${TBase}${'' | `?${string}` | `&${string}`}`;
type UrlParams = {backTo?: string; forwardTo?: string} & Record<string, string | number | undefined>;
/**
Expand All @@ -93,4 +151,4 @@ function getUrlWithParams<TBase extends string, TParams extends UrlParams>(baseU
return (queryString ? `${path}?${queryString}` : path) as UrlWithParams<TBase>;
}

export {getSearchParamFromUrl, hasSameExpensifyOrigin, getPathFromURL, appendParam, hasURL, addLeadingForwardSlash, extractUrlDomain, getUrlWithParams};
export {getSearchParamFromUrl, getSearchParamFromPath, hasSameExpensifyOrigin, getPathFromURL, appendParam, hasURL, addLeadingForwardSlash, extractUrlDomain, getUrlWithParams};
10 changes: 5 additions & 5 deletions src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import {
isSelfDM,
} from '@libs/ReportUtils';
import {buildSearchQueryJSON} from '@libs/SearchQueryUtils';
import {shouldShowDeleteOption} from '@libs/SearchUIUtils';
import {navigateToSearchRHP, shouldShowDeleteOption} from '@libs/SearchUIUtils';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {hasTransactionBeenRejected} from '@libs/TransactionUtils';
import type {ReceiptFile} from '@pages/iou/request/step/IOURequestStepScan/types';
Expand Down Expand Up @@ -904,7 +904,7 @@ function SearchPage({route}: SearchPageProps) {
const isDismissed = areAllTransactionsFromSubmitter ? dismissedHoldUseExplanation : dismissedRejectUseExplanation;

if (isDismissed) {
Navigation.navigate(ROUTES.TRANSACTION_HOLD_REASON_RHP);
navigateToSearchRHP(ROUTES.TRANSACTION_HOLD_REASON_SEARCH, ROUTES.TRANSACTION_HOLD_REASON_RHP);
} else if (areAllTransactionsFromSubmitter) {
setIsHoldEducationalModalVisible(true);
} else {
Expand Down Expand Up @@ -985,7 +985,7 @@ function SearchPage({route}: SearchPageProps) {
icon: expensifyIcons.DocumentMerge,
value: CONST.SEARCH.BULK_ACTION_TYPES.CHANGE_REPORT,
shouldCloseModalOnSelect: true,
onSelected: () => Navigation.navigate(ROUTES.MOVE_TRANSACTIONS_SEARCH_RHP),
onSelected: () => Navigation.navigate(ROUTES.MOVE_TRANSACTIONS_SEARCH_RHP.getRoute()),
});
}

Expand Down Expand Up @@ -1262,15 +1262,15 @@ function SearchPage({route}: SearchPageProps) {
setIsHoldEducationalModalVisible(false);
setNameValuePair(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION, true, false, !isOffline);
if (hash && selectedTransactionsKeys.length > 0) {
Navigation.navigate(ROUTES.TRANSACTION_HOLD_REASON_RHP);
navigateToSearchRHP(ROUTES.TRANSACTION_HOLD_REASON_SEARCH, ROUTES.TRANSACTION_HOLD_REASON_RHP);
}
}, [hash, selectedTransactionsKeys.length, isOffline]);

const dismissRejectModalBasedOnAction = useCallback(() => {
if (rejectModalAction === CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.HOLD) {
dismissRejectUseExplanation();
if (hash && selectedTransactionsKeys.length > 0) {
Navigation.navigate(ROUTES.TRANSACTION_HOLD_REASON_RHP);
navigateToSearchRHP(ROUTES.TRANSACTION_HOLD_REASON_SEARCH, ROUTES.TRANSACTION_HOLD_REASON_RHP);
}
} else {
dismissRejectUseExplanation();
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/UrlTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,30 @@ describe('Url', () => {
expect(Url.getUrlWithParams(baseUrl, params)).toBe(expected);
});
});
describe('getSearchParamFromPath', () => {
it.each([
['returns null when no query string', 'search/hold/search', 'q', null],
// cspell:disable-next-line
['reads query param from path', 'search/hold/search?q=type%3aexpense&name=Expenses', 'q', 'type:expense'],
['returns null for missing param', 'search/hold/search?name=Expenses', 'q', null],
// cspell:disable-next-line
['handles hash fragments', 'search/hold/search?q=type%3aexpense#section', 'q', 'type:expense'],
['decodes ampersand', 'search/hold/search?q=AT%26T', 'q', 'AT&T'],
// cspell:disable-next-line
['decodes slash', 'search/hold/search?q=foo%2fbar', 'q', 'foo/bar'],
['decodes encoded percent', 'search/hold/search?q=100%25', 'q', '100%'],
['returns raw value when decoding fails', 'search/hold/search?q=100%', 'q', '100%'],
// cspell:disable-next-line
['double decodes encoded percent', 'search/hold/search?q=foo%252fbar', 'q', 'foo/bar'],
[
'reads query from encoded backTo segment',
// cspell:disable-next-line
'create/split-expense/overview/4936432564974252/324399768798079300/0/search/%2Fsearch%3Fq=type%253Aexpense-report%2520sortBy%253Adate%2520sortOrder%253Adesc%2520action%253Asubmit%2520from%253A21227763/amount',
'q',
'type:expense-report sortBy:date sortOrder:desc action:submit from:21227763',
],
])('%s', (_, path, param, expected) => {
expect(Url.getSearchParamFromPath(path, param)).toBe(expected);
});
});
});
Loading