Skip to content

Commit 08aa2bc

Browse files
authored
Merge pull request #91508 from marufsharifi/fix/preserve-search-context-when-opening-reports
Preserve Search context when opening reports
2 parents 3e3f6e1 + 2587184 commit 08aa2bc

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

src/components/ReportActionItem/TaskPreview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ import ControlSelection from '@libs/ControlSelection';
2929
import {canUseTouchScreen} from '@libs/DeviceCapabilities';
3030
import getButtonState from '@libs/getButtonState';
3131
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
32+
import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext';
3233
import Navigation from '@libs/Navigation/Navigation';
3334
import Parser from '@libs/Parser';
3435
import {getOriginalMessage} from '@libs/ReportActionsUtils';
3536
import {isCanceledTaskReport, isOpenTaskReport, isReportManager} from '@libs/ReportUtils';
3637
import CONST from '@src/CONST';
3738
import ONYXKEYS from '@src/ONYXKEYS';
38-
import ROUTES from '@src/ROUTES';
3939
import type {Report, ReportAction} from '@src/types/onyx';
4040
import {isEmptyObject} from '@src/types/utils/EmptyObject';
4141

@@ -121,7 +121,7 @@ function TaskPreview({action, chatReportID, currentUserPersonalDetails, isHovere
121121
return (
122122
<View style={[styles.chatItemMessage, !hasAssignee && styles.mv1]}>
123123
<PressableWithoutFeedback
124-
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(taskReportID, undefined, undefined, Navigation.getActiveRoute()))}
124+
onPress={() => Navigation.navigate(getReportRouteForCurrentContext({reportID: taskReportID}))}
125125
onPressIn={() => canUseTouchScreen() && ControlSelection.block()}
126126
onPressOut={() => ControlSelection.unblock()}
127127
onLongPress={(event) =>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Navigation from '@libs/Navigation/Navigation';
2+
import type {Route} from '@src/ROUTES';
3+
import ROUTES from '@src/ROUTES';
4+
import isSearchTopmostFullScreenRoute from './isSearchTopmostFullScreenRoute';
5+
6+
type GetReportRouteForCurrentContextParams = {
7+
reportID: string | undefined;
8+
};
9+
10+
function getReportRouteForCurrentContext({reportID}: GetReportRouteForCurrentContextParams): Route {
11+
if (!reportID) {
12+
return ROUTES.REPORT_WITH_ID.getRoute('');
13+
}
14+
15+
const backTo = Navigation.getActiveRoute();
16+
if (isSearchTopmostFullScreenRoute()) {
17+
return ROUTES.SEARCH_REPORT.getRoute({reportID, backTo});
18+
}
19+
20+
return ROUTES.REPORT_WITH_ID.getRoute(reportID, undefined, undefined, backTo);
21+
}
22+
23+
export default getReportRouteForCurrentContext;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import getReportRouteForCurrentContext from '@libs/Navigation/helpers/getReportRouteForCurrentContext';
2+
import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute';
3+
import Navigation from '@libs/Navigation/Navigation';
4+
import ROUTES from '@src/ROUTES';
5+
6+
jest.mock('@libs/Navigation/Navigation', () => ({
7+
getActiveRoute: jest.fn(),
8+
}));
9+
10+
jest.mock('@libs/Navigation/helpers/isSearchTopmostFullScreenRoute', () => jest.fn());
11+
12+
describe('getReportRouteForCurrentContext', () => {
13+
const mockGetActiveRoute = Navigation.getActiveRoute as jest.MockedFunction<typeof Navigation.getActiveRoute>;
14+
const mockIsSearchTopmostFullScreenRoute = isSearchTopmostFullScreenRoute as jest.MockedFunction<typeof isSearchTopmostFullScreenRoute>;
15+
16+
beforeEach(() => {
17+
jest.clearAllMocks();
18+
mockGetActiveRoute.mockReturnValue('search?q=type:chat');
19+
mockIsSearchTopmostFullScreenRoute.mockReturnValue(false);
20+
});
21+
22+
it('returns the default report route when Search is not the topmost fullscreen route', () => {
23+
expect(getReportRouteForCurrentContext({reportID: '42'})).toBe(ROUTES.REPORT_WITH_ID.getRoute('42', undefined, undefined, 'search?q=type:chat'));
24+
});
25+
26+
it('returns the search report route when Search is the topmost fullscreen route', () => {
27+
mockIsSearchTopmostFullScreenRoute.mockReturnValue(true);
28+
29+
expect(getReportRouteForCurrentContext({reportID: '42'})).toBe(
30+
ROUTES.SEARCH_REPORT.getRoute({
31+
reportID: '42',
32+
backTo: 'search?q=type:chat',
33+
}),
34+
);
35+
});
36+
});

0 commit comments

Comments
 (0)