mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 01:15:46 +08:00

* WIP * Refactor and update how we display these fields in the form * Add test for getTemplateOptions and udpate parseTemplates to handle minus simbol * fix betterer * Fix wrapper * Create new usePreviewTemplate to be reused from TemplatePreview and TemplateContentAndPreview * remove unnecessary check * track interactions * Include the whole content of the template in the preview * Update parseTemplates function to return default templates * handle nested templates in parseTemplates function * Missing border fixed, whitespaces preserved and no empty space at the bottom * remove unused styles and add a comment in test * Add missing error in getPreviewResults * fix styles for template selector containers * Alerting: PR feedback to move default templates into RTKQ (#88172) Move default templates to RTKQ API + constant * move parseTemplates to a utils file and refactor last part of this function * Keep selected options when loading exising input and when switching between tabs * Update descritpion in tabs * Fix not previewing when loading existing values * Update text addressing Brenda's feedback * Add test for matchesOnlyOneTemplate function * Add minheight to viewer container and fix getContentFromOptions function --------- Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
52 lines
2.6 KiB
TypeScript
52 lines
2.6 KiB
TypeScript
// We need to use this constat until we have an API to get the default templates
|
|
export const DEFAULT_TEMPLATES = `{{ define "__subject" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ if gt (.Alerts.Resolved | len) 0 }}, RESOLVED:{{ .Alerts.Resolved | len }}{{ end }}{{ end }}] {{ .GroupLabels.SortedPairs.Values | join " " }} {{ if gt (len .CommonLabels) (len .GroupLabels) }}({{ with .CommonLabels.Remove .GroupLabels.Names }}{{ .Values | join " " }}{{ end }}){{ end }}{{ end }}
|
|
|
|
{{ define "__text_values_list" }}{{ if len .Values }}{{ $first := true }}{{ range $refID, $value := .Values -}}
|
|
{{ if $first }}{{ $first = false }}{{ else }}, {{ end }}{{ $refID }}={{ $value }}{{ end -}}
|
|
{{ else }}[no value]{{ end }}{{ end }}
|
|
|
|
{{ define "__text_alert_list" }}{{ range . }}
|
|
Value: {{ template "__text_values_list" . }}
|
|
Labels:
|
|
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
|
|
{{ end }}Annotations:
|
|
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
|
|
{{ end }}{{ if gt (len .GeneratorURL) 0 }}Source: {{ .GeneratorURL }}
|
|
{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: {{ .SilenceURL }}
|
|
{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: {{ .DashboardURL }}
|
|
{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: {{ .PanelURL }}
|
|
{{ end }}{{ end }}{{ end }}
|
|
|
|
{{ define "default.title" }}{{ template "__subject" . }}{{ end }}
|
|
|
|
{{ define "default.message" }}{{ if gt (len .Alerts.Firing) 0 }}**Firing**
|
|
{{ template "__text_alert_list" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}
|
|
|
|
{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
|
|
{{ template "__text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}
|
|
|
|
{{ define "__teams_text_alert_list" }}{{ range . }}
|
|
Value: {{ template "__text_values_list" . }}
|
|
Labels:
|
|
{{ range .Labels.SortedPairs }} - {{ .Name }} = {{ .Value }}
|
|
{{ end }}
|
|
Annotations:
|
|
{{ range .Annotations.SortedPairs }} - {{ .Name }} = {{ .Value }}
|
|
{{ end }}
|
|
{{ if gt (len .GeneratorURL) 0 }}Source: [{{ .GeneratorURL }}]({{ .GeneratorURL }})
|
|
|
|
{{ end }}{{ if gt (len .SilenceURL) 0 }}Silence: [{{ .SilenceURL }}]({{ .SilenceURL }})
|
|
|
|
{{ end }}{{ if gt (len .DashboardURL) 0 }}Dashboard: [{{ .DashboardURL }}]({{ .DashboardURL }})
|
|
|
|
{{ end }}{{ if gt (len .PanelURL) 0 }}Panel: [{{ .PanelURL }}]({{ .PanelURL }})
|
|
|
|
{{ end }}
|
|
{{ end }}{{ end }}
|
|
|
|
{{ define "teams.default.message" }}{{ if gt (len .Alerts.Firing) 0 }}**Firing**
|
|
{{ template "__teams_text_alert_list" .Alerts.Firing }}{{ if gt (len .Alerts.Resolved) 0 }}
|
|
|
|
{{ end }}{{ end }}{{ if gt (len .Alerts.Resolved) 0 }}**Resolved**
|
|
{{ template "__teams_text_alert_list" .Alerts.Resolved }}{{ end }}{{ end }}`;
|