"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2835],{37011(P,h,e){e.d(h,{R:()=>l});var t=e(74848),o=e(22803),u=e(92745),d=e(76319),f=e(63142);const l=({labelKey:r,value:p,operator:y="=",onRemoveLabel:m})=>{const v=(0,f.of)(x);return(0,t.jsxs)("div",{className:v.wrapper,children:[r,y,p,!!m&&(0,t.jsx)(d.K,{name:"times",size:"xs",onClick:m,tooltip:(0,u.t)("alerting.alert-label.tooltip-remove-label","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"})})},32835(P,h,e){e.r(h),e.d(h,{default:()=>J,groupStateByLabels:()=>S,matchKey:()=>C});var t=e(74848),o=e(22803),u=e(2543),d=e(96540),f=e(80011),l=e(92745),x=e(63142),r=e(6975),p=e(34999),y=e(37386),m=e(72636),v=e(41654),R=e(45967),E=e(30703),B=e(63527),D=e(52763),K=e(11018),M=e(98127);function O(a){const n=(0,D.wA)(),s=(0,M.$)(c=>c.managedAlertStateHistory);return(0,d.useEffect)(()=>{n((0,K.JH)(a))},[n,a]),s}var b=e(37011),I=e(6106),W=e(65420);const z=({ruleUID:a})=>{const[n,s]=(0,d.useState)(""),c=(0,d.useCallback)(i=>{s(i.currentTarget.value)},[]),{loading:g,error:j,result:X=[]}=O(a),L=(0,x.of)(T);if(g&&!j)return(0,t.jsx)(r._,{text:(0,l.t)("alerting.state-history.text-loading-history","Loading history...")});if(j&&!g)return(0,t.jsx)(p.F,{title:(0,l.t)("alerting.state-history.title-failed-to-fetch-alert-state-history","Failed to fetch alert state history"),children:j.message});const $=[{id:"state",label:(0,l.t)("alerting.state-history.columns.label.state","State"),size:"max-content",renderCell:F},{id:"value",label:"",size:"auto",renderCell:H},{id:"timestamp",label:(0,l.t)("alerting.state-history.columns.label.time","Time"),size:"max-content",renderCell:N}],V=Object.entries(S(X)).sort().filter(([i])=>C(i,n)).map(([i,Q])=>{const Y=Q.map(A=>({id:A.id,data:A}));return(0,t.jsxs)("div",{children:[(0,t.jsx)("header",{className:L.tableGroupKey,children:(0,t.jsx)("code",{className:L.goupKeyText,"aria-label":i,children:i})}),(0,t.jsx)(I.E,{cols:$,items:Y,pagination:{itemsPerPage:25}})]},i)});return(0,t.jsxs)("div",{children:[(0,t.jsx)("nav",{children:(0,t.jsx)(y.D,{label:(0,t.jsx)(m.J,{children:(0,t.jsxs)(v.B,{gap:.5,alignItems:"center",children:[(0,t.jsx)("span",{children:(0,t.jsx)(l.x6,{i18nKey:"alerting.state-history.filter-group",children:"Filter group"})}),(0,t.jsx)(R.m,{content:(0,t.jsxs)("div",{children:[(0,t.jsx)(l.x6,{i18nKey:"alerting.state-history.filter-group-tooltip",children:"Filter each state history group either by exact match or a regular expression, for example:"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("code",{children:"region=eu-west-1"}),(0,t.jsx)("code",{children:"/region=us-.+/"})]})]}),children:(0,t.jsx)(E.I,{name:"info-circle",size:"sm"})})]})}),children:(0,t.jsx)(B.p,{prefix:(0,t.jsx)(E.I,{name:"search"}),onChange:c,placeholder:(0,l.t)("alerting.state-history.placeholder-search","Search")})})}),V]})};function S(a){const n=a.map(s=>{const c=/{.*?}/g,g=s.text.match(c)?.at(-1)??"";return{id:String(s.id),state:s.newState,text:s.text.replace(g,""),data:s.data,timestamp:s.updated,stringifiedLabels:g}});return(0,u.groupBy)(n,s=>s.stringifiedLabels)}function C(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 H(a){const n=a.data.data?.evalMatches??[];return(0,t.jsxs)(t.Fragment,{children:[a.data.text,(0,t.jsx)(U,{children:n.map(s=>(0,t.jsx)(b.R,{labelKey:s.metric,value:String(s.value)},s.metric))})]})}function F(a){return(0,t.jsx)(W.C,{state:a.data.state})}function N(a){return(0,t.jsx)("div",{className:G,children:a.data.timestamp&&(0,t.jsx)("span",{children:(0,f.LE)(a.data.timestamp)})})}const U=({children:a})=>{const{wrapper:n}=(0,x.of)(T);return(0,t.jsx)("div",{className:n,children:a})},G=(0,o.css)({display:"flex",alignItems:"flex-end",flexDirection:"column"}),T=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"})}),J=z}}]);

//# sourceMappingURL=2835.3029918cd8eeff732f5f.js.map