Skip to content
Closed
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
5 changes: 0 additions & 5 deletions src/components/AvatarWithDisplayName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ type AvatarWithDisplayNameProps = {

/** Transactions inside report */
transactions?: TransactionListItemType[];

/** Whether to open the parent report link in the current tab if possible */
openParentReportInCurrentTab?: boolean;
};

const fallbackIcon: Icon = {
Expand Down Expand Up @@ -159,7 +156,6 @@ function AvatarWithDisplayName({
shouldEnableDetailPageNavigation = false,
shouldUseCustomSearchTitleName = false,
transactions = [],
openParentReportInCurrentTab = false,
}: AvatarWithDisplayNameProps) {
const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`, {canEvict: false, canBeMissing: false});
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false}) ?? CONST.EMPTY_OBJECT;
Expand Down Expand Up @@ -271,7 +267,6 @@ function AvatarWithDisplayName({
parentReportID={report?.parentReportID}
parentReportActionID={report?.parentReportActionID}
pressableStyles={[styles.alignSelfStart, styles.mw100]}
openParentReportInCurrentTab={openParentReportInCurrentTab}
/>
)}
{!!subtitle && (
Expand Down
3 changes: 0 additions & 3 deletions src/components/HeaderWithBackButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function HeaderWithBackButton({
progressBarPercentage,
style,
subTitleLink = '',
openParentReportInCurrentTab = false,
}: HeaderWithBackButtonProps) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -102,7 +101,6 @@ function HeaderWithBackButton({
report={report}
policy={policy}
shouldEnableDetailPageNavigation={shouldEnableDetailPageNavigation}
openParentReportInCurrentTab={openParentReportInCurrentTab}
/>
);
}
Expand Down Expand Up @@ -135,7 +133,6 @@ function HeaderWithBackButton({
title,
titleColor,
translate,
openParentReportInCurrentTab,
]);

return (
Expand Down
3 changes: 0 additions & 3 deletions src/components/HeaderWithBackButton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ type HeaderWithBackButtonProps = Partial<ChildrenProps> & {

/** The URL link associated with the attachment's subtitle, if available */
subTitleLink?: string;

/** Whether to open the parent report link in the current tab if possible */
openParentReportInCurrentTab?: boolean;
};

export type {ThreeDotsMenuItem};
Expand Down
1 change: 0 additions & 1 deletion src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
shouldDisplayHelpButton={!isReportInRHP}
onBackButtonPress={onBackButtonPress}
shouldEnableDetailPageNavigation
openParentReportInCurrentTab
>
{!shouldUseNarrowLayout && (
<View style={[styles.flexRow, styles.gap2]}>
Expand Down
47 changes: 2 additions & 45 deletions src/components/ParentNavigationSubtitle.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import {useRoute} from '@react-navigation/native';
import React from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useRootNavigationState from '@hooks/useRootNavigationState';
import useThemeStyles from '@hooks/useThemeStyles';
import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName';
import Navigation from '@libs/Navigation/Navigation';
import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types';
import {getReportAction, shouldReportActionBeVisible} from '@libs/ReportActionsUtils';
import {canUserPerformWriteAction as canUserPerformWriteActionReportUtils} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import type {ParentNavigationSummaryParams} from '@src/languages/params';
import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SCREENS from '@src/SCREENS';
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';
import Text from './Text';

Expand All @@ -30,26 +24,14 @@

/** PressableWithoutFeedback additional styles */
pressableStyles?: StyleProp<ViewStyle>;

/** Whether to open the parent report link in the current tab if possible */
openParentReportInCurrentTab?: boolean;
};

function ParentNavigationSubtitle({
parentNavigationSubtitleData,
parentReportActionID,
parentReportID = '',
pressableStyles,
openParentReportInCurrentTab = false,
}: ParentNavigationSubtitleProps) {
const currentRoute = useRoute();
function ParentNavigationSubtitle({parentNavigationSubtitleData, parentReportActionID, parentReportID = '', pressableStyles}: ParentNavigationSubtitleProps) {
const styles = useThemeStyles();
const {workspaceName, reportName} = parentNavigationSubtitleData;
const {translate} = useLocalize();
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, {canBeMissing: false});
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`);

Check failure on line 33 in src/components/ParentNavigationSubtitle.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

useOnyx() calls require you to pass the "canBeMissing" param
const canUserPerformWriteAction = canUserPerformWriteActionReportUtils(report);
const isReportInRHP = currentRoute.name === SCREENS.SEARCH.REPORT_RHP;
const currentFullScreenRoute = useRootNavigationState((state) => state?.routes?.findLast((route) => isFullScreenName(route.name)));

// We should not display the parent navigation subtitle if the user does not have access to the parent chat (the reportName is empty in this case)
if (!reportName) {
Expand All @@ -61,31 +43,6 @@
onPress={() => {
const parentAction = getReportAction(parentReportID, parentReportActionID);
const isVisibleAction = shouldReportActionBeVisible(parentAction, parentAction?.reportActionID ?? CONST.DEFAULT_NUMBER_ID, canUserPerformWriteAction);

if (openParentReportInCurrentTab && isReportInRHP) {
// If the report is displayed in RHP in Reports tab, we want to stay in the current tab after opening the parent report
if (currentFullScreenRoute?.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR) {
const lastRoute = currentFullScreenRoute?.state?.routes.at(-1);
if (lastRoute?.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT) {
const moneyRequestReportID = (lastRoute?.params as SearchFullscreenNavigatorParamList[typeof SCREENS.SEARCH.MONEY_REQUEST_REPORT])?.reportID;
// If the parent report is already displayed underneath RHP, simply dismiss the modal
if (moneyRequestReportID === parentReportID) {
Navigation.dismissModal();
return;
}
}

Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: parentReportID}));
return;
}

// If the parent report is already displayed underneath RHP, simply dismiss the modal
if (Navigation.getTopmostReportId() === parentReportID) {
Navigation.dismissModal();
return;
}
}

if (isVisibleAction) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(parentReportID, parentReportActionID));
} else {
Expand Down
25 changes: 8 additions & 17 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import getCurrentUrl from '@libs/Navigation/currentUrl';
import Navigation from '@libs/Navigation/Navigation';
import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation';
import Presentation from '@libs/Navigation/PlatformStackNavigation/navigationOptions/presentation';
import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types';
import type {AuthScreensParamList} from '@libs/Navigation/types';
import NetworkConnection from '@libs/NetworkConnection';
import onyxSubscribe from '@libs/onyxSubscribe';
Expand Down Expand Up @@ -62,12 +61,7 @@ import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type ReactComponentModule from '@src/types/utils/ReactComponentModule';
import createRootStackNavigator from './createRootStackNavigator';
import {
reportsSplitsWithEnteringAnimation,
searchFullscreenWithEnteringAnimation,
settingsSplitWithEnteringAnimation,
workspaceSplitsWithoutEnteringAnimation,
} from './createRootStackNavigator/GetStateForActionHandlers';
import {reportsSplitsWithEnteringAnimation, settingsSplitWithEnteringAnimation, workspaceSplitsWithoutEnteringAnimation} from './createRootStackNavigator/GetStateForActionHandlers';
import defaultScreenOptions from './defaultScreenOptions';
import {ShareModalStackNavigator} from './ModalStackNavigators';
import ExplanationModalNavigator from './Navigators/ExplanationModalNavigator';
Expand Down Expand Up @@ -468,30 +462,27 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
};
};

const getFullScreenNavigatorOptions =
(routesWithEnteringAnimation: Set<string>, defaultOptions: PlatformStackNavigationOptions) =>
const getSplitNavigatorOptions =
(routesWithEnteringAnimation: Set<string>) =>
({route}: {route: RouteProp<AuthScreensParamList>}) => {
// We don't need to do anything special for the wide screen.
if (!shouldUseNarrowLayout) {
return defaultOptions;
return rootNavigatorScreenOptions.splitNavigator;
}
// On the narrow screen, we want to animate this navigator if pushed SplitNavigator includes desired screen
const animationEnabled = routesWithEnteringAnimation.has(route.key);

return {
...defaultOptions,
...rootNavigatorScreenOptions.splitNavigator,
animation: animationEnabled ? Animations.SLIDE_FROM_RIGHT : Animations.NONE,
};
};

// Animation is enabled when navigating to the report screen
const getReportsSplitNavigatorOptions = getFullScreenNavigatorOptions(reportsSplitsWithEnteringAnimation, rootNavigatorScreenOptions.splitNavigator);
const getReportsSplitNavigatorOptions = getSplitNavigatorOptions(reportsSplitsWithEnteringAnimation);

// Animation is enabled when navigating to any screen different than SCREENS.SETTINGS.ROOT
const getSettingsSplitNavigatorOptions = getFullScreenNavigatorOptions(settingsSplitWithEnteringAnimation, rootNavigatorScreenOptions.splitNavigator);

// Animation is enabled when navigating to SCREENS.SEARCH.MONEY_REQUEST_REPORT
const getSearchFullscreenNavigatorOptions = getFullScreenNavigatorOptions(searchFullscreenWithEnteringAnimation, rootNavigatorScreenOptions.fullScreen);
const getSettingsSplitNavigatorOptions = getSplitNavigatorOptions(settingsSplitWithEnteringAnimation);

const clearStatus = () => {
User.clearCustomStatus();
Expand Down Expand Up @@ -542,7 +533,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
/>
<RootStack.Screen
name={NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR}
options={getSearchFullscreenNavigatorOptions}
options={rootNavigatorScreenOptions.fullScreen}
getComponent={loadSearchNavigator}
/>
<RootStack.Screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type {CommonActions, RouterConfigOptions, StackActionType, StackNavigatio
import {StackActions} from '@react-navigation/native';
import type {ParamListBase, Router} from '@react-navigation/routers';
import Log from '@libs/Log';
import type {RootNavigatorParamList} from '@libs/Navigation/types';
import getPolicyIDFromState from '@libs/Navigation/helpers/getPolicyIDFromState';
import type {RootNavigatorParamList, State} from '@libs/Navigation/types';
import * as SearchQueryUtils from '@libs/SearchQueryUtils';
import NAVIGATORS from '@src/NAVIGATORS';
import SCREENS from '@src/SCREENS';
Expand All @@ -28,7 +29,7 @@ const MODAL_ROUTES_TO_DISMISS: string[] = [
const workspaceSplitsWithoutEnteringAnimation = new Set<string>();
const reportsSplitsWithEnteringAnimation = new Set<string>();
const settingsSplitWithEnteringAnimation = new Set<string>();
const searchFullscreenWithEnteringAnimation = new Set<string>();

/**
* Handles the OPEN_WORKSPACE_SPLIT action.
* If the user is on other tab than workspaces and the workspace split is "remembered", this action will be called after pressing the settings tab.
Expand Down Expand Up @@ -201,23 +202,44 @@ function handlePushSearchPageAction(
action: PushActionType,
configOptions: RouterConfigOptions,
stackRouter: Router<StackNavigationState<ParamListBase>, CommonActions.Action | StackActionType>,
setActiveWorkspaceID: (workspaceID: string | undefined) => void,
) {
const stateWithSearchFullscreenNavigator = stackRouter.getStateForAction(state, action, configOptions);
let updatedAction = action;
const currentParams = action.payload.params as RootNavigatorParamList[typeof NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR];
if (currentParams?.screen === SCREENS.SEARCH.ROOT) {
const searchParams = currentParams?.params;
const queryJSON = SearchQueryUtils.buildSearchQueryJSON(searchParams.q);
if (!queryJSON) {
return null;
}

if (!stateWithSearchFullscreenNavigator) {
Log.hmmm('[handlePushSettingsAction] SearchFullscreenNavigator has not been found in the navigation state.');
return null;
}
if (!queryJSON.policyID) {
const policyID = getPolicyIDFromState(state as State<RootNavigatorParamList>);

const lastFullScreenRoute = stateWithSearchFullscreenNavigator.routes.at(-1);
const actionPayloadScreen = action.payload?.params && 'screen' in action.payload.params ? action.payload?.params?.screen : undefined;
if (policyID) {
queryJSON.policyID = policyID;
} else {
delete queryJSON.policyID;
}
} else {
setActiveWorkspaceID(queryJSON.policyID);
}

// Transitioning to SCREENS.SEARCH.MONEY_REQUEST_REPORT should be animated
if (actionPayloadScreen === SCREENS.SEARCH.MONEY_REQUEST_REPORT && lastFullScreenRoute?.key) {
searchFullscreenWithEnteringAnimation.add(lastFullScreenRoute.key);
updatedAction = {
...action,
payload: {
...action.payload,
params: {
...action.payload.params,
params: {
q: SearchQueryUtils.buildSearchQueryString(queryJSON),
},
},
},
};
}

return stateWithSearchFullscreenNavigator;
return stackRouter.getStateForAction(state, updatedAction, configOptions);
}

function handleReplaceReportsSplitNavigatorAction(
Expand Down Expand Up @@ -287,7 +309,6 @@ export {
handleSwitchPolicyIDAction,
handleSwitchPolicyIDFromSearchAction,
reportsSplitsWithEnteringAnimation,
searchFullscreenWithEnteringAnimation,
settingsSplitWithEnteringAnimation,
workspaceSplitsWithoutEnteringAnimation,
};
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function RootStackRouter(options: RootStackNavigatorRouterOptions) {
}

if (action.payload.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR) {
return handlePushSearchPageAction(state, action, configOptions, stackRouter);
return handlePushSearchPageAction(state, action, configOptions, stackRouter, setActiveWorkspaceID);
}

if (action.payload.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR) {
Expand Down
Loading