(window.webpackJsonp=window.webpackJsonp||[]).push([[11],{"9f6O":function(e,t,n){"use strict";(function(e){n.d(t,"a",(function(){return i}));var a=n("t8hP"),r=n("q1tI"),l=n("Ty5D");function i(){const{search:t}=Object(l.l)();return[Object(r.useMemo)(()=>Object(a.locationSearchToObject)(t||""),[t]),Object(r.useCallback)((t,n)=>e(()=>a.locationService.partial(t,n)),[])]}}).call(this,n("URgk").setImmediate)},"Ev/k":function(e,t,n){"use strict";n.r(t);var a=n("q1tI"),r=n("vF1F"),l=n("kDLi"),i=n("/MKj"),o=n("Ty5D"),s=n("SGmB"),c=n("sbt+"),u=n("lcDh"),d=n("G1gI"),p=n("Sp9v"),j=n("LvDl");function b(){return(b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}const m=["",d.d[0].value],g=(e,t)=>Object.entries(null!=e?e:{}).reduce((e,[n,a])=>[...e,{name:n,value:a,isRegex:t,isEqual:!0}],[]),v=e=>{if(!e)return m;const[t,n]=e?Object(d.b)(e):[void 0,void 0],a=d.d.find(e=>e.value===n);return t&&a?[String(t),a.value]:m},h=e=>e.value,f={name:"",value:"",isRegex:!1,isEqual:!0},O={id:"",groupBy:[],matchers:[],routes:[],continue:!1,receiver:"",groupWaitValue:"",groupWaitValueType:d.d[0].value,groupIntervalValue:"",groupIntervalValueType:d.d[0].value,repeatIntervalValue:"",repeatIntervalValueType:d.d[0].value},x=e=>{var t,n,a,r,l,i;if(!e||0===Object.keys(e).length)return[O,{}];const[o,s]=v(e.group_wait),[c,u]=v(e.group_interval),[d,j]=v(e.repeat_interval),b=String(Math.random()),m={[b]:e},h=[];return null===(t=e.routes)||void 0===t||t.forEach(e=>{const[t,n]=x(e);h.push(t),Object.assign(m,n)}),[{id:b,matchers:[...null!==(n=null===(a=e.matchers)||void 0===a?void 0:a.map(p.e))&&void 0!==n?n:[],...g(e.match,!1),...g(e.match_re,!0)],continue:null!==(r=e.continue)&&void 0!==r&&r,receiver:null!==(l=e.receiver)&&void 0!==l?l:"",groupBy:null!==(i=e.group_by)&&void 0!==i?i:[],groupWaitValue:o,groupWaitValueType:s,groupIntervalValue:c,groupIntervalValueType:u,repeatIntervalValue:d,repeatIntervalValueType:j,routes:h},m]},y=(e,t)=>{const n=t[e.id],a=b({},null!=n?n:{},{continue:e.continue,group_by:e.groupBy,matchers:e.matchers.length?e.matchers.map(p.g):void 0,match:void 0,match_re:void 0,group_wait:e.groupWaitValue?`${e.groupWaitValue}${e.groupWaitValueType}`:void 0,group_interval:e.groupIntervalValue?`${e.groupIntervalValue}${e.groupIntervalValueType}`:void 0,repeat_interval:e.repeatIntervalValue?`${e.repeatIntervalValue}${e.repeatIntervalValueType}`:void 0,routes:e.routes.map(e=>y(e,t))});return e.receiver&&(a.receiver=e.receiver),Object(j.omitBy)(a,j.isUndefined)},C=e=>({label:e,value:e}),I=e=>(null!=e?e:[]).map(C),w=e=>{var t;return e&&null!==(t=h(e))&&void 0!==t?t:""},S=e=>{return e?(null!=(t=e)?t:[]).map(h):[];var t},$=e=>{if(e)return/^\d+$/.test(e)?void 0:"Must be a positive integer."};var N=n("8qpb");const V=e=>({container:r.css`
      align-items: center;
      display: flex;
      flex-flow: row nowrap;

      & > * + * {
        margin-left: ${e.spacing(1)};
      }
    `,input:r.css`
      flex: 1;
    `,timingContainer:r.css`
      max-width: ${e.spacing(33)};
    `,smallInput:r.css`
      width: ${e.spacing(6.5)};
    `});var k,T,F=n("nKUr");const E=["onChange","ref"],B=["onChange","ref"],M=["onChange","ref"],R=["onChange","ref"],_=["onChange","ref"];function P(){return(P=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}function G(e,t){if(null==e)return{};var n,a,r={},l=Object.keys(e);for(a=0;a<l.length;a++)n=l[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}const W=({alertManagerSourceName:e,onCancel:t,onSave:n,receivers:i,routes:o})=>{var s;const c=Object(l.useStyles2)(V),[u,p]=Object(a.useState)(!1),[j,b]=Object(a.useState)(I(o.groupBy));return Object(F.jsx)(l.Form,{defaultValues:o,onSubmit:n,children:({control:n,errors:a,setValue:o})=>{var m,g,v,h;return Object(F.jsxs)(F.Fragment,{children:[Object(F.jsx)(l.Field,{label:"Default contact point",invalid:!!a.receiver,error:null===(m=a.receiver)||void 0===m?void 0:m.message,children:Object(F.jsx)(F.Fragment,{children:Object(F.jsxs)("div",{className:c.container,"data-testid":"am-receiver-select",children:[Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=G(e.field,E);return Object(F.jsx)(l.Select,P({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(w(e)),options:i}))},control:n,name:"receiver",rules:{required:{value:!0,message:"Required."}}}),k||(k=Object(F.jsx)("span",{children:"or"})),Object(F.jsx)(l.Link,{href:Object(N.e)("/alerting/notifications/receivers/new",e),children:"Create a contact point"})]})})}),Object(F.jsx)(l.Field,{label:"Group by",description:"Group alerts when you receive a notification based on labels.","data-testid":"am-group-select",children:Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=G(e.field,B);return Object(F.jsx)(l.MultiSelect,P({menuShouldPortal:!0},n,{allowCustomValue:!0,className:c.input,onCreateOption:e=>{b(t=>[...t,C(e)]),o("groupBy",[...n.value,e])},onChange:e=>t(S(e)),options:j}))},control:n,name:"groupBy"})}),Object(F.jsxs)(l.Collapse,{collapsible:!0,isOpen:u,label:"Timing options",onToggle:p,children:[Object(F.jsx)(l.Field,{label:"Group wait",description:"The waiting time until the initial notification is sent for a new group created by an incoming alert. Default 30 seconds.",invalid:!!a.groupWaitValue,error:null===(g=a.groupWaitValue)||void 0===g?void 0:g.message,"data-testid":"am-group-wait",children:Object(F.jsx)(F.Fragment,{children:Object(F.jsxs)("div",{className:Object(r.cx)(c.container,c.timingContainer),children:[Object(F.jsx)(l.InputControl,{render:({field:e,fieldState:{invalid:t}})=>Object(F.jsx)(l.Input,P({},e,{className:c.smallInput,invalid:t})),control:n,name:"groupWaitValue",rules:{validate:$}}),Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=G(e.field,M);return Object(F.jsx)(l.Select,P({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(w(e)),options:d.d}))},control:n,name:"groupWaitValueType"})]})})}),Object(F.jsx)(l.Field,{label:"Group interval",description:"The waiting time to send a batch of new alerts for that group after the first notification was sent. Default 5 minutes.",invalid:!!a.groupIntervalValue,error:null===(v=a.groupIntervalValue)||void 0===v?void 0:v.message,"data-testid":"am-group-interval",children:Object(F.jsx)(F.Fragment,{children:Object(F.jsxs)("div",{className:Object(r.cx)(c.container,c.timingContainer),children:[Object(F.jsx)(l.InputControl,{render:({field:e,fieldState:{invalid:t}})=>Object(F.jsx)(l.Input,P({},e,{className:c.smallInput,invalid:t})),control:n,name:"groupIntervalValue",rules:{validate:$}}),Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=G(e.field,R);return Object(F.jsx)(l.Select,P({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(w(e)),options:d.d}))},control:n,name:"groupIntervalValueType"})]})})}),Object(F.jsx)(l.Field,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent. Default 4 hours.",invalid:!!a.repeatIntervalValue,error:null===(h=a.repeatIntervalValue)||void 0===h?void 0:h.message,"data-testid":"am-repeat-interval",children:Object(F.jsx)(F.Fragment,{children:Object(F.jsxs)("div",{className:Object(r.cx)(c.container,c.timingContainer),children:[Object(F.jsx)(l.InputControl,{render:({field:e,fieldState:{invalid:t}})=>Object(F.jsx)(l.Input,P({},e,{className:c.smallInput,invalid:t})),control:n,name:"repeatIntervalValue",rules:{validate:$}}),Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=G(e.field,_);return Object(F.jsx)(l.Select,P({menuShouldPortal:!0},n,{className:c.input,menuPlacement:"top",onChange:e=>t(w(e)),options:d.d}))},control:n,name:"repeatIntervalValueType"})]})})})]}),Object(F.jsxs)("div",{className:c.container,children:[T||(T=Object(F.jsx)(l.Button,{type:"submit",children:"Save"})),s||(s=Object(F.jsx)(l.Button,{onClick:t,type:"reset",variant:"secondary",fill:"outline",children:"Cancel"}))]})]})}})},A=e=>({container:r.css`
      display: grid;
      font-style: ${e.typography.fontSize};
      grid-template-columns: ${e.spacing(15.5)} auto;

      ${e.breakpoints.down("md")} {
        grid-template-columns: 100%;
      }
    `,titleCell:r.css`
      color: ${e.colors.text.primary};
    `,valueCell:r.css`
      color: ${e.colors.text.secondary};
      margin-bottom: ${e.spacing(1)};
    `}),L=({routes:e})=>{const t=Object(l.useStyles2)(A),n=e.receiver||"-",a=e.groupBy.join(", ")||"-",r=e.groupWaitValue?`${e.groupWaitValue}${e.groupWaitValueType}`:"-",i=e.groupIntervalValue?`${e.groupIntervalValue}${e.groupIntervalValueType}`:"-",o=e.repeatIntervalValue?`${e.repeatIntervalValue}${e.repeatIntervalValueType}`:"-";return Object(F.jsxs)("div",{className:t.container,children:[Object(F.jsx)("div",{className:t.titleCell,children:"Contact point"}),Object(F.jsx)("div",{className:t.valueCell,"data-testid":"am-routes-root-receiver",children:n}),Object(F.jsx)("div",{className:t.titleCell,children:"Group by"}),Object(F.jsx)("div",{className:t.valueCell,"data-testid":"am-routes-root-group-by",children:a}),Object(F.jsx)("div",{className:t.titleCell,children:"Timings"}),Object(F.jsxs)("div",{className:t.valueCell,"data-testid":"am-routes-root-timings",children:["Group wait: ",r," | Group interval: ",i," | Repeat interval: ",o]})]})};var q,z;const D=({isEditMode:e,onSave:t,onEnterEditMode:n,onExitEditMode:a,receivers:r,routes:i,alertManagerSourceName:o})=>{const s=Object(l.useStyles2)(U);return Object(F.jsxs)("div",{className:s.container,"data-testid":"am-root-route-container",children:[Object(F.jsxs)("div",{className:s.titleContainer,children:[Object(F.jsxs)("h5",{className:s.title,children:["Root policy - ",q||(q=Object(F.jsx)("i",{children:"default for all alerts"}))]}),!e&&Object(F.jsx)(l.Button,{icon:"pen",onClick:n,size:"sm",type:"button",variant:"secondary",children:"Edit"})]}),z||(z=Object(F.jsx)("p",{children:"All alerts will go to the default contact point, unless you set additional matchers in the specific routing area."})),e?Object(F.jsx)(W,{alertManagerSourceName:o,onCancel:a,onSave:t,receivers:r,routes:i}):Object(F.jsx)(L,{routes:i})]})},U=e=>({container:r.css`
      background-color: ${e.colors.background.secondary};
      color: ${e.colors.text.secondary};
      padding: ${e.spacing(2)};
    `,titleContainer:r.css`
      color: ${e.colors.text.primary};
      display: flex;
      flex-flow: row nowrap;
    `,title:r.css`
      flex: 100%;
    `}),K=({buttonIcon:e,buttonLabel:t,buttonSize:n="lg",buttonVariant:a="primary",onButtonClick:r,text:i})=>{const o=Object(l.useStyles)(J);return Object(F.jsxs)("div",{className:o.container,children:[Object(F.jsx)("p",{className:o.text,children:i}),Object(F.jsx)(l.Button,{className:o.button,icon:e,onClick:r,size:n,type:"button",variant:a,children:t})]})},J=e=>({container:r.css`
      background-color: ${e.colors.bg2};
      color: ${e.colors.textSemiWeak};
      padding: ${e.spacing.xl};
      text-align: center;
    `,text:r.css`
      margin-bottom: ${e.spacing.md};
    `,button:r.css`
      margin: ${e.spacing.md} 0 ${e.spacing.sm};
    `});var Y=n("wDOy");const H=["onChange","ref"],X=["onChange","ref"],Q=["onChange","ref"],Z=["onChange","ref"],ee=["onChange","ref"];var te,ne;function ae(e,t){if(null==e)return{};var n,a,r={},l=Object.keys(e);for(a=0;a<l.length;a++)n=l[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}function re(){return(re=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}const le=({onCancel:e,onSave:t,receivers:n,routes:i})=>{var o;const s=Object(l.useStyles2)(ie),c=Object(l.useStyles2)(V),[u,p]=Object(a.useState)(i.groupBy.length>0),[j,b]=Object(a.useState)(!!i.groupWaitValue||!!i.groupIntervalValue||!!i.repeatIntervalValue),[m,g]=Object(a.useState)(I(i.groupBy));return Object(F.jsx)(l.Form,{defaultValues:i,onSubmit:t,children:({control:t,register:a,errors:i,setValue:v})=>{var h,O,x;return Object(F.jsxs)(F.Fragment,{children:[Object(F.jsx)("input",re({type:"hidden"},a("id"))),Object(F.jsx)(l.FieldArray,{name:"matchers",control:t,children:({fields:e,append:t,remove:n})=>Object(F.jsxs)(F.Fragment,{children:[te||(te=Object(F.jsx)("div",{children:"Matching labels"})),Object(F.jsx)("div",{className:s.matchersContainer,children:e.map((e,t)=>{var r,o,c,u,d,p,j,b,m,g;const v=`matchers[${t}]`;return Object(F.jsxs)(l.HorizontalGroup,{align:"flex-start",children:[Object(F.jsx)(l.Field,{label:"Label",invalid:!(null===(r=i.matchers)||void 0===r||null===(o=r[t])||void 0===o||!o.name),error:null===(c=i.matchers)||void 0===c||null===(u=c[t])||void 0===u||null===(d=u.name)||void 0===d?void 0:d.message,children:Object(F.jsx)(l.Input,re({},a(v+".name",{required:"Field is required"}),{defaultValue:e.name,placeholder:"label"}))}),Object(F.jsx)(l.Field,{label:"Value",invalid:!(null===(p=i.matchers)||void 0===p||null===(j=p[t])||void 0===j||!j.value),error:null===(b=i.matchers)||void 0===b||null===(m=b[t])||void 0===m||null===(g=m.value)||void 0===g?void 0:g.message,children:Object(F.jsx)(l.Input,re({},a(v+".value",{required:"Field is required"}),{defaultValue:e.value,placeholder:"value"}))}),Object(F.jsx)(l.Field,{className:s.matcherRegexField,label:"Regex",children:Object(F.jsx)(l.Checkbox,re({},a(v+".isRegex"),{defaultChecked:e.isRegex}))}),Object(F.jsx)(l.Field,{className:s.matcherRegexField,label:"Equal",children:Object(F.jsx)(l.Checkbox,re({},a(v+".isEqual"),{defaultChecked:e.isEqual}))}),Object(F.jsx)(l.IconButton,{className:s.removeButton,tooltip:"Remove matcher",name:"trash-alt",onClick:()=>n(t),children:"Remove"})]},e.id)})}),Object(F.jsx)(l.Button,{className:s.addMatcherBtn,icon:"plus",onClick:()=>t(f),variant:"secondary",type:"button",children:"Add matcher"})]})}),Object(F.jsx)(l.Field,{label:"Contact point",children:Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,a=ae(e.field,H);return Object(F.jsx)(l.Select,re({menuShouldPortal:!0},a,{className:c.input,onChange:e=>t(w(e)),options:n}))},control:t,name:"receiver"})}),Object(F.jsx)(l.Field,{label:"Continue matching subsequent sibling nodes",children:Object(F.jsx)(l.Switch,re({},a("continue")))}),Object(F.jsx)(l.Field,{label:"Override grouping",children:Object(F.jsx)(l.Switch,{value:u,onChange:()=>p(e=>!e)})}),u&&Object(F.jsx)(l.Field,{label:"Group by",description:"Group alerts when you receive a notification based on labels.",children:Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=ae(e.field,X);return Object(F.jsx)(l.MultiSelect,re({menuShouldPortal:!0},n,{allowCustomValue:!0,className:c.input,onCreateOption:e=>{g(t=>[...t,C(e)]),v("groupBy",[...n.value,e])},onChange:e=>t(S(e)),options:m}))},control:t,name:"groupBy"})}),Object(F.jsx)(l.Field,{label:"Override general timings",children:Object(F.jsx)(l.Switch,{value:j,onChange:()=>b(e=>!e)})}),j&&Object(F.jsxs)(F.Fragment,{children:[Object(F.jsx)(l.Field,{label:"Group wait",description:"The waiting time until the initial notification is sent for a new group created by an incoming alert.",invalid:!!i.groupWaitValue,error:null===(h=i.groupWaitValue)||void 0===h?void 0:h.message,children:Object(F.jsx)(F.Fragment,{children:Object(F.jsxs)("div",{className:Object(r.cx)(c.container,c.timingContainer),children:[Object(F.jsx)(l.InputControl,{render:({field:e,fieldState:{invalid:t}})=>Object(F.jsx)(l.Input,re({},e,{className:c.smallInput,invalid:t})),control:t,name:"groupWaitValue",rules:{validate:$}}),Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=ae(e.field,Q);return Object(F.jsx)(l.Select,re({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(w(e)),options:d.d}))},control:t,name:"groupWaitValueType"})]})})}),Object(F.jsx)(l.Field,{label:"Group interval",description:"The waiting time to send a batch of new alerts for that group after the first notification was sent.",invalid:!!i.groupIntervalValue,error:null===(O=i.groupIntervalValue)||void 0===O?void 0:O.message,children:Object(F.jsx)(F.Fragment,{children:Object(F.jsxs)("div",{className:Object(r.cx)(c.container,c.timingContainer),children:[Object(F.jsx)(l.InputControl,{render:({field:e,fieldState:{invalid:t}})=>Object(F.jsx)(l.Input,re({},e,{className:c.smallInput,invalid:t})),control:t,name:"groupIntervalValue",rules:{validate:$}}),Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=ae(e.field,Z);return Object(F.jsx)(l.Select,re({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(w(e)),options:d.d}))},control:t,name:"groupIntervalValueType"})]})})}),Object(F.jsx)(l.Field,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent.",invalid:!!i.repeatIntervalValue,error:null===(x=i.repeatIntervalValue)||void 0===x?void 0:x.message,children:Object(F.jsx)(F.Fragment,{children:Object(F.jsxs)("div",{className:Object(r.cx)(c.container,c.timingContainer),children:[Object(F.jsx)(l.InputControl,{render:({field:e,fieldState:{invalid:t}})=>Object(F.jsx)(l.Input,re({},e,{className:c.smallInput,invalid:t})),control:t,name:"repeatIntervalValue",rules:{validate:$}}),Object(F.jsx)(l.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=ae(e.field,ee);return Object(F.jsx)(l.Select,re({menuShouldPortal:!0},n,{className:c.input,menuPlacement:"top",onChange:e=>t(w(e)),options:d.d}))},control:t,name:"repeatIntervalValueType"})]})})})]}),Object(F.jsxs)("div",{className:s.buttonGroup,children:[ne||(ne=Object(F.jsx)(l.Button,{type:"submit",children:"Save policy"})),o||(o=Object(F.jsx)(l.Button,{onClick:e,fill:"outline",type:"button",variant:"secondary",children:"Cancel"}))]})]})}})},ie=e=>{const t=e.spacing(3.5);return{addMatcherBtn:r.css`
      margin-bottom: ${t};
    `,matchersContainer:r.css`
      background-color: ${e.colors.background.secondary};
      margin: ${e.spacing(1,0)};
      padding: ${e.spacing(1,4.6,1,1.5)};
      width: fit-content;
    `,matcherRegexField:r.css`
      margin-left: ${e.spacing(6)};
    `,nestedPolicies:r.css`
      margin-top: ${t};
    `,removeButton:r.css`
      margin-left: ${e.spacing(1)};
      margin-top: ${e.spacing(2.5)};
    `,buttonGroup:r.css`
      margin: ${e.spacing(6)} 0 ${t};

      & > * + * {
        margin-left: ${e.spacing(1.5)};
      }
    `}};var oe;function se(){return(se=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}const ce=({onChange:e,receivers:t,routes:n})=>{const r=Object(l.useStyles2)(ue),i=Object(l.useStyles2)(A),o=n.groupWaitValue?`${n.groupWaitValue}${n.groupWaitValueType}`:"-",s=n.groupIntervalValue?`${n.groupIntervalValue}${n.groupIntervalValueType}`:"-",c=n.repeatIntervalValue?`${n.repeatIntervalValue}${n.repeatIntervalValueType}`:"-",[u,d]=Object(a.useState)(n.routes),[p,j]=Object(a.useState)(!1);return Object(F.jsxs)("div",{className:i.container,children:[Object(F.jsx)("div",{className:i.titleCell,children:"Group wait"}),Object(F.jsx)("div",{className:i.valueCell,children:o}),Object(F.jsx)("div",{className:i.titleCell,children:"Group interval"}),Object(F.jsx)("div",{className:i.valueCell,children:s}),Object(F.jsx)("div",{className:i.titleCell,children:"Repeat interval"}),Object(F.jsx)("div",{className:i.valueCell,children:c}),Object(F.jsx)("div",{className:i.titleCell,children:"Nested policies"}),Object(F.jsxs)("div",{className:i.valueCell,children:[u.length?Object(F.jsx)(je,{isAddMode:p,onCancelAdd:()=>{j(!1),d(e=>{const t=[...e];return t.pop(),t})},onChange:t=>{e(se({},n,{routes:t})),p&&j(!1)},receivers:t,routes:u}):oe||(oe=Object(F.jsx)("p",{children:"No nested policies configured."})),!p&&Object(F.jsx)(l.Button,{className:r.addNestedRoutingBtn,icon:"plus",onClick:()=>{d(e=>[...e,O]),j(!0)},variant:"secondary",type:"button",children:"Add nested policy"})]})]})},ue=e=>({addNestedRoutingBtn:r.css`
      margin-top: ${e.spacing(2)};
    `});var de=n("Jv5Q");function pe(){return(pe=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}const je=({isAddMode:e,onCancelAdd:t,onChange:n,receivers:r,routes:i})=>{const[o,s]=Object(a.useState)(!1),[c,u]=Object(a.useState)(),d=Object(a.useCallback)(e=>u(e.id),[]),p=Object(a.useCallback)(()=>u(void 0),[]),j=[{id:"matchingCriteria",label:"Matching labels",renderCell:e=>Object(F.jsx)(de.a,{matchers:e.data.matchers}),size:10},{id:"groupBy",label:"Group by",renderCell:e=>e.data.groupBy.join(", ")||"-",size:5},{id:"receiverChannel",label:"Contact point",renderCell:e=>e.data.receiver||"-",size:5},{id:"actions",label:"Actions",renderCell:(e,t)=>{if(e.renderExpandedContent)return null;return Object(F.jsxs)(l.HorizontalGroup,{children:[Object(F.jsx)(l.Button,{icon:"pen",onClick:()=>{d(e),s(!0)},size:"sm",type:"button",variant:"secondary",children:"Edit"}),Object(F.jsx)(l.IconButton,{name:"trash-alt",onClick:()=>{const e=[...i];e.splice(t,1),n(e)},type:"button"})]})},size:"100px"}],b=Object(a.useMemo)(()=>((e,t)=>e.map((e,n)=>{var a;return{id:null!==(a=null==t?void 0:t(e))&&void 0!==a?a:n,data:e}}))(i),[i]);return Object(a.useEffect)(()=>{e&&b.length&&u(b[b.length-1].id)},[e,b]),Object(F.jsx)(Y.a,{cols:j,isExpandable:!0,items:b,testIdGenerator:()=>"am-routes-row",onCollapse:p,onExpand:d,isExpanded:e=>c===e.id,renderExpandedContent:(a,l)=>e||o?Object(F.jsx)(le,{onCancel:()=>{e&&t(),s(!1)},onSave:e=>{const t=[...i];t[l]=pe({},t[l],e),s(!1),n(t)},receivers:r,routes:a.data}):Object(F.jsx)(ce,{onChange:e=>{const t=[...i];t[l]=pe({},a.data,e),n(t)},receivers:r,routes:a.data})})};var be,me;function ge(){return(ge=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}const ve=({onChange:e,onRootRouteEdit:t,receivers:n,routes:r})=>{const[i,o]=Object(a.useState)(r.routes),[s,c]=Object(a.useState)(!1),u=Object(l.useStyles2)(he),d=()=>{c(!0),o(e=>[...e,ge({},O,{matchers:[f]})])};return Object(F.jsxs)("div",{className:u.container,children:[be||(be=Object(F.jsx)("h5",{children:"Specific routing"})),me||(me=Object(F.jsx)("p",{children:"Send specific alerts to chosen contact points, based on matching criteria"})),r.receiver?i.length>0?Object(F.jsxs)(F.Fragment,{children:[!s&&Object(F.jsx)(l.Button,{className:u.addMatcherBtn,icon:"plus",onClick:d,type:"button",children:"New policy"}),Object(F.jsx)(je,{isAddMode:s,onCancelAdd:()=>{c(!1),o(e=>{const t=[...e];return t.pop(),t})},onChange:t=>{e(ge({},r,{routes:t})),s&&c(!1)},receivers:n,routes:i})]}):Object(F.jsx)(K,{buttonIcon:"plus",buttonLabel:"New specific policy",onButtonClick:d,text:"You haven't created any specific policies yet."}):Object(F.jsx)(K,{buttonIcon:"rocket",buttonLabel:"Set a default contact point",onButtonClick:t,text:"You haven't set a default contact point for the root route yet."})]})},he=e=>({container:r.css`
      display: flex;
      flex-flow: column nowrap;
    `,addMatcherBtn:r.css`
      align-self: flex-end;
      margin-bottom: ${e.spacing(3.5)};
    `});var fe,Oe,xe=n("dEXO"),ye=n("w+lj"),Ce=n("4Yfp"),Ie=n("fXZ9");function we(){return(we=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}t.default=Object(l.withErrorBoundary)(()=>{var e;const t=Object(i.useDispatch)(),n=Object(l.useStyles2)(Se),[r,d]=Object(a.useState)(!1),[p,j]=Object(xe.a)(),b=Object(ye.a)(e=>e.amConfigs),m=Object(a.useCallback)(()=>{p&&t(Object(Ce.i)(p))},[p,t]);Object(a.useEffect)(()=>{m()},[m]);const{result:g,loading:v,error:h}=p&&b[p]||Ie.c,f=null==g?void 0:g.alertmanager_config,[O,C]=Object(a.useMemo)(()=>x(null==f?void 0:f.route),[null==f?void 0:f.route]),w=I((null!==(e=null==f?void 0:f.receivers)&&void 0!==e?e:[]).map(e=>e.name)),S=()=>{d(!0)},$=()=>{d(!1)};Object(s.a)(e=>e.unifiedAlerting.saveAMConfig);const N=e=>{const n=y(we({},O,e),C);r&&$(),t(Object(Ce.u)({newConfig:we({},g,{alertmanager_config:we({},g.alertmanager_config,{route:n})}),oldConfig:g,alertManagerSourceName:p,successMessage:"Saved",refetch:!0}))};return p?Object(F.jsxs)(c.a,{pageId:"am-routes",children:[Object(F.jsx)(u.a,{current:p,onChange:j}),h&&!v&&Object(F.jsx)(l.Alert,{severity:"error",title:"Error loading Alertmanager config",children:h.message||"Unknown error."}),v&&(Oe||(Oe=Object(F.jsx)(l.LoadingPlaceholder,{text:"Loading Alertmanager config..."}))),g&&!v&&!h&&Object(F.jsxs)(F.Fragment,{children:[Object(F.jsx)(D,{alertManagerSourceName:p,isEditMode:r,onSave:N,onEnterEditMode:S,onExitEditMode:$,receivers:w,routes:O}),Object(F.jsx)("div",{className:n.break}),Object(F.jsx)(ve,{onChange:N,onRootRouteEdit:S,receivers:w,routes:O})]})]}):fe||(fe=Object(F.jsx)(o.c,{to:"/alerting/routes"}))},{style:"page"});const Se=e=>({break:r.css`
    width: 100%;
    height: 0;
    margin-bottom: ${e.spacing(2)};
    border-bottom: solid 1px ${e.colors.border.medium};
  `})},Jv5Q:function(e,t,n){"use strict";n.d(t,"a",(function(){return c}));var a=n("q1tI"),r=n("kDLi"),l=n("vF1F"),i=n("A5n/"),o=n("Sp9v"),s=n("nKUr");const c=({matchers:e,onRemoveLabel:t})=>{const n=Object(r.useStyles)(u),l=Object(a.useCallback)(e=>{t&&t(e)},[t]);return Object(s.jsx)("div",{className:n.wrapper,children:e.map((e,n)=>{const{name:a,value:r}=e;return Object(s.jsx)(i.a,{labelKey:a,value:r,operator:Object(o.d)(e),onRemoveLabel:t?()=>l(n):void 0},`${a}-${r}-${n}`)})})},u=e=>({wrapper:l.css`
    & > * {
      margin-top: ${e.spacing.xs};
      margin-right: ${e.spacing.xs};
    }
    padding-bottom: ${e.spacing.xs};
  `})},SGmB:function(e,t,n){"use strict";n.d(t,"a",(function(){return i}));var a=n("q1tI"),r=n("/MKj"),l=n("zVNn");function i(e){const t=Object(r.useDispatch)(),n=Object(a.useRef)(e);n.current=e,Object(a.useEffect)(()=>()=>{t(Object(l.a)({stateSelector:n.current}))},[t])}},URgk:function(e,t,n){(function(e){var a=void 0!==e&&e||"undefined"!=typeof self&&self||window,r=Function.prototype.apply;function l(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new l(r.call(setTimeout,a,arguments),clearTimeout)},t.setInterval=function(){return new l(r.call(setInterval,a,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},l.prototype.unref=l.prototype.ref=function(){},l.prototype.close=function(){this._clearFn.call(a,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout((function(){e._onTimeout&&e._onTimeout()}),t))},n("YBdB"),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,n("yLpj"))},YBdB:function(e,t,n){(function(e,t){!function(e,n){"use strict";if(!e.setImmediate){var a,r,l,i,o,s=1,c={},u=!1,d=e.document,p=Object.getPrototypeOf&&Object.getPrototypeOf(e);p=p&&p.setTimeout?p:e,"[object process]"==={}.toString.call(e.process)?a=function(e){t.nextTick((function(){b(e)}))}:!function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?e.MessageChannel?((l=new MessageChannel).port1.onmessage=function(e){b(e.data)},a=function(e){l.port2.postMessage(e)}):d&&"onreadystatechange"in d.createElement("script")?(r=d.documentElement,a=function(e){var t=d.createElement("script");t.onreadystatechange=function(){b(e),t.onreadystatechange=null,r.removeChild(t),t=null},r.appendChild(t)}):a=function(e){setTimeout(b,0,e)}:(i="setImmediate$"+Math.random()+"$",o=function(t){t.source===e&&"string"==typeof t.data&&0===t.data.indexOf(i)&&b(+t.data.slice(i.length))},e.addEventListener?e.addEventListener("message",o,!1):e.attachEvent("onmessage",o),a=function(t){e.postMessage(i+t,"*")}),p.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n<t.length;n++)t[n]=arguments[n+1];var r={callback:e,args:t};return c[s]=r,a(s),s++},p.clearImmediate=j}function j(e){delete c[e]}function b(e){if(u)setTimeout(b,0,e);else{var t=c[e];if(t){u=!0;try{!function(e){var t=e.callback,n=e.args;switch(n.length){case 0:t();break;case 1:t(n[0]);break;case 2:t(n[0],n[1]);break;case 3:t(n[0],n[1],n[2]);break;default:t.apply(void 0,n)}}(t)}finally{j(e),u=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(this,n("yLpj"),n("8oxB"))},dEXO:function(e,t,n){"use strict";n.d(t,"a",(function(){return c}));var a=n("9f6O"),r=n("SMGL"),l=n("q1tI"),i=n("d6cI"),o=n("Jzaf");function s(e){return e===o.b||!!Object(o.c)().find(t=>t.name===e)}function c(){const[e,t]=Object(a.a)(),n=Object(l.useCallback)(e=>{s(e)&&(e===o.b?(r.a.delete(i.a),t({[i.b]:null})):(r.a.set(i.a,e),t({[i.b]:e})))},[t]),c=e[i.b];if(c&&"string"==typeof c)return s(c)?[c,n]:[void 0,n];const u=r.a.get(i.a);return u&&"string"==typeof u&&s(u)?(n(u),[u,n]):[o.b,n]}},lcDh:function(e,t,n){"use strict";n.d(t,"a",(function(){return c}));var a=n("Jzaf"),r=n("q1tI"),l=n("kDLi"),i=n("pz/R"),o=n("vF1F"),s=n("nKUr");const c=({onChange:e,current:t,disabled:n=!1})=>{const o=Object(l.useStyles2)(u),c=Object(r.useMemo)(()=>[{label:"Grafana",value:a.b,imgUrl:"public/img/grafana_icon.svg",meta:{}},...Object(i.a)().filter(e=>e.type===a.a.Alertmanager).map(e=>({label:e.name.substr(0,37),value:e.name,imgUrl:e.meta.info.logos.small,meta:e.meta}))],[]);return 1===c.length?null:Object(s.jsx)(l.Field,{className:o.field,label:n?"Alertmanager":"Choose Alertmanager",disabled:n,"data-testid":"alertmanager-picker",children:Object(s.jsx)(l.Select,{menuShouldPortal:!0,width:29,className:"ds-picker select-container",backspaceRemovesValue:!1,onChange:t=>t.value&&e(t.value),options:c,maxMenuHeight:500,noOptionsMessage:"No datasources found",value:t,getOptionLabel:e=>e.label})})},u=e=>({field:o.css`
    margin-bottom: ${e.spacing(4)};
  `})},"sbt+":function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));n("q1tI");var a=n("ZGyg"),r=n("lzJ5"),l=n("/MKj"),i=n("nKUr");const o=({children:e,pageId:t,isLoading:n})=>{const o=Object(r.a)(Object(l.useSelector)(e=>e.navIndex),t);return Object(i.jsx)(a.b,{navModel:o,children:Object(i.jsx)(a.b.Contents,{isLoading:n,children:e})})}},wDOy:function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var a=n("q1tI"),r=n("vF1F"),l=n("kDLi"),i=n("nKUr");const o=({cols:e,items:t,isExpandable:n=!1,onCollapse:o,onExpand:c,isExpanded:u,renderExpandedContent:d,testIdGenerator:p,renderPrefixCell:j,renderPrefixHeader:b})=>{if((o||c||u)&&!(o&&c&&u))throw new Error("either all of onCollapse, onExpand, isExpanded must be provided, or none");if((n||d)&&(!n||!d))throw new Error("either both isExpanded and renderExpandedContent must be provided, or neither");const m=Object(l.useStyles2)(s(e,n,!!b)),[g,v]=Object(a.useState)([]);return Object(i.jsxs)("div",{className:m.container,"data-testid":"dynamic-table",children:[Object(i.jsxs)("div",{className:m.row,"data-testid":"header",children:[b&&b(),n&&Object(i.jsx)("div",{className:m.cell}),e.map(e=>Object(i.jsx)("div",{className:m.cell,children:e.label},e.id))]}),t.map((a,s)=>{var b;const h=u?u(a):g.includes(a.id);return Object(i.jsxs)("div",{className:m.row,"data-testid":null!==(b=null==p?void 0:p(a,s))&&void 0!==b?b:"row",children:[j&&j(a,s,t),n&&Object(i.jsx)("div",{className:Object(r.cx)(m.cell,m.expandCell),children:Object(i.jsx)(l.IconButton,{size:"xl","data-testid":"collapse-toggle",className:m.expandButton,name:h?"angle-down":"angle-right",onClick:()=>(e=>{u&&o&&c?u(e)?o(e):c(e):v(g.includes(e.id)?g.filter(t=>t!==e.id):[...g,e.id])})(a),type:"button"})}),e.map(e=>Object(i.jsx)("div",{className:Object(r.cx)(m.cell,m.bodyCell),"data-column":e.label,children:e.renderCell(a,s)},`${a.id}-${e.id}`)),h&&d&&Object(i.jsx)("div",{className:m.expandedContentRow,"data-testid":"expanded-content",children:d(a,s,t)})]},a.id)})]})},s=(e,t,n)=>{const a=e.map(e=>e.size?"number"==typeof e.size?e.size+"fr":e.size:"auto");return t&&a.unshift("calc(1em + 16px)"),n&&a.unshift("0"),e=>({container:r.css`
      border: 1px solid ${e.colors.border.strong};
      border-radius: 2px;
      color: ${e.colors.text.secondary};
    `,row:r.css`
      display: grid;
      grid-template-columns: ${a.join(" ")};
      grid-template-rows: 1fr auto;

      &:nth-child(2n + 1) {
        background-color: ${e.colors.background.secondary};
      }

      &:nth-child(2n) {
        background-color: ${e.colors.background.primary};
      }

      ${e.breakpoints.down("sm")} {
        grid-template-columns: auto 1fr;
        grid-template-areas: 'left right';
        padding: 0 ${e.spacing(.5)};

        &:first-child {
          display: none;
        }

        ${n?"\n            & > *:first-child {\n              display: none;\n            }\n          ":""}
      }
    `,cell:r.css`
      align-items: center;
      padding: ${e.spacing(1)};

      ${e.breakpoints.down("sm")} {
        padding: ${e.spacing(1)} 0;
        grid-template-columns: 1fr;
      }
    `,bodyCell:r.css`
      overflow: hidden;
      word-break: break-all;
      ${e.breakpoints.down("sm")} {
        grid-column-end: right;
        grid-column-start: right;

        &::before {
          content: attr(data-column);
          display: block;
          color: ${e.colors.text.primary};
        }
      }
    `,expandCell:r.css`
      justify-content: center;

      ${e.breakpoints.down("sm")} {
        align-items: start;
        grid-area: left;
      }
    `,expandedContentRow:r.css`
      grid-column-end: ${a.length+1};
      grid-column-start: ${n?3:2};
      grid-row: 2;
      padding: 0 ${e.spacing(3)} 0 ${e.spacing(1)};
      position: relative;

      ${e.breakpoints.down("sm")} {
        grid-column-start: 2;
        border-top: 1px solid ${e.colors.border.strong};
        grid-row: auto;
        padding: ${e.spacing(1)} 0 0 0;
      }
    `,expandButton:r.css`
      margin-right: 0;
      display: block;
    `})}}}]);
//# sourceMappingURL=AlertAmRoutes.4bfd7b0ee99616560b7a.js.map