"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7520],{87520:(X,m,a)=>{a.r(m),a.d(m,{default:()=>I,groupStateByLabels:()=>g,matchKey:()=>E});var o=a(9892),h=a(82897),e=a(66111),p=a(77258),y=a(26418),d=a(72648),S=a(61744),x=a(45253),C=a(24799),L=a(64353),T=a(61860),u=a(39904),A=a(46967),W=a(27876),b=a(72004),z=a(69945);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(24782),H=a(53731),R=a(45608);const G=({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:K},{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.Stack,{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 K(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(R.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=o.css`
  display: flex;
  align-items: flex-end;
  flex-direction: column;
`,v=t=>({wrapper:o.css`
    & > * {
      margin-right: ${t.spacing(1)};
    }
  `,tableGroupKey:o.css`
    margin-top: ${t.spacing(2)};
    margin-bottom: ${t.spacing(2)};
  `}),I=G}}]);

//# sourceMappingURL=7520.953bff3b406d067a1aac.js.map