"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[1783],{29507:(e,t,s)=>{s.d(t,{x:()=>l});var a=s(68404),n=s(47570),r=s(45193);function l(e){const t=(0,n.I0)(),s=(0,a.useRef)(e);s.current=e,(0,a.useEffect)((()=>()=>{t((0,r.e)({cleanupAction:s.current}))}),[t])}},43298:(e,t,s)=>{s.r(t),s.d(t,{default:()=>ct});var a,n=s(68404),r=s(70356),l=s(8771),i=s(95967),c=s(78721),o=s(47570),d=s(92938),u=s(50489),m=s(40256),h=s(71308),g=s(27549),x=s(82897),p=s(59052),v=s(94255),f=s(90915),j=s(75414),b=s(91115),y=s(48147),w=s(9617),A=s(64624),S=s(84719),N=s(1652),C=s(63639),$=s(40920),k=s(29507),R=s(10331),M=s(28410),q=s(33899),I=s(83809),O=s(82139),D=s(77048),E=s(39357),_=s(8455),z=s(87885),B=s(75678),Q=s(86647),Y=s(94322),Z=s(9019),T=s(69357),V=s(45916);const W=()=>{var e;const[t,s]=(0,n.useState)([]),r=(0,p.Gc)(),l=(0,o.I0)(),{watch:i}=r,c=i("matchers"),d=(0,w.wW)(F),u=[{id:"state",label:"State",renderCell:function(e){let{data:{matchedInstance:t}}=e;return(0,V.jsx)(T.l,{state:t.state})},size:"160px"},{id:"labels",label:"Labels",renderCell:function(e){let{data:{matchedInstance:t}}=e;return(0,V.jsx)(Y.s,{labels:t.labels})},size:"250px"},{id:"created",label:"Created",renderCell:function(e){let{data:{matchedInstance:t}}=e;return(0,V.jsx)(V.Fragment,{children:t.activeAt.startsWith("0001")?"-":(0,b.CQ)(t.activeAt).format("YYYY-MM-DD HH:mm:ss")})},size:"400px"}];(0,n.useEffect)((()=>{l((0,I.ei)())}),[l]);const m=(0,B.Zo)();return(0,v.Z)((()=>{const e=m.flatMap((e=>e.groups.flatMap((e=>e.rules.map((e=>e.promRule)).filter((e=>(0,Q.x_)(e))).flatMap((e=>{var t;return(0,D.TZ)(null!==(t=e.alerts)&&void 0!==t?t:[],c)}))))));s(e)}),500,[m,c]),(0,V.jsxs)("div",{children:[(0,V.jsxs)("h4",{className:d.title,children:["Affected alert instances",t.length>0?(0,V.jsx)(z.C,{className:d.badge,color:"blue",text:t.length}):null]}),(0,V.jsx)("div",{className:d.table,children:c.every((e=>!e.value&&!e.name))?a||(a=(0,V.jsx)("span",{children:"Add a valid matcher to see affected alerts"})):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Z.t,{items:null!==(e=t.slice(0,5))&&void 0!==e?e:[],isExpandable:!1,cols:u}),t.length>5&&(0,V.jsxs)("div",{className:d.moreMatches,children:["and ",t.length-5," more"]})]})})]})};const F=e=>({table:g.css`
    max-width: ${e.breakpoints.values.lg}px;
  `,moreMatches:g.css`
    margin-top: ${e.spacing(1)};
  `,title:g.css`
    display: flex;
    align-items: center;
  `,badge:g.css`
    margin-left: ${e.spacing(1)};
  `});var K=s(65586),H=s(2563),P=s(85965);const G=["onChange","ref"];const L=e=>({wrapper:g.css`
      margin-top: ${e.spacing(2)};
    `,row:g.css`
      display: flex;
      align-items: flex-start;
      flex-direction: row;
      background-color: ${e.colors.background.secondary};
      padding: ${e.spacing(1)} ${e.spacing(1)} 0 ${e.spacing(1)};
      & > * + * {
        margin-left: ${e.spacing(2)};
      }
    `,removeButton:g.css`
      margin-left: ${e.spacing(1)};
      margin-top: ${e.spacing(2.5)};
    `,matcherOptions:g.css`
      min-width: 140px;
    `,matchers:g.css`
      max-width: ${e.breakpoints.values.sm}px;
      margin: ${e.spacing(1)} 0;
      padding-top: ${e.spacing(.5)};
    `}),J=e=>{let{className:t}=e;const s=(0,w.wW)(L),a=(0,p.Gc)(),{control:n,register:r,formState:{errors:l}}=a,{fields:i=[],append:c,remove:o}=(0,p.Dq)({name:"matchers"});return(0,V.jsx)("div",{className:(0,g.cx)(t,s.wrapper),children:(0,V.jsx)(S.g,{label:"Matching labels",required:!0,children:(0,V.jsxs)("div",{children:[(0,V.jsx)("div",{className:s.matchers,children:i.map(((e,t)=>{var a,c,d,u,m,h,g,x,p,v;return(0,V.jsxs)("div",{className:s.row,"data-testid":"matcher",children:[(0,V.jsx)(S.g,{label:"Label",invalid:!(null==l||null===(a=l.matchers)||void 0===a||null===(c=a[t])||void 0===c||!c.name),error:null==l||null===(d=l.matchers)||void 0===d||null===(u=d[t])||void 0===u||null===(m=u.name)||void 0===m?void 0:m.message,children:(0,V.jsx)(N.I,Object.assign({},r(`matchers.${t}.name`,{required:{value:!0,message:"Required."}}),{defaultValue:e.name,placeholder:"label"}))}),(0,V.jsx)(S.g,{label:"Operator",children:(0,V.jsx)(K.g,{control:n,render:e=>{let{field:{onChange:t}}=e,a=function(e,t){if(null==e)return{};var s,a,n={},r=Object.keys(e);for(a=0;a<r.length;a++)s=r[a],t.indexOf(s)>=0||(n[s]=e[s]);return n}(e.field,G);return(0,V.jsx)(H.Ph,Object.assign({},a,{onChange:e=>t(e.value),className:s.matcherOptions,options:O.tA,"aria-label":"operator"}))},defaultValue:e.operator||O.tA[0].value,name:`matchers.${t}.operator`,rules:{required:{value:!0,message:"Required."}}})}),(0,V.jsx)(S.g,{label:"Value",invalid:!(null==l||null===(h=l.matchers)||void 0===h||null===(g=h[t])||void 0===g||!g.value),error:null==l||null===(x=l.matchers)||void 0===x||null===(p=x[t])||void 0===p||null===(v=p.value)||void 0===v?void 0:v.message,children:(0,V.jsx)(N.I,Object.assign({},r(`matchers.${t}.value`,{required:{value:!0,message:"Required."}}),{defaultValue:e.value,placeholder:"value"}))}),i.length>1&&(0,V.jsx)(P.h,{className:s.removeButton,tooltip:"Remove matcher",name:"trash-alt",onClick:()=>o(t),children:"Remove"})]},`${e.id}`)}))}),(0,V.jsx)($.zx,{type:"button",icon:"plus",variant:"secondary",onClick:()=>{const e={name:"",value:"",operator:R._M.equal};c(e)},children:"Add matcher"})]})})})};var U=s(87379);const X=()=>{const{control:e,getValues:t}=(0,p.Gc)(),s=(0,w.yK)(ee),{field:{onChange:a,value:n},fieldState:{invalid:r}}=(0,p.bc)({name:"startsAt",control:e,rules:{validate:e=>t().endsAt>e}}),{field:{onChange:l,value:i},fieldState:{invalid:c}}=(0,p.bc)({name:"endsAt",control:e,rules:{validate:e=>t().startsAt<e}}),{field:{onChange:o,value:d}}=(0,p.bc)({name:"timeZone",control:e}),u=r||c,m=(0,b.CQ)(n),h=(0,b.CQ)(i);return(0,V.jsx)(S.g,{className:s.timeRange,label:"Silence start and end",error:u?"To is before or the same as from":"",invalid:u,children:(0,V.jsx)(U.K,{value:{from:m,to:h,raw:{from:m,to:h}},timeZone:d,onChange:e=>{a((0,b.CQ)(e.from)),l((0,b.CQ)(e.to))},onChangeTimeZone:e=>o(e),hideTimeZone:!1,hideQuickRanges:!0,placeholder:"Select time range"})})},ee=e=>({timeRange:g.css`
    width: 400px;
  `});var te,se,ae,ne,re;const le=(e,t)=>{const s=new Date;if(t){var a;const e=Date.parse(t.endsAt)<Date.now()?{start:s,end:(0,f.Ks)(s,{hours:2})}:{start:new Date(t.startsAt),end:new Date(t.endsAt)};return{id:t.id,startsAt:e.start.toISOString(),endsAt:e.end.toISOString(),comment:t.comment,createdBy:t.createdBy,duration:(0,f.vT)(e),isRegex:!1,matchers:(null===(a=t.matchers)||void 0===a?void 0:a.map(O.cm))||[],matcherName:"",matcherValue:"",timeZone:j.Ys}}{const t=(0,f.Ks)(s,{hours:2});return Object.assign({id:"",startsAt:s.toISOString(),endsAt:t.toISOString(),comment:`created ${(0,b.CQ)().format("YYYY-MM-DD HH:mm")}`,createdBy:y.v.bootData.user.name,duration:"2h",isRegex:!1,matchers:[{name:"",value:"",operator:R._M.equal}],matcherName:"",matcherValue:"",timeZone:j.Ys},(e=>{const t={},s=e.get("comment"),a=e.getAll("matcher"),n=(0,D.RT)(a);return n.length&&(t.matchers=n.map(O.cm)),s&&(t.comment=s),t})(e))}},ie=e=>({field:g.css`
    margin: ${e.spacing(1,0)};
  `,textArea:g.css`
    max-width: ${e.breakpoints.values.sm}px;
  `,createdBy:g.css`
    width: 200px;
  `,flexRow:g.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;

    & > * {
      margin-right: ${e.spacing(1)};
    }
  `,silencePeriod:g.css`
    max-width: ${e.breakpoints.values.sm}px;
  `}),ce=e=>{var t,s;let{silence:a,alertManagerSourceName:r}=e;const[l]=(0,M.j)(),i=(0,n.useMemo)((()=>le(l,a)),[a,l]),c=(0,p.cI)({defaultValues:i}),d=(0,o.I0)(),u=(0,w.wW)(ie),{loading:m}=(0,q._)((e=>e.updateSilence));(0,k.x)((e=>e.unifiedAlerting.updateSilence=_.oq));const{register:h,handleSubmit:j,formState:R,watch:D,setValue:z,clearErrors:B}=c,Q=D("duration"),Y=D("startsAt"),Z=D("endsAt"),[T,F]=(0,n.useState)(Q);(0,v.Z)((()=>{if((0,f.qb)(Y)&&(0,f.qb)(Z))if(Q!==T)z("endsAt",(0,b.CQ)((0,f.Ks)(new Date(Y),(0,f.RA)(Q))).toISOString()),F(Q);else{const e=new Date(Y).valueOf();if(new Date(Z).valueOf()>e){const e=(0,f.vT)({start:new Date(Y),end:new Date(Z)});z("duration",e),F(e)}}}),700,[B,Q,Z,T,z,Y]);const K=Boolean(y.v.bootData.user.isSignedIn&&y.v.bootData.user.name);return(0,V.jsx)(p.RV,Object.assign({},c,{children:(0,V.jsxs)("form",{onSubmit:j((e=>{const{id:t,startsAt:s,endsAt:a,comment:n,createdBy:l,matchers:i}=e,c=i.map(O._J),o=(0,x.pickBy)({id:t,startsAt:s,endsAt:a,comment:n,createdBy:l,matchers:c},(e=>!!e));d((0,I.QY)({alertManagerSourceName:r,payload:o,exitOnSave:!0,successMessage:"Silence "+(o.id?"updated":"created")}))})),children:[(0,V.jsxs)(A.C,{label:""+(a?"Recreate silence":"Create silence"),children:[(0,V.jsxs)("div",{className:(0,g.cx)(u.flexRow,u.silencePeriod),children:[te||(te=(0,V.jsx)(X,{})),(0,V.jsx)(S.g,{label:"Duration",invalid:!!R.errors.duration,error:R.errors.duration&&("required"===R.errors.duration.type?"Required field":R.errors.duration.message),children:(0,V.jsx)(N.I,Object.assign({className:u.createdBy},h("duration",{validate:e=>0===Object.keys((0,f.RA)(e)).length?"Invalid duration. Valid example: 1d 4h (Available units: y, M, w, d, h, m, s)":void 0}),{id:"duration"}))})]}),se||(se=(0,V.jsx)(J,{})),(0,V.jsx)(S.g,{className:(0,g.cx)(u.field,u.textArea),label:"Comment",required:!0,error:null===(t=R.errors.comment)||void 0===t?void 0:t.message,invalid:!!R.errors.comment,children:(0,V.jsx)(C.K,Object.assign({},h("comment",{required:{value:!0,message:"Required."}}),{rows:5,placeholder:"Details about the silence"}))}),!K&&(0,V.jsx)(S.g,{className:(0,g.cx)(u.field,u.createdBy),label:"Created By",required:!0,error:null===(s=R.errors.createdBy)||void 0===s?void 0:s.message,invalid:!!R.errors.createdBy,children:(0,V.jsx)(N.I,Object.assign({},h("createdBy",{required:{value:!0,message:"Required."}}),{placeholder:"Who's creating the silence"}))}),ae||(ae=(0,V.jsx)(W,{}))]}),(0,V.jsxs)("div",{className:u.flexRow,children:[m&&(ne||(ne=(0,V.jsx)($.zx,{disabled:!0,icon:"fa fa-spinner",variant:"primary",children:"Saving..."}))),!m&&(re||(re=(0,V.jsx)($.zx,{type:"submit",children:"Submit"}))),(0,V.jsx)($.Qj,{href:(0,E.eQ)("alerting/silences",r),variant:"secondary",fill:"outline",children:"Cancel"})]})]})}))};var oe=s(35089),de=s(35011),ue=s(24085),me=s(74025),he=s(26011),ge=s(61959),xe=s(82969),pe=s(53262);const ve=["className"];const fe=e=>{let{className:t}=e,s=function(e,t){if(null==e)return{};var s,a,n={},r=Object.keys(e);for(a=0;a<r.length;a++)s=r[a],t.indexOf(s)>=0||(n[s]=e[s]);return n}(e,ve);return(0,V.jsx)($.zx,Object.assign({variant:"secondary",size:"xs",className:(0,g.cx)((0,w.yK)(je),t)},s))},je=e=>g.css`
  height: 24px;
  font-size: ${e.typography.size.sm};
`;var be,ye=s(3799),we=s(68698),Ae=s(74727),Se=s(28436);const Ne=e=>{let{alertManagerSourceName:t}=e;const s=(0,xe.QX)(t);return ge.Vt.hasAccess(s.create,ge.Vt.isEditor)?(0,V.jsx)(Se.Z,{title:"You haven't created any silences yet",buttonIcon:"bell-slash",buttonLink:(0,E.eQ)("alerting/silence/new",t),buttonTitle:"New silence"}):be||(be=(0,V.jsx)(Ae._,{callToActionElement:(0,V.jsx)("div",{}),message:"No silences found."}))};var Ce,$e=s(12783),ke=s(91045),Re=s(82344);const Me=e=>{let{alert:t,className:s}=e;const[a,r]=(0,n.useState)(!0),l=(0,f.vT)({start:new Date(t.startsAt),end:new Date(t.endsAt)}),i=Object.entries(t.labels).reduce(((e,t)=>{let[s,a]=t;return"alertname"!==s&&"__alert_rule_title__"!==s||(e=a),e}),"");return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)("tr",{className:s,children:[(0,V.jsx)("td",{children:(0,V.jsx)(ke.U,{isCollapsed:a,onToggle:e=>r(e)})}),(0,V.jsx)("td",{children:(0,V.jsx)(Re.G,{state:t.status.state})}),(0,V.jsxs)("td",{children:["for ",l," seconds"]}),(0,V.jsx)("td",{children:i})]}),!a&&(0,V.jsxs)("tr",{className:s,children:[Ce||(Ce=(0,V.jsx)("td",{})),(0,V.jsx)("td",{colSpan:5,children:(0,V.jsx)(Y.s,{labels:t.labels})})]})]})};var qe,Ie;const Oe=e=>({tableMargin:g.css`
    margin-bottom: ${e.spacing(1)};
  `,colState:g.css`
    width: 110px;
  `,colName:g.css`
    width: 65%;
  `}),De=e=>{let{silencedAlerts:t}=e;const s=(0,w.wW)($e.D),a=(0,w.wW)(Oe);return t.length?(0,V.jsxs)("table",{className:(0,g.cx)(s.table,a.tableMargin),children:[(0,V.jsxs)("colgroup",{children:[(0,V.jsx)("col",{className:s.colExpand}),(0,V.jsx)("col",{className:a.colState}),qe||(qe=(0,V.jsx)("col",{})),(0,V.jsx)("col",{className:a.colName})]}),Ie||(Ie=(0,V.jsx)("thead",{children:(0,V.jsxs)("tr",{children:[(0,V.jsx)("th",{}),(0,V.jsx)("th",{children:"State"}),(0,V.jsx)("th",{}),(0,V.jsx)("th",{children:"Alert name"})]})})),(0,V.jsx)("tbody",{children:t.map(((e,t)=>(0,V.jsx)(Me,{alert:e,className:t%2==0?s.evenRow:""},e.fingerprint)))})]}):null},Ee=e=>{let{silence:t}=e;const{startsAt:s,endsAt:a,comment:n,createdBy:r,silencedAlerts:l}=t,i=(0,w.wW)(_e),c="YYYY-MM-DD HH:mm",o=oe.parse(s),d=oe.parse(a),u=(0,f.vT)({start:new Date(s),end:new Date(a)});return(0,V.jsxs)("div",{className:i.container,children:[(0,V.jsx)("div",{className:i.title,children:"Comment"}),(0,V.jsx)("div",{children:n}),(0,V.jsx)("div",{className:i.title,children:"Schedule"}),(0,V.jsx)("div",{children:`${null==o?void 0:o.format(c)} - ${null==d?void 0:d.format(c)}`}),(0,V.jsx)("div",{className:i.title,children:"Duration"}),(0,V.jsxs)("div",{children:[" ",u]}),(0,V.jsx)("div",{className:i.title,children:"Created by"}),(0,V.jsxs)("div",{children:[" ",r]}),(0,V.jsx)("div",{className:i.title,children:"Affected alerts"}),(0,V.jsx)(De,{silencedAlerts:l})]})},_e=e=>({container:g.css`
    display: grid;
    grid-template-columns: 1fr 9fr;
    grid-row-gap: 1rem;
  `,title:g.css`
    color: ${e.colors.text.primary};
  `,row:g.css`
    margin: ${e.spacing(1,0)};
  `});var ze=s(49179);const Be={[R.As.Active]:"good",[R.As.Expired]:"neutral",[R.As.Pending]:"neutral"},Qe=e=>{let{state:t}=e;return(0,V.jsx)(ze.i,{state:Be[t],children:t})};var Ye,Ze,Te=s(4546),Ve=s(9442),We=s(96380);const Fe=Object.entries(R.As).map((e=>{let[t,s]=e;return{label:t,value:s}})),Ke=()=>(0,x.uniqueId)("query-string-"),He=()=>{const[e,t]=(0,n.useState)(Ke()),[s,a]=(0,he.K)(),{queryString:r,silenceState:l}=(0,E.pF)(s),i=(0,w.wW)(Pe),c=(0,x.debounce)((e=>{const t=e.target;a({queryString:t.value||null})}),400),o=!!(r&&r.length>3)&&0===(0,O.Zh)(r).length;return(0,V.jsxs)("div",{className:i.flexRow,children:[(0,V.jsx)(S.g,{className:i.rowChild,label:Ye||(Ye=(0,V.jsx)(Te._,{children:(0,V.jsxs)(me.K,{gap:.5,children:[(0,V.jsx)("span",{children:"Search by matchers"}),(0,V.jsx)(Ve.u,{content:(0,V.jsxs)("div",{children:["Filter silences by matchers using a comma separated list of matchers, ie:",(0,V.jsx)("pre",{children:"severity=critical, instance=~cluster-us-.+"})]}),children:(0,V.jsx)(ue.J,{name:"info-circle",size:"sm"})})]})})),invalid:o,error:o?"Query must use valid matcher syntax":null,children:(0,V.jsx)(N.I,{className:i.searchInput,prefix:Ze||(Ze=(0,V.jsx)(ue.J,{name:"search"})),onChange:c,defaultValue:null!=r?r:"",placeholder:"Search","data-testid":"search-query-input"},e)}),(0,V.jsx)(S.g,{className:i.rowChild,label:"State",children:(0,V.jsx)(We.S,{options:Fe,value:l,onChange:e=>{a({silenceState:e})}})}),(r||l)&&(0,V.jsx)("div",{className:i.rowChild,children:(0,V.jsx)($.zx,{variant:"secondary",icon:"times",onClick:()=>{a({queryString:null,silenceState:null}),setTimeout((()=>t(Ke())))},children:"Clear filters"})})]})},Pe=e=>({searchInput:g.css`
    width: 360px;
  `,flexRow:g.css`
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    padding-bottom: ${e.spacing(2)};
    border-bottom: 1px solid ${e.colors.border.strong};
  `,rowChild:g.css`
    margin-right: ${e.spacing(1)};
    margin-bottom: 0;
    max-height: 52px;
  `,fieldLabel:g.css`
    font-size: 12px;
    font-weight: 500;
  `});var Ge,Le,Je,Ue;const Xe=e=>{const[t]=(0,he.K)();return(0,n.useMemo)((()=>{const{queryString:s,silenceState:a}=(0,E.pF)(t),n=null==t?void 0:t.silenceIds;return e.filter((e=>{if("string"==typeof n){if(!n.split(",").includes(e.id))return!1}if(s){if(!(0,O.Zh)(s).every((t=>{var s;return null===(s=e.matchers)||void 0===s?void 0:s.some((e=>{let{name:s,value:a,isEqual:n,isRegex:r}=e;return t.name===s&&t.value===a&&t.isEqual===n&&t.isRegex===r}))})))return!1}if(a){if(!(e.status.state===a))return!1}return!0}))}),[t,e])},et=e=>({topButtonContainer:g.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
  `,addNewSilence:g.css`
    margin: ${e.spacing(2,0)};
  `,callout:g.css`
    background-color: ${e.colors.background.secondary};
    border-top: 3px solid ${e.colors.info.border};
    border-radius: 2px;
    height: 62px;
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-top: ${e.spacing(2)};

    & > * {
      margin-left: ${e.spacing(1)};
    }
  `,calloutIcon:g.css`
    color: ${e.colors.info.text};
  `,editButton:g.css`
    margin-left: ${e.spacing(.5)};
  `});const tt=e=>{let{silences:t,alertManagerAlerts:s,alertManagerSourceName:a}=e;const r=(0,w.wW)(et),[l]=(0,he.K)(),i=Xe(t),c=(0,xe.QX)(a),{silenceState:d}=(0,E.pF)(l),u=!!i.length&&(void 0===d||d===R.As.Expired),m=function(e){const t=(0,o.I0)(),s=(0,w.wW)(et),a=(0,xe.QX)(e);return(0,n.useMemo)((()=>{const n=s=>{t((0,I.yO)(e,s))},r=[{id:"state",label:"State",renderCell:function(e){let{data:{status:t}}=e;return(0,V.jsx)(Qe,{state:t.state})},size:"88px"},{id:"matchers",label:"Matching labels",renderCell:function(e){let{data:{matchers:t}}=e;return(0,V.jsx)(we.g,{matchers:t||[]})},size:9},{id:"alerts",label:"Alerts",renderCell:function(e){let{data:{silencedAlerts:t}}=e;return(0,V.jsx)("span",{"data-testid":"alerts",children:t.length})},size:1},{id:"schedule",label:"Schedule",renderCell:function(e){let{data:{startsAt:t,endsAt:s}}=e;const a=oe.parse(t),n=oe.parse(s),r="YYYY-MM-DD HH:mm";return(0,V.jsxs)(V.Fragment,{children:[" ",null==a?void 0:a.format(r)," ","-",Je||(Je=(0,V.jsx)("br",{})),null==n?void 0:n.format(r)]})},size:"150px"}];return ge.Vt.hasAccess(a.update,ge.Vt.isEditor)&&r.push({id:"actions",label:"Actions",renderCell:function(t){let{data:a}=t;return(0,V.jsxs)(me.K,{gap:.5,children:["expired"===a.status.state?(0,V.jsx)(de.r,{href:(0,E.eQ)(`/alerting/silence/${a.id}/edit`,e),children:Ue||(Ue=(0,V.jsx)(fe,{icon:"sync",children:"Recreate"}))}):(0,V.jsx)(fe,{icon:"bell",onClick:()=>n(a.id),children:"Unsilence"}),"expired"!==a.status.state&&(0,V.jsx)(ye.A,{className:s.editButton,to:(0,E.eQ)(`/alerting/silence/${a.id}/edit`,e),icon:"pen",tooltip:"edit"})]})},size:"147px"}),r}),[e,t,s,a])}(a),h=(0,n.useMemo)((()=>i.map((e=>{const t=(a=e.id,s.filter((e=>e.status.silencedBy.includes(a))));var a;return{id:e.id,data:Object.assign({},e,{silencedAlerts:t})}}))),[i,s]);return(0,V.jsxs)("div",{"data-testid":"silences-table",children:[!!t.length&&(0,V.jsxs)(V.Fragment,{children:[Ge||(Ge=(0,V.jsx)(He,{})),(0,V.jsx)(pe.q,{actions:[c.create],fallback:ge.Vt.isEditor,children:(0,V.jsx)("div",{className:r.topButtonContainer,children:(0,V.jsx)(de.r,{href:(0,E.eQ)("/alerting/silence/new",a),children:(0,V.jsx)($.zx,{className:r.addNewSilence,icon:"plus",children:"New Silence"})})})}),h.length?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Z.t,{items:h,cols:m,isExpandable:!0,renderExpandedContent:e=>{let{data:t}=e;return(0,V.jsx)(Ee,{silence:t})}}),u&&(0,V.jsxs)("div",{className:r.callout,children:[(0,V.jsx)(ue.J,{className:r.calloutIcon,name:"info-circle"}),Le||(Le=(0,V.jsx)("span",{children:"Expired silences are automatically deleted after 5 days."}))]})]}):"No matching silences found"]}),!t.length&&(0,V.jsx)(Ne,{alertManagerSourceName:a})]})};var st,at,nt,rt=s(82498),lt=s(1698),it=s(85464);const ct=(0,c.Pf)((()=>{var e,t,s;const a=(0,lt.k)("instance"),[c,g]=(0,rt.k)(a),x=(0,o.I0)(),p=(0,q._)((e=>e.silences)),v=(0,q._)((e=>e.amAlerts)),f=c?v[c]||_.oq:void 0,j=(0,r.TH)().pathname.endsWith("/alerting/silences"),{currentData:b}=d.T.useDiscoverAmFeaturesQuery({amSourceName:null!=c?c:""},{skip:!c});(0,n.useEffect)((()=>{function e(){c&&(x((0,I.je)(c)),x((0,I.dB)(c)))}e();const t=setInterval((()=>e),it.cm);return()=>{clearInterval(t)}}),[c,x]);const{result:y,loading:w,error:A}=c&&p[c]||_.oq,S=(0,n.useCallback)((e=>y&&y.find((t=>t.id===e))),[y]),N=(null==A||null===(e=A.message)||void 0===e?void 0:e.includes("the Alertmanager is not configured"))&&(null==b?void 0:b.lazyConfigInit);return c?(0,V.jsxs)(m.J,{pageId:"silences",children:[(0,V.jsx)(u.P,{disabled:!j,current:c,onChange:g,dataSources:a}),N&&(at||(at=(0,V.jsx)(l.b,{title:"The selected Alertmanager has no configuration",severity:"warning",children:"Create a new contact point to create a configuration using the default values or contact your administrator to set up the Alertmanager."}))),A&&!w&&!N&&(0,V.jsx)(l.b,{severity:"error",title:"Error loading silences",children:A.message||"Unknown error."}),(null==f?void 0:f.error)&&!(null!=f&&f.loading)&&!N&&(0,V.jsx)(l.b,{severity:"error",title:"Error loading Alertmanager alerts",children:(null===(t=f.error)||void 0===t?void 0:t.message)||"Unknown error."}),w&&(nt||(nt=(0,V.jsx)(i.u,{text:"loading silences..."}))),y&&!A&&(0,V.jsxs)(r.rs,{children:[(0,V.jsx)(r.AW,{exact:!0,path:"/alerting/silences",children:(0,V.jsx)(tt,{silences:y,alertManagerAlerts:null!==(s=null==f?void 0:f.result)&&void 0!==s?s:[],alertManagerSourceName:c})}),(0,V.jsx)(r.AW,{exact:!0,path:"/alerting/silence/new",children:(0,V.jsx)(ce,{alertManagerSourceName:c})}),(0,V.jsx)(r.AW,{exact:!0,path:"/alerting/silence/:id/edit",children:e=>{let{match:t}=e;return(null==t?void 0:t.params.id)&&(0,V.jsx)(ce,{silence:S(t.params.id),alertManagerSourceName:c})}})]})]}):j?(0,V.jsx)(m.J,{pageId:"silences",children:(0,V.jsx)(h.I,{availableAlertManagers:a})}):st||(st=(0,V.jsx)(r.l_,{to:"/alerting/silences"}))}),{style:"page"})},40256:(e,t,s)=>{s.d(t,{J:()=>r});s(68404);var a=s(90894),n=s(45916);const r=e=>{let{children:t,pageId:s,pageNav:r,isLoading:l}=e;return(0,n.jsx)(a.T,{pageNav:r,navId:s,children:(0,n.jsx)(a.T.Contents,{isLoading:l,children:t})})}},53262:(e,t,s)=>{s.d(t,{q:()=>r});s(68404);var a=s(61959),n=s(45916);const r=e=>{let{actions:t,children:s,fallback:r=!0}=e;return t.some((e=>a.Vt.hasAccess(e,r)))?(0,n.jsx)(n.Fragment,{children:s}):null}},71308:(e,t,s)=>{s.d(t,{I:()=>h});s(68404);var a,n,r,l,i=s(8771),c=s(82498),o=s(50489),d=s(45916);const u=()=>a||(a=(0,d.jsx)(i.b,{title:"No Alertmanager found",severity:"warning",children:"We could not find any external Alertmanagers and you may not have access to the built-in Grafana Alertmanager."})),m=()=>n||(n=(0,d.jsx)(i.b,{title:"Selected Alertmanager not found. Select a different Alertmanager.",severity:"warning",children:"Selected Alertmanager no longer exists or you may not have permission to access it."})),h=e=>{let{availableAlertManagers:t}=e;const[s,a]=(0,c.k)(t),n=t.length>0;return(0,d.jsx)("div",{children:n?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(o.P,{onChange:a,dataSources:t}),r||(r=(0,d.jsx)(m,{}))]}):l||(l=(0,d.jsx)(u,{}))})}},3799:(e,t,s)=>{s.d(t,{A:()=>i});s(68404);var a=s(9442),n=s(40920),r=s(45916);const l=["tooltip","icon","to","target","onClick","className","tooltipPlacement"];const i=e=>{let{tooltip:t,icon:s,to:i,target:c,onClick:o,className:d,tooltipPlacement:u="top"}=e,m=function(e,t){if(null==e)return{};var s,a,n={},r=Object.keys(e);for(a=0;a<r.length;a++)s=r[a],t.indexOf(s)>=0||(n[s]=e[s]);return n}(e,l);const h="string"==typeof t?t:void 0;return(0,r.jsx)(a.u,{content:t,placement:u,children:i?(0,r.jsx)(n.Qj,Object.assign({variant:"secondary",fill:"text",icon:s,href:i,size:"sm",target:c},m,{"aria-label":h})):(0,r.jsx)(n.zx,Object.assign({className:d,variant:"secondary",fill:"text",size:"sm",icon:s,type:"button",onClick:o},m,{"aria-label":h}))})}},82344:(e,t,s)=>{s.d(t,{G:()=>i});s(68404);var a=s(10331),n=s(49179),r=s(45916);const l={[a.Z9.Active]:"bad",[a.Z9.Unprocessed]:"neutral",[a.Z9.Suppressed]:"info"},i=e=>{let{state:t}=e;return(0,r.jsx)(n.i,{state:l[t],children:t})}},68698:(e,t,s)=>{s.d(t,{g:()=>c});var a=s(27549),n=(s(68404),s(9617)),r=s(58760),l=s(82139),i=s(45916);const c=e=>{let{matchers:t}=e;const s=(0,n.wW)(o);return(0,i.jsx)("div",{children:(0,i.jsx)(r.P,{className:s.tags,tags:t.map((e=>`${e.name}${(0,l.zy)(e)}${e.value}`))})})},o=()=>({tags:a.css`
    justify-content: flex-start;
  `})},82498:(e,t,s)=>{s.d(t,{k:()=>c});var a=s(68404),n=s(26011),r=s(17421),l=s(85464),i=s(19462);function c(e){const[t,s]=(0,n.K)(),c=function(e){return(0,a.useCallback)((t=>e.map((e=>e.name)).includes(t)),[e])}(e),o=(0,a.useCallback)((e=>{c(e)&&(e===i.GC?(r.Z.delete(l.de),s({[l.c4]:null})):(r.Z.set(l.de,e),s({[l.c4]:e})))}),[s,c]),d=t[l.c4];if(d&&"string"==typeof d)return c(d)?[d,o]:[void 0,o];const u=r.Z.get(l.de);return u&&"string"==typeof u&&c(u)?(o(u),[u,o]):c(i.GC)?[i.GC,o]:[void 0,o]}},1698:(e,t,s)=>{s.d(t,{k:()=>r});var a=s(68404),n=s(19462);function r(e){return(0,a.useMemo)((()=>(0,n.LE)(e)),[e])}},75678:(e,t,s)=>{s.d(t,{Kd:()=>o,Zo:()=>c});var a=s(82897),n=s(68404),r=s(19462),l=s(86647),i=s(33899);function c(e){const t=(0,i._)((e=>e.promRules)),s=(0,i._)((e=>e.rulerRules)),a=(0,n.useRef)({}),c=(0,n.useMemo)((()=>{if(e){const t=(0,r.o_)(e);if(!t)throw new Error(`Unknown rules source: ${e}`);return[t]}return(0,r.h_)()}),[e]);return(0,n.useMemo)((()=>c.map((e=>{var n,i;const c=(0,r.jq)(e)?e.name:e,o=null===(n=t[c])||void 0===n?void 0:n.result,m=null===(i=s[c])||void 0===i?void 0:i.result,h=a.current[c];if(h&&h.promRules===o&&h.rulerRules===m)return h.result;const g={};Object.entries(m||{}).forEach((t=>{let[s,a]=t;const n={rulesSource:e,name:s,groups:[]};g[s]=n,function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];e.groups=t.map((t=>{const s={name:t.name,interval:t.interval,source_tenants:t.source_tenants,rules:[]};return s.rules=t.rules.map((t=>d(t,e,s))),s}))}(n,a)})),null==o||o.forEach((t=>{let{name:s,groups:a}=t;!function(e,t){const s=new Map;e.groups.forEach((e=>s.set(e.name,e))),t.forEach((t=>{var a;let n=s.get(t.name);n||(n={name:t.name,rules:[]},e.groups.push(n),s.set(t.name,n));const i=new Map;n.rules.forEach((e=>{const t=i.get(e.name);t?t.push(e):i.set(e.name,[e])})),(null!==(a=t.rules)&&void 0!==a?a:[]).forEach((t=>{const s=function(e,t,s){const a=t.get(e.name);if(!a)return;if((0,r.HY)(s))return a[0];const n=a.find((t=>!t.promRule&&u(t,e,!0)));if(n)return n;const l=a.find((t=>!t.promRule&&u(t,e,!1)));if(l)return l;return}(t,i,e.rulesSource);s?s.promRule=t:n.rules.push(function(e,t,s){return{name:e.name,query:e.query,labels:e.labels||{},annotations:(0,l.x_)(e)&&e.annotations||{},promRule:e,namespace:t,group:s}}(t,e,n))}))}))}(g[s]=g[s]||{rulesSource:e,name:s,groups:[]},a)}));const x=Object.values(g);return a.current[c]={promRules:o,rulerRules:m,result:x},x})).flat()),[t,s,c])}function o(e){return e.map((e=>{const t=Object.assign({},e,{groups:[]});var s;return t.groups.push({name:"default",rules:(s=e.groups.flatMap((e=>e.rules)),s.sort(((e,t)=>e.name.localeCompare(t.name))))}),t}))}function d(e,t,s){return(0,l.cG)(e)?{name:e.alert,query:e.expr,labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:t,group:s}:(0,l.yF)(e)?{name:e.record,query:e.expr,labels:e.labels||{},annotations:{},rulerRule:e,namespace:t,group:s}:{name:e.grafana_alert.title,query:"",labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:t,group:s}}function u(e,t){let s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.name===t.name&&(0,a.isEqual)([s?m(e.query):"",e.labels,e.annotations],[s?m(t.query):"",t.labels||{},(0,l.x_)(t)&&t.annotations||{}])}function m(e){return e.length>1&&"("===e[0]&&")"===e[e.length-1]&&(e=e.slice(1,-1)),(e=e.replace(/\s|\n/g,"")).split("").sort().join("")}},28410:(e,t,s)=>{s.d(t,{j:()=>l});var a=s(68404),n=s(70356),r=s(98712);function l(){const{search:e}=(0,n.TH)();return[(0,a.useMemo)((()=>new URLSearchParams(e)),[e]),(0,a.useCallback)(((e,t)=>{r.E1.partial(e,t)}),[])]}},12783:(e,t,s)=>{s.d(t,{D:()=>n});var a=s(27549);const n=e=>({table:a.css`
    width: 100%;
    border-radius: ${e.shape.borderRadius()};
    border: solid 1px ${e.colors.border.weak};
    background-color: ${e.colors.background.secondary};

    th {
      padding: ${e.spacing(1)};
    }

    td {
      padding: 0 ${e.spacing(1)};
    }

    tr {
      height: 38px;
    }
  `,evenRow:a.css`
    background-color: ${e.colors.background.primary};
  `,colExpand:a.css`
    width: 36px;
  `,actionsCell:a.css`
    text-align: right;
    width: 1%;
    white-space: nowrap;

    & > * + * {
      margin-left: ${e.spacing(.5)};
    }
  `})}}]);
//# sourceMappingURL=AlertSilences.7e7eb8b1e412d705997d.js.map