"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[990],{60990:(V,m,a)=>{a.r(m),a.d(m,{default:()=>I,groupStateByLabels:()=>g,matchKey:()=>E});var o=a(66681),h=a(56375),e=a(85960),y=a(12537),d=a(47257),S=a(79468),x=a(49199),T=a(20519),C=a(57445),L=a(13086),A=a(14607),u=a(97666),b=a(24956),K=a(95162),W=a(5970),z=a(92746);function B(t){const l=(0,K.useDispatch)(),n=(0,z._)(r=>r.managedAlertStateHistory);return(0,e.useEffect)(()=>{l((0,W.Ms)(t))},[l,t]),n}var F=a(62570),H=a(79253),N=a(14591);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),f=(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:P}],X=Object.entries(g(J)).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:f.tableGroupKey},e.createElement("code",{className:f.goupKeyText,"aria-label":s},s)),e.createElement(H.t,{cols:O,items:U,pagination:{itemsPerPage:25}}))});return e.createElement("div",null,e.createElement("nav",null,e.createElement(T.g,{label:e.createElement(C._,null,e.createElement(L.K,{gap:.5},e.createElement("span",null,"Filter group"),e.createElement(A.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(b.I,{prefix:e.createElement(u.J,{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 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(N.l,{state:t.data.state})}function P(t){return e.createElement("div",{className:D},t.data.timestamp&&e.createElement("span",null,(0,y.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)};
  `,goupKeyText:(0,o.css)({overflowX:"auto",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block"})}),I=R}}]);

//# sourceMappingURL=990.e8a19b325e491959878b.js.map