From 16005af4b77d283ef3611811413ab448e2135e42 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Wed, 7 May 2025 10:39:00 +0200 Subject: [PATCH] Alerting: Add skipSubpath option when redirecting to details view page (#104994) add skipSubpath option when redirecting to details view page --- .../rule-editor/alert-rule-form/AlertRuleForm.tsx | 10 ++++++++-- .../app/features/alerting/unified/utils/navigation.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx index cf8dfd3f589..4a01b9364a5 100644 --- a/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/alert-rule-form/AlertRuleForm.tsx @@ -319,7 +319,9 @@ function useRedirectToDetailsPage(existingUid?: string) { const newOrUpdatedRuleUid = (saveResult.created?.at(0) || saveResult.updated?.at(0)) ?? existingUid; if (newOrUpdatedRuleUid) { locationService.replace( - rulesNav.detailsPageLink('grafana', { uid: newOrUpdatedRuleUid, ruleSourceName: 'grafana' }) + rulesNav.detailsPageLink('grafana', { uid: newOrUpdatedRuleUid, ruleSourceName: 'grafana' }, undefined, { + skipSubPath: true, + }) ); } else { notifyApp.error( @@ -335,7 +337,11 @@ function useRedirectToDetailsPage(existingUid?: string) { const redirectCloudRulerRule = useCallback((rule: RulerRuleDTO, groupId: RuleGroupIdentifier) => { const { dataSourceName, namespaceName, groupName } = groupId; const updatedRuleIdentifier = fromRulerRule(dataSourceName, namespaceName, groupName, rule); - locationService.replace(rulesNav.detailsPageLink(updatedRuleIdentifier.ruleSourceName, updatedRuleIdentifier)); + locationService.replace( + rulesNav.detailsPageLink(updatedRuleIdentifier.ruleSourceName, updatedRuleIdentifier, undefined, { + skipSubPath: true, + }) + ); }, []); const redirectToDetailsPage = useCallback( diff --git a/public/app/features/alerting/unified/utils/navigation.ts b/public/app/features/alerting/unified/utils/navigation.ts index 0c72f7ae8c1..15081fb8b4e 100644 --- a/public/app/features/alerting/unified/utils/navigation.ts +++ b/public/app/features/alerting/unified/utils/navigation.ts @@ -51,9 +51,15 @@ export const rulesNav = { /** * Creates a link to the details page of a rule. Encodes the rules source name and rule identifier. */ - detailsPageLink: (rulesSourceName: string, ruleIdentifier: RuleIdentifier, params?: QueryParams) => + detailsPageLink: ( + rulesSourceName: string, + ruleIdentifier: RuleIdentifier, + params?: QueryParams, + options?: { skipSubPath?: boolean } + ) => createRelativeUrl( `/alerting/${encodeURIComponent(rulesSourceName)}/${encodeURIComponent(stringifyIdentifier(ruleIdentifier))}/view`, - params + params, + { skipSubPath: options?.skipSubPath } ), };