Skip to content

Commit d7542be

Browse files
luacmartinsOSBotify
authored andcommitted
Merge pull request #44444 from software-mansion-labs/fix/link-to-without-central-pane
Fix navigating between CentralPane screens (cherry picked from commit f757005)
1 parent 751f540 commit d7542be

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/libs/Navigation/linkTo/index.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,21 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam
7272

7373
// If action type is different than NAVIGATE we can't change it to the PUSH safely
7474
if (action?.type === CONST.NAVIGATION.ACTION_TYPE.NAVIGATE) {
75-
const actionParams: ActionPayloadParams = action.payload.params;
75+
const actionPayloadParams: ActionPayloadParams = action.payload.params;
7676
const topRouteName = lastRoute?.name;
77+
78+
// CentralPane screens aren't nested in any navigator, if actionPayloadParams?.screen is undefined, it means the screen name and parameters have to be read directly from action.payload
79+
const targetName = actionPayloadParams?.screen ?? action.payload.name;
80+
const targetParams = actionPayloadParams?.params ?? actionPayloadParams;
7781
const isTargetNavigatorOnTop = topRouteName === action.payload.name;
7882

79-
const isTargetScreenDifferentThanCurrent = !!(!topmostCentralPaneRoute || topmostCentralPaneRoute.name !== (actionParams?.screen ?? action.payload.name));
83+
const isTargetScreenDifferentThanCurrent = !!(!topmostCentralPaneRoute || topmostCentralPaneRoute.name !== targetName);
8084
const areParamsDifferent =
81-
actionParams?.screen === SCREENS.REPORT
85+
targetName === SCREENS.REPORT
8286
? getTopmostReportId(rootState) !== getTopmostReportId(stateFromPath)
8387
: !shallowCompare(
8488
omitBy(topmostCentralPaneRoute?.params as Record<string, unknown> | undefined, (value) => value === undefined),
85-
omitBy(actionParams?.params as Record<string, unknown> | undefined, (value) => value === undefined),
89+
omitBy(targetParams as Record<string, unknown> | undefined, (value) => value === undefined),
8690
);
8791

8892
// If this action is navigating to the report screen and the top most navigator is different from the one we want to navigate - PUSH the new screen to the top of the stack by default
@@ -110,8 +114,8 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam
110114
}
111115

112116
// If we navigate to SCREENS.SEARCH.CENTRAL_PANE, it's necessary to pass the current policyID, but we have to remember that this param is called policyIDs on this page
113-
if (actionParams?.screen === SCREENS.SEARCH.CENTRAL_PANE && actionParams?.params && policyID) {
114-
(actionParams.params as Record<string, string | undefined>).policyIDs = policyID;
117+
if (targetName === SCREENS.SEARCH.CENTRAL_PANE && targetParams && policyID) {
118+
(targetParams as Record<string, string | undefined>).policyIDs = policyID;
115119
}
116120

117121
// If the type is UP, we deeplinked into one of the RHP flows and we want to replace the current screen with the previous one in the flow

src/libs/NavigationUtils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import SCREENS from '@src/SCREENS';
22
import type {CentralPaneName} from './Navigation/types';
33

4-
const CENTRAL_PANE_SCREEN_NAMES = [
4+
const CENTRAL_PANE_SCREEN_NAMES = new Set([
55
SCREENS.SETTINGS.WORKSPACES,
66
SCREENS.SETTINGS.PREFERENCES.ROOT,
77
SCREENS.SETTINGS.SECURITY,
@@ -13,14 +13,14 @@ const CENTRAL_PANE_SCREEN_NAMES = [
1313
SCREENS.SETTINGS.SUBSCRIPTION.ROOT,
1414
SCREENS.SEARCH.CENTRAL_PANE,
1515
SCREENS.REPORT,
16-
];
16+
]);
1717

1818
function isCentralPaneName(screen: string | undefined): screen is CentralPaneName {
1919
if (!screen) {
2020
return false;
2121
}
2222

23-
return CENTRAL_PANE_SCREEN_NAMES.includes(screen as CentralPaneName);
23+
return CENTRAL_PANE_SCREEN_NAMES.has(screen as CentralPaneName);
2424
}
2525

2626
export default isCentralPaneName;

0 commit comments

Comments
 (0)