mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix broken panelId links (#84839)
This commit is contained in:
parent
6ce3469bb8
commit
4c247f959b
@ -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}
|
||||
/>
|
||||
)}
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user