Skip to content

Commit

Permalink
Merge pull request #44444 from software-mansion-labs/fix/link-to-with…
Browse files Browse the repository at this point in the history
…out-central-pane

Fix navigating between CentralPane screens
  • Loading branch information
luacmartins authored Jun 26, 2024
2 parents d53df45 + 89b6676 commit f757005
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/libs/Navigation/linkTo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,21 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam

// 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 actionParams: ActionPayloadParams = action.payload.params;
const actionPayloadParams: ActionPayloadParams = action.payload.params;
const topRouteName = lastRoute?.name;

// 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
const targetName = actionPayloadParams?.screen ?? action.payload.name;
const targetParams = actionPayloadParams?.params ?? actionPayloadParams;
const isTargetNavigatorOnTop = topRouteName === action.payload.name;

const isTargetScreenDifferentThanCurrent = !!(!topmostCentralPaneRoute || topmostCentralPaneRoute.name !== (actionParams?.screen ?? action.payload.name));
const isTargetScreenDifferentThanCurrent = !!(!topmostCentralPaneRoute || topmostCentralPaneRoute.name !== targetName);
const areParamsDifferent =
actionParams?.screen === SCREENS.REPORT
targetName === SCREENS.REPORT
? getTopmostReportId(rootState) !== getTopmostReportId(stateFromPath)
: !shallowCompare(
omitBy(topmostCentralPaneRoute?.params as Record<string, unknown> | undefined, (value) => value === undefined),
omitBy(actionParams?.params as Record<string, unknown> | undefined, (value) => value === undefined),
omitBy(targetParams as Record<string, unknown> | undefined, (value) => value === undefined),
);

// 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
Expand Down Expand Up @@ -110,8 +114,8 @@ export default function linkTo(navigation: NavigationContainerRef<RootStackParam
}

// 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
if (actionParams?.screen === SCREENS.SEARCH.CENTRAL_PANE && actionParams?.params && policyID) {
(actionParams.params as Record<string, string | undefined>).policyIDs = policyID;
if (targetName === SCREENS.SEARCH.CENTRAL_PANE && targetParams && policyID) {
(targetParams as Record<string, string | undefined>).policyIDs = policyID;
}

// 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
Expand Down
6 changes: 3 additions & 3 deletions src/libs/NavigationUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SCREENS from '@src/SCREENS';
import type {CentralPaneName} from './Navigation/types';

const CENTRAL_PANE_SCREEN_NAMES = [
const CENTRAL_PANE_SCREEN_NAMES = new Set([
SCREENS.SETTINGS.WORKSPACES,
SCREENS.SETTINGS.PREFERENCES.ROOT,
SCREENS.SETTINGS.SECURITY,
Expand All @@ -13,14 +13,14 @@ const CENTRAL_PANE_SCREEN_NAMES = [
SCREENS.SETTINGS.SUBSCRIPTION.ROOT,
SCREENS.SEARCH.CENTRAL_PANE,
SCREENS.REPORT,
];
]);

function isCentralPaneName(screen: string | undefined): screen is CentralPaneName {
if (!screen) {
return false;
}

return CENTRAL_PANE_SCREEN_NAMES.includes(screen as CentralPaneName);
return CENTRAL_PANE_SCREEN_NAMES.has(screen as CentralPaneName);
}

export default isCentralPaneName;

0 comments on commit f757005

Please sign in to comment.