Skip to content

Commit 620c531

Browse files
shashjargeorge-sentry
authored andcommitted
ref(projects): Replace useRouter calls for PickProjectToContinue usages (#112317)
getsentry/frontend-tsc#78 Replaces `useRouter` calls in `PickProjectToContinue` component usages.
1 parent e69d59b commit 620c531

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

static/app/components/pickProjectToContinue.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import {useEffect} from 'react';
12
import styled from '@emotion/styled';
23
import type {LocationDescriptor, LocationDescriptorObject} from 'history';
34

45
import {openModal} from 'sentry/actionCreators/modal';
56
import {ContextPickerModalContainer as ContextPickerModal} from 'sentry/components/contextPickerModal';
6-
import type {InjectedRouter} from 'sentry/types/legacyReactRouter';
7+
import {useNavigate} from 'sentry/utils/useNavigate';
78

89
type Project = {
910
id: string;
@@ -22,17 +23,16 @@ type Props = {
2223
*/
2324
noProjectRedirectPath: LocationDescriptor;
2425
projects: Project[];
25-
router: InjectedRouter;
2626
allowAllProjectsSelection?: boolean;
2727
};
2828

2929
export function PickProjectToContinue({
3030
noProjectRedirectPath,
3131
nextPath,
32-
router,
3332
projects,
3433
allowAllProjectsSelection = false,
3534
}: Props) {
35+
const navigate = useNavigate();
3636
const nextPathQuery = nextPath.query;
3737
let navigating = false;
3838
let path = `${nextPath.pathname}?project=`;
@@ -48,8 +48,14 @@ export function PickProjectToContinue({
4848
}
4949

5050
// if the project in URL is missing, but this release belongs to only one project, redirect there
51-
if (projects.length === 1) {
52-
router.replace(path + projects[0]!.id);
51+
const shouldRedirect = projects.length === 1;
52+
useEffect(() => {
53+
if (shouldRedirect) {
54+
navigate(path + projects[0]!.id, {replace: true});
55+
}
56+
}, [shouldRedirect, navigate, path, projects]);
57+
58+
if (shouldRedirect) {
5359
return null;
5460
}
5561

@@ -62,7 +68,7 @@ export function PickProjectToContinue({
6268
nextPath={`${path}:project`}
6369
onFinish={to => {
6470
navigating = true;
65-
router.replace(to);
71+
navigate(to, {replace: true});
6672
modalProps.closeModal();
6773
}}
6874
projectSlugs={projects.map(p => p.slug)}
@@ -74,7 +80,7 @@ export function PickProjectToContinue({
7480
// we want this to be executed only if the user didn't select any project
7581
// (closed modal either via button, Esc, clicking outside, ...)
7682
if (!navigating) {
77-
router.push(noProjectRedirectPath);
83+
navigate(noProjectRedirectPath);
7884
}
7985
},
8086
}

static/app/views/performance/transactionSummary/pageLayout.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {PerformanceEventViewProvider} from 'sentry/utils/performance/contexts/pe
3434
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';
3535
import {useDatePageFilterProps} from 'sentry/utils/useDatePageFilterProps';
3636
import {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
37-
import {useRouter} from 'sentry/utils/useRouter';
3837
import {useTransactionSummaryEAP} from 'sentry/views/performance/eap/useTransactionSummaryEAP';
3938
import {TransactionSummaryContext} from 'sentry/views/performance/transactionSummary/transactionSummaryContext';
4039
import {
@@ -98,7 +97,6 @@ export function PageLayout(props: Props) {
9897
}
9998

10099
const theme = useTheme();
101-
const router = useRouter();
102100
const transactionName = getTransactionName(location);
103101
const [error, setError] = useState<string | undefined>();
104102
const metricsCardinality = useMetricsCardinalityContext();
@@ -241,7 +239,6 @@ export function PageLayout(props: Props) {
241239
<PickProjectToContinue
242240
data-test-id="transaction-sumamry-project-picker-modal"
243241
projects={selectableProjects}
244-
router={router}
245242
nextPath={{
246243
pathname: generateTransactionSummaryRoute({organization}),
247244
query: {

static/app/views/releases/detail/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {useLocation} from 'sentry/utils/useLocation';
3434
import {useNavigate} from 'sentry/utils/useNavigate';
3535
import {useOrganization} from 'sentry/utils/useOrganization';
3636
import {useParams} from 'sentry/utils/useParams';
37-
import {useRouter} from 'sentry/utils/useRouter';
3837
import {formatVersion} from 'sentry/utils/versions/formatVersion';
3938
import type {ReleaseBounds} from 'sentry/views/releases/utils';
4039
import {getReleaseBounds, searchReleaseVersion} from 'sentry/views/releases/utils';
@@ -242,7 +241,6 @@ function ReleasesDetailContainer() {
242241
const params = useParams<{release: string}>();
243242
const location = useLocation();
244243
const navigate = useNavigate();
245-
const router = useRouter();
246244
const organization = useOrganization();
247245
const {release} = params;
248246

@@ -299,7 +297,6 @@ function ReleasesDetailContainer() {
299297
id: String(id),
300298
slug,
301299
}))}
302-
router={router}
303300
nextPath={{
304301
pathname: makeReleasesPathname({
305302
path: `/${encodeURIComponent(release)}/`,

0 commit comments

Comments
 (0)