Skip to content

Commit 9bb8da6

Browse files
authored
ref(performance): Remove browserHistory usages from some performance views (#112554)
getsentry/frontend-tsc#78 Removes `browserHistory` usages from some performance views.
1 parent 65bf4f0 commit 9bb8da6

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

static/app/views/performance/table.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {t, tct} from 'sentry/locale';
1919
import type {Organization} from 'sentry/types/organization';
2020
import type {Project} from 'sentry/types/project';
2121
import {trackAnalytics} from 'sentry/utils/analytics';
22-
import {browserHistory} from 'sentry/utils/browserHistory';
2322
import type {TableData, TableDataRow} from 'sentry/utils/discover/discoverQuery';
2423
import {DiscoverQuery} from 'sentry/utils/discover/discoverQuery';
2524
import type {EventView, MetaType} from 'sentry/utils/discover/eventView';
@@ -30,6 +29,7 @@ import {MEPConsumer} from 'sentry/utils/performance/contexts/metricsEnhancedSett
3029
import {VisuallyCompleteWithData} from 'sentry/utils/performanceForSentry';
3130
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
3231
import {useLocation} from 'sentry/utils/useLocation';
32+
import {useNavigate} from 'sentry/utils/useNavigate';
3333
import {useOrganization} from 'sentry/utils/useOrganization';
3434
import {Actions, CellAction, updateQuery} from 'sentry/views/discover/table/cellAction';
3535
import type {TableColumn} from 'sentry/views/discover/table/types';
@@ -132,6 +132,7 @@ export function Table({
132132
const [tableMetricSet, setTableMetricSet] = useState(false);
133133
const unparameterizedMetricProject = useRef<{project?: Project | undefined}>(undefined);
134134

135+
const navigate = useNavigate();
135136
const domainViewFilters = useDomainViewFilters();
136137

137138
useEffect(() => {
@@ -237,7 +238,7 @@ export function Table({
237238

238239
updateQuery(searchConditions, action, column, value);
239240

240-
browserHistory.push({
241+
navigate({
241242
pathname: location.pathname,
242243
query: {
243244
...location.query,

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import type {Organization} from 'sentry/types/organization';
2323
import type {Project} from 'sentry/types/project';
2424
import {defined} from 'sentry/utils';
2525
import {trackAnalytics} from 'sentry/utils/analytics';
26-
import {browserHistory} from 'sentry/utils/browserHistory';
2726
import {DiscoverQuery} from 'sentry/utils/discover/discoverQuery';
2827
import type {EventView} from 'sentry/utils/discover/eventView';
2928
import {
@@ -34,6 +33,8 @@ import {PerformanceEventViewProvider} from 'sentry/utils/performance/contexts/pe
3433
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';
3534
import {useDatePageFilterProps} from 'sentry/utils/useDatePageFilterProps';
3635
import {useMaxPickableDays} from 'sentry/utils/useMaxPickableDays';
36+
import {useNavigate} from 'sentry/utils/useNavigate';
37+
import type {ReactRouter3Navigate} from 'sentry/utils/useNavigate';
3738
import {useTransactionSummaryEAP} from 'sentry/views/performance/eap/useTransactionSummaryEAP';
3839
import {TransactionSummaryContext} from 'sentry/views/performance/transactionSummary/transactionSummaryContext';
3940
import {
@@ -97,6 +98,7 @@ export function PageLayout(props: Props) {
9798
}
9899

99100
const theme = useTheme();
101+
const navigate = useNavigate();
100102
const transactionName = getTransactionName(location);
101103
const [error, setError] = useState<string | undefined>();
102104
const metricsCardinality = useMetricsCardinalityContext();
@@ -175,15 +177,15 @@ export function PageLayout(props: Props) {
175177
});
176178
}
177179

178-
browserHistory.push(normalizeUrl(getNewRoute(newTab)));
180+
navigate(normalizeUrl(getNewRoute(newTab)));
179181
},
180-
[getNewRoute, tab, organization, location, projects]
182+
[getNewRoute, tab, organization, location, projects, navigate]
181183
);
182184

183185
const shouldUseEAP = useTransactionSummaryEAP();
184186

185187
if (!defined(transactionName)) {
186-
redirectToPerformanceHomepage(organization, location);
188+
redirectToPerformanceHomepage(organization, location, navigate);
187189
return null;
188190
}
189191

@@ -222,7 +224,7 @@ export function PageLayout(props: Props) {
222224
{({isLoading, tableData, error: discoverQueryError}) => {
223225
if (discoverQueryError) {
224226
addErrorMessage(t('Unable to get projects associated with transaction'));
225-
redirectToPerformanceHomepage(organization, location);
227+
redirectToPerformanceHomepage(organization, location, navigate);
226228
return null;
227229
}
228230

@@ -369,15 +371,17 @@ const StyledBody = styled(Layout.Body)<{fillSpace?: boolean; hasError?: boolean}
369371

370372
export function redirectToPerformanceHomepage(
371373
organization: Organization,
372-
location: Location
374+
location: Location,
375+
navigate: ReactRouter3Navigate
373376
) {
374377
// If there is no transaction name, redirect to the Performance landing page
375-
browserHistory.replace(
378+
navigate(
376379
normalizeUrl({
377380
pathname: getPerformanceBaseUrl(organization.slug, 'backend'),
378381
query: {
379382
...location.query,
380383
},
381-
})
384+
}),
385+
{replace: true}
382386
);
383387
}

static/app/views/performance/transactionSummary/transactionEvents/operationSort.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {Radio} from '@sentry/scraps/radio';
1010
import type {GetActorPropsFn} from 'sentry/components/deprecatedDropdownMenu';
1111
import {MenuItem} from 'sentry/components/menuItem';
1212
import {t} from 'sentry/locale';
13-
import {browserHistory} from 'sentry/utils/browserHistory';
1413
import type {TableData} from 'sentry/utils/discover/discoverQuery';
1514
import type {EventView} from 'sentry/utils/discover/eventView';
15+
import {useNavigate} from 'sentry/utils/useNavigate';
1616

1717
export type TitleProps = Partial<ReturnType<GetActorPropsFn>>;
1818

@@ -24,6 +24,7 @@ type Props = {
2424
};
2525

2626
export function OperationSort({eventView, location, tableMeta, title: Title}: Props) {
27+
const navigate = useNavigate();
2728
const [isOpen, setIsOpen] = useState(false);
2829
const menuEl = useRef<Element | null>(null);
2930

@@ -75,7 +76,7 @@ export function OperationSort({eventView, location, tableMeta, title: Title}: Pr
7576
onClick={() => {
7677
const sortLink = generateSortLink({field: operation});
7778
if (sortLink) {
78-
browserHistory.push(sortLink);
79+
navigate(sortLink);
7980
}
8081
}}
8182
/>

static/app/views/performance/transactionSummary/transactionProfiles/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ const StyledMain = styled(Layout.Main)`
146146
function ProfilesIndex() {
147147
const organization = useOrganization();
148148
const location = useLocation();
149+
const navigate = useNavigate();
149150
const transaction = decodeScalar(location.query.transaction);
150151

151152
if (!transaction) {
152-
redirectToPerformanceHomepage(organization, location);
153+
redirectToPerformanceHomepage(organization, location, navigate);
153154
return null;
154155
}
155156

0 commit comments

Comments
 (0)