Skip to content

Commit

Permalink
Adjust getTopmostReportActionID and cleanup getTopmostReportID
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekBoman committed Oct 25, 2024
1 parent 927c68b commit 8cd6ade
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
25 changes: 8 additions & 17 deletions src/libs/Navigation/getTopmostReportActionID.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {NavigationState, PartialState} from '@react-navigation/native';
import {isCentralPaneName} from '@libs/NavigationUtils';
import NAVIGATORS from '@src/NAVIGATORS';
import SCREENS from '@src/SCREENS';
import type {RootStackParamList} from './types';

Expand All @@ -16,33 +16,24 @@ function getTopmostReportActionID(state: NavigationState | NavigationState<RootS
return;
}

const topmostCentralPane = state.routes.filter((route) => isCentralPaneName(route.name)).at(-1);
if (!topmostCentralPane) {
const topmostReportsSplitNavigator = state.routes.filter((route) => route.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR).at(-1);
if (!topmostReportsSplitNavigator?.state) {
return;
}

const directReportParams = topmostCentralPane.params;
const directReportActionIDParam = directReportParams && 'reportActionID' in directReportParams && directReportParams?.reportActionID;
const topmostReport = topmostReportsSplitNavigator.state?.routes.filter((route) => route.name === SCREENS.REPORT).at(-1);

if (!topmostCentralPane.state && !directReportActionIDParam) {
if (!topmostReport || !topmostReport?.params) {
return;
}

if (directReportActionIDParam) {
return directReportActionIDParam;
}

const topmostReport = topmostCentralPane.state?.routes.filter((route) => route.name === SCREENS.REPORT).at(-1);
if (!topmostReport) {
return;
}
const reportActionID = 'reportActionID' in topmostReport.params && topmostReport.params.reportActionID;

const topmostReportActionID = topmostReport.params && 'reportActionID' in topmostReport.params && topmostReport.params?.reportActionID;
if (typeof topmostReportActionID !== 'string') {
if (typeof reportActionID !== 'string') {
return;
}

return topmostReportActionID;
return reportActionID;
}

export default getTopmostReportActionID;
15 changes: 0 additions & 15 deletions src/libs/Navigation/getTopmostReportId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@ function getTopmostReportId(state: NavigationState | NavigationState<RootStackPa
return;
}

// const directReportParams = topmostCentralPane.params;
// const directReportIdParam = directReportParams && 'reportID' in directReportParams && directReportParams?.reportID;

// if (!topmostCentralPane.state && !directReportIdParam) {
// return;
// }

// if (directReportIdParam) {
// return directReportIdParam;
// }

if (!topmostReport) {
return;
}

const topmostReportId = topmostReport.params && 'reportID' in topmostReport.params && topmostReport.params?.reportID;
if (typeof topmostReportId !== 'string') {
return;
Expand Down

0 comments on commit 8cd6ade

Please sign in to comment.