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
4 changes: 2 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ const ROUTES = {
REPORT: 'r',
REPORT_WITH_ID: {
route: 'r/:reportID?/:reportActionID?',
getRoute: (reportID: string | undefined, reportActionID?: string, referrer?: string, moneyRequestReportActionID?: string, transactionID?: string) => {
getRoute: (reportID: string | undefined, reportActionID?: string, referrer?: string, moneyRequestReportActionID?: string, transactionID?: string, backTo?: string) => {
if (!reportID) {
Log.warn('Invalid reportID is used to build the REPORT_WITH_ID route');
}
Expand All @@ -384,7 +384,7 @@ const ROUTES = {

const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : '';

return `${baseRoute}${queryString}` as const;
return getUrlWithBackToParam(`${baseRoute}${queryString}` as const, backTo);
},
},
REPORT_AVATAR: {
Expand Down
12 changes: 10 additions & 2 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,20 +475,25 @@ type NavigateToReportWithPolicyCheckPayload = MergeExclusive<{report: OnyxEntry<
reportActionID?: string;
referrer?: string;
policyIDToCheck?: string;
backTo?: string;
};

/**
* Navigates to a report passed as a param (as an id or report object) and checks whether the target object belongs to the currently selected workspace.
* If not, the current workspace is set to global.
*/
function navigateToReportWithPolicyCheck({report, reportID, reportActionID, referrer, policyIDToCheck}: NavigateToReportWithPolicyCheckPayload, forceReplace = false, ref = navigationRef) {
function navigateToReportWithPolicyCheck(
{report, reportID, reportActionID, referrer, policyIDToCheck, backTo}: NavigateToReportWithPolicyCheckPayload,
forceReplace = false,
ref = navigationRef,
) {
const targetReport = reportID ? {reportID, ...allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]} : report;
const policyID = policyIDToCheck ?? getPolicyIDFromState(navigationRef.getRootState() as State<RootNavigatorParamList>);
const policyMemberAccountIDs = getPolicyEmployeeAccountIDs(policyID);
const shouldOpenAllWorkspace = isEmptyObject(targetReport) ? true : !doesReportBelongToWorkspace(targetReport, policyMemberAccountIDs, policyID);

if ((shouldOpenAllWorkspace && !policyID) || !shouldOpenAllWorkspace) {
linkTo(ref.current, ROUTES.REPORT_WITH_ID.getRoute(targetReport?.reportID, reportActionID, referrer), {forceReplace: !!forceReplace});
linkTo(ref.current, ROUTES.REPORT_WITH_ID.getRoute(targetReport?.reportID, reportActionID, referrer, undefined, undefined, backTo), {forceReplace: !!forceReplace});
return;
}

Expand All @@ -515,6 +520,9 @@ function navigateToReportWithPolicyCheck({report, reportID, reportActionID, refe
return;
}

if (backTo) {
params.backTo = backTo;
}
ref.dispatch(
StackActions.push(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, {
policyID: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function navigateToReport({reportID}: PushNotificationData): Promise<void> {
}

Log.info('[PushNotification] onSelected() - Navigation is ready. Navigating...', false, {reportID});
Navigation.navigateToReportWithPolicyCheck({reportID: String(reportID), policyIDToCheck: policyID});
Navigation.navigateToReportWithPolicyCheck({reportID: String(reportID), policyIDToCheck: policyID, backTo: Navigation.getActiveRoute()});

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.

Coming from the #62261 checklist: We missed handling the case where opening a notification on the same active route leads to a duplicated navigation stack.

updateLastVisitedPath(ROUTES.REPORT_WITH_ID.getRoute(String(reportID)));
} catch (error) {
let errorMessage = String(error);
Expand Down
5 changes: 5 additions & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
} from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
Expand Down Expand Up @@ -318,6 +319,10 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
Navigation.dismissModal();
return;
}
if (backTo) {
Navigation.goBack(backTo as Route, {shouldPopToTop: true});
return;
}
Navigation.goBack(undefined, {shouldPopToTop: true});
}, [isInNarrowPaneModal, backTo]);

Expand Down