mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Use Runbook URL label everywhere and add validation in the alert rule… (#90523)
* Use Runbook URL label everywhere and add validation in the alert rule form for it * remove validation in alert rule form and render link on detail view only when its a valid url
This commit is contained in:
parent
07c2d886fa
commit
42c29cac0b
@ -5,7 +5,7 @@ import { useFieldArray, useFormContext } from 'react-hook-form';
|
||||
import { useToggle } from 'react-use';
|
||||
|
||||
import { GrafanaTheme2 } from '@grafana/data';
|
||||
import { Button, Field, Input, Text, TextArea, useStyles2, Stack } from '@grafana/ui';
|
||||
import { Button, Field, Input, Stack, Text, TextArea, useStyles2 } from '@grafana/ui';
|
||||
|
||||
import { DashboardModel } from '../../../../dashboard/state';
|
||||
import { RuleFormValues } from '../../types/rule-form';
|
||||
|
@ -148,14 +148,18 @@ const createMetadata = (rule: CombinedRule): PageInfoItem[] => {
|
||||
const interval = group.interval;
|
||||
|
||||
if (runbookUrl) {
|
||||
/* TODO instead of truncating the string, we should use flex and text overflow properly to allow it to take up all of the horizontal space available */
|
||||
const truncatedUrl = truncate(runbookUrl, { length: 42 });
|
||||
const valueToAdd = isValidRunbookURL(runbookUrl) ? (
|
||||
<TextLink variant="bodySmall" href={runbookUrl} external>
|
||||
{truncatedUrl}
|
||||
</TextLink>
|
||||
) : (
|
||||
<Text variant="bodySmall">{truncatedUrl}</Text>
|
||||
);
|
||||
metadata.push({
|
||||
label: 'Runbook',
|
||||
value: (
|
||||
<TextLink variant="bodySmall" href={runbookUrl} external>
|
||||
{/* TODO instead of truncating the string, we should use flex and text overflow properly to allow it to take up all of the horizontal space available */}
|
||||
{truncate(runbookUrl, { length: 42 })}
|
||||
</TextLink>
|
||||
),
|
||||
label: 'Runbook URL',
|
||||
value: valueToAdd,
|
||||
});
|
||||
}
|
||||
|
||||
@ -360,4 +364,18 @@ const getStyles = () => ({
|
||||
}),
|
||||
});
|
||||
|
||||
function isValidRunbookURL(url: string) {
|
||||
const isRelative = url.startsWith('/');
|
||||
let isAbsolute = false;
|
||||
|
||||
try {
|
||||
new URL(url);
|
||||
isAbsolute = true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isRelative || isAbsolute;
|
||||
}
|
||||
|
||||
export default RuleViewer;
|
||||
|
Loading…
Reference in New Issue
Block a user