"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9355],{89657:(F,P,a)=>{a.r(P),a.d(P,{default:()=>ce});var e=a(66111),p=a(56895),C=a(61744),g=a(45253),D=a(96044),I=a(27876),i=a(9892),h=a(66698),S=a(72648),R=a(13393),v=a(24799),f=a(46967),M=a(31403),N=a(29614),b=a(23403),K=a(69945),j=a(72004),k=a(20194),Y=a(10505),H=a(82897);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,o,d)=>t?t.split(",").map(r=>r.trim()).every(r=>r.split(":").every(o))||d:!0,L=t=>t?t.split(",").map(o=>o.trim()):void 0,w=t=>{const o=t.time_intervals.map(({times:d,weekdays:r,days_of_month:T,months:y,years:E})=>{const n={times:d.filter(({start_time:l,end_time:u})=>!!l&&!!u),weekdays:L(r)?.map(l=>l.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:o}};var z=a(46818),_=a(94984),q=a(45524),G=a(40106),ee=a(11543),Q=a(81764),te=a(8180);const ae=({intervalIndex:t})=>{const o=(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"},l=r.errors.time_intervals?.[t],u=l?.times?.some(s=>s?.start_time||s?.end_time)??!1;return e.createElement("div",null,e.createElement(v.g,{className:o.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:o.timeRange,key:s.id},e.createElement(ee.Z,null,e.createElement(Q._,{label:"Start time",invalid:!!l?.times?.[m]?.start_time},e.createElement(f.I,{...d(`time_intervals.${t}.times.${m}.start_time`,{validate:n}),className:o.timeRangeInput,defaultValue:s.start_time,placeholder:"HH:MM","data-testid":"mute-timing-starts-at"})),e.createElement(Q._,{label:"End time",invalid:!!l?.times?.[m]?.end_time},e.createElement(f.I,{...d(`time_intervals.${t}.times.${m}.end_time`,{validate:n}),className:o.timeRangeInput,defaultValue:s.end_time,placeholder:"HH:MM","data-testid":"mute-timing-ends-at"})),e.createElement(te.h,{className:o.deleteTimeRange,title:"Remove",name:"trash-alt",type:"button",onClick:c=>{c.preventDefault(),E(m)}})))))),e.createElement(M.zx,{className:o.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:o,register:d}=(0,h.Gc)(),{fields:r,append:T,remove:y}=(0,h.Dq)({name:"time_intervals"});return e.createElement(R.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 l=o.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:l.time_intervals?.[n]?.weekdays?.message??"",invalid:!!l.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:!!l.time_intervals?.[n]?.days_of_month,error:l.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:!!l.time_intervals?.[n]?.months,error:l.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:!!l.time_intervals?.[n]?.years,error:l.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 o={name:"",time_intervals:[O]};if(!t)return o;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"}]},oe=({muteTiming:t,showError:o,provenance:d})=>{const r=(0,I.useDispatch)(),T=(0,b.k)("notification"),[y,E]=(0,N.k)(T),n=(0,S.wW)(le),l={alertmanager_config:{},template_files:{}},u=(0,K._)(A=>A.amConfigs),{result:s=l,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"},o&&e.createElement(g.b,{title:"No matching mute timing found"}),e.createElement(R.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.zx,{type:"submit",className:n.submitButton},"Save mute timing"),e.createElement(M.Qj,{type:"button",variant:"secondary",href:(0,Y.eQ)("/alerting/routes/",y)},"Cancel")))))},le=t=>({input:i.css`
    width: 400px;
  `,submitButton:i.css`
    margin-right: ${t.spacing(1)};
  `}),x=oe,ce=()=>{const[t]=(0,D.K)(),o=(0,I.useDispatch)(),d=(0,b.k)("notification"),[r]=(0,N.k)(d),T=(0,K._)(m=>m.amConfigs),y=(0,e.useCallback)(()=>{r&&o((0,j.Yh)(r))},[r,o]);(0,e.useEffect)(()=>{y()},[y]);const{result:E,error:n,loading:l}=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,l&&e.createElement(C.u,{text:"Loading mute timing"}),n&&!l&&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"})})))}},40106:(F,P,a)=>{a.d(P,{C0:()=>I,Uv:()=>g,Xq:()=>D});var e=a(66111),p=a(45253),C=a(19985),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"})},29614:(F,P,a)=>{a.d(P,{k:()=>i});var e=a(66111),p=a(96044),C=a(58379),g=a(37190),D=a(45849);function I(h){return(0,e.useCallback)(S=>h.map(v=>v.name).includes(S),[h])}function i(h){const[S,R]=(0,p.K)(),v=I(h),f=(0,e.useCallback)(b=>{v(b)&&(b===D.GC?(C.Z.delete(g.de),R({[g.c4]:null})):(C.Z.set(g.de,b),R({[g.c4]:b})))},[R,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]}},23403:(F,P,a)=>{a.d(P,{k:()=>C});var e=a(66111),p=a(45849);function C(g){return(0,e.useMemo)(()=>(0,p.LE)(g),[g])}}}]);

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