diff --git a/public/app/features/alerting/unified/components/rule-editor/AnnotationsStep.tsx b/public/app/features/alerting/unified/components/rule-editor/AnnotationsStep.tsx index df6d82009c1..12c66c2ca01 100644 --- a/public/app/features/alerting/unified/components/rule-editor/AnnotationsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/AnnotationsStep.tsx @@ -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'; diff --git a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx index 0ff7c324605..13922c65f58 100644 --- a/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx +++ b/public/app/features/alerting/unified/components/rule-viewer/RuleViewer.tsx @@ -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) ? ( + + {truncatedUrl} + + ) : ( + {truncatedUrl} + ); metadata.push({ - label: 'Runbook', - value: ( - - {/* 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 })} - - ), + 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;