"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4009],{50166:(Le,ae,e)=>{e.r(ae),e.d(ae,{default:()=>We});var n=e(96540),a=e(16817),t=e(66602),te=e(80348),h=e(32196),R=e(42418),g=e(40845),j=e(55852);function S({title:c,children:E}){return n.createElement(R.F,{className:(0,g.of)(T).warning,severity:"warning",title:c},n.createElement("p",null,E),n.createElement(j.z9,{href:"alerting/list"},"To rule list"))}const T=c=>({warning:(0,h.css)`
    margin: ${c.spacing(4)};
  `});var se=e(2543),$=e(12131),F=e(39558),V=e(49785),ue=e(24180),je=e(54625),we=e(32264),ze=e(66864),Re=e(62930),Ee=e(40276),Ae=e(67061),Pe=e(96374),he=e(75269),xe=e(3169),Qe=e(10096),f=e(40715),X=e(83277),y=e(25027),fe=e(61410),ie=e(23770),M=e(86590),Se=e(88467),k=e(63066),be=e(18461),He=e(79938),De=e(16293),Ne=e(76648),Je=e(84029);const W=({alertUid:c,exportFormat:E,onClose:A})=>{const{currentData:N="",isFetching:Y}=He.hK.endpoints.exportRules.useQuery({ruleUid:c,format:E}),D=`${c}-${new Date().getTime()}`;return Y?n.createElement(F._,{text:"Loading...."}):n.createElement(De.J,{format:E,textDefinition:N,downloadFileName:D,onClose:A})},ne=({onClose:c,alertUid:E})=>{const[A,N]=(0,n.useState)("yaml");return n.createElement(Ne.m,{activeTab:A,onTabChange:N,onClose:c,formatProviders:Object.values(Je.sl)},n.createElement(W,{alertUid:E,exportFormat:A,onClose:c}))};var U=e(53534),le=e(31099),v=e(88575),O=e(10354),I=e(16504),C=e(88323),Q=e(25968),_=e(7921);const pe=({rulesSourceName:c})=>{const{control:E,watch:A,formState:{errors:N},setValue:Y}=(0,V.xW)(),D=(0,g.of)(ge),ce=(0,fe.$)(Te=>Te.rulerRules),H=(0,te.useDispatch)();(0,n.useEffect)(()=>{H((0,ie.eB)({rulesSourceName:c}))},[c,H]);const re=ce[c]?.result,Ie=A("namespace"),me=(0,n.useMemo)(()=>re?Object.keys(re).map(Te=>({label:Te,value:Te})):[],[re]),Me=(0,n.useMemo)(()=>Ie&&re?.[Ie]?.map(Te=>({label:Te.name,value:Te.name}))||[],[Ie,re]);return n.createElement("div",{className:D.flexRow},n.createElement(v.D,{"data-testid":"namespace-picker",label:"Namespace",error:N.namespace?.message,invalid:!!N.namespace?.message},n.createElement(I.e,{render:({field:{onChange:Te,ref:st,...mt}})=>n.createElement(C.ip,{...mt,allowCustomValue:!0,className:D.input,onChange:ye=>{Y("group",""),Te(ye.value)},options:me,width:42}),name:"namespace",control:E,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:_.G0}}})),n.createElement(v.D,{"data-testid":"group-picker",label:"Group",error:N.group?.message,invalid:!!N.group?.message},n.createElement(I.e,{render:({field:{ref:Te,...st}})=>n.createElement(C.ip,{...st,allowCustomValue:!0,options:Me,width:42,onChange:mt=>{Y("group",mt.value??"")},className:D.input}),name:"group",control:E,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:_.G0}}})))},ge=c=>({flexRow:(0,h.css)`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;

    & > * + * {
      margin-left: ${c.spacing(3)};
    }
  `,input:(0,h.css)`
    width: 330px !important;
  `});var Xe=e(67986),Fe=e(271);const it=()=>{const c=(0,g.of)(rt),{register:E,control:A,watch:N,formState:{errors:Y}}=(0,V.xW)(),D=N("type"),ce=N("dataSourceName");return n.createElement(Fe.P,{stepNo:3,title:"Set evaluation behavior"},n.createElement(v.D,{label:"Pending period",description:"Period in which an alert rule can be in breach of the condition until the alert rule fires."},n.createElement("div",{className:c.flexRow},n.createElement(v.D,{invalid:!!Y.forTime?.message,error:Y.forTime?.message,className:c.inlineField},n.createElement(O.p,{...E("forTime",{pattern:{value:/^\d+$/,message:"Must be a positive integer."}}),width:8})),n.createElement(I.e,{name:"forTimeUnit",render:({field:{onChange:H,ref:re,...Ie}})=>n.createElement(C.l6,{...Ie,options:Q.sc,onChange:me=>H(me?.value),width:15,className:c.timeUnit}),control:A}))),D===M.Z.cloudAlerting&&ce&&n.createElement(pe,{rulesSourceName:ce}),n.createElement(Xe.L,null))},rt=c=>({inlineField:(0,h.css)`
    margin-bottom: 0;
  `,flexRow:(0,h.css)`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
  `,timeUnit:(0,h.css)`
    margin-left: ${c.spacing(.5)};
  `});var tt=e(74400),ot=e(9267);function Ve(){const{watch:c}=(0,V.xW)(),E=c("dataSourceName");return E?n.createElement(Fe.P,{stepNo:3,title:"Add namespace and group",description:"Select the Namespace and Group for your recording rule."},n.createElement(pe,{rulesSourceName:E})):null}var Et=e(73716),yt=e(890);const ct=({existing:c,prefill:E})=>{const A=(0,g.of)(It),N=(0,te.useDispatch)(),Y=(0,xe._2)(),[D]=(0,X.s)(),[ce,H]=(0,n.useState)(!1),[re,Ie]=(0,n.useState)(c?.group.interval??k.pY),me=(0,ue.g)(),Me=(0,_._u)(me.type),Te=me.id,st=D.returnTo?String(D.returnTo):"/alerting/list",[mt,ye]=(0,n.useState)(!1),Pt=(0,n.useMemo)(()=>c?(0,k.ir)(c):E?St(E):typeof D.defaults=="string"?xt(D.defaults,Me):{...(0,k.IJ)(),condition:"C",queries:(0,k.qO)(),type:Me||M.Z.grafana,evaluateEvery:re},[c,E,D,re,Me]),Gt=(0,V.mN)({mode:"onSubmit",defaultValues:Pt,shouldFocusError:!0}),{handleSubmit:Dt,watch:ft}=Gt,_e=ft("type"),Bt=ft("dataSourceName"),Ut=!!(_e&&(_e===M.Z.grafana||Bt)),nt=(0,fe.$)(ve=>ve.ruleForm.saveRule)||Se.jA;(0,f.o)(ve=>ve.unifiedAlerting.ruleForm.saveRule=Se.jA);const[Tt,vt]=(0,n.useState)(""),$t=(ve="")=>{vt(ve)},At=(ve,wt)=>{if(Tt!==""){Y.error(Tt);return}c||(ve.manualRouting?localStorage.setItem(k.Q8,"true"):localStorage.setItem(k.Q8,"false")),N((0,ie._$)({values:{...Pt,...ve,annotations:ve.annotations?.map(({key:at,value:pt})=>({key:at.trim(),value:pt.trim()})).filter(({key:at,value:pt})=>!!at&&!!pt)??[],labels:ve.labels?.map(({key:at,value:pt})=>({key:at.trim(),value:pt.trim()})).filter(({key:at})=>!!at)??[]},existing:c,redirectOnSave:wt?st:void 0,initialAlertRuleName:Pt.name,evaluateEvery:re}))},Ot=()=>{if(c){const ve=be.P1(c.ruleSourceName,c.namespace,c.group.name,c.rule);N((0,ie.KH)(ve,{navigateTo:"/alerting/list"}))}},Nt=ve=>{c||(0,y.SN)({grafana_version:we.$.buildInfo.version,org_id:Qe.TP.user.orgId,user_id:Qe.TP.user.id,error:Object.keys(ve).toString()}),Y.error("There are errors in the form. Please correct them and try again!")},Qt=()=>{(0,y.fH)(y.le.cancelSavingAlertRule)},Mt=ft("evaluateEvery");(0,n.useEffect)(()=>Ie(Mt),[Mt]);const Lt=n.createElement(ze.Gy,{height:"auto",justify:"flex-end"},c&&n.createElement(j.$n,{variant:"primary",type:"button",size:"sm",onClick:Dt(ve=>At(ve,!1),Nt),disabled:nt.loading},nt.loading&&n.createElement(Re.y,{className:A.buttonSpinner,inline:!0}),"Save rule"),n.createElement(j.$n,{variant:"primary",type:"button",size:"sm",onClick:Dt(ve=>At(ve,!0),Nt),disabled:nt.loading},nt.loading&&n.createElement(Re.y,{className:A.buttonSpinner,inline:!0}),"Save rule and exit"),n.createElement(je.Link,{to:st},n.createElement(j.$n,{variant:"secondary",disabled:nt.loading,type:"button",onClick:Qt,size:"sm"},"Cancel")),c?n.createElement(j.$n,{fill:"outline",variant:"destructive",type:"button",onClick:()=>ye(!0),size:"sm"},"Delete"):null,c&&ht(ft)&&n.createElement(j.$n,{variant:"secondary",type:"button",onClick:()=>H(!0),disabled:nt.loading,size:"sm"},"Edit YAML"));return n.createElement(V.Op,{...Gt},n.createElement(he.H,{actions:Lt}),n.createElement("form",{onSubmit:ve=>ve.preventDefault(),className:A.form},n.createElement("div",{className:A.contentOuter},n.createElement(Ee.E,{autoHeightMin:"100%",hideHorizontalTrack:!0},n.createElement(Ae.B,{direction:"column",gap:3},n.createElement(U.G,null),n.createElement(yt.N,{editingExistingRule:!!c,onDataChange:$t}),Ut&&n.createElement(n.Fragment,null,_e===M.Z.grafana&&n.createElement(tt.R,{evaluateEvery:re,setEvaluateEvery:Ie,existing:!!c,enableProvisionedGroups:!1}),_e===M.Z.cloudAlerting&&n.createElement(it,null),_e===M.Z.cloudRecording&&n.createElement(Ve,null),n.createElement(ot.N,{alertUid:Te}),_e!==M.Z.cloudRecording&&n.createElement(le.A,null)))))),mt?n.createElement(Pe.u,{isOpen:!0,title:"Delete rule",body:"Deleting this rule will permanently remove it. Are you sure you want to delete this rule?",confirmText:"Yes, delete",icon:"exclamation-triangle",onConfirm:Ot,onDismiss:()=>ye(!1)}):null,ce?_e===M.Z.grafana?n.createElement(ne,{alertUid:Te,onClose:()=>H(!1)}):n.createElement(Et.G_,{onClose:()=>H(!1)}):null)},ht=c=>{const[E,A]=c(["type","dataSourceName"]);return(E===M.Z.cloudAlerting||E===M.Z.cloudRecording)&&A!==""};function xt(c,E){let A;try{A=JSON.parse(c)}catch{return{...(0,k.IJ)(),queries:(0,k.qO)()}}return(0,k.Rk)({...(0,k.IJ)(),...A,annotations:(0,k.JE)(A.annotations??[]),queries:A.queries??(0,k.qO)(),type:E||M.Z.grafana,evaluateEvery:k.pY})}function St(c){return(0,k.Rk)({...(0,k.IJ)(),...c})}const It=c=>({buttonSpinner:(0,h.css)({marginRight:c.spacing(1)}),form:(0,h.css)({width:"100%",height:"100%",display:"flex",flexDirection:"column"}),contentOuter:(0,h.css)({background:c.colors.background.primary,overflow:"hidden",flex:1}),flexRow:(0,h.css)({display:"flex",flexDirection:"row",justifyContent:"flex-start"})});var ut=e(79944),qe=e(23662),Rt=e(3704);function Ct({sourceRuleId:c}){const E=(0,te.useDispatch)(),{loading:A,value:N,error:Y}=(0,a.A)(()=>E((0,ie.pT)(c)).unwrap(),[c]);if(A)return n.createElement(F._,{text:"Loading the rule"});if(N){const D=i(N),ce=(0,k.QX)(D);return n.createElement(ct,{prefill:ce})}return Y?n.createElement(R.F,{title:"Error",severity:"error"},Y.message):n.createElement(R.F,{title:"Cannot copy the rule. The rule does not exist",buttonContent:"Go back to alert list",onRemove:()=>$.Ny.replace((0,Rt.c)("/alerting/list"))})}function dt(c,E){(0,qe.lT)(c)&&(c.grafana_alert.title=E),(0,qe.$y)(c)&&(c.alert=E),(0,qe.i7)(c)&&(c.record=E)}function i(c){const E=(0,se.cloneDeep)(c);return dt(E.rule,(0,ut.V)((0,qe.qz)(E.rule),E.group.rules.map(qe.qz))),(0,qe.lT)(E.rule)&&(E.rule.grafana_alert.uid="",E.rule.grafana_alert.provenance&&(E.group={name:"",rules:E.group.rules})),E}var P=e(97009);function b({identifier:c,id:E}){(0,f.o)(me=>me.unifiedAlerting.ruleForm.existingRule=Se.jA);const{loading:A,result:N,error:Y,dispatched:D}=(0,fe.$)(me=>me.ruleForm.existingRule),ce=(0,te.useDispatch)(),{isEditable:H,loading:re}=(0,P.g)(be.VY(c),N?.rule),Ie=A||re;return(0,n.useEffect)(()=>{D||ce((0,ie.pT)(c))},[D,ce,c]),Ie||H===void 0?n.createElement(F._,{text:"Loading rule..."}):Y?n.createElement(R.F,{severity:"error",title:"Failed to load rule"},Y.message):N?H===!1?n.createElement(S,{title:"Cannot edit rule"},"Sorry! You do not have permission to edit this rule."):n.createElement(ct,{existing:N}):n.createElement(S,{title:"Rule not found"},"Sorry! This rule does not exist.")}var G=e(33450),K=e(39964),de=e(41520);const z={icon:"bell",id:"alert-rule-view"},q=(c,E)=>E==="recording"?c?{...z,id:"alert-rule-edit",text:"Edit recording rule"}:{...z,id:"alert-rule-add",text:"New recording rule"}:c?{...z,id:"alert-rule-edit",text:"Edit rule"}:{...z,id:"alert-rule-add",text:"New alert rule"},Ge=({match:c})=>{const E=(0,te.useDispatch)(),[A]=(0,K.l)(),{type:N}=c.params,Y=be.uE(c.params),D=be.x6(Y,!0),ce=A.get("copyFrom")??void 0,H=be.x6(ce),{loading:re=!0}=(0,a.A)(async()=>{D&&await E((0,ie.DC)({rulesSourceName:D.ruleSourceName})),H&&await E((0,ie.DC)({rulesSourceName:H.ruleSourceName}))},[E]),{canCreateGrafanaRules:Ie,canCreateCloudRules:me,canEditRules:Me}=(0,de.V)(),Te=(0,n.useCallback)(()=>{if(!re)return!D&&!Ie&&!me?n.createElement(S,{title:"Cannot create rules"},"Sorry! You are not allowed to create rules."):D&&!Me(D.ruleSourceName)?n.createElement(S,{title:"Cannot edit rules"},"Sorry! You are not allowed to edit rules."):D?n.createElement(b,{key:Y,identifier:D,id:Y}):H?n.createElement(Ct,{sourceRuleId:H}):n.createElement(ct,null)},[me,Ie,Me,H,Y,D,re]);return n.createElement(G.d,{isLoading:re,navId:"alert-list",pageNav:q(D,N)},Te())},We=(0,t.Xc)(Ge,{style:"page"})},69179:(Le,ae,e)=>{e.r(ae),e.d(ae,{default:()=>Je});var n=e(96540),a=e(16817),t=e(12131),te=e(39558),h=e(42418),R=e(80348),g=e(23770),j=e(63066),S=e(18461),T=e(23662),se=e(3704),$=e(33450),F=e(49785),V=e(55852),ue=e(40276),je=e(67061),we=e(3169),ze=e(83277),Re=e(75269),Ee=e(79938),Ae=e(28220),Pe=e(730),he=e(57220),xe=e(16293),Qe=e(76648),f=e(84029),X=e(53534),y=e(31099),fe=e(74400),ie=e(9267),M=e(890);function Se({ruleForm:W,alertUid:ne}){const U=(0,F.mN)({mode:"onSubmit",defaultValues:W,shouldFocusError:!0}),[le]=(0,ze.s)(),v=!!W,O=(0,we._2)(),I=le.returnTo?String(le.returnTo):"/alerting/list",[C,Q]=(0,n.useState)(void 0),[_,pe]=(0,n.useState)(""),[ge,Xe]=(0,n.useState)(W?.evaluateEvery??j.pY),Fe=()=>{O.error("There are errors in the form. Please correct them and try again!")},it=(Ve="")=>{pe(Ve)},rt=Ve=>{if(_!==""){O.error(_);return}Q(Ve)},tt=(0,n.useCallback)(()=>{Q(void 0)},[Q]),ot=[n.createElement(V.z9,{href:I,key:"cancel",size:"sm",variant:"secondary",onClick:()=>rt(void 0)},"Cancel"),n.createElement(V.$n,{key:"export-rule",size:"sm",onClick:U.handleSubmit(Ve=>rt(Ve),Fe)},"Export")];return n.createElement(n.Fragment,null,n.createElement(F.Op,{...U},n.createElement(Re.H,{actions:ot}),n.createElement("form",{onSubmit:Ve=>Ve.preventDefault()},n.createElement("div",null,n.createElement(ue.E,{autoHeightMin:"100%",hideHorizontalTrack:!0},n.createElement(je.B,{direction:"column",gap:3},n.createElement(X.G,null),n.createElement(M.N,{editingExistingRule:v,onDataChange:it}),n.createElement(fe.R,{evaluateEvery:ge,setEvaluateEvery:Xe,existing:!!v,enableProvisionedGroups:!0}),n.createElement(ie.N,{alertUid:ne}),n.createElement(y.A,null))))),C&&n.createElement(Ne,{exportValues:C,onClose:tt,uid:ne})))}const k=(W,ne)=>{const{dsFeatures:U}=(0,Pe.O3)(he.hY),le=U?.rulerConfig;return(0,a.A)(async()=>le?await(0,Ae.HO)(le,W,ne):void 0,[le,W,ne])},be=(W,ne,U)=>{const le=(0,j.Z9)(ne),v={...le,grafana_alert:{...le.grafana_alert,uid:W}};if(U?.rules){let O=!1;const I=U.rules.map(C=>(0,T.lT)(C)&&C.grafana_alert.uid===W?(O=!0,v):C);return O||I.push(v),{...U,rules:I}}else return{name:U?.name??"",rules:[v]}},He=(W,ne)=>{const U=k(W.folder?.uid??"",W.group);return{payload:(0,n.useMemo)(()=>be(ne,W,U?.value),[ne,U,W]),loadingGroup:U.loading}},De=({exportFormat:W,exportValues:ne,onClose:U,uid:le})=>{const[v,O]=Ee.hK.endpoints.exportModifiedRuleGroup.useMutation(),{loadingGroup:I,payload:C}=He(ne,le),Q=ne.folder?.uid??"";if((0,n.useEffect)(()=>{!I&&v({payload:C,format:W,nameSpaceUID:Q})},[Q,W,C,v,I]),O.isLoading)return n.createElement(te._,{text:"Loading...."});const _=`modify-export-${C.name}-${le}-${new Date().getTime()}`;return n.createElement(xe.J,{format:W,textDefinition:O.data??"",downloadFileName:_,onClose:U})},Ne=n.memo(({onClose:W,exportValues:ne,uid:U})=>{const[le,v]=(0,n.useState)("yaml");return n.createElement(Qe.m,{title:"Export Group",activeTab:le,onTabChange:v,onClose:W,formatProviders:Object.values(f.sl)},n.createElement(De,{exportFormat:le,onClose:W,exportValues:ne,uid:U}))});Ne.displayName="GrafanaRuleDesignExporter";function Je({match:W}){const ne=(0,R.useDispatch)(),[U,le]=(0,n.useState)(void 0);(0,n.useEffect)(()=>{const Q=S.x6(W.params.id,!0);le(Q)},[W.params.id]);const{loading:v=!0}=(0,a.A)(async()=>{U&&await ne((0,g.DC)({rulesSourceName:U.ruleSourceName}))},[ne,U]),{loading:O,value:I,error:C}=(0,a.A)(async()=>{if(U)return await ne((0,g.pT)(U)).unwrap()},[U,v]);return U?O?n.createElement(te._,{text:"Loading the rule"}):C?n.createElement(h.F,{title:"Cannot load modify export",severity:"error"},C.message):!I&&!O&&!v?n.createElement($.d,{isLoading:O,navId:"alert-list",pageNav:{text:"Modify export"}},n.createElement(h.F,{title:"Cannot load the rule. The rule does not exist",buttonContent:"Go back to alert list",onRemove:()=>t.Ny.replace((0,se.c)("/alerting/list"))})):I&&!(0,T.lT)(I.rule)?n.createElement($.d,{isLoading:O,navId:"alert-list",pageNav:{text:"Modify export"}},n.createElement(h.F,{title:"This rule is not a Grafana-managed alert rule",buttonContent:"Go back to alert list",onRemove:()=>t.Ny.replace((0,se.c)("/alerting/list"))})):n.createElement($.d,{isLoading:O,navId:"alert-list",pageNav:{text:"Modify export",subTitle:"Modify the current alert rule and export the rule definition in the format of your choice. Any changes you make will not be saved."}},I&&n.createElement(Se,{ruleForm:(0,j.ir)(I),alertUid:W.params.id??""})):n.createElement("div",null,"Rule not found")}},33915:(Le,ae,e)=>{e.d(ae,{V:()=>se});var n=e(96540),a=e(10354),t=e(14578),te=e(35108),h=e(32196),R=e(40845),g=e(41068);function j(){const $=(0,R.of)(T);return n.createElement("div",null,"Prometheus duration format consist of a number followed by a time unit.",n.createElement("br",null),"Different units can be combined for more granularity.",n.createElement("hr",null),n.createElement("div",{className:$.list},n.createElement("div",{className:$.header},n.createElement("div",null,"Symbol"),n.createElement("div",null,"Time unit"),n.createElement("div",null,"Example")),n.createElement(S,{unit:g.y.seconds,name:"seconds",example:"20s"}),n.createElement(S,{unit:g.y.minutes,name:"minutes",example:"10m"}),n.createElement(S,{unit:g.y.hours,name:"hours",example:"4h"}),n.createElement(S,{unit:g.y.days,name:"days",example:"3d"}),n.createElement(S,{unit:g.y.weeks,name:"weeks",example:"2w"}),n.createElement("div",{className:$.examples},n.createElement("div",null,"Multiple units combined"),n.createElement("code",null,"1m30s, 2h30m20s, 1w2d"))))}function S({unit:$,name:F,example:V}){const ue=(0,R.of)(T);return n.createElement(n.Fragment,null,n.createElement("div",{className:ue.unit},$),n.createElement("div",null,F),n.createElement("code",null,V))}const T=$=>({unit:(0,h.css)`
    font-weight: ${$.typography.fontWeightBold};
  `,list:(0,h.css)`
    display: grid;
    grid-template-columns: max-content 1fr 2fr;
    gap: ${$.spacing(1,3)};
  `,header:(0,h.css)`
    display: contents;
    font-weight: ${$.typography.fontWeightBold};
  `,examples:(0,h.css)`
    display: contents;
    & > div {
      grid-column: 1 / span 2;
    }
  `}),se=n.forwardRef(($,F)=>n.createElement(a.p,{suffix:n.createElement(te.j,{content:n.createElement(j,null),disabled:!1},n.createElement(t.I,{name:"info-circle",size:"lg"})),...$,ref:F}));se.displayName="PromDurationInput"},99903:(Le,ae,e)=>{e.d(ae,{t:()=>a});var n=e(32196);const a=t=>({container:(0,n.css)`
      align-items: center;
      display: flex;
      flex-flow: row nowrap;

      & > * + * {
        margin-left: ${t.spacing(1)};
      }
    `,input:(0,n.css)`
      flex: 1;
    `,promDurationInput:(0,n.css)`
      max-width: ${t.spacing(32)};
    `,timingFormContainer:(0,n.css)`
      padding: ${t.spacing(1)};
    `,linkText:(0,n.css)`
      text-decoration: underline;
    `,collapse:(0,n.css)`
      border: none;
      background: none;
      color: ${t.colors.text.primary};
    `})},97174:(Le,ae,e)=>{e.d(ae,{G:()=>n});const n={groupWait:{label:"Group wait",description:"The waiting time until the initial notification is sent for a new group created by an incoming alert. If empty it will be inherited from the parent policy.",ariaLabel:"Group wait value"},groupInterval:{label:"Group interval",description:"The waiting time to send a batch of new alerts for that group after the first notification was sent. If empty it will be inherited from the parent policy.",ariaLabel:"Group interval value"},repeatInterval:{label:"Repeat interval",description:"The waiting time to resend an alert after they have successfully been sent.",ariaLabel:"Repeat interval value"}}},27835:(Le,ae,e)=>{e.d(ae,{H:()=>n});const n={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"}},53534:(Le,ae,e)=>{e.d(ae,{G:()=>S});var n=e(96540),a=e(49785),t=e(94753),te=e(88575),h=e(10354),R=e(86590),g=e(271);const j={message:"Recording rule name must be valid metric name. It may only contain letters, numbers, and colons. It may not contain whitespace.",value:/^[a-zA-Z_:][a-zA-Z0-9_:]*$/},S=()=>{const{register:T,watch:se,formState:{errors:$}}=(0,a.xW)(),F=se("type"),V=F===R.Z.cloudRecording?"recording rule":"alert rule";return n.createElement(g.P,{stepNo:1,title:`Enter ${V} name`,description:n.createElement(t.E,{variant:"bodySmall",color:"secondary"},"Enter a name to identify your ",V,".")},n.createElement(te.D,{label:"Name",error:$?.name?.message,invalid:!!$.name?.message},n.createElement(h.p,{id:"name",width:35,...T("name",{required:{value:!0,message:"Must enter a name"},pattern:F===R.Z.cloudRecording?j:void 0}),"aria-label":"name",placeholder:`Give your ${V} a name`})))}},9267:(Le,ae,e)=>{e.d(ae,{N:()=>St});var n=e(32196),a=e(96540),t=e(49785),te=e(32264),h=e(40845),R=e(67061),g=e(94753),j=e(94354),S=e(14578),T=e(86590),se=e(57220),$=e(54749),F=e(64100),V=e(271),ue=e(70383),je=e(42418),we=e(39558),ze=e(57418),Re=e(13726),Ee=e(79381),Ae=e(77141);const Pe=({receivers:i})=>a.createElement(R.B,{direction:"column",gap:0},a.createElement("div",null,i.map((P,b)=>{const G=P[Ee.MX],K=P[Ee.sW],de=G.name+b;return a.createElement(Re.ContactPointReceiverTitleRow,{key:de,name:G.name,type:P.type,description:(0,Ae.aM)(P),pluginMetadata:K})})));var he=e(88575),xe=e(16504),Qe=e(88323),f=e(29158),X=e(72093),y=e(72109),fe=e(3704);const ie=500;function M({alertManager:i,options:P,onSelectContactPoint:b,refetchReceivers:G}){const K=(0,h.of)(k),{control:de,watch:z,trigger:q}=(0,t.xW)(),Ge=z(`contactPoints.${i}.selectedContactPoint`),We=P.find(H=>H.value.name===Ge)?.value,c=We?{value:We,label:We.name}:{value:void 0,label:""},E=1e3,[A,N]=(0,a.useState)(!1),Y=H=>new Promise(re=>setTimeout(re,H)),D=(0,a.useCallback)(()=>{Ge&&q(`contactPoints.${i}.selectedContactPoint`,{shouldFocus:!0})},[i,Ge,q]),ce=()=>{N(!0),Promise.all([G(),Y(E)]).finally(()=>{N(!1),D()})};return(0,a.useEffect)(()=>{D()},[D]),a.createElement(R.B,{direction:"column"},a.createElement(R.B,{direction:"row",alignItems:"center"},a.createElement(he.D,{label:"Contact point"},a.createElement(xe.e,{render:({field:{onChange:H,ref:re,...Ie},fieldState:{error:me}})=>a.createElement(a.Fragment,null,a.createElement("div",{className:K.contactPointsSelector},a.createElement(Qe.l6,{virtualized:P.length>ie,"aria-label":"Contact point",defaultValue:c,onChange:(Me,Te)=>{H(Me?.value?.name),b(Me?.value)},options:P,width:50}),a.createElement("div",{className:K.contactPointsInfo},a.createElement(f.K,{name:"sync",onClick:ce,"aria-label":"Refresh contact points",tooltip:"Refresh contact points list",className:(0,n.cx)(K.refreshButton,{[K.loading]:A})}),a.createElement(Se,null))),me&&a.createElement(X.P,null,me?.message)),rules:{required:{value:!0,message:"Contact point is required."},validate:{contactPointExists:H=>P.some(re=>re.value.name===H)?!0:`Contact point ${Ge} does not exist.`}},control:de,name:`contactPoints.${i}.selectedContactPoint`}))))}function Se(){const i="/alerting/notifications";return a.createElement(y.Y,{external:!0,href:(0,fe.c)(i),"aria-label":"View or create contact points"},"View or create contact points")}const k=i=>({contactPointsSelector:(0,n.css)({display:"flex",flexDirection:"row",alignItems:"center",gap:i.spacing(1),marginTop:i.spacing(1)}),contactPointsInfo:(0,n.css)({display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"center",gap:i.spacing(1)}),refreshButton:(0,n.css)({color:i.colors.text.secondary,cursor:"pointer",borderRadius:i.shape.radius.circle,overflow:"hidden"}),loading:(0,n.css)({pointerEvents:"none",animation:"rotation 2s infinite linear","@keyframes rotation":{from:{transform:"rotate(720deg)"},to:{transform:"rotate(0deg)"}}}),warn:(0,n.css)({color:i.colors.warning.text})});var be=e(82843),He=e(98164),De=e(79657),Ne=e(99903);function Je({alertManager:i}){const P=(0,h.of)(Ne.t),{control:b,formState:{errors:G}}=(0,t.xW)(),K=W();return a.createElement(he.D,{label:"Mute timings","data-testid":"am-mute-timing-select",description:"Select a mute timing to define when not to send notifications for this alert rule",invalid:!!G.contactPoints?.[i]?.muteTimeIntervals},a.createElement(xe.e,{render:({field:{onChange:de,ref:z,...q}})=>a.createElement(Qe.KF,{"aria-label":"Mute timings",...q,className:P.input,onChange:Ge=>de((0,De.ie)(Ge)),options:K,placeholder:"Select mute timings..."}),control:b,name:`contactPoints.${i}.muteTimeIntervals`}))}function W(){return be.m.endpoints.getMuteTimingList.useQuery(void 0,{refetchOnFocus:!0,refetchOnReconnect:!0,selectFromResult:P=>({...P,mutetimings:P.data?P.data.map(b=>({value:b.name,label:b.name,description:b.time_intervals.map(G=>(0,He.LF)(G)).join(", AND ")})):[]})}).mutetimings}var ne=e(14186),U=e(15292),le=e(5342),v=e(27835),O=e(33915),I=e(97174);function C({alertManager:i}){const P=(0,h.of)(Ne.t),{register:b,formState:{errors:G},getValues:K}=(0,t.xW)();return a.createElement(a.Fragment,null,a.createElement(he.D,{label:I.G.groupWait.label,description:I.G.groupWait.description,invalid:!!G.contactPoints?.[i]?.groupWaitValue,error:G.contactPoints?.[i]?.groupWaitValue?.message},a.createElement(O.V,{...b(`contactPoints.${i}.groupWaitValue`,{validate:De.hH}),"aria-label":I.G.groupWait.ariaLabel,className:P.promDurationInput,placeholder:v.H.group_wait})),a.createElement(he.D,{label:I.G.groupInterval.label,description:I.G.groupInterval.description,invalid:!!G.contactPoints?.[i]?.groupIntervalValue,error:G.contactPoints?.[i]?.groupIntervalValue?.message},a.createElement(O.V,{...b(`contactPoints.${i}.groupIntervalValue`,{validate:De.hH}),"aria-label":I.G.groupInterval.ariaLabel,className:P.promDurationInput,placeholder:v.H.group_interval})),a.createElement(he.D,{label:I.G.repeatInterval.label,description:I.G.repeatInterval.description,invalid:!!G.contactPoints?.[i]?.repeatIntervalValue,error:G.contactPoints?.[i]?.repeatIntervalValue?.message},a.createElement(O.V,{...b(`contactPoints.${i}.repeatIntervalValue`,{validate:de=>{const z=K(`contactPoints.${i}.repeatIntervalValue`);return(0,De.DY)(de,z)}}),"aria-label":I.G.repeatInterval.ariaLabel,className:P.promDurationInput,placeholder:v.H.repeat_interval})))}const Q=["grafana_folder","alertname"],_={groupWaitValue:v.H.group_wait,groupIntervalValue:v.H.group_interval,repeatIntervalValue:v.H.repeat_interval},pe="...",ge=({alertManager:i})=>{const P=(0,h.of)(Ne.t),{control:b,watch:G,register:K,setValue:de,formState:{errors:z}}=(0,t.xW)(),[q,Ge]=(0,a.useState)((0,De.gY)([])),{groupIntervalValue:We,groupWaitValue:c,repeatIntervalValue:E}=_,A=G(`contactPoints.${i}.overrideGrouping`),N=G(`contactPoints.${i}.overrideTimings`),Y=G(`contactPoints.${i}.groupBy`)?.length??0,D=(0,h.of)(Xe);return(0,a.useEffect)(()=>{A&&Y===0&&de(`contactPoints.${i}.groupBy`,Q)},[A,de,i,Y]),a.createElement(R.B,{direction:"column"},a.createElement(R.B,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between"},a.createElement(ne.I,{label:"Override grouping",transparent:!0,className:D.switchElement},a.createElement(U.d,{id:"override-grouping-toggle",...K(`contactPoints.${i}.overrideGrouping`)})),!A&&a.createElement(g.E,{variant:"body",color:"secondary"},"Grouping: ",a.createElement("strong",null,Q.join(", ")))),A&&a.createElement(he.D,{label:"Group by",description:"Group alerts when you receive a notification based on labels. If empty it will be inherited from the default notification policy.",...K(`contactPoints.${i}.groupBy`),invalid:!!z.contactPoints?.[i]?.groupBy,className:D.optionalContent},a.createElement(xe.e,{rules:{validate:ce=>!ce||ce.length===0?"At least one group by option is required.":ce.length===1&&ce[0]===pe||Q.every(re=>ce.includes(re))?!0:`Group by must include ${Q.join(", ")}`},render:({field:{onChange:ce,ref:H,...re},fieldState:{error:Ie}})=>a.createElement(a.Fragment,null,a.createElement(Qe.KF,{"aria-label":"Group by",...re,allowCustomValue:!0,className:P.input,onCreateOption:me=>{Ge(Me=>[...Me,(0,De.Mk)(me)]),de(`contactPoints.${i}.groupBy`,[...re.value,me])},onChange:me=>ce((0,De.ie)(me)),options:[...De.Yl,...q],components:{MultiValueRemove(me){const{data:Me}=me;return Me.isFixed?null:(0,le.p)(me)}}}),Ie&&a.createElement(X.P,null,Ie.message)),name:`contactPoints.${i}.groupBy`,control:b})),a.createElement(R.B,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between"},a.createElement(ne.I,{label:"Override timings",transparent:!0,className:D.switchElement},a.createElement(U.d,{id:"override-timings-toggle",...K(`contactPoints.${i}.overrideTimings`)})),!N&&a.createElement(g.E,{variant:"body",color:"secondary"},"Group wait: ",a.createElement("strong",null,c,", "),"Group interval: ",a.createElement("strong",null,We,", "),"Repeat interval: ",a.createElement("strong",null,E))),N&&a.createElement("div",{className:D.optionalContent},a.createElement(C,{alertManager:i})))},Xe=i=>({switchElement:(0,n.css)({flexFlow:"row-reverse",gap:i.spacing(1),alignItems:"center"}),optionalContent:(0,n.css)({marginLeft:"49px",marginBottom:i.spacing(1)})});function Fe({alertManager:i}){const P=(0,h.of)(it),b=i.name,{isLoading:G,error:K,contactPoints:de,refetchReceivers:z}=(0,Ee.dK)({includePoliciesCount:!1,receiverStatusPollingInterval:0}),[q,Ge]=(0,a.useState)(),We=N=>{Ge(N)},{watch:c}=(0,t.xW)(),E=c(`contactPoints.${b}.overrideGrouping`)||c(`contactPoints.${b}.overrideTimings`)||c(`contactPoints.${b}.muteTimeIntervals`)?.length>0,A=de.map(N=>{const Y=N?.grafana_managed_receiver_configs,D=a.createElement(Re.ContactPointReceiverSummary,{receivers:Y??[]});return{label:N.name,value:N,description:D}});return K?a.createElement(je.F,{title:"Failed to fetch contact points",severity:"error"}):G?a.createElement(we._,{text:"Loading..."}):a.createElement(R.B,{direction:"column"},a.createElement(R.B,{direction:"row",alignItems:"center"},a.createElement("div",{className:P.firstAlertManagerLine}),a.createElement("div",{className:P.alertManagerName},"Alert manager:",a.createElement("img",{src:i.imgUrl,alt:"Alert manager logo",className:P.img}),b),a.createElement("div",{className:P.secondAlertManagerLine})),a.createElement(R.B,{direction:"row",gap:1,alignItems:"center"},a.createElement(M,{alertManager:b,options:A,onSelectContactPoint:We,refetchReceivers:z})),q?.grafana_managed_receiver_configs&&a.createElement(Pe,{receivers:q.grafana_managed_receiver_configs}),a.createElement("div",{className:P.routingSection},a.createElement(ze.M,{label:"Muting, grouping and timings (optional)",isOpen:E,className:P.collapsableSection},a.createElement(R.B,{direction:"column",gap:1},a.createElement(Je,{alertManager:b}),a.createElement(ge,{alertManager:b})))))}const it=i=>({firstAlertManagerLine:(0,n.css)({height:1,width:i.spacing(4),backgroundColor:i.colors.secondary.main}),alertManagerName:(0,n.css)({with:"fit-content"}),secondAlertManagerLine:(0,n.css)({height:"1px",width:"100%",flex:1,backgroundColor:i.colors.secondary.main}),img:(0,n.css)({marginLeft:i.spacing(2),width:i.spacing(3),height:i.spacing(3),marginRight:i.spacing(1)}),collapsableSection:(0,n.css)({width:"fit-content",fontSize:i.typography.body.fontSize}),routingSection:(0,n.css)({display:"flex",flexDirection:"column",maxWidth:i.breakpoints.values.xl,border:`solid 1px ${i.colors.border.weak}`,borderRadius:i.shape.radius.default,padding:`${i.spacing(1)} ${i.spacing(2)}`,marginTop:i.spacing(2)})});function rt(){const{getValues:i}=(0,t.xW)(),P=i("contactPoints"),K=(0,se.sq)("notification").availableInternalDataSources.filter(z=>z.hasConfigurationAPI);return(0,a.useMemo)(()=>K.map(z=>{const q=P?P[z.name]:void 0;return{alertManager:z,selectedContactPoint:q?.selectedContactPoint??"",routeSettings:{muteTimeIntervals:q?.muteTimeIntervals??[],overrideGrouping:q?.overrideGrouping??!1,groupBy:q?.groupBy??[],overrideTimings:q?.overrideTimings??!1,groupWaitValue:q?.groupWaitValue??"",groupIntervalValue:q?.groupIntervalValue??"",repeatIntervalValue:q?.repeatIntervalValue??""}}}),[K,P]).map((z,q)=>a.createElement(ue.b9,{accessType:"notification",alertmanagerSourceName:z.alertManager.name,key:z.alertManager.name+q},a.createElement(Fe,{alertManager:z.alertManager})))}var tt=e(2543),ot=e(55852),Ve=e(79938),Et=e(87286);const yt=(0,a.lazy)(()=>e.e(9711).then(e.bind(e,39711))),ct=({alertQueries:i,customLabels:P,condition:b,folder:G,alertName:K,alertUid:de})=>{const z=(0,h.of)(ht),q=!b||!G,Ge=Ve.hK.endpoints.preview,[We,{data:c=[],isLoading:E,isUninitialized:A}]=Ge.useMutation(),N=(0,tt.compact)(c.flatMap(H=>H?.labels)),Y=()=>{!G||!b||We({alertQueries:i,condition:b,customLabels:P,folder:G,alertName:K,alertUid:de})},D=(0,se.cy)("notification"),ce=D.length===1;return a.createElement(Et.B,{direction:"column"},a.createElement("div",{className:z.routePreviewHeaderRow},a.createElement("div",{className:z.previewHeader},a.createElement(g.E,{element:"h5"},"Alert instance routing preview"),E&&A&&a.createElement(g.E,{color:"secondary",variant:"bodySmall"},"Loading..."),A?a.createElement(g.E,{color:"secondary",variant:"bodySmall"},'When you have your folder selected and your query and labels are configured, click "Preview routing" to see the results here.'):a.createElement(g.E,{color:"secondary",variant:"bodySmall"},"Based on the labels added, alert instances are routed to the following notification policies. Expand each notification policy below to view more details.")),a.createElement("div",{className:z.button},a.createElement(ot.$n,{icon:"sync",variant:"secondary",type:"button",onClick:Y,disabled:q},"Preview routing"))),!E&&!A&&N.length>0&&a.createElement(a.Suspense,{fallback:a.createElement(we._,{text:"Loading preview..."})},D.map(H=>a.createElement(yt,{alertManagerSource:H,potentialInstances:N,onlyOneAM:ce,key:H.name}))))},ht=i=>({collapsableSection:(0,n.css)`
    width: auto;
    border: 0;
  `,previewHeader:(0,n.css)`
    margin: 0;
  `,routePreviewHeaderRow:(0,n.css)`
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: ${i.spacing(1)};
  `,collapseLabel:(0,n.css)`
    flex: 1;
  `,button:(0,n.css)`
    justify-content: flex-end;
  `,tagsInDetails:(0,n.css)`
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
  `,policyPathItemMatchers:(0,n.css)`
    display: flex;
    flex-direction: row;
    gap: ${i.spacing(1)};
  `});var xt=(i=>(i.NotificationPolicy="notification policy",i.ContactPoint="contact point",i))(xt||{});const St=({alertUid:i})=>{const{watch:P}=(0,t.xW)(),b=(0,h.of)(dt),[G]=P(["type","labels","queries","condition","folder","name","manualRouting"]),K=P("dataSourceName")??se.hY,de=te.$.featureToggles.alertingSimplifiedRouting??!1,z=G===T.Z.grafana,q=G===T.Z.grafana&&de;return a.createElement(V.P,{stepNo:4,title:G===T.Z.cloudRecording?"Add labels":"Configure labels and notifications",description:a.createElement(R.B,{direction:"row",gap:.5,alignItems:"baseline"},G===T.Z.cloudRecording?a.createElement(g.E,{variant:"bodySmall",color:"secondary"},"Add labels to help you better manage your recording rules"):q&&a.createElement(g.E,{variant:"bodySmall",color:"secondary"},"Select who should receive a notification when an alert rule fires.")),fullWidth:!0},a.createElement($.A,{dataSourceName:K}),q&&a.createElement("div",{className:b.configureNotifications},a.createElement(g.E,{element:"h5"},"Notifications"),a.createElement(g.E,{variant:"bodySmall",color:"secondary"},"Select who should receive a notification when an alert rule fires.")),q?a.createElement(It,{alertUid:i}):z?a.createElement(ut,{alertUid:i}):null)};function It({alertUid:i}){const{watch:P,setValue:b}=(0,t.xW)(),G=(0,h.of)(dt),[K]=P(["manualRouting"]),de=[{label:"Select contact point",value:"contact point"},{label:"Use notification policy",value:"notification policy"}],z=q=>{b("manualRouting",q==="contact point")};return a.createElement(R.B,{direction:"column"},a.createElement(R.B,{direction:"column"},a.createElement(j.z,{options:de,value:K?"contact point":"notification policy",onChange:z,className:G.routingOptions})),a.createElement(Ct,{manualRouting:K}),K?a.createElement(rt,null):a.createElement(ut,{alertUid:i}))}function ut({alertUid:i}){const{watch:P}=(0,t.xW)(),[b,G,K,de,z]=P(["labels","queries","condition","folder","name","manualRouting"]);return a.createElement(ct,{alertQueries:G,customLabels:b,condition:K,folder:de,alertName:z,alertUid:i})}function qe(){return a.createElement(F.G,{contentText:a.createElement(R.B,{gap:1,direction:"column"},a.createElement(R.B,{direction:"column",gap:0},a.createElement(a.Fragment,null,"Firing alert rule instances are routed to notification policies based on matching labels. All alert rules and instances, irrespective of their labels, match the default notification policy. If there are no nested policies, or no nested policies match the labels in the alert rule or alert instance, then the default notification policy is the matching policy."),a.createElement("a",{href:"https://grafana.com/docs/grafana/latest/alerting/fundamentals/notification-policies/notifications/",target:"_blank",rel:"noreferrer"},a.createElement(g.E,{color:"link"},"Read about notification routing. ",a.createElement(S.I,{name:"external-link-alt"})))),a.createElement(R.B,{direction:"column",gap:0},a.createElement(a.Fragment,null,"Custom labels change the way your notifications are routed. First, add labels to your alert rule and then connect them to your notification policy by adding label matchers."),a.createElement("a",{href:"https://grafana.com/docs/grafana/latest/alerting/fundamentals/annotation-label/",target:"_blank",rel:"noreferrer"},a.createElement(g.E,{color:"link"},"Read about Labels and annotations. ",a.createElement(S.I,{name:"external-link-alt"}))))),title:"Notification routing"})}function Rt(){return a.createElement(F.G,{contentText:a.createElement(a.Fragment,null,"Select a contact point to notify all recipients in it.",a.createElement("br",null),a.createElement("br",null),"Notifications for firing alert instances are grouped based on folder and alert rule name.",a.createElement("br",null),"The waiting time until the initial notification is sent for a new group created by an incoming alert is 30 seconds.",a.createElement("br",null),"The waiting time to send a batch of new alerts for that group after the first notification was sent is 5 minutes.",a.createElement("br",null),"The waiting time to resend an alert after they have successfully been sent is 4 hours.",a.createElement("br",null),"Grouping and wait time values are defined in your default notification policy."),externalLink:"`https://grafana.com/docs/grafana/latest/alerting/fundamentals/notification-policies/notifications/`",linkText:"Read more about notifiying contact points",title:"Notify contact points"})}const Ct=({manualRouting:i})=>{const P=(0,h.of)(dt);return a.createElement("div",{className:P.notificationsOptionDescription},a.createElement(g.E,{variant:"bodySmall",color:"secondary"},i?"Notifications for firing alerts are routed to a selected contact point.":"Notifications for firing alerts are routed to contact points based on matching labels and the notification policy tree."),i?a.createElement(Rt,null):a.createElement(qe,null))},dt=i=>({routingOptions:(0,n.css)({marginTop:i.spacing(2),width:"fit-content"}),configureNotifications:(0,n.css)({display:"flex",flexDirection:"column",gap:i.spacing(1),marginTop:i.spacing(2)}),notificationsOptionDescription:(0,n.css)({marginTop:i.spacing(1),display:"flex",flexDirection:"row",alignItems:"baseline",gap:i.spacing(.5)})})},67986:(Le,ae,e)=>{e.d(ae,{L:()=>Je,g:()=>W});var n=e(32196),a=e(96540),t=e(49785),te=e(1604),h=e(46662),R=e(72724),g=e(39070),j=e(19347),S=e(40845),T=e(66864),se=e(55852),$=e(42418),F=e(62467),V=e(81160),ue=e(66847),je=e(1005),we=e(72495),ze=e(89667),Re=e(43127),Ee=e(17172),Ae=e(12091);function Pe(v){return"expr"in v}function he(v){return"grafana_condition"in v}var xe=e(86590),Qe=e(57220);function f(v){if(Pe(v))return X(v,v.dataSourceUid,xe.Z.cloudAlerting);if(he(v))return X(v,Qe.hY,xe.Z.grafana);throw new Error("unsupported preview rule request")}function X(v,O,I){return(0,we.k)({whileLoading:y(I),source:(0,Ee.AI)().fetch({method:"POST",url:`/api/v1/rule/test/${O}`,data:v}).pipe((0,V.T)(({data:C})=>y(I,{state:g.Gu.Done,series:C.instances.map(ze.or)})),(0,ue.W)(C=>(0,F.of)(y(I,{state:g.Gu.Error,error:(0,Ae.u)(C)}))),(0,je.u)())})}function y(v,O={}){return{ruleType:v,data:{state:g.Gu.Loading,series:[],timeRange:(0,Re.E2)(),...O}}}var fe=e(36135),ie=e(70713),M=e(1173),Se=e(24308),k=e(52622),be=e(88467);function He(v){const{preview:O}=v,I=(0,S.of)(De),C={defaults:{},overrides:[{matcher:{id:M.Ct.byName,options:"Info"},properties:[{id:"custom.displayMode",value:k.ob.JSONView}]}]};if(!O)return null;const{data:Q,ruleType:_}=O;return Q.state===g.Gu.Loading?a.createElement("div",{className:I.container},a.createElement("span",null,"Loading preview...")):Q.state===g.Gu.Error?a.createElement("div",{className:I.container},Q.error?(0,be.CZ)(Q.error):"Failed to preview alert rule"):a.createElement("div",{className:I.container},a.createElement("span",null,"Preview based on the result of running the query, for this moment."," ",_===xe.Z.grafana?"Configuration for `no data` and `error handling` is not applied.":null),a.createElement("div",{className:I.table},a.createElement(ie.Ay,null,({width:pe,height:ge})=>a.createElement("div",{style:{width:`${pe}px`,height:`${ge}px`}},a.createElement(Se.m,{title:"",width:pe,height:ge,pluginId:"table",data:Q,fieldConfig:C})))))}function De(v){return{container:(0,n.css)`
      margin: ${v.spacing(2)} 0;
    `,table:(0,n.css)`
      flex: 1 1 auto;
      height: 135px;
      margin-top: ${v.spacing(2)};
      border: 1px solid ${v.colors.border.medium};
      border-radius: ${v.shape.radius.default};
    `}}const Ne=["type","dataSourceName","condition","queries","expression"];function Je(){const v=(0,S.of)(le),[O,I]=W(),{watch:C}=(0,t.xW)(),[Q,_,pe]=C(["type","condition","queries"]),{allDataSourcesAvailable:ge}=(0,fe.g)(pe);if(Q===xe.Z.cloudRecording||Q===xe.Z.cloudAlerting)return null;const Xe=!!_&&ge;return a.createElement("div",{className:v.container},a.createElement(T.Gy,null,ge&&a.createElement(se.$n,{disabled:!Xe,type:"button",variant:"primary",onClick:I},"Preview alerts"),!ge&&a.createElement($.F,{title:"Preview is not available",severity:"warning"},"Cannot display the query preview. Some of the data sources used in the queries are not available.")),a.createElement(He,{preview:O}))}function W(){const[v,O]=(0,a.useState)(),{getValues:I}=(0,t.xW)(),C=(0,te.A)(),Q=(0,a.useCallback)(()=>{const _=I(Ne),pe=ne(_);f(pe).pipe((0,h.v)(ge=>!U(ge),!0)).subscribe(ge=>{C()&&O(ge)})},[I,C]);return[v,Q]}function ne(v){const[O,I,C,Q,_]=v,pe=(0,j.l)().getInstanceSettings(I);if(!pe)throw new Error(`Cannot find data source settings for ${I}`);switch(O){case xe.Z.cloudAlerting:return{dataSourceUid:pe.uid,dataSourceName:I,expr:_};case xe.Z.grafana:return{grafana_condition:{condition:C,data:Q,now:(0,R.M7)(Date.now())}};default:throw new Error(`Alert type ${O} not supported by preview.`)}}function U(v){switch(v.data.state){case g.Gu.Done:case g.Gu.Error:return!0;default:return!1}}function le(v){return{container:(0,n.css)`
      margin-top: ${v.spacing(2)};
      max-width: ${v.breakpoints.values.xxl}px;
    `}}},890:(Le,ae,e)=>{e.d(ae,{N:()=>un});var n=e(32196),a=e(2543),t=e(96540),te=e(49785),h=e(43127),R=e(13544),g=e(19347),j=e(32264),S=e(40845),T=e(67061),se=e(88575),$=e(16504),F=e(56034),V=e(55852),ue=e(42418),je=e(38138),we=e(64539),ze=e(83122),Re=e(14578),Ee=e(94753),Ae=e(69437),Pe=e(66718),he=e(80348),xe=e(57220),Qe=e(61410);function f(){const o=(0,Qe.$)(r=>r.dataSources);return Object.values(o).map(r=>r.result).filter(r=>!!r?.rulerConfig).map(r=>(0,xe.oh)(r.name)).filter(r=>!!r)}var X=e(23770),y=e(86590),fe=e(63066),ie=e(16817),M=e(39070),Se=e(76287),k=e(41987),be=e(64149),He=e(75214),De=e(30423),Ne=e(94822);function Je({fields:o}){const s=o.filter(u=>!["State","Info"].includes(u.name)),r=o.findIndex(u=>u.name==="State"),l=o.findIndex(u=>u.name==="Info"),d=s.map(u=>o.indexOf(u)),m=o[r]?.values.length??0,p=[];for(let u=0;u<m;u++){const L=d.map(oe=>[o[oe].name,o[oe].values[u]]),ee=o[r]?.values?.[u],w=o[l]?.values?.[u];(0,Ne.s1)(ee)&&p.push({state:ee,info:w,labels:Object.fromEntries(L)})}return{instances:p}}function W({preview:o}){const s=(0,S.of)(ne),r=Je(o);return t.createElement("table",{className:s.table},t.createElement("caption",null,t.createElement("div",null,"Alerts preview"),t.createElement("span",null,"Preview based on the result of running the query for this moment.")),t.createElement("thead",null,t.createElement("tr",null,t.createElement("th",null,"State"),t.createElement("th",null,"Labels"),t.createElement("th",null,"Info"))),t.createElement("tbody",null,r.instances.map(({state:l,info:d,labels:m},p)=>{const u=(0,He.M4)(m);return t.createElement("tr",{key:p},t.createElement("td",null,t.createElement(De.C,{state:l})),t.createElement("td",null,t.createElement(be.L,{tags:u,className:s.tagList})),t.createElement("td",null,d&&t.createElement(F.m,{content:d},t.createElement(Re.I,{name:"info-circle"}))))})))}const ne=o=>({table:(0,n.css)`
    width: 100%;
    margin: ${o.spacing(2,0)};

    caption {
      caption-side: top;
      color: ${o.colors.text.primary};

      & > span {
        font-size: ${o.typography.bodySmall.fontSize};
        color: ${o.colors.text.secondary};
      }
    }

    td,
    th {
      padding: ${o.spacing(1,1)};
    }

    td + td,
    th + th {
      padding-left: ${o.spacing(3)};
    }

    thead th {
      &:nth-child(1) {
        width: 80px;
      }

      &:nth-child(2) {
        width: auto;
      }

      &:nth-child(3) {
        width: 40px;
      }
    }

    td:nth-child(3) {
      text-align: center;
    }

    tbody tr:nth-child(2n + 1) {
      background-color: ${o.colors.background.secondary};
    }
  `,tagList:(0,n.css)`
    justify-content: flex-start;
  `});var U=e(67986);const le=({value:o,onChange:s,dataSourceName:r,showPreviewAlertsButton:l=!0})=>{const d=(0,S.of)(v),{mapToValue:m,mapToQuery:p}=O(r),u=p({refId:"A",hide:!1},o),{error:L,loading:ee,value:w}=(0,ie.A)(()=>(0,g.l)().get(r),[r]),oe=(0,t.useCallback)(Ze=>{s(m(Ze))},[s,m]),[Be,Z]=(0,U.g)(),B=async()=>{Z()};if(ee||w?.name!==r)return null;const $e=(0,g.l)().getInstanceSettings(r);if(L||!w||!w?.components?.QueryEditor||!$e){const Ze=L?.message||"Data source plugin does not export any Query Editor component";return t.createElement("div",null,"Could not load query editor due to: ",Ze)}const Oe=Be?.data.state===M.Gu.Done,Ue=w?.components?.QueryEditor,ke=Be?.data?.series?.find(Ze=>Ze.name==="evaluation results"),lt=ke&&ke.fields.some(Ze=>Ze.values.length>0);return t.createElement(t.Fragment,null,t.createElement(Se.p,{instanceSettings:$e},t.createElement(Ue,{query:u,queries:[u],app:k.Jk.CloudAlerting,onChange:oe,onRunQuery:a.noop,datasource:w})),l&&t.createElement("div",{className:d.preview},t.createElement(V.$n,{type:"button",onClick:B,disabled:Be?.data.state===M.Gu.Loading},"Preview alerts"),Oe&&!lt&&t.createElement(ue.F,{title:"Alerts preview",severity:"info",className:d.previewAlert},"There are no firing alerts for your query."),lt&&t.createElement(W,{preview:ke})))},v=o=>({preview:(0,n.css)`
    padding: ${o.spacing(2,0)};
    max-width: ${o.breakpoints.values.xl}px;
  `,previewAlert:(0,n.css)`
    margin: ${o.spacing(1,0)};
  `});function O(o){return(0,t.useMemo)(()=>{switch((0,g.l)().getInstanceSettings(o)?.type){case"loki":case"prometheus":return{mapToValue:r=>r.expr,mapToQuery:(r,l)=>({...r,expr:l})};default:throw new Error(`${o} is not supported as an expression editor`)}},[o])}var I=e(56528),C=e(7921);const Q=({condition:o,onSetCondition:s,queries:r,panelData:l,onUpdateRefId:d,onRemoveExpression:m,onUpdateExpressionType:p,onUpdateQueryExpression:u})=>{const L=(0,t.useMemo)(()=>r.reduce((w,oe)=>(0,Ae.f)(oe.model)?w.concat(oe.model):w,[]),[r]),ee=(0,S.of)(_);return t.createElement("div",{className:ee.wrapper},L.map(w=>{const oe=l[w.refId],Be=o===w.refId,Z=oe?(0,C.lb)(oe):void 0,B=oe?(0,C.yr)(oe.series):void 0;return t.createElement(I.r4,{key:w.refId,isAlertCondition:Be,data:oe,error:Z,warning:B,queries:r,query:w,onSetCondition:s,onRemoveExpression:m,onUpdateRefId:d,onUpdateExpressionType:p,onChangeQuery:u})}))},_=o=>({wrapper:(0,n.css)`
    display: flex;
    gap: ${o.spacing(2)};
    align-content: stretch;
    flex-wrap: wrap;
  `});var pe=e(64100),ge=e(75494),Xe=e(65879),Fe=e(10860),it=e(7788),rt=e(31193),tt=e(14186),ot=e(10354),Ve=e(65160),Et=e(25968),yt=e(81875),ct=e(47232),ht=e(60782),xt=e(3759);const St=({query:o,queryOptions:s,onChangeTimeRange:r,onChangeQueryOptions:l,index:d})=>{const m=(0,S.of)(It),[p,u]=(0,t.useState)(!1),L=o.relativeTimeRange?(0,Xe.relativeToTimeRange)(o.relativeTimeRange):void 0;return t.createElement(t.Fragment,null,t.createElement(ht.G,{content:t.createElement("div",{className:m.queryOptions},r&&t.createElement(tt.I,{label:"Time Range"},t.createElement(xt.N,{timeRange:o.relativeTimeRange??(0,h.Cn)(),onChange:ee=>r(ee,d)})),t.createElement(i,{options:s,onChange:ee=>l(ee,d)}),t.createElement(P,{options:s,onChange:ee=>l(ee,d)})),closeButton:!0,placement:"bottom-start"},t.createElement("button",{type:"button",className:m.actionLink,onClick:()=>u(!p)},"Options ",p?t.createElement(Re.I,{name:"angle-right"}):t.createElement(Re.I,{name:"angle-down"}))),t.createElement("div",{className:m.staticValues},t.createElement("span",null,(0,ct.KQ)(L?.from).locale("en").fromNow(!0)),s.maxDataPoints&&t.createElement("span",null,", MD = ",s.maxDataPoints),s.minInterval&&t.createElement("span",null,", Min. Interval = ",s.minInterval)))},It=o=>{const s=(0,V.my)(o);return{queryOptions:(0,n.css)`
      > div {
        justify-content: space-between;
      }
    `,staticValues:(0,n.css)`
      color: ${o.colors.text.secondary};
      margin-right: ${o.spacing(1)};
    `,actionLink:(0,n.css)`
      ${s};
      color: ${o.colors.text.link};
      cursor: pointer;

      &:hover {
        text-decoration: underline;
      }
    `}};var ut=e(74685);const qe=43200,Rt="1s",Ct=({data:o,error:s,dsSettings:r,index:l,onChangeDataSource:d,onChangeQuery:m,onChangeTimeRange:p,onRunQueries:u,onRemoveQuery:L,onDuplicateQuery:ee,query:w,queries:oe,thresholds:Be,thresholdsType:Z,onChangeThreshold:B,condition:$e,onSetCondition:Oe,onChangeQueryOptions:Ue})=>{const ke=(0,S.of)(b),[lt,Ze]=(0,t.useState)(),bt={...lt?.getDefaultQuery?lt.getDefaultQuery(k.Jk.UnifiedAlerting):{},...(0,a.cloneDeep)(w.model)};function et(){const Ce=(0,S.of)(b);return t.createElement("div",{className:Ce.dsTooltip},t.createElement(F.m,{content:t.createElement(t.Fragment,null,"Not finding the data source you want? Some data sources are not supported for alerting. Click on the icon for more information.")},t.createElement(Re.I,{name:"info-circle",onClick:()=>window.open(" https://grafana.com/docs/grafana/latest/alerting/fundamentals/data-source-alerting/","_blank")})))}function Ft({query:Ce,error:gt,index:Yt}){const Ke={maxDataPoints:Ce.model.maxDataPoints,minInterval:Ce.model.intervalMs?(0,Et.yl)(Ce.model.intervalMs):void 0},Jt={maxDataPoints:Ke.maxDataPoints,minInterval:Ke.minInterval},Xt=$e===Ce.refId;return t.createElement(T.B,{direction:"row",alignItems:"center",gap:1},t.createElement(et,null),t.createElement(St,{onChangeTimeRange:p,query:Ce,queryOptions:Jt,onChangeQueryOptions:Ue,index:Yt}),t.createElement(yt.a,{onSetCondition:()=>Oe(Ce.refId),isCondition:Xt}))}const Ht=o.state!==M.Gu.NotStarted,Kt=(0,a.cloneDeep)(oe.map(Ce=>Ce.model));return t.createElement(T.B,{direction:"column",gap:.5},t.createElement("div",{className:ke.wrapper},t.createElement(Ve.c,{alerting:!0,collapsable:!1,dataSource:r,onDataSourceLoaded:Ze,onChangeDataSource:Ce=>d(Ce,l),id:w.refId,index:l,key:w.refId,data:o,query:bt,onChange:Ce=>m(Ce,l),onRemoveQuery:L,onAddQuery:()=>ee((0,a.cloneDeep)(w)),onRunQuery:u,queries:Kt,renderHeaderExtras:()=>t.createElement(Ft,{query:w,index:l,error:s}),app:k.Jk.UnifiedAlerting,hideDisableQuery:!0})),Ht&&t.createElement(ut.j,{data:o,thresholds:Be,thresholdsType:Z,onThresholdsChange:B?Ce=>B(Ce,l):void 0}))},dt=({children:o})=>{const s=(0,S.of)(b);return t.createElement("div",{className:s.wrapper},o)};function i({options:o,onChange:s}){const r=o.maxDataPoints??"",l=d=>{const m=parseInt(d.target.value,10),p=isNaN(m)||m===0?void 0:m;p!==o.maxDataPoints&&s({...o,maxDataPoints:p})};return t.createElement(tt.I,{labelWidth:24,label:"Max data points",tooltip:"The maximum data points per series. Used directly by some data sources and used in calculation of auto interval. With streaming data this value is used for the rolling buffer."},t.createElement(ot.p,{type:"number",width:10,placeholder:qe.toString(),spellCheck:!1,onBlur:l,defaultValue:r}))}function P({options:o,onChange:s}){const r=o.minInterval??"",l=d=>{const m=d.target.value;m!==r&&s({...o,minInterval:m})};return t.createElement(tt.I,{label:"Interval",labelWidth:24,tooltip:t.createElement(t.Fragment,null,"Interval sent to the data source. Recommended to be set to write frequency, for example ",t.createElement("code",null,"1m")," if your data is written every minute.")},t.createElement(ot.p,{type:"text",width:10,placeholder:Rt,spellCheck:!1,onBlur:l,defaultValue:r}))}const b=o=>({wrapper:(0,n.css)`
    label: AlertingQueryWrapper;
    margin-bottom: ${o.spacing(1)};
    border: 1px solid ${o.colors.border.weak};
    border-radius: ${o.shape.radius.default};

    button {
      overflow: visible;
    }
  `,dsTooltip:(0,n.css)`
    display: flex;
    align-items: center;
    &:hover {
      opacity: 0.85;
      cursor: pointer;
    }
  `});class G extends t.PureComponent{constructor(s){super(s),this.onRemoveQuery=r=>{const{queries:l,onQueriesChange:d}=this.props;d(l.filter(m=>m.refId!==r.refId))},this.onChangeTimeRange=(r,l)=>{const{queries:d,onQueriesChange:m}=this.props;m(d.map((p,u)=>u!==l?p:{...p,relativeTimeRange:r}))},this.onChangeQueryOptions=(r,l)=>{const{queries:d,onQueriesChange:m}=this.props;m(d.map((p,u)=>u!==l?p:{...p,model:{...p.model,maxDataPoints:r.maxDataPoints,intervalMs:r.minInterval?Xe.intervalToMs(r.minInterval):void 0}}))},this.onChangeDataSource=(r,l)=>{const{queries:d,onQueriesChange:m}=this.props,p=d.map((u,L)=>{if(L!==l)return u;const ee=this.getDataSourceSettings(u);return r.type===ee?.type?K(u,r):de(u,r)});m(p)},this.onChangeQuery=(r,l)=>{const{queries:d,onQueriesChange:m}=this.props;m(d.map((p,u)=>u!==l?p:{...p,refId:r.refId,queryType:p.model.queryType??"",model:{...p.model,...r,datasource:r.datasource}}))},this.onDragEnd=r=>{const{queries:l,onQueriesChange:d}=this.props;if(!r||!r.destination)return;const m=r.source.index,p=r.destination.index;if(m===p)return;const u=Array.from(l),[L]=u.splice(m,1);u.splice(p,0,L),d(u)},this.getDataSourceSettings=r=>(0,g.l)().getInstanceSettings(r.datasourceUid)}render(){const{queries:s,expressions:r,condition:l}=this.props,d=(0,C.an)([...s,...r],l);return t.createElement(ge.JY,{onDragEnd:this.onDragEnd},t.createElement(ge.gL,{droppableId:"alerting-queries",direction:"vertical"},m=>t.createElement("div",{ref:m.innerRef,...m.droppableProps},t.createElement(T.B,{direction:"column"},s.map((p,u)=>{const L=this.props.condition===p.refId,ee=this.props.data?.[p.refId]??{series:[],state:M.Gu.NotStarted},w=this.getDataSourceSettings(p);let oe;return ee&&L?oe=(0,C.zy)(ee):ee&&(oe=(0,C.lb)(ee)),w?t.createElement(Ct,{index:u,key:p.refId,dsSettings:w,data:ee,error:oe,query:p,onChangeQuery:this.onChangeQuery,onRemoveQuery:this.onRemoveQuery,queries:[...s,...r],onChangeDataSource:this.onChangeDataSource,onDuplicateQuery:this.props.onDuplicateQuery,onChangeTimeRange:this.onChangeTimeRange,onChangeQueryOptions:this.onChangeQueryOptions,thresholds:d[p.refId]?.config,thresholdsType:d[p.refId]?.mode,onRunQueries:this.props.onRunQueries,condition:this.props.condition,onSetCondition:this.props.onSetCondition}):t.createElement(z,{key:`${p.refId}-${u}`,index:u,model:p.model,onUpdateDatasource:()=>{const Be=(0,rt.tR)().getInstanceSettings(null);Be&&this.onChangeDataSource(Be,u)},onRemoveQuery:()=>{this.onRemoveQuery(p)}})}),m.placeholder))))}}function K(o,s){return{...o,model:{...(0,a.omit)(o.model,"datasource"),datasource:{type:s.type,uid:s.uid}},datasourceUid:s.uid}}function de(o,s){return{refId:o.refId,relativeTimeRange:o.relativeTimeRange,queryType:"",datasourceUid:s.uid,model:{refId:o.refId,hide:!1,datasource:{type:s.type,uid:s.uid}}}}const z=({index:o,onUpdateDatasource:s,onRemoveQuery:r,model:l})=>{const d=l.refId,[m,p]=(0,t.useState)(!1),u=()=>{p(ee=>!ee)},L=()=>{s()};return t.createElement(dt,null,t.createElement(it.u,{title:d,draggable:!0,index:o,id:d,isOpen:!0,collapsable:!1},t.createElement(Fe.Z,null,t.createElement(Fe.Z.Heading,null,"This datasource has been removed"),t.createElement(Fe.Z.Description,null,"The datasource for this query was not found, it was either removed or is not installed correctly."),t.createElement(Fe.Z.Figure,null,t.createElement(Re.I,{name:"question-circle"})),t.createElement(Fe.Z.Actions,null,t.createElement(V.$n,{key:"update",variant:"secondary",onClick:L},"Update datasource"),t.createElement(V.$n,{key:"remove",variant:"destructive",onClick:r},"Remove query")),t.createElement(Fe.Z.SecondaryActions,null,t.createElement(V.$n,{key:"details",onClick:u,icon:m?"angle-up":"angle-down",fill:"text",size:"sm"},"Show details"))),m&&t.createElement("div",null,t.createElement("pre",null,t.createElement("code",null,JSON.stringify(l,null,2))))))},q=({queries:o,expressions:s,panelData:r,onRunQueries:l,onChangeQueries:d,onDuplicateQuery:m,condition:p,onSetCondition:u})=>{const L=(0,S.of)(Ge);return t.createElement("div",{className:L.container},t.createElement(G,{data:r,queries:o,expressions:s,onRunQueries:l,onQueriesChange:d,onDuplicateQuery:m,condition:p,onSetCondition:u}))},Ge=o=>({container:(0,n.css)`
    background-color: ${o.colors.background.primary};
    height: 100%;
  `});var We=e(74856);const c=({queries:o,onChangeQuery:s,runQueries:r,panelData:l,dataSourceName:d})=>{const[m,p]=(0,t.useState)({series:[],state:M.Gu.NotStarted,timeRange:(0,We.jG)().timeRange()}),u=(0,S.of)(E);(0,t.useEffect)(()=>{p(l?.[o[0]?.refId])},[l,o]);const{error:L,loading:ee,value:w}=(0,ie.A)(()=>(0,g.l)().get(d),[d]),oe=B=>{const $e=o[0],Oe=(0,g.l)().getInstanceSettings(d)?.uid;if(!(0,fe.Bu)(B)||!Oe)return;const Ue=B.expr,ke={...$e,...B,datasourceUid:Oe,expr:Ue,model:{expr:Ue,datasource:B.datasource,refId:B.refId,editorMode:B.editorMode,instant:!!B.instant,range:!!B.range,legendFormat:B.legendFormat}};s([ke])};if(ee||w?.name!==d)return null;const Be=(0,g.l)().getInstanceSettings(d);if(L||!w||!w?.components?.QueryEditor||!Be){const B=L?.message||"Data source plugin does not export any Query Editor component";return t.createElement("div",null,"Could not load query editor due to: ",B)}const Z=w.components.QueryEditor;return t.createElement(t.Fragment,null,o.length&&t.createElement(Z,{query:o[0],queries:o,app:k.Jk.UnifiedAlerting,onChange:oe,onRunQuery:r,datasource:w}),m&&t.createElement("div",{className:u.vizWrapper},t.createElement(ut.j,{data:m})))},E=o=>({vizWrapper:(0,n.css)`
    margin: ${o.spacing(1,0)};
  `});var A=e(271),N=e(51612),Y=e(99140);function D({value:o,disabled:s,...r}){const l=f(),{loading:d=!0}=(0,ie.A)(()=>(0,Y.JD)((0,X.wE)()),[Y.JD]),m=(0,t.useCallback)(p=>!!l.find(({id:u})=>u===p.id),[l]);return t.createElement(N.s,{disabled:d||s,noDefault:!0,alerting:!0,filter:m,current:o,...r})}const ce=({disabled:o,onChangeCloudDatasource:s})=>{const{control:r,formState:{errors:l},setValue:d,watch:m}=(0,te.xW)(),p=(0,S.of)(H),u=m("type");return t.createElement(t.Fragment,null,t.createElement("div",{className:p.flexRow},(u===y.Z.cloudAlerting||u===y.Z.cloudRecording)&&t.createElement(se.D,{className:p.formInput,label:o?"Data source":"Select data source",error:l.dataSourceName?.message,invalid:!!l.dataSourceName?.message},t.createElement($.e,{render:({field:{onChange:L,ref:ee,...w}})=>t.createElement(D,{...w,disabled:o,onChange:oe=>{d("expression",""),L(oe?.name??null),s(oe?.uid??null)}}),name:"dataSourceName",control:r,rules:{required:{value:!0,message:"Please select a data source"}}}))))},H=o=>({formInput:(0,n.css)`
    width: 330px;
    & + & {
      margin-left: ${o.spacing(3)};
    }
  `,flexRow:(0,n.css)`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-end;
  `});var re=e(94354),Ie=e(10096);function me(){const o=Ie.TP.hasPermission(he.AccessControlAction.AlertingRuleCreate),s=Ie.TP.hasPermission(he.AccessControlAction.AlertingRuleExternalWrite),r=o?y.Z.grafana:y.Z.cloudAlerting,l=[];return o&&l.push(y.Z.grafana),s&&l.push(y.Z.cloudAlerting,y.Z.cloudRecording),{enabledRuleTypes:l,defaultRuleType:r}}const Me=o=>o.filter(s=>s.datasourceUid!==Pe.Uj).length===1,Te=({queries:o,ruleFormType:s,rulesSourcesWithRuler:r})=>{const l=me(),d=Me(o),m=o[0]?.datasourceUid??"",p=s===y.Z.cloudRecording,u=!p&&d&&r.some(Z=>Z.uid===m),L=!p,ee=l.enabledRuleTypes.includes(y.Z.grafana),w=l.enabledRuleTypes.includes(y.Z.cloudAlerting),oe=s===y.Z.cloudAlerting&&ee&&L,Be=s===y.Z.grafana&&u&&w&&u;return oe||Be};function st({editingExistingRule:o,rulesSourcesWithRuler:s,queries:r,onClickSwitch:l}){const{getValues:d}=(0,te.xW)(),[m]=d(["type"]),p=Te({queries:r,ruleFormType:m,rulesSourcesWithRuler:s}),u=[{label:"Grafana-managed",value:y.Z.grafana},{label:"Data source-managed",value:y.Z.cloudAlerting}],L=p?[]:[y.Z.cloudAlerting];return t.createElement(T.B,{direction:"column",gap:1,alignItems:"flex-start"},t.createElement(T.B,{direction:"column",gap:0},t.createElement(Ee.E,{variant:"h5"},"Rule type"),t.createElement(T.B,{direction:"row",gap:.5,alignItems:"baseline"},t.createElement(Ee.E,{variant:"bodySmall",color:"secondary"},"Select where the alert rule will be managed."),t.createElement(pe.G,{contentText:t.createElement(t.Fragment,null,t.createElement(Ee.E,{color:"primary",variant:"h6"},"Grafana-managed alert rules"),t.createElement("p",null,"Grafana-managed alert rules allow you to create alerts that can act on data from any of our supported data sources, including having multiple data sources in the same rule. You can also add expressions to transform your data and set alert conditions. Using images in alert notifications is also supported."),t.createElement(Ee.E,{color:"primary",variant:"h6"},"Data source-managed alert rules"),t.createElement("p",null,"Data source-managed alert rules can be used for Grafana Mimir or Grafana Loki data sources which have been configured to support rule creation. The use of expressions or multiple queries is not supported.")),externalLink:"https://grafana.com/docs/grafana/latest/alerting/fundamentals/alert-rules/alert-rule-types/",linkText:"Read about alert rule types",title:"Alert rule types"}))),t.createElement(re.z,{options:u,disabled:o,disabledOptions:L,value:m,onChange:l}),o&&t.createElement(Ee.E,{color:"secondary"},"The alert rule type cannot be changed for an existing rule."),!o&&t.createElement(t.Fragment,null,p?t.createElement(Ee.E,{color:"secondary"},m===y.Z.grafana?"The data source selected in your query supports alert rule management. Switch to data source-managed if you want the alert rule to be managed by the data source instead of Grafana.":"Switch to Grafana-managed to use expressions, multiple queries, images in notifications and various other features."):t.createElement(Ee.E,{color:"secondary"},"Based on the selected data sources this alert rule will be Grafana-managed.")))}const mt={[y.Z.cloudRecording]:{sectionTitle:"Define recording rule",helpLabel:"Define your recording rule",helpContent:"Pre-compute frequently needed or computationally expensive expressions and save their result as a new set of time series.",helpLink:""},[y.Z.grafana]:{sectionTitle:"Define query and alert condition",helpLabel:"Define query and alert condition",helpContent:"An alert rule consists of one or more queries and expressions that select the data you want to measure. Define queries and/or expressions and then choose one of them as the alert rule condition. This is the threshold that an alert rule must meet or exceed in order to fire. For more information on queries and expressions, see Query and transform data.",helpLink:"https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/"},[y.Z.cloudAlerting]:{sectionTitle:"Define query and alert condition",helpLabel:"Define query and alert condition",helpContent:"An alert rule consists of one or more queries and expressions that select the data you want to measure. Define queries and/or expressions and then choose one of them as the alert rule condition. This is the threshold that an alert rule must meet or exceed in order to fire. For more information on queries and expressions, see Query and transform data.",helpLink:"https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/"}};var ye=e(30038),Pt=e(21969);const Gt=o=>{try{return JSON.stringify(o),!1}catch{return!0}},Dt=(o,s)=>{if(Gt(o))return null;if(s.datasourceUid!==Pe.Uj)return s;{const r=o.find(l=>l.refId===s.model.expression);return r?Dt(o,r):null}};var ft=e(53478),_e=e(76942);const Bt=(o,s)=>{const r=o.find(d=>d.refId===s);return r&&Dt(o,r)},Ut={queries:[]},nt=(0,ye.VP)("duplicateQuery"),Tt=(0,ye.VP)("addNewDataQuery"),vt=(0,ye.VP)("setDataQueries"),$t=(0,ye.VP)("addNewExpression"),At=(0,ye.VP)("removeExpression"),Ot=(0,ye.VP)("removeExpressions"),Nt=(0,ye.VP)("addExpressions"),Qt=(0,ye.VP)("updateExpression"),Mt=(0,ye.VP)("updateExpressionRefId"),Lt=(0,ye.VP)("rewireExpressions"),ve=(0,ye.VP)("updateExpressionType"),wt=(0,ye.VP)("updateExpressionTimeRange"),at=(0,ye.VP)("updateMaxDataPoints"),pt=(0,ye.VP)("updateMinInterval"),Zt=(0,ye.VP)("setRecordingRulesQueries"),on=(0,ye.vy)(Ut,o=>{o.addCase(nt,(s,{payload:r})=>{s.queries=jt(s.queries,r)}).addCase(Tt,s=>{const r=(0,xe.y9)();r&&(s.queries=jt(s.queries,{datasourceUid:r.uid,model:{refId:"",datasource:{type:r.type,uid:r.uid}}}))}).addCase(vt,(s,{payload:r})=>{const l=s.queries.filter(d=>(0,Ae.f)(d.model));s.queries=[...r,...l]}).addCase(Zt,(s,{payload:r})=>{const l=r.recordingRuleQueries[0],d={...l,expr:r.expression,model:l?.model};s.queries=[d]}).addCase(at,(s,r)=>{s.queries=s.queries.map(l=>l.refId===r.payload.refId?{...l,model:{...l.model,maxDataPoints:r.payload.maxDataPoints}}:l)}).addCase(pt,(s,r)=>{s.queries=s.queries.map(l=>l.refId===r.payload.refId?{...l,model:{...l.model,intervalMs:r.payload.minInterval?Xe.intervalToMs(r.payload.minInterval):void 0}}:l)}),o.addCase($t,(s,{payload:r})=>{s.queries=jt(s.queries,{datasourceUid:Pe.Uj,model:ft.Ex.newQuery({type:r,conditions:[{..._e.P,query:{params:[]}}],expression:""})})}).addCase(At,(s,{payload:r})=>{s.queries=s.queries.filter(l=>l.refId!==r)}).addCase(Ot,s=>{s.queries=s.queries.filter(r=>!(0,Ae.f)(r.model))}).addCase(Nt,(s,{payload:r})=>{s.queries=[...s.queries,...r]}).addCase(Qt,(s,{payload:r})=>{s.queries=s.queries.map(l=>{const d=Bt(s.queries,r.expression),m=d?d.relativeTimeRange:(0,h.Cn)();return l.refId===r.refId&&(l.model=r,r.type===Pe.Tz.resample&&(l.relativeTimeRange=m)),l})}).addCase(wt,s=>{const r=s.queries.map(l=>{if(l.datasourceUid===Pe.Uj){const d=Bt(s.queries,l.model.expression),m=d?d.relativeTimeRange:(0,h.Cn)();l.relativeTimeRange=m}return l});s.queries=r}).addCase(Mt,(s,{payload:r})=>{const{newRefId:l,oldRefId:d}=r;if((0,C.xb)(s.queries,l))return;const p=(0,C.I3)(s.queries,d,l);s.queries=p.map(u=>u.refId===d?{...u,refId:l,model:{...u.model,refId:l}}:u)}).addCase(Lt,(s,{payload:r})=>{s.queries=(0,C.I3)(s.queries,r.oldRefId,r.newRefId)}).addCase(ve,(s,r)=>{s.queries=s.queries.map(l=>l.refId===r.payload.refId?{...l,model:{...ft.Ex.newQuery({type:r.payload.type,conditions:[{..._e.P,query:{params:[]}}],expression:""}),refId:r.payload.refId}}:l)})}),jt=(o,s)=>{const r=(0,Pt.W3)(o),l={...s,refId:r,queryType:"",model:{...s.model,hide:!1,refId:r},relativeTimeRange:s.relativeTimeRange??sn(s.model)};return[...o,l]},sn=o=>{if(!(0,Ae.f)(o))return(0,h.Cn)()};var ln=e(28318);function cn(){const[o,s]=(0,t.useState)({}),r=(0,t.useRef)(new ln.t);(0,t.useEffect)(()=>{const u=r.current;return u.get().subscribe(L=>{s(L)}),()=>{u.destroy()}},[]);const l=(0,t.useCallback)(()=>{s({})},[]),d=(0,t.useCallback)(()=>{r.current.cancel()},[]),m=(0,t.useCallback)((u,L)=>{r.current.run(u,L)},[]),p=(0,t.useMemo)(()=>Object.values(o).some(u=>u.state===M.Gu.Loading),[o]);return{queryPreviewData:o,runQueries:m,cancelQueries:d,isPreviewLoading:p,clearPreviewData:l}}const un=({editingExistingRule:o,onDataChange:s})=>{const{setValue:r,getValues:l,watch:d,formState:{errors:m},control:p}=(0,te.xW)(),{queryPreviewData:u,runQueries:L,cancelQueries:ee,isPreviewLoading:w,clearPreviewData:oe}=cn(),Be={queries:l("queries")},[{queries:Z},B]=(0,t.useReducer)(on,Be),[$e,Oe,Ue]=d(["type","condition","dataSourceName"]),ke=$e===y.Z.grafana,lt=$e===y.Z.cloudRecording,Ze=$e===y.Z.cloudAlerting,zt=(0,he.useDispatch)();(0,t.useEffect)(()=>{zt((0,X.wE)())},[zt]);const bt=f(),et=(0,t.useCallback)(x=>{Ze||L(l("queries"),x||(l("condition")??""))},[Ze,L,l]);(0,t.useEffect)(()=>{r("queries",Z,{shouldValidate:!1})},[Z,L,r]);const Ft=(0,xe.y9)()===void 0,Ht=(0,t.useMemo)(()=>Z.filter(x=>!(0,Ae.f)(x.model)),[Z]),Kt=(0,t.useMemo)(()=>Z.filter(x=>(0,Ae.f)(x.model)),[Z]),Ce=Z.length===0;(0,t.useEffect)(()=>{if(!ke)return;const x=l("condition");if(!x)return;const J=u[x];if(!J)return;const Ye=(0,C.lb)(J)??(0,C.zy)(J);s(Ye?.message||"")},[u,l,s,ke]);const gt=(0,t.useCallback)(x=>{x&&(et(x),r("condition",x))},[et,r]),Yt=(0,t.useCallback)((x,J)=>{(0,C.xb)(Z,J)||(B(Mt({oldRefId:x,newRefId:J})),Oe===x&&gt(J))},[Oe,Z,gt]),Ke=fn(),Jt=(0,t.useCallback)(x=>{const Ye=l("queries").filter(Cn=>(0,Ae.f)(Cn.model));r("queries",[...x,...Ye],{shouldValidate:!1}),Ke(x),B(vt(x)),B(wt());const[Wt,rn]=(0,C.YG)(Z,x);Wt&&rn&&B(Lt({oldRefId:Wt,newRefId:rn}))},[Z,Ke,l,r]),Xt=(0,t.useCallback)(x=>{const J=x[0];if(!(0,fe.Bu)(J.model))return;const Ye=J.model.expr;r("queries",x,{shouldValidate:!1}),Ke(x),B(Zt({recordingRuleQueries:x,expression:Ye})),et()},[et,r,Ke]),kt=bt[0];(0,t.useEffect)(()=>{if(oe(),$e===y.Z.cloudRecording){const x=l("expression");if(!kt)return;const Ye={refId:"A",datasourceUid:o&&(0,g.l)().getInstanceSettings(Ue)?.uid||kt.uid,queryType:"",relativeTimeRange:(0,h.Cn)(),expr:x,instant:!0,model:{refId:"A",hide:!1,expr:x}};B(Zt({recordingRuleQueries:[Ye],expression:x}))}},[$e,kt,o,l,Ue,oe]);const pn=(0,t.useCallback)(x=>{B(nt(x))},[]);(0,t.useEffect)(()=>{if(!(0,C.xb)(Z,Oe)){const x=Z.at(-1)?.refId??null;gt(x)}},[Oe,Z,gt]);const gn=(0,t.useCallback)(x=>{B($t(x))},[B]),vn=(0,S.of)(mn),En=(0,t.useCallback)(x=>{const J=(0,a.cloneDeep)(Z);J[0].datasourceUid=x,r("queries",J,{shouldValidate:!1}),Ke(J),B(vt(J))},[Z,r,Ke,B]),yn=x=>{const J=(0,a.cloneDeep)(Z);if(J[0].model)if((0,fe.Bu)(J[0].model))J[0].model.expr=x;else{const Ye={...(0,a.cloneDeep)(J[0].model),expr:x};J[0].model=Ye}r("queries",J,{shouldValidate:!1}),Ke(J),B(vt(J)),et()},_t=(0,t.useCallback)(()=>B(Ot()),[B]),en=(0,t.useCallback)(x=>B(Nt(x)),[B]),[Vt,hn]=(0,t.useState)([]),[qt,xn]=(0,t.useState)(null),tn=(0,t.useCallback)(()=>{en(Vt)},[Vt,en]),nn=(0,t.useCallback)(()=>{if(l("type")===y.Z.cloudAlerting)r("type",y.Z.grafana),r("dataSourceName",null),Vt.length>0&&tn(),qt&&r("condition",qt);else{r("type",y.Z.cloudAlerting);const J=(0,g.l)().getInstanceSettings(Z[0].datasourceUid)?.name;J&&r("dataSourceName",J),Ke(Z);const Ye=Z.filter(Wt=>Wt.datasourceUid===Pe.Uj);hn(Ye),_t(),xn(Oe)}},[l,r,Vt.length,tn,qt,Ke,Z,_t,Oe]),{sectionTitle:Sn,helpLabel:an,helpContent:In,helpLink:Rn}=mt[$e??y.Z.grafana];return t.createElement(A.P,{stepNo:2,title:Sn,description:t.createElement(T.B,{direction:"row",gap:.5,alignItems:"center"},t.createElement(Ee.E,{variant:"bodySmall",color:"secondary"},an),t.createElement(pe.G,{contentText:In,externalLink:Rn,linkText:"Read more on our documentation website",title:an}))},($e===y.Z.cloudRecording||$e===y.Z.cloudAlerting)&&t.createElement(ce,{onChangeCloudDatasource:En,disabled:o}),lt&&Ue&&t.createElement(se.D,{error:m.expression?.message,invalid:!!m.expression?.message},t.createElement(c,{dataSourceName:Ue,queries:Z,runQueries:et,onChangeQuery:Xt,panelData:u})),Ze&&Ue&&t.createElement(T.B,{direction:"column"},t.createElement(se.D,{error:m.expression?.message,invalid:!!m.expression?.message},t.createElement($.e,{name:"expression",render:({field:{ref:x,...J}})=>t.createElement(le,{...J,dataSourceName:Ue,showPreviewAlertsButton:!lt,onChange:yn}),control:p,rules:{required:{value:!0,message:"A valid expression is required"}}})),t.createElement(st,{editingExistingRule:o,queries:Z,rulesSourcesWithRuler:bt,onClickSwitch:nn})),ke&&t.createElement(T.B,{direction:"column"},t.createElement(q,{queries:Ht,expressions:Kt,onRunQueries:()=>et(),onChangeQueries:Jt,onDuplicateQuery:pn,panelData:u,condition:Oe,onSetCondition:gt}),t.createElement(F.m,{content:"You appear to have no compatible data sources",show:Ft},t.createElement(V.$n,{type:"button",onClick:()=>{B(Tt())},variant:"secondary","data-testid":R.Tp.components.QueryTab.addQuery,disabled:Ft,className:vn.addQueryButton},"Add query")),t.createElement(st,{editingExistingRule:o,rulesSourcesWithRuler:bt,queries:Z,onClickSwitch:nn}),t.createElement(T.B,{direction:"column",gap:0},t.createElement(Ee.E,{element:"h5"},"Expressions"),t.createElement(Ee.E,{variant:"bodySmall",color:"secondary"},"Manipulate data returned from queries with math and other operations.")),t.createElement(Q,{queries:Z,panelData:u,condition:Oe,onSetCondition:gt,onRemoveExpression:x=>{B(At(x))},onUpdateRefId:Yt,onUpdateExpressionType:(x,J)=>{B(ve({refId:x,type:J}))},onUpdateQueryExpression:x=>{B(Qt(x))}}),t.createElement(T.B,{direction:"row"},j.$.expressionsEnabled&&t.createElement(dn,{onClickType:gn}),w&&t.createElement(V.$n,{icon:"spinner",type:"button",variant:"destructive",onClick:ee},"Cancel"),!w&&t.createElement(V.$n,{icon:"sync",type:"button",onClick:()=>et(),disabled:Ce},"Preview")),Ce&&t.createElement(ue.F,{title:"No queries or expressions have been configured",severity:"warning"},"Create at least one query or expression to be alerted on")))};function dn({onClickType:o}){const s=t.createElement(je.W,null,Pe.uQ.map(r=>t.createElement(F.m,{key:r.value,content:r.description??"",placement:"right"},t.createElement(we.D,{key:r.value,onClick:()=>o(r.value??Pe.Tz.math),label:r.label??""}))));return t.createElement(ze.m,{overlay:s},t.createElement(V.$n,{variant:"secondary"},"Add expression",t.createElement(Re.I,{name:"angle-down"})))}const mn=o=>({addQueryButton:(0,n.css)`
    width: fit-content;
  `,helpInfo:(0,n.css)`
    display: flex;
    flex-direction: row;
    align-items: center;
    width: fit-content;
    font-weight: ${o.typography.fontWeightMedium};
    margin-left: ${o.spacing(1)};
    font-size: ${o.typography.size.sm};
    cursor: pointer;
  `,helpInfoText:(0,n.css)`
    margin-left: ${o.spacing(.5)};
    text-decoration: underline;
  `,infoLink:(0,n.css)`
    color: ${o.colors.text.link};
  `}),fn=()=>{const{setValue:o}=(0,te.xW)();return s=>{const r=s[0];if(!r)return;if(!(0,g.l)().getInstanceSettings(r.datasourceUid))throw new Error("The Data source has not been defined.");if((0,fe.Bu)(r.model)){const d=r.model.expr;o("expression",d)}}}},79657:(Le,ae,e)=>{e.d(ae,{DY:()=>Qe,Mk:()=>Re,QM:()=>je,Rg:()=>$,SJ:()=>ze,YE:()=>we,Yl:()=>V,eb:()=>Ae,gY:()=>Ee,hH:()=>he,ie:()=>Pe});var n=e(2543),a=e.n(n),t=e(60021),te=e(98164),h=e(57220),R=e(32642),g=e(67332),j=e(25968);const S=(f,X)=>Object.entries(f??{}).reduce((y,[fe,ie])=>[...y,{name:fe,value:ie,operator:X?t.ho.regex:t.ho.equal}],[]),T=f=>f.value,se=f=>(f??[]).map(T),$={name:"",value:"",operator:t.ho.equal},F=["grafana_folder","alertname"],V=[{label:"grafana_folder",value:"grafana_folder",isFixed:!0},{label:"alertname",value:"alertname",isFixed:!0},{label:"Disable (...)",value:"..."}],ue={id:"",overrideGrouping:!1,groupBy:F,object_matchers:[],routes:[],continue:!1,receiver:"",overrideTimings:!1,groupWaitValue:"",groupIntervalValue:"",repeatIntervalValue:"",muteTimeIntervals:[]};function je(f){return{id:(0,n.uniqueId)("route-"),...f,routes:(f.routes??[]).map(je)}}const we=f=>{if(!f)return ue;const X="id"in f?f.id:(0,n.uniqueId)("route-");if(Object.keys(f).length===0)return{...ue,id:X};const y=[];f.routes?.forEach(M=>{const Se=we(M);y.push(Se)});const fe=f.object_matchers?.map(M=>({name:M[0],operator:M[1],value:M[2]}))??[],ie=f.matchers?.map(M=>(0,te.MU)((0,R.qR)(M))).map(({name:M,operator:Se,value:k})=>({name:M,operator:Se,value:(0,R.Ig)(k)}))??[];return{id:X,object_matchers:[...ie,...fe,...S(f.match,!1),...S(f.match_re,!0)],continue:f.continue??!1,receiver:f.receiver??"",overrideGrouping:Array.isArray(f.group_by)&&f.group_by.length>0,groupBy:f.group_by??void 0,overrideTimings:[f.group_wait,f.group_interval,f.repeat_interval].some(Boolean),groupWaitValue:f.group_wait??"",groupIntervalValue:f.group_interval??"",repeatIntervalValue:f.repeat_interval??"",routes:y,muteTimeIntervals:f.mute_time_intervals??[]}},ze=(f,X,y)=>{const fe=(0,g.eM)(X.id??"",y),{overrideGrouping:ie,groupBy:M,overrideTimings:Se,groupWaitValue:k,groupIntervalValue:be,repeatIntervalValue:He,receiver:De}=X,Ne=void 0,Je=ie?M:Ne,ne=Se&&k?k:Ne,le=Se&&be?be:Ne,O=Se&&He?He:Ne,I=X.object_matchers?.filter(_=>_.name&&_.operator&&_.value!==null&&_.value!==void 0).map(({name:_,operator:pe,value:ge})=>[_,pe,ge]),C=X.routes?.map(_=>ze(f,_,y)),Q={...fe??{},continue:X.continue,group_by:Je,object_matchers:I,match:void 0,match_re:void 0,group_wait:ne,group_interval:le,repeat_interval:O,routes:C,mute_time_intervals:X.muteTimeIntervals,receiver:De};return f!==h.hY?(Q.matchers=X.object_matchers?.map(({name:_,operator:pe,value:ge})=>`${_}${pe}${(0,R.ot)(ge)}`),Q.object_matchers=void 0):(Q.object_matchers=(0,R.J$)(Q),Q.matchers=void 0),X.receiver&&(Q.receiver=X.receiver),Q},Re=f=>({label:f,value:f}),Ee=f=>(f??[]).map(Re),Ae=f=>f===null?null:f?T(f)??"":"",Pe=f=>f?se(f):[];function he(f){return!f||f.length===0?!0:(0,j.TN)(f)||"Invalid duration format. Must be {number}{time_unit}"}const xe=f=>f.map(X=>{const[y,fe,ie]=X;return`${y}${fe}${ie}`}),Qe=(f,X="")=>{if(f.length===0)return!0;const y=he(f),fe=he(X);if(y!==!0)return y;if(fe!==!0)return fe;const ie=(0,j.ge)(f),M=(0,j.ge)(X);return M!==0&&ie<M?"Repeat interval should be higher or equal to Group interval":!0}},79944:(Le,ae,e)=>{e.d(ae,{V:()=>n});function n(a,t){const te=a.replace(/\(copy( [0-9]+)?\)$/,"").trim();let h=`${te} (copy)`;for(let R=2;t.includes(h);R++)h=`${te} (copy ${R})`;return h}},67332:(Le,ae,e)=>{e.d(ae,{AB:()=>te,AS:()=>h,eM:()=>g,pq:()=>R});var n=e(2543),a=e.n(n),t=e(79657);const te=(j,S,T)=>{if(!g(S.id??"",T))throw new Error(`No such route with ID '${S.id}'`);function $(F){let V=F;if(F.id===S.id){const ue=(0,t.SJ)(j,S,T);V=(0,n.omit)({...F,...ue},"id")}return(0,n.omit)({...V,routes:F.routes?.map($)},"id")}return $(T)},h=(j,S)=>{if(j.id===S.id)throw new Error("You cant remove the root policy");function T(se){return(0,n.omit)({...se,routes:se.routes?.reduce(($=[],F)=>(F.id===j.id||$.push(T(F)),$),[])},"id")}return T(S)},R=(j,S,T,se)=>{const $=(0,t.SJ)(j,S,se);function F(ue){return ue.id===T.id?{...ue,routes:ue.routes?.concat($)}:{...ue,routes:ue.routes?.map(F)}}function V(ue){return(0,n.omit)({...ue,routes:ue.routes?.map(V)},"id")}return V(F(se))};function g(j,S){return S.id===j?S:S.routes?.find(T=>g(j,T))}},87286:(Le,ae,e)=>{e.d(ae,{B:()=>te});var n=e(32196),a=e(96540),t=e(40845);function te(R){const g=(0,t.of)(h,R);return a.createElement("div",{className:g.root},R.children)}const h=(R,g)=>({root:(0,n.css)({display:"flex",flexDirection:g.direction??"row",flexWrap:g.wrap??!0?"wrap":void 0,alignItems:g.alignItems,gap:R.spacing(g.gap??2),flexGrow:g.flexGrow})})}}]);

//# sourceMappingURL=AlertingRuleForm.ddb9dca92b632dbd5163.js.map