Skip to content

Commit bf6c26e

Browse files
committed
Revert "Merge pull request #61774 from software-mansion-labs/better-expense-report-view/go-to-parent"
This reverts commit d4347a6, reversing changes made to 060c78b.
1 parent 98d5d8c commit bf6c26e

File tree

8 files changed

+46
-89
lines changed

8 files changed

+46
-89
lines changed

src/components/AvatarWithDisplayName.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ type AvatarWithDisplayNameProps = {
6363

6464
/** Transactions inside report */
6565
transactions?: TransactionListItemType[];
66-
67-
/** Whether to open the parent report link in the current tab if possible */
68-
openParentReportInCurrentTab?: boolean;
6966
};
7067

7168
const fallbackIcon: Icon = {
@@ -159,7 +156,6 @@ function AvatarWithDisplayName({
159156
shouldEnableDetailPageNavigation = false,
160157
shouldUseCustomSearchTitleName = false,
161158
transactions = [],
162-
openParentReportInCurrentTab = false,
163159
}: AvatarWithDisplayNameProps) {
164160
const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`, {canEvict: false, canBeMissing: false});
165161
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: false}) ?? CONST.EMPTY_OBJECT;
@@ -271,7 +267,6 @@ function AvatarWithDisplayName({
271267
parentReportID={report?.parentReportID}
272268
parentReportActionID={report?.parentReportActionID}
273269
pressableStyles={[styles.alignSelfStart, styles.mw100]}
274-
openParentReportInCurrentTab={openParentReportInCurrentTab}
275270
/>
276271
)}
277272
{!!subtitle && (

src/components/HeaderWithBackButton/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ function HeaderWithBackButton({
7272
progressBarPercentage,
7373
style,
7474
subTitleLink = '',
75-
openParentReportInCurrentTab = false,
7675
}: HeaderWithBackButtonProps) {
7776
const theme = useTheme();
7877
const styles = useThemeStyles();
@@ -102,7 +101,6 @@ function HeaderWithBackButton({
102101
report={report}
103102
policy={policy}
104103
shouldEnableDetailPageNavigation={shouldEnableDetailPageNavigation}
105-
openParentReportInCurrentTab={openParentReportInCurrentTab}
106104
/>
107105
);
108106
}
@@ -135,7 +133,6 @@ function HeaderWithBackButton({
135133
title,
136134
titleColor,
137135
translate,
138-
openParentReportInCurrentTab,
139136
]);
140137

141138
return (

src/components/HeaderWithBackButton/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ type HeaderWithBackButtonProps = Partial<ChildrenProps> & {
156156

157157
/** The URL link associated with the attachment's subtitle, if available */
158158
subTitleLink?: string;
159-
160-
/** Whether to open the parent report link in the current tab if possible */
161-
openParentReportInCurrentTab?: boolean;
162159
};
163160

164161
export type {ThreeDotsMenuItem};

src/components/MoneyRequestHeader.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ function MoneyRequestHeader({report, parentReportAction, policy, onBackButtonPre
254254
shouldDisplayHelpButton={!isReportInRHP}
255255
onBackButtonPress={onBackButtonPress}
256256
shouldEnableDetailPageNavigation
257-
openParentReportInCurrentTab
258257
>
259258
{!shouldUseNarrowLayout && (
260259
<View style={[styles.flexRow, styles.gap2]}>

src/components/ParentNavigationSubtitle.tsx

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import {useRoute} from '@react-navigation/native';
21
import React from 'react';
32
import type {StyleProp, ViewStyle} from 'react-native';
43
import {useOnyx} from 'react-native-onyx';
54
import useLocalize from '@hooks/useLocalize';
6-
import useRootNavigationState from '@hooks/useRootNavigationState';
75
import useThemeStyles from '@hooks/useThemeStyles';
8-
import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName';
96
import Navigation from '@libs/Navigation/Navigation';
10-
import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types';
117
import {getReportAction, shouldReportActionBeVisible} from '@libs/ReportActionsUtils';
128
import {canUserPerformWriteAction as canUserPerformWriteActionReportUtils} from '@libs/ReportUtils';
139
import CONST from '@src/CONST';
1410
import type {ParentNavigationSummaryParams} from '@src/languages/params';
15-
import NAVIGATORS from '@src/NAVIGATORS';
1611
import ONYXKEYS from '@src/ONYXKEYS';
1712
import ROUTES from '@src/ROUTES';
18-
import SCREENS from '@src/SCREENS';
1913
import PressableWithoutFeedback from './Pressable/PressableWithoutFeedback';
2014
import Text from './Text';
2115

@@ -30,26 +24,14 @@ type ParentNavigationSubtitleProps = {
3024

3125
/** PressableWithoutFeedback additional styles */
3226
pressableStyles?: StyleProp<ViewStyle>;
33-
34-
/** Whether to open the parent report link in the current tab if possible */
35-
openParentReportInCurrentTab?: boolean;
3627
};
3728

38-
function ParentNavigationSubtitle({
39-
parentNavigationSubtitleData,
40-
parentReportActionID,
41-
parentReportID = '',
42-
pressableStyles,
43-
openParentReportInCurrentTab = false,
44-
}: ParentNavigationSubtitleProps) {
45-
const currentRoute = useRoute();
29+
function ParentNavigationSubtitle({parentNavigationSubtitleData, parentReportActionID, parentReportID = '', pressableStyles}: ParentNavigationSubtitleProps) {
4630
const styles = useThemeStyles();
4731
const {workspaceName, reportName} = parentNavigationSubtitleData;
4832
const {translate} = useLocalize();
49-
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, {canBeMissing: false});
33+
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`);
5034
const canUserPerformWriteAction = canUserPerformWriteActionReportUtils(report);
51-
const isReportInRHP = currentRoute.name === SCREENS.SEARCH.REPORT_RHP;
52-
const currentFullScreenRoute = useRootNavigationState((state) => state?.routes?.findLast((route) => isFullScreenName(route.name)));
5335

5436
// 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)
5537
if (!reportName) {
@@ -61,31 +43,6 @@ function ParentNavigationSubtitle({
6143
onPress={() => {
6244
const parentAction = getReportAction(parentReportID, parentReportActionID);
6345
const isVisibleAction = shouldReportActionBeVisible(parentAction, parentAction?.reportActionID ?? CONST.DEFAULT_NUMBER_ID, canUserPerformWriteAction);
64-
65-
if (openParentReportInCurrentTab && isReportInRHP) {
66-
// If the report is displayed in RHP in Reports tab, we want to stay in the current tab after opening the parent report
67-
if (currentFullScreenRoute?.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR) {
68-
const lastRoute = currentFullScreenRoute?.state?.routes.at(-1);
69-
if (lastRoute?.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT) {
70-
const moneyRequestReportID = (lastRoute?.params as SearchFullscreenNavigatorParamList[typeof SCREENS.SEARCH.MONEY_REQUEST_REPORT])?.reportID;
71-
// If the parent report is already displayed underneath RHP, simply dismiss the modal
72-
if (moneyRequestReportID === parentReportID) {
73-
Navigation.dismissModal();
74-
return;
75-
}
76-
}
77-
78-
Navigation.navigate(ROUTES.SEARCH_MONEY_REQUEST_REPORT.getRoute({reportID: parentReportID}));
79-
return;
80-
}
81-
82-
// If the parent report is already displayed underneath RHP, simply dismiss the modal
83-
if (Navigation.getTopmostReportId() === parentReportID) {
84-
Navigation.dismissModal();
85-
return;
86-
}
87-
}
88-
8946
if (isVisibleAction) {
9047
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(parentReportID, parentReportActionID));
9148
} else {

src/libs/Navigation/AppNavigator/AuthScreens.tsx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import getCurrentUrl from '@libs/Navigation/currentUrl';
3030
import Navigation from '@libs/Navigation/Navigation';
3131
import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation';
3232
import Presentation from '@libs/Navigation/PlatformStackNavigation/navigationOptions/presentation';
33-
import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types';
3433
import type {AuthScreensParamList} from '@libs/Navigation/types';
3534
import NetworkConnection from '@libs/NetworkConnection';
3635
import onyxSubscribe from '@libs/onyxSubscribe';
@@ -62,12 +61,7 @@ import type {SelectedTimezone, Timezone} from '@src/types/onyx/PersonalDetails';
6261
import {isEmptyObject} from '@src/types/utils/EmptyObject';
6362
import type ReactComponentModule from '@src/types/utils/ReactComponentModule';
6463
import createRootStackNavigator from './createRootStackNavigator';
65-
import {
66-
reportsSplitsWithEnteringAnimation,
67-
searchFullscreenWithEnteringAnimation,
68-
settingsSplitWithEnteringAnimation,
69-
workspaceSplitsWithoutEnteringAnimation,
70-
} from './createRootStackNavigator/GetStateForActionHandlers';
64+
import {reportsSplitsWithEnteringAnimation, settingsSplitWithEnteringAnimation, workspaceSplitsWithoutEnteringAnimation} from './createRootStackNavigator/GetStateForActionHandlers';
7165
import defaultScreenOptions from './defaultScreenOptions';
7266
import {ShareModalStackNavigator} from './ModalStackNavigators';
7367
import ExplanationModalNavigator from './Navigators/ExplanationModalNavigator';
@@ -468,30 +462,27 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
468462
};
469463
};
470464

471-
const getFullScreenNavigatorOptions =
472-
(routesWithEnteringAnimation: Set<string>, defaultOptions: PlatformStackNavigationOptions) =>
465+
const getSplitNavigatorOptions =
466+
(routesWithEnteringAnimation: Set<string>) =>
473467
({route}: {route: RouteProp<AuthScreensParamList>}) => {
474468
// We don't need to do anything special for the wide screen.
475469
if (!shouldUseNarrowLayout) {
476-
return defaultOptions;
470+
return rootNavigatorScreenOptions.splitNavigator;
477471
}
478472
// On the narrow screen, we want to animate this navigator if pushed SplitNavigator includes desired screen
479473
const animationEnabled = routesWithEnteringAnimation.has(route.key);
480474

481475
return {
482-
...defaultOptions,
476+
...rootNavigatorScreenOptions.splitNavigator,
483477
animation: animationEnabled ? Animations.SLIDE_FROM_RIGHT : Animations.NONE,
484478
};
485479
};
486480

487481
// Animation is enabled when navigating to the report screen
488-
const getReportsSplitNavigatorOptions = getFullScreenNavigatorOptions(reportsSplitsWithEnteringAnimation, rootNavigatorScreenOptions.splitNavigator);
482+
const getReportsSplitNavigatorOptions = getSplitNavigatorOptions(reportsSplitsWithEnteringAnimation);
489483

490484
// Animation is enabled when navigating to any screen different than SCREENS.SETTINGS.ROOT
491-
const getSettingsSplitNavigatorOptions = getFullScreenNavigatorOptions(settingsSplitWithEnteringAnimation, rootNavigatorScreenOptions.splitNavigator);
492-
493-
// Animation is enabled when navigating to SCREENS.SEARCH.MONEY_REQUEST_REPORT
494-
const getSearchFullscreenNavigatorOptions = getFullScreenNavigatorOptions(searchFullscreenWithEnteringAnimation, rootNavigatorScreenOptions.fullScreen);
485+
const getSettingsSplitNavigatorOptions = getSplitNavigatorOptions(settingsSplitWithEnteringAnimation);
495486

496487
const clearStatus = () => {
497488
User.clearCustomStatus();
@@ -542,7 +533,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
542533
/>
543534
<RootStack.Screen
544535
name={NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR}
545-
options={getSearchFullscreenNavigatorOptions}
536+
options={rootNavigatorScreenOptions.fullScreen}
546537
getComponent={loadSearchNavigator}
547538
/>
548539
<RootStack.Screen

src/libs/Navigation/AppNavigator/createRootStackNavigator/GetStateForActionHandlers.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type {CommonActions, RouterConfigOptions, StackActionType, StackNavigatio
22
import {StackActions} from '@react-navigation/native';
33
import type {ParamListBase, Router} from '@react-navigation/routers';
44
import Log from '@libs/Log';
5-
import type {RootNavigatorParamList} from '@libs/Navigation/types';
5+
import getPolicyIDFromState from '@libs/Navigation/helpers/getPolicyIDFromState';
6+
import type {RootNavigatorParamList, State} from '@libs/Navigation/types';
67
import * as SearchQueryUtils from '@libs/SearchQueryUtils';
78
import NAVIGATORS from '@src/NAVIGATORS';
89
import SCREENS from '@src/SCREENS';
@@ -28,7 +29,7 @@ const MODAL_ROUTES_TO_DISMISS: string[] = [
2829
const workspaceSplitsWithoutEnteringAnimation = new Set<string>();
2930
const reportsSplitsWithEnteringAnimation = new Set<string>();
3031
const settingsSplitWithEnteringAnimation = new Set<string>();
31-
const searchFullscreenWithEnteringAnimation = new Set<string>();
32+
3233
/**
3334
* Handles the OPEN_WORKSPACE_SPLIT action.
3435
* 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.
@@ -201,23 +202,44 @@ function handlePushSearchPageAction(
201202
action: PushActionType,
202203
configOptions: RouterConfigOptions,
203204
stackRouter: Router<StackNavigationState<ParamListBase>, CommonActions.Action | StackActionType>,
205+
setActiveWorkspaceID: (workspaceID: string | undefined) => void,
204206
) {
205-
const stateWithSearchFullscreenNavigator = stackRouter.getStateForAction(state, action, configOptions);
207+
let updatedAction = action;
208+
const currentParams = action.payload.params as RootNavigatorParamList[typeof NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR];
209+
if (currentParams?.screen === SCREENS.SEARCH.ROOT) {
210+
const searchParams = currentParams?.params;
211+
const queryJSON = SearchQueryUtils.buildSearchQueryJSON(searchParams.q);
212+
if (!queryJSON) {
213+
return null;
214+
}
206215

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

212-
const lastFullScreenRoute = stateWithSearchFullscreenNavigator.routes.at(-1);
213-
const actionPayloadScreen = action.payload?.params && 'screen' in action.payload.params ? action.payload?.params?.screen : undefined;
219+
if (policyID) {
220+
queryJSON.policyID = policyID;
221+
} else {
222+
delete queryJSON.policyID;
223+
}
224+
} else {
225+
setActiveWorkspaceID(queryJSON.policyID);
226+
}
214227

215-
// Transitioning to SCREENS.SEARCH.MONEY_REQUEST_REPORT should be animated
216-
if (actionPayloadScreen === SCREENS.SEARCH.MONEY_REQUEST_REPORT && lastFullScreenRoute?.key) {
217-
searchFullscreenWithEnteringAnimation.add(lastFullScreenRoute.key);
228+
updatedAction = {
229+
...action,
230+
payload: {
231+
...action.payload,
232+
params: {
233+
...action.payload.params,
234+
params: {
235+
q: SearchQueryUtils.buildSearchQueryString(queryJSON),
236+
},
237+
},
238+
},
239+
};
218240
}
219241

220-
return stateWithSearchFullscreenNavigator;
242+
return stackRouter.getStateForAction(state, updatedAction, configOptions);
221243
}
222244

223245
function handleReplaceReportsSplitNavigatorAction(
@@ -287,7 +309,6 @@ export {
287309
handleSwitchPolicyIDAction,
288310
handleSwitchPolicyIDFromSearchAction,
289311
reportsSplitsWithEnteringAnimation,
290-
searchFullscreenWithEnteringAnimation,
291312
settingsSplitWithEnteringAnimation,
292313
workspaceSplitsWithoutEnteringAnimation,
293314
};

src/libs/Navigation/AppNavigator/createRootStackNavigator/RootStackRouter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function RootStackRouter(options: RootStackNavigatorRouterOptions) {
111111
}
112112

113113
if (action.payload.name === NAVIGATORS.SEARCH_FULLSCREEN_NAVIGATOR) {
114-
return handlePushSearchPageAction(state, action, configOptions, stackRouter);
114+
return handlePushSearchPageAction(state, action, configOptions, stackRouter, setActiveWorkspaceID);
115115
}
116116

117117
if (action.payload.name === NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR) {

0 commit comments

Comments
 (0)