Skip to content

Commit e736724

Browse files
authored
feat(nav): Update rest of alert links to use new pathname builder (#85257)
1 parent fbd6405 commit e736724

File tree

10 files changed

+80
-24
lines changed

10 files changed

+80
-24
lines changed

static/app/components/createAlertButton.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type EventView from 'sentry/utils/discover/eventView';
1818
import useApi from 'sentry/utils/useApi';
1919
import useProjects from 'sentry/utils/useProjects';
2020
import useRouter from 'sentry/utils/useRouter';
21+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
2122
import type {AlertType, AlertWizardAlertNames} from 'sentry/views/alerts/wizard/options';
2223
import {
2324
AlertWizardRuleTemplates,
@@ -75,7 +76,10 @@ function CreateAlertFromViewButton({
7576
: DEFAULT_WIZARD_TEMPLATE;
7677

7778
const to = {
78-
pathname: `/organizations/${organization.slug}/alerts/new/metric/`,
79+
pathname: makeAlertsPathname({
80+
path: '/new/metric/',
81+
organization,
82+
}),
7983
query: {
8084
...queryParams,
8185
createFromDiscover: true,
@@ -143,7 +147,12 @@ export default function CreateAlertButton({
143147
if (alertOption) {
144148
params.append('alert_option', alertOption);
145149
}
146-
return `/organizations/${organization.slug}/alerts/wizard/?${params.toString()}`;
150+
return (
151+
makeAlertsPathname({
152+
path: '/wizard/',
153+
organization,
154+
}) + `?${params.toString()}`
155+
);
147156
};
148157

149158
function handleClickWithoutProject(event: React.MouseEvent) {

static/app/components/events/interfaces/crons/cronTimelineSection.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {Organization} from 'sentry/types/organization';
2323
import type {Project} from 'sentry/types/project';
2424
import {useDimensions} from 'sentry/utils/useDimensions';
2525
import {useLocation} from 'sentry/utils/useLocation';
26+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
2627
import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
2728
import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection';
2829
import {ResolutionSelector} from 'sentry/views/monitors/components/overviewTimeline/resolutionSelector';
@@ -77,7 +78,10 @@ export function CronTimelineSection({event, organization, project}: Props) {
7778
size="xs"
7879
icon={<IconOpen />}
7980
to={{
80-
pathname: `/organizations/${organization.slug}/alerts/rules/crons/${project.slug}/${monitorSlug}/details/`,
81+
pathname: makeAlertsPathname({
82+
path: `/rules/crons/${project.slug}/${monitorSlug}/details/`,
83+
organization,
84+
}),
8185
query: {environment},
8286
}}
8387
>

static/app/components/events/interfaces/uptime/uptimeDataSection.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import type {Event} from 'sentry/types/event';
2525
import {type Group, GroupActivityType, GroupStatus} from 'sentry/types/group';
2626
import type {Project} from 'sentry/types/project';
2727
import {defined} from 'sentry/utils';
28-
import normalizeUrl from 'sentry/utils/url/normalizeUrl';
2928
import {useDebouncedValue} from 'sentry/utils/useDebouncedValue';
3029
import {useDimensions} from 'sentry/utils/useDimensions';
3130
import {useLocation} from 'sentry/utils/useLocation';
3231
import useOrganization from 'sentry/utils/useOrganization';
32+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
3333
import {
3434
checkStatusPrecedent,
3535
statusToText,
@@ -133,9 +133,10 @@ export function UptimeDataSection({group, event, project}: Props) {
133133
<LinkButton
134134
icon={<IconSettings />}
135135
size="xs"
136-
to={normalizeUrl(
137-
`/organizations/${organization.slug}/alerts/rules/uptime/${project.slug}/${alertRuleId}/details/`
138-
)}
136+
to={makeAlertsPathname({
137+
path: `/rules/uptime/${project.slug}/${alertRuleId}/details/`,
138+
organization,
139+
})}
139140
>
140141
{t('Uptime Alert Rule')}
141142
</LinkButton>

static/app/components/onboardingWizard/taskConfig.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type {Organization} from 'sentry/types/organization';
2222
import type {Project} from 'sentry/types/project';
2323
import {isDemoModeEnabled} from 'sentry/utils/demoMode';
2424
import {getDemoWalkthroughTasks} from 'sentry/utils/demoMode/guides';
25+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
2526
import {getPerformanceBaseUrl} from 'sentry/views/performance/utils';
2627
import {makeReplaysPathname} from 'sentry/views/replays/pathnames';
2728

@@ -47,12 +48,18 @@ type Options = {
4748

4849
function getIssueAlertUrl({projects, organization}: Options) {
4950
if (!projects || !projects.length) {
50-
return `/organizations/${organization.slug}/alerts/rules/`;
51+
return makeAlertsPathname({
52+
path: '/rules/',
53+
organization,
54+
});
5155
}
5256
// pick the first project with events if we have that, otherwise just pick the first project
5357
const firstProjectWithEvents = projects.find(project => !!project.firstEvent);
5458
const project = firstProjectWithEvents ?? projects[0]!;
55-
return `/organizations/${organization.slug}/alerts/${project.slug}/wizard/`;
59+
return makeAlertsPathname({
60+
path: `/${project.slug}/wizard/`,
61+
organization,
62+
});
5663
}
5764

5865
function getOnboardingInstructionsUrl({projects, organization}: Options) {

static/app/components/sidebar/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import useMedia from 'sentry/utils/useMedia';
5555
import useOrganization from 'sentry/utils/useOrganization';
5656
import usePageFilters from 'sentry/utils/usePageFilters';
5757
import useProjects from 'sentry/utils/useProjects';
58+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
5859
import {MODULE_BASE_URLS} from 'sentry/views/insights/common/utils/useModuleURL';
5960
import {
6061
AI_LANDING_SUB_PATH,
@@ -328,7 +329,10 @@ function Sidebar() {
328329
{...sidebarItemProps}
329330
icon={<IconSiren />}
330331
label={t('Alerts')}
331-
to={`/organizations/${organization.slug}/alerts/rules/`}
332+
to={makeAlertsPathname({
333+
path: '/rules/',
334+
organization,
335+
})}
332336
id="alerts"
333337
/>
334338
);

static/app/views/issueDetails/streamline/sidebar/detectorSection.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {Group} from 'sentry/types/group';
88
import type {Organization} from 'sentry/types/organization';
99
import type {Project} from 'sentry/types/project';
1010
import {getConfigForIssueType} from 'sentry/utils/issueTypeConfig';
11+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
1112
import {useIssueDetails} from 'sentry/views/issueDetails/streamline/context';
1213
import {SidebarSectionTitle} from 'sentry/views/issueDetails/streamline/sidebar/sidebar';
1314

@@ -38,7 +39,10 @@ export function getDetectorDetails({
3839
return {
3940
detectorType: 'metric_alert',
4041
detectorId: metricAlertRuleId,
41-
detectorPath: `/organizations/${organization.slug}/alerts/rules/details/${metricAlertRuleId}/`,
42+
detectorPath: makeAlertsPathname({
43+
path: `/rules/details/${metricAlertRuleId}/`,
44+
organization,
45+
}),
4246
// TODO(issues): We can probably enrich this description with details from the alert itself.
4347
description: t(
4448
'This issue was created by a metric alert detector. View the detector details to learn more.'
@@ -53,7 +57,10 @@ export function getDetectorDetails({
5357
detectorType: 'cron_monitor',
5458
detectorId: cronId,
5559
detectorSlug: cronSlug,
56-
detectorPath: `/organizations/${organization.slug}/alerts/rules/crons/${project.slug}/${cronSlug}/details/`,
60+
detectorPath: makeAlertsPathname({
61+
path: `/rules/crons/${project.slug}/${cronSlug}/details/`,
62+
organization,
63+
}),
5764
description: t(
5865
'This issue was created by a cron monitor. View the monitor details to learn more.'
5966
),
@@ -65,7 +72,10 @@ export function getDetectorDetails({
6572
return {
6673
detectorType: 'uptime_monitor',
6774
detectorId: uptimeAlertRuleId,
68-
detectorPath: `/organizations/${organization.slug}/alerts/rules/uptime/${project.slug}/${uptimeAlertRuleId}/details/`,
75+
detectorPath: makeAlertsPathname({
76+
path: `/rules/uptime/${project.slug}/${uptimeAlertRuleId}/details/`,
77+
organization,
78+
}),
6979
// TODO(issues): Update this to mention detectors when that language is user-facing
7080
description: t(
7181
'This issue was created by an uptime monitoring alert rule after detecting 3 consecutive failed checks.'

static/app/views/organizationStats/teamInsights/teamAlertsTriggered.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {Project} from 'sentry/types/project';
1919
import {formatPercentage} from 'sentry/utils/number/formatPercentage';
2020
import {useApiQuery} from 'sentry/utils/queryClient';
2121
import type {ColorOrAlias} from 'sentry/utils/theme';
22+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
2223
import type {MetricRule} from 'sentry/views/alerts/rules/metric/types';
2324

2425
import {ProjectBadge, ProjectBadgeContainer} from './styles';
@@ -154,7 +155,10 @@ function TeamAlertsTriggered({
154155
<LinkButton
155156
priority="primary"
156157
size="sm"
157-
to={`/organizations/${organization.slug}/alerts/rules/`}
158+
to={makeAlertsPathname({
159+
path: `/rules/`,
160+
organization,
161+
})}
158162
>
159163
{t('Create Alert')}
160164
</LinkButton>
@@ -182,7 +186,10 @@ function TeamAlertsTriggered({
182186
<Fragment key={rule.id}>
183187
<AlertNameContainer>
184188
<Link
185-
to={`/organizations/${organization.slug}/alerts/rules/details/${rule.id}/`}
189+
to={makeAlertsPathname({
190+
path: `/rules/details/${rule.id}/`,
191+
organization,
192+
})}
186193
>
187194
{rule.name}
188195
</Link>

static/app/views/projectDetail/projectLatestAlerts.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {t} from 'sentry/locale';
1515
import {space} from 'sentry/styles/space';
1616
import type {Organization} from 'sentry/types/organization';
1717
import {useApiQuery} from 'sentry/utils/queryClient';
18+
import useOrganization from 'sentry/utils/useOrganization';
19+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
1820
import type {Incident} from 'sentry/views/alerts/types';
1921
import {IncidentStatus} from 'sentry/views/alerts/types';
2022

@@ -25,10 +27,10 @@ const PLACEHOLDER_AND_EMPTY_HEIGHT = '172px';
2527

2628
interface AlertRowProps {
2729
alert: Incident;
28-
orgSlug: string;
2930
}
3031

31-
function AlertRow({alert, orgSlug}: AlertRowProps) {
32+
function AlertRow({alert}: AlertRowProps) {
33+
const organization = useOrganization();
3234
const {status, identifier, title, dateClosed, dateStarted} = alert;
3335
const isResolved = status === IncidentStatus.CLOSED;
3436
const isWarning = status === IncidentStatus.WARNING;
@@ -40,7 +42,10 @@ function AlertRow({alert, orgSlug}: AlertRowProps) {
4042
return (
4143
<AlertRowLink
4244
aria-label={title}
43-
to={`/organizations/${orgSlug}/alerts/${identifier}/`}
45+
to={makeAlertsPathname({
46+
path: `/${identifier}/`,
47+
organization,
48+
})}
4449
>
4550
<AlertBadgeWrapper icon={Icon}>
4651
<AlertBadge status={status} />
@@ -154,9 +159,7 @@ function ProjectLatestAlerts({
154159

155160
return alertsUnresolvedAndResolved
156161
.slice(0, 3)
157-
.map(alert => (
158-
<AlertRow key={alert.id} alert={alert} orgSlug={organization.slug} />
159-
));
162+
.map(alert => <AlertRow key={alert.id} alert={alert} />);
160163
}
161164

162165
return (
@@ -166,7 +169,10 @@ function ProjectLatestAlerts({
166169
{/* as this is a link to latest alerts, we want to only preserve project and environment */}
167170
<SectionHeadingLink
168171
to={{
169-
pathname: `/organizations/${organization.slug}/alerts/`,
172+
pathname: makeAlertsPathname({
173+
path: `/`,
174+
organization,
175+
}),
170176
query: {
171177
statsPeriod: undefined,
172178
start: undefined,

static/app/views/settings/organizationIntegrations/integrationAlertRules.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import PanelItem from 'sentry/components/panels/panelItem';
1010
import {t} from 'sentry/locale';
1111
import useOrganization from 'sentry/utils/useOrganization';
1212
import useProjects from 'sentry/utils/useProjects';
13+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
1314

1415
export default function IntegrationAlertRules() {
1516
const organization = useOrganization();
@@ -27,7 +28,10 @@ export default function IntegrationAlertRules() {
2728
<ProjectItem key={project.slug}>
2829
<ProjectBadge project={project} avatarSize={16} />
2930
<LinkButton
30-
to={`/organizations/${organization.slug}/alerts/${project.slug}/wizard/`}
31+
to={makeAlertsPathname({
32+
path: `/${project.slug}/wizard/`,
33+
organization,
34+
})}
3135
size="xs"
3236
>
3337
{t('Add Alert Rule')}

static/app/views/settings/projectAlerts/settings.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {ApiQueryKey} from 'sentry/utils/queryClient';
1919
import {setApiQueryData, useApiQuery, useQueryClient} from 'sentry/utils/queryClient';
2020
import routeTitleGen from 'sentry/utils/routeTitle';
2121
import useOrganization from 'sentry/utils/useOrganization';
22+
import {makeAlertsPathname} from 'sentry/views/alerts/pathnames';
2223
import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
2324
import {ProjectPermissionAlert} from 'sentry/views/settings/project/projectPermissionAlert';
2425

@@ -107,7 +108,10 @@ function ProjectAlertSettings({canEditRule, params}: ProjectAlertSettingsProps)
107108
action={
108109
<LinkButton
109110
to={{
110-
pathname: `/organizations/${organization.slug}/alerts/rules/`,
111+
pathname: makeAlertsPathname({
112+
path: `/rules/`,
113+
organization,
114+
}),
111115
query: {project: project?.id},
112116
}}
113117
size="sm"

0 commit comments

Comments
 (0)