Skip to content

Commit d5e6ef7

Browse files
ref(js): Remove browserHistory from discover utils (#82594)
1 parent 2da8db1 commit d5e6ef7

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

static/app/utils/useNavigate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type NavigateOptions = {
1212
state?: any;
1313
};
1414

15-
interface ReactRouter3Navigate {
15+
export interface ReactRouter3Navigate {
1616
(to: LocationDescriptor, options?: NavigateOptions): void;
1717
(delta: number): void;
1818
}

static/app/views/discover/table/tableView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {generateProfileFlamechartRoute} from 'sentry/utils/profiling/routes';
4949
import {decodeList} from 'sentry/utils/queryString';
5050
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
5151
import normalizeUrl from 'sentry/utils/url/normalizeUrl';
52+
import {useNavigate} from 'sentry/utils/useNavigate';
5253
import useProjects from 'sentry/utils/useProjects';
5354
import {useRoutes} from 'sentry/utils/useRoutes';
5455
import {appendQueryDatasetParam, hasDatasetSelector} from 'sentry/views/dashboards/utils';
@@ -109,6 +110,7 @@ export type TableViewProps = {
109110
function TableView(props: TableViewProps) {
110111
const {projects} = useProjects();
111112
const routes = useRoutes();
113+
const navigate = useNavigate();
112114
const replayLinkGenerator = generateReplayLink(routes);
113115

114116
/**
@@ -124,6 +126,7 @@ function TableView(props: TableViewProps) {
124126
const nextEventView = eventView.withResizedColumn(columnIndex, newWidth);
125127

126128
pushEventViewToLocation({
129+
navigate,
127130
location,
128131
nextEventView,
129132
extraQuery: {

static/app/views/discover/utils.spec.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {LocationFixture} from 'sentry-fixture/locationFixture';
44
import {initializeOrg} from 'sentry-test/initializeOrg';
55

66
import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
7-
import {browserHistory} from 'sentry/utils/browserHistory';
87
import type {EventViewOptions} from 'sentry/utils/discover/eventView';
98
import EventView from 'sentry/utils/discover/eventView';
109
import {DisplayType} from 'sentry/views/dashboards/types';
@@ -252,14 +251,16 @@ describe('pushEventViewToLocation', function () {
252251
});
253252

254253
it('correct query string object pushed to history', function () {
254+
const navigate = jest.fn();
255255
const eventView = new EventView({...baseView, ...state});
256256

257257
pushEventViewToLocation({
258+
navigate,
258259
location,
259260
nextEventView: eventView,
260261
});
261262

262-
expect(browserHistory.push).toHaveBeenCalledWith(
263+
expect(navigate).toHaveBeenCalledWith(
263264
expect.objectContaining({
264265
query: expect.objectContaining({
265266
id: '1234',
@@ -280,17 +281,19 @@ describe('pushEventViewToLocation', function () {
280281
});
281282

282283
it('extra query params', function () {
284+
const navigate = jest.fn();
283285
const eventView = new EventView({...baseView, ...state});
284286

285287
pushEventViewToLocation({
288+
navigate,
286289
location,
287290
nextEventView: eventView,
288291
extraQuery: {
289292
cursor: 'some cursor',
290293
},
291294
});
292295

293-
expect(browserHistory.push).toHaveBeenCalledWith(
296+
expect(navigate).toHaveBeenCalledWith(
294297
expect.objectContaining({
295298
query: expect.objectContaining({
296299
id: '1234',

static/app/views/discover/utils.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type {
1515
OrganizationSummary,
1616
} from 'sentry/types/organization';
1717
import type {Project} from 'sentry/types/project';
18-
import {browserHistory} from 'sentry/utils/browserHistory';
1918
import {getUtcDateString} from 'sentry/utils/dates';
2019
import type {TableDataRow} from 'sentry/utils/discover/discoverQuery';
2120
import type {EventData} from 'sentry/utils/discover/eventView';
@@ -48,6 +47,7 @@ import {getTitle} from 'sentry/utils/events';
4847
import {DISCOVER_FIELDS, FieldValueType, getFieldDefinition} from 'sentry/utils/fields';
4948
import localStorage from 'sentry/utils/localStorage';
5049
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
50+
import type {ReactRouter3Navigate} from 'sentry/utils/useNavigate';
5151

5252
import {
5353
DashboardWidgetSource,
@@ -124,14 +124,15 @@ export function decodeColumnOrder(fields: Readonly<Field[]>): TableColumn<string
124124

125125
export function pushEventViewToLocation(props: {
126126
location: Location;
127+
navigate: ReactRouter3Navigate;
127128
nextEventView: EventView;
128129
extraQuery?: Query;
129130
}) {
130-
const {location, nextEventView} = props;
131+
const {navigate, location, nextEventView} = props;
131132
const extraQuery = props.extraQuery || {};
132133
const queryStringObject = nextEventView.generateQueryStringObject();
133134

134-
browserHistory.push({
135+
navigate({
135136
...location,
136137
query: {
137138
...extraQuery,

0 commit comments

Comments
 (0)