From 9c5544a6deb8404d35a5cbe840a4a23aa84b8b61 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Wed, 19 Nov 2025 17:22:17 -0800 Subject: [PATCH 1/2] ref(releases): Migrate release actions off deprecated route props --- .../detail/header/releaseActions.spec.tsx | 77 ++++++++----------- .../releases/detail/header/releaseActions.tsx | 23 +++--- 2 files changed, 41 insertions(+), 59 deletions(-) diff --git a/static/app/views/releases/detail/header/releaseActions.spec.tsx b/static/app/views/releases/detail/header/releaseActions.spec.tsx index 91229aabf01f3c..46bce14ce40599 100644 --- a/static/app/views/releases/detail/header/releaseActions.spec.tsx +++ b/static/app/views/releases/detail/header/releaseActions.spec.tsx @@ -1,12 +1,8 @@ -import type {Location} from 'history'; import {HealthFixture} from 'sentry-fixture/health'; -import {LocationFixture} from 'sentry-fixture/locationFixture'; import {OrganizationFixture} from 'sentry-fixture/organization'; import {ReleaseFixture} from 'sentry-fixture/release'; import {ReleaseMetaFixture} from 'sentry-fixture/releaseMeta'; import {ReleaseProjectFixture} from 'sentry-fixture/releaseProject'; -import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture'; -import {RouterFixture} from 'sentry-fixture/routerFixture'; import { render, @@ -15,13 +11,13 @@ import { userEvent, waitFor, } from 'sentry-test/reactTestingLibrary'; +import type {RouterConfig} from 'sentry-test/reactTestingLibrary'; import type {ReleaseProject} from 'sentry/types/release'; import {ReleaseStatus} from 'sentry/types/release'; import ReleaseActions from 'sentry/views/releases/detail/header/releaseActions'; describe('ReleaseActions', () => { - const router = RouterFixture(); const organization = OrganizationFixture(); const project1 = ReleaseProjectFixture({ @@ -40,15 +36,17 @@ describe('ReleaseActions', () => { projects: [project1, project2], }); - const location: Location = { - ...LocationFixture(), - pathname: `/organizations/${organization.slug}/releases/${release.version}/`, - query: { - project: '1', - statsPeriod: '24h', - yAxis: 'events', + const initialRouterConfig: RouterConfig = { + location: { + pathname: `/organizations/${organization.slug}/releases/${release.version}/`, + query: { + project: '1', + statsPeriod: '24h', + yAxis: 'events', + }, }, }; + let mockUpdate: ReturnType; beforeEach(() => { @@ -63,21 +61,19 @@ describe('ReleaseActions', () => { }); it('archives a release', async () => { - render( + const {router} = render( , { - router, - deprecatedRouterMocks: true, + organization, + initialRouterConfig, } ); - renderGlobalModal({router, deprecatedRouterMocks: true}); + renderGlobalModal(); await userEvent.click(screen.getByLabelText('Actions')); @@ -106,8 +102,10 @@ describe('ReleaseActions', () => { }) ); await waitFor(() => - expect(router.push).toHaveBeenCalledWith( - `/organizations/${organization.slug}/explore/releases/` + expect(router.location).toEqual( + expect.objectContaining({ + pathname: `/organizations/${organization.slug}/explore/releases/`, + }) ) ); }); @@ -117,20 +115,17 @@ describe('ReleaseActions', () => { render( , { - router, - deprecatedRouterMocks: true, + organization, + initialRouterConfig, } ); - renderGlobalModal({router}); + renderGlobalModal(); await userEvent.click(screen.getByLabelText('Actions')); @@ -162,19 +157,17 @@ describe('ReleaseActions', () => { await waitFor(() => expect(refetchDataMock).toHaveBeenCalledTimes(1)); }); - it('navigates to a next/prev release', () => { - const {rerender} = render( + it('navigates to a next/prev release', async () => { + const {router} = render( , { - router, - deprecatedRouterMocks: true, + organization, + initialRouterConfig, } ); @@ -195,19 +188,13 @@ describe('ReleaseActions', () => { `/organizations/${organization.slug}/releases/999/?project=1&statsPeriod=24h&yAxis=events` ); - rerender( - - ); + // Simulate navigation to a sub-page + await waitFor(() => { + router.navigate({ + pathname: `/organizations/${organization.slug}/releases/${release.version}/files-changed/`, + search: 'project=1&statsPeriod=24h&yAxis=events', + }); + }); expect(screen.getByLabelText('Newer')).toHaveAttribute( 'href', diff --git a/static/app/views/releases/detail/header/releaseActions.tsx b/static/app/views/releases/detail/header/releaseActions.tsx index 933d80b985d107..71edabb6d4d777 100644 --- a/static/app/views/releases/detail/header/releaseActions.tsx +++ b/static/app/views/releases/detail/header/releaseActions.tsx @@ -1,6 +1,5 @@ import {Fragment} from 'react'; import styled from '@emotion/styled'; -import type {Location} from 'history'; import {archiveRelease, restoreRelease} from 'sentry/actionCreators/release'; import {Client} from 'sentry/api'; @@ -14,31 +13,27 @@ import TextOverflow from 'sentry/components/textOverflow'; import {IconEllipsis, IconNext, IconPrevious} from 'sentry/icons'; import {t, tct, tn} from 'sentry/locale'; import {space} from 'sentry/styles/space'; -import type {Organization} from 'sentry/types/organization'; import type {Release, ReleaseMeta} from 'sentry/types/release'; import {trackAnalytics} from 'sentry/utils/analytics'; -import {browserHistory} from 'sentry/utils/browserHistory'; +import {useLocation} from 'sentry/utils/useLocation'; +import {useNavigate} from 'sentry/utils/useNavigate'; +import useOrganization from 'sentry/utils/useOrganization'; import {formatVersion} from 'sentry/utils/versions/formatVersion'; import {isReleaseArchived} from 'sentry/views/releases/utils'; import {makeReleasesPathname} from 'sentry/views/releases/utils/pathnames'; type Props = { - location: Location; - organization: Organization; projectSlug: string; refetchData: () => void; release: Release; releaseMeta: ReleaseMeta; }; -function ReleaseActions({ - location, - organization, - projectSlug, - release, - releaseMeta, - refetchData, -}: Props) { +function ReleaseActions({projectSlug, release, releaseMeta, refetchData}: Props) { + const location = useLocation(); + const navigate = useNavigate(); + const organization = useOrganization(); + async function handleArchive() { try { await archiveRelease(new Client(), { @@ -46,7 +41,7 @@ function ReleaseActions({ projectSlug, releaseVersion: release.version, }); - browserHistory.push( + navigate( makeReleasesPathname({ organization, path: '/', From ce024b2af5772db41f8150b76f866b86f84bbad7 Mon Sep 17 00:00:00 2001 From: Scott Cooper Date: Wed, 19 Nov 2025 17:23:45 -0800 Subject: [PATCH 2/2] whoops commit file --- static/app/views/releases/detail/header/releaseHeader.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/static/app/views/releases/detail/header/releaseHeader.tsx b/static/app/views/releases/detail/header/releaseHeader.tsx index b125b49ae7556f..e1282352efe785 100644 --- a/static/app/views/releases/detail/header/releaseHeader.tsx +++ b/static/app/views/releases/detail/header/releaseHeader.tsx @@ -174,12 +174,10 @@ function ReleaseHeader({