"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8050],{8050:(ie,N,n)=>{n.r(N),n.d(N,{default:()=>se});var o=n(42844),t=n(27702),$=n(66310),L=n(63439),A=n(52419),B=n(37647),m=n(86954),M=n(89949),D=n(6772),K=n.n(D),k=n(73195),b=n(66670),S=n(64714),h=n(86004),W=n(10759),T=n(218),j=n(67045),w=n(54915);function P(e){return e.path?.length===0}function z(e){const r=new Map;function c(s,i=[]){r.set(s.id,{...s,path:i}),s.routes?.forEach(a=>c(a,[...i,s.id]))}return c(e,[]),r}function I(e){return e.object_matchers?.length===0}function F({route:e}){const r=(0,$.wW)(H);return P(e)?t.createElement("div",{className:r.defaultPolicy},"Default policy"):I(e)?t.createElement("div",{className:r.textMuted},"No matchers"):t.createElement(w.g,{matchers:e.object_matchers??[]})}const H=e=>({defaultPolicy:(0,o.css)`
    padding: ${e.spacing(.5)};
    background: ${e.colors.background.secondary};
    width: fit-content;
  `,textMuted:(0,o.css)`
    color: ${e.colors.text.secondary};
  `});var O=n(13741),G=n(73453),U=n(2082),Y=n(39036),Z=n(89439);function J({route:e,routesByIdMap:r}){const c=(0,$.wW)(R),s=e.path?.slice(1)??[],i=[...(0,M.compact)(s.map(a=>r.get(a))),e];return t.createElement("div",{className:c.policyPathWrapper},t.createElement("div",{className:c.defaultPolicy},"Default policy"),i.map((a,l)=>t.createElement("div",{key:a.id},t.createElement("div",{className:c.policyInPath(l,l===i.length-1)},I(a)?t.createElement("div",{className:c.textMuted},"No matchers"):t.createElement(w.g,{matchers:a.object_matchers??[]})))))}function Q({onClose:e,route:r,receiver:c,routesByIdMap:s,alertManagerSourceName:i}){const a=(0,$.wW)(R),l=P(r),d=(0,U.Ko)(i);return t.createElement(O.u,{className:a.detailsModal,isOpen:!0,title:"Routing details",onDismiss:e,onClickBackdrop:e},t.createElement(m.K,{gap:0,direction:"column"},t.createElement("div",{className:(0,o.cx)(a.textMuted,a.marginBottom(2))},"Your alert instances are routed as follows."),t.createElement("div",null,"Notification policy path"),l&&t.createElement("div",{className:a.textMuted},"Default policy"),t.createElement("div",{className:a.separator(1)}),!l&&t.createElement(t.Fragment,null,t.createElement(J,{route:r,routesByIdMap:s})),t.createElement("div",{className:a.separator(4)}),t.createElement("div",{className:a.contactPoint},t.createElement(m.K,{gap:1,direction:"row",alignItems:"center"},"Contact point:",t.createElement("span",{className:a.textMuted},c.name)),t.createElement(Z.q,{actions:[d.update]},t.createElement(m.K,{gap:1,direction:"row",alignItems:"center"},t.createElement("a",{href:(0,Y.eQ)(`/alerting/notifications/receivers/${encodeURIComponent(c.name)}/edit`,i),className:a.link,target:"_blank",rel:"noreferrer"},"See details ",t.createElement(G.J,{name:"external-link-alt"}))))),t.createElement("div",{className:a.button},t.createElement(b.zx,{variant:"primary",type:"button",onClick:e},"Close"))))}const R=e=>({textMuted:(0,o.css)`
    color: ${e.colors.text.secondary};
  `,link:(0,o.css)`
    display: block;
    color: ${e.colors.text.link};
  `,button:(0,o.css)`
    justify-content: flex-end;
    display: flex;
  `,detailsModal:(0,o.css)`
    max-width: 560px;
  `,defaultPolicy:(0,o.css)`
    padding: ${e.spacing(.5)};
    background: ${e.colors.background.secondary};
    width: fit-content;
  `,contactPoint:(0,o.css)`
    display: flex;
    flex-direction: row;
    gap: ${e.spacing(1)};
    align-items: center;
    justify-content: space-between;
    margin-bottom: ${e.spacing(1)};
  `,policyPathWrapper:(0,o.css)`
    display: flex;
    flex-direction: column;
    margin-top: ${e.spacing(1)};
  `,separator:r=>(0,o.css)`
    margin-top: ${e.spacing(r)};
  `,marginBottom:r=>(0,o.css)`
    margin-bottom: ${e.spacing(e.spacing(r))};
  `,policyInPath:(r=0,c=!1)=>(0,o.css)`
    margin-left: ${30+r*30}px;
    padding: ${e.spacing(1)};
    margin-top: ${e.spacing(1)};
    border: solid 1px ${e.colors.border.weak};
    background: ${e.colors.background.secondary};
    width: fit-content;
    position: relative;

    ${c&&(0,o.css)`
        border: solid 1px ${e.colors.info.border};
      `},
    &:before {
      content: '';
      position: absolute;
      height: calc(100% - 10px);
      width: ${e.spacing(1)};
      border-left: solid 1px ${e.colors.border.weak};
      border-bottom: solid 1px ${e.colors.border.weak};
      margin-top: ${e.spacing(-2)};
      margin-left: -17px;
    }
  }  `});function X({route:e,receiver:r,routesByIdMap:c,instancesCount:s,alertManagerSourceName:i,expandRoute:a,onExpandRouteClick:l}){const d=(0,$.wW)(C),[v,E]=(0,t.useState)(!1),u=()=>{E(!0)};return t.createElement("div",{className:d.routeHeader},t.createElement(W.U,{isCollapsed:!a,onToggle:y=>l(!y),"aria-label":"Expand policy route"}),t.createElement(m.K,{flexGrow:1,gap:1},t.createElement("div",{onClick:()=>l(!a),className:d.expandable},t.createElement(m.K,{gap:1,direction:"row",alignItems:"center"},"Notification policy",t.createElement(F,{route:e}))),t.createElement(j.L,null),t.createElement(m.K,{gap:2,direction:"row",alignItems:"center"},t.createElement(T.g,{icon:"layers-alt","data-testid":"matching-instances"},s??"-",t.createElement("span",null,K()("instance",s))),t.createElement(m.K,{gap:1,direction:"row",alignItems:"center"},t.createElement("div",null,t.createElement("span",{className:d.textMuted},"@ Delivered to")," ",r.name),t.createElement("div",{className:d.verticalBar}),t.createElement(b.zx,{type:"button",onClick:u,variant:"secondary",fill:"outline",size:"sm"},"See details")))),v&&t.createElement(Q,{onClose:()=>E(!1),route:e,receiver:r,routesByIdMap:c,alertManagerSourceName:i}))}function V({route:e,instanceMatches:r,receiver:c,routesByIdMap:s,alertManagerSourceName:i}){const a=(0,$.wW)(C),[l,d]=(0,k.Z)(!1),v=9;return t.createElement("div",{"data-testid":"matching-policy-route"},t.createElement(X,{route:e,receiver:c,routesByIdMap:s,instancesCount:r.length,alertManagerSourceName:i,expandRoute:l,onExpandRouteClick:d}),l&&t.createElement(m.K,{gap:1,direction:"column"},t.createElement("div",{className:a.routeInstances,"data-testid":"route-matching-instance"},r.map(E=>{const u=Array.from(E.labelsMatch);let y=u.map(([g,f])=>({label:`${g[0]}=${g[1]}`,match:f.match,colorIndex:f.match?(0,S.tu)(g[0]):v}));const p=y.filter(g=>g.match),x=y.filter(g=>!g.match);return t.createElement("div",{className:a.tagListCard,key:(0,M.uniqueId)()},u.length>0?t.createElement(t.Fragment,null,p.length>0?t.createElement(h.P,{tags:p.map(g=>g.label),className:a.labelList,getColorIndex:(g,f)=>p[f].colorIndex}):t.createElement("div",{className:(0,o.cx)(a.textMuted,a.textItalic)},"No matching labels"),t.createElement("div",{className:a.labelSeparator}),t.createElement(h.P,{tags:x.map(g=>g.label),className:a.labelList,getColorIndex:(g,f)=>x[f].colorIndex})):t.createElement("div",{className:a.textMuted},"No labels"))}))))}const C=e=>({textMuted:(0,o.css)`
    color: ${e.colors.text.secondary};
  `,textItalic:(0,o.css)`
    font-style: italic;
  `,expandable:(0,o.css)`
    cursor: pointer;
  `,routeHeader:(0,o.css)`
    display: flex;
    flex-direction: row;
    gap: ${e.spacing(1)};
    align-items: center;
    border-bottom: 1px solid ${e.colors.border.weak};
    &:hover {
      background-color: ${e.components.table.rowHoverBackground};
    }
    padding: ${e.spacing(.5,.5,.5,0)};
  `,labelList:(0,o.css)`
    flex: 0 1 auto;
    justify-content: flex-start;
  `,labelSeparator:(0,o.css)`
    width: 1px;
    background-color: ${e.colors.border.weak};
  `,tagListCard:(0,o.css)`
    display: flex;
    flex-direction: row;
    gap: ${e.spacing(2)};

    position: relative;
    background: ${e.colors.background.secondary};
    padding: ${e.spacing(1)};

    border-radius: ${e.shape.borderRadius(2)};
    border: solid 1px ${e.colors.border.weak};
  `,routeInstances:(0,o.css)`
    padding: ${e.spacing(1,0,1,4)};
    position: relative;

    display: flex;
    flex-direction: column;
    gap: ${e.spacing(1)};

    &:before {
      content: '';
      position: absolute;
      left: ${e.spacing(2)};
      height: calc(100% - ${e.spacing(2)});
      width: ${e.spacing(4)};
      border-left: solid 1px ${e.colors.border.weak};
    }
  `,verticalBar:(0,o.css)`
    width: 1px;
    height: 20px;
    background-color: ${e.colors.secondary.main};
    margin-left: ${e.spacing(1)};
    margin-right: ${e.spacing(1)};
  `});var q=n(25111),_=n(97529),ee=n(36546),te=n(26630),ae=n(95984),ne=n(9908);const oe=(e,r)=>{const{currentData:c,isLoading:s,error:i}=(0,_.W)(e),a=c?.alertmanager_config,{matchInstancesToRoute:l}=(0,ee.N)(),{rootRoute:d,receivers:v}=(0,t.useMemo)(()=>a?{rootRoute:a.route?(0,ae.w2)((0,te.br)(a.route)):void 0,receivers:a.receivers??[]}:{receivers:[],rootRoute:void 0},[a]),E=d?z((0,ne.tK)(d)):new Map,u=v.reduce((g,f)=>g.set(f.name,f),new Map)??new Map,{value:y=new Map,loading:p,error:x}=(0,q.Z)(async()=>{if(d)return await l(d,r)},[d,r]);return{routesByIdMap:E,receiversByName:u,matchingMap:y,loading:s||p,error:i??x}};function re({alertManagerSource:e,potentialInstances:r,onlyOneAM:c}){const s=(0,$.wW)(ce),{routesByIdMap:i,receiversByName:a,matchingMap:l,loading:d,error:v}=oe(e.name,r);return v?t.createElement(L.b,{title:"Cannot load Alertmanager configuration",severity:"error"},v.message):d?t.createElement(A.u,{text:"Loading routing preview..."}):l.size>0?t.createElement("div",{className:s.alertManagerRow},!c&&t.createElement(m.K,{direction:"row",alignItems:"center"},t.createElement("div",{className:s.firstAlertManagerLine}),t.createElement("div",{className:s.alertManagerName}," ","Alert manager:",t.createElement("img",{src:e.img,alt:"",className:s.img}),e.name),t.createElement("div",{className:s.secondAlertManagerLine})),t.createElement(m.K,{gap:1,direction:"column"},Array.from(l.entries()).map(([u,y])=>{const p=i.get(u),x=p?.receiver&&a.get(p.receiver);if(!p)return null;if(!x)throw new Error("Receiver not found");return t.createElement(V,{instanceMatches:y,route:p,receiver:x,key:u,routesByIdMap:i,alertManagerSourceName:e.name})}))):null}const se=(0,B.Pf)(re),ce=e=>({alertManagerRow:(0,o.css)`
    margin-top: ${e.spacing(2)};
    display: flex;
    flex-direction: column;
    gap: ${e.spacing(1)};
    width: 100%;
  `,firstAlertManagerLine:(0,o.css)`
    height: 1px;
    width: ${e.spacing(4)};
    background-color: ${e.colors.secondary.main};
  `,alertManagerName:(0,o.css)`
    width: fit-content;
  `,secondAlertManagerLine:(0,o.css)`
    height: 1px;
    width: 100%;
    flex: 1;
    background-color: ${e.colors.secondary.main};
  `,img:(0,o.css)`
    margin-left: ${e.spacing(2)};
    width: ${e.spacing(3)};
    height: ${e.spacing(3)};
    margin-right: ${e.spacing(1)};
  `})}}]);

//# sourceMappingURL=8050.2787cce537a7d9c65c69.js.map