"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[1783],{29507:(e,t,s)=>{s.d(t,{x:()=>l});var a=s(68404),n=s(18745),r=s(45193);function l(e){const t=(0,n.useDispatch)(),s=(0,a.useRef)(e);s.current=e,(0,a.useEffect)((()=>()=>{t((0,r.e)({stateSelector:s.current}))}),[t])}},43298:(e,t,s)=>{s.r(t),s.d(t,{default:()=>Fe});var a,n=s(68404),r=s(18745),l=s(42326),i=s(69783),c=s(50489),o=s(40256),d=s(71308),u=s(36636),m=s(82897),h=s(80916),g=s(17873),x=s(43215),p=s(90923),v=s(29507),f=s(10331),j=s(28410),b=s(33899),y=s(83809),S=s(82139),A=s(77048),w=s(39357),N=s(75678),C=s(86647),$=s(94322),k=s(9019),D=s(69357),M=s(45916);const R=()=>{var e;const[t,s]=(0,n.useState)([]),l=(0,h.Gc)(),c=(0,r.useDispatch)(),{watch:o}=l,d=o("matchers"),u=(0,i.useStyles2)(O),m=[{id:"state",label:"State",renderCell:function(e){let{data:{matchedInstance:t}}=e;return(0,M.jsx)(D.l,{state:t.state})},size:"160px"},{id:"labels",label:"Labels",renderCell:function(e){let{data:{matchedInstance:t}}=e;return(0,M.jsx)($.s,{labels:t.labels})},size:"250px"},{id:"created",label:"Created",renderCell:function(e){let{data:{matchedInstance:t}}=e;return(0,M.jsx)(M.Fragment,{children:t.activeAt.startsWith("0001")?"-":(0,x.dateTime)(t.activeAt).format("YYYY-MM-DD HH:mm:ss")})},size:"400px"}];(0,n.useEffect)((()=>{c((0,y.ei)())}),[c]);const p=(0,N.Zo)();return(0,g.Z)((()=>{const e=p.flatMap((e=>e.groups.flatMap((e=>e.rules.map((e=>e.promRule)).filter((e=>(0,C.x_)(e))).flatMap((e=>{var t;return(0,A.TZ)(null!==(t=e.alerts)&&void 0!==t?t:[],d)}))))));s(e)}),500,[p,d]),(0,M.jsxs)("div",{children:[(0,M.jsxs)("h4",{className:u.title,children:["Affected alert instances",t.length>0?(0,M.jsx)(i.Badge,{className:u.badge,color:"blue",text:t.length}):null]}),(0,M.jsx)("div",{className:u.table,children:d.every((e=>!e.value&&!e.name))?a||(a=(0,M.jsx)("span",{children:"Add a valid matcher to see affected alerts"})):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(k.t,{items:null!==(e=t.slice(0,5))&&void 0!==e?e:[],isExpandable:!1,cols:m}),t.length>5&&(0,M.jsxs)("div",{className:u.moreMatches,children:["and ",t.length-5," more"]})]})})]})};const O=e=>({table:u.css`
    max-width: ${e.breakpoints.values.lg}px;
  `,moreMatches:u.css`
    margin-top: ${e.spacing(1)};
  `,title:u.css`
    display: flex;
    align-items: center;
  `,badge:u.css`
    margin-left: ${e.spacing(1)};
  `}),q=["onChange","ref"];const I=e=>({wrapper:u.css`
      margin-top: ${e.spacing(2)};
    `,row:u.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:u.css`
      margin-left: ${e.spacing(1)};
      margin-top: ${e.spacing(2.5)};
    `,matcherOptions:u.css`
      min-width: 140px;
    `,matchers:u.css`
      max-width: ${e.breakpoints.values.sm}px;
      margin: ${e.spacing(1)} 0;
      padding-top: ${e.spacing(.5)};
    `}),T=e=>{let{className:t}=e;const s=(0,i.useStyles2)(I),a=(0,h.Gc)(),{control:n,register:r,formState:{errors:l}}=a,{fields:c=[],append:o,remove:d}=(0,h.Dq)({name:"matchers"});return(0,M.jsx)("div",{className:(0,u.cx)(t,s.wrapper),children:(0,M.jsx)(i.Field,{label:"Matching labels",required:!0,children:(0,M.jsxs)("div",{children:[(0,M.jsx)("div",{className:s.matchers,children:c.map(((e,t)=>{var a,o,u,m,h,g,x,p,v,f;return(0,M.jsxs)("div",{className:s.row,"data-testid":"matcher",children:[(0,M.jsx)(i.Field,{label:"Label",invalid:!(null==l||null===(a=l.matchers)||void 0===a||null===(o=a[t])||void 0===o||!o.name),error:null==l||null===(u=l.matchers)||void 0===u||null===(m=u[t])||void 0===m||null===(h=m.name)||void 0===h?void 0:h.message,children:(0,M.jsx)(i.Input,Object.assign({},r(`matchers.${t}.name`,{required:{value:!0,message:"Required."}}),{defaultValue:e.name,placeholder:"label"}))}),(0,M.jsx)(i.Field,{label:"Operator",children:(0,M.jsx)(i.InputControl,{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,q);return(0,M.jsx)(i.Select,Object.assign({},a,{onChange:e=>t(e.value),className:s.matcherOptions,options:S.tA,"aria-label":"operator"}))},defaultValue:e.operator||S.tA[0].value,name:`matchers.${t}.operator`,rules:{required:{value:!0,message:"Required."}}})}),(0,M.jsx)(i.Field,{label:"Value",invalid:!(null==l||null===(g=l.matchers)||void 0===g||null===(x=g[t])||void 0===x||!x.value),error:null==l||null===(p=l.matchers)||void 0===p||null===(v=p[t])||void 0===v||null===(f=v.value)||void 0===f?void 0:f.message,children:(0,M.jsx)(i.Input,Object.assign({},r(`matchers.${t}.value`,{required:{value:!0,message:"Required."}}),{defaultValue:e.value,placeholder:"value"}))}),c.length>1&&(0,M.jsx)(i.IconButton,{className:s.removeButton,tooltip:"Remove matcher",name:"trash-alt",onClick:()=>d(t),children:"Remove"})]},`${e.id}`)}))}),(0,M.jsx)(i.Button,{type:"button",icon:"plus",variant:"secondary",onClick:()=>{const e={name:"",value:"",operator:f._M.equal};o(e)},children:"Add matcher"})]})})})},B=()=>{const{control:e,getValues:t}=(0,h.Gc)(),s=(0,i.useStyles)(E),{field:{onChange:a,value:n},fieldState:{invalid:r}}=(0,h.bc)({name:"startsAt",control:e,rules:{validate:e=>t().endsAt>e}}),{field:{onChange:l,value:c},fieldState:{invalid:o}}=(0,h.bc)({name:"endsAt",control:e,rules:{validate:e=>t().startsAt<e}}),{field:{onChange:d,value:u}}=(0,h.bc)({name:"timeZone",control:e}),m=r||o,g=(0,x.dateTime)(n),p=(0,x.dateTime)(c);return(0,M.jsx)(i.Field,{className:s.timeRange,label:"Silence start and end",error:m?"To is before or the same as from":"",invalid:m,children:(0,M.jsx)(i.TimeRangeInput,{value:{from:g,to:p,raw:{from:g,to:p}},timeZone:u,onChange:e=>{a((0,x.dateTime)(e.from)),l((0,x.dateTime)(e.to))},onChangeTimeZone:e=>d(e),hideTimeZone:!1,hideQuickRanges:!0,placeholder:"Select time range"})})},E=e=>({timeRange:u.css`
    width: 400px;
  `});var Z,F,_,V,Y;const z=(e,t)=>{const s=new Date;if(t){var a;const e=Date.parse(t.endsAt)<Date.now()?{start:s,end:(0,x.addDurationToDate)(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,x.intervalToAbbreviatedDurationString)(e),isRegex:!1,matchers:(null===(a=t.matchers)||void 0===a?void 0:a.map(S.cm))||[],matcherName:"",matcherValue:"",timeZone:x.DefaultTimeZone}}{const t=(0,x.addDurationToDate)(s,{hours:2});return Object.assign({id:"",startsAt:s.toISOString(),endsAt:t.toISOString(),comment:`created ${(0,x.dateTime)().format("YYYY-MM-DD HH:mm")}`,createdBy:p.config.bootData.user.name,duration:"2h",isRegex:!1,matchers:[{name:"",value:"",operator:f._M.equal}],matcherName:"",matcherValue:"",timeZone:x.DefaultTimeZone},(e=>{const t={},s=e.get("comment"),a=e.getAll("matcher"),n=(0,A.RT)(a);return n.length&&(t.matchers=n.map(S.cm)),s&&(t.comment=s),t})(e))}},L=e=>({field:u.css`
    margin: ${e.spacing(1,0)};
  `,textArea:u.css`
    max-width: ${e.breakpoints.values.sm}px;
  `,createdBy:u.css`
    width: 200px;
  `,flexRow:u.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;

    & > * {
      margin-right: ${e.spacing(1)};
    }
  `,silencePeriod:u.css`
    max-width: ${e.breakpoints.values.sm}px;
  `}),G=e=>{var t;let{silence:s,alertManagerSourceName:a}=e;const[l]=(0,j.j)(),c=(0,n.useMemo)((()=>z(l,s)),[s,l]),o=(0,h.cI)({defaultValues:c}),d=(0,r.useDispatch)(),p=(0,i.useStyles2)(L),{loading:f}=(0,b._)((e=>e.updateSilence));(0,v.x)((e=>e.unifiedAlerting.updateSilence));const{register:A,handleSubmit:N,formState:C,watch:$,setValue:k,clearErrors:D}=o,O=$("duration"),q=$("startsAt"),I=$("endsAt"),[E,G]=(0,n.useState)(O);return(0,g.Z)((()=>{if((0,x.isValidDate)(q)&&(0,x.isValidDate)(I))if(O!==E)k("endsAt",(0,x.dateTime)((0,x.addDurationToDate)(new Date(q),(0,x.parseDuration)(O))).toISOString()),G(O);else{const e=new Date(q).valueOf();if(new Date(I).valueOf()>e){const e=(0,x.intervalToAbbreviatedDurationString)({start:new Date(q),end:new Date(I)});k("duration",e),G(e)}}}),700,[D,O,I,E,k,q]),(0,M.jsx)(h.RV,Object.assign({},o,{children:(0,M.jsxs)("form",{onSubmit:N((e=>{const{id:t,startsAt:s,endsAt:n,comment:r,createdBy:l,matchers:i}=e,c=i.map(S._J),o=(0,m.pickBy)({id:t,startsAt:s,endsAt:n,comment:r,createdBy:l,matchers:c},(e=>!!e));d((0,y.QY)({alertManagerSourceName:a,payload:o,exitOnSave:!0,successMessage:"Silence "+(o.id?"updated":"created")}))})),children:[(0,M.jsxs)(i.FieldSet,{label:""+(s?"Recreate silence":"Create silence"),children:[(0,M.jsxs)("div",{className:(0,u.cx)(p.flexRow,p.silencePeriod),children:[Z||(Z=(0,M.jsx)(B,{})),(0,M.jsx)(i.Field,{label:"Duration",invalid:!!C.errors.duration,error:C.errors.duration&&("required"===C.errors.duration.type?"Required field":C.errors.duration.message),children:(0,M.jsx)(i.Input,Object.assign({className:p.createdBy},A("duration",{validate:e=>0===Object.keys((0,x.parseDuration)(e)).length?"Invalid duration. Valid example: 1d 4h (Available units: y, M, w, d, h, m, s)":void 0}),{id:"duration"}))})]}),F||(F=(0,M.jsx)(T,{})),(0,M.jsx)(i.Field,{className:(0,u.cx)(p.field,p.textArea),label:"Comment",required:!0,error:null===(t=C.errors.comment)||void 0===t?void 0:t.message,invalid:!!C.errors.comment,children:(0,M.jsx)(i.TextArea,Object.assign({},A("comment",{required:{value:!0,message:"Required."}}),{rows:5,placeholder:"Details about the silence"}))}),_||(_=(0,M.jsx)(R,{}))]}),(0,M.jsxs)("div",{className:p.flexRow,children:[f&&(V||(V=(0,M.jsx)(i.Button,{disabled:!0,icon:"fa fa-spinner",variant:"primary",children:"Saving..."}))),!f&&(Y||(Y=(0,M.jsx)(i.Button,{type:"submit",children:"Submit"}))),(0,M.jsx)(i.LinkButton,{href:(0,w.eQ)("alerting/silences",a),variant:"secondary",fill:"outline",children:"Cancel"})]})]})}))};var H=s(90747),Q=s(26011),P=s(61959),U=s(82969),J=s(53262),W=s(68581);const K=["className"];const X=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,K);return(0,M.jsx)(W.zx,Object.assign({variant:"secondary",size:"xs",className:(0,u.cx)((0,i.useStyles)(ee),t)},s))},ee=e=>u.css`
  height: 24px;
  font-size: ${e.typography.size.sm};
`;var te,se=s(3799),ae=s(68698),ne=s(28436);const re=e=>{let{alertManagerSourceName:t}=e;const s=(0,U.QX)(t);return P.Vt.hasAccess(s.create,P.Vt.isEditor)?(0,M.jsx)(ne.Z,{title:"You haven't created any silences yet",buttonIcon:"bell-slash",buttonLink:(0,w.eQ)("alerting/silence/new",t),buttonTitle:"New silence"}):te||(te=(0,M.jsx)(i.CallToActionCard,{callToActionElement:(0,M.jsx)("div",{}),message:"No silences found."}))};var le,ie=s(12783),ce=s(91045),oe=s(82344);const de=e=>{let{alert:t,className:s}=e;const[a,r]=(0,n.useState)(!0),l=(0,x.intervalToAbbreviatedDurationString)({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,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)("tr",{className:s,children:[(0,M.jsx)("td",{children:(0,M.jsx)(ce.U,{isCollapsed:a,onToggle:e=>r(e)})}),(0,M.jsx)("td",{children:(0,M.jsx)(oe.G,{state:t.status.state})}),(0,M.jsxs)("td",{children:["for ",l," seconds"]}),(0,M.jsx)("td",{children:i})]}),!a&&(0,M.jsxs)("tr",{className:s,children:[le||(le=(0,M.jsx)("td",{})),(0,M.jsx)("td",{colSpan:5,children:(0,M.jsx)($.s,{labels:t.labels})})]})]})};var ue,me;const he=e=>({tableMargin:u.css`
    margin-bottom: ${e.spacing(1)};
  `,colState:u.css`
    width: 110px;
  `,colName:u.css`
    width: 65%;
  `}),ge=e=>{let{silencedAlerts:t}=e;const s=(0,i.useStyles2)(ie.D),a=(0,i.useStyles2)(he);return t.length?(0,M.jsxs)("table",{className:(0,u.cx)(s.table,a.tableMargin),children:[(0,M.jsxs)("colgroup",{children:[(0,M.jsx)("col",{className:s.colExpand}),(0,M.jsx)("col",{className:a.colState}),ue||(ue=(0,M.jsx)("col",{})),(0,M.jsx)("col",{className:a.colName})]}),me||(me=(0,M.jsx)("thead",{children:(0,M.jsxs)("tr",{children:[(0,M.jsx)("th",{}),(0,M.jsx)("th",{children:"State"}),(0,M.jsx)("th",{}),(0,M.jsx)("th",{children:"Alert name"})]})})),(0,M.jsx)("tbody",{children:t.map(((e,t)=>(0,M.jsx)(de,{alert:e,className:t%2==0?s.evenRow:""},e.fingerprint)))})]}):null},xe=e=>{let{silence:t}=e;const{startsAt:s,endsAt:a,comment:n,createdBy:r,silencedAlerts:l}=t,c=(0,i.useStyles2)(pe),o="YYYY-MM-DD HH:mm",d=x.dateMath.parse(s),u=x.dateMath.parse(a),m=(0,x.intervalToAbbreviatedDurationString)({start:new Date(s),end:new Date(a)});return(0,M.jsxs)("div",{className:c.container,children:[(0,M.jsx)("div",{className:c.title,children:"Comment"}),(0,M.jsx)("div",{children:n}),(0,M.jsx)("div",{className:c.title,children:"Schedule"}),(0,M.jsx)("div",{children:`${null==d?void 0:d.format(o)} - ${null==u?void 0:u.format(o)}`}),(0,M.jsx)("div",{className:c.title,children:"Duration"}),(0,M.jsxs)("div",{children:[" ",m]}),(0,M.jsx)("div",{className:c.title,children:"Created by"}),(0,M.jsxs)("div",{children:[" ",r]}),(0,M.jsx)("div",{className:c.title,children:"Affected alerts"}),(0,M.jsx)(ge,{silencedAlerts:l})]})},pe=e=>({container:u.css`
    display: grid;
    grid-template-columns: 1fr 9fr;
    grid-row-gap: 1rem;
  `,title:u.css`
    color: ${e.colors.text.primary};
  `,row:u.css`
    margin: ${e.spacing(1,0)};
  `});var ve=s(49179);const fe={[f.As.Active]:"good",[f.As.Expired]:"neutral",[f.As.Pending]:"neutral"},je=e=>{let{state:t}=e;return(0,M.jsx)(ve.i,{state:fe[t],children:t})};var be,ye;const Se=Object.entries(f.As).map((e=>{let[t,s]=e;return{label:t,value:s}})),Ae=()=>(0,m.uniqueId)("query-string-"),we=()=>{const[e,t]=(0,n.useState)(Ae()),[s,a]=(0,Q.K)(),{queryString:r,silenceState:l}=(0,w.pF)(s),c=(0,i.useStyles2)(Ne),o=(0,m.debounce)((e=>{const t=e.target;a({queryString:t.value||null})}),400),d=!!(r&&r.length>3)&&0===(0,S.Zh)(r).length;return(0,M.jsxs)("div",{className:c.flexRow,children:[(0,M.jsx)(i.Field,{className:c.rowChild,label:be||(be=(0,M.jsx)(i.Label,{children:(0,M.jsxs)(H.Stack,{gap:.5,children:[(0,M.jsx)("span",{children:"Search by matchers"}),(0,M.jsx)(i.Tooltip,{content:(0,M.jsxs)("div",{children:["Filter silences by matchers using a comma separated list of matchers, ie:",(0,M.jsx)("pre",{children:"severity=critical, instance=~cluster-us-.+"})]}),children:(0,M.jsx)(i.Icon,{name:"info-circle",size:"sm"})})]})})),invalid:d,error:d?"Query must use valid matcher syntax":null,children:(0,M.jsx)(i.Input,{className:c.searchInput,prefix:ye||(ye=(0,M.jsx)(i.Icon,{name:"search"})),onChange:o,defaultValue:null!=r?r:"",placeholder:"Search","data-testid":"search-query-input"},e)}),(0,M.jsx)(i.Field,{className:c.rowChild,label:"State",children:(0,M.jsx)(i.RadioButtonGroup,{options:Se,value:l,onChange:e=>{a({silenceState:e})}})}),(r||l)&&(0,M.jsx)("div",{className:c.rowChild,children:(0,M.jsx)(i.Button,{variant:"secondary",icon:"times",onClick:()=>{a({queryString:null,silenceState:null}),setTimeout((()=>t(Ae())))},children:"Clear filters"})})]})},Ne=e=>({searchInput:u.css`
    width: 360px;
  `,flexRow:u.css`
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    padding-bottom: ${e.spacing(2)};
    border-bottom: 1px solid ${e.colors.border.strong};
  `,rowChild:u.css`
    margin-right: ${e.spacing(1)};
    margin-bottom: 0;
    max-height: 52px;
  `,fieldLabel:u.css`
    font-size: 12px;
    font-weight: 500;
  `});var Ce,$e,ke,De;const Me=e=>{const[t]=(0,Q.K)();return(0,n.useMemo)((()=>{const{queryString:s,silenceState:a}=(0,w.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,S.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])},Re=e=>({topButtonContainer:u.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
  `,addNewSilence:u.css`
    margin: ${e.spacing(2,0)};
  `,callout:u.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:u.css`
    color: ${e.colors.info.text};
  `,editButton:u.css`
    margin-left: ${e.spacing(.5)};
  `});const Oe=e=>{let{silences:t,alertManagerAlerts:s,alertManagerSourceName:a}=e;const l=(0,i.useStyles2)(Re),[c]=(0,Q.K)(),o=Me(t),d=(0,U.QX)(a),{silenceState:u}=(0,w.pF)(c),m=!!o.length&&(void 0===u||u===f.As.Expired),h=function(e){const t=(0,r.useDispatch)(),s=(0,i.useStyles2)(Re),a=(0,U.QX)(e);return(0,n.useMemo)((()=>{const n=s=>{t((0,y.yO)(e,s))},r=[{id:"state",label:"State",renderCell:function(e){let{data:{status:t}}=e;return(0,M.jsx)(je,{state:t.state})},size:"88px"},{id:"matchers",label:"Matching labels",renderCell:function(e){let{data:{matchers:t}}=e;return(0,M.jsx)(ae.g,{matchers:t||[]})},size:9},{id:"alerts",label:"Alerts",renderCell:function(e){let{data:{silencedAlerts:t}}=e;return(0,M.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=x.dateMath.parse(t),n=x.dateMath.parse(s),r="YYYY-MM-DD HH:mm";return(0,M.jsxs)(M.Fragment,{children:[" ",null==a?void 0:a.format(r)," ","-",ke||(ke=(0,M.jsx)("br",{})),null==n?void 0:n.format(r)]})},size:"150px"}];return P.Vt.hasAccess(a.update,P.Vt.isEditor)&&r.push({id:"actions",label:"Actions",renderCell:function(t){let{data:a}=t;return(0,M.jsxs)(H.Stack,{gap:.5,children:["expired"===a.status.state?(0,M.jsx)(i.Link,{href:(0,w.eQ)(`/alerting/silence/${a.id}/edit`,e),children:De||(De=(0,M.jsx)(X,{icon:"sync",children:"Recreate"}))}):(0,M.jsx)(X,{icon:"bell",onClick:()=>n(a.id),children:"Unsilence"}),"expired"!==a.status.state&&(0,M.jsx)(se.A,{className:s.editButton,to:(0,w.eQ)(`/alerting/silence/${a.id}/edit`,e),icon:"pen",tooltip:"edit"})]})},size:"147px"}),r}),[e,t,s,a])}(a),g=(0,n.useMemo)((()=>o.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})}}))),[o,s]);return(0,M.jsxs)("div",{"data-testid":"silences-table",children:[!!t.length&&(0,M.jsxs)(M.Fragment,{children:[Ce||(Ce=(0,M.jsx)(we,{})),(0,M.jsx)(J.q,{actions:[d.create],fallback:P.Vt.isEditor,children:(0,M.jsx)("div",{className:l.topButtonContainer,children:(0,M.jsx)(i.Link,{href:(0,w.eQ)("/alerting/silence/new",a),children:(0,M.jsx)(i.Button,{className:l.addNewSilence,icon:"plus",children:"New Silence"})})})}),g.length?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(k.t,{items:g,cols:h,isExpandable:!0,renderExpandedContent:e=>{let{data:t}=e;return(0,M.jsx)(xe,{silence:t})}}),m&&(0,M.jsxs)("div",{className:l.callout,children:[(0,M.jsx)(i.Icon,{className:l.calloutIcon,name:"info-circle"}),$e||($e=(0,M.jsx)("span",{children:"Expired silences are automatically deleted after 5 days."}))]})]}):"No matching silences found"]}),!t.length&&(0,M.jsx)(re,{alertManagerSourceName:a})]})};var qe,Ie,Te=s(82498),Be=s(1698),Ee=s(85464),Ze=s(8455);const Fe=(0,i.withErrorBoundary)((()=>{var e,t;const s=(0,Be.k)("instance"),[a,u]=(0,Te.k)(s),m=(0,r.useDispatch)(),h=(0,b._)((e=>e.silences)),g=(0,b._)((e=>e.amAlerts)),x=a?g[a]||Ze.oq:void 0,p=(0,l.TH)().pathname.endsWith("/alerting/silences");(0,n.useEffect)((()=>{function e(){a&&(m((0,y.je)(a)),m((0,y.dB)(a)))}e();const t=setInterval((()=>e),Ee.cm);return()=>{clearInterval(t)}}),[a,m]);const{result:v,loading:f,error:j}=a&&h[a]||Ze.oq,S=(0,n.useCallback)((e=>v&&v.find((t=>t.id===e))),[v]);return a?(0,M.jsxs)(o.J,{pageId:"silences",children:[(0,M.jsx)(c.P,{disabled:!p,current:a,onChange:u,dataSources:s}),j&&!f&&(0,M.jsx)(i.Alert,{severity:"error",title:"Error loading silences",children:j.message||"Unknown error."}),(null==x?void 0:x.error)&&!(null!=x&&x.loading)&&(0,M.jsx)(i.Alert,{severity:"error",title:"Error loading Alertmanager alerts",children:(null===(e=x.error)||void 0===e?void 0:e.message)||"Unknown error."}),f&&(Ie||(Ie=(0,M.jsx)(i.LoadingPlaceholder,{text:"loading silences..."}))),v&&!j&&(0,M.jsxs)(l.rs,{children:[(0,M.jsx)(l.AW,{exact:!0,path:"/alerting/silences",children:(0,M.jsx)(Oe,{silences:v,alertManagerAlerts:null!==(t=null==x?void 0:x.result)&&void 0!==t?t:[],alertManagerSourceName:a})}),(0,M.jsx)(l.AW,{exact:!0,path:"/alerting/silence/new",children:(0,M.jsx)(G,{alertManagerSourceName:a})}),(0,M.jsx)(l.AW,{exact:!0,path:"/alerting/silence/:id/edit",children:e=>{let{match:t}=e;return(null==t?void 0:t.params.id)&&(0,M.jsx)(G,{silence:S(t.params.id),alertManagerSourceName:a})}})]})]}):p?(0,M.jsx)(o.J,{pageId:"silences",children:(0,M.jsx)(d.I,{availableAlertManagers:s})}):qe||(qe=(0,M.jsx)(l.l_,{to:"/alerting/silences"}))}),{style:"page"})},40256:(e,t,s)=>{s.d(t,{J:()=>i});s(68404);var a=s(18745),n=s(33801),r=s(8674),l=s(45916);const i=e=>{let{children:t,pageId:s,isLoading:i}=e;const c=(0,r.h)((0,a.useSelector)((e=>e.navIndex)),s);return(0,l.jsx)(n.Z,{navModel:c,children:(0,l.jsx)(n.Z.Contents,{isLoading:i,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(69783),c=s(82498),o=s(50489),d=s(45916);const u=()=>a||(a=(0,d.jsx)(i.Alert,{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.Alert,{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:()=>l});s(68404);var a=s(69783),n=s(45916);const r=["tooltip","icon","to","target","onClick","className","tooltipPlacement"];const l=e=>{let{tooltip:t,icon:s,to:l,target:i,onClick:c,className:o,tooltipPlacement:d="top"}=e,u=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,r);const m="string"==typeof t?t:void 0;return(0,n.jsx)(a.Tooltip,{content:t,placement:d,children:l?(0,n.jsx)(a.LinkButton,Object.assign({variant:"secondary",fill:"text",icon:s,href:l,size:"sm",target:i},u,{"aria-label":m})):(0,n.jsx)(a.Button,Object.assign({className:o,variant:"secondary",fill:"text",size:"sm",icon:s,type:"button",onClick:c},u,{"aria-label":m}))})}},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:()=>i});var a=s(36636),n=(s(68404),s(69783)),r=s(82139),l=s(45916);const i=e=>{let{matchers:t}=e;const s=(0,n.useStyles2)(c);return(0,l.jsx)("div",{children:(0,l.jsx)(n.TagList,{className:s.tags,tags:t.map((e=>`${e.name}${(0,r.zy)(e)}${e.value}`))})})},c=()=>({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:()=>c,Zo:()=>i});var a=s(68404),n=s(19462),r=s(86647),l=s(33899);function i(e){const t=(0,l._)((e=>e.promRules)),s=(0,l._)((e=>e.rulerRules)),i=(0,a.useRef)({}),c=(0,a.useMemo)((()=>{if(e){const t=(0,n.o_)(e);if(!t)throw new Error(`Unknown rules source: ${e}`);return[t]}return(0,n.h_)()}),[e]);return(0,a.useMemo)((()=>c.map((e=>{var a,l;const c=(0,n.jq)(e)?e.name:e,d=null===(a=t[c])||void 0===a?void 0:a.result,u=null===(l=s[c])||void 0===l?void 0:l.result,m=i.current[c];if(m&&m.promRules===d&&m.rulerRules===u)return m.result;const h={};Object.entries(u||{}).forEach((t=>{let[s,a]=t;const n={rulesSource:e,name:s,groups:[]};h[s]=n,function(e,t){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=>function(e,t,s){return(0,r.cG)(e)?{name:e.alert,query:e.expr,labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:t,group:s}:(0,r.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}}(t,e,s))),s}))}(n,a)})),null==d||d.forEach((t=>{let{name:s,groups:a}=t;!function(e,t){t.forEach((t=>{var s;let a=e.groups.find((e=>e.name===t.name));a||(a={name:t.name,rules:[]},e.groups.push(a)),(null!==(s=t.rules)&&void 0!==s?s:[]).forEach((t=>{const s=function(e,t,s){var a;if((0,n.HY)(s))return t.rules.find((t=>t.name===e.name));return null!==(a=t.rules.find((t=>!t.promRule&&o(t,e,!0))))&&void 0!==a?a:t.rules.find((t=>!t.promRule&&o(t,e,!1)))}(t,a,e.rulesSource);s?s.promRule=t:a.rules.push(function(e,t,s){return{name:e.name,query:e.query,labels:e.labels||{},annotations:(0,r.x_)(e)&&e.annotations||{},promRule:e,namespace:t,group:s}}(t,e,a))}))}))}(h[s]=h[s]||{rulesSource:e,name:s,groups:[]},a)}));const g=Object.values(h);return i.current[c]={promRules:d,rulerRules:u,result:g},g})).flat()),[t,s,c])}function c(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 o(e,t){let s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.name===t.name&&JSON.stringify([s?d(e.query):"",e.labels,e.annotations])===JSON.stringify([s?d(t.query):"",t.labels||{},(0,r.x_)(t)&&t.annotations||{}])}function d(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(42326),r=s(90923);function l(){const{search:e}=(0,n.TH)();return[(0,a.useMemo)((()=>new URLSearchParams(e)),[e]),(0,a.useCallback)(((e,t)=>{r.locationService.partial(e,t)}),[])]}},12783:(e,t,s)=>{s.d(t,{D:()=>n});var a=s(36636);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.5c41dd28003455689d75.js.map