Skip to content

Commit 74876e4

Browse files
shashjargeorge-sentry
authored andcommitted
ref(admin): Replace useRouter usage in CustomerStats & CustomerStatsFilters (#112291)
getsentry/frontend-tsc#78 Replaces `useRouter` usages in `CustomerStats` & `CustomerStatsFilters`.
1 parent d3241ca commit 74876e4

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

static/gsAdmin/components/customers/customerStats.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {defined} from 'sentry/utils';
2222
import {getApiUrl} from 'sentry/utils/api/getApiUrl';
2323
import {getDynamicText} from 'sentry/utils/getDynamicText';
2424
import {useApiQuery} from 'sentry/utils/queryClient';
25-
import {useRouter} from 'sentry/utils/useRouter';
25+
import {useLocation} from 'sentry/utils/useLocation';
2626

2727
enum SeriesName {
2828
ACCEPTED = 'Accepted',
@@ -434,15 +434,15 @@ type Props = {
434434

435435
export const CustomerStats = memo(
436436
({orgSlug, projectId, dataType, onDemandPeriodStart, onDemandPeriodEnd}: Props) => {
437-
const router = useRouter();
437+
const location = useLocation();
438438

439439
const dataDatetime = useMemo((): DateTimeObject => {
440440
const {
441441
start,
442442
end,
443443
utc: utcString,
444444
statsPeriod,
445-
} = normalizeDateTimeParams(router.location.query, {
445+
} = normalizeDateTimeParams(location.query, {
446446
allowEmptyPeriod: true,
447447
allowAbsoluteDatetime: true,
448448
allowAbsolutePageDatetime: true,
@@ -474,7 +474,7 @@ export const CustomerStats = memo(
474474
return {
475475
period: statsPeriod ?? '90d',
476476
};
477-
}, [router.location.query, onDemandPeriodStart, onDemandPeriodEnd]);
477+
}, [location.query, onDemandPeriodStart, onDemandPeriodEnd]);
478478

479479
const statsEndpointUrl = getApiUrl(`/organizations/$organizationIdOrSlug/stats_v2/`, {
480480
path: {organizationIdOrSlug: orgSlug},

static/gsAdmin/components/customers/customerStatsFilters.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
import {DATA_CATEGORY_INFO, DEFAULT_RELATIVE_PERIODS} from 'sentry/constants';
1818
import {DataCategoryExact} from 'sentry/types/core';
1919
import type {Organization} from 'sentry/types/organization';
20-
import {useRouter} from 'sentry/utils/useRouter';
20+
import {useLocation} from 'sentry/utils/useLocation';
21+
import {useNavigate} from 'sentry/utils/useNavigate';
2122

2223
const ON_DEMAND_PERIOD_KEY = 'onDemand';
2324

@@ -35,13 +36,12 @@ export function CustomerStatsFilters({
3536
onDemandPeriodStart,
3637
onDemandPeriodEnd,
3738
}: Props) {
38-
const router = useRouter();
39+
const location = useLocation();
40+
const navigate = useNavigate();
3941
const onDemand = !!onDemandPeriodStart && !!onDemandPeriodEnd;
4042

4143
const pageDateTime = useMemo((): DateTimeObject => {
42-
const query = router.location.query;
43-
44-
const {start, end, statsPeriod} = normalizeDateTimeParams(query, {
44+
const {start, end, statsPeriod} = normalizeDateTimeParams(location.query, {
4545
allowEmptyPeriod: true,
4646
allowAbsoluteDatetime: true,
4747
allowAbsolutePageDatetime: true,
@@ -59,7 +59,7 @@ export function CustomerStatsFilters({
5959
}
6060

6161
return {};
62-
}, [router.location.query]);
62+
}, [location.query]);
6363

6464
const handleDateChange = useCallback(
6565
(datetime: ChangeData) => {
@@ -68,10 +68,10 @@ export function CustomerStatsFilters({
6868
if (start && end) {
6969
const parser = utc ? moment.utc : moment;
7070

71-
router.push({
71+
navigate({
7272
...location,
7373
query: {
74-
...router.location.query,
74+
...location.query,
7575
statsPeriod: undefined,
7676
start: parser(start).format(),
7777
end: parser(end).format(),
@@ -81,18 +81,18 @@ export function CustomerStatsFilters({
8181
return;
8282
}
8383

84-
router.push({
84+
navigate({
8585
...location,
8686
query: {
87-
...router.location.query,
87+
...location.query,
8888
statsPeriod: relative === ON_DEMAND_PERIOD_KEY ? undefined : relative,
8989
start: undefined,
9090
end: undefined,
9191
utc: undefined,
9292
},
9393
});
9494
},
95-
[router]
95+
[location, navigate]
9696
);
9797

9898
const {start, end, period, utc} = pageDateTime;

0 commit comments

Comments
 (0)