Skip to content

Commit 1636a61

Browse files
ref(issue-details): replace useRouter with specific hooks in useGroupDetailsRoute (#110122)
Part of the React Router 6 cleanup — replaces `useRouter()` with specific hooks (`useNavigate`, `useLocation`, `useParams`, etc.) --------- Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
1 parent 7652d18 commit 1636a61

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
1+
import type {PlainRoute} from 'sentry/types/legacyReactRouter';
22
import type {Organization} from 'sentry/types/organization';
33
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';
44
import {useOrganization} from 'sentry/utils/useOrganization';
55
import {useParams} from 'sentry/utils/useParams';
6-
import {useRouter} from 'sentry/utils/useRouter';
6+
import {useRoutes} from 'sentry/utils/useRoutes';
77
import {Tab, TabPaths} from 'sentry/views/issueDetails/types';
88

9-
type RouteProps = RouteComponentProps<{groupId: string; eventId?: string}>;
10-
11-
function getCurrentTab({router}: {router: RouteProps['router']}) {
12-
const currentRoute = router.routes[router.routes.length - 1];
9+
function getCurrentTab({
10+
routes,
11+
params,
12+
}: {
13+
params: Record<string, string | undefined>;
14+
routes: PlainRoute[];
15+
}) {
16+
const currentRoute = routes[routes.length - 1];
1317

1418
// If we're in the tag details page ("/distributions/:tagKey/")
15-
if (router.params.tagKey) {
19+
if (params.tagKey) {
1620
return Tab.DISTRIBUTIONS;
1721
}
1822
return (
@@ -24,21 +28,23 @@ function getCurrentRouteInfo({
2428
groupId,
2529
eventId,
2630
organization,
27-
router,
31+
routes,
32+
params,
2833
}: {
2934
eventId: string | undefined;
3035
groupId: string;
3136
organization: Organization;
32-
router: RouteProps['router'];
37+
params: Record<string, string | undefined>;
38+
routes: PlainRoute[];
3339
}): {
3440
baseUrl: string;
3541
currentTab: Tab;
3642
} {
37-
const currentTab = getCurrentTab({router});
43+
const currentTab = getCurrentTab({routes, params});
3844

3945
const baseUrl = normalizeUrl(
4046
`/organizations/${organization.slug}/issues/${groupId}/${
41-
router.params.eventId && eventId ? `events/${eventId}/` : ''
47+
params.eventId && eventId ? `events/${eventId}/` : ''
4248
}`
4349
);
4450

@@ -50,12 +56,17 @@ export function useGroupDetailsRoute(): {
5056
currentTab: Tab;
5157
} {
5258
const organization = useOrganization();
53-
const params = useParams<{groupId: string; eventId?: string}>();
54-
const router = useRouter();
59+
const params = useParams<{
60+
groupId: string;
61+
eventId?: string;
62+
tagKey?: string;
63+
}>();
64+
const routes = useRoutes();
5565
return getCurrentRouteInfo({
5666
groupId: params.groupId,
5767
eventId: params.eventId,
5868
organization,
59-
router,
69+
routes,
70+
params,
6071
});
6172
}

0 commit comments

Comments
 (0)