Skip to content

Commit

Permalink
Merge pull request #56381 from Expensify/revert-55015-fix/54058
Browse files Browse the repository at this point in the history
Revert "fix: navigate to parent report on delete track expense"
  • Loading branch information
puneetlath authored Feb 4, 2025
2 parents f24b3eb + 639c3e4 commit 1ab0695
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 46 deletions.
24 changes: 1 addition & 23 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import NAVIGATORS from '@src/NAVIGATORS';
import ONYXKEYS from '@src/ONYXKEYS';
import type {HybridAppRoute, Route} from '@src/ROUTES';
import ROUTES, {HYBRID_APP_ROUTES} from '@src/ROUTES';
import SCREENS, {PROTECTED_SCREENS} from '@src/SCREENS';
import {PROTECTED_SCREENS} from '@src/SCREENS';
import type {Screen} from '@src/SCREENS';
import type {Report} from '@src/types/onyx';
import originalCloseRHPFlow from './closeRHPFlow';
Expand Down Expand Up @@ -428,13 +428,6 @@ function getTopMostCentralPaneRouteFromRootState() {
return getTopmostCentralPaneRoute(navigationRef.getRootState() as State<RootStackParamList>);
}

function getReportRouteByID(reportID?: string) {
if (!reportID) {
return null;
}
return navigationRef.getRootState().routes.find((r) => r.name === SCREENS.REPORT && !!r.params && 'reportID' in r.params && r.params.reportID === reportID);
}

function removeScreenFromNavigationState(screen: Screen) {
isNavigationReady().then(() => {
navigationRef.dispatch((state) => {
Expand All @@ -449,19 +442,6 @@ function removeScreenFromNavigationState(screen: Screen) {
});
}

function removeScreenFromNavigationStateByKey(key: string) {
const state = navigationRef.getRootState();
const routes = state.routes.filter((item) => item.key !== key);

navigationRef.current?.dispatch(() => {
return CommonActions.reset({
...state,
routes,
index: routes.length < state.routes.length ? state.index - 1 : state.index,
});
});
}

export default {
setShouldPopAllStateOnUP,
navigate,
Expand All @@ -487,8 +467,6 @@ export default {
setNavigationActionToMicrotaskQueue,
getTopMostCentralPaneRouteFromRootState,
removeScreenFromNavigationState,
getReportRouteByID,
removeScreenFromNavigationStateByKey,
};

export {navigationRef};
11 changes: 2 additions & 9 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4642,7 +4642,7 @@ function goBackToDetailsPage(report: OnyxEntry<Report>, backTo?: string) {
}
}

function navigateBackOnDeleteTransaction(backRoute: Route | undefined, isFromRHP?: boolean, reportIDToRemove?: string) {
function navigateBackOnDeleteTransaction(backRoute: Route | undefined, isFromRHP?: boolean) {
if (!backRoute) {
return;
}
Expand All @@ -4652,14 +4652,7 @@ function navigateBackOnDeleteTransaction(backRoute: Route | undefined, isFromRHP
return;
}
if (isFromRHP) {
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportIDToRemove}`];
if (report && isTrackExpenseReport(report)) {
const trackReportRoute = Navigation.getReportRouteByID(reportIDToRemove);
if (trackReportRoute?.key) {
Navigation.removeScreenFromNavigationStateByKey(trackReportRoute.key);
}
}
Navigation.isNavigationReady().then(() => Navigation.dismissModal());
Navigation.dismissModal();
}
Navigation.isNavigationReady().then(() => {
Navigation.goBack(backRoute);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,9 @@ function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDeta
Navigation.dismissModal();
} else {
setDeleteTransactionNavigateBackUrl(urlToNavigateBack);
navigateBackOnDeleteTransaction(urlToNavigateBack as Route, true, report.reportID);
navigateBackOnDeleteTransaction(urlToNavigateBack as Route, true);
}
}, [iouTransactionID, requestParentReportAction, isSingleTransactionView, isTransactionDeleted, moneyRequestReport?.reportID, report.reportID]);
}, [iouTransactionID, requestParentReportAction, isSingleTransactionView, isTransactionDeleted, moneyRequestReport?.reportID]);

const mentionReportContextValue = useMemo(() => ({currentReportID: report.reportID, exactlyMatch: true}), [report.reportID]);

Expand Down
12 changes: 0 additions & 12 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,8 @@ jest.mock('@src/libs/Navigation/Navigation', () => ({
goBack: jest.fn(),
getTopmostReportId: jest.fn(() => topMostReportID),
setNavigationActionToMicrotaskQueue: jest.fn(),
removeScreenByKey: jest.fn(),
isNavigationReady: jest.fn(() => Promise.resolve()),
getPreviousTrackReport: jest.fn(),
}));

jest.mock('@src/libs/Navigation/navigationRef', () => ({
getRootState: () => ({
routes: [],
}),
}));

jest.mock('@react-navigation/native');

jest.mock('@src/libs/actions/Report', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const originalModule = jest.requireActual('@src/libs/actions/Report');
Expand All @@ -99,7 +88,6 @@ jest.mock('@src/libs/actions/Report', () => {
notifyNewAction: jest.fn(),
};
});

jest.mock('@src/libs/Navigation/isSearchTopmostCentralPane', () => jest.fn());

const CARLOS_EMAIL = '[email protected]';
Expand Down

0 comments on commit 1ab0695

Please sign in to comment.