Alerting: Add skipSubpath option when redirecting to details view page (#104994)

add skipSubpath option when redirecting to details view page
This commit is contained in:
Sonia Aguilar
2025-05-07 10:39:00 +02:00
committed by GitHub
parent 977e923555
commit 16005af4b7
2 changed files with 16 additions and 4 deletions
@@ -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(
@@ -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 }
),
};