"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[1600],{99696:(A,g,s)=>{s.d(g,{R:()=>u});var t=s(74848),o=s(22803),h=s(29675),c=s(99764);const u=({labelKey:r,value:p,operator:f="=",onRemoveLabel:m})=>{const v=(0,h.of)(x);return(0,t.jsxs)("div",{className:v.wrapper,children:[r,f,p,!!m&&(0,t.jsx)(c.K,{name:"times",size:"xs",onClick:m,tooltip:"Remove label"})]})},x=r=>({wrapper:(0,o.css)({padding:r.spacing(.5,1),borderRadius:r.shape.radius.default,border:`solid 1px ${r.colors.border.medium}`,fontSize:r.typography.bodySmall.fontSize,backgroundColor:r.colors.background.secondary,fontWeight:r.typography.fontWeightBold,color:r.colors.text.primary,display:"inline-block",lineHeight:"1.2"})})},81600:(A,g,s)=>{s.r(g),s.d(g,{default:()=>G,groupStateByLabels:()=>S,matchKey:()=>E});var t=s(74848),o=s(22803),h=s(2543),c=s(96540),u=s(88090),x=s(29675),r=s(81876),p=s(37e3),f=s(86489),m=s(40271),v=s(48583),R=s(6736),j=s(79784),B=s(34128),D=s(61491),P=s(48542),M=s(9912);function O(a){const n=(0,D.useDispatch)(),e=(0,M.$)(i=>i.managedAlertStateHistory);return(0,c.useEffect)(()=>{n((0,P.JH)(a))},[n,a]),e}var I=s(99696),K=s(50585),W=s(17025);const b=({ruleUID:a})=>{const[n,e]=(0,c.useState)(""),i=(0,c.useCallback)(l=>{e(l.currentTarget.value)},[]),{loading:d,error:y,result:J=[]}=O(a),T=(0,x.of)(C);if(d&&!y)return(0,t.jsx)(r._,{text:"Loading history..."});if(y&&!d)return(0,t.jsx)(p.F,{title:"Failed to fetch alert state history",children:y.message});const X=[{id:"state",label:"State",size:"max-content",renderCell:H},{id:"value",label:"",size:"auto",renderCell:z},{id:"timestamp",label:"Time",size:"max-content",renderCell:F}],$=Object.entries(S(J)).sort().filter(([l])=>E(l,n)).map(([l,V])=>{const Q=V.map(L=>({id:L.id,data:L}));return(0,t.jsxs)("div",{children:[(0,t.jsx)("header",{className:T.tableGroupKey,children:(0,t.jsx)("code",{className:T.goupKeyText,"aria-label":l,children:l})}),(0,t.jsx)(K.E,{cols:X,items:Q,pagination:{itemsPerPage:25}})]},l)});return(0,t.jsxs)("div",{children:[(0,t.jsx)("nav",{children:(0,t.jsx)(f.D,{label:(0,t.jsx)(m.J,{children:(0,t.jsxs)(v.B,{gap:.5,alignItems:"center",children:[(0,t.jsx)("span",{children:"Filter group"}),(0,t.jsx)(R.m,{content:(0,t.jsxs)("div",{children:["Filter each state history group either by exact match or a regular expression, ex:"," ",(0,t.jsx)("code",{children:"region=eu-west-1"})," or ",(0,t.jsx)("code",{children:"/region=us-.+/"})]}),children:(0,t.jsx)(j.I,{name:"info-circle",size:"sm"})})]})}),children:(0,t.jsx)(B.p,{prefix:(0,t.jsx)(j.I,{name:"search"}),onChange:i,placeholder:"Search"})})}),$]})};function S(a){const n=a.map(e=>{const i=/{.*?}/g,d=e.text.match(i)?.at(-1)??"";return{id:String(e.id),state:e.newState,text:e.text.replace(d,""),data:e.data,timestamp:e.updated,stringifiedLabels:d}});return(0,h.groupBy)(n,e=>e.stringifiedLabels)}function E(a,n){if(n==="")return!0;if(!(n.startsWith("/")&&n.endsWith("/")))return a.includes(n);try{return new RegExp(n.slice(1,-1)).test(a)}catch{return!1}}function z(a){const n=a.data.data?.evalMatches??[];return(0,t.jsxs)(t.Fragment,{children:[a.data.text,(0,t.jsx)(N,{children:n.map(e=>(0,t.jsx)(I.R,{labelKey:e.metric,value:String(e.value)},e.metric))})]})}function H(a){return(0,t.jsx)(W.C,{state:a.data.state})}function F(a){return(0,t.jsx)("div",{className:U,children:a.data.timestamp&&(0,t.jsx)("span",{children:(0,u.LE)(a.data.timestamp)})})}const N=({children:a})=>{const{wrapper:n}=(0,x.of)(C);return(0,t.jsx)("div",{className:n,children:a})},U=(0,o.css)({display:"flex",alignItems:"flex-end",flexDirection:"column"}),C=a=>({wrapper:(0,o.css)({"& > *":{marginRight:a.spacing(1)}}),tableGroupKey:(0,o.css)({marginTop:a.spacing(2),marginBottom:a.spacing(2)}),goupKeyText:(0,o.css)({overflowX:"auto",textOverflow:"ellipsis",whiteSpace:"nowrap",display:"block"})}),G=b}}]);

//# sourceMappingURL=1600.52e5bf14c0bdeb8b234a.js.map