"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7409],{87409:(V,m,a)=>{a.r(m),a.d(m,{default:()=>J,groupStateByLabels:()=>g,matchKey:()=>E});var o=a(32196),h=a(2543),e=a(96540),y=a(72724),d=a(40845),S=a(39558),x=a(42418),C=a(88575),L=a(60029),T=a(67061),A=a(56034),u=a(14578),b=a(10354),B=a(80348),F=a(23770),H=a(61410);function R(t){const l=(0,B.useDispatch)(),n=(0,H.$)(r=>r.managedAlertStateHistory);return(0,e.useEffect)(()=>{l((0,F.JH)(t))},[l,t]),n}var z=a(15458),K=a(75591),N=a(30423);const $=({alertId:t})=>{const[l,n]=(0,e.useState)(""),r=(0,e.useCallback)(s=>{n(s.currentTarget.value)},[]),{loading:c,error:i,result:M=[]}=R(t),v=(0,d.of)(f);if(c&&!i)return e.createElement(S._,{text:"Loading history..."});if(i&&!c)return e.createElement(x.F,{title:"Failed to fetch alert state history"},i.message);const O=[{id:"state",label:"State",size:"max-content",renderCell:G},{id:"value",label:"",size:"auto",renderCell:D},{id:"timestamp",label:"Time",size:"max-content",renderCell:I}],X=Object.entries(g(M)).sort().filter(([s])=>E(s,l)).map(([s,j])=>{const U=j.map(p=>({id:p.id,data:p}));return e.createElement("div",{key:s},e.createElement("header",{className:v.tableGroupKey},e.createElement("code",{className:v.goupKeyText,"aria-label":s},s)),e.createElement(K.E,{cols:O,items:U,pagination:{itemsPerPage:25}}))});return e.createElement("div",null,e.createElement("nav",null,e.createElement(C.D,{label:e.createElement(L.J,null,e.createElement(T.B,{gap:.5},e.createElement("span",null,"Filter group"),e.createElement(A.m,{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.I,{name:"info-circle",size:"sm"}))))},e.createElement(b.p,{prefix:e.createElement(u.I,{name:"search"}),onChange:r,placeholder:"Search"}))),X)};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 D(t){const l=t.data.data?.evalMatches??[];return e.createElement(e.Fragment,null,t.data.text,e.createElement(P,null,l.map(n=>e.createElement(z.R,{key:n.metric,labelKey:n.metric,value:String(n.value)}))))}function G(t){return e.createElement(N.C,{state:t.data.state})}function I(t){return e.createElement("div",{className:W},t.data.timestamp&&e.createElement("span",null,(0,y.LE)(t.data.timestamp)))}const P=({children:t})=>{const{wrapper:l}=(0,d.of)(f);return e.createElement("div",{className:l},t)},W=(0,o.css)`
  display: flex;
  align-items: flex-end;
  flex-direction: column;
`,f=t=>({wrapper:(0,o.css)`
    & > * {
      margin-right: ${t.spacing(1)};
    }
  `,tableGroupKey:(0,o.css)`
    margin-top: ${t.spacing(2)};
    margin-bottom: ${t.spacing(2)};
  `,goupKeyText:(0,o.css)({overflowX:"auto",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block"})}),J=$}}]);

//# sourceMappingURL=7409.24316c87d08c1053c46a.js.map