"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9355],{"./public/app/features/alerting/unified/MuteTimings.tsx":(e,t,a)=>{a.r(t),a.d(t,{default:()=>O});var n=a("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),i=a("./.yarn/__virtual__/react-router-virtual-31642fe47a/3/opt/drone/yarncache/react-router-npm-5.2.1-ea754d7473-7daae084bf.zip/node_modules/react-router/esm/react-router.js"),s=a("./public/app/features/alerting/unified/components/AlertingPageWrapper.tsx"),r=a("./packages/grafana-ui/src/index.ts"),l=a("./.yarn/__virtual__/react-hook-form-virtual-92b6119fd4/3/opt/drone/yarncache/react-hook-form-npm-7.5.3-f9cc466c62-fbfaa3b664.zip/node_modules/react-hook-form/dist/index.esm.js"),o=a("./.yarn/__virtual__/react-redux-virtual-7ad20a440e/3/opt/drone/yarncache/react-redux-npm-7.2.6-134f5ed64d-0bf142ce0d.zip/node_modules/react-redux/es/index.js"),d=a("./.yarn/__virtual__/@emotion-css-virtual-72c314ddb1/3/opt/drone/yarncache/@emotion-css-npm-11.7.1-25ff8755a7-ac1f56656f.zip/node_modules/@emotion/css/dist/emotion-css.esm.js"),m=a("./public/app/features/alerting/unified/components/AlertManagerPicker.tsx"),u=a("./public/app/features/alerting/unified/hooks/useAlertManagerSourceName.ts"),c=a("./public/app/features/alerting/unified/state/actions.ts"),p=a("./public/app/features/alerting/unified/hooks/useUnifiedAlertingSelector.ts"),v=a("./public/app/features/alerting/unified/utils/redux.ts"),g=a("../../opt/drone/yarncache/lodash-npm-4.17.21-6382451519-eb835a2e51.zip/node_modules/lodash/lodash.js");const h=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"],f=["january","february","march","april","may","june","july","august","september","october","november","december"],_={times:[{start_time:"",end_time:""}],weekdays:"",days_of_month:"",months:"",years:""},y=(e,t,a)=>!e||(e.split(",").map((e=>e.trim())).every((e=>e.split(":").every(t)))||a),b=e=>e?e.split(",").map((e=>e.trim())):void 0;var x=a("./public/app/features/alerting/unified/utils/misc.ts"),j=a("./public/app/features/alerting/unified/utils/alertmanager.ts"),k=a("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");const I=e=>{var t,a,n;let{intervalIndex:i}=e;const s=(0,r.useStyles2)(w),{register:o,formState:d}=(0,l.Gc)(),{fields:m,append:u,remove:c}=(0,l.Dq)({name:`time_intervals.${i}.times`}),p=e=>{if(!e)return!0;const[t,a]=e.split(":").map((e=>parseInt(e,10)));return(24===t?0===a:t>=0&&t<25&&(a>-1&&a<60))||"Time is invalid"},v=null===(t=d.errors.time_intervals)||void 0===t?void 0:t[i],g=null!==(a=null==v||null===(n=v.times)||void 0===n?void 0:n.some((e=>(null==e?void 0:e.start_time)||(null==e?void 0:e.end_time))))&&void 0!==a&&a;return(0,k.jsxs)("div",{children:[(0,k.jsx)(r.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,k.jsx)(k.Fragment,{children:m.map(((e,t)=>{var a,n,l,d;return(0,k.jsx)("div",{className:s.timeRange,children:(0,k.jsxs)(r.InlineFieldRow,{children:[(0,k.jsx)(r.InlineField,{label:"Start time",invalid:!(null==v||null===(a=v.times)||void 0===a||null===(n=a[t])||void 0===n||!n.start_time),children:(0,k.jsx)(r.Input,Object.assign({},o(`time_intervals.${i}.times.${t}.start_time`,{validate:p}),{className:s.timeRangeInput,defaultValue:e.start_time,placeholder:"HH:MM","data-testid":"mute-timing-starts-at"}))}),(0,k.jsx)(r.InlineField,{label:"End time",invalid:!(null==v||null===(l=v.times)||void 0===l||null===(d=l[t])||void 0===d||!d.end_time),children:(0,k.jsx)(r.Input,Object.assign({},o(`time_intervals.${i}.times.${t}.end_time`,{validate:p}),{className:s.timeRangeInput,defaultValue:e.end_time,placeholder:"HH:MM","data-testid":"mute-timing-ends-at"}))}),(0,k.jsx)(r.IconButton,{className:s.deleteTimeRange,title:"Remove",name:"trash-alt",type:"button",onClick:e=>{e.preventDefault(),c(t)}})]})},e.id)}))})}),(0,k.jsx)(r.Button,{className:s.addTimeRange,variant:"secondary",type:"button",icon:"plus",onClick:()=>u({start_time:"",end_time:""}),children:"Add another time range"})]})},w=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 C;const N=()=>{const e=(0,r.useStyles2)(S),{formState:t,register:a}=(0,l.Gc)(),{fields:n,append:i,remove:s}=(0,l.Dq)({name:"time_intervals"});return(0,k.jsx)(r.FieldSet,{className:e.timeIntervalLegend,label:"Time intervals",children:(0,k.jsxs)(k.Fragment,{children:[C||(C=(0,k.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."})),n.map(((n,i)=>{var l,o,d,m,u,c,p,v,g,_,b,x,j,w,C,N,S,$,M,T,A,F;const R=t.errors;return(0,k.jsxs)("div",{className:e.timeIntervalSection,children:[(0,k.jsx)(I,{intervalIndex:i}),(0,k.jsx)(r.Field,{label:"Days of the week",error:null!==(l=null===(o=R.time_intervals)||void 0===o||null===(d=o[i])||void 0===d||null===(m=d.weekdays)||void 0===m?void 0:m.message)&&void 0!==l?l:"",invalid:!(null===(u=R.time_intervals)||void 0===u||null===(c=u[i])||void 0===c||!c.weekdays),children:(0,k.jsx)(r.Input,Object.assign({},a(`time_intervals.${i}.weekdays`,{validate:e=>y(e,(e=>h.includes(e.toLowerCase())),"Invalid day of the week")}),{className:e.input,"data-testid":"mute-timing-weekdays",defaultValue:n.weekdays,placeholder:"Example: monday, tuesday:thursday"}))}),(0,k.jsx)(r.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===(p=R.time_intervals)||void 0===p||null===(v=p[i])||void 0===v||!v.days_of_month),error:null===(g=R.time_intervals)||void 0===g||null===(_=g[i])||void 0===_||null===(b=_.days_of_month)||void 0===b?void 0:b.message,children:(0,k.jsx)(r.Input,Object.assign({},a(`time_intervals.${i}.days_of_month`,{validate:e=>y(e,(e=>{const t=parseInt(e,10);return t>-31&&t<0||t>0&&t<32}),"Invalid day")}),{className:e.input,defaultValue:n.days_of_month,placeholder:"Example: 1, 14:16, -1","data-testid":"mute-timing-days"}))}),(0,k.jsx)(r.Field,{label:"Months",description:"The months of the year in either numerical or the full calendar month",invalid:!(null===(x=R.time_intervals)||void 0===x||null===(j=x[i])||void 0===j||!j.months),error:null===(w=R.time_intervals)||void 0===w||null===(C=w[i])||void 0===C||null===(N=C.months)||void 0===N?void 0:N.message,children:(0,k.jsx)(r.Input,Object.assign({},a(`time_intervals.${i}.months`,{validate:e=>y(e,(e=>f.includes(e)||parseInt(e,10)<13&&parseInt(e,10)>0),"Invalid month")}),{className:e.input,placeholder:"Example: 1:3, may:august, december",defaultValue:n.months,"data-testid":"mute-timing-months"}))}),(0,k.jsx)(r.Field,{label:"Years",invalid:!(null===(S=R.time_intervals)||void 0===S||null===($=S[i])||void 0===$||!$.years),error:null!==(M=null===(T=R.time_intervals)||void 0===T||null===(A=T[i])||void 0===A||null===(F=A.years)||void 0===F?void 0:F.message)&&void 0!==M?M:"",children:(0,k.jsx)(r.Input,Object.assign({},a(`time_intervals.${i}.years`,{validate:e=>y(e,(e=>/^\d{4}$/.test(e)),"Invalid year")}),{className:e.input,placeholder:"Example: 2021:2022, 2030",defaultValue:n.years,"data-testid":"mute-timing-years"}))}),(0,k.jsx)(r.Button,{type:"button",variant:"destructive",icon:"trash-alt",onClick:()=>s(i),children:"Remove time interval"})]},n.id)})),(0,k.jsx)(r.Button,{type:"button",variant:"secondary",className:e.removeTimeIntervalButton,onClick:()=>{i(_)},icon:"plus",children:"Add another time interval"})]})})},S=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 $,M;const T=e=>({input:d.css`
    width: 400px;
  `,submitButton:d.css`
    margin-left: ${e.spacing(1)};
  `}),A=e=>{var t,a,i;let{muteTiming:d,showError:h}=e;const f=(0,o.useDispatch)(),[y,I]=(0,u.k)(),w=(0,r.useStyles2)(T),C={alertmanager_config:{},template_files:{}},S=(0,p._)((e=>e.amConfigs)),{result:A=C,loading:F}=y&&S[y]||v.oq,R=null!==(t=null==A?void 0:A.alertmanager_config)&&void 0!==t?t:{},z=(e=>(0,n.useMemo)((()=>{if(!e)return{name:"",time_intervals:[_]};const t=e.time_intervals.map((e=>{var t,a,n,i,s,r,l,o,d;return{times:null!==(t=e.times)&&void 0!==t?t:_.times,weekdays:null!==(a=null==e||null===(n=e.weekdays)||void 0===n?void 0:n.join(", "))&&void 0!==a?a:_.weekdays,days_of_month:null!==(i=null==e||null===(s=e.days_of_month)||void 0===s?void 0:s.join(", "))&&void 0!==i?i:_.days_of_month,months:null!==(r=null==e||null===(l=e.months)||void 0===l?void 0:l.join(", "))&&void 0!==r?r:_.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]))(d),B=(0,l.cI)({defaultValues:z});return(0,k.jsxs)(s.J,{pageId:"am-routes",children:[(0,k.jsx)(m.P,{current:y,onChange:I,disabled:!0}),A&&!F&&(0,k.jsx)(l.RV,Object.assign({},B,{children:(0,k.jsxs)("form",{onSubmit:B.handleSubmit((e=>{var t,a;const n=(e=>{const t=e.time_intervals.map((e=>{var t;let{times:a,weekdays:n,days_of_month:i,months:s,years:r}=e;const l={times:a.filter((e=>{let{start_time:t,end_time:a}=e;return!!t&&!!a})),weekdays:null===(t=b(n))||void 0===t?void 0:t.map((e=>e.toLowerCase())),days_of_month:b(i),months:b(s),years:b(r)};return(0,g.omitBy)(l,g.isUndefined)}));return{name:e.name,time_intervals:t}})(e),i=d?null==R||null===(t=R.mute_time_intervals)||void 0===t?void 0:t.filter((e=>{let{name:t}=e;return t!==d.name})):R.mute_time_intervals,s=Object.assign({},A,{alertmanager_config:Object.assign({},R,{route:d&&n.name!==d.name?(0,j.FM)(n.name,d.name,null!==(a=R.route)&&void 0!==a?a:{}):R.route,mute_time_intervals:[...i||[],n]})});f((0,c.mM)({newConfig:s,oldConfig:A,alertManagerSourceName:y,successMessage:"Mute timing saved",redirectPath:"/alerting/routes/"}))})),"data-testid":"mute-timing-form",children:[h&&($||($=(0,k.jsx)(r.Alert,{title:"No matching mute timing found"}))),(0,k.jsxs)(r.FieldSet,{label:"Create mute timing",children:[(0,k.jsx)(r.Field,{required:!0,label:"Name",description:"A unique name for the mute timing",invalid:!(null===(a=B.formState.errors)||void 0===a||!a.name),error:null===(i=B.formState.errors.name)||void 0===i?void 0:i.message,children:(0,k.jsx)(r.Input,Object.assign({},B.register("name",{required:!0,validate:e=>{if(!d){var t;return!(null==R||null===(t=R.mute_time_intervals)||void 0===t?void 0:t.find((t=>{let{name:a}=t;return e===a})))||`Mute timing already exists for "${e}"`}return e.length>0||"Name is required"}}),{className:w.input,"data-testid":"mute-timing-name"}))}),M||(M=(0,k.jsx)(N,{})),(0,k.jsx)(r.LinkButton,{type:"button",variant:"secondary",href:(0,x.eQ)("/alerting/routes/",y),children:"Cancel"}),(0,k.jsx)(r.Button,{type:"submit",className:w.submitButton,children:d?"Save":"Submit"})]})]})}))]})};var F,R,z,B=a("./public/app/core/hooks/useQueryParams.ts");const O=()=>{const[e]=(0,B.K)(),t=(0,o.useDispatch)(),[a]=(0,u.k)(),s=(0,p._)((e=>e.amConfigs)),l=(0,n.useCallback)((()=>{a&&t((0,c.Yh)(a))}),[a,t]);(0,n.useEffect)((()=>{l()}),[l]);const{result:d,error:m,loading:g}=a&&s[a]||v.oq,h=null==d?void 0:d.alertmanager_config,f=(0,n.useCallback)((e=>{var t;return null==h||null===(t=h.mute_time_intervals)||void 0===t?void 0:t.find((t=>{let{name:a}=t;return a===e}))}),[h]);return(0,k.jsxs)(k.Fragment,{children:[g&&(F||(F=(0,k.jsx)(r.LoadingPlaceholder,{text:"Loading mute timing"}))),m&&!g&&(0,k.jsx)(r.Alert,{severity:"error",title:`Error loading Alertmanager config for ${a}`,children:m.message||"Unknown error."}),d&&!m&&(0,k.jsxs)(i.rs,{children:[R||(R=(0,k.jsx)(i.AW,{exact:!0,path:"/alerting/routes/mute-timing/new",children:(0,k.jsx)(A,{})})),(0,k.jsx)(i.AW,{exact:!0,path:"/alerting/routes/mute-timing/edit",children:()=>{if(e.muteName){const t=f(String(e.muteName));return(0,k.jsx)(A,{muteTiming:t,showError:!t})}return z||(z=(0,k.jsx)(i.l_,{to:"/alerting/routes"}))}})]})]})}},"./public/app/features/alerting/unified/components/AlertingPageWrapper.tsx":(e,t,a)=>{a.d(t,{J:()=>l});a("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js");var n=a("./public/app/core/components/Page/Page.tsx"),i=a("./public/app/core/selectors/navModel.ts"),s=a("./.yarn/__virtual__/react-redux-virtual-7ad20a440e/3/opt/drone/yarncache/react-redux-npm-7.2.6-134f5ed64d-0bf142ce0d.zip/node_modules/react-redux/es/index.js"),r=a("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");const l=e=>{let{children:t,pageId:a,isLoading:l}=e;const o=(0,i.h)((0,s.useSelector)((e=>e.navIndex)),a);return(0,r.jsx)(n.Z,{navModel:o,children:(0,r.jsx)(n.Z.Contents,{isLoading:l,children:t})})}},"./public/app/features/alerting/unified/hooks/useAlertManagerSourceName.ts":(e,t,a)=>{a.d(t,{k:()=>d});var n=a("./public/app/core/hooks/useQueryParams.ts"),i=a("./public/app/core/store.ts"),s=a("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),r=a("./public/app/features/alerting/unified/utils/constants.ts"),l=a("./public/app/features/alerting/unified/utils/datasource.ts");function o(e){return e===l.GC||!!(0,l.aM)().find((t=>t.name===e))}function d(){const[e,t]=(0,n.K)(),a=(0,s.useCallback)((e=>{o(e)&&(e===l.GC?(i.Z.delete(r.de),t({[r.c4]:null})):(i.Z.set(r.de,e),t({[r.c4]:e})))}),[t]),d=e[r.c4];if(d&&"string"==typeof d)return o(d)?[d,a]:[void 0,a];const m=i.Z.get(r.de);return m&&"string"==typeof m&&o(m)?(a(m),[m,a]):[l.GC,a]}}}]);
//# sourceMappingURL=MuteTimings.cd4ada1146b53ad3284f.js.map