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
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;

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.

Not a blocker but i think we should instead use action?.payload?.params to avoid any kind of crash(IDK if ever the params would be undefined but better to have), as this is related to deploy blocker i won't focus on this much though, we can come up with a follow up PR for this @luacmartins @WojtekBoman

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;