From ac86cd1a20b0d7af86f97a580c375e9516175f7a Mon Sep 17 00:00:00 2001 From: Mia Hsu Date: Tue, 25 Nov 2025 11:59:57 -0800 Subject: [PATCH 1/3] feat(aci): redirect incidents to metric issue details --- static/app/router/routes.tsx | 4 +- .../incident.tsx | 9 ++ .../views/alerts/workflowEngineRedirects.tsx | 133 +++++++++++++++++- 3 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 static/app/views/alerts/workflowEngineRedirectWrappers/incident.tsx diff --git a/static/app/router/routes.tsx b/static/app/router/routes.tsx index 764fb3dc187168..31088b4cf3ee01 100644 --- a/static/app/router/routes.tsx +++ b/static/app/router/routes.tsx @@ -1658,7 +1658,9 @@ function buildRoutes(): RouteObject[] { }, { path: ':alertId/', - component: make(() => import('sentry/views/alerts/incidentRedirect')), + component: make( + () => import('sentry/views/alerts/workflowEngineRedirectWrappers/incident') + ), }, { path: ':projectId/', diff --git a/static/app/views/alerts/workflowEngineRedirectWrappers/incident.tsx b/static/app/views/alerts/workflowEngineRedirectWrappers/incident.tsx new file mode 100644 index 00000000000000..0b9a3587ea9fdf --- /dev/null +++ b/static/app/views/alerts/workflowEngineRedirectWrappers/incident.tsx @@ -0,0 +1,9 @@ +import {lazy} from 'react'; + +import {withOpenPeriodRedirect} from 'sentry/views/alerts/workflowEngineRedirects'; + +const AlertWizardProjectProvider = lazy( + () => import('sentry/views/alerts/incidentRedirect') +); + +export default withOpenPeriodRedirect(AlertWizardProjectProvider); diff --git a/static/app/views/alerts/workflowEngineRedirects.tsx b/static/app/views/alerts/workflowEngineRedirects.tsx index c4d48c4e4b718d..87495cd7f6d1a9 100644 --- a/static/app/views/alerts/workflowEngineRedirects.tsx +++ b/static/app/views/alerts/workflowEngineRedirects.tsx @@ -1,6 +1,7 @@ import LoadingIndicator from 'sentry/components/loadingIndicator'; import Redirect from 'sentry/components/redirect'; import {useApiQuery} from 'sentry/utils/queryClient'; +import {useLocation} from 'sentry/utils/useLocation'; import useOrganization from 'sentry/utils/useOrganization'; import {useParams} from 'sentry/utils/useParams'; import {useUser} from 'sentry/utils/useUser'; @@ -26,6 +27,13 @@ interface AlertRuleDetector { ruleId: string | null; } +interface IncidentGroupOpenPeriod { + groupId: string; + incidentId: string | null; + incidentIdentifier: string; + openPeriodId: string; +} + /** * HoC that wraps a component to handle workflow engine * redirects for issue alert rules. Fetches workflow data if needed and @@ -137,10 +145,86 @@ export const withAutomationEditRedirect =

>( export const withDetectorDetailsRedirect =

>( Component: React.ComponentType

-) => - withAlertRuleRedirect(Component, (detectorId, orgSlug) => - makeMonitorDetailsPathname(orgSlug, detectorId) - ); +) => { + return function WorkflowEngineRedirectWrapper(props: P) { + const user = useUser(); + const organization = useOrganization(); + const {ruleId, detectorId} = useParams(); + const location = useLocation(); + const alertId = location.query.alert as string | undefined; + + const shouldRedirect = + !user.isStaff && organization.features.includes('workflow-engine-ui'); + + // Check for incident open period if alertId is present + const {data: incidentGroupOpenPeriod, isPending: isOpenPeriodPending} = + useApiQuery( + [ + `/organizations/${organization.slug}/incident-groupopenperiod/`, + {query: {incident_identifier: alertId}}, + ], + { + staleTime: 0, + enabled: shouldRedirect && !!alertId, + retry: false, + } + ); + + // Check for detector if no alertId + const {data: alertRuleDetector, isPending: isDetectorPending} = + useApiQuery( + [ + `/organizations/${organization.slug}/alert-rule-detector/`, + {query: {alert_rule_id: ruleId}}, + ], + { + staleTime: 0, + enabled: shouldRedirect && !!ruleId && !detectorId && !alertId, + retry: false, + } + ); + + if (shouldRedirect) { + // If alertId is provided, redirect to metric issue + if (alertId) { + if (isOpenPeriodPending) { + return ; + } + if (incidentGroupOpenPeriod) { + return ( + + ); + } + } + + // If detectorId is provided, redirect to monitor details + if (detectorId) { + return ( + + ); + } + + // If alertRuleId is provided, fetch detector and redirect + if (isDetectorPending) { + return ; + } + if (alertRuleDetector) { + return ( + + ); + } + } + + return ; + }; +}; export const withDetectorEditRedirect =

>( Component: React.ComponentType

@@ -183,3 +267,44 @@ export function withDetectorCreateRedirect

>( return ; }; } + +export function withOpenPeriodRedirect

>( + Component: React.ComponentType

+) { + return function OpenPeriodRedirectWrapper(props: P) { + const user = useUser(); + const organization = useOrganization(); + const {alertId} = useParams(); + + const shouldRedirect = + !user.isStaff && organization.features.includes('workflow-engine-ui'); + + const {data: incidentGroupOpenPeriod, isPending} = + useApiQuery( + [ + `/organizations/${organization.slug}/incident-groupopenperiod/`, + {query: {incident_identifier: alertId}}, + ], + { + staleTime: 0, + enabled: shouldRedirect && !!alertId, + retry: false, + } + ); + + if (shouldRedirect) { + if (isPending) { + return ; + } + if (incidentGroupOpenPeriod) { + return ( + + ); + } + } + + return ; + }; +} From 2fd6ec657aeb51fa1eaace50df4e235159adb967 Mon Sep 17 00:00:00 2001 From: Mia Hsu Date: Tue, 25 Nov 2025 14:13:05 -0800 Subject: [PATCH 2/3] trailing slash --- static/app/views/alerts/workflowEngineRedirects.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/app/views/alerts/workflowEngineRedirects.tsx b/static/app/views/alerts/workflowEngineRedirects.tsx index 87495cd7f6d1a9..71ac2ab04e6561 100644 --- a/static/app/views/alerts/workflowEngineRedirects.tsx +++ b/static/app/views/alerts/workflowEngineRedirects.tsx @@ -193,7 +193,7 @@ export const withDetectorDetailsRedirect =

>( if (incidentGroupOpenPeriod) { return ( ); } From 65702be791d0ab469f1e79859759f6584282e99b Mon Sep 17 00:00:00 2001 From: Mia Hsu Date: Tue, 25 Nov 2025 14:17:16 -0800 Subject: [PATCH 3/3] missed the other one --- static/app/views/alerts/workflowEngineRedirects.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/app/views/alerts/workflowEngineRedirects.tsx b/static/app/views/alerts/workflowEngineRedirects.tsx index 71ac2ab04e6561..7e3283dd707909 100644 --- a/static/app/views/alerts/workflowEngineRedirects.tsx +++ b/static/app/views/alerts/workflowEngineRedirects.tsx @@ -299,7 +299,7 @@ export function withOpenPeriodRedirect

>( if (incidentGroupOpenPeriod) { return ( ); }