"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[3634],{13634:(X,m,a)=>{a.r(m),a.d(m,{default:()=>D,groupStateByLabels:()=>g,matchKey:()=>E});var o=a(41407),h=a(86832),e=a(39953),p=a(48069),y=a(27366),d=a(82803),S=a(84766),x=a(33155),C=a(96227),L=a(36495),T=a(69865),u=a(12190),A=a(38637),W=a(57721),b=a(79493),z=a(26544);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(91085),H=a(47224),K=a(10162);const R=({alertId:t})=>{const[l,n]=(0,e.useState)(""),r=(0,e.useCallback)(s=>{n(s.currentTarget.value)},[]),{loading:c,error:i,result:I=[]}=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 j=[{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}],O=Object.entries(g(I)).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:j,items:V,pagination:{itemsPerPage:25}}))});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"}))),O)};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(P,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:$},t.data.timestamp&&e.createElement("span",null,(0,p.dq)(t.data.timestamp)))}const P=({children:t})=>{const{wrapper:l}=(0,d.wW)(v);return e.createElement("div",{className:l},t)},$=(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)};
  `}),D=R}}]);

//# sourceMappingURL=3634.d37264039b28a9a9e2d0.js.map