"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9841],{79841:(X,m,a)=>{a.r(m),a.d(m,{default:()=>I,groupStateByLabels:()=>g,matchKey:()=>E});var o=a(42844),h=a(89949),e=a(27702),p=a(60956),y=a(23852),d=a(66310),S=a(52419),x=a(63439),C=a(22209),L=a(79978),T=a(80011),u=a(73453),A=a(1128),W=a(18771),b=a(47702),z=a(10027);function B(t){const l=(0,W.useDispatch)(),n=(0,z._)(r=>r.managedAlertStateHistory);return(0,e.useEffect)(()=>{l((0,b.Ms)(t))},[l,t]),n}var F=a(21915),H=a(45986),K=a(68614);const R=({alertId:t})=>{const[l,n]=(0,e.useState)(""),r=(0,e.useCallback)(s=>{n(s.currentTarget.value)},[]),{loading:c,error:i,result:J=[]}=B(t),j=(0,d.wW)(v);if(c&&!i)return e.createElement(S.u,{text:"Loading history..."});if(i&&!c)return e.createElement(x.b,{title:"Failed to fetch alert state history"},i.message);const O=[{id:"state",label:"State",size:"max-content",renderCell:M},{id:"value",label:"",size:"auto",renderCell:G},{id:"timestamp",label:"Time",size:"max-content",renderCell:N}],P=Object.entries(g(J)).sort().filter(([s])=>E(s,l)).map(([s,U])=>{const V=U.map(f=>({id:f.id,data:f}));return e.createElement("div",{key:s},e.createElement("header",{className:j.tableGroupKey},e.createElement("code",null,s)),e.createElement(H.t,{cols:O,items:V}))});return e.createElement("div",null,e.createElement("nav",null,e.createElement(C.g,{label:e.createElement(L._,null,e.createElement(y.K,{gap:.5},e.createElement("span",null,"Filter group"),e.createElement(T.u,{content:e.createElement("div",null,"Filter each state history group either by exact match or a regular expression, ex:"," ",e.createElement("code",null,"region=eu-west-1")," or ",e.createElement("code",null,"/region=us-.+/"))},e.createElement(u.J,{name:"info-circle",size:"sm"}))))},e.createElement(A.I,{prefix:e.createElement(u.J,{name:"search"}),onChange:r,placeholder:"Search"}))),P)};function g(t){const l=t.map(n=>{const r=/{.*?}/g,c=n.text.match(r)?.at(-1)??"";return{id:String(n.id),state:n.newState,text:n.text.replace(c,""),data:n.data,timestamp:n.updated,stringifiedLabels:c}});return(0,h.groupBy)(l,n=>n.stringifiedLabels)}function E(t,l){if(l==="")return!0;if(!(l.startsWith("/")&&l.endsWith("/")))return t.includes(l);try{return new RegExp(l.slice(1,-1)).test(t)}catch{return!1}}function G(t){const l=t.data.data?.evalMatches??[];return e.createElement(e.Fragment,null,t.data.text,e.createElement($,null,l.map(n=>e.createElement(F.i,{key:n.metric,labelKey:n.metric,value:String(n.value)}))))}function M(t){return e.createElement(K.l,{state:t.data.state})}function N(t){return e.createElement("div",{className:D},t.data.timestamp&&e.createElement("span",null,(0,p.dq)(t.data.timestamp)))}const $=({children:t})=>{const{wrapper:l}=(0,d.wW)(v);return e.createElement("div",{className:l},t)},D=(0,o.css)`
  display: flex;
  align-items: flex-end;
  flex-direction: column;
`,v=t=>({wrapper:(0,o.css)`
    & > * {
      margin-right: ${t.spacing(1)};
    }
  `,tableGroupKey:(0,o.css)`
    margin-top: ${t.spacing(2)};
    margin-bottom: ${t.spacing(2)};
  `}),I=R}}]);

//# sourceMappingURL=9841.ed2dffd6eafac8571cbf.js.map