Skip to content

Commit

Permalink
Merge pull request #44001 from software-mansion-labs/search/fix-remov…
Browse files Browse the repository at this point in the history
…ing-rhp-report-from-nav-state

[Search v1] Report screen in RHP is removed from navigation history after navigating to the chat in CentralPane
  • Loading branch information
luacmartins authored Jun 20, 2024
2 parents b90ac12 + 296e8dd commit 41d02de
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/libs/Navigation/linkTo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam
const extractedPolicyID = extractPolicyIDFromPath(`/${path}`);
const policyIDFromState = getPolicyIDFromState(rootState);
const policyID = extractedPolicyID ?? policyIDFromState ?? policyIDs;
const lastRoute = rootState?.routes?.at(-1);

const isNarrowLayout = getIsNarrowLayout();

const isFullScreenOnTop = rootState.routes?.at(-1)?.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR;
const isFullScreenOnTop = lastRoute?.name === NAVIGATORS.FULL_SCREEN_NAVIGATOR;

// policyIDs is present only on SCREENS.SEARCH.CENTRAL_PANE and it's displayed in the url as a query param, on the other pages this parameter is called policyID and it's shown in the url in the format: /w/:policyID
if (policyID && !isFullScreenOnTop && !policyIDs) {
Expand All @@ -66,9 +67,11 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam

const action: StackNavigationAction = getActionFromState(stateFromPath, linkingConfig.config);

const isReportInRhpOpened = lastRoute?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR && lastRoute?.state?.routes?.some((route) => route?.name === SCREENS.RIGHT_MODAL.SEARCH_REPORT);

// If action type is different than NAVIGATE we can't change it to the PUSH safely
if (action?.type === CONST.NAVIGATION.ACTION_TYPE.NAVIGATE) {
const topRouteName = rootState?.routes?.at(-1)?.name;
const topRouteName = lastRoute?.name;
const isTargetNavigatorOnTop = topRouteName === action.payload.name;

const isTargetScreenDifferentThanCurrent = !!(!topmostCentralPaneRoute || topmostCentralPaneRoute.name !== action.payload.params?.screen);
Expand Down Expand Up @@ -201,6 +204,11 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam
}
}

// When we navigate from the ReportScreen opened in RHP, this page shouldn't be removed from the navigation state to allow users to go back to it.
if (isReportInRhpOpened && action) {
action.type = CONST.NAVIGATION.ACTION_TYPE.PUSH;
}

if (action !== undefined) {
root.dispatch(action);
} else {
Expand Down

0 comments on commit 41d02de

Please sign in to comment.