"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9355],{13730:(e,t,n)=>{n.r(t),n.d(t,{default:()=>O});var i=n(68404),a=n(18745),s=n(42326),l=n(69783),r=n(26011),o=n(36636),d=n(80916),m=n(82498),u=n(1698),c=n(33899),v=n(83809),h=n(82139),g=n(39357),f=n(82897);const p=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],y=["january","february","march","april","may","june","july","august","september","october","november","december"],_={times:[{start_time:"",end_time:""}],weekdays:"",days_of_month:"",months:"",years:""},j=(e,t,n)=>!e||(e.split(",").map((e=>e.trim())).every((e=>e.split(":").every(t)))||n),x=e=>e?e.split(",").map((e=>e.trim())):void 0;var b=n(8455),k=n(50489),I=n(40256),w=n(45916);const C=e=>{var t,n,i;let{intervalIndex:a}=e;const s=(0,l.useStyles2)(N),{register:r,formState:o}=(0,d.Gc)(),{fields:m,append:u,remove:c}=(0,d.Dq)({name:`time_intervals.${a}.times`}),v=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"},h=null===(t=o.errors.time_intervals)||void 0===t?void 0:t[a],g=null!==(n=null==h||null===(i=h.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,w.jsxs)("div",{children:[(0,w.jsx)(l.Field,{className:s.field,label:"Time range",description:"The time inclusive of the starting time and exclusive of the end time in UTC",invalid:g,error:g?"Times must be between 00:00 and 24:00 UTC":"",children:(0,w.jsx)(w.Fragment,{children:m.map(((e,t)=>{var n,i,o,d;return(0,w.jsx)("div",{className:s.timeRange,children:(0,w.jsxs)(l.InlineFieldRow,{children:[(0,w.jsx)(l.InlineField,{label:"Start time",invalid:!(null==h||null===(n=h.times)||void 0===n||null===(i=n[t])||void 0===i||!i.start_time),children:(0,w.jsx)(l.Input,Object.assign({},r(`time_intervals.${a}.times.${t}.start_time`,{validate:v}),{className:s.timeRangeInput,defaultValue:e.start_time,placeholder:"HH:MM","data-testid":"mute-timing-starts-at"}))}),(0,w.jsx)(l.InlineField,{label:"End time",invalid:!(null==h||null===(o=h.times)||void 0===o||null===(d=o[t])||void 0===d||!d.end_time),children:(0,w.jsx)(l.Input,Object.assign({},r(`time_intervals.${a}.times.${t}.end_time`,{validate:v}),{className:s.timeRangeInput,defaultValue:e.end_time,placeholder:"HH:MM","data-testid":"mute-timing-ends-at"}))}),(0,w.jsx)(l.IconButton,{className:s.deleteTimeRange,title:"Remove",name:"trash-alt",type:"button",onClick:e=>{e.preventDefault(),c(t)}})]})},e.id)}))})}),(0,w.jsx)(l.Button,{className:s.addTimeRange,variant:"secondary",type:"button",icon:"plus",onClick:()=>u({start_time:"",end_time:""}),children:"Add another time range"})]})},N=e=>({field:o.css`
    margin-bottom: 0;
  `,timeRange:o.css`
    margin-bottom: ${e.spacing(1)};
  `,timeRangeInput:o.css`
    width: 120px;
  `,deleteTimeRange:o.css`
    margin: ${e.spacing(1)} 0 0 ${e.spacing(.5)};
  `,addTimeRange:o.css`
    margin-bottom: ${e.spacing(2)};
  `});var $;const S=()=>{const e=(0,l.useStyles2)(T),{formState:t,register:n}=(0,d.Gc)(),{fields:i,append:a,remove:s}=(0,d.Dq)({name:"time_intervals"});return(0,w.jsx)(l.FieldSet,{className:e.timeIntervalLegend,label:"Time intervals",children:(0,w.jsxs)(w.Fragment,{children:[$||($=(0,w.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 r,o,d,m,u,c,v,h,g,f,_,x,b,k,I,N,$,S,T,F,M,R;const A=t.errors;return(0,w.jsxs)("div",{className:e.timeIntervalSection,children:[(0,w.jsx)(C,{intervalIndex:a}),(0,w.jsx)(l.Field,{label:"Days of the week",error:null!==(r=null===(o=A.time_intervals)||void 0===o||null===(d=o[a])||void 0===d||null===(m=d.weekdays)||void 0===m?void 0:m.message)&&void 0!==r?r:"",invalid:!(null===(u=A.time_intervals)||void 0===u||null===(c=u[a])||void 0===c||!c.weekdays),children:(0,w.jsx)(l.Input,Object.assign({},n(`time_intervals.${a}.weekdays`,{validate:e=>j(e,(e=>p.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,w.jsx)(l.Field,{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===(v=A.time_intervals)||void 0===v||null===(h=v[a])||void 0===h||!h.days_of_month),error:null===(g=A.time_intervals)||void 0===g||null===(f=g[a])||void 0===f||null===(_=f.days_of_month)||void 0===_?void 0:_.message,children:(0,w.jsx)(l.Input,Object.assign({},n(`time_intervals.${a}.days_of_month`,{validate:e=>j(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,w.jsx)(l.Field,{label:"Months",description:"The months of the year in either numerical or the full calendar month",invalid:!(null===(x=A.time_intervals)||void 0===x||null===(b=x[a])||void 0===b||!b.months),error:null===(k=A.time_intervals)||void 0===k||null===(I=k[a])||void 0===I||null===(N=I.months)||void 0===N?void 0:N.message,children:(0,w.jsx)(l.Input,Object.assign({},n(`time_intervals.${a}.months`,{validate:e=>j(e,(e=>y.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,w.jsx)(l.Field,{label:"Years",invalid:!(null===($=A.time_intervals)||void 0===$||null===(S=$[a])||void 0===S||!S.years),error:null!==(T=null===(F=A.time_intervals)||void 0===F||null===(M=F[a])||void 0===M||null===(R=M.years)||void 0===R?void 0:R.message)&&void 0!==T?T:"",children:(0,w.jsx)(l.Input,Object.assign({},n(`time_intervals.${a}.years`,{validate:e=>j(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,w.jsx)(l.Button,{type:"button",variant:"destructive",icon:"trash-alt",onClick:()=>s(a),children:"Remove time interval"})]},i.id)})),(0,w.jsx)(l.Button,{type:"button",variant:"secondary",className:e.removeTimeIntervalButton,onClick:()=>{a(_)},icon:"plus",children:"Add another time interval"})]})})},T=e=>({input:o.css`
    width: 400px;
  `,timeIntervalLegend:o.css`
    legend {
      font-size: 1.25rem;
    }
  `,timeIntervalSection:o.css`
    background-color: ${e.colors.background.secondary};
    padding: ${e.spacing(1)};
    margin-bottom: ${e.spacing(1)};
  `,removeTimeIntervalButton:o.css`
    margin-top: ${e.spacing(1)};
  `});var F,M;const R=e=>({input:o.css`
    width: 400px;
  `,submitButton:o.css`
    margin-left: ${e.spacing(1)};
  `}),A=e=>{var t,n,s;let{muteTiming:r,showError:o}=e;const p=(0,a.useDispatch)(),y=(0,u.k)("notification"),[j,C]=(0,m.k)(y),N=(0,l.useStyles2)(R),$={alertmanager_config:{},template_files:{}},T=(0,c._)((e=>e.amConfigs)),{result:A=$,loading:B}=j&&T[j]||b.oq,E=null!==(t=null==A?void 0:A.alertmanager_config)&&void 0!==t?t:{},L=(e=>(0,i.useMemo)((()=>{if(!e)return{name:"",time_intervals:[_]};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:_.times,weekdays:null!==(n=null==e||null===(i=e.weekdays)||void 0===i?void 0:i.join(", "))&&void 0!==n?n:_.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:_.days_of_month,months:null!==(l=null==e||null===(r=e.months)||void 0===r?void 0:r.join(", "))&&void 0!==l?l:_.months,years:null!==(o=null==e||null===(d=e.years)||void 0===d?void 0:d.join(", "))&&void 0!==o?o:_.years}}));return{name:e.name,time_intervals:t}}),[e]))(r),O=(0,d.cI)({defaultValues:L});return(0,w.jsxs)(I.J,{pageId:"am-routes",children:[(0,w.jsx)(k.P,{current:j,onChange:C,disabled:!0,dataSources:y}),A&&!B&&(0,w.jsx)(d.RV,Object.assign({},O,{children:(0,w.jsxs)("form",{onSubmit:O.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=x(i))||void 0===t?void 0:t.map((e=>e.toLowerCase())),days_of_month:x(a),months:x(s),years:x(l)};return(0,f.omitBy)(r,f.isUndefined)}));return{name:e.name,time_intervals:t}})(e),a=r?null==E||null===(t=E.mute_time_intervals)||void 0===t?void 0:t.filter((e=>{let{name:t}=e;return t!==r.name})):E.mute_time_intervals,s=Object.assign({},A,{alertmanager_config:Object.assign({},E,{route:r&&i.name!==r.name?(0,h.FM)(i.name,r.name,null!==(n=E.route)&&void 0!==n?n:{}):E.route,mute_time_intervals:[...a||[],i]})});p((0,v.mM)({newConfig:s,oldConfig:A,alertManagerSourceName:j,successMessage:"Mute timing saved",redirectPath:"/alerting/routes/"}))})),"data-testid":"mute-timing-form",children:[o&&(F||(F=(0,w.jsx)(l.Alert,{title:"No matching mute timing found"}))),(0,w.jsxs)(l.FieldSet,{label:"Create mute timing",children:[(0,w.jsx)(l.Field,{required:!0,label:"Name",description:"A unique name for the mute timing",invalid:!(null===(n=O.formState.errors)||void 0===n||!n.name),error:null===(s=O.formState.errors.name)||void 0===s?void 0:s.message,children:(0,w.jsx)(l.Input,Object.assign({},O.register("name",{required:!0,validate:e=>{if(!r){var t;return!(null==E||null===(t=E.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:N.input,"data-testid":"mute-timing-name"}))}),M||(M=(0,w.jsx)(S,{})),(0,w.jsx)(l.LinkButton,{type:"button",variant:"secondary",href:(0,g.eQ)("/alerting/routes/",j),children:"Cancel"}),(0,w.jsx)(l.Button,{type:"submit",className:N.submitButton,children:r?"Save":"Submit"})]})]})}))]})};var B,E,L;const O=()=>{const[e]=(0,r.K)(),t=(0,a.useDispatch)(),n=(0,u.k)("notification"),[o]=(0,m.k)(n),d=(0,c._)((e=>e.amConfigs)),h=(0,i.useCallback)((()=>{o&&t((0,v.Yh)(o))}),[o,t]);(0,i.useEffect)((()=>{h()}),[h]);const{result:g,error:f,loading:p}=o&&d[o]||b.oq,y=null==g?void 0:g.alertmanager_config,_=(0,i.useCallback)((e=>{var t;return null==y||null===(t=y.mute_time_intervals)||void 0===t?void 0:t.find((t=>{let{name:n}=t;return n===e}))}),[y]);return(0,w.jsxs)(w.Fragment,{children:[p&&(B||(B=(0,w.jsx)(l.LoadingPlaceholder,{text:"Loading mute timing"}))),f&&!p&&(0,w.jsx)(l.Alert,{severity:"error",title:`Error loading Alertmanager config for ${o}`,children:f.message||"Unknown error."}),g&&!f&&(0,w.jsxs)(s.rs,{children:[E||(E=(0,w.jsx)(s.AW,{exact:!0,path:"/alerting/routes/mute-timing/new",children:(0,w.jsx)(A,{})})),(0,w.jsx)(s.AW,{exact:!0,path:"/alerting/routes/mute-timing/edit",children:()=>{if(e.muteName){const t=_(String(e.muteName));return(0,w.jsx)(A,{muteTiming:t,showError:!t})}return L||(L=(0,w.jsx)(s.l_,{to:"/alerting/routes"}))}})]})]})}},40256:(e,t,n)=>{n.d(t,{J:()=>r});n(68404);var i=n(18745),a=n(33801),s=n(8674),l=n(45916);const r=e=>{let{children:t,pageId:n,isLoading:r}=e;const o=(0,s.h)((0,i.useSelector)((e=>e.navIndex)),n);return(0,l.jsx)(a.Z,{navModel:o,children:(0,l.jsx)(a.Z.Contents,{isLoading:r,children:t})})}},82498:(e,t,n)=>{n.d(t,{k:()=>o});var i=n(68404),a=n(26011),s=n(17421),l=n(85464),r=n(19462);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]}},1698:(e,t,n)=>{n.d(t,{k:()=>s});var i=n(68404),a=n(19462);function s(e){return(0,i.useMemo)((()=>(0,a.LE)(e)),[e])}}}]);
//# sourceMappingURL=MuteTimings.266a68e609baeb5c3ed9.js.map