Skip to content

Commit

Permalink
Merge pull request #29268 from tienifr/fix/29056
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisl authored Oct 18, 2023
2 parents f626744 + c09537e commit f0d2d08
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,61 @@
import _ from 'underscore';
import {StackRouter} from '@react-navigation/native';
import lodashFindLast from 'lodash/findLast';
import NAVIGATORS from '../../../../NAVIGATORS';
import SCREENS from '../../../../SCREENS';

/**
* @param {Object} state - react-navigation state
* @returns {Boolean}
*/
const isAtLeastOneCentralPaneNavigatorInState = (state) => _.find(state.routes, (r) => r.name === NAVIGATORS.CENTRAL_PANE_NAVIGATOR);

/**
* @param {Object} state - react-navigation state
* @returns {String|undefined}
*/
const getTopMostReportIDFromRHP = (state) => {
if (!state) {
return;
}
const topmostRightPane = lodashFindLast(state.routes, (route) => route.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR);

if (topmostRightPane) {
return getTopMostReportIDFromRHP(topmostRightPane.state);
}

const topmostRoute = lodashFindLast(state.routes);

if (topmostRoute.state) {
return getTopMostReportIDFromRHP(topmostRoute.state);
}

if (topmostRoute.params && topmostRoute.params.reportID) {
return topmostRoute.params.reportID;
}
};
/**
* Adds report route without any specific reportID to the state.
* The report screen will self set proper reportID param based on the helper function findLastAccessedReport (look at ReportScreenWrapper for more info)
*
* @param {Object} state - react-navigation state
*/
const addCentralPaneNavigatorRoute = (state) => {
state.routes.splice(1, 0, {name: NAVIGATORS.CENTRAL_PANE_NAVIGATOR});
const reportID = getTopMostReportIDFromRHP(state);
const centralPaneNavigatorRoute = {
name: NAVIGATORS.CENTRAL_PANE_NAVIGATOR,
state: {
routes: [
{
name: SCREENS.REPORT,
params: {
reportID,
},
},
],
},
};
state.routes.splice(1, 0, centralPaneNavigatorRoute);
// eslint-disable-next-line no-param-reassign
state.index = state.routes.length - 1;
};
Expand Down
13 changes: 12 additions & 1 deletion src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,18 @@ function ReportDetailsPage(props) {
return (
<ScreenWrapper testID={ReportDetailsPage.displayName}>
<FullPageNotFoundView shouldShow={_.isEmpty(props.report)}>
<HeaderWithBackButton title={props.translate('common.details')} />
<HeaderWithBackButton
title={props.translate('common.details')}
onBackButtonPress={() => {
const topMostReportID = Navigation.getTopmostReportId();
if (topMostReportID) {
Navigation.goBack(ROUTES.HOME);
return;
}
Navigation.goBack();
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(props.report.reportID));
}}
/>
<ScrollView style={[styles.flex1]}>
<View style={styles.reportDetailsTitleContainer}>
<View style={styles.mb3}>
Expand Down

0 comments on commit f0d2d08

Please sign in to comment.