"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2461],{95500:(le,W,t)=>{t.d(W,{x:()=>h});var l=t(85960),e=t(95162),g=t(1992);function h(y){const f=(0,e.useDispatch)(),D=(0,l.useRef)(y);D.current=y,(0,l.useEffect)(()=>()=>{f((0,g.e)({cleanupAction:D.current}))},[f])}},14388:(le,W,t)=>{t.r(W),t.d(W,{default:()=>ga});var l=t(66681),e=t(85960),g=t(85954),h=t(23426),y=t(8958),f=t(47257),D=t(29165),O=t(13086),F=t(763),G=t(95162),R=t(34456),I=t(56375),N=t(30694),$=t(45220),fe=t(173),Pe=t(69707),Re=t(44839),Ce=t(54635),ne=t(97666),te=t(79468),Oe=t(14411),Me=t(27908),Te=t(29657),H=t(23694);function me({onClose:a}){const[n,r]=(0,e.useState)("yaml");return e.createElement(Te.i,{activeTab:n,onTabChange:r,onClose:a,formatProviders:Object.values(H.uN)},e.createElement(ve,{exportFormat:n,onClose:a}))}function ve({exportFormat:a,onClose:n}){const{currentData:r="",isFetching:c}=Oe.alertRuleApi.endpoints.exportRules.useQuery({format:a}),s=`alert-rules-${new Date().getTime()}`;return c?e.createElement(te.u,{text:"Loading...."}):e.createElement(Me.u,{format:a,textDefinition:r,downloadFileName:s,onClose:n})}var w=t(57297);function de({}){const[a,n]=(0,w.E$)(w.jU.CreateAlertRule),[r,c]=(0,w.E$)(w.jU.CreateExternalAlertRule),[s,o]=(0,w.E$)(w.jU.ExportGrafanaManagedRules),i=(0,N.TH)(),[u,d]=(0,$.Z)(!1),m=a&&n,T=r&&c,P=s&&o,L=[];return(m||T)&&L.push(e.createElement(Pe.s,{label:"New recording rule",key:"new-recording-rule",url:fe.Cj.renderUrl("alerting/new/recording",{returnTo:i.pathname+i.search})})),P&&L.push(e.createElement(Pe.s,{label:"Export all Grafana-managed rules",key:"export-all-rules",onClick:d})),e.createElement(e.Fragment,null,(m||T)&&e.createElement(D.Qj,{href:fe.Cj.renderUrl("alerting/new/alerting",{returnTo:i.pathname+i.search}),icon:"plus",onClick:()=>(0,R.PN)(R.z7.alertRuleFromScratch)},"New alert rule"),!(0,I.isEmpty)(L)&&e.createElement(Re.L,{overlay:e.createElement(Ce.v,null,L)},e.createElement(D.zx,{variant:"secondary"},"More",e.createElement(ne.J,{name:"angle-down"}))),P&&u&&e.createElement(me,{onClose:d}))}var Ae=t(65892),Se=t(11318),ge=t(64409),p=t(44097);const E=()=>{const{canCreateGrafanaRules:a,canCreateCloudRules:n}=(0,p.B)(),r=(0,f.wW)(M);return a||n?e.createElement("div",null,e.createElement("p",null,"You haven't created any alert rules yet"),e.createElement(O.K,{gap:1},e.createElement("div",{className:r.newRuleCard},e.createElement(ge.Z,{title:"",buttonIcon:"bell",buttonLink:"alerting/new/alerting",buttonTitle:"New alert rule",proTip:"you can also create alert rules from existing panels and queries.",proTipLink:"https://grafana.com/docs/",proTipLinkTitle:"Learn more",proTipTarget:"_blank",onClick:()=>(0,R.PN)(R.z7.alertRuleFromScratch)})),e.createElement("div",{className:r.newRuleCard},e.createElement(ge.Z,{title:"",buttonIcon:"plus",buttonLink:"alerting/new/recording",buttonTitle:"New recording rule",onClick:()=>(0,R.PN)(R.z7.recordingRuleFromScratch)})))):e.createElement(Se._,{message:"No rules exist yet.",callToActionElement:e.createElement("div",null)})},M=a=>({newRuleCard:(0,l.css)`
    width: calc(50% - ${a.spacing(1)});

    > div {
      height: 100%;
    }
  `});var v=t(60808),Q=t(53136),x=t.n(Q),B=t(6753),Z=t(49199),re=t(14607),_=t(92746),K=t(76679),se=t(77294),ae=t(9001);function Je(){const[a,n]=(0,e.useState)(!1),[r,c]=(0,B.Z)("grafana.unifiedalerting.hideErrors",!1),s=(0,_._)(m=>m.dataSources),o=(0,_._)(m=>m.promRules),i=(0,_._)(m=>m.rulerRules),u=(0,f.wW)(ce),d=(0,e.useMemo)(()=>{const[m,T,P]=[s,o,i].map(A=>(0,K.Eu)().reduce((C,q)=>{const pe=A[q.name]?.error;return A[q.name]&&pe&&!(0,ae.m$)(A[q.name])?[...C,{dataSource:q,error:pe}]:C},[])),L=o[K.GC]?.error,b=i[K.GC]?.error,U=[];return L&&U.push(e.createElement(e.Fragment,null,"Failed to load Grafana rules state: ",L.message||"Unknown error.")),b&&U.push(e.createElement(e.Fragment,null,"Failed to load Grafana rules config: ",b.message||"Unknown error.")),m.forEach(({dataSource:A,error:C})=>{U.push(e.createElement(e.Fragment,null,"Failed to load the data source configuration for"," ",e.createElement("a",{href:(0,se.__)(A),className:u.dsLink},A.name),": ",C.message||"Unknown error."))}),T.forEach(({dataSource:A,error:C})=>U.push(e.createElement(e.Fragment,null,"Failed to load rules state from"," ",e.createElement("a",{href:(0,se.__)(A),className:u.dsLink},A.name),": ",C.message||"Unknown error."))),P.forEach(({dataSource:A,error:C})=>U.push(e.createElement(e.Fragment,null,"Failed to load rules config from"," ",e.createElement("a",{href:(0,se.__)(A),className:u.dsLink},A.name),": ",C.message||"Unknown error."))),U},[s,o,i,u.dsLink]);return e.createElement(e.Fragment,null,!!d.length&&r&&e.createElement(Ie,{count:d.length,onClick:()=>c(m=>!m)}),!!d.length&&!r&&e.createElement(Z.b,{"data-testid":"cloud-rulessource-errors",title:"Errors loading rules",severity:"error",onRemove:()=>c(!0)},a&&d.map((m,T)=>e.createElement("div",{key:T},m)),!a&&e.createElement(e.Fragment,null,e.createElement("div",null,d[0]),d.length>=2&&e.createElement(D.zx,{className:u.moreButton,fill:"text",icon:"angle-right",size:"sm",onClick:()=>n(!0)},d.length-1," more ",x()("error",d.length-1)))))}const Ie=({count:a,onClick:n})=>{const r=(0,f.wW)(ce);return e.createElement("div",{className:r.floatRight},e.createElement(re.u,{content:"Show all errors",placement:"bottom"},e.createElement(D.zx,{fill:"text",variant:"destructive",icon:"exclamation-triangle",onClick:n},a>1?e.createElement(e.Fragment,null,a," errors"):e.createElement(e.Fragment,null,"1 error"))))},ce=a=>({moreButton:(0,l.css)`
    padding: 0;
  `,floatRight:(0,l.css)`
    display: flex;
    justify-content: flex-end;
  `,dsLink:(0,l.css)`
    font-weight: ${a.typography.fontWeightBold};
  `});var Ge=t(53914),Ne=t(75682),Ze=t(44574),Ye=t(89248),Xe=t(37310),ke=t(52912),Ue=t(30422),_e=t(74042),je=t(67192),pt=t(77980),Et=t(20420),ft=t(72142),Be=t(5970),qe=t(44211),et=t(58662);function vt({folder:a,onClose:n}){const[r,c]=(0,e.useState)("yaml");return e.createElement(Te.i,{title:`Export ${a.title} rules`,activeTab:r,onTabChange:c,onClose:n,formatProviders:Object.values(H.uN)},e.createElement(ht,{folder:a,exportFormat:r,onClose:n}))}function ht({folder:a,exportFormat:n,onClose:r}){const{currentData:c="",isFetching:s}=Oe.alertRuleApi.endpoints.exportRules.useQuery({folderUid:a.uid,format:n});if(s)return e.createElement(te.u,{text:"Loading...."});const o=`${a.title}-${a.uid}`;return e.createElement(Me.u,{format:n,textDefinition:c,downloadFileName:o,onClose:r})}function Rt({folderUid:a,groupName:n,onClose:r}){const[c,s]=(0,e.useState)("yaml");return e.createElement(Te.i,{title:`Export ${n} rules`,activeTab:c,onTabChange:s,onClose:r,formatProviders:Object.values(H.uN)},e.createElement(yt,{folderUid:a,groupName:n,exportFormat:c,onClose:r}))}function yt({folderUid:a,groupName:n,exportFormat:r,onClose:c}){const{currentData:s="",isFetching:o}=Oe.alertRuleApi.endpoints.exportRules.useQuery({folderUid:a,group:n,format:r});return o?e.createElement(te.u,{text:"Loading...."}):e.createElement(Me.u,{format:r,textDefinition:s,downloadFileName:n,onClose:c})}var ye=t(90504),xt=t(68684),Pt=t(70318),tt=t.n(Pt),ze=t(31173),Ct=t(7288),St=t(59767),Dt=t(60956),Ot=t(14591);const Mt=a=>{const{group:n,namespace:r,onClose:c}=a,[s,o]=(0,e.useState)(!1),[i,u]=(0,e.useState)(n.rules),d=(0,f.wW)(He),m=(0,e.useCallback)(P=>{if(!P.destination||P.destination.index===P.source.index)return;const b=At(i,P.source.index,P.destination.index);u(b);const U=(0,K.EG)(r.rulesSource),A=(0,I.compact)(b.map(C=>C.rulerRule));o(!0),(0,St.WI)((0,Be.tg)({namespaceName:r.name,groupName:n.name,rulesSourceName:U,newRules:A})).unwrap().finally(()=>{o(!1)})},[n.name,r.name,r.rulesSource,i]),T=i.map(P=>({...P,uid:String((0,Dt.Om)(P.rulerRule))}));return e.createElement(Ct.u,{className:d.modal,isOpen:!0,title:e.createElement(Tt,{namespace:r,group:n}),onDismiss:c,onClickBackdrop:c},e.createElement(ze.Z5,{onDragEnd:m},e.createElement(ze.bK,{droppableId:"alert-list",mode:"standard",renderClone:(P,L,b)=>e.createElement(at,{provided:P,rule:T[b.source.index],isClone:!0})},P=>e.createElement("div",{ref:P.innerRef,className:tt()(d.listContainer,s&&d.disabled),...P.droppableProps},T.map((L,b)=>e.createElement(ze._l,{key:L.uid,draggableId:L.uid,index:b,isDragDisabled:s},U=>e.createElement(at,{key:L.uid,provided:U,rule:L}))),P.placeholder))))},at=({provided:a,rule:n,isClone:r=!1,isDragging:c=!1})=>{const s=(0,f.wW)(He);return e.createElement("div",{className:tt()(s.listItem,r&&"isClone",c&&"isDragging"),ref:a.innerRef,...a.draggableProps,...a.dragHandleProps},(0,ae.x_)(n.promRule)&&e.createElement(Ot.l,{state:n.promRule.state}),(0,ae.OP)(n.promRule)&&e.createElement(je.C,{text:"Recording",color:"blue"}),e.createElement("div",{className:s.listItemName},n.name),e.createElement(ne.J,{name:"draggabledots"}))},Tt=({namespace:a,group:n})=>{const r=(0,f.wW)(He);return e.createElement("div",{className:r.header},e.createElement(ne.J,{name:"folder"}),(0,K.jq)(a.rulesSource)&&e.createElement(re.u,{content:a.rulesSource.name,placement:"top"},e.createElement("img",{alt:a.rulesSource.meta.name,className:r.dataSourceIcon,src:a.rulesSource.meta.info.logos.small})),e.createElement("span",null,a.name),e.createElement(ne.J,{name:"angle-right"}),e.createElement("span",null,n.name))},He=a=>({modal:(0,l.css)`
    max-width: 640px;
    max-height: 80%;
    overflow: hidden;
  `,listItem:(0,l.css)`
    display: flex;
    flex-direction: row;
    align-items: center;

    gap: ${a.spacing()};

    background: ${a.colors.background.primary};
    color: ${a.colors.text.secondary};

    border-bottom: solid 1px ${a.colors.border.medium};
    padding: ${a.spacing(1)} ${a.spacing(2)};

    &:last-child {
      border-bottom: none;
    }

    &.isClone {
      border: solid 1px ${a.colors.primary.shade};
    }
  `,listContainer:(0,l.css)`
    user-select: none;
    border: solid 1px ${a.colors.border.medium};
  `,disabled:(0,l.css)`
    opacity: 0.5;
    pointer-events: none;
  `,listItemName:(0,l.css)`
    flex: 1;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  `,header:(0,l.css)`
    display: flex;
    align-items: center;

    gap: ${a.spacing(1)};
  `,dataSourceIcon:(0,l.css)`
    width: ${a.spacing(2)};
    height: ${a.spacing(2)};
  `});function At(a,n,r){const c=Array.from(a),[s]=c.splice(n,1);return c.splice(r,0,s),c}var nt=t(85701),rt=t(50657);const we=e.memo(({group:a,namespace:n,expandAll:r,viewMode:c})=>{const{rulesSource:s}=n,o=(0,G.useDispatch)(),i=(0,f.wW)(It),[u,d]=(0,e.useState)(!1),[m,T]=(0,e.useState)(!1),[P,L]=(0,e.useState)(!1),[b,U]=(0,e.useState)(void 0),[A,C]=(0,e.useState)(!r),{canEditRules:q}=(0,p.B)();(0,e.useEffect)(()=>{C(!r)},[r]);const{hasRuler:pe,rulerRulesLoaded:V}=(0,ft.h)(),z=a.rules[0]?.rulerRule,ie=z&&(0,ae.Pc)(z)&&z.grafana_alert.namespace_uid||void 0,{folder:j}=(0,Et.W)(ie),J=pe(s)&&V(s)&&!a.rules.find(Ee=>!!Ee.rulerRule),X=(0,ae.Jq)(a),he=a.rules.some(Ee=>(0,ae.Pc)(Ee.rulerRule)&&Ee.rulerRule.grafana_alert.provenance),k=c==="list",S=c==="grouped",ue=()=>{o((0,Be.oE)(n,a)),T(!1)},ee=[];if(J)ee.push(e.createElement(_e.Lh,{key:"is-deleting"},e.createElement(Ne.$,null),"deleting"));else if(s===K.GC){if(ie){const Ee=(0,se.HV)(ie);j?.canSave&&(S&&!he&&(ee.push(e.createElement(ye.A,{"aria-label":"edit rule group","data-testid":"edit-group",key:"edit",icon:"pen",tooltip:"edit rule group",onClick:()=>d(!0)})),ee.push(e.createElement(ye.A,{"aria-label":"re-order rules","data-testid":"reorder-group",key:"reorder",icon:"exchange-alt",tooltip:"reorder rules",className:i.rotate90,onClick:()=>L(!0)}))),k&&(ee.push(e.createElement(ye.A,{"aria-label":"go to folder",key:"goto",icon:"folder-open",tooltip:"go to folder",to:Ee,target:"__blank"})),j?.canAdmin&&ee.push(e.createElement(ye.A,{"aria-label":"manage permissions",key:"manage-perms",icon:"lock",tooltip:"manage permissions",to:Ee+"/permissions",target:"__blank"})))),j&&(k?ee.push(e.createElement(ye.A,{"aria-label":"export rule folder","data-testid":"export-folder",key:"export-folder",icon:"download-alt",tooltip:"Export rules folder",onClick:()=>U("folder")})):S&&ee.push(e.createElement(ye.A,{"aria-label":"export rule group","data-testid":"export-group",key:"export-group",icon:"download-alt",tooltip:"Export rule group",onClick:()=>U("group")})))}}else q(s.name)&&pe(s)&&(X||(ee.push(e.createElement(ye.A,{"aria-label":"edit rule group","data-testid":"edit-group",key:"edit",icon:"pen",tooltip:"edit rule group",onClick:()=>d(!0)})),ee.push(e.createElement(ye.A,{"aria-label":"re-order rules","data-testid":"reorder-group",key:"reorder",icon:"exchange-alt",tooltip:"re-order rules",className:i.rotate90,onClick:()=>L(!0)}))),ee.push(e.createElement(ye.A,{"aria-label":"delete rule group","data-testid":"delete-group",key:"delete-group",icon:"trash-alt",tooltip:"delete rule group",onClick:()=>T(!0)})));const xe=k?e.createElement(et.V,{namespace:n.name}):e.createElement(et.V,{namespace:n.name,group:a.name}),$e=(Ee=!1)=>{Ee||(0,R.PN)(R.z7.leavingRuleGroupEdit),d(!1)};return e.createElement("div",{className:i.wrapper,"data-testid":"rule-group"},e.createElement("div",{className:i.header,"data-testid":"rule-group-header"},e.createElement(qe.U,{size:"sm",className:i.collapseToggle,isCollapsed:A,onToggle:C,"data-testid":"group-collapse-toggle"}),e.createElement(ne.J,{name:A?"folder":"folder-open"}),(0,K.jq)(s)&&e.createElement(re.u,{content:s.name,placement:"top"},e.createElement("img",{alt:s.meta.name,className:i.dataSourceIcon,src:s.meta.info.logos.small})),e.createElement("div",{className:i.groupName,onClick:()=>C(!A)},X&&e.createElement(je.C,{color:"purple",text:"Federated"})," ",xe),e.createElement("div",{className:i.spacer}),e.createElement("div",{className:i.headerStats},e.createElement(nt.Pb,{group:a})),he&&e.createElement(e.Fragment,null,e.createElement("div",{className:i.actionsSeparator},"|"),e.createElement("div",{className:i.actionIcons},e.createElement(je.C,{color:"purple",text:"Provisioned"}))),!!ee.length&&e.createElement(e.Fragment,null,e.createElement("div",{className:i.actionsSeparator},"|"),e.createElement("div",{className:i.actionIcons},e.createElement(O.K,{gap:.5},ee)))),!A&&e.createElement(rt.i,{showSummaryColumn:!0,className:i.rulesTable,showGuidelines:!0,showNextEvaluationColumn:!!a.interval,rules:a.rules}),u&&e.createElement(xt.vq,{namespace:n,group:a,onClose:()=>$e(),folderUrl:j?.canEdit?(0,se.aH)(j):void 0}),P&&e.createElement(Mt,{group:a,namespace:n,onClose:()=>L(!1)}),e.createElement(pt.s,{isOpen:m,title:"Delete group",body:e.createElement("div",null,e.createElement("p",null,'Deleting "',e.createElement("strong",null,a.name),'" will permanently remove the group and'," ",a.rules.length," alert ",x()("rule",a.rules.length)," belonging to it."),e.createElement("p",null,"Are you sure you want to delete this group?")),onConfirm:ue,onDismiss:()=>T(!1),confirmText:"Delete"}),j&&b==="folder"&&e.createElement(vt,{folder:j,onClose:()=>U(void 0)}),j&&b==="group"&&e.createElement(Rt,{folderUid:j.uid,groupName:a.name,onClose:()=>U(void 0)}))});we.displayName="RulesGroup";const It=a=>({wrapper:(0,l.css)``,header:(0,l.css)`
      display: flex;
      flex-direction: row;
      align-items: center;
      padding: ${a.spacing(1)} ${a.spacing(1)} ${a.spacing(1)} 0;
      flex-wrap: nowrap;
      border-bottom: 1px solid ${a.colors.border.weak};

      &:hover {
        background-color: ${a.components.table.rowHoverBackground};
      }
    `,headerStats:(0,l.css)`
      flex-shrink: 0;

      span {
        vertical-align: middle;
      }

      ${a.breakpoints.down("sm")} {
        order: 2;
        width: 100%;
        padding-left: ${a.spacing(1)};
      }
    `,groupName:(0,l.css)`
      margin-left: ${a.spacing(1)};
      margin-bottom: 0;
      cursor: pointer;

      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    `,spacer:(0,l.css)`
      flex: 1;
    `,collapseToggle:(0,l.css)`
      background: none;
      border: none;
      margin-top: -${a.spacing(1)};
      margin-bottom: -${a.spacing(1)};

      svg {
        margin-bottom: 0;
      }
    `,dataSourceIcon:(0,l.css)`
      width: ${a.spacing(2)};
      height: ${a.spacing(2)};
      margin-left: ${a.spacing(2)};
    `,dataSourceOrigin:(0,l.css)`
      margin-right: 1em;
      color: ${a.colors.text.disabled};
    `,actionsSeparator:(0,l.css)`
      margin: 0 ${a.spacing(2)};
    `,actionIcons:(0,l.css)`
      width: 80px;
      align-items: center;

      flex-shrink: 0;
    `,rulesTable:(0,l.css)`
      margin: ${a.spacing(2,0)};
    `,rotate90:(0,l.css)`
      transform: rotate(90deg);
    `});function lt(a){return(0,e.useMemo)(()=>a.flatMap(n=>n.groups.map(r=>({namespace:n,group:r}))),[a])}const Nt=({namespaces:a,expandAll:n})=>{const r=(0,f.wW)(Lt),c=(0,_._)(C=>C.dataSources),s=(0,_._)(C=>C.promRules),o=(0,e.useMemo)(K.Eu,[]),i=lt(a),u=(0,e.useMemo)(()=>o.filter(C=>(0,Ue.op)(s[C.name])||(0,Ue.op)(c[C.name])),[s,c,o]),d=o.some(C=>!!s[C.name]?.result?.length),m=o.length>0,T=u.length>0,P=a.length>0,{numberOfPages:L,onPageChange:b,page:U,pageItems:A}=(0,Xe.h)(i,1,Ye.gN);return e.createElement("section",{className:r.wrapper},e.createElement("div",{className:r.sectionHeader},e.createElement("h5",null,"Mimir / Cortex / Loki"),u.length?e.createElement(te.u,{className:r.loader,text:`Loading rules from ${u.length} ${x()("source",u.length)}`}):e.createElement("div",null)),A.map(({group:C,namespace:q})=>e.createElement(we,{group:C,key:`${(0,K.v_)(q.rulesSource)}-${q.name}-${C.name}`,namespace:q,expandAll:n,viewMode:"grouped"})),!m&&e.createElement("p",null,"There are no Prometheus or Loki data sources configured."),m&&!T&&!P&&e.createElement("p",null,"No rules found."),!d&&T&&e.createElement(Ne.$,{size:"xl",className:r.spinner}),e.createElement(Ze.t,{className:r.pagination,currentPage:U,numberOfPages:L,onNavigate:b,hideWhenSinglePage:!0}))},Lt=a=>({loader:(0,l.css)`
    margin-bottom: 0;
  `,sectionHeader:(0,l.css)`
    display: flex;
    justify-content: space-between;
  `,wrapper:(0,l.css)`
    margin-bottom: ${a.spacing(4)};
  `,spinner:(0,l.css)`
    text-align: center;
    padding: ${a.spacing(2)};
  `,pagination:(0,ke.Z)(a)});var Fe=t(68700);const Ft=({namespaces:a,expandAll:n})=>{const r=(0,f.wW)(Wt),[c]=(0,F.K)(),{prom:s,ruler:o}=(0,_._)(A=>({prom:A.promRules[K.GC]||Ue.oq,ruler:A.rulerRules[K.GC]||Ue.oq})),i=s.loading||o.loading,u=!!s.result||!!o.result,d=c.view==="list",m=d?(0,Fe.Kd)(a):a,T=lt(m),{numberOfPages:P,onPageChange:L,page:b,pageItems:U}=(0,Xe.h)(T,1,Ye.gN);return e.createElement("section",{className:r.wrapper},e.createElement("div",{className:r.sectionHeader},e.createElement("h5",null,"Grafana"),i?e.createElement(te.u,{className:r.loader,text:"Loading..."}):e.createElement("div",null)),U.map(({group:A,namespace:C})=>e.createElement(we,{group:A,key:`${C.name}-${A.name}`,namespace:C,expandAll:n,viewMode:d?"list":"grouped"})),u&&m?.length===0&&e.createElement("p",null,"No rules found."),!u&&i&&e.createElement(Ne.$,{size:"xl",className:r.spinner}),e.createElement(Ze.t,{className:r.pagination,currentPage:b,numberOfPages:P,onNavigate:L,hideWhenSinglePage:!0}))},Wt=a=>({loader:(0,l.css)`
    margin-bottom: 0;
  `,sectionHeader:(0,l.css)`
    display: flex;
    justify-content: space-between;
    margin-bottom: ${a.spacing(1)};
  `,wrapper:(0,l.css)`
    margin-bottom: ${a.spacing(4)};
  `,spinner:(0,l.css)`
    text-align: center;
    padding: ${a.spacing(2)};
  `,pagination:(0,ke.Z)(a)}),$t=({namespaces:a,expandAll:n})=>{const[r,c]=(0,e.useMemo)(()=>{const s=a.map(o=>({...o,groups:o.groups.sort((i,u)=>i.name.localeCompare(u.name))})).sort((o,i)=>o.name.localeCompare(i.name));return[s.filter(o=>(0,K.HY)(o.rulesSource)),s.filter(o=>(0,K.jq)(o.rulesSource))]},[a]);return(0,e.useEffect)(()=>{(0,R.PN)(R.z7.loadedList)},[]),e.createElement(e.Fragment,null,e.createElement(Ge.q,{actions:[w.jU.ViewAlertRule]},e.createElement(Ft,{namespaces:r,expandAll:n})),e.createElement(Ge.q,{actions:[w.jU.ViewExternalAlertRule]},e.createElement(Nt,{namespaces:c,expandAll:n})))};var Y=t(25119);const Qe=({rules:a,state:n,defaultCollapsed:r=!1})=>{const[c,s]=(0,e.useState)(r),o=(0,f.wW)(Ut);return e.createElement(e.Fragment,null,e.createElement("h4",{className:o.header},e.createElement(qe.U,{className:o.collapseToggle,size:"xxl",isCollapsed:c,onToggle:()=>s(!c)}),(0,ae.SS)(n)," (",a.length,")"),!c&&e.createElement(rt.i,{className:o.rulesTable,rules:a,showGroupColumn:!0}))},Ut=a=>({collapseToggle:(0,l.css)`
    vertical-align: middle;
  `,header:(0,l.css)`
    margin-top: ${a.spacing(2)};
  `,rulesTable:(0,l.css)`
    margin-top: ${a.spacing(3)};
  `}),Bt=({namespaces:a})=>{const n=(0,se.lC)((0,F.K)()[0]),r=(0,e.useMemo)(()=>{const c={[Y.x_.Firing]:[],[Y.x_.Inactive]:[],[Y.x_.Pending]:[]};return a.forEach(s=>s.groups.forEach(o=>o.rules.forEach(i=>{i.promRule&&(0,ae.x_)(i.promRule)&&c[i.promRule.state].push(i)}))),Object.values(c).forEach(s=>s.sort((o,i)=>o.name.localeCompare(i.name))),c},[a]);return e.createElement(e.Fragment,null,(!n.alertState||n.alertState===Y.x_.Firing)&&e.createElement(Qe,{state:Y.x_.Firing,rules:r[Y.x_.Firing]}),(!n.alertState||n.alertState===Y.x_.Pending)&&e.createElement(Qe,{state:Y.x_.Pending,rules:r[Y.x_.Pending]}),(!n.alertState||n.alertState===Y.x_.Inactive)&&e.createElement(Qe,{defaultCollapsed:n.alertState!==Y.x_.Inactive,state:Y.x_.Inactive,rules:r[Y.x_.Inactive]}))};var bt=t(53285),st=t(20519),Le=t(57445),be=t(5106),Kt=t(24956),Gt=t(10402),jt=t(93638),ot=t(81502),We=t(35782),Ke=t(98724),zt=t(41460),Ht=t(75636);function ct(){const[a,n]=(0,Ht.j)(),r=a.get("search")??"",c=(0,e.useMemo)(()=>(0,We.ug)(r),[r]),s=(0,e.useMemo)(()=>Object.values(c).some(u=>!(0,I.isEmpty)(u)),[c]),o=(0,e.useCallback)(u=>{const d=(0,We.HY)(r,u);n({search:d})},[r,n]),i=(0,e.useCallback)(u=>{n({search:u})},[n]);return(0,e.useEffect)(()=>{const u={dataSource:a.get("dataSource")??void 0,alertState:a.get("alertState")??void 0,ruleType:a.get("ruleType")??void 0,labels:(0,Ke.Zh)(a.get("queryString")??"").map(Ke.cm)};Object.values(u).some(m=>!(0,I.isEmpty)(m))&&(n({dataSource:void 0,alertState:void 0,ruleType:void 0,queryString:void 0}),o((0,jt.Uy)(c,m=>{if(m.dataSourceNames??=u.dataSource?[u.dataSource]:[],u.alertState&&(0,Y.I9)(u.alertState)&&(m.ruleState??=u.alertState),u.ruleType&&(0,ae.Wd)(u.ruleType)&&(m.ruleType??=u.ruleType),m.labels.length===0&&u.labels.length>0){const T=u.labels.map(({name:P,operator:L,value:b})=>`${P}${L}${b}`);m.labels.push(...T)}})))},[a,o,c,n]),{filterState:c,hasActiveFilters:s,searchQuery:r,setSearchQuery:i,updateFilters:o}}const wt=(a,n)=>(0,e.useMemo)(()=>{const r=Qt(a,n);return r.forEach(c=>{c.groups.forEach(s=>{s.rules.forEach(o=>{(0,ae.x_)(o.promRule)&&(o.instanceTotals=(0,Fe.Fm)(o.promRule),o.filteredInstanceTotals=(0,Fe.ZP)(o.promRule))}),s.totals=(0,Fe.DD)({rules:s.rules.map(o=>o.promRule).filter(o=>!!o)})})}),r},[a,n]),Ve=new Gt.Z({intraMode:1,intraIns:1,intraSub:1,intraTrn:1,intraDel:1}),Qt=(a,n={dataSourceNames:[],labels:[],freeFormWords:[]})=>{let r=a;const c=n.dataSourceNames;c.length&&(r=r.filter(({rulesSource:o})=>(0,K.jq)(o)?c.includes(o.name):!0));const s=n.namespace;if(s){const o=r.map(m=>m.name),[i,u,d]=Ve.search(o,s);u&&d?r=d.map(m=>r[u.idx[m]]):i&&(r=i.map(m=>r[m]))}return r.reduce(Vt(n),[])},Vt=a=>(n,r)=>{const c=a.groupName;let s=r.groups;if(c){const o=s.map(m=>m.name),[i,u,d]=Ve.search(o,c);u&&d?s=d.map(m=>s[u.idx[m]]):i&&(s=i.map(m=>s[m]))}return s=s.reduce(Jt(a),[]),s.length&&n.push({...r,groups:s}),n},Jt=a=>{const n=a.ruleName??a.freeFormWords.join(" ");return(r,c)=>{let s=c.rules;if(n){const o=s.map(m=>m.name),[i,u,d]=Ve.search(o,n);u&&d?s=d.map(m=>s[u.idx[m]]):i&&(s=i.map(m=>s[m]))}return s=s.filter(o=>{const i=o.promRule,u=(0,I.chain)(a).pick(["ruleType","dataSourceNames","ruleHealth","labels","ruleState"]).omitBy(I.isEmpty).mapValues(()=>!1).value();if("ruleType"in u&&a.ruleType===i?.type&&(u.ruleType=!0),"dataSourceNames"in u&&((0,ae.Pc)(o.rulerRule)?Yt(o.rulerRule,a)&&(u.dataSourceNames=!0):u.dataSourceNames=!0),"ruleHealth"in a&&i){const d=(0,ae.vU)(i.health);a.ruleHealth===d&&(u.ruleHealth=!0)}if("labels"in u){const d=(0,I.compact)(a.labels.map(Zt)),m=d.length>0&&(0,Ke.eD)(o.labels,d),T=d.length>0&&i&&i.type===Y.pz.Alerting&&i.alerts&&i.alerts.some(P=>(0,Ke.eD)(P.labels,d));(m||T)&&(u.labels=!0)}if("ruleState"in u){const d=o.promRule;d&&(0,ae.x_)(d)&&d.state===a.ruleState&&(u.ruleState=!0)}return Object.values(u).every(d=>d===!0)}),s.length&&r.push({...c,rules:s}),r}};function Zt(a){try{return(0,zt.tC)(a)}catch{return{name:a,value:"",isRegex:!0,isEqual:!0}}}const Yt=(a,n)=>n.dataSourceNames?.length?!!a.grafana_alert.data.find(r=>{if(!r.datasourceUid)return!1;const c=(0,ot.F)().getInstanceSettings(r.datasourceUid);return c?.name&&n?.dataSourceNames?.includes(c.name)}):!0;var Xt=t(23595),kt=t(52219),_t=t(1058),it=t(92369),ut=t(32063),qt=t(27436),ea=t(15343);const ta=a=>{const n=(0,ot.F)(),[r,c]=(0,e.useState)(),s=(V,z)=>{if(z.action==="clear"&&a.onClear){a.onClear();return}const ie=V[V.length-1];let j,J;z.action==="pop-value"||z.action==="remove-value"?(j=z.removedValue?.value,J="remove"):(j=ie.value,J="add");const X=n.getInstanceSettings(j);X&&(a.onChange(X,J),c({error:void 0}))},o=()=>{const{current:V,hideTextValue:z,noDefault:ie}=a;if(!(!V&&ie))return V?.map(j=>{const J=n.getInstanceSettings(j);if(J)return{label:J.name.slice(0,37),value:J.name,imgUrl:J.meta.info.logos.small,hideText:z,meta:J.meta};const X=(0,kt.BT)(j);return X===ut.hr.uid||X===ut.hr.name?{label:X,value:X,hideText:z}:{label:(X??"no name")+" - not found",value:X??void 0,imgUrl:"",hideText:z}})},i=()=>{const{alerting:V,tracing:z,metrics:ie,mixed:j,dashboard:J,variables:X,annotations:he,pluginId:k,type:S,filter:ue,logs:ee}=a,xe=n.getList({alerting:V,tracing:z,metrics:ie,logs:ee,dashboard:J,mixed:j,variables:X,annotations:he,pluginId:k,filter:ue,type:S}),$e=xe.filter(K.G_).map(oe=>({value:oe.name,label:`${oe.name}${oe.isDefault?" (default)":""}`,imgUrl:oe.meta.info.logos.small,meta:oe.meta})),Ee=xe.filter(oe=>!(0,K.G_)(oe)).map(oe=>({value:oe.name,label:`${oe.name}${oe.isDefault?" (default)":""}`,imgUrl:oe.meta.info.logos.small,meta:oe.meta}));return[{label:"Data sources with configured alert rules",options:$e,expanded:!0},{label:"Other data sources",options:Ee,expanded:!0}]},{autoFocus:u,onBlur:d,onClear:m,openMenuOnFocus:T,placeholder:P,width:L,inputId:b,disabled:U=!1,isLoading:A=!1}=a,C=i(),q=o(),pe=typeof m=="function";return e.createElement("div",{"data-testid":it.wl.components.DataSourcePicker.container},e.createElement(qt.NU,{isLoading:A,disabled:U,"data-testid":it.wl.components.DataSourcePicker.inputV2,inputId:b||"data-source-picker",className:"ds-picker select-container",isClearable:pe,backspaceRemovesValue:!0,onChange:s,options:C,autoFocus:u,onBlur:d,width:L,openMenuOnFocus:T,maxMenuHeight:500,placeholder:P,noOptionsMessage:"No datasources found",value:q??[],invalid:!!r?.error||!!a.invalid,getOptionLabel:V=>V.meta&&(0,_t.x)(V.meta.signature)&&V!==q?e.createElement(_e.Lh,{align:"center",justify:"space-between",height:"auto"},e.createElement("span",null,V.label)," ",e.createElement(ea.o,{status:V.meta.signature})):V.label||""}))},mt=[{icon:"folder",label:"Grouped",value:"grouped"},{icon:"list-ul",label:"List",value:"list"},{icon:"heart-rate",label:"State",value:"state"}],aa=[{label:"Alert ",value:Y.pz.Alerting},{label:"Recording ",value:Y.pz.Recording}],na=[{label:"Ok",value:We.VG.Ok},{label:"No Data",value:We.VG.NoData},{label:"Error",value:We.VG.Error}],ra=Object.entries(Y.x_).map(([a,n])=>({label:(0,ae.SS)(n),value:n})),la=({onFilterCleared:a=()=>{}})=>{const n=(0,f.wW)(sa),[r,c]=(0,F.K)(),{filterState:s,hasActiveFilters:o,searchQuery:i,setSearchQuery:u,updateFilters:d}=ct(),[m,T]=(0,e.useState)(Math.floor(Math.random()*100)),P=`dataSource-${m}`,L=`queryString-${m}`,b=(0,e.useRef)(null),{handleSubmit:U,register:A,setValue:C}=(0,bt.cI)({defaultValues:{searchQuery:i}}),{ref:q,...pe}=A("searchQuery");(0,e.useEffect)(()=>{C("searchQuery",i)},[i,C]);const V=(S,ue)=>{const ee=ue==="add"?[...s.dataSourceNames].concat([S.name]):s.dataSourceNames.filter(xe=>xe!==S.name);d({...s,dataSourceNames:ee}),T(xe=>xe+1)},z=()=>{d({...s,dataSourceNames:[]}),T(S=>S+1)},ie=S=>{(0,R.PN)(R.z7.clickingAlertStateFilters),d({...s,ruleState:S}),T(ue=>ue+1)},j=S=>{c({view:S})},J=S=>{d({...s,ruleType:S}),T(ue=>ue+1)},X=S=>{d({...s,ruleHealth:S}),T(ue=>ue+1)},he=()=>{u(void 0),a(),setTimeout(()=>T(m+1),100)},k=e.createElement(ne.J,{name:"search"});return e.createElement("div",{className:n.container},e.createElement(O.K,{direction:"column",gap:1},e.createElement(O.K,{direction:"row",gap:1},e.createElement(st.g,{className:n.dsPickerContainer,label:e.createElement(Le._,{htmlFor:"data-source-picker"},e.createElement(O.K,{gap:.5},e.createElement("span",null,"Search by data sources"),e.createElement(re.u,{content:e.createElement("div",null,e.createElement("p",null,"Data sources containing configured alert rules are Mimir or Loki data sources where alert rules are stored and evaluated in the data source itself."),e.createElement("p",null,"In these data sources, you can select Manage alerts via Alerting UI to be able to manage these alert rules in the Grafana UI as well as in the data source where they were configured."))},e.createElement(ne.J,{name:"info-circle",size:"sm"}))))},e.createElement(ta,{key:P,alerting:!0,noDefault:!0,placeholder:"All data sources",current:s.dataSourceNames,onChange:V,onClear:z})),e.createElement("div",null,e.createElement(Le._,null,"State"),e.createElement(be.S,{options:ra,value:s.ruleState,onChange:ie})),e.createElement("div",null,e.createElement(Le._,null,"Rule type"),e.createElement(be.S,{options:aa,value:s.ruleType,onChange:J})),e.createElement("div",null,e.createElement(Le._,null,"Health"),e.createElement(be.S,{options:na,value:s.ruleHealth,onChange:X}))),e.createElement(O.K,{direction:"column",gap:1},e.createElement(O.K,{direction:"row",gap:1},e.createElement("form",{className:n.searchInput,onSubmit:U(S=>{u(S.searchQuery),b.current?.blur()})},e.createElement(st.g,{label:e.createElement(Le._,{htmlFor:"rulesSearchInput"},e.createElement(O.K,{gap:.5},e.createElement("span",null,"Search"),e.createElement(Xt.z,{content:e.createElement(oa,null)},e.createElement(ne.J,{name:"info-circle",size:"sm",tabIndex:0}))))},e.createElement(Kt.I,{id:"rulesSearchInput",key:L,prefix:k,ref:S=>{q(S),b.current=S},...pe,placeholder:"Search","data-testid":"search-query-input"})),e.createElement("input",{type:"submit",hidden:!0})),e.createElement("div",null,e.createElement(Le._,null,"View as"),e.createElement(be.S,{options:mt,value:String(r.view??mt[0].value),onChange:j}))),o&&e.createElement("div",null,e.createElement(D.zx,{fullWidth:!1,icon:"times",variant:"secondary",onClick:he},"Clear filters")))))},sa=a=>({container:(0,l.css)`
      margin-bottom: ${a.spacing(1)};
    `,dsPickerContainer:(0,l.css)`
      width: 550px;
      flex-grow: 0;
      margin: 0;
    `,searchInput:(0,l.css)`
      flex: 1;
      margin: 0;
    `});function oa(){const a=(0,f.wW)(dt);return e.createElement("div",null,e.createElement("div",null,"Search syntax allows to query alert rules by the parameters defined below."),e.createElement("hr",null),e.createElement("div",{className:a.grid},e.createElement("div",null,"Filter type"),e.createElement("div",null,"Expression"),e.createElement(De,{title:"Datasources",expr:"datasource:mimir datasource:prometheus"}),e.createElement(De,{title:"Folder/Namespace",expr:"namespace:global"}),e.createElement(De,{title:"Group",expr:"group:cpu-usage"}),e.createElement(De,{title:"Rule",expr:'rule:"cpu 80%"'}),e.createElement(De,{title:"Labels",expr:"label:team=A label:cluster=a1"}),e.createElement(De,{title:"State",expr:"state:firing|normal|pending"}),e.createElement(De,{title:"Type",expr:"type:alerting|recording"}),e.createElement(De,{title:"Health",expr:"health:ok|nodata|error"})))}function De({title:a,expr:n}){const r=(0,f.wW)(dt);return e.createElement(e.Fragment,null,e.createElement("div",null,a),e.createElement("code",{className:r.code},n))}const dt=a=>({grid:(0,l.css)`
    display: grid;
    grid-template-columns: max-content auto;
    gap: ${a.spacing(1)};
    align-items: center;
  `,code:(0,l.css)`
    display: block;
    text-align: center;
  `}),ca=la;var ia=t(46002);const gt={groups:$t,state:Bt},ua=v.gr+1,ma=(0,y.Pf)(()=>{const a=(0,G.useDispatch)(),n=(0,f.wW)(da),r=(0,e.useMemo)(K.mA,[]),[c,s]=(0,e.useState)(!1),o=(0,e.useCallback)(()=>s(!1),[]),[i]=(0,F.K)(),{filterState:u,hasActiveFilters:d}=ct(),m=gt[i.view]?i.view:"groups",T=gt[m],P=(0,_._)(k=>k.promRules),L=(0,_._)(k=>k.rulerRules),b=r.some(k=>P[k]?.loading||L[k]?.loading),U=Object.entries(P),A=Object.entries(L),C=U.every(([k,S])=>S.dispatched&&(S?.result!==void 0||S?.error!==void 0)),q=A.every(([k,S])=>S.dispatched&&(S?.result!==void 0||S?.error!==void 0)),pe=U.every(([k,S])=>S.dispatched&&S?.result?.length===0),V=A.every(([k,S])=>Object.entries(S?.result??{}).every(([xe,$e])=>$e?.length===0)&&S.dispatched),z=d?void 0:ua,[ie,j]=(0,g.Z)(async()=>{b||await a((0,Be.ei)(!1,{limitAlerts:z}))},[b,z,a]);(0,e.useEffect)(()=>{(0,R.$I)().catch(()=>{})},[]),(0,e.useEffect)(()=>{a((0,Be.ei)(!1,{limitAlerts:z}))},[a,z]),(0,h.Z)(j,ia.p4);const J=C&&pe&&U.length>0&&V&&q,X=(0,Fe.Zo)(),he=wt(X,u);return e.createElement(Ae.J,{navId:"alert-list",isLoading:!1},e.createElement(Je,null),e.createElement(ca,{onFilterCleared:o}),!J&&e.createElement(e.Fragment,null,e.createElement("div",{className:n.break}),e.createElement("div",{className:n.buttonsContainer},e.createElement("div",{className:n.statsContainer},m==="groups"&&d&&e.createElement(D.zx,{className:n.expandAllButton,icon:c?"angle-double-up":"angle-double-down",variant:"secondary",onClick:()=>s(!c)},c?"Collapse all":"Expand all"),e.createElement(nt.WN,{namespaces:he})),e.createElement(O.K,{direction:"row",gap:.5},e.createElement(de,null)))),J&&e.createElement(E,null),!J&&e.createElement(T,{expandAll:c,namespaces:he}))},{style:"page"}),da=a=>({break:(0,l.css)`
    width: 100%;
    height: 0;
    margin-bottom: ${a.spacing(2)};
    border-bottom: solid 1px ${a.colors.border.medium};
  `,buttonsContainer:(0,l.css)`
    margin-bottom: ${a.spacing(2)};
    display: flex;
    justify-content: space-between;
  `,statsContainer:(0,l.css)`
    display: flex;
    flex-direction: row;
    align-items: center;
  `,expandAllButton:(0,l.css)`
    margin-right: ${a.spacing(1)};
  `}),ga=ma},53914:(le,W,t)=>{t.d(W,{q:()=>y});var l=t(56375),e=t.n(l),g=t(85960),h=t(57297);const y=({actions:R,children:I})=>{const N=(0,l.filter)(R,F),$=(0,l.filter)(R,G);return N.length?g.createElement(f,{actions:N},I):$.length?g.createElement(D,{actions:$},I):null},f=({actions:R,children:I})=>{const N=(0,h.Mz)();return O(N,R)?g.createElement(g.Fragment,null,I):null},D=({actions:R,children:I})=>{const N=(0,h.K_)();return O(N,R)?g.createElement(g.Fragment,null,I):null};function O(R,I){return(0,l.chain)(R).pick(I).values().value().some(([N,$])=>$===!0)}function F(R){return Object.values(h.oI).includes(R)}function G(R){return Object.values(h.jU).includes(R)}},27908:(le,W,t)=>{t.d(W,{u:()=>R});var l=t(66681),e=t(78344),g=t.n(e),h=t(85960),y=t(53565),f=t(47257),D=t(62577),O=t(29165),F=t(55855),G=t(23694);function R({format:N,textDefinition:$,downloadFileName:fe,onClose:Pe}){const Re=(0,f.wW)(I),Ce=(0,h.useCallback)(()=>{const te=new Blob([$],{type:`application/${N};charset=utf-8`});g()(te,`${fe}.${N}`)},[$,fe,N]),ne=(0,h.useMemo)(()=>{const te=G.uN[N];return te.formatter?te.formatter($):$},[N,$]);return h.createElement("div",{className:Re.container},h.createElement("div",{className:Re.content},h.createElement(y.Z,{disableWidth:!0},({height:te})=>h.createElement(D.p,{width:"100%",height:te,language:N,value:ne,monacoOptions:{minimap:{enabled:!1},scrollBeyondLastLine:!1,lineNumbers:"on",readOnly:!0}}))),h.createElement("div",{className:Re.actions},h.createElement(O.zx,{variant:"secondary",onClick:Pe},"Cancel"),h.createElement(F.m,{icon:"copy",getText:()=>$},"Copy code"),h.createElement(O.zx,{icon:"download-alt",onClick:Ce},"Download")))}const I=N=>({container:(0,l.css)`
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: ${N.spacing(2)};
  `,content:(0,l.css)`
    flex: 1 1 100%;
  `,actions:(0,l.css)`
    flex: 0;
    justify-content: flex-end;
    display: flex;
    gap: ${N.spacing(1)};
  `})},29657:(le,W,t)=>{t.d(W,{i:()=>h});var l=t(85960),e=t(63153),g=t(47831);function h({activeTab:y,onTabChange:f,children:D,onClose:O,formatProviders:F,title:G="Export"}){const R=Object.values(F).map(I=>({label:I.name,value:I.exportFormat}));return l.createElement(e.d,{title:G,subtitle:"Select the format and download the file or copy the contents to clipboard",tabs:l.createElement(g.mg,{tabs:R,setActiveTab:f,activeTab:y}),onClose:O,size:"md"},D)}},23694:(le,W,t)=>{t.d(W,{uN:()=>h});const l={name:"JSON",exportFormat:"json",formatter:f=>{try{return JSON.stringify(JSON.parse(f),null,4)}catch{return f}}},e={name:"YAML",exportFormat:"yaml"},g={name:"Terraform (HCL)",exportFormat:"hcl"},h={[l.exportFormat]:l,[e.exportFormat]:e,[g.exportFormat]:g},y=[l,e]},21863:(le,W,t)=>{t.d(W,{h:()=>O});var l=t(66681),e=t(85960),g=t(47257),h=t(57652),y=t(13086),f=t(97666),D=t(40377);function O({contentText:G,externalLink:R,linkText:I,title:N}){const $=(0,g.wW)(F);return e.createElement(h.P,{content:e.createElement("div",{className:$.mutedText},G),title:e.createElement(y.K,{gap:1,direction:"row"},e.createElement(f.J,{name:"question-circle"}),N),footer:R?e.createElement("a",{href:R,target:"_blank",rel:"noreferrer"},e.createElement(y.K,{direction:"row",gap:.5,alignItems:"center"},e.createElement(D.x,{color:"link"},I," ",e.createElement(f.J,{size:"sm",name:"external-link-alt"})))):void 0,closeButton:!0,placement:"bottom-start"},e.createElement("div",{className:$.helpInfo},e.createElement(y.K,{direction:"row",alignItems:"center",gap:.5},e.createElement(f.J,{name:"question-circle",size:"sm"}),e.createElement(D.x,{variant:"bodySmall",color:"primary"},"Need help?"))))}const F=G=>({mutedText:(0,l.css)`
    color: ${G.colors.text.secondary};
    font-size: ${G.typography.size.sm};
  `,helpInfo:(0,l.css)`
    cursor: pointer;
    text-decoration: underline;
  `})},78985:(le,W,t)=>{t.d(W,{z:()=>D});var l=t(66681),e=t(85960),g=t(47257),h=t(51637),y=t(40377),f=t(13086);const D=({title:F,stepNo:G,children:R,fullWidth:I=!1,description:N})=>{const $=(0,g.wW)(O);return e.createElement("div",{className:$.parent},e.createElement(h.C,{className:(0,l.cx)(I&&$.fullWidth),label:e.createElement(y.x,{variant:"h3"},G,". ",F)},e.createElement(f.K,{direction:"column"},N&&e.createElement("div",{className:$.description},N),R)))},O=F=>({parent:(0,l.css)`
    display: flex;
    flex-direction: row;
    max-width: ${F.breakpoints.values.xl}px;
    border: solid 1px ${F.colors.border.weak};
    border-radius: ${F.shape.radius.default};
    padding: ${F.spacing(2)} ${F.spacing(3)};
  `,description:(0,l.css)`
    margin-top: -${F.spacing(2)};
  `,fullWidth:(0,l.css)`
    width: 100%;
  `})},47831:(le,W,t)=>{t.d(W,{CU:()=>Re,mg:()=>Ce});var l=t(66681),e=t(48525),g=t(85960),h=t(53285),y=t(53565),f=t(47257),D=t(63153),O=t(70523),F=t(94439),G=t(29165),R=t(14607),I=t(97666),N=t(62577),$=t(38884),fe=t(9001);const Pe=[{label:"Yaml",value:"yaml"}],Re=({onClose:H})=>{const[me,ve]=(0,g.useState)("yaml"),{setValue:w}=(0,h.Gc)(),de=(0,f.wW)(Te),Ae=Se=>{for(const ge in Se)w(ge,Se[ge]);H()};return g.createElement(D.d,{title:"Inspect Alert rule",subtitle:g.createElement("div",{className:de.subtitle},g.createElement(Ce,{tabs:Pe,setActiveTab:ve,activeTab:me})),onClose:H},me==="yaml"&&g.createElement(ne,{onSubmit:Ae}))};function Ce({tabs:H,activeTab:me,setActiveTab:ve}){return g.createElement(O.J,null,H.map((w,de)=>g.createElement(F.O,{key:`${w.value}-${de}`,label:w.label,value:w.value,onChangeTab:()=>ve(w.value),active:me===w.value})))}const ne=({onSubmit:H})=>{const me=(0,f.wW)(Me),{getValues:ve}=(0,h.Gc)(),w=(0,$.yh)(ve()),[de,Ae]=(0,g.useState)((0,e.$w)(w)),Se=()=>{const ge=(0,e.zD)(de),p=ve(),E=Oe(ge);H({...p,...E})};return g.createElement(g.Fragment,null,g.createElement("div",{className:me.applyButton},g.createElement(G.zx,{type:"button",onClick:Se},"Apply"),g.createElement(R.u,{content:g.createElement(te,null),theme:"info",placement:"left-start",interactive:!0},g.createElement(I.J,{name:"exclamation-triangle",size:"xl"}))),g.createElement("div",{className:me.content},g.createElement(y.Z,{disableWidth:!0},({height:ge})=>g.createElement(N.p,{width:"100%",height:ge,language:"yaml",value:de,onBlur:Ae,monacoOptions:{minimap:{enabled:!1}}}))))};function te(){return g.createElement("div",null,"The YAML content in the editor only contains alert rule configuration ",g.createElement("br",null),"To configure Prometheus, you need to provide the rest of the"," ",g.createElement("a",{href:"https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/",target:"_blank",rel:"noreferrer"},"configuration file content."))}function Oe(H){return(0,fe.cG)(H)?(0,$.WL)(H):(0,fe.yF)(H)?(0,$.lN)(H):{}}const Me=H=>({content:(0,l.css)`
    flex-grow: 1;
    height: 100%;
    padding-bottom: 16px;
    margin-bottom: ${H.spacing(2)};
  `,applyButton:(0,l.css)`
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    flex-grow: 0;
    margin-bottom: ${H.spacing(2)};
  `}),Te=()=>({subtitle:(0,l.css)`
    display: flex;
    align-items: center;
    justify-content: space-between;
  `})},90943:(le,W,t)=>{t.d(W,{p0:()=>Te,Ps:()=>H,_m:()=>me,eW:()=>ge,_4:()=>Ae,Fu:()=>w,Ry:()=>te,Dr:()=>Me,KP:()=>Se,Yq:()=>ve});var l=t(56375),e=t(24677),g=t(37634),h=t(23757),y=t(1713),f=t(67954),D=t(34524),O=t(31476),F=t(36530),G=t(20304),R=t(84513),I=t(18745);const N=(0,R.Z)($,(p,E)=>ne(p[0])===ne(E[0]));function $(p){const E=new I.kJ,M=p.map(v=>v.refId);return E.createNodes(M),p.forEach(v=>{const Q=v.refId;((0,O.j)(v.model)&&v.model.type==="math"?fe(v.model.expression??""):[v.model.expression]).forEach(Z=>{Q&&Z&&!(Q===Z)&&E.link(Z,Q)})}),E}function fe(p){const E=new RegExp(/\$\{(?<var>[a-zA-Z0-9_ ]+?)\}/gm),M=new RegExp(/\$(?<var>[a-zA-Z0-9_]+)/gm),v=Array.from(p.matchAll(E)).map(x=>x.groups?.var),Q=Array.from(p.matchAll(M)).map(x=>x.groups?.var);return(0,l.compact)((0,l.uniq)([...v,...Q]))}const Pe=(0,l.memoize)(Re,(p,E)=>p+Ce(E));function Re(p,E){const M=E.getNode(p);let v=[];function Q(x){const B=x.inputEdges;B.length>0?B.forEach(Z=>{Z.inputNode&&Q(Z.inputNode)}):v?.push(x)}return Q(M),v.map(x=>x.name)}function Ce(p){return Object.keys(p.nodes).map(E=>{const M=p.nodes[E];let v=M.outputEdges.map(x=>x.outputNode?.name).join(", "),Q=M.inputEdges.map(x=>x.inputNode?.name).join(", ");return`${M.name}:${v}:${Q}`}).join(" ")}function ne(p){return p.map(E=>{const M=(0,O.j)(E.model)?E.model.type:E.queryType;return E.refId+(E.model.expression??"")+M}).join()}function te(p,E,M){return p.map(v=>{if(E===M||!(0,O.j)(v.model))return v;const Q=v.model.type==="math",x=v.model.type==="reduce",B=v.model.type==="resample",Z=v.model.type==="classic_conditions",re=v.model.type==="threshold";if(Q)return{...v,model:{...v.model,expression:Oe(v.model.expression??"",E,M)}};if(B||x||re){const _=v.model.expression===E;return{...v,model:{...v.model,expression:_?M:v.model.expression}}}if(Z){const _=v.model.conditions?.map(K=>({...K,query:{...K.query,params:K.query.params.map(se=>se===E?M:se)}}));return{...v,model:{...v.model,conditions:_}}}return v})}function Oe(p,E,M){const v=new RegExp("(\\$"+E+"\\b)|(\\${"+E+"})","gm"),Q="${"+M+"}";return p.replace(v,Q)}function Me(p,E){return p.find(M=>M.refId===E)!==void 0}function Te(p){return p.includes("/")||p.includes("\\")?'Cannot contain "/" or "\\" characters':!0}function H(p){if(p.series.length===0)return;const E=(0,e.xI)(p.series);let M;return E&&(M=new Error("You cannot use time series data as an alert condition, consider adding a reduce expression.")),M}function me(p){if(p.errors?.length)return new Error(p.errors[0].message)}function ve(p){const M=(p[0]?.meta?.notices??[]).find(v=>v.severity==="warning")?.text;return M?new Error(M):void 0}function w(p){const E={},M=[F.Us.threshold,F.Us.classic];for(const x of p){if(!(0,O.j)(x.model)||!M.includes(x.model.type)||!Array.isArray(x.model.conditions))continue;const B=x.model.conditions.some(de);x.model.conditions.forEach(Z=>{const re=Z.evaluator.params,_=Z.query?.params[0]??x.model.expression;if(!_)return;const K=de(Z);try{const se=N(p),ae=Pe(_,se);p.filter(Ie=>ae.includes(Ie.refId)).forEach(Ie=>{const ce=Ie.refId,Ne=!!(!(0,O.j)(Ie?.model)&&ce);ce&&!E[ce]&&(E[ce]={config:{mode:g.H.Absolute,steps:[]},mode:y.i3.Line}),ce&&Ne&&!K&&!B?v(ce,re[0]):ce&&Ne&&K&&(Q(ce,re,Z.evaluator.type),E[ce].mode=y.i3.LineAndArea)})}catch(se){console.error("Failed to parse thresholds",se);return}})}function v(x,B){E[x].config.steps.push({value:-1/0,color:"transparent"},{value:B,color:f.config.theme2.colors.error.main})}function Q(x,B,Z){Z===D.$.IsWithinRange&&E[x].config.steps.push({value:-1/0,color:"transparent"},{value:B[0],color:f.config.theme2.colors.error.main},{value:B[1],color:f.config.theme2.colors.error.main},{value:B[1],color:"transparent"}),Z===D.$.IsOutsideRange&&E[x].config.steps.push({value:-1/0,color:f.config.theme2.colors.error.main},{value:B[0],color:f.config.theme2.colors.error.main},{value:B[0],color:"transparent"},{value:B[1],color:f.config.theme2.colors.error.main}),E[x].config.steps.sort((re,_)=>re.value-_.value),E[x].config.steps=E[x].config.steps.filter(re=>re.value!==void 0)}return E}function de(p){return p.evaluator.type===D.$.IsWithinRange||p.evaluator.type===D.$.IsOutsideRange}function Ae(p){const E="Failed to fetch data";if(p.state!==h.Gu.Error)return;const M=p.errors;return M?.length?M.map(v=>v.message??E).join(", "):p.error?.message??E}function Se(p=""){return p==="recording"?G.$.cloudRecording:G.$.grafana}function ge(p,E){const M=E.filter(B=>!(0,O.j)(B.model)).map(B=>B.refId),v=p.filter(B=>!(0,O.j)(B.model)).map(B=>B.refId),[Q,x]=(0,l.xor)(v,M);return[Q,x]}},90504:(le,W,t)=>{t.d(W,{A:()=>h});var l=t(85960),e=t(14607),g=t(29165);const h=({tooltip:y,icon:f,to:D,target:O,onClick:F,className:G,tooltipPlacement:R="top",...I})=>{const N=typeof y=="string"?y:void 0;return l.createElement(e.u,{content:y,placement:R},D?l.createElement(g.Qj,{variant:"secondary",fill:"text",icon:f,href:D,size:"sm",target:O,...I,"aria-label":N}):l.createElement(g.zx,{className:G,variant:"secondary",fill:"text",size:"sm",icon:f,type:"button",onClick:F,...I,"aria-label":N}))}},75636:(le,W,t)=>{t.d(W,{j:()=>h});var l=t(85960),e=t(30694),g=t(91);function h(){const{search:y}=(0,e.TH)(),f=(0,l.useMemo)(()=>new URLSearchParams(y),[y]),D=(0,l.useCallback)((O,F)=>{g.E1.partial(O,F)},[]);return[f,D]}},31476:(le,W,t)=>{t.d(W,{j:()=>g});var l=t(32063),e=t(36530);const g=h=>{if(!h)return!1;if((0,l.Pr)(h.datasource))return!0;const y=h;return typeof y.type!="string"?!1:Object.values(e.Us).includes(y.type)}},23426:(le,W,t)=>{t.d(W,{Z:()=>g});var l=t(85960),e=function(h,y){var f=(0,l.useRef)(function(){});(0,l.useEffect)(function(){f.current=h}),(0,l.useEffect)(function(){if(y!==null){var D=setInterval(function(){return f.current()},y||0);return function(){return clearInterval(D)}}},[y])};const g=e}}]);

//# sourceMappingURL=AlertRuleListIndex.263f0b82c67e12bccf33.js.map