"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9355],{27648:(F,P,a)=>{a.r(P),a.d(P,{default:()=>ce});var e=a(65237),p=a(60894),C=a(16693),g=a(88347),D=a(68532),I=a(3315),i=a(60234),h=a(89822),S=a(93048),b=a(37885),v=a(5263),f=a(96682),M=a(48389),N=a(14014),R=a(13697),K=a(57811),j=a(99997),k=a(25312),Y=a(78442),H=a(89949);const X=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],J=["january","february","march","april","may","june","july","august","september","october","november","december"],O={times:[{start_time:"",end_time:""}],weekdays:"",days_of_month:"",months:"",years:""},U=(t,l,d)=>t?t.split(",").map(r=>r.trim()).every(r=>r.split(":").every(l))||d:!0,L=t=>t?t.split(",").map(l=>l.trim()):void 0,w=t=>{const l=t.time_intervals.map(({times:d,weekdays:r,days_of_month:T,months:y,years:E})=>{const n={times:d.filter(({start_time:o,end_time:u})=>!!o&&!!u),weekdays:L(r)?.map(o=>o.toLowerCase()),days_of_month:L(T),months:L(y),years:L(E)};return(0,H.omitBy)(n,H.isUndefined)});return{name:t.name,time_intervals:l}};var z=a(84078),_=a(70755),q=a(58866),G=a(89745),ee=a(54805),Q=a(1163),te=a(67262);const ae=({intervalIndex:t})=>{const l=(0,S.wW)(ne),{register:d,formState:r}=(0,h.Gc)(),{fields:T,append:y,remove:E}=(0,h.Dq)({name:`time_intervals.${t}.times`}),n=s=>{if(!s)return!0;const[m,c]=s.split(":").map(A=>parseInt(A,10)),$=m>=0&&m<25,B=c>-1&&c<60;return(m===24?c===0:$&&B)||"Time is invalid"},o=r.errors.time_intervals?.[t],u=o?.times?.some(s=>s?.start_time||s?.end_time)??!1;return e.createElement("div",null,e.createElement(v.g,{className:l.field,label:"Time range",description:"The time inclusive of the starting time and exclusive of the end time in UTC",invalid:u,error:u?"Times must be between 00:00 and 24:00 UTC":""},e.createElement(e.Fragment,null,T.map((s,m)=>e.createElement("div",{className:l.timeRange,key:s.id},e.createElement(ee.Z,null,e.createElement(Q._,{label:"Start time",invalid:!!o?.times?.[m]?.start_time},e.createElement(f.I,{...d(`time_intervals.${t}.times.${m}.start_time`,{validate:n}),className:l.timeRangeInput,defaultValue:s.start_time,placeholder:"HH:MM","data-testid":"mute-timing-starts-at"})),e.createElement(Q._,{label:"End time",invalid:!!o?.times?.[m]?.end_time},e.createElement(f.I,{...d(`time_intervals.${t}.times.${m}.end_time`,{validate:n}),className:l.timeRangeInput,defaultValue:s.end_time,placeholder:"HH:MM","data-testid":"mute-timing-ends-at"})),e.createElement(te.h,{className:l.deleteTimeRange,title:"Remove",name:"trash-alt",type:"button",onClick:c=>{c.preventDefault(),E(m)}})))))),e.createElement(M.zx,{className:l.addTimeRange,variant:"secondary",type:"button",icon:"plus",onClick:()=>y({start_time:"",end_time:""})},"Add another time range"))},ne=t=>({field:i.css`
    margin-bottom: 0;
  `,timeRange:i.css`
    margin-bottom: ${t.spacing(1)};
  `,timeRangeInput:i.css`
    width: 120px;
  `,deleteTimeRange:i.css`
    margin: ${t.spacing(1)} 0 0 ${t.spacing(.5)};
  `,addTimeRange:i.css`
    margin-bottom: ${t.spacing(2)};
  `}),se=()=>{const t=(0,S.wW)(ie),{formState:l,register:d}=(0,h.Gc)(),{fields:r,append:T,remove:y}=(0,h.Dq)({name:"time_intervals"});return e.createElement(b.C,{className:t.timeIntervalLegend,label:"Time intervals"},e.createElement(e.Fragment,null,e.createElement("p",null,"A time interval is a definition for a moment in time. All fields are lists, and at least one list element must be satisfied to match the field. If a field is left blank, any moment of time will match the field. For an instant of time to match a complete time interval, all fields must match. A mute timing can contain multiple time intervals."),r.map((E,n)=>{const o=l.errors;return e.createElement("div",{key:E.id,className:t.timeIntervalSection},e.createElement(ae,{intervalIndex:n}),e.createElement(v.g,{label:"Days of the week",error:o.time_intervals?.[n]?.weekdays?.message??"",invalid:!!o.time_intervals?.[n]?.weekdays},e.createElement(f.I,{...d(`time_intervals.${n}.weekdays`,{validate:u=>U(u,s=>X.includes(s.toLowerCase()),"Invalid day of the week")}),className:t.input,"data-testid":"mute-timing-weekdays",defaultValue:E.weekdays,placeholder:"Example: monday, tuesday:thursday"})),e.createElement(v.g,{label:"Days of the month",description:"The days of the month, 1-31, of a month. Negative values can be used to represent days which begin at the end of the month",invalid:!!o.time_intervals?.[n]?.days_of_month,error:o.time_intervals?.[n]?.days_of_month?.message},e.createElement(f.I,{...d(`time_intervals.${n}.days_of_month`,{validate:u=>U(u,s=>{const m=parseInt(s,10);return m>-31&&m<0||m>0&&m<32},"Invalid day")}),className:t.input,defaultValue:E.days_of_month,placeholder:"Example: 1, 14:16, -1","data-testid":"mute-timing-days"})),e.createElement(v.g,{label:"Months",description:"The months of the year in either numerical or the full calendar month",invalid:!!o.time_intervals?.[n]?.months,error:o.time_intervals?.[n]?.months?.message},e.createElement(f.I,{...d(`time_intervals.${n}.months`,{validate:u=>U(u,s=>J.includes(s)||parseInt(s,10)<13&&parseInt(s,10)>0,"Invalid month")}),className:t.input,placeholder:"Example: 1:3, may:august, december",defaultValue:E.months,"data-testid":"mute-timing-months"})),e.createElement(v.g,{label:"Years",invalid:!!o.time_intervals?.[n]?.years,error:o.time_intervals?.[n]?.years?.message??""},e.createElement(f.I,{...d(`time_intervals.${n}.years`,{validate:u=>U(u,s=>/^\d{4}$/.test(s),"Invalid year")}),className:t.input,placeholder:"Example: 2021:2022, 2030",defaultValue:E.years,"data-testid":"mute-timing-years"})),e.createElement(M.zx,{type:"button",variant:"destructive",icon:"trash-alt",onClick:()=>y(n)},"Remove time interval"))}),e.createElement(M.zx,{type:"button",variant:"secondary",className:t.removeTimeIntervalButton,onClick:()=>{T(O)},icon:"plus"},"Add another time interval")))},ie=t=>({input:i.css`
    width: 400px;
  `,timeIntervalLegend:i.css`
    legend {
      font-size: 1.25rem;
    }
  `,timeIntervalSection:i.css`
    background-color: ${t.colors.background.secondary};
    padding: ${t.spacing(1)};
    margin-bottom: ${t.spacing(1)};
  `,removeTimeIntervalButton:i.css`
    margin-top: ${t.spacing(1)};
  `}),re=t=>(0,e.useMemo)(()=>{const l={name:"",time_intervals:[O]};if(!t)return l;const d=t.time_intervals.map(r=>({times:r.times??O.times,weekdays:r?.weekdays?.join(", ")??O.weekdays,days_of_month:r?.days_of_month?.join(", ")??O.days_of_month,months:r?.months?.join(", ")??O.months,years:r?.years?.join(", ")??O.years}));return{name:t.name,time_intervals:d}},[t]),me={icon:"sitemap",breadcrumbs:[{title:"Notification Policies",url:"alerting/routes"}]},le=({muteTiming:t,showError:l,provenance:d})=>{const r=(0,I.useDispatch)(),T=(0,R.k)("notification"),[y,E]=(0,N.k)(T),n=(0,S.wW)(oe),o={alertmanager_config:{},template_files:{}},u=(0,K._)(A=>A.amConfigs),{result:s=o,loading:m}=y&&u[y]||z.oq,c=s?.alertmanager_config??{},$=re(t),B=(0,h.cI)({defaultValues:$}),Z=A=>{const W=w(A),V=t?c?.mute_time_intervals?.filter(({name:ue})=>ue!==t.name):c.mute_time_intervals,de={...s,alertmanager_config:{...c,route:t&&W.name!==t.name?(0,k.FM)(W.name,t.name,c.route??{}):c.route,mute_time_intervals:[...V||[],W]}};r((0,j.mM)({newConfig:de,oldConfig:s,alertManagerSourceName:y,successMessage:"Mute timing saved",redirectPath:"/alerting/routes/"}))};return e.createElement(q.J,{pageId:"am-routes",pageNav:{...me,id:t?"alert-policy-edit":"alert-policy-new",text:t?"Edit mute timing":"Add mute timing"}},e.createElement(_.P,{current:y,onChange:E,disabled:!0,dataSources:T}),d&&e.createElement(G.Xq,{resource:G.Uv.MuteTiming}),s&&!m&&e.createElement(h.RV,{...B},e.createElement("form",{onSubmit:B.handleSubmit(Z),"data-testid":"mute-timing-form"},l&&e.createElement(g.b,{title:"No matching mute timing found"}),e.createElement(b.C,{label:"Create mute timing",disabled:Boolean(d)},e.createElement(v.g,{required:!0,label:"Name",description:"A unique name for the mute timing",invalid:!!B.formState.errors?.name,error:B.formState.errors.name?.message},e.createElement(f.I,{...B.register("name",{required:!0,validate:A=>t?A.length>0||"Name is required":c?.mute_time_intervals?.find(({name:V})=>A===V)?`Mute timing already exists for "${A}"`:!0}),className:n.input,"data-testid":"mute-timing-name"})),e.createElement(se,null),e.createElement(M.Qj,{type:"button",variant:"secondary",href:(0,Y.eQ)("/alerting/routes/",y)},"Cancel"),e.createElement(M.zx,{type:"submit",className:n.submitButton},t?"Save":"Submit")))))},oe=t=>({input:i.css`
    width: 400px;
  `,submitButton:i.css`
    margin-left: ${t.spacing(1)};
  `}),x=le,ce=()=>{const[t]=(0,D.K)(),l=(0,I.useDispatch)(),d=(0,R.k)("notification"),[r]=(0,N.k)(d),T=(0,K._)(m=>m.amConfigs),y=(0,e.useCallback)(()=>{r&&l((0,j.Yh)(r))},[r,l]);(0,e.useEffect)(()=>{y()},[y]);const{result:E,error:n,loading:o}=r&&T[r]||z.oq,u=E?.alertmanager_config,s=(0,e.useCallback)(m=>{const c=u?.mute_time_intervals?.find(({name:$})=>$===m);if(c){const $=(u?.muteTimeProvenances??{})[c.name];return{...c,provenance:$}}return c},[u]);return e.createElement(e.Fragment,null,o&&e.createElement(C.u,{text:"Loading mute timing"}),n&&!o&&e.createElement(g.b,{severity:"error",title:`Error loading Alertmanager config for ${r}`},n.message||"Unknown error."),E&&!n&&e.createElement(p.rs,null,e.createElement(p.AW,{exact:!0,path:"/alerting/routes/mute-timing/new"},e.createElement(x,null)),e.createElement(p.AW,{exact:!0,path:"/alerting/routes/mute-timing/edit"},()=>{if(t.muteName){const m=s(String(t.muteName)),c=m?.provenance;return e.createElement(x,{muteTiming:m,showError:!m,provenance:c})}return e.createElement(p.l_,{to:"/alerting/routes"})})))}},89745:(F,P,a)=>{a.d(P,{C0:()=>I,Uv:()=>g,Xq:()=>D});var e=a(65237),p=a(88347),C=a(66434),g=(i=>(i.ContactPoint="contact point",i.Template="template",i.MuteTiming="mute timing",i.AlertRule="alert rule",i.RootNotificationPolicy="root notification policy",i))(g||{});const D=({resource:i})=>e.createElement(p.b,{title:`This ${i} cannot be edited through the UI`,severity:"info"},"This ",i," has been provisioned, that means it was created by config. Please contact your server admin to update this ",i,"."),I=()=>e.createElement(C.C,{text:"Provisioned",color:"purple"})},14014:(F,P,a)=>{a.d(P,{k:()=>i});var e=a(65237),p=a(68532),C=a(81453),g=a(98401),D=a(50328);function I(h){return(0,e.useCallback)(S=>h.map(v=>v.name).includes(S),[h])}function i(h){const[S,b]=(0,p.K)(),v=I(h),f=(0,e.useCallback)(R=>{v(R)&&(R===D.GC?(C.Z.delete(g.de),b({[g.c4]:null})):(C.Z.set(g.de,R),b({[g.c4]:R})))},[b,v]),M=S[g.c4];if(M&&typeof M=="string")return v(M)?[M,f]:[void 0,f];const N=C.Z.get(g.de);return N&&typeof N=="string"&&v(N)?(f(N),[N,f]):v(D.GC)?[D.GC,f]:[void 0,f]}},13697:(F,P,a)=>{a.d(P,{k:()=>C});var e=a(65237),p=a(50328);function C(g){return(0,e.useMemo)(()=>(0,p.LE)(g),[g])}}}]);

//# sourceMappingURL=MuteTimings.b227d0c77cb4e1dc5d7e.js.map