"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8648],{"./public/app/core/hooks/useCleanup.ts":(e,t,n)=>{n.d(t,{x:()=>l});var a=n("./node_modules/react/index.js"),r=n("./node_modules/react-redux/es/index.js"),s=n("./public/app/core/actions/cleanUp.ts");function l(e){const t=(0,r.useDispatch)(),n=(0,a.useRef)(e);n.current=e,(0,a.useEffect)((()=>()=>{t((0,s.e)({stateSelector:n.current}))}),[t])}},"./public/app/core/hooks/useQueryParams.ts":(e,t,n)=>{n.d(t,{K:()=>l});var a=n("./packages/grafana-runtime/src/index.ts"),r=n("./node_modules/react/index.js"),s=n("./node_modules/react-router/esm/react-router.js");function l(){const{search:e}=(0,s.TH)();return[(0,r.useMemo)((()=>(0,a.locationSearchToObject)(e||"")),[e]),(0,r.useCallback)(((e,t)=>setImmediate((()=>a.locationService.partial(e,t)))),[])]}},"./public/app/features/alerting/unified/AmRoutes.tsx":(e,t,n)=>{n.r(t),n.d(t,{default:()=>ye});var a=n("./node_modules/react/index.js"),r=n("./node_modules/@emotion/css/dist/emotion-css.esm.js"),s=n("./packages/grafana-ui/src/index.ts"),l=n("./node_modules/react-redux/es/index.js"),i=n("./node_modules/react-router/esm/react-router.js"),o=n("./public/app/core/hooks/useCleanup.ts"),c=n("./public/app/features/alerting/unified/components/AlertingPageWrapper.tsx"),d=n("./public/app/features/alerting/unified/components/AlertManagerPicker.tsx"),u=n("./public/app/plugins/datasource/alertmanager/types.ts"),p=n("./public/app/features/alerting/unified/utils/time.ts"),g=n("./node_modules/lodash/lodash.js"),m=n("./public/app/features/alerting/unified/utils/alertmanager.ts"),v=n("./public/app/features/alerting/unified/utils/datasource.ts");const h=["",p.qr[0].value],x=(e,t)=>Object.entries(null!=e?e:{}).reduce(((e,[n,a])=>[...e,{name:n,value:a,operator:t?u._M.regex:u._M.equal}]),[]),j=e=>{if(!e)return h;const[t,n]=e?(0,p.bG)(e):[void 0,void 0],a=p.qr.find((e=>e.value===n));return t&&a?[String(t),a.value]:h},f=e=>e.value,b={name:"",value:"",operator:u._M.equal},C={id:"",groupBy:[],object_matchers:[],routes:[],continue:!1,receiver:"",groupWaitValue:"",groupWaitValueType:p.qr[0].value,groupIntervalValue:"",groupIntervalValueType:p.qr[0].value,repeatIntervalValue:"",repeatIntervalValueType:p.qr[0].value},y=e=>{var t,n,a,r,s,l,i,o;if(!e||0===Object.keys(e).length)return[C,{}];const[c,d]=j(e.group_wait),[u,p]=j(e.group_interval),[g,v]=j(e.repeat_interval),h=String(Math.random()),f={[h]:e},b=[];null===(t=e.routes)||void 0===t||t.forEach((e=>{const[t,n]=y(e);b.push(t),Object.assign(f,n)}));return[{id:h,object_matchers:[...e.matchers?null!==(n=null===(a=e.matchers)||void 0===a?void 0:a.map((e=>(0,m.cm)((0,m.tC)(e)))))&&void 0!==n?n:[]:null!==(r=null===(s=e.object_matchers)||void 0===s?void 0:s.map((e=>({name:e[0],operator:e[1],value:e[2]}))))&&void 0!==r?r:[],...x(e.match,!1),...x(e.match_re,!0)],continue:null!==(l=e.continue)&&void 0!==l&&l,receiver:null!==(i=e.receiver)&&void 0!==i?i:"",groupBy:null!==(o=e.group_by)&&void 0!==o?o:[],groupWaitValue:c,groupWaitValueType:d,groupIntervalValue:u,groupIntervalValueType:p,repeatIntervalValue:g,repeatIntervalValueType:v,routes:b},f]},$=(e,t,n)=>{const a=n[t.id],r=Object.assign({},null!=a?a:{},{continue:t.continue,group_by:t.groupBy,object_matchers:t.object_matchers.length?t.object_matchers.map((e=>[e.name,e.operator,e.value])):void 0,match:void 0,match_re:void 0,group_wait:t.groupWaitValue?`${t.groupWaitValue}${t.groupWaitValueType}`:void 0,group_interval:t.groupIntervalValue?`${t.groupIntervalValue}${t.groupIntervalValueType}`:void 0,repeat_interval:t.repeatIntervalValue?`${t.repeatIntervalValue}${t.repeatIntervalValueType}`:void 0,routes:t.routes.map((t=>$(e,t,n)))});return e!==v.GC?(r.matchers=t.object_matchers.map((({name:e,operator:t,value:n})=>`${e}${t}${n}`)),r.object_matchers=void 0):r.matchers=void 0,t.receiver&&(r.receiver=t.receiver),(0,g.omitBy)(r,g.isUndefined)},I=e=>({label:e,value:e}),S=e=>(null!=e?e:[]).map(I),N=e=>{var t;return e&&null!==(t=f(e))&&void 0!==t?t:""},V=e=>{return e?(null!=(t=e)?t:[]).map(f):[];var t},w=e=>{if(e)return/^\d+$/.test(e)?void 0:"Must be a positive integer."};var k=n("./public/app/features/alerting/unified/utils/misc.ts");const _=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 O,B,M=n("./node_modules/react/jsx-runtime.js");const E=["onChange","ref"],F=["onChange","ref"],T=["onChange","ref"],A=["onChange","ref"],G=["onChange","ref"];function W(e,t){if(null==e)return{};var n,a,r={},s=Object.keys(e);for(a=0;a<s.length;a++)n=s[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}const P=({alertManagerSourceName:e,onCancel:t,onSave:n,receivers:l,routes:i})=>{var o;const c=(0,s.useStyles2)(_),[d,u]=(0,a.useState)(!1),[g,m]=(0,a.useState)(S(i.groupBy));return(0,M.jsx)(s.Form,{defaultValues:i,onSubmit:n,children:({control:n,errors:a,setValue:i})=>{var v,h,x,j;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(s.Field,{label:"Default contact point",invalid:!!a.receiver,error:null===(v=a.receiver)||void 0===v?void 0:v.message,children:(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)("div",{className:c.container,"data-testid":"am-receiver-select",children:[(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=W(e.field,E);return(0,M.jsx)(s.Select,Object.assign({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(N(e)),options:l}))},control:n,name:"receiver",rules:{required:{value:!0,message:"Required."}}}),O||(O=(0,M.jsx)("span",{children:"or"})),(0,M.jsx)(s.Link,{href:(0,k.eQ)("/alerting/notifications/receivers/new",e),children:"Create a contact point"})]})})}),(0,M.jsx)(s.Field,{label:"Group by",description:"Group alerts when you receive a notification based on labels.","data-testid":"am-group-select",children:(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=W(e.field,F);return(0,M.jsx)(s.MultiSelect,Object.assign({menuShouldPortal:!0},n,{allowCustomValue:!0,className:c.input,onCreateOption:e=>{m((t=>[...t,I(e)])),i("groupBy",[...n.value,e])},onChange:e=>t(V(e)),options:g}))},control:n,name:"groupBy"})}),(0,M.jsxs)(s.Collapse,{collapsible:!0,isOpen:d,label:"Timing options",onToggle:u,children:[(0,M.jsx)(s.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===(h=a.groupWaitValue)||void 0===h?void 0:h.message,"data-testid":"am-group-wait",children:(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)("div",{className:(0,r.cx)(c.container,c.timingContainer),children:[(0,M.jsx)(s.InputControl,{render:({field:e,fieldState:{invalid:t}})=>(0,M.jsx)(s.Input,Object.assign({},e,{className:c.smallInput,invalid:t})),control:n,name:"groupWaitValue",rules:{validate:w}}),(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=W(e.field,T);return(0,M.jsx)(s.Select,Object.assign({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(N(e)),options:p.qr}))},control:n,name:"groupWaitValueType"})]})})}),(0,M.jsx)(s.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===(x=a.groupIntervalValue)||void 0===x?void 0:x.message,"data-testid":"am-group-interval",children:(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)("div",{className:(0,r.cx)(c.container,c.timingContainer),children:[(0,M.jsx)(s.InputControl,{render:({field:e,fieldState:{invalid:t}})=>(0,M.jsx)(s.Input,Object.assign({},e,{className:c.smallInput,invalid:t})),control:n,name:"groupIntervalValue",rules:{validate:w}}),(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=W(e.field,A);return(0,M.jsx)(s.Select,Object.assign({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(N(e)),options:p.qr}))},control:n,name:"groupIntervalValueType"})]})})}),(0,M.jsx)(s.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===(j=a.repeatIntervalValue)||void 0===j?void 0:j.message,"data-testid":"am-repeat-interval",children:(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)("div",{className:(0,r.cx)(c.container,c.timingContainer),children:[(0,M.jsx)(s.InputControl,{render:({field:e,fieldState:{invalid:t}})=>(0,M.jsx)(s.Input,Object.assign({},e,{className:c.smallInput,invalid:t})),control:n,name:"repeatIntervalValue",rules:{validate:w}}),(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=W(e.field,G);return(0,M.jsx)(s.Select,Object.assign({menuShouldPortal:!0},n,{className:c.input,menuPlacement:"top",onChange:e=>t(N(e)),options:p.qr}))},control:n,name:"repeatIntervalValueType"})]})})})]}),(0,M.jsxs)("div",{className:c.container,children:[B||(B=(0,M.jsx)(s.Button,{type:"submit",children:"Save"})),o||(o=(0,M.jsx)(s.Button,{onClick:t,type:"reset",variant:"secondary",fill:"outline",children:"Cancel"}))]})]})}})},q=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)};
    `}),R=({routes:e})=>{const t=(0,s.useStyles2)(q),n=e.receiver||"-",a=e.groupBy.join(", ")||"-",r=e.groupWaitValue?`${e.groupWaitValue}${e.groupWaitValueType}`:"-",l=e.groupIntervalValue?`${e.groupIntervalValue}${e.groupIntervalValueType}`:"-",i=e.repeatIntervalValue?`${e.repeatIntervalValue}${e.repeatIntervalValueType}`:"-";return(0,M.jsxs)("div",{className:t.container,children:[(0,M.jsx)("div",{className:t.titleCell,children:"Contact point"}),(0,M.jsx)("div",{className:t.valueCell,"data-testid":"am-routes-root-receiver",children:n}),(0,M.jsx)("div",{className:t.titleCell,children:"Group by"}),(0,M.jsx)("div",{className:t.valueCell,"data-testid":"am-routes-root-group-by",children:a}),(0,M.jsx)("div",{className:t.titleCell,children:"Timings"}),(0,M.jsxs)("div",{className:t.valueCell,"data-testid":"am-routes-root-timings",children:["Group wait: ",r," | Group interval: ",l," | Repeat interval: ",i]})]})};var z,L;const D=({isEditMode:e,onSave:t,onEnterEditMode:n,onExitEditMode:a,receivers:r,routes:l,alertManagerSourceName:i})=>{const o=(0,s.useStyles2)(Y),c=(0,v.RY)(i);return(0,M.jsxs)("div",{className:o.container,"data-testid":"am-root-route-container",children:[(0,M.jsxs)("div",{className:o.titleContainer,children:[(0,M.jsxs)("h5",{className:o.title,children:["Root policy - ",z||(z=(0,M.jsx)("i",{children:"default for all alerts"}))]}),!e&&!c&&(0,M.jsx)(s.Button,{icon:"pen",onClick:n,size:"sm",type:"button",variant:"secondary",children:"Edit"})]}),L||(L=(0,M.jsx)("p",{children:"All alerts will go to the default contact point, unless you set additional matchers in the specific routing area."})),e?(0,M.jsx)(P,{alertManagerSourceName:i,onCancel:a,onSave:t,receivers:r,routes:l}):(0,M.jsx)(R,{routes:l})]})},Y=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%;
    `}),Z=({buttonIcon:e,buttonLabel:t,buttonSize:n="lg",buttonVariant:a="primary",onButtonClick:r,text:l})=>{const i=(0,s.useStyles)(H);return(0,M.jsxs)("div",{className:i.container,children:[(0,M.jsx)("p",{className:i.text,children:l}),(0,M.jsx)(s.Button,{className:i.button,icon:e,onClick:r,size:n,type:"button",variant:a,children:t})]})},H=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 U=n("./public/app/features/alerting/unified/components/DynamicTable.tsx");const J=["onChange","ref"],K=["onChange","ref"],Q=["onChange","ref"],X=["onChange","ref"],ee=["onChange","ref"],te=["onChange","ref"];var ne,ae;function re(e,t){if(null==e)return{};var n,a,r={},s=Object.keys(e);for(a=0;a<s.length;a++)n=s[a],t.indexOf(n)>=0||(r[n]=e[n]);return r}const se=({onCancel:e,onSave:t,receivers:n,routes:l})=>{var i;const o=(0,s.useStyles2)(le),c=(0,s.useStyles2)(_),[d,u]=(0,a.useState)(l.groupBy.length>0),[g,v]=(0,a.useState)(!!l.groupWaitValue||!!l.groupIntervalValue||!!l.repeatIntervalValue),[h,x]=(0,a.useState)(S(l.groupBy));return(0,M.jsx)(s.Form,{defaultValues:l,onSubmit:t,children:({control:t,register:a,errors:l,setValue:j})=>{var f,C,y;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)("input",Object.assign({type:"hidden"},a("id"))),(0,M.jsx)(s.FieldArray,{name:"object_matchers",control:t,children:({fields:e,append:n,remove:r})=>(0,M.jsxs)(M.Fragment,{children:[ne||(ne=(0,M.jsx)("div",{children:"Matching labels"})),(0,M.jsx)("div",{className:o.matchersContainer,children:e.map(((e,n)=>{var i,c,d,u,p,g,v,h,x,j;const f=`object_matchers[${n}]`;return(0,M.jsxs)(s.HorizontalGroup,{align:"flex-start",children:[(0,M.jsx)(s.Field,{label:"Label",invalid:!(null===(i=l.object_matchers)||void 0===i||null===(c=i[n])||void 0===c||!c.name),error:null===(d=l.object_matchers)||void 0===d||null===(u=d[n])||void 0===u||null===(p=u.name)||void 0===p?void 0:p.message,children:(0,M.jsx)(s.Input,Object.assign({},a(`${f}.name`,{required:"Field is required"}),{defaultValue:e.name,placeholder:"label"}))}),(0,M.jsx)(s.Field,{label:"Operator",children:(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=re(e.field,J);return(0,M.jsx)(s.Select,Object.assign({},n,{className:o.matchersOperator,onChange:e=>t(null==e?void 0:e.value),options:m.tA}))},defaultValue:e.operator,control:t,name:`${f}.operator`,rules:{required:{value:!0,message:"Required."}}})}),(0,M.jsx)(s.Field,{label:"Value",invalid:!(null===(g=l.object_matchers)||void 0===g||null===(v=g[n])||void 0===v||!v.value),error:null===(h=l.object_matchers)||void 0===h||null===(x=h[n])||void 0===x||null===(j=x.value)||void 0===j?void 0:j.message,children:(0,M.jsx)(s.Input,Object.assign({},a(`${f}.value`,{required:"Field is required"}),{defaultValue:e.value,placeholder:"value"}))}),(0,M.jsx)(s.IconButton,{className:o.removeButton,tooltip:"Remove matcher",name:"trash-alt",onClick:()=>r(n),children:"Remove"})]},e.id)}))}),(0,M.jsx)(s.Button,{className:o.addMatcherBtn,icon:"plus",onClick:()=>n(b),variant:"secondary",type:"button",children:"Add matcher"})]})}),(0,M.jsx)(s.Field,{label:"Contact point",children:(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,a=re(e.field,K);return(0,M.jsx)(s.Select,Object.assign({menuShouldPortal:!0},a,{className:c.input,onChange:e=>t(N(e)),options:n}))},control:t,name:"receiver"})}),(0,M.jsx)(s.Field,{label:"Continue matching subsequent sibling nodes",children:(0,M.jsx)(s.Switch,Object.assign({},a("continue")))}),(0,M.jsx)(s.Field,{label:"Override grouping",children:(0,M.jsx)(s.Switch,{value:d,onChange:()=>u((e=>!e))})}),d&&(0,M.jsx)(s.Field,{label:"Group by",description:"Group alerts when you receive a notification based on labels.",children:(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=re(e.field,Q);return(0,M.jsx)(s.MultiSelect,Object.assign({menuShouldPortal:!0},n,{allowCustomValue:!0,className:c.input,onCreateOption:e=>{x((t=>[...t,I(e)])),j("groupBy",[...n.value,e])},onChange:e=>t(V(e)),options:h}))},control:t,name:"groupBy"})}),(0,M.jsx)(s.Field,{label:"Override general timings",children:(0,M.jsx)(s.Switch,{value:g,onChange:()=>v((e=>!e))})}),g&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(s.Field,{label:"Group wait",description:"The waiting time until the initial notification is sent for a new group created by an incoming alert.",invalid:!!l.groupWaitValue,error:null===(f=l.groupWaitValue)||void 0===f?void 0:f.message,children:(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)("div",{className:(0,r.cx)(c.container,c.timingContainer),children:[(0,M.jsx)(s.InputControl,{render:({field:e,fieldState:{invalid:t}})=>(0,M.jsx)(s.Input,Object.assign({},e,{className:c.smallInput,invalid:t})),control:t,name:"groupWaitValue",rules:{validate:w}}),(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=re(e.field,X);return(0,M.jsx)(s.Select,Object.assign({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(N(e)),options:p.qr}))},control:t,name:"groupWaitValueType"})]})})}),(0,M.jsx)(s.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:!!l.groupIntervalValue,error:null===(C=l.groupIntervalValue)||void 0===C?void 0:C.message,children:(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)("div",{className:(0,r.cx)(c.container,c.timingContainer),children:[(0,M.jsx)(s.InputControl,{render:({field:e,fieldState:{invalid:t}})=>(0,M.jsx)(s.Input,Object.assign({},e,{className:c.smallInput,invalid:t})),control:t,name:"groupIntervalValue",rules:{validate:w}}),(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=re(e.field,ee);return(0,M.jsx)(s.Select,Object.assign({menuShouldPortal:!0},n,{className:c.input,onChange:e=>t(N(e)),options:p.qr}))},control:t,name:"groupIntervalValueType"})]})})}),(0,M.jsx)(s.Field,{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent.",invalid:!!l.repeatIntervalValue,error:null===(y=l.repeatIntervalValue)||void 0===y?void 0:y.message,children:(0,M.jsx)(M.Fragment,{children:(0,M.jsxs)("div",{className:(0,r.cx)(c.container,c.timingContainer),children:[(0,M.jsx)(s.InputControl,{render:({field:e,fieldState:{invalid:t}})=>(0,M.jsx)(s.Input,Object.assign({},e,{className:c.smallInput,invalid:t})),control:t,name:"repeatIntervalValue",rules:{validate:w}}),(0,M.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=re(e.field,te);return(0,M.jsx)(s.Select,Object.assign({menuShouldPortal:!0},n,{className:c.input,menuPlacement:"top",onChange:e=>t(N(e)),options:p.qr}))},control:t,name:"repeatIntervalValueType"})]})})})]}),(0,M.jsxs)("div",{className:o.buttonGroup,children:[ae||(ae=(0,M.jsx)(s.Button,{type:"submit",children:"Save policy"})),i||(i=(0,M.jsx)(s.Button,{onClick:e,fill:"outline",type:"button",variant:"secondary",children:"Cancel"}))]})]})}})},le=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;
    `,matchersOperator:r.css`
      min-width: 140px;
    `,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 ie;const oe=({onChange:e,receivers:t,routes:n,readOnly:r=!1})=>{const l=(0,s.useStyles2)(ce),i=(0,s.useStyles2)(q),o=n.groupWaitValue?`${n.groupWaitValue}${n.groupWaitValueType}`:"-",c=n.groupIntervalValue?`${n.groupIntervalValue}${n.groupIntervalValueType}`:"-",d=n.repeatIntervalValue?`${n.repeatIntervalValue}${n.repeatIntervalValueType}`:"-",[u,p]=(0,a.useState)(n.routes),[g,m]=(0,a.useState)(!1);return(0,M.jsxs)("div",{className:i.container,children:[(0,M.jsx)("div",{className:i.titleCell,children:"Group wait"}),(0,M.jsx)("div",{className:i.valueCell,children:o}),(0,M.jsx)("div",{className:i.titleCell,children:"Group interval"}),(0,M.jsx)("div",{className:i.valueCell,children:c}),(0,M.jsx)("div",{className:i.titleCell,children:"Repeat interval"}),(0,M.jsx)("div",{className:i.valueCell,children:d}),(0,M.jsx)("div",{className:i.titleCell,children:"Nested policies"}),(0,M.jsxs)("div",{className:i.valueCell,children:[u.length?(0,M.jsx)(ue,{isAddMode:g,onCancelAdd:()=>{m(!1),p((e=>{const t=[...e];return t.pop(),t}))},onChange:t=>{e(Object.assign({},n,{routes:t})),g&&m(!1)},receivers:t,routes:u}):ie||(ie=(0,M.jsx)("p",{children:"No nested policies configured."})),!g&&!r&&(0,M.jsx)(s.Button,{className:l.addNestedRoutingBtn,icon:"plus",onClick:()=>{p((e=>[...e,C])),m(!0)},variant:"secondary",type:"button",children:"Add nested policy"})]})]})},ce=e=>({addNestedRoutingBtn:r.css`
      margin-top: ${e.spacing(2)};
    `});var de=n("./public/app/features/alerting/unified/components/silences/Matchers.tsx");const ue=({isAddMode:e,onCancelAdd:t,onChange:n,receivers:r,routes:l,readOnly:i=!1})=>{const[o,c]=(0,a.useState)(!1),[d,u]=(0,a.useState)(),p=(0,a.useCallback)((e=>u(e.id)),[]),g=(0,a.useCallback)((()=>u(void 0)),[]),v=[{id:"matchingCriteria",label:"Matching labels",renderCell:e=>(0,M.jsx)(de.g,{matchers:e.data.object_matchers.map(m._J)}),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},...i?[]:[{id:"actions",label:"Actions",renderCell:(e,t)=>{if(e.renderExpandedContent)return null;return(0,M.jsxs)(s.HorizontalGroup,{children:[(0,M.jsx)(s.Button,{"data-testid":"edit-route",icon:"pen",onClick:()=>{p(e),c(!0)},size:"sm",type:"button",variant:"secondary",children:"Edit"}),(0,M.jsx)(s.IconButton,{"data-testid":"delete-route",name:"trash-alt",onClick:()=>{const e=[...l];e.splice(t,1),n(e)},type:"button"})]})},size:"100px"}]],h=(0,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}})))(l)),[l]);return(0,a.useEffect)((()=>{e&&h.length&&u(h[h.length-1].id)}),[e,h]),(0,M.jsx)(U.t,{cols:v,isExpandable:!0,items:h,testIdGenerator:()=>"am-routes-row",onCollapse:g,onExpand:p,isExpanded:e=>d===e.id,renderExpandedContent:(a,s)=>e||o?(0,M.jsx)(se,{onCancel:()=>{e&&t(),c(!1)},onSave:e=>{const t=[...l];t[s]=Object.assign({},t[s],e),c(!1),n(t)},receivers:r,routes:a.data}):(0,M.jsx)(oe,{onChange:e=>{const t=[...l];t[s]=Object.assign({},a.data,e),n(t)},receivers:r,routes:a.data,readOnly:i})})};var pe,ge;const me=({onChange:e,onRootRouteEdit:t,receivers:n,routes:r,readOnly:l=!1})=>{const[i,o]=(0,a.useState)(r.routes),[c,d]=(0,a.useState)(!1),u=(0,s.useStyles2)(ve),p=()=>{d(!0),o((e=>[...e,Object.assign({},C,{matchers:[b]})]))};return(0,M.jsxs)("div",{className:u.container,children:[pe||(pe=(0,M.jsx)("h5",{children:"Specific routing"})),ge||(ge=(0,M.jsx)("p",{children:"Send specific alerts to chosen contact points, based on matching criteria"})),r.receiver?i.length>0?(0,M.jsxs)(M.Fragment,{children:[!c&&!l&&(0,M.jsx)(s.Button,{className:u.addMatcherBtn,icon:"plus",onClick:p,type:"button",children:"New policy"}),(0,M.jsx)(ue,{isAddMode:c,readOnly:l,onCancelAdd:()=>{d(!1),o((e=>{const t=[...e];return t.pop(),t}))},onChange:t=>{e(Object.assign({},r,{routes:t})),c&&d(!1)},receivers:n,routes:i})]}):(0,M.jsx)(Z,{buttonIcon:"plus",buttonLabel:"New specific policy",onButtonClick:p,text:"You haven't created any specific policies yet."}):(0,M.jsx)(Z,{buttonIcon:"rocket",buttonLabel:"Set a default contact point",onButtonClick:t,text:"You haven't set a default contact point for the root route yet."})]})},ve=e=>({container:r.css`
      display: flex;
      flex-flow: column nowrap;
    `,addMatcherBtn:r.css`
      align-self: flex-end;
      margin-bottom: ${e.spacing(3.5)};
    `});var he,xe,je=n("./public/app/features/alerting/unified/hooks/useAlertManagerSourceName.ts"),fe=n("./public/app/features/alerting/unified/hooks/useUnifiedAlertingSelector.ts"),be=n("./public/app/features/alerting/unified/state/actions.ts"),Ce=n("./public/app/features/alerting/unified/utils/redux.ts");const ye=(0,s.withErrorBoundary)((()=>{var e;const t=(0,l.useDispatch)(),n=(0,s.useStyles2)($e),[r,u]=(0,a.useState)(!1),[p,g]=(0,je.k)(),m=!p||(0,v.RY)(p),h=(0,fe._)((e=>e.amConfigs)),x=(0,a.useCallback)((()=>{p&&t((0,be.Yh)(p))}),[p,t]);(0,a.useEffect)((()=>{x()}),[x]);const{result:j,loading:f,error:b}=p&&h[p]||Ce.oq,C=null==j?void 0:j.alertmanager_config,[I,N]=(0,a.useMemo)((()=>y(null==C?void 0:C.route)),[null==C?void 0:C.route]),V=S((null!==(e=null==C?void 0:C.receivers)&&void 0!==e?e:[]).map((e=>e.name))),w=()=>{u(!0)},k=()=>{u(!1)};(0,o.x)((e=>e.unifiedAlerting.saveAMConfig));const _=e=>{const n=$(p,Object.assign({},I,e),N);r&&k(),t((0,be.mM)({newConfig:Object.assign({},j,{alertmanager_config:Object.assign({},j.alertmanager_config,{route:n})}),oldConfig:j,alertManagerSourceName:p,successMessage:"Saved",refetch:!0}))};return p?(0,M.jsxs)(c.J,{pageId:"am-routes",children:[(0,M.jsx)(d.P,{current:p,onChange:g}),b&&!f&&(0,M.jsx)(s.Alert,{severity:"error",title:"Error loading Alertmanager config",children:b.message||"Unknown error."}),f&&(xe||(xe=(0,M.jsx)(s.LoadingPlaceholder,{text:"Loading Alertmanager config..."}))),j&&!f&&!b&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(D,{alertManagerSourceName:p,isEditMode:r,onSave:_,onEnterEditMode:w,onExitEditMode:k,receivers:V,routes:I}),(0,M.jsx)("div",{className:n.break}),(0,M.jsx)(me,{onChange:_,readOnly:m,onRootRouteEdit:w,receivers:V,routes:I})]})]}):he||(he=(0,M.jsx)(i.l_,{to:"/alerting/routes"}))}),{style:"page"}),$e=e=>({break:r.css`
    width: 100%;
    height: 0;
    margin-bottom: ${e.spacing(2)};
    border-bottom: solid 1px ${e.colors.border.medium};
  `})},"./public/app/features/alerting/unified/components/AlertingPageWrapper.tsx":(e,t,n)=>{n.d(t,{J:()=>i});n("./node_modules/react/index.js");var a=n("./public/app/core/components/Page/Page.tsx"),r=n("./public/app/core/selectors/navModel.ts"),s=n("./node_modules/react-redux/es/index.js"),l=n("./node_modules/react/jsx-runtime.js");const i=({children:e,pageId:t,isLoading:n})=>{const i=(0,r.h)((0,s.useSelector)((e=>e.navIndex)),t);return(0,l.jsx)(a.Z,{navModel:i,children:(0,l.jsx)(a.Z.Contents,{isLoading:n,children:e})})}},"./public/app/features/alerting/unified/components/DynamicTable.tsx":(e,t,n)=>{n.d(t,{t:()=>i});var a=n("./node_modules/react/index.js"),r=n("./node_modules/@emotion/css/dist/emotion-css.esm.js"),s=n("./packages/grafana-ui/src/index.ts"),l=n("./node_modules/react/jsx-runtime.js");const i=({cols:e,items:t,isExpandable:n=!1,onCollapse:i,onExpand:c,isExpanded:d,renderExpandedContent:u,testIdGenerator:p,renderPrefixCell:g,renderPrefixHeader:m})=>{if((i||c||d)&&!(i&&c&&d))throw new Error("either all of onCollapse, onExpand, isExpanded must be provided, or none");if((n||u)&&(!n||!u))throw new Error("either both isExpanded and renderExpandedContent must be provided, or neither");const v=(0,s.useStyles2)(o(e,n,!!m)),[h,x]=(0,a.useState)([]);return(0,l.jsxs)("div",{className:v.container,"data-testid":"dynamic-table",children:[(0,l.jsxs)("div",{className:v.row,"data-testid":"header",children:[m&&m(),n&&(0,l.jsx)("div",{className:v.cell}),e.map((e=>(0,l.jsx)("div",{className:v.cell,children:e.label},e.id)))]}),t.map(((a,o)=>{var m;const j=d?d(a):h.includes(a.id);return(0,l.jsxs)("div",{className:v.row,"data-testid":null!==(m=null==p?void 0:p(a,o))&&void 0!==m?m:"row",children:[g&&g(a,o,t),n&&(0,l.jsx)("div",{className:(0,r.cx)(v.cell,v.expandCell),children:(0,l.jsx)(s.IconButton,{size:"xl","data-testid":"collapse-toggle",className:v.expandButton,name:j?"angle-down":"angle-right",onClick:()=>(e=>{d&&i&&c?d(e)?i(e):c(e):x(h.includes(e.id)?h.filter((t=>t!==e.id)):[...h,e.id])})(a),type:"button"})}),e.map((e=>(0,l.jsx)("div",{className:(0,r.cx)(v.cell,v.bodyCell),"data-column":e.label,children:e.renderCell(a,o)},`${a.id}-${e.id}`))),j&&u&&(0,l.jsx)("div",{className:v.expandedContentRow,"data-testid":"expanded-content",children:u(a,o,t)})]},a.id)}))]})},o=(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;
    `})}},"./public/app/features/alerting/unified/components/silences/Matchers.tsx":(e,t,n)=>{n.d(t,{g:()=>c});var a=n("./node_modules/react/index.js"),r=n("./packages/grafana-ui/src/index.ts"),s=n("./node_modules/@emotion/css/dist/emotion-css.esm.js"),l=n("./public/app/features/alerting/unified/components/AlertLabel.tsx"),i=n("./public/app/features/alerting/unified/utils/alertmanager.ts"),o=n("./node_modules/react/jsx-runtime.js");const c=({matchers:e,onRemoveLabel:t})=>{const n=(0,r.useStyles)(d),s=(0,a.useCallback)((e=>{t&&t(e)}),[t]);return(0,o.jsx)("div",{className:n.wrapper,children:e.map(((e,n)=>{const{name:a,value:r}=e;return(0,o.jsx)(l.i,{labelKey:a,value:r,operator:(0,i.zy)(e),onRemoveLabel:t?()=>s(n):void 0},`${a}-${r}-${n}`)}))})},d=e=>({wrapper:s.css`
    & > * {
      margin-top: ${e.spacing.xs};
      margin-right: ${e.spacing.xs};
    }
    padding-bottom: ${e.spacing.xs};
  `})},"./public/app/features/alerting/unified/hooks/useAlertManagerSourceName.ts":(e,t,n)=>{n.d(t,{k:()=>c});var a=n("./public/app/core/hooks/useQueryParams.ts"),r=n("./public/app/core/store.ts"),s=n("./node_modules/react/index.js"),l=n("./public/app/features/alerting/unified/utils/constants.ts"),i=n("./public/app/features/alerting/unified/utils/datasource.ts");function o(e){return e===i.GC||!!(0,i.aM)().find((t=>t.name===e))}function c(){const[e,t]=(0,a.K)(),n=(0,s.useCallback)((e=>{o(e)&&(e===i.GC?(r.Z.delete(l.de),t({[l.c4]:null})):(r.Z.set(l.de,e),t({[l.c4]:e})))}),[t]),c=e[l.c4];if(c&&"string"==typeof c)return o(c)?[c,n]:[void 0,n];const d=r.Z.get(l.de);return d&&"string"==typeof d&&o(d)?(n(d),[d,n]):[i.GC,n]}}}]);
//# sourceMappingURL=AlertAmRoutes.8128b05ac04b15cbf98d.js.map