"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8648],{23569:(Z,C,n)=>{n.r(C),n.d(C,{default:()=>jn,findRoutesMatchingFilters:()=>Dt});var s=n(9892),i=n(82897),e=n(68404),d=n(26418),p=n(72648),P=n(72142),f=n(79841),T=n(94893),S=n(61744),W=n(45253),R=n(53546),L=n(96044),k=n(81168),I=n(40014),B=n(96678),J=n(94984),X=n(45524),pe=n(731),Fe=n(88331),Ee=n(40106),z=n(31403),Ve=n(98102),ve=n(29460),me=n(8180),y=n(82002),H=n(51981),j=n(69945),q=n(72004),te=n(97953),x=n(20194),Q=n(10505),se=n(46818),$t=n(53731);const Wt=({children:t})=>{const a=(0,p.wW)(Bt);return e.createElement("div",{className:a.container},t)},Bt=t=>({container:s.css`
      background-color: ${t.colors.background.secondary};
      color: ${t.colors.text.secondary};
      padding: ${t.spacing(4)};
      text-align: center;
    `}),wt=({buttonIcon:t,buttonLabel:a,buttonSize:r="lg",buttonVariant:l="primary",onButtonClick:m,text:o,href:c,showButton:u=!0})=>{const g=(0,p.wW)(Gt),v={className:g.button,icon:t,size:r,variant:l};return e.createElement(Wt,null,e.createElement(e.Fragment,null,e.createElement("p",{className:g.text},o),u&&(c?e.createElement(z.Qj,{href:c,type:"button",...v},a):e.createElement(z.zx,{onClick:m,type:"button",...v},a))))},Gt=t=>({container:s.css`
      background-color: ${t.colors.background.secondary};
      color: ${t.colors.text.secondary};
      padding: ${t.spacing(4)};
      text-align: center;
    `,text:s.css`
      margin-bottom: ${t.spacing(2)};
    `,button:s.css`
      margin: ${t.spacing(2,0,1)};
    `});var rt=n(63029);const Nt=({alertManagerSourceName:t,muteTimingNames:a,hideActions:r})=>{const l=(0,p.wW)(Ft),m=(0,k.useDispatch)(),o=(0,te.Ko)(t),c=(0,j._)(G=>G.amConfigs),[u,g]=(0,e.useState)(""),{result:v}=t&&c[t]||se.oq,b=(0,e.useMemo)(()=>{const G=v?.alertmanager_config?.mute_time_intervals??[],D=v?.alertmanager_config?.muteTimeProvenances??{};return G.filter(({name:E})=>a?a.includes(E):!0).map(E=>({id:E.name,data:{...E,provenance:D[E.name]}}))},[v?.alertmanager_config?.mute_time_intervals,v?.alertmanager_config?.muteTimeProvenances,a]),h=Lt(t,r,g);return e.createElement("div",{className:l.container},e.createElement(d.Stack,{direction:"row",alignItems:"center"},e.createElement("span",null,"Enter specific time intervals when not to send notifications or freeze notifications for recurring periods of time."),e.createElement(rt.L,null),!r&&b.length>0&&e.createElement(H.q,{actions:[o.create]},e.createElement(z.Qj,{className:l.addMuteButton,icon:"plus",variant:"primary",href:(0,Q.eQ)("alerting/routes/mute-timing/new",t)},"Add mute timing"))),b.length>0?e.createElement($t.t,{items:b,cols:h}):r?e.createElement("p",null,"No mute timings configured"):e.createElement(wt,{text:"You haven't created any mute timings yet",buttonLabel:"Add mute timing",buttonIcon:"plus",buttonSize:"lg",href:(0,Q.eQ)("alerting/routes/mute-timing/new",t),showButton:y.Vt.hasPermission(o.create)}),!r&&e.createElement(Ve.s,{isOpen:!!u,title:"Delete mute timing",body:`Are you sure you would like to delete "${u}"`,confirmText:"Delete",onConfirm:()=>m((0,q.r0)(t,u)),onDismiss:()=>g("")}))};function Lt(t,a=!1,r){const l=(0,te.Ko)(t),m=y.Vt.hasPermission(l.update),o=y.Vt.hasPermission(l.delete),c=!a&&(m||o);return(0,e.useMemo)(()=>{const u=[{id:"name",label:"Name",renderCell:function({data:v}){return e.createElement(e.Fragment,null,v.name," ",v.provenance&&e.createElement(Ee.C0,null))},size:"250px"},{id:"timeRange",label:"Time range",renderCell:({data:g})=>Ut(g.time_intervals)}];return c&&u.push({id:"actions",label:"Actions",renderCell:function({data:v}){return v.provenance?e.createElement("div",null,e.createElement(ve.r,{href:(0,Q.eQ)("/alerting/routes/mute-timing/edit",t,{muteName:v.name})},e.createElement(me.h,{name:"file-alt",title:"View mute timing"}))):e.createElement("div",null,e.createElement(H.q,{actions:[l.update]},e.createElement(ve.r,{href:(0,Q.eQ)("/alerting/routes/mute-timing/edit",t,{muteName:v.name})},e.createElement(me.h,{name:"edit",title:"Edit mute timing"}))),e.createElement(H.q,{actions:[l.delete]},e.createElement(me.h,{name:"trash-alt",title:"Delete mute timing",onClick:()=>r(v.name)})))},size:"100px"}),u},[t,r,c,l])}function Ut(t){return t.map((a,r)=>{const{times:l,weekdays:m,days_of_month:o,months:c,years:u}=a,g=(0,x.u6)(l),v=(0,x.v7)(m),b=(0,x.J8)(o),h=(0,x.m8)(c),G=(0,x.qw)(u);return e.createElement(e.Fragment,{key:JSON.stringify(a)+r},`${g} ${v}`,e.createElement("br",null),[b,h,G].join(" | "),e.createElement("br",null))})}const Ft=t=>({container:s.css`
    display: flex;
    flex-flow: column nowrap;
  `,addMuteButton:s.css`
    margin-bottom: ${t.spacing(2)};
    align-self: flex-end;
  `});var U=n(24799),Vt=n(64353),fe=n(6554),re=n(39904),Oe=n(46967),ie=n(53217),zt=n(31808);const jt=({receivers:t,onChangeReceiver:a,onChangeMatchers:r})=>{const[l,m]=(0,zt.j)(),o=(0,e.useRef)(null),{queryString:c,contactPoint:u}=kt(l),g=(0,p.wW)(Qt),v=(0,e.useCallback)(()=>(0,i.debounce)(r,500),[r]);(0,e.useEffect)(()=>{a(u)},[u,a]),(0,e.useEffect)(()=>{const M=(0,x.Zh)(c??"").map(x.xz);v()(M)},[v,c]);const b=(0,e.useCallback)(()=>{o.current&&(o.current.value=""),m({contactPoint:void 0,queryString:void 0})},[m]),h=t.map(Kt),G=h.find(M=>M.value===u)??null,D=c||u,E=c&&c.length>3?(0,x.Zh)(c).length===0:!1;return e.createElement(d.Stack,{direction:"row",alignItems:"flex-start",gap:.5},e.createElement(U.g,{className:g.noBottom,label:e.createElement(Vt._,null,e.createElement(d.Stack,{gap:.5},e.createElement("span",null,"Search by matchers"),e.createElement(fe.u,{content:e.createElement("div",null,"Filter silences by matchers using a comma separated list of matchers, ie:",e.createElement("pre",null,"severity=critical, instance=~cluster-us-.+"))},e.createElement(re.J,{name:"info-circle",size:"sm"})))),invalid:E,error:E?"Query must use valid matcher syntax":null},e.createElement(Oe.I,{ref:o,"data-testid":"search-query-input",placeholder:"Search",width:46,prefix:e.createElement(re.J,{name:"search"}),onChange:M=>{m({queryString:M.currentTarget.value})},defaultValue:c})),e.createElement(U.g,{label:"Search by contact point",style:{marginBottom:0}},e.createElement(ie.Ph,{id:"receiver","aria-label":"Search by contact point",value:G,options:h,onChange:M=>{m({contactPoint:M?.value})},width:28,isClearable:!0})),D&&e.createElement(z.zx,{variant:"secondary",icon:"times",onClick:b,style:{marginTop:19}},"Clear filters"))};function ot(t,a){const r=[];function l(m){a(m)&&r.push(m),m.routes?.forEach(l)}return l(t),r}function lt(t){return{...t,routes:t.routes?.map(a=>{const r=(0,i.pick)(t,["receiver","group_by","group_wait","group_interval","repeat_interval","mute_time_intervals"]);return lt({...r,...a})})}}const Kt=t=>({label:t.name,value:t.name}),kt=t=>({queryString:t.get("queryString")??void 0,contactPoint:t.get("contactPoint")??void 0}),Qt=()=>({noBottom:s.css`
    margin-bottom: 0;
  `});var ne=n(35029),Zt=n(67487),K=n(39031),Ht=n(94647),st=n(52259),Jt=n(64681),Se=n.n(Jt),he=n(19985);const Yt=({active:t=0,suppressed:a=0,unprocessed:r=0})=>{const l=[],m=t+a+r;return t&&l.push(e.createElement(he.C,{color:"red",key:"firing",text:`${t} firing`})),a&&l.push(e.createElement(he.C,{color:"blue",key:"suppressed",text:`${a} suppressed`})),r&&l.push(e.createElement(he.C,{color:"orange",key:"unprocessed",text:`${r} unprocessed`})),l.length>1&&l.unshift(e.createElement(e.Fragment,{key:"total"},m," ",Se()("instance",m))),Boolean(l.length)?e.createElement(d.Stack,{gap:.5},l):null};var it=n(94270),ue=n(63619),Xt=n(2352),ct=n(45849);const qt=(t,a,r)=>{if(!ze(a.id??"",r))throw new Error(`No such route with ID '${a.id}'`);function m(o){let c=o;if(o.id===a.id){const u=Ke(t,a,r);c=(0,i.omit)({...o,...u},"id")}return(0,i.omit)({...c,routes:o.routes?.map(m)},"id")}return m(r)},_t=(t,a)=>{if(t.id===a.id)throw new Error("You cant remove the root policy");function r(l){return(0,i.omit)({...l,routes:l.routes?.reduce((m=[],o)=>(o.id===t.id||m.push(r(o)),m),[])},"id")}return r(a)},en=(t,a,r,l)=>{const m=Ke(t,a,l);function o(u){return u.id===r.id?{...u,routes:u.routes?.concat(m)}:{...u,routes:u.routes?.map(o)}}function c(u){return(0,i.omit)({...u,routes:u.routes?.map(c)},"id")}return c(o(l))};function ze(t,a){return a.id===t?a:a.routes?.find(r=>ze(t,r))}var tn=n(20383);const mt=(t,a)=>Object.entries(t??{}).reduce((r,[l,m])=>[...r,{name:l,value:m,operator:a?K._M.regex:K._M.equal}],[]),ut=t=>t.value,nn=t=>(t??[]).map(ut),an={name:"",value:"",operator:K._M.equal},rn=["grafana_folder","alertname"],dt=[{label:"grafana_folder",value:"grafana_folder"},{label:"alertname",value:"alertname"},{label:"Disable (...)",value:"..."}],gt={id:"",overrideGrouping:!1,groupBy:rn,object_matchers:[],routes:[],continue:!1,receiver:"",overrideTimings:!1,groupWaitValue:"",groupIntervalValue:"",repeatIntervalValue:"",muteTimeIntervals:[]},De=t=>{const a=[];return t.matchers&&t.matchers.forEach(r=>{const{name:l,value:m,isEqual:o,isRegex:c}=(0,x.tC)(r);let u=K._M.equal;o&&c&&(u=K._M.regex),!o&&c&&(u=K._M.notRegex),o&&!c&&(u=K._M.equal),!o&&!c&&(u=K._M.notEqual),a.push([l,u,m])}),t.object_matchers&&a.push(...t.object_matchers),t.match_re&&Object.entries(t.match_re).forEach(([r,l])=>{a.push([r,K._M.regex,l])}),t.match&&Object.entries(t.match).forEach(([r,l])=>{a.push([r,K._M.equal,l])}),a};function pt(t){return{id:(0,i.uniqueId)("route-"),...t,routes:(t.routes??[]).map(pt)}}const je=t=>{if(!t)return gt;const a="id"in t?t.id:(0,i.uniqueId)("route-");if(Object.keys(t).length===0)return{...gt,id:a};const r=[];t.routes?.forEach(o=>{const c=je(o);r.push(c)});const l=t.object_matchers?.map(o=>({name:o[0],operator:o[1],value:o[2]}))??[],m=t.matchers?.map(o=>(0,x.cm)((0,x.tC)(o)))??[];return{id:a,object_matchers:[...m,...l,...mt(t.match,!1),...mt(t.match_re,!0)],continue:t.continue??!1,receiver:t.receiver??"",overrideGrouping:Array.isArray(t.group_by)&&t.group_by.length!==0,groupBy:t.group_by??[],overrideTimings:[t.group_wait,t.group_interval,t.repeat_interval].some(Boolean),groupWaitValue:t.group_wait??"",groupIntervalValue:t.group_interval??"",repeatIntervalValue:t.repeat_interval??"",routes:r,muteTimeIntervals:t.mute_time_intervals??[]}},Ke=(t,a,r)=>{const l=ze(a.id??"",r),{overrideGrouping:m,groupBy:o,overrideTimings:c,groupWaitValue:u,groupIntervalValue:g,repeatIntervalValue:v,receiver:b}=a,h=m&&o?o:[],D=c&&u?u:void 0,M=c&&g?g:void 0,_=c&&v?v:void 0,w=a.object_matchers?.filter(O=>O.name&&O.value&&O.operator).map(({name:O,operator:$,value:A})=>[O,$,A]),N=a.routes?.map(O=>Ke(t,O,r)),V={...l??{},continue:a.continue,group_by:h,object_matchers:w,match:void 0,match_re:void 0,group_wait:D,group_interval:M,repeat_interval:_,routes:N,mute_time_intervals:a.muteTimeIntervals,receiver:b};return t!==ct.GC?(V.matchers=a.object_matchers?.map(({name:O,operator:$,value:A})=>`${O}${$}${A}`),V.object_matchers=void 0):(V.object_matchers=De(V),V.matchers=void 0),a.receiver&&(V.receiver=a.receiver),V},ke=t=>({label:t,value:t}),Et=t=>(t??[]).map(ke),vt=t=>{if(t!==null)return t?ut(t)??"":""},Qe=t=>t?nn(t):[];function de(t){return t.length===0?!0:(0,tn.wd)(t)||"Invalid duration format. Must be {number}{time_unit}"}var ye=n(42042),be=n(4528);function on(){const t=(0,p.wW)(ft);return e.createElement("div",null,"Prometheus duration format consist of a number followed by a time unit.",e.createElement("br",null),"Different units can be combined for more granularity.",e.createElement("hr",null),e.createElement("div",{className:t.list},e.createElement("div",{className:t.header},e.createElement("div",null,"Symbol"),e.createElement("div",null,"Time unit"),e.createElement("div",null,"Example")),e.createElement(Ce,{unit:be.t.seconds,name:"seconds",example:"20s"}),e.createElement(Ce,{unit:be.t.minutes,name:"minutes",example:"10m"}),e.createElement(Ce,{unit:be.t.hours,name:"hours",example:"4h"}),e.createElement(Ce,{unit:be.t.days,name:"days",example:"3d"}),e.createElement(Ce,{unit:be.t.weeks,name:"weeks",example:"2w"}),e.createElement("div",{className:t.examples},e.createElement("div",null,"Multiple units combined"),e.createElement("code",null,"1m30s, 2h30m20s, 1w2d"))))}function Ce({unit:t,name:a,example:r}){const l=(0,p.wW)(ft);return e.createElement(e.Fragment,null,e.createElement("div",{className:l.unit},t),e.createElement("div",null,a),e.createElement("code",null,r))}const ft=t=>({unit:s.css`
    font-weight: ${t.typography.fontWeightBold};
  `,list:s.css`
    display: grid;
    grid-template-columns: max-content 1fr 2fr;
    gap: ${t.spacing(1,3)};
  `,header:s.css`
    display: contents;
    font-weight: ${t.typography.fontWeightBold};
  `,examples:s.css`
    display: contents;
    & > div {
      grid-column: 1 / span 2;
    }
  `}),ce=e.forwardRef((t,a)=>e.createElement(Oe.I,{suffix:e.createElement(ye.z,{content:e.createElement(on,null),disabled:!1},e.createElement(re.J,{name:"info-circle",size:"lg"})),...t,ref:a}));ce.displayName="PromDurationInput";const ht=t=>({container:s.css`
      align-items: center;
      display: flex;
      flex-flow: row nowrap;

      & > * + * {
        margin-left: ${t.spacing(1)};
      }
    `,input:s.css`
      flex: 1;
    `,promDurationInput:s.css`
      max-width: ${t.spacing(32)};
    `,timingFormContainer:s.css`
      padding: ${t.spacing(1)};
    `,linkText:s.css`
      text-decoration: underline;
    `,collapse:s.css`
      border: none;
      background: none;
      color: ${t.colors.text.primary};
    `}),Ae={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"},ln=({actionButtons:t,alertManagerSourceName:a,onSubmit:r,receivers:l,route:m})=>{const o=(0,p.wW)(ht),[c,u]=(0,e.useState)(!1),[g,v]=(0,e.useState)(Et(m.group_by)),b=je(m);return e.createElement(it.l,{defaultValues:{...b,overrideTimings:!0,overrideGrouping:!0},onSubmit:r},({register:h,control:G,errors:D,setValue:E})=>e.createElement(e.Fragment,null,e.createElement(U.g,{label:"Default contact point",invalid:!!D.receiver,error:D.receiver?.message},e.createElement(e.Fragment,null,e.createElement("div",{className:o.container,"data-testid":"am-receiver-select"},e.createElement(ue.g,{render:({field:{onChange:M,ref:F,..._}})=>e.createElement(ie.Ph,{"aria-label":"Default contact point",..._,className:o.input,onChange:w=>M(vt(w)),options:l}),control:G,name:"receiver",rules:{required:{value:!0,message:"Required."}}}),e.createElement("span",null,"or"),e.createElement(ve.r,{className:o.linkText,href:(0,Q.eQ)("/alerting/notifications/receivers/new",a)},"Create a contact point")))),e.createElement(U.g,{label:"Group by",description:"Group alerts when you receive a notification based on labels.","data-testid":"am-group-select"},e.createElement(ue.g,{render:({field:{onChange:M,ref:F,..._}})=>e.createElement(ie.NU,{"aria-label":"Group by",..._,allowCustomValue:!0,className:o.input,onCreateOption:w=>{v(N=>[...N,ke(w)]),E("groupBy",[..._.value,w])},onChange:w=>M(Qe(w)),options:[...dt,...g]}),control:G,name:"groupBy"})),e.createElement(Xt.U,{collapsible:!0,className:o.collapse,isOpen:c,label:"Timing options",onToggle:u},e.createElement("div",{className:o.timingFormContainer},e.createElement(U.g,{label:"Group wait",description:"The waiting time until the initial notification is sent for a new group created by an incoming alert. Default 30 seconds.",invalid:!!D.groupWaitValue,error:D.groupWaitValue?.message,"data-testid":"am-group-wait"},e.createElement(ce,{...h("groupWaitValue",{validate:de}),placeholder:Ae.group_wait,className:o.promDurationInput,"aria-label":"Group wait"})),e.createElement(U.g,{label:"Group interval",description:"The waiting time to send a batch of new alerts for that group after the first notification was sent. Default 5 minutes.",invalid:!!D.groupIntervalValue,error:D.groupIntervalValue?.message,"data-testid":"am-group-interval"},e.createElement(ce,{...h("groupIntervalValue",{validate:de}),placeholder:Ae.group_interval,className:o.promDurationInput,"aria-label":"Group interval"})),e.createElement(U.g,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent. Default 4 hours.",invalid:!!D.repeatIntervalValue,error:D.repeatIntervalValue?.message,"data-testid":"am-repeat-interval"},e.createElement(ce,{...h("repeatIntervalValue",{validate:de}),placeholder:Ae.repeat_interval,className:o.promDurationInput,"aria-label":"Repeat interval"})))),e.createElement("div",{className:o.container},t)))};var sn=n(70132),Ze=n(8944),yt=n(29614),bt=n(23403);function cn(){const t=(0,bt.k)("notification"),[a]=(0,yt.k)(t),r=(0,j._)(l=>l.amConfigs);return(0,e.useMemo)(()=>{const{result:l}=a&&r[a]||se.oq;return(l?.alertmanager_config??{})?.mute_time_intervals?.map(c=>({value:c.name,label:c.name,description:c.time_intervals.map(u=>(0,x.uK)(u)).join(", AND ")}))??[]},[a,r])}var mn=n(2390);const Ct=({actionButtons:t,receivers:a,route:r,onSubmit:l,defaults:m})=>{const o=(0,p.wW)(dn),c=(0,p.wW)(ht),[u,g]=(0,e.useState)(Et(r?.group_by)),v=cn(),b=[{name:"",operator:K._M.equal,value:""}],h=a.sort(un),G={...je(r),...m},D={...G,object_matchers:r?G.object_matchers:b};return e.createElement(it.l,{defaultValues:D,onSubmit:l,maxWidth:"none"},({control:E,register:M,errors:F,setValue:_,watch:w})=>e.createElement(e.Fragment,null,e.createElement("input",{type:"hidden",...M("id")}),e.createElement(sn.F,{name:"object_matchers",control:E},({fields:N,append:V,remove:O})=>e.createElement(e.Fragment,null,e.createElement(d.Stack,{direction:"column",alignItems:"flex-start"},e.createElement("div",null,"Matching labels"),N.length===0&&e.createElement(he.C,{color:"orange",className:o.noMatchersWarning,icon:"exclamation-triangle",text:"If no matchers are specified, this notification policy will handle all alert instances."}),N.length>0&&e.createElement("div",{className:o.matchersContainer},N.map(($,A)=>e.createElement(d.Stack,{direction:"row",key:$.id,alignItems:"center"},e.createElement(U.g,{label:"Label",invalid:!!F.object_matchers?.[A]?.name,error:F.object_matchers?.[A]?.name?.message},e.createElement(Oe.I,{...M(`object_matchers.${A}.name`,{required:"Field is required"}),defaultValue:$.name,placeholder:"label",autoFocus:!0})),e.createElement(U.g,{label:"Operator"},e.createElement(ue.g,{render:({field:{onChange:le,ref:ge,...We}})=>e.createElement(ie.Ph,{...We,className:o.matchersOperator,onChange:Me=>le(Me?.value),options:x.tA,"aria-label":"Operator"}),defaultValue:$.operator,control:E,name:`object_matchers.${A}.operator`,rules:{required:{value:!0,message:"Required."}}})),e.createElement(U.g,{label:"Value",invalid:!!F.object_matchers?.[A]?.value,error:F.object_matchers?.[A]?.value?.message},e.createElement(Oe.I,{...M(`object_matchers.${A}.value`,{required:"Field is required"}),defaultValue:$.value,placeholder:"value"})),e.createElement(me.h,{type:"button",tooltip:"Remove matcher",name:"trash-alt",onClick:()=>O(A)},"Remove")))),e.createElement(z.zx,{className:o.addMatcherBtn,icon:"plus",onClick:()=>V(an),variant:"secondary",type:"button"},"Add matcher")))),e.createElement(U.g,{label:"Contact point"},e.createElement(ue.g,{render:({field:{onChange:N,ref:V,...O}})=>e.createElement(ie.Ph,{"aria-label":"Contact point",...O,className:c.input,onChange:$=>N(vt($)),options:h,isClearable:!0}),control:E,name:"receiver"})),e.createElement(U.g,{label:"Continue matching subsequent sibling nodes"},e.createElement(Ze.r,{id:"continue-toggle",...M("continue")})),e.createElement(U.g,{label:"Override grouping"},e.createElement(Ze.r,{id:"override-grouping-toggle",...M("overrideGrouping")})),w().overrideGrouping&&e.createElement(U.g,{label:"Group by",description:"Group alerts when you receive a notification based on labels. If empty it will be inherited from the parent policy."},e.createElement(ue.g,{render:({field:{onChange:N,ref:V,...O}})=>e.createElement(ie.NU,{"aria-label":"Group by",...O,allowCustomValue:!0,className:c.input,onCreateOption:$=>{g(A=>[...A,ke($)]),_("groupBy",[...O.value,$])},onChange:$=>N(Qe($)),options:[...dt,...u]}),control:E,name:"groupBy"})),e.createElement(U.g,{label:"Override general timings"},e.createElement(Ze.r,{id:"override-timings-toggle",...M("overrideTimings")})),w().overrideTimings&&e.createElement(e.Fragment,null,e.createElement(U.g,{label:"Group wait",description:"The waiting time until the initial notification is sent for a new group created by an incoming alert. If empty it will be inherited from the parent policy.",invalid:!!F.groupWaitValue,error:F.groupWaitValue?.message},e.createElement(ce,{...M("groupWaitValue",{validate:de}),"aria-label":"Group wait value",className:c.promDurationInput})),e.createElement(U.g,{label:"Group interval",description:"The waiting time to send a batch of new alerts for that group after the first notification was sent. If empty it will be inherited from the parent policy.",invalid:!!F.groupIntervalValue,error:F.groupIntervalValue?.message},e.createElement(ce,{...M("groupIntervalValue",{validate:de}),"aria-label":"Group interval value",className:c.promDurationInput})),e.createElement(U.g,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent.",invalid:!!F.repeatIntervalValue,error:F.repeatIntervalValue?.message},e.createElement(ce,{...M("repeatIntervalValue",{validate:de}),"aria-label":"Repeat interval value",className:c.promDurationInput}))),e.createElement(U.g,{label:"Mute timings","data-testid":"am-mute-timing-select",description:"Add mute timing to policy",invalid:!!F.muteTimeIntervals},e.createElement(ue.g,{render:({field:{onChange:N,ref:V,...O}})=>e.createElement(ie.NU,{"aria-label":"Mute timings",...O,className:c.input,onChange:$=>N(Qe($)),options:v}),control:E,name:"muteTimeIntervals"})),t))};function un(t){return t.grafanaAppReceiverType===mn.W.OnCall?-1:0}const dn=t=>{const a=t.spacing(3.5);return{addMatcherBtn:s.css`
      margin-bottom: ${a};
    `,matchersContainer:s.css`
      background-color: ${t.colors.background.secondary};
      padding: ${t.spacing(1.5)} ${t.spacing(2)};
      padding-bottom: 0;
      width: fit-content;
    `,matchersOperator:s.css`
      min-width: 120px;
    `,noMatchersWarning:s.css`
      padding: ${t.spacing(1)} ${t.spacing(2)};
    `}};var At=n(3385);const Mt=({matchers:t})=>{const a=(0,p.wW)(Tt),r=5,l=(0,i.take)(t,r),m=(0,i.takeRight)(t,t.length-r),o=m.length>0;return e.createElement("span",{"data-testid":"label-matchers"},e.createElement(d.Stack,{direction:"row",gap:1,alignItems:"center"},l.map(c=>e.createElement(Pt,{key:(0,i.uniqueId)(),matcher:c})),o&&e.createElement(ye.z,{arrow:!0,placement:"top",content:e.createElement(e.Fragment,null,m.map(c=>e.createElement(Pt,{key:(0,i.uniqueId)(),matcher:c})))},e.createElement("span",null,e.createElement("div",{className:a.metadata},`and ${m.length} more`)))))},Pt=({matcher:[t,a,r]})=>{const l=(0,p.wW)(Tt);return e.createElement("div",{className:l.matcher(t).wrapper},e.createElement(d.Stack,{direction:"row",gap:0,alignItems:"baseline"},t," ",a," ",r))},Tt=t=>({matcher:a=>{const{color:r,borderColor:l}=(0,At.Bx)(a);return{wrapper:s.css`
        color: #fff;
        background: ${r};
        padding: ${t.spacing(.33)} ${t.spacing(.66)};
        font-size: ${t.typography.bodySmall.fontSize};

        border: solid 1px ${l};
        border-radius: ${t.shape.borderRadius(2)};
      `}},metadata:s.css`
    color: ${t.colors.text.secondary};

    font-size: ${t.typography.bodySmall.fontSize};
    font-weight: ${t.typography.bodySmall.fontWeight};
  `}),gn=(t=[],a,r)=>{const[l,m]=(0,e.useState)(!1),[o,c]=(0,e.useState)(),u=(0,st.Kt)(t),g=(0,e.useCallback)(()=>{c(void 0),m(!1)},[]),v=(0,e.useCallback)(h=>{c(h),m(!0)},[]);return[(0,e.useMemo)(()=>r?e.createElement(He,{isOpen:l}):e.createElement(ne.u,{isOpen:l,onDismiss:g,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Add notification policy"},e.createElement(Ct,{receivers:u,defaults:{groupBy:o?.group_by},onSubmit:h=>o&&a(h,o),actionButtons:e.createElement(ne.u.ButtonRow,null,e.createElement(z.zx,{type:"submit"},"Add policy"),e.createElement(z.zx,{type:"button",variant:"secondary",onClick:g},"Cancel"))})),[u,a,g,r,o,l]),v,g]},pn=(t,a,r,l)=>{const[m,o]=(0,e.useState)(!1),[c,u]=(0,e.useState)(!1),[g,v]=(0,e.useState)(),b=(0,st.Kt)(a),h=(0,e.useCallback)(()=>{v(void 0),o(!1)},[]),G=(0,e.useCallback)((E,M)=>{u(M??!1),v(E),o(!0)},[]);return[(0,e.useMemo)(()=>l?e.createElement(He,{isOpen:m}):e.createElement(ne.u,{isOpen:m,onDismiss:h,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Edit notification policy"},c&&g&&e.createElement(ln,{alertManagerSourceName:t,onSubmit:r,receivers:b,route:g,actionButtons:e.createElement(ne.u.ButtonRow,null,e.createElement(z.zx,{type:"submit"},"Update default policy"),e.createElement(z.zx,{type:"button",variant:"secondary",onClick:h},"Cancel"))}),!c&&e.createElement(Ct,{receivers:b,route:g,onSubmit:r,actionButtons:e.createElement(ne.u.ButtonRow,null,e.createElement(z.zx,{type:"submit"},"Update policy"),e.createElement(z.zx,{type:"button",variant:"secondary",onClick:h},"Cancel"))})),[b,t,h,r,c,l,g,m]),G,h]},En=(t,a)=>{const[r,l]=(0,e.useState)(!1),[m,o]=(0,e.useState)(),c=(0,e.useCallback)(()=>{o(void 0),l(!1)},[o]),u=(0,e.useCallback)(b=>{o(b),l(!0)},[]),g=(0,e.useCallback)(()=>{m&&t(m)},[t,m]);return[(0,e.useMemo)(()=>a?e.createElement(He,{isOpen:r}):e.createElement(ne.u,{isOpen:r,onDismiss:c,closeOnBackdropClick:!0,closeOnEscape:!0,title:"Delete notification policy"},e.createElement("p",null,"Deleting this notification policy will permanently remove it."),e.createElement("p",null,"Are you sure you want to delete this policy?"),e.createElement(ne.u.ButtonRow,null,e.createElement(z.zx,{type:"button",variant:"destructive",onClick:g},"Yes, delete policy"),e.createElement(z.zx,{type:"button",variant:"secondary",onClick:c},"Cancel"))),[c,g,a,r]),u,c]},vn=()=>{const[t,a]=(0,e.useState)(!1),[r,l]=(0,e.useState)([]),[m,o]=(0,e.useState)([]),c=(0,e.useCallback)(()=>{a(!1),l([]),o([])},[]),u=(0,e.useCallback)((b,h)=>{l(b),o(h),a(!0)},[]),g=(0,e.useMemo)(()=>{const b=r.flatMap(h=>h.alerts);return(0,i.groupBy)(b,h=>h.status.state)},[r]);return[(0,e.useMemo)(()=>e.createElement(ne.u,{isOpen:t,onDismiss:c,closeOnBackdropClick:!0,closeOnEscape:!0,title:e.createElement(d.Stack,{direction:"row",alignItems:"center",gap:1,flexGrow:1},e.createElement(d.Stack,{direction:"row",alignItems:"center",gap:.5},e.createElement(re.J,{name:"x"})," Matchers"),e.createElement(Mt,{matchers:m}))},e.createElement(d.Stack,{direction:"column"},e.createElement(Yt,{active:g[K.Z9.Active]?.length,suppressed:g[K.Z9.Suppressed]?.length,unprocessed:g[K.Z9.Unprocessed]?.length}),e.createElement("div",null,r.map((b,h)=>e.createElement(Ht.y,{key:h,alertManagerSourceName:"",group:b})))),e.createElement(ne.u.ButtonRow,null,e.createElement(z.zx,{type:"button",variant:"secondary",onClick:c},"Cancel"))),[r,c,g,m,t]),u,c]},He=({isOpen:t})=>e.createElement(ne.u,{isOpen:t,onDismiss:()=>{},closeOnBackdropClick:!1,closeOnEscape:!1,title:e.createElement(d.Stack,{direction:"row",alignItems:"center",gap:.5},"Updating... ",e.createElement(Zt.$,{inline:!0}))},"Please wait while we update your notification policies.");var fn=n(37802),xe=n(16144),hn=n(71698),Re=n(38484),It=n(77582),yn=n(27050);const bn={[K._M.equal]:(t,a)=>t===a,[K._M.notEqual]:(t,a)=>t!==a,[K._M.regex]:(t,a)=>Boolean(t.match(new RegExp(a))),[K._M.notRegex]:(t,a)=>!Boolean(t.match(new RegExp(a)))};function Cn(t,a){const[r,l]=a,[m,o,c]=t;if(r!==m)return!1;const u=bn[o];if(!u)throw new Error(`no such operator: ${o}`);return u(l,c)}function An(t,a){return t.every(r=>a.some(l=>Cn(r,l)))}function Ot(t,a){let r=[];const l=De(t);if(!An(l,a))return[];if(t.routes)for(let m=0;m<t.routes.length;m++){let o=t.routes[m],c=Ot(o,a);if(r=r.concat(c),c.length&&!o.continue)break}return r.length===0&&r.push(t),r}function Mn(t,a,r){const l=[];return r.reduce((m,o)=>{const c=o.alerts.filter(u=>{const g=Object.entries(u.labels);return Ot(t,g).some(v=>v===a)});return c.length&&m.push({...o,alerts:c}),m},l)}const Je=({label:t,value:a,icon:r})=>{const l=(0,p.wW)(Pn);return e.createElement("div",{className:l.meta().wrapper},e.createElement(d.Stack,{direction:"row",gap:0,alignItems:"stretch"},e.createElement("div",{className:l.meta().label},e.createElement(d.Stack,{direction:"row",gap:.5,alignItems:"center"},r&&e.createElement(re.J,{name:r})," ",t??"")),e.createElement("div",{className:l.meta().value},a)))},Pn=t=>({meta:a=>({wrapper:s.css`
      font-size: ${t.typography.bodySmall.fontSize};
    `,label:s.css`
      display: flex;
      align-items: center;

      padding: ${t.spacing(.33)} ${t.spacing(1)};
      background: ${t.colors.secondary.transparent};

      border: solid 1px ${t.colors.border.medium};
      border-top-left-radius: ${t.shape.borderRadius(2)};
      border-bottom-left-radius: ${t.shape.borderRadius(2)};
    `,value:s.css`
      padding: ${t.spacing(.33)} ${t.spacing(1)};
      font-weight: ${t.typography.fontWeightBold};

      border: solid 1px ${t.colors.border.medium};
      border-left: none;
      border-top-right-radius: ${t.shape.borderRadius(2)};
      border-bottom-right-radius: ${t.shape.borderRadius(2)};
    `})});var Tn=n(9085),In=n.n(Tn);const oe=({children:t,icon:a,...r})=>{const l=(0,p.wW)(On),m=typeof r.onClick=="function";return e.createElement("div",{className:In()({[l.metaText]:!0,[l.interactive]:m}),...r},e.createElement(d.Stack,{direction:"row",alignItems:"center",gap:.5},a&&e.createElement(re.J,{name:a}),t))},On=t=>({metaText:s.css`
    font-size: ${t.typography.bodySmall.fontSize};
    color: ${t.colors.text.secondary};
  `,interactive:s.css`
    cursor: pointer;

    &:hover {
      color: ${t.colors.text.primary};
    }
  `}),ee=({children:t})=>{const a=(0,p.l4)();return e.createElement("strong",{style:{color:a.colors.text.maxContrast}},t)},St=({receivers:t=[],contactPointsState:a,readOnly:r=!1,alertGroups:l=[],alertManagerSourceName:m,currentRoute:o,routeTree:c,inheritedProperties:u,routesMatchingFilters:g=[],onEditPolicy:v,onAddPolicy:b,onDeletePolicy:h,onShowAlertInstances:G})=>{const D=(0,p.wW)($e),E=o===c,M=(0,fn.Qb)(yn.v.NotificationPoliciesV2MatchingInstances),F=(0,te.Ko)(m),_=It.Vt.hasPermission(F.update),w=It.Vt.hasPermission(F.delete),N=o.receiver,V=o.continue??!1,O=o.group_by??[],$=o.mute_time_intervals??[],A={group_wait:o.group_wait,group_interval:o.group_interval,repeat_interval:o.repeat_interval},le=De(o),ge=Boolean(le&&le.length),We=Boolean($.length),Me=g.some(ae=>ae.id===o.id),Pe=[],Ye=!ge&&!E&&!V,Xe=N??u?.receiver??"";(a?Nn(Xe,a):[]).forEach(ae=>{Pe.push(ae)});const qe=o.routes??[],we=Array.isArray(O)&&O.length>0,_e=u&&Object.keys(u).length>0,et=_,tt=w&&!E,Ge=(0,e.useMemo)(()=>M?Mn(c,o,l):[],[l,o,c,M]),Ne=(0,i.sumBy)(Ge,ae=>ae.alerts.length);return e.createElement(d.Stack,{direction:"column",gap:1.5},e.createElement("div",{className:D.policyWrapper(Me),"data-testid":E?"am-root-route-container":"am-route-container"},V&&e.createElement(Dn,null),Ye&&e.createElement(xn,null),e.createElement(d.Stack,{direction:"column",gap:0},e.createElement("div",{className:D.matchersRow},e.createElement(d.Stack,{direction:"row",alignItems:"center",gap:1},E?e.createElement(Rn,null):ge?e.createElement(Mt,{matchers:le??[]}):e.createElement("span",{className:D.metadata},"No matchers"),e.createElement(rt.L,null),Pe.length>0&&e.createElement(Sn,{errors:Pe}),!r&&e.createElement(d.Stack,{direction:"row",gap:.5},e.createElement(z.zx,{variant:"secondary",icon:"plus",size:"sm",onClick:()=>b(o),type:"button"},"New nested policy"),e.createElement(hn.L,{overlay:e.createElement(Re.v,null,e.createElement(Re.v.Item,{icon:"pen",disabled:!et,label:"Edit",onClick:()=>v(o,E)}),tt&&e.createElement(e.Fragment,null,e.createElement(Re.v.Divider,null),e.createElement(Re.v.Item,{destructive:!0,icon:"trash-alt",label:"Delete",onClick:()=>h(o)})))},e.createElement(z.zx,{variant:"secondary",size:"sm",icon:"ellipsis-h",type:"button","aria-label":"more-actions","data-testid":"more-actions"}))))),e.createElement("div",{className:D.metadataRow},e.createElement(d.Stack,{direction:"row",alignItems:"center",gap:1},M&&e.createElement(oe,{icon:"layers-alt",onClick:()=>{G(Ge,le)},"data-testid":"matching-instances"},e.createElement(ee,null,Ne),e.createElement("span",null,Se()("instance",Ne))),N&&e.createElement(oe,{icon:"at","data-testid":"contact-point"},e.createElement("span",null,"Delivered to"),e.createElement(Gn,{alertManagerSourceName:m,receivers:t,contactPoint:N})),we&&e.createElement(oe,{icon:"layer-group","data-testid":"grouping"},e.createElement("span",null,"Grouped by"),e.createElement(ee,null,O.join(", "))),!we&&E&&e.createElement(oe,{icon:"layer-group"},e.createElement("span",null,"Not grouping")),We&&e.createElement(oe,{icon:"calendar-slash","data-testid":"mute-timings"},e.createElement("span",null,"Muted when"),e.createElement(Wn,{timings:$,alertManagerSourceName:m})),A&&Object.values(A).some(Boolean)&&e.createElement(Bn,{timingOptions:A}),_e&&e.createElement(e.Fragment,null,e.createElement(oe,{icon:"corner-down-right-alt","data-testid":"inherited-properties"},e.createElement("span",null,"Inherited"),e.createElement($n,{properties:u}))))))),e.createElement("div",{className:D.childPolicies},qe.map(ae=>{const nt=(0,i.pick)(o,["receiver","group_by","group_wait","group_interval","repeat_interval","mute_time_intervals"]),at=(0,i.merge)((0,i.reduce)(nt,(Le={},Te,Ue)=>(Te!==void 0&&ae[Ue]===void 0&&(Le[Ue]=Te),Le),{}),u);return e.createElement(St,{key:(0,i.uniqueId)(),routeTree:c,currentRoute:ae,receivers:t,contactPointsState:a,readOnly:r,inheritedProperties:at,onAddPolicy:b,onEditPolicy:v,onDeletePolicy:h,onShowAlertInstances:G,alertManagerSourceName:m,alertGroups:l,routesMatchingFilters:g})})))},Sn=({errors:t})=>e.createElement(ye.z,{arrow:!0,placement:"top",content:e.createElement(d.Stack,{direction:"column",gap:.5},t.map(a=>e.createElement(e.Fragment,{key:(0,i.uniqueId)()},a)))},e.createElement("span",null,e.createElement(he.C,{icon:"exclamation-circle",color:"red",text:Se()("error",t.length,!0)}))),Dn=()=>{const t=(0,p.wW)($e);return e.createElement(fe.u,{placement:"top",content:"This route will continue matching other policies"},e.createElement("div",{className:t.gutterIcon,"data-testid":"continue-matching"},e.createElement(re.J,{name:"arrow-down"})))},xn=()=>{const t=(0,p.wW)($e);return e.createElement(fe.u,{placement:"top",content:"This policy matches all labels"},e.createElement("div",{className:t.gutterIcon,"data-testid":"matches-all"},e.createElement(re.J,{name:"exclamation-triangle"})))},Rn=()=>{const t=(0,p.wW)($e);return e.createElement(e.Fragment,null,e.createElement("strong",null,"Default policy"),e.createElement("span",{className:t.metadata},"All alert instances will be handled by the default policy if no other matching policies are found."))},$n=({properties:t})=>e.createElement(ye.z,{arrow:!0,placement:"top",content:e.createElement(d.Stack,{direction:"row",gap:.5},Object.entries(t).map(([a,r])=>e.createElement(Je,{key:a,label:Ln(a),value:e.createElement(ee,null,Array.isArray(r)?r.join(", "):r)})))},e.createElement("div",null,e.createElement(ee,null,Se()("property",Object.keys(t).length,!0)))),Wn=({timings:t,alertManagerSourceName:a})=>e.createElement("div",null,e.createElement(ee,null,t.map(r=>e.createElement(xe.Link,{key:r,to:(0,Q.ET)(r,a)},r)))),Bn=({timingOptions:t})=>{const a=t.group_wait??Ae.group_wait,r=t.group_interval??Ae.group_interval;return e.createElement(oe,{icon:"hourglass","data-testid":"timing-options"},e.createElement("span",null,"Wait"),e.createElement(fe.u,{placement:"top",content:"How long to initially wait to send a notification for a group of alert instances."},e.createElement("span",null,e.createElement(ee,null,a)," ",e.createElement("span",null,"to group instances"),",")),e.createElement(fe.u,{placement:"top",content:"How long to wait before sending a notification about new alerts that are added to a group of alerts for which an initial notification has already been sent."},e.createElement("span",null,e.createElement(ee,null,r)," ",e.createElement("span",null,"before sending updates"))))},wn={discord:"discord",email:"envelope",googlechat:"google-hangouts-alt",hipchat:"hipchat",line:"line",pagerduty:"pagerduty",slack:"slack",teams:"microsoft",telegram:"telegram-alt"},Gn=({alertManagerSourceName:t,contactPoint:a,receivers:r})=>{const l=r.find(c=>c.name===a);if(!l)return e.createElement(xe.Link,{to:(0,Q.GV)(a,t)},e.createElement(ee,null,a));if(!l.grafana_managed_receiver_configs)return e.createElement(xe.Link,{to:(0,Q.GV)(a,t)},e.createElement(ee,null,a));const o=(0,i.groupBy)(l.grafana_managed_receiver_configs,c=>c.type);return e.createElement(ye.z,{arrow:!0,placement:"top",header:e.createElement(oe,{icon:"at"},e.createElement("div",null,"Contact Point"),e.createElement(ee,null,a)),key:(0,i.uniqueId)(),content:e.createElement(d.Stack,{direction:"row",gap:.5},Object.entries(o).map(([c,u])=>e.createElement(Je,{key:(0,i.uniqueId)(),label:u.length>1?u.length:void 0,icon:wn[c],value:(0,i.upperFirst)(c)})))},e.createElement(xe.Link,{to:(0,Q.GV)(a,t)},e.createElement(ee,null,a)))};function Nn(t,a){return Object.entries(a[t]?.notifiers??[]).reduce((m=[],[o,c])=>{const u=c.filter(g=>g.lastNotifyAttemptError).map(g=>e.createElement(Je,{icon:"at",key:(0,i.uniqueId)(),label:`Contact Point \u203A ${g.name}`,value:g.lastNotifyAttemptError}));return m.concat(u)},[])}const Ln=t=>{switch(t){case"receiver":return"Contact Point";case"group_by":return"Group by";case"group_interval":return"Group interval";case"group_wait":return"Group wait";case"mute_time_intervals":return"Mute timings";case"repeat_interval":return"Repeat interval"}},$e=t=>({matcher:a=>{const{color:r,borderColor:l}=(0,At.Bx)(a);return{wrapper:s.css`
        color: #fff;
        background: ${r};
        padding: ${t.spacing(.33)} ${t.spacing(.66)};
        font-size: ${t.typography.bodySmall.fontSize};

        border: solid 1px ${l};
        border-radius: ${t.shape.borderRadius(2)};
      `}},childPolicies:s.css`
    margin-left: ${t.spacing(4)};
    position: relative;

    &:before {
      content: '';
      position: absolute;
      height: calc(100% - 10px);

      border-left: solid 1px ${t.colors.border.weak};

      margin-top: 0;
      margin-left: -20px;
    }
  `,metadataRow:s.css`
    background: ${t.colors.background.primary};
    padding: ${t.spacing(1.5)};

    border-bottom-left-radius: ${t.shape.borderRadius(2)};
    border-bottom-right-radius: ${t.shape.borderRadius(2)};
  `,matchersRow:s.css`
    padding: ${t.spacing(1.5)};
    border-bottom: solid 1px ${t.colors.border.weak};
  `,policyWrapper:(a=!1)=>s.css`
    flex: 1;
    position: relative;
    background: ${t.colors.background.secondary};

    border-radius: ${t.shape.borderRadius(2)};
    border: solid 1px ${t.colors.border.weak};

    ${a&&s.css`
      border-color: ${t.colors.primary.border};
    `}
  `,metadata:s.css`
    color: ${t.colors.text.secondary};

    font-size: ${t.typography.bodySmall.fontSize};
    font-weight: ${t.typography.bodySmall.fontWeight};
  `,break:s.css`
    width: 100%;
    height: 0;
    margin-bottom: ${t.spacing(2)};
  `,addPolicyWrapper:a=>s.css`
    margin-top: -${t.spacing(a?1.5:2)};
    margin-bottom: ${t.spacing(1)};
  `,gutterIcon:s.css`
    position: absolute;

    top: 0;
    transform: translateY(50%);
    left: -${t.spacing(4)};

    color: ${t.colors.text.secondary};
    background: ${t.colors.background.primary};

    width: 25px;
    height: 25px;
    text-align: center;

    border: solid 1px ${t.colors.border.weak};
    border-radius: ${t.shape.borderRadius(2)};

    padding: 0;
  `});var Un=(t=>(t.NotificationPolicies="notification_policies",t.MuteTimings="mute_timings",t))(Un||{});const Fn=()=>{const t=(0,k.useDispatch)(),a=(0,p.wW)(Vn),[r,l]=(0,L.K)(),{tab:m}=zn(r),[o,c]=(0,e.useState)(m),[u,g]=(0,e.useState)(!1),[v,b]=(0,e.useState)(),[h,G]=(0,e.useState)([]),D=(0,bt.k)("notification"),[E,M]=(0,yt.k)(D),F=(0,j._)(Y=>Y.amConfigs),_=(0,B.V)(E??"");(0,e.useEffect)(()=>{E&&t((0,q.Yh)(E))},[E,t]);const{result:w,loading:N,error:V}=E&&F[E]||se.oq,O=w?.alertmanager_config,$=O?.receivers??[],A=(0,e.useMemo)(()=>{if(O?.route)return pt(O.route)},[O?.route]),le=(0,e.useMemo)(()=>A?Dt(A,{contactPointFilter:v,labelMatchersFilter:h}):[],[v,h,A]),ge=Boolean(O?.route?.provenance),Me=(0,j._)(Y=>Y.amAlertGroups)[E||""]??se.oq;function Pe(Y){if(!A)return;const Ie=qt(E??"",Y,A);Be(Ie)}function Ye(Y){if(!A)return;const Ie=_t(Y,A);Be(Ie)}function Xe(Y,Ie){if(!A)return;const Jn=en(E??"",Y,Ie,A);Be(Jn)}function Be(Y){w&&(g(!0),t((0,q.mM)({newConfig:{...w,alertmanager_config:{...w.alertmanager_config,route:Y}},oldConfig:w,alertManagerSourceName:E,successMessage:"Updated notification policies",refetch:!0})).unwrap().then(()=>{E&&t((0,q.mS)(E)),Ge(),_e(),nt()}).finally(()=>{g(!1)}))}const[qe,we,_e]=gn($,Xe,u),[et,tt,Ge]=pn(E??"",$,Pe,u),[Ne,ae,nt]=En(Ye,u),[at,Le]=vn();if((0,I.x)(Y=>Y.unifiedAlerting.saveAMConfig=se.oq),(0,e.useEffect)(()=>{E&&t((0,q.mS)(E))},[E,t]),!E)return e.createElement(X.J,{pageId:"am-routes"},e.createElement(Fe.I,{availableAlertManagers:D}));const Te=(0,ct.RY)(E),Ue=Te||ge,Kn=Te,kn=w?.alertmanager_config.mute_time_intervals?.length??0,Qn=w&&!V&&!N,Zn=!w&&N,Hn=V&&!N,xt=o==="mute_timings",Rt=o==="notification_policies";return e.createElement(X.J,{pageId:"am-routes"},e.createElement(J.P,{current:E,onChange:M,dataSources:D}),e.createElement(P.J,null,e.createElement(f.O,{label:"Notification Policies",active:Rt,onChangeTab:()=>{c("notification_policies"),l({tab:"notification_policies"})}}),e.createElement(f.O,{label:"Mute Timings",active:xt,counter:kn,onChangeTab:()=>{c("mute_timings"),l({tab:"mute_timings"})}})),e.createElement(T.I,{className:a.tabContent},Zn&&e.createElement(S.u,{text:"Loading Alertmanager config..."}),Hn&&e.createElement(W.b,{severity:"error",title:"Error loading Alertmanager config"},V.message||"Unknown error."),Qn&&e.createElement(e.Fragment,null,Rt&&e.createElement(e.Fragment,null,e.createElement(pe.u,{currentAlertmanager:E}),ge&&e.createElement(Ee.Xq,{resource:Ee.Uv.RootNotificationPolicy}),e.createElement(d.Stack,{direction:"column",gap:1},A&&e.createElement(jt,{receivers:$,onChangeMatchers:G,onChangeReceiver:b}),A&&e.createElement(St,{receivers:$,routeTree:A,currentRoute:A,alertGroups:Me.result,contactPointsState:_.receivers,readOnly:Ue,alertManagerSourceName:E,onAddPolicy:we,onEditPolicy:tt,onDeletePolicy:ae,onShowAlertInstances:Le,routesMatchingFilters:le})),qe,et,Ne,at),xt&&e.createElement(Nt,{alertManagerSourceName:E,hideActions:Kn}))))},Dt=(t,a)=>{const{contactPointFilter:r,labelMatchersFilter:l=[]}=a;let m=[];const o=lt(t),c=r?ot(o,g=>g.receiver===r):void 0;c&&m.push(c);const u=l.length?ot(o,g=>{const v=De(g);return l.every(b=>v.some(h=>(0,i.isEqual)(b,h)))}):void 0;return u&&m.push(u),(0,i.intersectionBy)(...m,"id")},Vn=t=>({tabContent:s.css`
    margin-top: ${t.spacing(2)};
  `});function zn(t){let a="notification_policies";return t.tab==="notification_policies"&&(a="notification_policies"),t.tab==="mute_timings"&&(a="mute_timings"),{tab:a}}const jn=(0,R.Pf)(Fn,{style:"page"})},30173:(Z,C,n)=>{n.d(C,{h:()=>i});var s=n(29427);const i=s.C.injectEndpoints({endpoints:e=>({getAlertmanagerChoiceStatus:e.query({query:()=>({url:"/api/v1/ngalert"}),providesTags:["AlertmanagerChoice"]}),getExternalAlertmanagerConfig:e.query({query:()=>({url:"/api/v1/ngalert/admin_config"}),providesTags:["AlertmanagerChoice"]}),getExternalAlertmanagers:e.query({query:()=>({url:"/api/v1/ngalert/alertmanagers"}),transformResponse:d=>d.data}),saveExternalAlertmanagersConfig:e.mutation({query:d=>({url:"/api/v1/ngalert/admin_config",method:"POST",data:d}),invalidatesTags:["AlertmanagerChoice"]})})})},96678:(Z,C,n)=>{n.d(C,{V:()=>p});var s=n(37190),i=n(29427),e=n(644);const d=i.C.injectEndpoints({endpoints:P=>({contactPointsState:P.query({queryFn:async({amSourceName:f})=>{try{return{data:await(0,e.QE)(f)}}catch(T){return{error:T}}}})})}),p=P=>{const f={receivers:{},errorCount:0},{currentData:T}=d.useContactPointsStateQuery({amSourceName:P??""},{skip:!P,pollingInterval:s.m4});return T??f}},51981:(Z,C,n)=>{n.d(C,{q:()=>e});var s=n(68404),i=n(82002);const e=({actions:d,children:p,fallback:P=!0})=>d.some(f=>i.Vt.hasAccess(f,P))?s.createElement(s.Fragment,null,p):null},94762:(Z,C,n)=>{n.d(C,{F:()=>p});var s=n(9892),i=n(68404),e=n(72648),d=n(53731);const p=({renderExpandedContent:f,...T})=>{const S=(0,e.wW)(P);return i.createElement(d.t,{renderExpandedContent:f?(W,R,L)=>i.createElement(i.Fragment,null,R!==L.length-1&&i.createElement("div",{className:(0,s.cx)(S.contentGuideline,S.guideline)}),f(W,R,L)):void 0,renderPrefixHeader:()=>i.createElement("div",{className:S.relative},i.createElement("div",{className:(0,s.cx)(S.headerGuideline,S.guideline)})),renderPrefixCell:(W,R,L)=>i.createElement("div",{className:S.relative},i.createElement("div",{className:(0,s.cx)(S.topGuideline,S.guideline)}),R!==L.length-1&&i.createElement("div",{className:(0,s.cx)(S.bottomGuideline,S.guideline)})),...T})},P=f=>({relative:s.css`
    position: relative;
    height: 100%;
  `,guideline:s.css`
    left: -19px;
    border-left: 1px solid ${f.colors.border.medium};
    position: absolute;

    ${f.breakpoints.down("md")} {
      display: none;
    }
  `,topGuideline:s.css`
    width: 18px;
    border-bottom: 1px solid ${f.colors.border.medium};
    top: 0;
    bottom: 50%;
  `,bottomGuideline:s.css`
    top: 50%;
    bottom: 0;
  `,contentGuideline:s.css`
    top: 0;
    bottom: 0;
    left: -49px !important;
  `,headerGuideline:s.css`
    top: -25px;
    bottom: 0;
  `})},731:(Z,C,n)=>{n.d(C,{u:()=>T});var s=n(9892),i=n(68404),e=n(72648),d=n(45253),p=n(39031),P=n(30173),f=n(45849);function T({currentAlertmanager:W}){const R=(0,e.wW)(S),{useGetAlertmanagerChoiceStatusQuery:L}=P.h,{currentData:k}=L(),I=W===f.GC;if(!(k?.alertmanagersChoice&&[p.TE.External,p.TE.All].includes(k?.alertmanagersChoice))||!I)return null;const J=k.numExternalAlertmanagers>0;return k.alertmanagersChoice===p.TE.External?i.createElement(d.b,{title:"Grafana alerts are not delivered to Grafana Alertmanager"},"Grafana is configured to send alerts to external Alertmanagers only. Changing Grafana Alertmanager configuration will not affect delivery of your alerts.",i.createElement("div",{className:R.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):k.alertmanagersChoice===p.TE.All&&J?i.createElement(d.b,{title:"You have additional Alertmanagers to configure",severity:"warning"},"Ensure you make configuration changes in the correct Alertmanagers; both internal and external. Changing one will not affect the others.",i.createElement("div",{className:R.adminHint},"To change your Alertmanager setup, go to the Alerting Admin page. If you do not have access, contact your Administrator.")):null}const S=W=>({adminHint:s.css`
    font-size: ${W.typography.bodySmall.fontSize};
    font-weight: ${W.typography.bodySmall.fontWeight};
  `})},88331:(Z,C,n)=>{n.d(C,{I:()=>f});var s=n(68404),i=n(45253),e=n(29614),d=n(94984);const p=()=>s.createElement(i.b,{title:"No Alertmanager found",severity:"warning"},"We could not find any external Alertmanagers and you may not have access to the built-in Grafana Alertmanager."),P=()=>s.createElement(i.b,{title:"Selected Alertmanager not found. Select a different Alertmanager.",severity:"warning"},"Selected Alertmanager no longer exists or you may not have permission to access it."),f=({availableAlertManagers:T})=>{const[S,W]=(0,e.k)(T),R=T.length>0;return s.createElement("div",null,R?s.createElement(s.Fragment,null,s.createElement(d.P,{onChange:W,dataSources:T}),s.createElement(P,null)):s.createElement(p,null))}},40106:(Z,C,n)=>{n.d(C,{C0:()=>P,Uv:()=>d,Xq:()=>p});var s=n(68404),i=n(45253),e=n(19985),d=(f=>(f.ContactPoint="contact point",f.Template="template",f.MuteTiming="mute timing",f.AlertRule="alert rule",f.RootNotificationPolicy="root notification policy",f))(d||{});const p=({resource:f})=>s.createElement(i.b,{title:`This ${f} cannot be edited through the UI`,severity:"info"},"This ",f," has been provisioned, that means it was created by config. Please contact your server admin to update this ",f,"."),P=()=>s.createElement(e.C,{text:"Provisioned",color:"purple"})},94647:(Z,C,n)=>{n.d(C,{y:()=>ve});var s=n(9892),i=n(68404),e=n(72648),d=n(39031),p=n(52694),P=n(33950),f=n(37556),T=n(94762),S=n(90072),W=n(31403),R=n(82002),L=n(81168),k=n(97953),I=n(45849),B=n(10505),J=n(78543),X=n(51981);const pe=({alert:y,alertManagerSourceName:H})=>{const j=(0,e.wW)(Fe),q=(0,k.QX)(H),x=(0,I.HY)(H)?R.Vt.hasPermission(L.AccessControlAction.AlertingRuleRead):!0;return i.createElement(i.Fragment,null,i.createElement("div",{className:j.actionsRow},i.createElement(X.q,{actions:[q.update,q.create],fallback:R.Vt.isEditor},y.status.state===d.Z9.Suppressed&&i.createElement(W.Qj,{href:`${(0,B.eQ)("/alerting/silences",H)}&silenceIds=${y.status.silencedBy.join(",")}`,className:j.button,icon:"bell",size:"sm"},"Manage silences"),y.status.state===d.Z9.Active&&i.createElement(W.Qj,{href:(0,B.VN)(H,y.labels),className:j.button,icon:"bell-slash",size:"sm"},"Silence")),x&&y.generatorURL&&i.createElement(W.Qj,{className:j.button,href:y.generatorURL,icon:"chart-line",size:"sm"},"See source")),Object.entries(y.annotations).map(([Q,se])=>i.createElement(J.a,{key:Q,annotationKey:Q,value:se})),i.createElement("div",{className:j.receivers},"Receivers:"," ",y.receivers.map(({name:Q})=>Q).filter(Q=>!!Q).join(", ")))},Fe=y=>({button:s.css`
    & + & {
      margin-left: ${y.spacing(1)};
    }
  `,actionsRow:s.css`
    padding: ${y.spacing(2,0)} !important;
    border-bottom: 1px solid ${y.colors.border.medium};
  `,receivers:s.css`
    padding: ${y.spacing(1,0)};
  `}),Ee=({alerts:y,alertManagerSourceName:H})=>{const j=(0,e.wW)(z),q=(0,i.useMemo)(()=>[{id:"state",label:"State",renderCell:({data:x})=>i.createElement(i.Fragment,null,i.createElement(S.G,{state:x.status.state}),i.createElement("span",{className:j.duration},"for"," ",(0,f.vT)({start:new Date(x.startsAt),end:new Date(x.endsAt)}))),size:"220px"},{id:"labels",label:"Labels",renderCell:({data:{labels:x}})=>i.createElement(p.s,{labels:x}),size:1}],[j]),te=(0,i.useMemo)(()=>y.map(x=>({id:x.fingerprint,data:x})),[y]);return i.createElement("div",{className:j.tableWrapper,"data-testid":"alert-group-table"},i.createElement(T.F,{cols:q,items:te,isExpandable:!0,renderExpandedContent:({data:x})=>i.createElement(pe,{alert:x,alertManagerSourceName:H})}))},z=y=>({tableWrapper:s.css`
    margin-top: ${y.spacing(3)};
    ${y.breakpoints.up("md")} {
      margin-left: ${y.spacing(4.5)};
    }
  `,duration:s.css`
    margin-left: ${y.spacing(1)};
    font-size: ${y.typography.bodySmall.fontSize};
  `});var Ve=n(96308);const ve=({alertManagerSourceName:y,group:H})=>{const[j,q]=(0,i.useState)(!0),te=(0,e.wW)(me);return i.createElement("div",{className:te.wrapper},i.createElement("div",{className:te.header},i.createElement("div",{className:te.group,"data-testid":"alert-group"},i.createElement(P.U,{size:"sm",isCollapsed:j,onToggle:()=>q(!j),"data-testid":"alert-group-collapse-toggle"}),Object.keys(H.labels).length?i.createElement(p.s,{labels:H.labels}):i.createElement("span",null,"No grouping")),i.createElement(Ve.Z,{group:H})),!j&&i.createElement(Ee,{alertManagerSourceName:y,alerts:H.alerts}))},me=y=>({wrapper:s.css`
    & + & {
      margin-top: ${y.spacing(2)};
    }
  `,header:s.css`
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: ${y.spacing(1,1,1,0)};
    background-color: ${y.colors.background.secondary};
    width: 100%;
  `,group:s.css`
    display: flex;
    flex-direction: row;
    align-items: center;
  `,summary:s.css``,spanElement:s.css`
    margin-left: ${y.spacing(.5)};
  `,[d.Z9.Active]:s.css`
    color: ${y.colors.error.main};
  `,[d.Z9.Suppressed]:s.css`
    color: ${y.colors.primary.main};
  `,[d.Z9.Unprocessed]:s.css`
    color: ${y.colors.secondary.main};
  `})},52259:(Z,C,n)=>{n.d(C,{Kt:()=>L,HU:()=>k});var s=n(65583),i=n(54899),e=n(29427);const d=e.C.injectEndpoints({endpoints:I=>({getOnCallIntegrations:I.query({queryFn:async()=>({data:await p()}),providesTags:["AlertmanagerChoice"]})})});async function p(){try{return(await(0,s.n)((0,i.i)().fetch({url:"/api/plugin-proxy/grafana-oncall-app/api/internal/v1/alert_receive_channels/",showErrorAlert:!1,showSuccessAlert:!1}))).data.map(B=>B.integration_url)}catch{return[]}}const{useGetOnCallIntegrationsQuery:P}=d;var f=n(58509),T=n(2390);const S=(I,B)=>B.includes(I),W=(I,B)=>{if(!I.grafana_managed_receiver_configs)return!1;const J=I.grafana_managed_receiver_configs.length===1,X=S(I.grafana_managed_receiver_configs[0]?.settings?.url??"",B);return J&&X},R=()=>{const{installed:I}=(0,f.n)(T.W.OnCall),{data:B}=P(void 0,{skip:!I});return X=>{if(I&&W(X,B??[]))return T.W.OnCall}},L=I=>{const B=R(),J=X=>({label:X.name,value:X.name,grafanaAppReceiverType:B(X)});return I.map(J)},k=I=>{const B=R();return I.map(J=>({...J,grafanaAppReceiverType:B(J)}))}},90072:(Z,C,n)=>{n.d(C,{G:()=>p});var s=n(68404),i=n(39031),e=n(79453);const d={[i.Z9.Active]:"bad",[i.Z9.Unprocessed]:"neutral",[i.Z9.Suppressed]:"info"},p=({state:P})=>s.createElement(e.i,{state:d[P]},P)},29614:(Z,C,n)=>{n.d(C,{k:()=>f});var s=n(68404),i=n(96044),e=n(58379),d=n(37190),p=n(45849);function P(T){return(0,s.useCallback)(S=>T.map(R=>R.name).includes(S),[T])}function f(T){const[S,W]=(0,i.K)(),R=P(T),L=(0,s.useCallback)(B=>{R(B)&&(B===p.GC?(e.Z.delete(d.de),W({[d.c4]:null})):(e.Z.set(d.de,B),W({[d.c4]:B})))},[W,R]),k=S[d.c4];if(k&&typeof k=="string")return R(k)?[k,L]:[void 0,L];const I=e.Z.get(d.de);return I&&typeof I=="string"&&R(I)?(L(I),[I,L]):R(p.GC)?[p.GC,L]:[void 0,L]}},23403:(Z,C,n)=>{n.d(C,{k:()=>e});var s=n(68404),i=n(45849);function e(d){return(0,s.useMemo)(()=>(0,i.LE)(d),[d])}},58509:(Z,C,n)=>{n.d(C,{n:()=>e});var s=n(22350),i=n(13011);function e(d){const{loading:p,error:P,value:f}=(0,s.Z)(()=>(0,i.a)(d,{showErrorAlert:!1})),T=f&&!P&&!p,S=f?.enabled;return p&&!f?{loading:!0}:!T||!S?{loading:!1,installed:!1}:{loading:p,installed:!0,settings:f}}},31808:(Z,C,n)=>{n.d(C,{j:()=>d});var s=n(68404),i=n(70356),e=n(37932);function d(){const{search:p}=(0,i.TH)(),P=(0,s.useMemo)(()=>new URLSearchParams(p),[p]),f=(0,s.useCallback)((T,S)=>{e.E1.partial(T,S)},[]);return[P,f]}},2390:(Z,C,n)=>{n.d(C,{W:()=>s});var s=(i=>(i.Incident="grafana-incident-app",i.OnCall="grafana-oncall-app",i.MachineLearning="grafana-ml-app",i))(s||{})}}]);

//# sourceMappingURL=AlertAmRoutes.dcffce27c65b6066e1ee.js.map