UNPKG

@grafana/alerting

Version:

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

81 lines (76 loc) 2.6 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var jsxRuntime = require('react/jsx-runtime'); var i18n = require('@grafana/i18n'); var ui = require('@grafana/ui'); var StateDot = require('./StateDot.cjs'); "use strict"; const StateText = ({ state, health, type = "alerting", isPaused = false }) => { if (isPaused) { return /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(InnerText, { color: recordingColor, text: recordingText }); } return /* @__PURE__ */ jsxRuntime.jsx(InnerText, { color, text: stateLabel }); }; function InnerText({ color, text }) { let textColor; if (color === "unknown") { textColor = "secondary"; } else { textColor = color; } return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { direction: "row", gap: 0.5, wrap: "nowrap", flex: "0 0 auto", alignItems: "center", children: [ /* @__PURE__ */ jsxRuntime.jsx(StateDot.StateDot, { color }), /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { variant: "bodySmall", color: textColor, children: text }) ] }); } function PausedText() { return /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { variant: "bodySmall", color: "warning", children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { direction: "row", gap: 0.5, wrap: "nowrap", flex: "0 0 auto", alignItems: "center", children: [ /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { name: "pause", size: "xs" }), /* @__PURE__ */ jsxRuntime.jsx(i18n.Trans, { i18nKey: "alerting.paused-badge.paused", children: "Paused" }) ] }) }); } exports.StateText = StateText; //# sourceMappingURL=StateText.cjs.map