⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.72
Server IP:
41.128.143.86
Server:
Linux host.raqmix.cloud 6.8.0-1025-azure #30~22.04.1-Ubuntu SMP Wed Mar 12 15:28:20 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.3.23
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
proc
/
self
/
root
/
usr
/
share
/
grafana
/
public
/
build
/
View File Name :
AlertingRuleForm.66bb5b2724b31ae6a5a4.js
"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4009],{50166:(Qe,k,e)=>{e.r(k),e.d(k,{default:()=>Ue});var n=e(96540),a=e(16817),t=e(66602),J=e(80348),x=e(32196),S=e(42418),g=e(40845),A=e(55852);function h({title:c,children:v}){return n.createElement(S.F,{className:(0,g.of)(P).warning,severity:"warning",title:c},n.createElement("p",null,v),n.createElement(A.z9,{href:"alerting/list"},"To rule list"))}const P=c=>({warning:(0,x.css)` margin: ${c.spacing(4)}; `});var ee=e(2543),N=e(12131),$=e(39558),Q=e(49785),oe=e(24180),Fe=e(54625),Oe=e(32264),ze=e(66864),Re=e(62930),ye=e(40276),Ne=e(67061),De=e(96374),Se=e(75269),Ie=e(3169),we=e(10096),f=e(40715),X=e(83277),y=e(25027),ge=e(55776),ve=e(61410),W=e(23770),se=e(86590),Ce=e(88467),ce=e(63066),be=e(18461),Te=e(79938),Me=e(16293),Je=e(76648),Z=e(84029);const te=({alertUid:c,exportFormat:v,onClose:T})=>{const{currentData:U="",isFetching:F}=Te.hK.endpoints.exportRules.useQuery({ruleUid:c,format:v}),B=`${c}-${new Date().getTime()}`;return F?n.createElement($._,{text:"Loading...."}):n.createElement(Me.J,{format:v,textDefinition:U,downloadFileName:B,onClose:T})},j=({onClose:c,alertUid:v})=>{const[T,U]=(0,n.useState)("yaml");return n.createElement(Je.m,{activeTab:T,onTabChange:U,onClose:c,formatProviders:Object.values(Z.sl)},n.createElement(te,{alertUid:v,exportFormat:T,onClose:c}))};var le=e(53534),E=e(31099),M=e(88575),C=e(10354),R=e(16504),O=e(88323),ie=e(25968),me=e(7921);const fe=({rulesSourceName:c})=>{const{control:v,watch:T,formState:{errors:U},setValue:F}=(0,Q.xW)(),B=(0,g.of)(Xe),ne=(0,ve.$)(Ae=>Ae.rulerRules),ae=(0,J.useDispatch)();(0,n.useEffect)(()=>{ae((0,W.eB)({rulesSourceName:c}))},[c,ae]);const pe=ne[c]?.result,de=T("namespace"),he=(0,n.useMemo)(()=>pe?Object.keys(pe).map(Ae=>({label:Ae,value:Ae})):[],[pe]),ke=(0,n.useMemo)(()=>de&&pe?.[de]?.map(Ae=>({label:Ae.name,value:Ae.name}))||[],[de,pe]);return n.createElement("div",{className:B.flexRow},n.createElement(M.D,{"data-testid":"namespace-picker",label:"Namespace",error:U.namespace?.message,invalid:!!U.namespace?.message},n.createElement(R.e,{render:({field:{onChange:Ae,ref:mt,...xe}})=>n.createElement(O.ip,{...xe,allowCustomValue:!0,className:B.input,onChange:vt=>{F("group",""),Ae(vt.value)},options:he,width:42}),name:"namespace",control:v,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:me.G0}}})),n.createElement(M.D,{"data-testid":"group-picker",label:"Group",error:U.group?.message,invalid:!!U.group?.message},n.createElement(R.e,{render:({field:{ref:Ae,...mt}})=>n.createElement(O.ip,{...mt,allowCustomValue:!0,options:ke,width:42,onChange:xe=>{F("group",xe.value??"")},className:B.input}),name:"group",control:v,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:me.G0}}})))},Xe=c=>({flexRow:(0,x.css)` display: flex; flex-direction: row; justify-content: flex-start; & > * + * { margin-left: ${c.spacing(3)}; } `,input:(0,x.css)` width: 330px !important; `});var Ke=e(67986),nt=e(271);const it=()=>{const c=(0,g.of)(at),{register:v,control:T,watch:U,formState:{errors:F}}=(0,Q.xW)(),B=U("type"),ne=U("dataSourceName");return n.createElement(nt.P,{stepNo:3,title:"Set evaluation behavior"},n.createElement(M.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(M.D,{invalid:!!F.forTime?.message,error:F.forTime?.message,className:c.inlineField},n.createElement(C.p,{...v("forTime",{pattern:{value:/^\d+$/,message:"Must be a positive integer."}}),width:8})),n.createElement(R.e,{name:"forTimeUnit",render:({field:{onChange:ae,ref:pe,...de}})=>n.createElement(O.l6,{...de,options:ie.sc,onChange:he=>ae(he?.value),width:15,className:c.timeUnit}),control:T}))),B===se.Z.cloudAlerting&&ne&&n.createElement(fe,{rulesSourceName:ne}),n.createElement(Ke.L,null))},at=c=>({inlineField:(0,x.css)` margin-bottom: 0; `,flexRow:(0,x.css)` display: flex; flex-direction: row; justify-content: flex-start; align-items: flex-start; `,timeUnit:(0,x.css)` margin-left: ${c.spacing(.5)}; `});var Ve=e(74400),Et=e(9267);function yt(){const{watch:c}=(0,Q.xW)(),v=c("dataSourceName");return v?n.createElement(nt.P,{stepNo:3,title:"Add namespace and group",description:"Select the Namespace and Group for your recording rule."},n.createElement(fe,{rulesSourceName:v})):null}var ht=e(73716),xt=e(890);const ct=({existing:c,prefill:v})=>{const T=(0,g.of)(ut),U=(0,J.useDispatch)(),F=(0,Ie._2)(),[B]=(0,X.s)(),[ne,ae]=(0,n.useState)(!1),[pe,de]=(0,n.useState)(c?.group.interval??ce.pY),he=(0,oe.g)(),ke=(0,me._u)(he.type),Ae=he.id,{returnTo:mt}=(0,ge.h)("/alerting/list"),[xe,vt]=(0,n.useState)(!1),Dt=(0,n.useMemo)(()=>c?(0,ce.ir)(c):v?Rt(v):typeof B.defaults=="string"?It(B.defaults,ke):{...(0,ce.IJ)(),condition:"C",queries:(0,ce.qO)(),type:ke||se.Z.grafana,evaluateEvery:pe},[c,v,B,pe,ke]),Tt=(0,Q.mN)({mode:"onSubmit",defaultValues:Dt,shouldFocusError:!0}),{handleSubmit:At,watch:ft}=Tt,et=ft("type"),Ut=ft("dataSourceName"),$t=!!(et&&(et===se.Z.grafana||Ut)),rt=(0,ve.$)(Ee=>Ee.ruleForm.saveRule)||Ce.jA;(0,f.o)(Ee=>Ee.unifiedAlerting.ruleForm.saveRule=Ce.jA);const[pt,Ot]=(0,n.useState)(""),Gt=(Ee="")=>{Ot(Ee)},Nt=(Ee,Zt)=>{if(pt!==""){F.error(pt);return}c||(Ee.manualRouting?localStorage.setItem(ce.Q8,"true"):localStorage.setItem(ce.Q8,"false")),U((0,W._$)({values:{...Dt,...Ee,annotations:Ee.annotations?.map(({key:ot,value:st})=>({key:ot.trim(),value:st.trim()})).filter(({key:ot,value:st})=>!!ot&&!!st)??[],labels:Ee.labels?.map(({key:ot,value:st})=>({key:ot.trim(),value:st.trim()})).filter(({key:ot})=>!!ot)??[]},existing:c,redirectOnSave:Zt?mt:void 0,initialAlertRuleName:Dt.name,evaluateEvery:pe}))},Lt=()=>{if(c){const Ee=be.P1(c.ruleSourceName,c.namespace,c.group.name,c.rule);U((0,W.KH)(Ee,{navigateTo:"/alerting/list"}))}},Mt=Ee=>{c||(0,y.SN)({grafana_version:Oe.$.buildInfo.version,org_id:we.TP.user.orgId,user_id:we.TP.user.id,error:Object.keys(Ee).toString()}),F.error("There are errors in the form. Please correct them and try again!")},Qt=()=>{(0,y.fH)(y.le.cancelSavingAlertRule)},bt=ft("evaluateEvery");(0,n.useEffect)(()=>de(bt),[bt]);const Ft=n.createElement(ze.Gy,{height:"auto",justify:"flex-end"},c&&n.createElement(A.$n,{variant:"primary",type:"button",size:"sm",onClick:At(Ee=>Nt(Ee,!1),Mt),disabled:rt.loading},rt.loading&&n.createElement(Re.y,{className:T.buttonSpinner,inline:!0}),"Save rule"),n.createElement(A.$n,{variant:"primary",type:"button",size:"sm",onClick:At(Ee=>Nt(Ee,!0),Mt),disabled:rt.loading},rt.loading&&n.createElement(Re.y,{className:T.buttonSpinner,inline:!0}),"Save rule and exit"),n.createElement(Fe.Link,{to:mt??"/alerting/list"},n.createElement(A.$n,{variant:"secondary",disabled:rt.loading,type:"button",onClick:Qt,size:"sm"},"Cancel")),c?n.createElement(A.$n,{fill:"outline",variant:"destructive",type:"button",onClick:()=>vt(!0),size:"sm"},"Delete"):null,c&&St(ft)&&n.createElement(A.$n,{variant:"secondary",type:"button",onClick:()=>ae(!0),disabled:rt.loading,size:"sm"},"Edit YAML"));return n.createElement(Q.Op,{...Tt},n.createElement(Se.H,{actions:Ft}),n.createElement("form",{onSubmit:Ee=>Ee.preventDefault(),className:T.form},n.createElement("div",{className:T.contentOuter},n.createElement(ye.E,{autoHeightMin:"100%",hideHorizontalTrack:!0},n.createElement(Ne.B,{direction:"column",gap:3},n.createElement(le.G,null),n.createElement(xt.N,{editingExistingRule:!!c,onDataChange:Gt}),$t&&n.createElement(n.Fragment,null,et===se.Z.grafana&&n.createElement(Ve.R,{evaluateEvery:pe,setEvaluateEvery:de,existing:!!c,enableProvisionedGroups:!1}),et===se.Z.cloudAlerting&&n.createElement(it,null),et===se.Z.cloudRecording&&n.createElement(yt,null),n.createElement(Et.N,{alertUid:Ae}),et!==se.Z.cloudRecording&&n.createElement(E.A,null)))))),xe?n.createElement(De.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:Lt,onDismiss:()=>vt(!1)}):null,ne?et===se.Z.grafana?n.createElement(j,{alertUid:Ae,onClose:()=>ae(!1)}):n.createElement(ht.G_,{onClose:()=>ae(!1)}):null)},St=c=>{const[v,T]=c(["type","dataSourceName"]);return(v===se.Z.cloudAlerting||v===se.Z.cloudRecording)&&T!==""};function It(c,v){let T;try{T=JSON.parse(c)}catch{return{...(0,ce.IJ)(),queries:(0,ce.qO)()}}return(0,ce.Rk)({...(0,ce.IJ)(),...T,annotations:(0,ce.JE)(T.annotations??[]),queries:T.queries??(0,ce.qO)(),type:v||se.Z.grafana,evaluateEvery:ce.pY})}function Rt(c){return(0,ce.Rk)({...(0,ce.IJ)(),...c})}const ut=c=>({buttonSpinner:(0,x.css)({marginRight:c.spacing(1)}),form:(0,x.css)({width:"100%",height:"100%",display:"flex",flexDirection:"column"}),contentOuter:(0,x.css)({background:c.colors.background.primary,overflow:"hidden",flex:1}),flexRow:(0,x.css)({display:"flex",flexDirection:"row",justifyContent:"flex-start"})});var Ct=e(79944),_e=e(23662),Pt=e(3704);function dt({sourceRuleId:c}){const v=(0,J.useDispatch)(),{loading:T,value:U,error:F}=(0,a.A)(()=>v((0,W.pT)(c)).unwrap(),[c]);if(T)return n.createElement($._,{text:"Loading the rule"});if(U){const B=D(U),ne=(0,ce.QX)(B);return n.createElement(ct,{prefill:ne})}return F?n.createElement(S.F,{title:"Error",severity:"error"},F.message):n.createElement(S.F,{title:"Cannot copy the rule. The rule does not exist",buttonContent:"Go back to alert list",onRemove:()=>N.Ny.replace((0,Pt.c)("/alerting/list"))})}function i(c,v){(0,_e.lT)(c)&&(c.grafana_alert.title=v),(0,_e.$y)(c)&&(c.alert=v),(0,_e.i7)(c)&&(c.record=v)}function D(c){const v=(0,ee.cloneDeep)(c);return i(v.rule,(0,Ct.V)((0,_e.qz)(v.rule),v.group.rules.map(_e.qz))),(0,_e.lT)(v.rule)&&(v.rule.grafana_alert.uid="",v.rule.grafana_alert.provenance&&(v.group={name:"",rules:v.group.rules})),v}var b=e(97009);function G({identifier:c,id:v}){(0,f.o)(he=>he.unifiedAlerting.ruleForm.existingRule=Ce.jA);const{loading:T,result:U,error:F,dispatched:B}=(0,ve.$)(he=>he.ruleForm.existingRule),ne=(0,J.useDispatch)(),{isEditable:ae,loading:pe}=(0,b.g)(be.VY(c),U?.rule),de=T||pe;return(0,n.useEffect)(()=>{B||ne((0,W.pT)(c))},[B,ne,c]),de||ae===void 0?n.createElement($._,{text:"Loading rule..."}):F?n.createElement(S.F,{severity:"error",title:"Failed to load rule"},F.message):U?ae===!1?n.createElement(h,{title:"Cannot edit rule"},"Sorry! You do not have permission to edit this rule."):n.createElement(ct,{existing:U}):n.createElement(h,{title:"Rule not found"},"Sorry! This rule does not exist.")}var H=e(33450),ue=e(39964),q=e(41520);const z={icon:"bell",id:"alert-rule-view"},Be=(c,v)=>v==="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"},We=({match:c})=>{const v=(0,J.useDispatch)(),[T]=(0,ue.l)(),{type:U}=c.params,F=be.uE(c.params),B=be.x6(F,!0),ne=T.get("copyFrom")??void 0,ae=be.x6(ne),{loading:pe=!0}=(0,a.A)(async()=>{B&&await v((0,W.DC)({rulesSourceName:B.ruleSourceName})),ae&&await v((0,W.DC)({rulesSourceName:ae.ruleSourceName}))},[v]),{canCreateGrafanaRules:de,canCreateCloudRules:he,canEditRules:ke}=(0,q.V)(),Ae=(0,n.useCallback)(()=>{if(!pe)return!B&&!de&&!he?n.createElement(h,{title:"Cannot create rules"},"Sorry! You are not allowed to create rules."):B&&!ke(B.ruleSourceName)?n.createElement(h,{title:"Cannot edit rules"},"Sorry! You are not allowed to edit rules."):B?n.createElement(G,{key:F,identifier:B,id:F}):ae?n.createElement(dt,{sourceRuleId:ae}):n.createElement(ct,null)},[he,de,ke,ae,F,B,pe]);return n.createElement(H.d,{isLoading:pe,navId:"alert-list",pageNav:Be(B,U)},Ae())},Ue=(0,t.Xc)(We,{style:"page"})},69179:(Qe,k,e)=>{e.r(k),e.d(k,{default:()=>Je});var n=e(96540),a=e(16817),t=e(12131),J=e(39558),x=e(42418),S=e(80348),g=e(23770),A=e(63066),h=e(18461),P=e(23662),ee=e(3704),N=e(33450),$=e(49785),Q=e(55852),oe=e(40276),Fe=e(67061),Oe=e(3169),ze=e(75269),Re=e(79938),ye=e(28220),Ne=e(730),De=e(55776),Se=e(57220),Ie=e(16293),we=e(76648),f=e(84029),X=e(53534),y=e(31099),ge=e(74400),ve=e(9267),W=e(890);function se({ruleForm:Z,alertUid:te}){const j=(0,$.mN)({mode:"onSubmit",defaultValues:Z,shouldFocusError:!0}),le=!!Z,E=(0,Oe._2)(),{returnTo:M}=(0,De.h)("/alerting/list"),[C,R]=(0,n.useState)(void 0),[O,ie]=(0,n.useState)(""),[me,fe]=(0,n.useState)(Z?.evaluateEvery??A.pY),Xe=()=>{E.error("There are errors in the form. Please correct them and try again!")},Ke=(Ve="")=>{ie(Ve)},nt=Ve=>{if(O!==""){E.error(O);return}R(Ve)},it=(0,n.useCallback)(()=>{R(void 0)},[R]),at=[n.createElement(Q.z9,{href:M,key:"cancel",size:"sm",variant:"secondary",onClick:()=>nt(void 0)},"Cancel"),n.createElement(Q.$n,{key:"export-rule",size:"sm",onClick:j.handleSubmit(Ve=>nt(Ve),Xe)},"Export")];return n.createElement(n.Fragment,null,n.createElement($.Op,{...j},n.createElement(ze.H,{actions:at}),n.createElement("form",{onSubmit:Ve=>Ve.preventDefault()},n.createElement("div",null,n.createElement(oe.E,{autoHeightMin:"100%",hideHorizontalTrack:!0},n.createElement(Fe.B,{direction:"column",gap:3},n.createElement(X.G,null),n.createElement(W.N,{editingExistingRule:le,onDataChange:Ke}),n.createElement(ge.R,{evaluateEvery:me,setEvaluateEvery:fe,existing:!!le,enableProvisionedGroups:!0}),n.createElement(ve.N,{alertUid:te}),n.createElement(y.A,null))))),C&&n.createElement(Me,{exportValues:C,onClose:it,uid:te})))}const Ce=(Z,te)=>{const{dsFeatures:j}=(0,Ne.O3)(Se.hY),le=j?.rulerConfig;return(0,a.A)(async()=>le?await(0,ye.HO)(le,Z,te):void 0,[le,Z,te])},ce=(Z,te,j)=>{const le=(0,A.Z9)(te),E={...le,grafana_alert:{...le.grafana_alert,uid:Z}};if(j?.rules){let M=!1;const C=j.rules.map(R=>(0,P.lT)(R)&&R.grafana_alert.uid===Z?(M=!0,E):R);return M||C.push(E),{...j,rules:C}}else return{name:j?.name??"",rules:[E]}},be=(Z,te)=>{const j=Ce(Z.folder?.uid??"",Z.group);return{payload:(0,n.useMemo)(()=>ce(te,Z,j?.value),[te,j,Z]),loadingGroup:j.loading}},Te=({exportFormat:Z,exportValues:te,onClose:j,uid:le})=>{const[E,M]=Re.hK.endpoints.exportModifiedRuleGroup.useMutation(),{loadingGroup:C,payload:R}=be(te,le),O=te.folder?.uid??"";if((0,n.useEffect)(()=>{!C&&E({payload:R,format:Z,nameSpaceUID:O})},[O,Z,R,E,C]),M.isLoading)return n.createElement(J._,{text:"Loading...."});const ie=`modify-export-${R.name}-${le}-${new Date().getTime()}`;return n.createElement(Ie.J,{format:Z,textDefinition:M.data??"",downloadFileName:ie,onClose:j})},Me=n.memo(({onClose:Z,exportValues:te,uid:j})=>{const[le,E]=(0,n.useState)("yaml");return n.createElement(we.m,{title:"Export Group",activeTab:le,onTabChange:E,onClose:Z,formatProviders:Object.values(f.sl)},n.createElement(Te,{exportFormat:le,onClose:Z,exportValues:te,uid:j}))});Me.displayName="GrafanaRuleDesignExporter";function Je({match:Z}){const te=(0,S.useDispatch)(),[j,le]=(0,n.useState)(void 0);(0,n.useEffect)(()=>{const O=h.x6(Z.params.id,!0);le(O)},[Z.params.id]);const{loading:E=!0}=(0,a.A)(async()=>{j&&await te((0,g.DC)({rulesSourceName:j.ruleSourceName}))},[te,j]),{loading:M,value:C,error:R}=(0,a.A)(async()=>{if(j)return await te((0,g.pT)(j)).unwrap()},[j,E]);return j?M?n.createElement(J._,{text:"Loading the rule"}):R?n.createElement(x.F,{title:"Cannot load modify export",severity:"error"},R.message):!C&&!M&&!E?n.createElement(N.d,{isLoading:M,navId:"alert-list",pageNav:{text:"Modify export"}},n.createElement(x.F,{title:"Cannot load the rule. The rule does not exist",buttonContent:"Go back to alert list",onRemove:()=>t.Ny.replace((0,ee.c)("/alerting/list"))})):C&&!(0,P.lT)(C.rule)?n.createElement(N.d,{isLoading:M,navId:"alert-list",pageNav:{text:"Modify export"}},n.createElement(x.F,{title:"This rule is not a Grafana-managed alert rule",buttonContent:"Go back to alert list",onRemove:()=>t.Ny.replace((0,ee.c)("/alerting/list"))})):n.createElement(N.d,{isLoading:M,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."}},C&&n.createElement(se,{ruleForm:(0,A.ir)(C),alertUid:Z.params.id??""})):n.createElement("div",null,"Rule not found")}},33915:(Qe,k,e)=>{e.d(k,{V:()=>ee});var n=e(96540),a=e(10354),t=e(14578),J=e(35108),x=e(32196),S=e(40845),g=e(41068);function A(){const N=(0,S.of)(P);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:N.list},n.createElement("div",{className:N.header},n.createElement("div",null,"Symbol"),n.createElement("div",null,"Time unit"),n.createElement("div",null,"Example")),n.createElement(h,{unit:g.y.seconds,name:"seconds",example:"20s"}),n.createElement(h,{unit:g.y.minutes,name:"minutes",example:"10m"}),n.createElement(h,{unit:g.y.hours,name:"hours",example:"4h"}),n.createElement(h,{unit:g.y.days,name:"days",example:"3d"}),n.createElement(h,{unit:g.y.weeks,name:"weeks",example:"2w"}),n.createElement("div",{className:N.examples},n.createElement("div",null,"Multiple units combined"),n.createElement("code",null,"1m30s, 2h30m20s, 1w2d"))))}function h({unit:N,name:$,example:Q}){const oe=(0,S.of)(P);return n.createElement(n.Fragment,null,n.createElement("div",{className:oe.unit},N),n.createElement("div",null,$),n.createElement("code",null,Q))}const P=N=>({unit:(0,x.css)` font-weight: ${N.typography.fontWeightBold}; `,list:(0,x.css)` display: grid; grid-template-columns: max-content 1fr 2fr; gap: ${N.spacing(1,3)}; `,header:(0,x.css)` display: contents; font-weight: ${N.typography.fontWeightBold}; `,examples:(0,x.css)` display: contents; & > div { grid-column: 1 / span 2; } `}),ee=n.forwardRef((N,$)=>n.createElement(a.p,{suffix:n.createElement(J.j,{content:n.createElement(A,null),disabled:!1},n.createElement(t.I,{name:"info-circle",size:"lg"})),...N,ref:$}));ee.displayName="PromDurationInput"},99903:(Qe,k,e)=>{e.d(k,{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:(Qe,k,e)=>{e.d(k,{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:(Qe,k,e)=>{e.d(k,{H:()=>n});const n={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"}},53534:(Qe,k,e)=>{e.d(k,{G:()=>h});var n=e(96540),a=e(49785),t=e(94753),J=e(88575),x=e(10354),S=e(86590),g=e(271);const A={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_:]*$/},h=()=>{const{register:P,watch:ee,formState:{errors:N}}=(0,a.xW)(),$=ee("type"),Q=$===S.Z.cloudRecording?"recording rule":"alert rule";return n.createElement(g.P,{stepNo:1,title:`Enter ${Q} name`,description:n.createElement(t.E,{variant:"bodySmall",color:"secondary"},"Enter a name to identify your ",Q,".")},n.createElement(J.D,{label:"Name",error:N?.name?.message,invalid:!!N.name?.message},n.createElement(x.p,{id:"name",width:35,...P("name",{required:{value:!0,message:"Must enter a name"},pattern:$===S.Z.cloudRecording?A:void 0}),"aria-label":"name",placeholder:`Give your ${Q} a name`})))}},9267:(Qe,k,e)=>{e.d(k,{N:()=>It});var n=e(32196),a=e(96540),t=e(49785),J=e(32264),x=e(40845),S=e(67061),g=e(94753),A=e(94354),h=e(14578),P=e(86590),ee=e(57220),N=e(54749),$=e(64100),Q=e(271),oe=e(70383),Fe=e(42418),Oe=e(39558),ze=e(57418),Re=e(13726),ye=e(79381),Ne=e(77141);const De=({receivers:i})=>a.createElement(S.B,{direction:"column",gap:0},a.createElement("div",null,i.map((D,b)=>{const G=D[ye.MX],H=D[ye.sW],ue=G.name+b;return a.createElement(Re.ContactPointReceiverTitleRow,{key:ue,name:G.name,type:D.type,description:(0,Ne.aM)(D),pluginMetadata:H})})));var Se=e(88575),Ie=e(16504),we=e(88323),f=e(29158),X=e(72093),y=e(72109),ge=e(3704);const ve=500;function W({alertManager:i,options:D,onSelectContactPoint:b,refetchReceivers:G}){const H=(0,x.of)(Ce),{control:ue,watch:q,trigger:z}=(0,t.xW)(),Be=q(`contactPoints.${i}.selectedContactPoint`),We=D.find(ne=>ne.value.name===Be)?.value,Ue=We?{value:We,label:We.name}:{value:void 0,label:""},c=1e3,[v,T]=(0,a.useState)(!1),U=ne=>new Promise(ae=>setTimeout(ae,ne)),F=(0,a.useCallback)(()=>{Be&&z(`contactPoints.${i}.selectedContactPoint`,{shouldFocus:!0})},[i,Be,z]),B=()=>{T(!0),Promise.all([G(),U(c)]).finally(()=>{T(!1),F()})};return(0,a.useEffect)(()=>{F()},[F]),a.createElement(S.B,{direction:"column"},a.createElement(S.B,{direction:"row",alignItems:"center"},a.createElement(Se.D,{label:"Contact point"},a.createElement(Ie.e,{render:({field:{onChange:ne,ref:ae,...pe},fieldState:{error:de}})=>a.createElement(a.Fragment,null,a.createElement("div",{className:H.contactPointsSelector},a.createElement(we.l6,{virtualized:D.length>ve,"aria-label":"Contact point",defaultValue:Ue,onChange:(he,ke)=>{ne(he?.value?.name),b(he?.value)},options:D,width:50}),a.createElement("div",{className:H.contactPointsInfo},a.createElement(f.K,{name:"sync",onClick:B,"aria-label":"Refresh contact points",tooltip:"Refresh contact points list",className:(0,n.cx)(H.refreshButton,{[H.loading]:v})}),a.createElement(se,null))),de&&a.createElement(X.P,null,de?.message)),rules:{required:{value:!0,message:"Contact point is required."},validate:{contactPointExists:ne=>D.some(ae=>ae.value.name===ne)?!0:`Contact point ${Be} does not exist.`}},control:ue,name:`contactPoints.${i}.selectedContactPoint`}))))}function se(){const i="/alerting/notifications";return a.createElement(y.Y,{external:!0,href:(0,ge.c)(i),"aria-label":"View or create contact points"},"View or create contact points")}const Ce=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 ce=e(82843),be=e(98164),Te=e(79657),Me=e(99903);function Je({alertManager:i}){const D=(0,x.of)(Me.t),{control:b,formState:{errors:G}}=(0,t.xW)(),H=Z();return a.createElement(Se.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(Ie.e,{render:({field:{onChange:ue,ref:q,...z}})=>a.createElement(we.KF,{"aria-label":"Mute timings",...z,className:D.input,onChange:Be=>ue((0,Te.ie)(Be)),options:H,placeholder:"Select mute timings..."}),control:b,name:`contactPoints.${i}.muteTimeIntervals`}))}function Z(){return ce.m.endpoints.getMuteTimingList.useQuery(void 0,{refetchOnFocus:!0,refetchOnReconnect:!0,selectFromResult:D=>({...D,mutetimings:D.data?D.data.map(b=>({value:b.name,label:b.name,description:b.time_intervals.map(G=>(0,be.LF)(G)).join(", AND ")})):[]})}).mutetimings}var te=e(14186),j=e(15292),le=e(5342),E=e(27835),M=e(33915),C=e(97174);function R({alertManager:i}){const D=(0,x.of)(Me.t),{register:b,formState:{errors:G},getValues:H}=(0,t.xW)();return a.createElement(a.Fragment,null,a.createElement(Se.D,{label:C.G.groupWait.label,description:C.G.groupWait.description,invalid:!!G.contactPoints?.[i]?.groupWaitValue,error:G.contactPoints?.[i]?.groupWaitValue?.message},a.createElement(M.V,{...b(`contactPoints.${i}.groupWaitValue`,{validate:Te.hH}),"aria-label":C.G.groupWait.ariaLabel,className:D.promDurationInput,placeholder:E.H.group_wait})),a.createElement(Se.D,{label:C.G.groupInterval.label,description:C.G.groupInterval.description,invalid:!!G.contactPoints?.[i]?.groupIntervalValue,error:G.contactPoints?.[i]?.groupIntervalValue?.message},a.createElement(M.V,{...b(`contactPoints.${i}.groupIntervalValue`,{validate:Te.hH}),"aria-label":C.G.groupInterval.ariaLabel,className:D.promDurationInput,placeholder:E.H.group_interval})),a.createElement(Se.D,{label:C.G.repeatInterval.label,description:C.G.repeatInterval.description,invalid:!!G.contactPoints?.[i]?.repeatIntervalValue,error:G.contactPoints?.[i]?.repeatIntervalValue?.message},a.createElement(M.V,{...b(`contactPoints.${i}.repeatIntervalValue`,{validate:ue=>{const q=H(`contactPoints.${i}.repeatIntervalValue`);return(0,Te.DY)(ue,q)}}),"aria-label":C.G.repeatInterval.ariaLabel,className:D.promDurationInput,placeholder:E.H.repeat_interval})))}const O=["grafana_folder","alertname"],ie={groupWaitValue:E.H.group_wait,groupIntervalValue:E.H.group_interval,repeatIntervalValue:E.H.repeat_interval},me="...",fe=({alertManager:i})=>{const D=(0,x.of)(Me.t),{control:b,watch:G,register:H,setValue:ue,formState:{errors:q}}=(0,t.xW)(),[z,Be]=(0,a.useState)((0,Te.gY)([])),{groupIntervalValue:We,groupWaitValue:Ue,repeatIntervalValue:c}=ie,v=G(`contactPoints.${i}.overrideGrouping`),T=G(`contactPoints.${i}.overrideTimings`),U=G(`contactPoints.${i}.groupBy`)?.length??0,F=(0,x.of)(Xe);return(0,a.useEffect)(()=>{v&&U===0&&ue(`contactPoints.${i}.groupBy`,O)},[v,ue,i,U]),a.createElement(S.B,{direction:"column"},a.createElement(S.B,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between"},a.createElement(te.I,{label:"Override grouping",transparent:!0,className:F.switchElement},a.createElement(j.d,{id:"override-grouping-toggle",...H(`contactPoints.${i}.overrideGrouping`)})),!v&&a.createElement(g.E,{variant:"body",color:"secondary"},"Grouping: ",a.createElement("strong",null,O.join(", ")))),v&&a.createElement(Se.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.",...H(`contactPoints.${i}.groupBy`),invalid:!!q.contactPoints?.[i]?.groupBy,className:F.optionalContent},a.createElement(Ie.e,{rules:{validate:B=>!B||B.length===0?"At least one group by option is required.":B.length===1&&B[0]===me||O.every(ae=>B.includes(ae))?!0:`Group by must include ${O.join(", ")}`},render:({field:{onChange:B,ref:ne,...ae},fieldState:{error:pe}})=>a.createElement(a.Fragment,null,a.createElement(we.KF,{"aria-label":"Group by",...ae,allowCustomValue:!0,className:D.input,onCreateOption:de=>{Be(he=>[...he,(0,Te.Mk)(de)]),ue(`contactPoints.${i}.groupBy`,[...ae.value,de])},onChange:de=>B((0,Te.ie)(de)),options:[...Te.Yl,...z],components:{MultiValueRemove(de){const{data:he}=de;return he.isFixed?null:(0,le.p)(de)}}}),pe&&a.createElement(X.P,null,pe.message)),name:`contactPoints.${i}.groupBy`,control:b})),a.createElement(S.B,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between"},a.createElement(te.I,{label:"Override timings",transparent:!0,className:F.switchElement},a.createElement(j.d,{id:"override-timings-toggle",...H(`contactPoints.${i}.overrideTimings`)})),!T&&a.createElement(g.E,{variant:"body",color:"secondary"},"Group wait: ",a.createElement("strong",null,Ue,", "),"Group interval: ",a.createElement("strong",null,We,", "),"Repeat interval: ",a.createElement("strong",null,c))),T&&a.createElement("div",{className:F.optionalContent},a.createElement(R,{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 Ke({alertManager:i}){const D=(0,x.of)(nt),b=i.name,{isLoading:G,error:H,contactPoints:ue,refetchReceivers:q}=(0,ye.dK)({includePoliciesCount:!1,receiverStatusPollingInterval:0}),[z,Be]=(0,a.useState)(),We=T=>{Be(T)},{watch:Ue}=(0,t.xW)(),c=Ue(`contactPoints.${b}.overrideGrouping`)||Ue(`contactPoints.${b}.overrideTimings`)||Ue(`contactPoints.${b}.muteTimeIntervals`)?.length>0,v=ue.map(T=>{const U=T?.grafana_managed_receiver_configs,F=a.createElement(Re.ContactPointReceiverSummary,{receivers:U??[]});return{label:T.name,value:T,description:F}});return H?a.createElement(Fe.F,{title:"Failed to fetch contact points",severity:"error"}):G?a.createElement(Oe._,{text:"Loading..."}):a.createElement(S.B,{direction:"column"},a.createElement(S.B,{direction:"row",alignItems:"center"},a.createElement("div",{className:D.firstAlertManagerLine}),a.createElement("div",{className:D.alertManagerName},"Alert manager:",a.createElement("img",{src:i.imgUrl,alt:"Alert manager logo",className:D.img}),b),a.createElement("div",{className:D.secondAlertManagerLine})),a.createElement(S.B,{direction:"row",gap:1,alignItems:"center"},a.createElement(W,{alertManager:b,options:v,onSelectContactPoint:We,refetchReceivers:q})),z?.grafana_managed_receiver_configs&&a.createElement(De,{receivers:z.grafana_managed_receiver_configs}),a.createElement("div",{className:D.routingSection},a.createElement(ze.M,{label:"Muting, grouping and timings (optional)",isOpen:c,className:D.collapsableSection},a.createElement(S.B,{direction:"column",gap:1},a.createElement(Je,{alertManager:b}),a.createElement(fe,{alertManager:b})))))}const nt=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 it(){const{getValues:i}=(0,t.xW)(),D=i("contactPoints"),H=(0,ee.sq)("notification").availableInternalDataSources.filter(q=>q.hasConfigurationAPI);return(0,a.useMemo)(()=>H.map(q=>{const z=D?D[q.name]:void 0;return{alertManager:q,selectedContactPoint:z?.selectedContactPoint??"",routeSettings:{muteTimeIntervals:z?.muteTimeIntervals??[],overrideGrouping:z?.overrideGrouping??!1,groupBy:z?.groupBy??[],overrideTimings:z?.overrideTimings??!1,groupWaitValue:z?.groupWaitValue??"",groupIntervalValue:z?.groupIntervalValue??"",repeatIntervalValue:z?.repeatIntervalValue??""}}}),[H,D]).map((q,z)=>a.createElement(oe.b9,{accessType:"notification",alertmanagerSourceName:q.alertManager.name,key:q.alertManager.name+z},a.createElement(Ke,{alertManager:q.alertManager})))}var at=e(2543),Ve=e(55852),Et=e(79938),yt=e(87286);const ht=(0,a.lazy)(()=>e.e(9711).then(e.bind(e,39711))),xt=({alertQueries:i,customLabels:D,condition:b,folder:G,alertName:H,alertUid:ue})=>{const q=(0,x.of)(ct),z=!b||!G,Be=Et.hK.endpoints.preview,[We,{data:Ue=[],isLoading:c,isUninitialized:v}]=Be.useMutation(),T=(0,at.compact)(Ue.flatMap(ne=>ne?.labels)),U=()=>{!G||!b||We({alertQueries:i,condition:b,customLabels:D,folder:G,alertName:H,alertUid:ue})},F=(0,ee.cy)("notification"),B=F.length===1;return a.createElement(yt.B,{direction:"column"},a.createElement("div",{className:q.routePreviewHeaderRow},a.createElement("div",{className:q.previewHeader},a.createElement(g.E,{element:"h5"},"Alert instance routing preview"),c&&v&&a.createElement(g.E,{color:"secondary",variant:"bodySmall"},"Loading..."),v?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:q.button},a.createElement(Ve.$n,{icon:"sync",variant:"secondary",type:"button",onClick:U,disabled:z},"Preview routing"))),!c&&!v&&T.length>0&&a.createElement(a.Suspense,{fallback:a.createElement(Oe._,{text:"Loading preview..."})},F.map(ne=>a.createElement(ht,{alertManagerSource:ne,potentialInstances:T,onlyOneAM:B,key:ne.name}))))},ct=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 St=(i=>(i.NotificationPolicy="notification policy",i.ContactPoint="contact point",i))(St||{});const It=({alertUid:i})=>{const{watch:D}=(0,t.xW)(),b=(0,x.of)(dt),[G]=D(["type","labels","queries","condition","folder","name","manualRouting"]),H=D("dataSourceName")??ee.hY,ue=J.$.featureToggles.alertingSimplifiedRouting??!1,q=G===P.Z.grafana,z=G===P.Z.grafana&&ue;return a.createElement(Q.P,{stepNo:4,title:G===P.Z.cloudRecording?"Add labels":"Configure labels and notifications",description:a.createElement(S.B,{direction:"row",gap:.5,alignItems:"baseline"},G===P.Z.cloudRecording?a.createElement(g.E,{variant:"bodySmall",color:"secondary"},"Add labels to help you better manage your recording rules"):z&&a.createElement(g.E,{variant:"bodySmall",color:"secondary"},"Select who should receive a notification when an alert rule fires.")),fullWidth:!0},a.createElement(N.A,{dataSourceName:H}),z&&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.")),z?a.createElement(Rt,{alertUid:i}):q?a.createElement(ut,{alertUid:i}):null)};function Rt({alertUid:i}){const{watch:D,setValue:b}=(0,t.xW)(),G=(0,x.of)(dt),[H]=D(["manualRouting"]),ue=[{label:"Select contact point",value:"contact point"},{label:"Use notification policy",value:"notification policy"}],q=z=>{b("manualRouting",z==="contact point")};return a.createElement(S.B,{direction:"column"},a.createElement(S.B,{direction:"column"},a.createElement(A.z,{options:ue,value:H?"contact point":"notification policy",onChange:q,className:G.routingOptions})),a.createElement(Pt,{manualRouting:H}),H?a.createElement(it,null):a.createElement(ut,{alertUid:i}))}function ut({alertUid:i}){const{watch:D}=(0,t.xW)(),[b,G,H,ue,q]=D(["labels","queries","condition","folder","name","manualRouting"]);return a.createElement(xt,{alertQueries:G,customLabels:b,condition:H,folder:ue,alertName:q,alertUid:i})}function Ct(){return a.createElement($.G,{contentText:a.createElement(S.B,{gap:1,direction:"column"},a.createElement(S.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(h.I,{name:"external-link-alt"})))),a.createElement(S.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(h.I,{name:"external-link-alt"}))))),title:"Notification routing"})}function _e(){return a.createElement($.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 Pt=({manualRouting:i})=>{const D=(0,x.of)(dt);return a.createElement("div",{className:D.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(_e,null):a.createElement(Ct,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:(Qe,k,e)=>{e.d(k,{L:()=>Je,g:()=>Z});var n=e(32196),a=e(96540),t=e(49785),J=e(1604),x=e(46662),S=e(72724),g=e(39070),A=e(19347),h=e(40845),P=e(66864),ee=e(55852),N=e(42418),$=e(62467),Q=e(81160),oe=e(66847),Fe=e(1005),Oe=e(72495),ze=e(89667),Re=e(43127),ye=e(17172),Ne=e(12091);function De(E){return"expr"in E}function Se(E){return"grafana_condition"in E}var Ie=e(86590),we=e(57220);function f(E){if(De(E))return X(E,E.dataSourceUid,Ie.Z.cloudAlerting);if(Se(E))return X(E,we.hY,Ie.Z.grafana);throw new Error("unsupported preview rule request")}function X(E,M,C){return(0,Oe.k)({whileLoading:y(C),source:(0,ye.AI)().fetch({method:"POST",url:`/api/v1/rule/test/${M}`,data:E}).pipe((0,Q.T)(({data:R})=>y(C,{state:g.Gu.Done,series:R.instances.map(ze.or)})),(0,oe.W)(R=>(0,$.of)(y(C,{state:g.Gu.Error,error:(0,Ne.u)(R)}))),(0,Fe.u)())})}function y(E,M={}){return{ruleType:E,data:{state:g.Gu.Loading,series:[],timeRange:(0,Re.E2)(),...M}}}var ge=e(36135),ve=e(70713),W=e(1173),se=e(24308),Ce=e(52622),ce=e(88467);function be(E){const{preview:M}=E,C=(0,h.of)(Te),R={defaults:{},overrides:[{matcher:{id:W.Ct.byName,options:"Info"},properties:[{id:"custom.displayMode",value:Ce.ob.JSONView}]}]};if(!M)return null;const{data:O,ruleType:ie}=M;return O.state===g.Gu.Loading?a.createElement("div",{className:C.container},a.createElement("span",null,"Loading preview...")):O.state===g.Gu.Error?a.createElement("div",{className:C.container},O.error?(0,ce.CZ)(O.error):"Failed to preview alert rule"):a.createElement("div",{className:C.container},a.createElement("span",null,"Preview based on the result of running the query, for this moment."," ",ie===Ie.Z.grafana?"Configuration for `no data` and `error handling` is not applied.":null),a.createElement("div",{className:C.table},a.createElement(ve.Ay,null,({width:me,height:fe})=>a.createElement("div",{style:{width:`${me}px`,height:`${fe}px`}},a.createElement(se.m,{title:"",width:me,height:fe,pluginId:"table",data:O,fieldConfig:R})))))}function Te(E){return{container:(0,n.css)` margin: ${E.spacing(2)} 0; `,table:(0,n.css)` flex: 1 1 auto; height: 135px; margin-top: ${E.spacing(2)}; border: 1px solid ${E.colors.border.medium}; border-radius: ${E.shape.radius.default}; `}}const Me=["type","dataSourceName","condition","queries","expression"];function Je(){const E=(0,h.of)(le),[M,C]=Z(),{watch:R}=(0,t.xW)(),[O,ie,me]=R(["type","condition","queries"]),{allDataSourcesAvailable:fe}=(0,ge.g)(me);if(O===Ie.Z.cloudRecording||O===Ie.Z.cloudAlerting)return null;const Xe=!!ie&&fe;return a.createElement("div",{className:E.container},a.createElement(P.Gy,null,fe&&a.createElement(ee.$n,{disabled:!Xe,type:"button",variant:"primary",onClick:C},"Preview alerts"),!fe&&a.createElement(N.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(be,{preview:M}))}function Z(){const[E,M]=(0,a.useState)(),{getValues:C}=(0,t.xW)(),R=(0,J.A)(),O=(0,a.useCallback)(()=>{const ie=C(Me),me=te(ie);f(me).pipe((0,x.v)(fe=>!j(fe),!0)).subscribe(fe=>{R()&&M(fe)})},[C,R]);return[E,O]}function te(E){const[M,C,R,O,ie]=E,me=(0,A.l)().getInstanceSettings(C);if(!me)throw new Error(`Cannot find data source settings for ${C}`);switch(M){case Ie.Z.cloudAlerting:return{dataSourceUid:me.uid,dataSourceName:C,expr:ie};case Ie.Z.grafana:return{grafana_condition:{condition:R,data:O,now:(0,S.M7)(Date.now())}};default:throw new Error(`Alert type ${M} not supported by preview.`)}}function j(E){switch(E.data.state){case g.Gu.Done:case g.Gu.Error:return!0;default:return!1}}function le(E){return{container:(0,n.css)` margin-top: ${E.spacing(2)}; max-width: ${E.breakpoints.values.xxl}px; `}}},890:(Qe,k,e)=>{e.d(k,{N:()=>un});var n=e(32196),a=e(2543),t=e(96540),J=e(49785),x=e(43127),S=e(13544),g=e(19347),A=e(32264),h=e(40845),P=e(67061),ee=e(88575),N=e(16504),$=e(56034),Q=e(55852),oe=e(42418),Fe=e(38138),Oe=e(64539),ze=e(83122),Re=e(14578),ye=e(94753),Ne=e(69437),De=e(66718),Se=e(80348),Ie=e(57220),we=e(61410);function f(){const o=(0,we.$)(r=>r.dataSources);return Object.values(o).map(r=>r.result).filter(r=>!!r?.rulerConfig).map(r=>(0,Ie.oh)(r.name)).filter(r=>!!r)}var X=e(23770),y=e(86590),ge=e(63066),ve=e(16817),W=e(39070),se=e(76287),Ce=e(41987),ce=e(64149),be=e(75214),Te=e(30423),Me=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
[o[re].name,o[re].values[u]]),_=o[r]?.values?.[u],V=o[l]?.values?.[u];(0,Me.s1)(_)&&p.push({state:_,info:V,labels:Object.fromEntries(w)})}return{instances:p}}function Z({preview:o}){const s=(0,h.of)(te),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,be.M4)(m);return t.createElement("tr",{key:p},t.createElement("td",null,t.createElement(Te.C,{state:l})),t.createElement("td",null,t.createElement(ce.L,{tags:u,className:s.tagList})),t.createElement("td",null,d&&t.createElement($.m,{content:d},t.createElement(Re.I,{name:"info-circle"}))))})))}const te=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 j=e(67986);const le=({value:o,onChange:s,dataSourceName:r,showPreviewAlertsButton:l=!0})=>{const d=(0,h.of)(E),{mapToValue:m,mapToQuery:p}=M(r),u=p({refId:"A",hide:!1},o),{error:w,loading:_,value:V}=(0,ve.A)(()=>(0,g.l)().get(r),[r]),re=(0,t.useCallback)(je=>{s(m(je))},[s,m]),[$e,K]=(0,j.g)(),L=async()=>{K()};if(_||V?.name!==r)return null;const Ge=(0,g.l)().getInstanceSettings(r);if(w||!V||!V?.components?.QueryEditor||!Ge){const je=w?.message||"Data source plugin does not export any Query Editor component";return t.createElement("div",null,"Could not load query editor due to: ",je)}const Le=$e?.data.state===W.Gu.Done,Ze=V?.components?.QueryEditor,qe=$e?.data?.series?.find(je=>je.name==="evaluation results"),lt=qe&&qe.fields.some(je=>je.values.length>0);return t.createElement(t.Fragment,null,t.createElement(se.p,{instanceSettings:Ge},t.createElement(Ze,{query:u,queries:[u],app:Ce.Jk.CloudAlerting,onChange:re,onRunQuery:a.noop,datasource:V})),l&&t.createElement("div",{className:d.preview},t.createElement(Q.$n,{type:"button",onClick:L,disabled:$e?.data.state===W.Gu.Loading},"Preview alerts"),Le&&!lt&&t.createElement(oe.F,{title:"Alerts preview",severity:"info",className:d.previewAlert},"There are no firing alerts for your query."),lt&&t.createElement(Z,{preview:qe})))},E=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 M(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 C=e(56528),R=e(7921);const O=({condition:o,onSetCondition:s,queries:r,panelData:l,onUpdateRefId:d,onRemoveExpression:m,onUpdateExpressionType:p,onUpdateQueryExpression:u})=>{const w=(0,t.useMemo)(()=>r.reduce((V,re)=>(0,Ne.f)(re.model)?V.concat(re.model):V,[]),[r]),_=(0,h.of)(ie);return t.createElement("div",{className:_.wrapper},w.map(V=>{const re=l[V.refId],$e=o===V.refId,K=re?(0,R.lb)(re):void 0,L=re?(0,R.yr)(re.series):void 0;return t.createElement(C.r4,{key:V.refId,isAlertCondition:$e,data:re,error:K,warning:L,queries:r,query:V,onSetCondition:s,onRemoveExpression:m,onUpdateRefId:d,onUpdateExpressionType:p,onChangeQuery:u})}))},ie=o=>({wrapper:(0,n.css)` display: flex; gap: ${o.spacing(2)}; align-content: stretch; flex-wrap: wrap; `});var me=e(64100),fe=e(75494),Xe=e(65879),Ke=e(10860),nt=e(7788),it=e(31193),at=e(14186),Ve=e(10354),Et=e(65160),yt=e(25968),ht=e(81875),xt=e(47232),ct=e(60782),St=e(3759);const It=({query:o,queryOptions:s,onChangeTimeRange:r,onChangeQueryOptions:l,index:d})=>{const m=(0,h.of)(Rt),[p,u]=(0,t.useState)(!1),w=o.relativeTimeRange?(0,Xe.relativeToTimeRange)(o.relativeTimeRange):void 0;return t.createElement(t.Fragment,null,t.createElement(ct.G,{content:t.createElement("div",{className:m.queryOptions},r&&t.createElement(at.I,{label:"Time Range"},t.createElement(St.N,{timeRange:o.relativeTimeRange??(0,x.Cn)(),onChange:_=>r(_,d)})),t.createElement(i,{options:s,onChange:_=>l(_,d)}),t.createElement(D,{options:s,onChange:_=>l(_,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,xt.KQ)(w?.from).locale("en").fromNow(!0)),s.maxDataPoints&&t.createElement("span",null,", MD = ",s.maxDataPoints),s.minInterval&&t.createElement("span",null,", Min. Interval = ",s.minInterval)))},Rt=o=>{const s=(0,Q.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 Ct=43200,_e="1s",Pt=({data:o,error:s,dsSettings:r,index:l,onChangeDataSource:d,onChangeQuery:m,onChangeTimeRange:p,onRunQueries:u,onRemoveQuery:w,onDuplicateQuery:_,query:V,queries:re,thresholds:$e,thresholdsType:K,onChangeThreshold:L,condition:Ge,onSetCondition:Le,onChangeQueryOptions:Ze})=>{const qe=(0,h.of)(b),[lt,je]=(0,t.useState)(),Bt={...lt?.getDefaultQuery?lt.getDefaultQuery(Ce.Jk.UnifiedAlerting):{},...(0,a.cloneDeep)(V.model)};function tt(){const Pe=(0,h.of)(b);return t.createElement("div",{className:Pe.dsTooltip},t.createElement($.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 wt({query:Pe,error:gt,index:Yt}){const He={maxDataPoints:Pe.model.maxDataPoints,minInterval:Pe.model.intervalMs?(0,yt.yl)(Pe.model.intervalMs):void 0},Jt={maxDataPoints:He.maxDataPoints,minInterval:He.minInterval},Xt=Ge===Pe.refId;return t.createElement(P.B,{direction:"row",alignItems:"center",gap:1},t.createElement(tt,null),t.createElement(It,{onChangeTimeRange:p,query:Pe,queryOptions:Jt,onChangeQueryOptions:Ze,index:Yt}),t.createElement(ht.a,{onSetCondition:()=>Le(Pe.refId),isCondition:Xt}))}const Kt=o.state!==W.Gu.NotStarted,Ht=(0,a.cloneDeep)(re.map(Pe=>Pe.model));return t.createElement(P.B,{direction:"column",gap:.5},t.createElement("div",{className:qe.wrapper},t.createElement(Et.c,{alerting:!0,collapsable:!1,dataSource:r,onDataSourceLoaded:je,onChangeDataSource:Pe=>d(Pe,l),id:V.refId,index:l,key:V.refId,data:o,query:Bt,onChange:Pe=>m(Pe,l),onRemoveQuery:w,onAddQuery:()=>_((0,a.cloneDeep)(V)),onRunQuery:u,queries:Ht,renderHeaderExtras:()=>t.createElement(wt,{query:V,index:l,error:s}),app:Ce.Jk.UnifiedAlerting,hideDisableQuery:!0})),Kt&&t.createElement(ut.j,{data:o,thresholds:$e,thresholdsType:K,onThresholdsChange:L?Pe=>L(Pe,l):void 0}))},dt=({children:o})=>{const s=(0,h.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(at.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(Ve.p,{type:"number",width:10,placeholder:Ct.toString(),spellCheck:!1,onBlur:l,defaultValue:r}))}function D({options:o,onChange:s}){const r=o.minInterval??"",l=d=>{const m=d.target.value;m!==r&&s({...o,minInterval:m})};return t.createElement(at.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(Ve.p,{type:"text",width:10,placeholder:_e,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,w)=>{if(w!==l)return u;const _=this.getDataSourceSettings(u);return r.type===_?.type?H(u,r):ue(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),[w]=u.splice(m,1);u.splice(p,0,w),d(u)},this.getDataSourceSettings=r=>(0,g.l)().getInstanceSettings(r.datasourceUid)}render(){const{queries:s,expressions:r,condition:l}=this.props,d=(0,R.an)([...s,...r],l);return t.createElement(fe.JY,{onDragEnd:this.onDragEnd},t.createElement(fe.gL,{droppableId:"alerting-queries",direction:"vertical"},m=>t.createElement("div",{ref:m.innerRef,...m.droppableProps},t.createElement(P.B,{direction:"column"},s.map((p,u)=>{const w=this.props.condition===p.refId,_=this.props.data?.[p.refId]??{series:[],state:W.Gu.NotStarted},V=this.getDataSourceSettings(p);let re;return _&&w?re=(0,R.zy)(_):_&&(re=(0,R.lb)(_)),V?t.createElement(Pt,{index:u,key:p.refId,dsSettings:V,data:_,error:re,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(q,{key:`${p.refId}-${u}`,index:u,model:p.model,onUpdateDatasource:()=>{const $e=(0,it.tR)().getInstanceSettings(null);$e&&this.onChangeDataSource($e,u)},onRemoveQuery:()=>{this.onRemoveQuery(p)}})}),m.placeholder))))}}function H(o,s){return{...o,model:{...(0,a.omit)(o.model,"datasource"),datasource:{type:s.type,uid:s.uid}},datasourceUid:s.uid}}function ue(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 q=({index:o,onUpdateDatasource:s,onRemoveQuery:r,model:l})=>{const d=l.refId,[m,p]=(0,t.useState)(!1),u=()=>{p(_=>!_)},w=()=>{s()};return t.createElement(dt,null,t.createElement(nt.u,{title:d,draggable:!0,index:o,id:d,isOpen:!0,collapsable:!1},t.createElement(Ke.Z,null,t.createElement(Ke.Z.Heading,null,"This datasource has been removed"),t.createElement(Ke.Z.Description,null,"The datasource for this query was not found, it was either removed or is not installed correctly."),t.createElement(Ke.Z.Figure,null,t.createElement(Re.I,{name:"question-circle"})),t.createElement(Ke.Z.Actions,null,t.createElement(Q.$n,{key:"update",variant:"secondary",onClick:w},"Update datasource"),t.createElement(Q.$n,{key:"remove",variant:"destructive",onClick:r},"Remove query")),t.createElement(Ke.Z.SecondaryActions,null,t.createElement(Q.$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))))))},z=({queries:o,expressions:s,panelData:r,onRunQueries:l,onChangeQueries:d,onDuplicateQuery:m,condition:p,onSetCondition:u})=>{const w=(0,h.of)(Be);return t.createElement("div",{className:w.container},t.createElement(G,{data:r,queries:o,expressions:s,onRunQueries:l,onQueriesChange:d,onDuplicateQuery:m,condition:p,onSetCondition:u}))},Be=o=>({container:(0,n.css)` background-color: ${o.colors.background.primary}; height: 100%; `});var We=e(74856);const Ue=({queries:o,onChangeQuery:s,runQueries:r,panelData:l,dataSourceName:d})=>{const[m,p]=(0,t.useState)({series:[],state:W.Gu.NotStarted,timeRange:(0,We.jG)().timeRange()}),u=(0,h.of)(c);(0,t.useEffect)(()=>{p(l?.[o[0]?.refId])},[l,o]);const{error:w,loading:_,value:V}=(0,ve.A)(()=>(0,g.l)().get(d),[d]),re=L=>{const Ge=o[0],Le=(0,g.l)().getInstanceSettings(d)?.uid;if(!(0,ge.Bu)(L)||!Le)return;const Ze=L.expr,qe={...Ge,...L,datasourceUid:Le,expr:Ze,model:{expr:Ze,datasource:L.datasource,refId:L.refId,editorMode:L.editorMode,instant:!!L.instant,range:!!L.range,legendFormat:L.legendFormat}};s([qe])};if(_||V?.name!==d)return null;const $e=(0,g.l)().getInstanceSettings(d);if(w||!V||!V?.components?.QueryEditor||!$e){const L=w?.message||"Data source plugin does not export any Query Editor component";return t.createElement("div",null,"Could not load query editor due to: ",L)}const K=V.components.QueryEditor;return t.createElement(t.Fragment,null,o.length&&t.createElement(K,{query:o[0],queries:o,app:Ce.Jk.UnifiedAlerting,onChange:re,onRunQuery:r,datasource:V}),m&&t.createElement("div",{className:u.vizWrapper},t.createElement(ut.j,{data:m})))},c=o=>({vizWrapper:(0,n.css)` margin: ${o.spacing(1,0)}; `});var v=e(271),T=e(51612),U=e(99140);function F({value:o,disabled:s,...r}){const l=f(),{loading:d=!0}=(0,ve.A)(()=>(0,U.JD)((0,X.wE)()),[U.JD]),m=(0,t.useCallback)(p=>!!l.find(({id:u})=>u===p.id),[l]);return t.createElement(T.s,{disabled:d||s,noDefault:!0,alerting:!0,filter:m,current:o,...r})}const B=({disabled:o,onChangeCloudDatasource:s})=>{const{control:r,formState:{errors:l},setValue:d,watch:m}=(0,J.xW)(),p=(0,h.of)(ne),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(ee.D,{className:p.formInput,label:o?"Data source":"Select data source",error:l.dataSourceName?.message,invalid:!!l.dataSourceName?.message},t.createElement(N.e,{render:({field:{onChange:w,ref:_,...V}})=>t.createElement(F,{...V,disabled:o,onChange:re=>{d("expression",""),w(re?.name??null),s(re?.uid??null)}}),name:"dataSourceName",control:r,rules:{required:{value:!0,message:"Please select a data source"}}}))))},ne=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 ae=e(94354),pe=e(10096);function de(){const o=pe.TP.hasPermission(Se.AccessControlAction.AlertingRuleCreate),s=pe.TP.hasPermission(Se.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 he=o=>o.filter(s=>s.datasourceUid!==De.Uj).length===1,ke=({queries:o,ruleFormType:s,rulesSourcesWithRuler:r})=>{const l=de(),d=he(o),m=o[0]?.datasourceUid??"",p=s===y.Z.cloudRecording,u=!p&&d&&r.some(K=>K.uid===m),w=!p,_=l.enabledRuleTypes.includes(y.Z.grafana),V=l.enabledRuleTypes.includes(y.Z.cloudAlerting),re=s===y.Z.cloudAlerting&&_&&w,$e=s===y.Z.grafana&&u&&V&&u;return re||$e};function Ae({editingExistingRule:o,rulesSourcesWithRuler:s,queries:r,onClickSwitch:l}){const{getValues:d}=(0,J.xW)(),[m]=d(["type"]),p=ke({queries:r,ruleFormType:m,rulesSourcesWithRuler:s}),u=[{label:"Grafana-managed",value:y.Z.grafana},{label:"Data source-managed",value:y.Z.cloudAlerting}],w=p?[]:[y.Z.cloudAlerting];return t.createElement(P.B,{direction:"column",gap:1,alignItems:"flex-start"},t.createElement(P.B,{direction:"column",gap:0},t.createElement(ye.E,{variant:"h5"},"Rule type"),t.createElement(P.B,{direction:"row",gap:.5,alignItems:"baseline"},t.createElement(ye.E,{variant:"bodySmall",color:"secondary"},"Select where the alert rule will be managed."),t.createElement(me.G,{contentText:t.createElement(t.Fragment,null,t.createElement(ye.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(ye.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(ae.z,{options:u,disabled:o,disabledOptions:w,value:m,onChange:l}),o&&t.createElement(ye.E,{color:"secondary"},"The alert rule type cannot be changed for an existing rule."),!o&&t.createElement(t.Fragment,null,p?t.createElement(ye.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(ye.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 xe=e(30038),vt=e(21969);const Dt=o=>{try{return JSON.stringify(o),!1}catch{return!0}},Tt=(o,s)=>{if(Dt(o))return null;if(s.datasourceUid!==De.Uj)return s;{const r=o.find(l=>l.refId===s.model.expression);return r?Tt(o,r):null}};var At=e(53478),ft=e(76942);const et=(o,s)=>{const r=o.find(d=>d.refId===s);return r&&Tt(o,r)},Ut={queries:[]},$t=(0,xe.VP)("duplicateQuery"),rt=(0,xe.VP)("addNewDataQuery"),pt=(0,xe.VP)("setDataQueries"),Ot=(0,xe.VP)("addNewExpression"),Gt=(0,xe.VP)("removeExpression"),Nt=(0,xe.VP)("removeExpressions"),Lt=(0,xe.VP)("addExpressions"),Mt=(0,xe.VP)("updateExpression"),Qt=(0,xe.VP)("updateExpressionRefId"),bt=(0,xe.VP)("rewireExpressions"),Ft=(0,xe.VP)("updateExpressionType"),Ee=(0,xe.VP)("updateExpressionTimeRange"),Zt=(0,xe.VP)("updateMaxDataPoints"),ot=(0,xe.VP)("updateMinInterval"),st=(0,xe.VP)("setRecordingRulesQueries"),on=(0,xe.vy)(Ut,o=>{o.addCase($t,(s,{payload:r})=>{s.queries=jt(s.queries,r)}).addCase(rt,s=>{const r=(0,Ie.y9)();r&&(s.queries=jt(s.queries,{datasourceUid:r.uid,model:{refId:"",datasource:{type:r.type,uid:r.uid}}}))}).addCase(pt,(s,{payload:r})=>{const l=s.queries.filter(d=>(0,Ne.f)(d.model));s.queries=[...r,...l]}).addCase(st,(s,{payload:r})=>{const l=r.recordingRuleQueries[0],d={...l,expr:r.expression,model:l?.model};s.queries=[d]}).addCase(Zt,(s,r)=>{s.queries=s.queries.map(l=>l.refId===r.payload.refId?{...l,model:{...l.model,maxDataPoints:r.payload.maxDataPoints}}:l)}).addCase(ot,(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(Ot,(s,{payload:r})=>{s.queries=jt(s.queries,{datasourceUid:De.Uj,model:At.Ex.newQuery({type:r,conditions:[{...ft.P,query:{params:[]}}],expression:""})})}).addCase(Gt,(s,{payload:r})=>{s.queries=s.queries.filter(l=>l.refId!==r)}).addCase(Nt,s=>{s.queries=s.queries.filter(r=>!(0,Ne.f)(r.model))}).addCase(Lt,(s,{payload:r})=>{s.queries=[...s.queries,...r]}).addCase(Mt,(s,{payload:r})=>{s.queries=s.queries.map(l=>{const d=et(s.queries,r.expression),m=d?d.relativeTimeRange:(0,x.Cn)();return l.refId===r.refId&&(l.model=r,r.type===De.Tz.resample&&(l.relativeTimeRange=m)),l})}).addCase(Ee,s=>{const r=s.queries.map(l=>{if(l.datasourceUid===De.Uj){const d=et(s.queries,l.model.expression),m=d?d.relativeTimeRange:(0,x.Cn)();l.relativeTimeRange=m}return l});s.queries=r}).addCase(Qt,(s,{payload:r})=>{const{newRefId:l,oldRefId:d}=r;if((0,R.xb)(s.queries,l))return;const p=(0,R.I3)(s.queries,d,l);s.queries=p.map(u=>u.refId===d?{...u,refId:l,model:{...u.model,refId:l}}:u)}).addCase(bt,(s,{payload:r})=>{s.queries=(0,R.I3)(s.queries,r.oldRefId,r.newRefId)}).addCase(Ft,(s,r)=>{s.queries=s.queries.map(l=>l.refId===r.payload.refId?{...l,model:{...At.Ex.newQuery({type:r.payload.type,conditions:[{...ft.P,query:{params:[]}}],expression:""}),refId:r.payload.refId}}:l)})}),jt=(o,s)=>{const r=(0,vt.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,Ne.f)(o))return(0,x.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(w=>{s(w)}),()=>{u.destroy()}},[]);const l=(0,t.useCallback)(()=>{s({})},[]),d=(0,t.useCallback)(()=>{r.current.cancel()},[]),m=(0,t.useCallback)((u,w)=>{r.current.run(u,w)},[]),p=(0,t.useMemo)(()=>Object.values(o).some(u=>u.state===W.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,J.xW)(),{queryPreviewData:u,runQueries:w,cancelQueries:_,isPreviewLoading:V,clearPreviewData:re}=cn(),$e={queries:l("queries")},[{queries:K},L]=(0,t.useReducer)(on,$e),[Ge,Le,Ze]=d(["type","condition","dataSourceName"]),qe=Ge===y.Z.grafana,lt=Ge===y.Z.cloudRecording,je=Ge===y.Z.cloudAlerting,zt=(0,Se.useDispatch)();(0,t.useEffect)(()=>{zt((0,X.wE)())},[zt]);const Bt=f(),tt=(0,t.useCallback)(I=>{je||w(l("queries"),I||(l("condition")??""))},[je,w,l]);(0,t.useEffect)(()=>{r("queries",K,{shouldValidate:!1})},[K,w,r]);const wt=(0,Ie.y9)()===void 0,Kt=(0,t.useMemo)(()=>K.filter(I=>!(0,Ne.f)(I.model)),[K]),Ht=(0,t.useMemo)(()=>K.filter(I=>(0,Ne.f)(I.model)),[K]),Pe=K.length===0;(0,t.useEffect)(()=>{if(!qe)return;const I=l("condition");if(!I)return;const Y=u[I];if(!Y)return;const Ye=(0,R.lb)(Y)??(0,R.zy)(Y);s(Ye?.message||"")},[u,l,s,qe]);const gt=(0,t.useCallback)(I=>{I&&(tt(I),r("condition",I))},[tt,r]),Yt=(0,t.useCallback)((I,Y)=>{(0,R.xb)(K,Y)||(L(Qt({oldRefId:I,newRefId:Y})),Le===I&>(Y))},[Le,K,gt]),He=fn(),Jt=(0,t.useCallback)(I=>{const Ye=l("queries").filter(Cn=>(0,Ne.f)(Cn.model));r("queries",[...I,...Ye],{shouldValidate:!1}),He(I),L(pt(I)),L(Ee());const[Wt,rn]=(0,R.YG)(K,I);Wt&&rn&&L(bt({oldRefId:Wt,newRefId:rn}))},[K,He,l,r]),Xt=(0,t.useCallback)(I=>{const Y=I[0];if(!(0,ge.Bu)(Y.model))return;const Ye=Y.model.expr;r("queries",I,{shouldValidate:!1}),He(I),L(st({recordingRuleQueries:I,expression:Ye})),tt()},[tt,r,He]),kt=Bt[0];(0,t.useEffect)(()=>{if(re(),Ge===y.Z.cloudRecording){const I=l("expression");if(!kt)return;const Ye={refId:"A",datasourceUid:o&&(0,g.l)().getInstanceSettings(Ze)?.uid||kt.uid,queryType:"",relativeTimeRange:(0,x.Cn)(),expr:I,instant:!0,model:{refId:"A",hide:!1,expr:I}};L(st({recordingRuleQueries:[Ye],expression:I}))}},[Ge,kt,o,l,Ze,re]);const pn=(0,t.useCallback)(I=>{L($t(I))},[]);(0,t.useEffect)(()=>{if(!(0,R.xb)(K,Le)){const I=K.at(-1)?.refId??null;gt(I)}},[Le,K,gt]);const gn=(0,t.useCallback)(I=>{L(Ot(I))},[L]),vn=(0,h.of)(mn),En=(0,t.useCallback)(I=>{const Y=(0,a.cloneDeep)(K);Y[0].datasourceUid=I,r("queries",Y,{shouldValidate:!1}),He(Y),L(pt(Y))},[K,r,He,L]),yn=I=>{const Y=(0,a.cloneDeep)(K);if(Y[0].model)if((0,ge.Bu)(Y[0].model))Y[0].model.expr=I;else{const Ye={...(0,a.cloneDeep)(Y[0].model),expr:I};Y[0].model=Ye}r("queries",Y,{shouldValidate:!1}),He(Y),L(pt(Y)),tt()},_t=(0,t.useCallback)(()=>L(Nt()),[L]),en=(0,t.useCallback)(I=>L(Lt(I)),[L]),[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 Y=(0,g.l)().getInstanceSettings(K[0].datasourceUid)?.name;Y&&r("dataSourceName",Y),He(K);const Ye=K.filter(Wt=>Wt.datasourceUid===De.Uj);hn(Ye),_t(),xn(Le)}},[l,r,Vt.length,tn,qt,He,K,_t,Le]),{sectionTitle:Sn,helpLabel:an,helpContent:In,helpLink:Rn}=mt[Ge??y.Z.grafana];return t.createElement(v.P,{stepNo:2,title:Sn,description:t.createElement(P.B,{direction:"row",gap:.5,alignItems:"center"},t.createElement(ye.E,{variant:"bodySmall",color:"secondary"},an),t.createElement(me.G,{contentText:In,externalLink:Rn,linkText:"Read more on our documentation website",title:an}))},(Ge===y.Z.cloudRecording||Ge===y.Z.cloudAlerting)&&t.createElement(B,{onChangeCloudDatasource:En,disabled:o}),lt&&Ze&&t.createElement(ee.D,{error:m.expression?.message,invalid:!!m.expression?.message},t.createElement(Ue,{dataSourceName:Ze,queries:K,runQueries:tt,onChangeQuery:Xt,panelData:u})),je&&Ze&&t.createElement(P.B,{direction:"column"},t.createElement(ee.D,{error:m.expression?.message,invalid:!!m.expression?.message},t.createElement(N.e,{name:"expression",render:({field:{ref:I,...Y}})=>t.createElement(le,{...Y,dataSourceName:Ze,showPreviewAlertsButton:!lt,onChange:yn}),control:p,rules:{required:{value:!0,message:"A valid expression is required"}}})),t.createElement(Ae,{editingExistingRule:o,queries:K,rulesSourcesWithRuler:Bt,onClickSwitch:nn})),qe&&t.createElement(P.B,{direction:"column"},t.createElement(z,{queries:Kt,expressions:Ht,onRunQueries:()=>tt(),onChangeQueries:Jt,onDuplicateQuery:pn,panelData:u,condition:Le,onSetCondition:gt}),t.createElement($.m,{content:"You appear to have no compatible data sources",show:wt},t.createElement(Q.$n,{type:"button",onClick:()=>{L(rt())},variant:"secondary","data-testid":S.Tp.components.QueryTab.addQuery,disabled:wt,className:vn.addQueryButton},"Add query")),t.createElement(Ae,{editingExistingRule:o,rulesSourcesWithRuler:Bt,queries:K,onClickSwitch:nn}),t.createElement(P.B,{direction:"column",gap:0},t.createElement(ye.E,{element:"h5"},"Expressions"),t.createElement(ye.E,{variant:"bodySmall",color:"secondary"},"Manipulate data returned from queries with math and other operations.")),t.createElement(O,{queries:K,panelData:u,condition:Le,onSetCondition:gt,onRemoveExpression:I=>{L(Gt(I))},onUpdateRefId:Yt,onUpdateExpressionType:(I,Y)=>{L(Ft({refId:I,type:Y}))},onUpdateQueryExpression:I=>{L(Mt(I))}}),t.createElement(P.B,{direction:"row"},A.$.expressionsEnabled&&t.createElement(dn,{onClickType:gn}),V&&t.createElement(Q.$n,{icon:"spinner",type:"button",variant:"destructive",onClick:_},"Cancel"),!V&&t.createElement(Q.$n,{icon:"sync",type:"button",onClick:()=>tt(),disabled:Pe},"Preview")),Pe&&t.createElement(oe.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(Fe.W,null,De.uQ.map(r=>t.createElement($.m,{key:r.value,content:r.description??"",placement:"right"},t.createElement(Oe.D,{key:r.value,onClick:()=>o(r.value??De.Tz.math),label:r.label??""}))));return t.createElement(ze.m,{overlay:s},t.createElement(Q.$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,J.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,ge.Bu)(r.model)){const d=r.model.expr;o("expression",d)}}}},55776:(Qe,k,e)=>{e.d(k,{h:()=>x});var n=e(40672),a=e(32264),t=e(25027),J=e(39964);function x(g){const A={returnTo:g},[h]=(0,J.l)(),P=h.get("returnTo");if(!P)return A;const ee=n.sQ.sanitizeUrl(P),N=`${window.location.origin}/${a.$.appSubUrl}`,$=S(ee,N);if(!$)return(0,t.FF)("Malformed returnTo parameter",{returnTo:P}),A;const{protocol:Q,origin:oe,pathname:Fe,search:Oe}=$;return["http:","https:"].includes(Q)===!1||oe!==window.location.origin?((0,t.FF)("Malformed returnTo parameter",{returnTo:P}),A):{returnTo:`${Fe}${Oe}`}}function S(g,A){try{return new URL(g,A)}catch{return null}}},79657:(Qe,k,e)=>{e.d(k,{DY:()=>we,Mk:()=>Re,QM:()=>Fe,Rg:()=>N,SJ:()=>ze,YE:()=>Oe,Yl:()=>Q,eb:()=>Ne,gY:()=>ye,hH:()=>Se,ie:()=>De});var n=e(2543),a=e.n(n),t=e(60021),J=e(98164),x=e(57220),S=e(32642),g=e(67332),A=e(25968);const h=(f,X)=>Object.entries(f??{}).reduce((y,[ge,ve])=>[...y,{name:ge,value:ve,operator:X?t.ho.regex:t.ho.equal}],[]),P=f=>f.value,ee=f=>(f??[]).map(P),N={name:"",value:"",operator:t.ho.equal},$=["grafana_folder","alertname"],Q=[{label:"grafana_folder",value:"grafana_folder",isFixed:!0},{label:"alertname",value:"alertname",isFixed:!0},{label:"Disable (...)",value:"..."}],oe={id:"",overrideGrouping:!1,groupBy:$,object_matchers:[],routes:[],continue:!1,receiver:"",overrideTimings:!1,groupWaitValue:"",groupIntervalValue:"",repeatIntervalValue:"",muteTimeIntervals:[]};function Fe(f){return{id:(0,n.uniqueId)("route-"),...f,routes:(f.routes??[]).map(Fe)}}const Oe=f=>{if(!f)return oe;const X="id"in f?f.id:(0,n.uniqueId)("route-");if(Object.keys(f).length===0)return{...oe,id:X};const y=[];f.routes?.forEach(W=>{const se=Oe(W);y.push(se)});const ge=f.object_matchers?.map(W=>({name:W[0],operator:W[1],value:W[2]}))??[],ve=f.matchers?.map(W=>(0,J.MU)((0,S.qR)(W))).map(({name:W,operator:se,value:Ce})=>({name:W,operator:se,value:(0,S.Ig)(Ce)}))??[];return{id:X,object_matchers:[...ve,...ge,...h(f.match,!1),...h(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 ge=(0,g.eM)(X.id??"",y),{overrideGrouping:ve,groupBy:W,overrideTimings:se,groupWaitValue:Ce,groupIntervalValue:ce,repeatIntervalValue:be,receiver:Te}=X,Me=void 0,Je=ve?W:Me,te=se&&Ce?Ce:Me,le=se&&ce?ce:Me,M=se&&be?be:Me,C=X.object_matchers?.filter(ie=>ie.name&&ie.operator&&ie.value!==null&&ie.value!==void 0).map(({name:ie,operator:me,value:fe})=>[ie,me,fe]),R=X.routes?.map(ie=>ze(f,ie,y)),O={...ge??{},continue:X.continue,group_by:Je,object_matchers:C,match:void 0,match_re:void 0,group_wait:te,group_interval:le,repeat_interval:M,routes:R,mute_time_intervals:X.muteTimeIntervals,receiver:Te};return f!==x.hY?(O.matchers=X.object_matchers?.map(({name:ie,operator:me,value:fe})=>`${ie}${me}${(0,S.ot)(fe)}`),O.object_matchers=void 0):(O.object_matchers=(0,S.J$)(O),O.matchers=void 0),X.receiver&&(O.receiver=X.receiver),O},Re=f=>({label:f,value:f}),ye=f=>(f??[]).map(Re),Ne=f=>f===null?null:f?P(f)??"":"",De=f=>f?ee(f):[];function Se(f){return!f||f.length===0?!0:(0,A.TN)(f)||"Invalid duration format. Must be {number}{time_unit}"}const Ie=f=>f.map(X=>{const[y,ge,ve]=X;return`${y}${ge}${ve}`}),we=(f,X="")=>{if(f.length===0)return!0;const y=Se(f),ge=Se(X);if(y!==!0)return y;if(ge!==!0)return ge;const ve=(0,A.ge)(f),W=(0,A.ge)(X);return W!==0&&ve
{e.d(k,{V:()=>n});function n(a,t){const J=a.replace(/\(copy( [0-9]+)?\)$/,"").trim();let x=`${J} (copy)`;for(let S=2;t.includes(x);S++)x=`${J} (copy ${S})`;return x}},67332:(Qe,k,e)=>{e.d(k,{AB:()=>J,AS:()=>x,eM:()=>g,pq:()=>S});var n=e(2543),a=e.n(n),t=e(79657);const J=(A,h,P)=>{if(!g(h.id??"",P))throw new Error(`No such route with ID '${h.id}'`);function N($){let Q=$;if($.id===h.id){const oe=(0,t.SJ)(A,h,P);Q=(0,n.omit)({...$,...oe},"id")}return(0,n.omit)({...Q,routes:$.routes?.map(N)},"id")}return N(P)},x=(A,h)=>{if(A.id===h.id)throw new Error("You cant remove the root policy");function P(ee){return(0,n.omit)({...ee,routes:ee.routes?.reduce((N=[],$)=>($.id===A.id||N.push(P($)),N),[])},"id")}return P(h)},S=(A,h,P,ee)=>{const N=(0,t.SJ)(A,h,ee);function $(oe){return oe.id===P.id?{...oe,routes:oe.routes?.concat(N)}:{...oe,routes:oe.routes?.map($)}}function Q(oe){return(0,n.omit)({...oe,routes:oe.routes?.map(Q)},"id")}return Q($(ee))};function g(A,h){return h.id===A?h:h.routes?.find(P=>g(A,P))}},87286:(Qe,k,e)=>{e.d(k,{B:()=>J});var n=e(32196),a=e(96540),t=e(40845);function J(S){const g=(0,t.of)(x,S);return a.createElement("div",{className:g.root},S.children)}const x=(S,g)=>({root:(0,n.css)({display:"flex",flexDirection:g.direction??"row",flexWrap:g.wrap??!0?"wrap":void 0,alignItems:g.alignItems,gap:S.spacing(g.gap??2),flexGrow:g.flexGrow})})}}]); //# sourceMappingURL=AlertingRuleForm.66bb5b2724b31ae6a5a4.js.map