UNPKG

@grafana/alerting

Version:

Grafana Alerting Library – Build vertical integrations on top of the industry-leading alerting solution

77 lines (74 loc) 2.4 kB
import { jsx, jsxs } from 'react/jsx-runtime'; import { Trans } from '@grafana/i18n'; import { Stack, Text, Icon } from '@grafana/ui'; import { StateDot } from './StateDot.mjs'; "use strict"; const StateText = ({ state, health, type = "alerting", isPaused = false }) => { if (isPaused) { return /* @__PURE__ */ jsx(PausedText, {}); } let stateLabel; let color; switch (state) { case "normal": color = "success"; stateLabel = "Normal"; break; case "firing": color = "error"; stateLabel = "Firing"; break; case "pending": color = "warning"; stateLabel = "Pending"; break; case "recovering": color = "warning"; stateLabel = "Recovering"; break; case "inhibited": color = "info"; stateLabel = "Inhibited"; break; case "unknown": default: color = "unknown"; stateLabel = "Unknown"; break; } if (health === "error") { color = "error"; stateLabel = "Error"; } if (health === "nodata") { color = "warning"; stateLabel = "No data"; } if (type === "recording") { const isRecordingError = health === "error"; const recordingText = isRecordingError ? "Recording error" : "Recording"; const recordingColor = isRecordingError ? "error" : "success"; return /* @__PURE__ */ jsx(InnerText, { color: recordingColor, text: recordingText }); } return /* @__PURE__ */ jsx(InnerText, { color, text: stateLabel }); }; function InnerText({ color, text }) { let textColor; if (color === "unknown") { textColor = "secondary"; } else { textColor = color; } return /* @__PURE__ */ jsxs(Stack, { direction: "row", gap: 0.5, wrap: "nowrap", flex: "0 0 auto", alignItems: "center", children: [ /* @__PURE__ */ jsx(StateDot, { color }), /* @__PURE__ */ jsx(Text, { variant: "bodySmall", color: textColor, children: text }) ] }); } function PausedText() { return /* @__PURE__ */ jsx(Text, { variant: "bodySmall", color: "warning", children: /* @__PURE__ */ jsxs(Stack, { direction: "row", gap: 0.5, wrap: "nowrap", flex: "0 0 auto", alignItems: "center", children: [ /* @__PURE__ */ jsx(Icon, { name: "pause", size: "xs" }), /* @__PURE__ */ jsx(Trans, { i18nKey: "alerting.paused-badge.paused", children: "Paused" }) ] }) }); } export { StateText }; //# sourceMappingURL=StateText.mjs.map