Skip to content
Merged
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
8 changes: 6 additions & 2 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3154,8 +3154,12 @@ function deleteReportComment(
// we should navigate to its report in order to not show not found page
if (Navigation.isActiveRoute(ROUTES.REPORT_WITH_ID.getRoute(reportID, reportActionID)) && !isDeletedParentAction) {
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(reportID));
} else if (Navigation.isActiveRoute(ROUTES.REPORT_WITH_ID.getRoute(reportAction.childReportID)) && !isDeletedParentAction) {
Navigation.goBack(undefined);
Comment on lines -3157 to -3158

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot Which PR first introduced this logic? Trying to find offending PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else if branch that navigates back when the deleted action's childReportID is the active route was first introduced in #58889 ("fix: header shows skeleton, message is empty" by nkdengineer, merged 2025-03-23, fixing #58134).

Before that PR the block only had the first if (navigate back from REPORT_WITH_ID.getRoute(reportID, reportActionID)), so #58889 is where the child-report goBack logic originated. This PR (#94293) later refactored that same branch to also handle the SEARCH_REPORT route.

Blame evidence

Blame of the pre-#94293 version of src/libs/actions/Report/index.ts:3157-3158:

eb215dab1aae (nkdengineer 2025-03-21)  } else if (Navigation.isActiveRoute(ROUTES.REPORT_WITH_ID.getRoute(reportAction.childReportID)) && !isDeletedParentAction) {
d2cea8ba7aa6 (nkdengineer 2025-03-21)      Navigation.goBack(undefined);

Both commits merged via #58889.

} else if (!isDeletedParentAction && reportAction.childReportID) {
const isOnChildReport = Navigation.isActiveRoute(ROUTES.REPORT_WITH_ID.getRoute(reportAction.childReportID));
const isOnSearchChildReport = Navigation.getTopmostSearchReportRouteParams()?.reportID === reportAction.childReportID;
if (isOnChildReport || isOnSearchChildReport) {
Navigation.goBack();
}
}
}

Expand Down
54 changes: 54 additions & 0 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ jest.mock('@libs/Navigation/Navigation', () => ({
isActiveRoute: jest.fn(() => false),
getTopmostReportId: jest.fn(() => undefined),
getTopmostSuperWideRHPReportID: jest.fn(() => undefined),
getTopmostSearchReportRouteParams: jest.fn(() => undefined),
goBack: jest.fn(),
popToSidebar: jest.fn(),
navigationRef: {
Expand Down Expand Up @@ -2536,6 +2537,59 @@ describe('actions/Report', () => {
expect(report?.lastMentionedTime).toBeUndefined();
});

describe('deleteReportComment SEARCH_REPORT navigation', () => {
const PARENT_REPORT_ID = '100';
const CHILD_REPORT_ID = '200';
const TEST_USER_ACCOUNT_ID = 1;

const mockNavigation: {isActiveRoute: jest.Mock; goBack: jest.Mock; getTopmostSearchReportRouteParams: jest.Mock} = jest.requireMock('@libs/Navigation/Navigation');

beforeEach(() => {
mockNavigation.goBack.mockClear();
});

afterEach(() => {
mockNavigation.isActiveRoute.mockImplementation(() => false);
mockNavigation.getTopmostSearchReportRouteParams.mockReturnValue(undefined);
});

it('calls goBack when viewing the child thread at search/view/<childReportID>', async () => {
const created = format(addSeconds(subMinutes(new Date(), 10), 10), CONST.DATE.FNS_DB_FORMAT_STRING);
const parentReport: OnyxTypes.Report = createRandomReport(Number(PARENT_REPORT_ID), undefined);
const reportAction = {
...TestHelper.buildTestReportComment(created, TEST_USER_ACCOUNT_ID, '101'),
childReportID: CHILD_REPORT_ID,
childVisibleActionCount: 0,
};

mockNavigation.getTopmostSearchReportRouteParams.mockReturnValue({reportID: CHILD_REPORT_ID});

const {result: ancestors} = renderHook(() => useAncestors(parentReport));
Report.deleteReportComment(parentReport, reportAction, ancestors.current, undefined, undefined, '');
await waitForBatchedUpdates();

expect(mockNavigation.goBack).toHaveBeenCalled();
});

it('calls goBack when viewing the child thread at search/view/<childReportID>/<reportActionID>', async () => {
const created = format(addSeconds(subMinutes(new Date(), 10), 10), CONST.DATE.FNS_DB_FORMAT_STRING);
const parentReport: OnyxTypes.Report = createRandomReport(Number(PARENT_REPORT_ID), undefined);
const reportAction = {
...TestHelper.buildTestReportComment(created, TEST_USER_ACCOUNT_ID, '101'),
childReportID: CHILD_REPORT_ID,
childVisibleActionCount: 0,
};

mockNavigation.getTopmostSearchReportRouteParams.mockReturnValue({reportID: CHILD_REPORT_ID, reportActionID: 'action-999'});

const {result: ancestors} = renderHook(() => useAncestors(parentReport));
Report.deleteReportComment(parentReport, reportAction, ancestors.current, undefined, undefined, '');
await waitForBatchedUpdates();

expect(mockNavigation.goBack).toHaveBeenCalled();
});
});

it('should create new report and "create report" quick action, when createNewReport gets called', async () => {
const accountID = 1234;
const policyID = '5678';
Expand Down
Loading