From 4c247f959b56b2e991c442201bad7e5968373bb4 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Thu, 21 Mar 2024 13:58:34 +0100 Subject: [PATCH] Alerting: Fix broken panelId links (#84839) --- .../unified/components/rules/RulesGroup.tsx | 2 +- .../alerting/unified/utils/misc.test.ts | 45 ++++++++++++++++++- .../features/alerting/unified/utils/misc.ts | 16 ++----- 3 files changed, 49 insertions(+), 14 deletions(-) diff --git a/public/app/features/alerting/unified/components/rules/RulesGroup.tsx b/public/app/features/alerting/unified/components/rules/RulesGroup.tsx index cab9ce12743..dab832d4298 100644 --- a/public/app/features/alerting/unified/components/rules/RulesGroup.tsx +++ b/public/app/features/alerting/unified/components/rules/RulesGroup.tsx @@ -279,7 +279,7 @@ export const RulesGroup = React.memo(({ group, namespace, expandAll, viewMode }: namespace={namespace} group={group} onClose={() => closeEditModal()} - folderUrl={folder?.canEdit ? makeFolderSettingsLink(folder) : undefined} + folderUrl={folder?.canEdit ? makeFolderSettingsLink(folder.uid) : undefined} folderUid={folderUID} /> )} diff --git a/public/app/features/alerting/unified/utils/misc.test.ts b/public/app/features/alerting/unified/utils/misc.test.ts index 24fe248b5f6..56dfde2854a 100644 --- a/public/app/features/alerting/unified/utils/misc.test.ts +++ b/public/app/features/alerting/unified/utils/misc.test.ts @@ -1,4 +1,16 @@ -import { sortAlerts, wrapWithQuotes, escapeQuotes, createExploreLink } from 'app/features/alerting/unified/utils/misc'; +import { + sortAlerts, + wrapWithQuotes, + escapeQuotes, + createExploreLink, + makeLabelBasedSilenceLink, + makeDataSourceLink, + makeFolderLink, + makeFolderAlertsLink, + makeFolderSettingsLink, + makeDashboardLink, + makePanelLink, +} from 'app/features/alerting/unified/utils/misc'; import { SortOrder } from 'app/plugins/panel/alertlist/types'; import { Alert } from 'app/types/unified-alerting'; import { GrafanaAlertState } from 'app/types/unified-alerting-dto'; @@ -95,3 +107,34 @@ describe('createExploreLink', () => { ); }); }); + +describe('create links', () => { + it('should create silence link', () => { + expect(makeLabelBasedSilenceLink('grafana', { foo: 'bar', bar: 'baz' })).toBe( + '/alerting/silence/new?alertmanager=grafana&matcher=foo%3Dbar&matcher=bar%3Dbaz' + ); + }); + + it('should create data source link', () => { + expect(makeDataSourceLink('my-data-source')).toBe('/datasources/edit/my-data-source'); + }); + + it('should make folder link', () => { + expect(makeFolderLink('abc123')).toBe('/dashboards/f/abc123'); + }); + + it('should make folder alerts link', () => { + expect(makeFolderAlertsLink('abc123', 'my-title')).toBe('/dashboards/f/abc123/my-title/alerting'); + }); + + it('should make folder settings link', () => { + expect(makeFolderSettingsLink('abc123')).toBe('/dashboards/f/abc123/settings'); + }); + + it('should make dashboard link', () => { + expect(makeDashboardLink('abc123 def456')).toBe('/d/abc123%20def456'); + }); + it('should make panel link', () => { + expect(makePanelLink('dashboard uid', '1')).toBe('/d/dashboard%20uid?viewPanel=1'); + }); +}); diff --git a/public/app/features/alerting/unified/utils/misc.ts b/public/app/features/alerting/unified/utils/misc.ts index 2fd698b3796..7f956f050b0 100644 --- a/public/app/features/alerting/unified/utils/misc.ts +++ b/public/app/features/alerting/unified/utils/misc.ts @@ -14,8 +14,6 @@ import { mapStateWithReasonToBaseState, } from 'app/types/unified-alerting-dto'; -import { FolderDTO } from '../../../../types'; - import { ALERTMANAGER_NAME_QUERY_KEY } from './constants'; import { getRulesSourceName, isCloudRulesSource } from './datasource'; import { getMatcherQueryParams } from './matchers'; @@ -149,22 +147,16 @@ export function makeFolderAlertsLink(folderUID: string, title: string): string { return createUrl(`/dashboards/f/${folderUID}/${title}/alerting`); } -export function makeFolderSettingsLink(folder: FolderDTO): string { - return createUrl(`/dashboards/f/${folder.uid}/settings`); +export function makeFolderSettingsLink(uid: string): string { + return createUrl(`/dashboards/f/${uid}/settings`); } export function makeDashboardLink(dashboardUID: string): string { return createUrl(`/d/${encodeURIComponent(dashboardUID)}`); } -type PanelLinkParams = { - viewPanel?: string; - editPanel?: string; - tab?: 'alert' | 'transform' | 'query'; -}; - -export function makePanelLink(dashboardUID: string, panelId: string, queryParams: PanelLinkParams = {}): string { - const panelParams = new URLSearchParams(queryParams); +export function makePanelLink(dashboardUID: string, panelId: string): string { + const panelParams = new URLSearchParams({ viewPanel: panelId }); return createUrl(`/d/${encodeURIComponent(dashboardUID)}`, panelParams); }