"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9355],{56021:(e,t,n)=>{n.r(t),n.d(t,{default:()=>Z});var i=n(76687),a=n(63322),s=n(42384),l=n(35562),r=n(95609),o=n(352),d=n(77813),m=n(84734),u=n(27668),c=n(72660),v=n(45550),g=n(9120),h=n(55312),f=n(84362),p=n(97758),y=n(7566),_=n(68175),j=n(13698),x=n(5504),b=n(86832);const k=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],I=["january","february","march","april","may","june","july","august","september","october","november","december"],w={times:[{start_time:"",end_time:""}],weekdays:"",days_of_month:"",months:"",years:""},C=(e,t,n)=>!e||(e.split(",").map((e=>e.trim())).every((e=>e.split(":").every(t)))||n),N=e=>e?e.split(",").map((e=>e.trim())):void 0;var T=n(27121),$=n(87925),M=n(80030),R=n(78391),S=n(23277),O=n(50385),q=n(2338),A=n(52010);const E=e=>{var t,n,i;let{intervalIndex:a}=e;const s=(0,u.wW)(L),{register:l,formState:r}=(0,m.Gc)(),{fields:o,append:d,remove:c}=(0,m.Dq)({name:`time_intervals.${a}.times`}),f=e=>{if(!e)return!0;const[t,n]=e.split(":").map((e=>parseInt(e,10)));return(24===t?0===n:t>=0&&t<25&&(n>-1&&n<60))||"Time is invalid"},p=null===(t=r.errors.time_intervals)||void 0===t?void 0:t[a],y=null!==(n=null==p||null===(i=p.times)||void 0===i?void 0:i.some((e=>(null==e?void 0:e.start_time)||(null==e?void 0:e.end_time))))&&void 0!==n&&n;return(0,A.jsxs)("div",{children:[(0,A.jsx)(v.g,{className:s.field,label:"Time range",description:"The time inclusive of the starting time and exclusive of the end time in UTC",invalid:y,error:y?"Times must be between 00:00 and 24:00 UTC":"",children:(0,A.jsx)(A.Fragment,{children:o.map(((e,t)=>{var n,i,r,o;return(0,A.jsx)("div",{className:s.timeRange,children:(0,A.jsxs)(S.Z,{children:[(0,A.jsx)(O._,{label:"Start time",invalid:!(null==p||null===(n=p.times)||void 0===n||null===(i=n[t])||void 0===i||!i.start_time),children:(0,A.jsx)(g.I,Object.assign({},l(`time_intervals.${a}.times.${t}.start_time`,{validate:f}),{className:s.timeRangeInput,defaultValue:e.start_time,placeholder:"HH:MM","data-testid":"mute-timing-starts-at"}))}),(0,A.jsx)(O._,{label:"End time",invalid:!(null==p||null===(r=p.times)||void 0===r||null===(o=r[t])||void 0===o||!o.end_time),children:(0,A.jsx)(g.I,Object.assign({},l(`time_intervals.${a}.times.${t}.end_time`,{validate:f}),{className:s.timeRangeInput,defaultValue:e.end_time,placeholder:"HH:MM","data-testid":"mute-timing-ends-at"}))}),(0,A.jsx)(q.h,{className:s.deleteTimeRange,title:"Remove",name:"trash-alt",type:"button",onClick:e=>{e.preventDefault(),c(t)}})]})},e.id)}))})}),(0,A.jsx)(h.zx,{className:s.addTimeRange,variant:"secondary",type:"button",icon:"plus",onClick:()=>d({start_time:"",end_time:""}),children:"Add another time range"})]})},L=e=>({field:d.css`
    margin-bottom: 0;
  `,timeRange:d.css`
    margin-bottom: ${e.spacing(1)};
  `,timeRangeInput:d.css`
    width: 120px;
  `,deleteTimeRange:d.css`
    margin: ${e.spacing(1)} 0 0 ${e.spacing(.5)};
  `,addTimeRange:d.css`
    margin-bottom: ${e.spacing(2)};
  `});var V;const P=()=>{const e=(0,u.wW)(U),{formState:t,register:n}=(0,m.Gc)(),{fields:i,append:a,remove:s}=(0,m.Dq)({name:"time_intervals"});return(0,A.jsx)(c.C,{className:e.timeIntervalLegend,label:"Time intervals",children:(0,A.jsxs)(A.Fragment,{children:[V||(V=(0,A.jsx)("p",{children:"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."})),i.map(((i,a)=>{var l,r,o,d,m,u,c,f,p,y,_,j,x,b,w,N,T,$,M,R,S,O;const q=t.errors;return(0,A.jsxs)("div",{className:e.timeIntervalSection,children:[(0,A.jsx)(E,{intervalIndex:a}),(0,A.jsx)(v.g,{label:"Days of the week",error:null!==(l=null===(r=q.time_intervals)||void 0===r||null===(o=r[a])||void 0===o||null===(d=o.weekdays)||void 0===d?void 0:d.message)&&void 0!==l?l:"",invalid:!(null===(m=q.time_intervals)||void 0===m||null===(u=m[a])||void 0===u||!u.weekdays),children:(0,A.jsx)(g.I,Object.assign({},n(`time_intervals.${a}.weekdays`,{validate:e=>C(e,(e=>k.includes(e.toLowerCase())),"Invalid day of the week")}),{className:e.input,"data-testid":"mute-timing-weekdays",defaultValue:i.weekdays,placeholder:"Example: monday, tuesday:thursday"}))}),(0,A.jsx)(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:!(null===(c=q.time_intervals)||void 0===c||null===(f=c[a])||void 0===f||!f.days_of_month),error:null===(p=q.time_intervals)||void 0===p||null===(y=p[a])||void 0===y||null===(_=y.days_of_month)||void 0===_?void 0:_.message,children:(0,A.jsx)(g.I,Object.assign({},n(`time_intervals.${a}.days_of_month`,{validate:e=>C(e,(e=>{const t=parseInt(e,10);return t>-31&&t<0||t>0&&t<32}),"Invalid day")}),{className:e.input,defaultValue:i.days_of_month,placeholder:"Example: 1, 14:16, -1","data-testid":"mute-timing-days"}))}),(0,A.jsx)(v.g,{label:"Months",description:"The months of the year in either numerical or the full calendar month",invalid:!(null===(j=q.time_intervals)||void 0===j||null===(x=j[a])||void 0===x||!x.months),error:null===(b=q.time_intervals)||void 0===b||null===(w=b[a])||void 0===w||null===(N=w.months)||void 0===N?void 0:N.message,children:(0,A.jsx)(g.I,Object.assign({},n(`time_intervals.${a}.months`,{validate:e=>C(e,(e=>I.includes(e)||parseInt(e,10)<13&&parseInt(e,10)>0),"Invalid month")}),{className:e.input,placeholder:"Example: 1:3, may:august, december",defaultValue:i.months,"data-testid":"mute-timing-months"}))}),(0,A.jsx)(v.g,{label:"Years",invalid:!(null===(T=q.time_intervals)||void 0===T||null===($=T[a])||void 0===$||!$.years),error:null!==(M=null===(R=q.time_intervals)||void 0===R||null===(S=R[a])||void 0===S||null===(O=S.years)||void 0===O?void 0:O.message)&&void 0!==M?M:"",children:(0,A.jsx)(g.I,Object.assign({},n(`time_intervals.${a}.years`,{validate:e=>C(e,(e=>/^\d{4}$/.test(e)),"Invalid year")}),{className:e.input,placeholder:"Example: 2021:2022, 2030",defaultValue:i.years,"data-testid":"mute-timing-years"}))}),(0,A.jsx)(h.zx,{type:"button",variant:"destructive",icon:"trash-alt",onClick:()=>s(a),children:"Remove time interval"})]},i.id)})),(0,A.jsx)(h.zx,{type:"button",variant:"secondary",className:e.removeTimeIntervalButton,onClick:()=>{a(w)},icon:"plus",children:"Add another time interval"})]})})},U=e=>({input:d.css`
    width: 400px;
  `,timeIntervalLegend:d.css`
    legend {
      font-size: 1.25rem;
    }
  `,timeIntervalSection:d.css`
    background-color: ${e.colors.background.secondary};
    padding: ${e.spacing(1)};
    margin-bottom: ${e.spacing(1)};
  `,removeTimeIntervalButton:d.css`
    margin-top: ${e.spacing(1)};
  `});var B,z;const D=e=>({input:d.css`
    width: 400px;
  `,submitButton:d.css`
    margin-left: ${e.spacing(1)};
  `}),F=e=>{var t,n,a;let{muteTiming:s,showError:r,provenance:d}=e;const k=(0,o.I0)(),I=(0,p.k)("notification"),[C,S]=(0,f.k)(I),O=(0,u.wW)(D),q={alertmanager_config:{},template_files:{}},E=(0,y._)((e=>e.amConfigs)),{result:L=q,loading:V}=C&&E[C]||T.oq,U=null!==(t=null==L?void 0:L.alertmanager_config)&&void 0!==t?t:{},F=(e=>(0,i.useMemo)((()=>{if(!e)return{name:"",time_intervals:[w]};const t=e.time_intervals.map((e=>{var t,n,i,a,s,l,r,o,d;return{times:null!==(t=e.times)&&void 0!==t?t:w.times,weekdays:null!==(n=null==e||null===(i=e.weekdays)||void 0===i?void 0:i.join(", "))&&void 0!==n?n:w.weekdays,days_of_month:null!==(a=null==e||null===(s=e.days_of_month)||void 0===s?void 0:s.join(", "))&&void 0!==a?a:w.days_of_month,months:null!==(l=null==e||null===(r=e.months)||void 0===r?void 0:r.join(", "))&&void 0!==l?l:w.months,years:null!==(o=null==e||null===(d=e.years)||void 0===d?void 0:d.join(", "))&&void 0!==o?o:w.years}}));return{name:e.name,time_intervals:t}}),[e]))(s),G=(0,m.cI)({defaultValues:F});return(0,A.jsxs)(M.J,{pageId:"am-routes",children:[(0,A.jsx)($.P,{current:C,onChange:S,disabled:!0,dataSources:I}),d&&(0,A.jsx)(R.Xq,{resource:R.Uv.MuteTiming}),L&&!V&&(0,A.jsx)(m.RV,Object.assign({},G,{children:(0,A.jsxs)("form",{onSubmit:G.handleSubmit((e=>{var t,n;const i=(e=>{const t=e.time_intervals.map((e=>{var t;let{times:n,weekdays:i,days_of_month:a,months:s,years:l}=e;const r={times:n.filter((e=>{let{start_time:t,end_time:n}=e;return!!t&&!!n})),weekdays:null===(t=N(i))||void 0===t?void 0:t.map((e=>e.toLowerCase())),days_of_month:N(a),months:N(s),years:N(l)};return(0,b.omitBy)(r,b.isUndefined)}));return{name:e.name,time_intervals:t}})(e),a=s?null==U||null===(t=U.mute_time_intervals)||void 0===t?void 0:t.filter((e=>{let{name:t}=e;return t!==s.name})):U.mute_time_intervals,l=Object.assign({},L,{alertmanager_config:Object.assign({},U,{route:s&&i.name!==s.name?(0,j.FM)(i.name,s.name,null!==(n=U.route)&&void 0!==n?n:{}):U.route,mute_time_intervals:[...a||[],i]})});k((0,_.mM)({newConfig:l,oldConfig:L,alertManagerSourceName:C,successMessage:"Mute timing saved",redirectPath:"/alerting/routes/"}))})),"data-testid":"mute-timing-form",children:[r&&(B||(B=(0,A.jsx)(l.b,{title:"No matching mute timing found"}))),(0,A.jsxs)(c.C,{label:"Create mute timing",disabled:Boolean(d),children:[(0,A.jsx)(v.g,{required:!0,label:"Name",description:"A unique name for the mute timing",invalid:!(null===(n=G.formState.errors)||void 0===n||!n.name),error:null===(a=G.formState.errors.name)||void 0===a?void 0:a.message,children:(0,A.jsx)(g.I,Object.assign({},G.register("name",{required:!0,validate:e=>{if(!s){var t;return!(null==U||null===(t=U.mute_time_intervals)||void 0===t?void 0:t.find((t=>{let{name:n}=t;return e===n})))||`Mute timing already exists for "${e}"`}return e.length>0||"Name is required"}}),{className:O.input,"data-testid":"mute-timing-name"}))}),z||(z=(0,A.jsx)(P,{})),(0,A.jsx)(h.Qj,{type:"button",variant:"secondary",href:(0,x.eQ)("/alerting/routes/",C),children:"Cancel"}),(0,A.jsx)(h.zx,{type:"submit",className:O.submitButton,children:s?"Save":"Submit"})]})]})}))]})};var G,W,H;const Z=()=>{const[e]=(0,r.K)(),t=(0,o.I0)(),n=(0,p.k)("notification"),[d]=(0,f.k)(n),m=(0,y._)((e=>e.amConfigs)),u=(0,i.useCallback)((()=>{d&&t((0,_.Yh)(d))}),[d,t]);(0,i.useEffect)((()=>{u()}),[u]);const{result:c,error:v,loading:g}=d&&m[d]||T.oq,h=null==c?void 0:c.alertmanager_config,j=(0,i.useCallback)((e=>{var t;const n=null==h||null===(t=h.mute_time_intervals)||void 0===t?void 0:t.find((t=>{let{name:n}=t;return n===e}));if(n){var i;const e=(null!==(i=null==h?void 0:h.muteTimeProvenances)&&void 0!==i?i:{})[n.name];return Object.assign({},n,{provenance:e})}return n}),[h]);return(0,A.jsxs)(A.Fragment,{children:[g&&(G||(G=(0,A.jsx)(s.u,{text:"Loading mute timing"}))),v&&!g&&(0,A.jsx)(l.b,{severity:"error",title:`Error loading Alertmanager config for ${d}`,children:v.message||"Unknown error."}),c&&!v&&(0,A.jsxs)(a.rs,{children:[W||(W=(0,A.jsx)(a.AW,{exact:!0,path:"/alerting/routes/mute-timing/new",children:(0,A.jsx)(F,{})})),(0,A.jsx)(a.AW,{exact:!0,path:"/alerting/routes/mute-timing/edit",children:()=>{if(e.muteName){const t=j(String(e.muteName)),n=null==t?void 0:t.provenance;return(0,A.jsx)(F,{muteTiming:t,showError:!t,provenance:n})}return H||(H=(0,A.jsx)(a.l_,{to:"/alerting/routes"}))}})]})]})}},80030:(e,t,n)=>{n.d(t,{J:()=>s});n(76687);var i=n(28781),a=n(52010);const s=e=>{let{children:t,pageId:n,pageNav:s,isLoading:l}=e;return(0,a.jsx)(i.T,{pageNav:s,navId:n,children:(0,a.jsx)(i.T.Contents,{isLoading:l,children:t})})}},78391:(e,t,n)=>{n.d(t,{C0:()=>d,Uv:()=>r,Xq:()=>o});n(76687);var i,a=n(35562),s=n(94903),l=n(52010);let r;!function(e){e.ContactPoint="contact point",e.Template="template",e.MuteTiming="mute timing",e.AlertRule="alert rule",e.RootNotificationPolicy="root notification policy"}(r||(r={}));const o=e=>{let{resource:t}=e;return(0,l.jsxs)(a.b,{title:`This ${t} cannot be edited through the UI`,severity:"info",children:["This ",t," has been provisioned, that means it was created by config. Please contact your server admin to update this ",t,"."]})},d=()=>i||(i=(0,l.jsx)(s.C,{text:"Provisioned",color:"purple"}))},84362:(e,t,n)=>{n.d(t,{k:()=>o});var i=n(76687),a=n(95609),s=n(22814),l=n(73285),r=n(11126);function o(e){const[t,n]=(0,a.K)(),o=function(e){return(0,i.useCallback)((t=>e.map((e=>e.name)).includes(t)),[e])}(e),d=(0,i.useCallback)((e=>{o(e)&&(e===r.GC?(s.Z.delete(l.de),n({[l.c4]:null})):(s.Z.set(l.de,e),n({[l.c4]:e})))}),[n,o]),m=t[l.c4];if(m&&"string"==typeof m)return o(m)?[m,d]:[void 0,d];const u=s.Z.get(l.de);return u&&"string"==typeof u&&o(u)?(d(u),[u,d]):o(r.GC)?[r.GC,d]:[void 0,d]}},97758:(e,t,n)=>{n.d(t,{k:()=>s});var i=n(76687),a=n(11126);function s(e){return(0,i.useMemo)((()=>(0,a.LE)(e)),[e])}}}]);
//# sourceMappingURL=MuteTimings.4bc8a70576781b24fb7f.js.map