Skip to content

Commit e741a9a

Browse files
authored
ref(releases): Migrate release actions off deprecated route props (#103705)
switches a few props out for hooks
1 parent 7bb37df commit e741a9a

File tree

3 files changed

+41
-61
lines changed

3 files changed

+41
-61
lines changed

static/app/views/releases/detail/header/releaseActions.spec.tsx

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import type {Location} from 'history';
21
import {HealthFixture} from 'sentry-fixture/health';
3-
import {LocationFixture} from 'sentry-fixture/locationFixture';
42
import {OrganizationFixture} from 'sentry-fixture/organization';
53
import {ReleaseFixture} from 'sentry-fixture/release';
64
import {ReleaseMetaFixture} from 'sentry-fixture/releaseMeta';
75
import {ReleaseProjectFixture} from 'sentry-fixture/releaseProject';
8-
import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
9-
import {RouterFixture} from 'sentry-fixture/routerFixture';
106

117
import {
128
render,
@@ -15,13 +11,13 @@ import {
1511
userEvent,
1612
waitFor,
1713
} from 'sentry-test/reactTestingLibrary';
14+
import type {RouterConfig} from 'sentry-test/reactTestingLibrary';
1815

1916
import type {ReleaseProject} from 'sentry/types/release';
2017
import {ReleaseStatus} from 'sentry/types/release';
2118
import ReleaseActions from 'sentry/views/releases/detail/header/releaseActions';
2219

2320
describe('ReleaseActions', () => {
24-
const router = RouterFixture();
2521
const organization = OrganizationFixture();
2622

2723
const project1 = ReleaseProjectFixture({
@@ -40,15 +36,17 @@ describe('ReleaseActions', () => {
4036
projects: [project1, project2],
4137
});
4238

43-
const location: Location = {
44-
...LocationFixture(),
45-
pathname: `/organizations/${organization.slug}/releases/${release.version}/`,
46-
query: {
47-
project: '1',
48-
statsPeriod: '24h',
49-
yAxis: 'events',
39+
const initialRouterConfig: RouterConfig = {
40+
location: {
41+
pathname: `/organizations/${organization.slug}/releases/${release.version}/`,
42+
query: {
43+
project: '1',
44+
statsPeriod: '24h',
45+
yAxis: 'events',
46+
},
5047
},
5148
};
49+
5250
let mockUpdate: ReturnType<typeof MockApiClient.addMockResponse>;
5351

5452
beforeEach(() => {
@@ -63,21 +61,19 @@ describe('ReleaseActions', () => {
6361
});
6462

6563
it('archives a release', async () => {
66-
render(
64+
const {router} = render(
6765
<ReleaseActions
68-
organization={organization}
6966
projectSlug={release.projects[0]!.slug}
7067
release={release}
7168
refetchData={jest.fn()}
7269
releaseMeta={{...ReleaseMetaFixture(), projects: release.projects}}
73-
location={location}
7470
/>,
7571
{
76-
router,
77-
deprecatedRouterMocks: true,
72+
organization,
73+
initialRouterConfig,
7874
}
7975
);
80-
renderGlobalModal({router, deprecatedRouterMocks: true});
76+
renderGlobalModal();
8177

8278
await userEvent.click(screen.getByLabelText('Actions'));
8379

@@ -106,8 +102,10 @@ describe('ReleaseActions', () => {
106102
})
107103
);
108104
await waitFor(() =>
109-
expect(router.push).toHaveBeenCalledWith(
110-
`/organizations/${organization.slug}/explore/releases/`
105+
expect(router.location).toEqual(
106+
expect.objectContaining({
107+
pathname: `/organizations/${organization.slug}/explore/releases/`,
108+
})
111109
)
112110
);
113111
});
@@ -117,20 +115,17 @@ describe('ReleaseActions', () => {
117115

118116
render(
119117
<ReleaseActions
120-
{...RouteComponentPropsFixture()}
121-
organization={organization}
122118
projectSlug={release.projects[0]!.slug}
123119
release={{...release, status: ReleaseStatus.ARCHIVED}}
124120
refetchData={refetchDataMock}
125121
releaseMeta={{...ReleaseMetaFixture(), projects: release.projects}}
126-
location={location}
127122
/>,
128123
{
129-
router,
130-
deprecatedRouterMocks: true,
124+
organization,
125+
initialRouterConfig,
131126
}
132127
);
133-
renderGlobalModal({router});
128+
renderGlobalModal();
134129

135130
await userEvent.click(screen.getByLabelText('Actions'));
136131

@@ -162,19 +157,17 @@ describe('ReleaseActions', () => {
162157
await waitFor(() => expect(refetchDataMock).toHaveBeenCalledTimes(1));
163158
});
164159

165-
it('navigates to a next/prev release', () => {
166-
const {rerender} = render(
160+
it('navigates to a next/prev release', async () => {
161+
const {router} = render(
167162
<ReleaseActions
168-
organization={organization}
169163
projectSlug={release.projects[0]!.slug}
170164
release={release}
171165
refetchData={jest.fn()}
172166
releaseMeta={{...ReleaseMetaFixture(), projects: release.projects}}
173-
location={location}
174167
/>,
175168
{
176-
router,
177-
deprecatedRouterMocks: true,
169+
organization,
170+
initialRouterConfig,
178171
}
179172
);
180173

@@ -195,19 +188,13 @@ describe('ReleaseActions', () => {
195188
`/organizations/${organization.slug}/releases/999/?project=1&statsPeriod=24h&yAxis=events`
196189
);
197190

198-
rerender(
199-
<ReleaseActions
200-
organization={organization}
201-
projectSlug={release.projects[0]!.slug}
202-
release={release}
203-
refetchData={jest.fn()}
204-
releaseMeta={{...ReleaseMetaFixture(), projects: release.projects}}
205-
location={{
206-
...location,
207-
pathname: `/organizations/${organization.slug}/releases/${release.version}/files-changed/`,
208-
}}
209-
/>
210-
);
191+
// Simulate navigation to a sub-page
192+
await waitFor(() => {
193+
router.navigate({
194+
pathname: `/organizations/${organization.slug}/releases/${release.version}/files-changed/`,
195+
search: 'project=1&statsPeriod=24h&yAxis=events',
196+
});
197+
});
211198

212199
expect(screen.getByLabelText('Newer')).toHaveAttribute(
213200
'href',

static/app/views/releases/detail/header/releaseActions.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {Fragment} from 'react';
22
import styled from '@emotion/styled';
3-
import type {Location} from 'history';
43

54
import {archiveRelease, restoreRelease} from 'sentry/actionCreators/release';
65
import {Client} from 'sentry/api';
@@ -14,39 +13,35 @@ import TextOverflow from 'sentry/components/textOverflow';
1413
import {IconEllipsis, IconNext, IconPrevious} from 'sentry/icons';
1514
import {t, tct, tn} from 'sentry/locale';
1615
import {space} from 'sentry/styles/space';
17-
import type {Organization} from 'sentry/types/organization';
1816
import type {Release, ReleaseMeta} from 'sentry/types/release';
1917
import {trackAnalytics} from 'sentry/utils/analytics';
20-
import {browserHistory} from 'sentry/utils/browserHistory';
18+
import {useLocation} from 'sentry/utils/useLocation';
19+
import {useNavigate} from 'sentry/utils/useNavigate';
20+
import useOrganization from 'sentry/utils/useOrganization';
2121
import {formatVersion} from 'sentry/utils/versions/formatVersion';
2222
import {isReleaseArchived} from 'sentry/views/releases/utils';
2323
import {makeReleasesPathname} from 'sentry/views/releases/utils/pathnames';
2424

2525
type Props = {
26-
location: Location;
27-
organization: Organization;
2826
projectSlug: string;
2927
refetchData: () => void;
3028
release: Release;
3129
releaseMeta: ReleaseMeta;
3230
};
3331

34-
function ReleaseActions({
35-
location,
36-
organization,
37-
projectSlug,
38-
release,
39-
releaseMeta,
40-
refetchData,
41-
}: Props) {
32+
function ReleaseActions({projectSlug, release, releaseMeta, refetchData}: Props) {
33+
const location = useLocation();
34+
const navigate = useNavigate();
35+
const organization = useOrganization();
36+
4237
async function handleArchive() {
4338
try {
4439
await archiveRelease(new Client(), {
4540
orgSlug: organization.slug,
4641
projectSlug,
4742
releaseVersion: release.version,
4843
});
49-
browserHistory.push(
44+
navigate(
5045
makeReleasesPathname({
5146
organization,
5247
path: '/',

static/app/views/releases/detail/header/releaseHeader.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,10 @@ function ReleaseHeader({
174174

175175
<Layout.HeaderActions>
176176
<ReleaseActions
177-
organization={organization}
178177
projectSlug={project.slug}
179178
release={release}
180179
releaseMeta={releaseMeta}
181180
refetchData={refetchData}
182-
location={location}
183181
/>
184182
</Layout.HeaderActions>
185183

0 commit comments

Comments
 (0)