"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5372],{53734:(Oe,Z,e)=>{e.d(Z,{HE:()=>f,l4:()=>M,wW:()=>b});var n=e(42913),a=e.n(n),t=e(63957),w=e.n(t),y=e(85960),C=e(76176);let u=null;const A=new WeakMap,R=te=>{const Ee=ye=>{const ue=u||ThemeContext;return React.createElement(ue.Consumer,null,me=>React.createElement(te,{...ye,theme:me.v1}))};return Ee.displayName=`WithTheme(${te.displayName})`,hoistNonReactStatics(Ee,te),Ee},f=te=>{const Ee=ye=>{const ue=u||C.N;return y.createElement(ue.Consumer,null,me=>y.createElement(te,{...ye,theme:me}))};return Ee.displayName=`WithTheme(${te.displayName})`,a()(Ee,te),Ee};function z(){return useContext(u||ThemeContext).v1}function M(){return(0,y.useContext)(u||C.N)}function F(te){const Ee=z();let ye=A.get(te);return ye||(ye=stylesFactory(te),A.set(te,ye)),ye(Ee)}function b(te,...Ee){const ye=M();let ue=A.get(te);return ue||(ue=w()(te,{maxSize:10}),A.set(te,ue)),ue(ye,...Ee)}const se=te=>(u=React.createContext(te),()=>{u=null})},84157:(Oe,Z,e)=>{e.r(Z),e.d(Z,{default:()=>at});var n=e(85960),a=e(81445),t=e(8958),w=e(95162),y=e(66681),C=e(49199),u=e(47257),A=e(29165);function R({title:d,children:P}){return n.createElement(C.b,{className:(0,u.wW)(f).warning,severity:"warning",title:d},n.createElement("p",null,P),n.createElement(A.Qj,{href:"alerting/list"},"To rule list"))}const f=d=>({warning:(0,y.css)`
    margin: ${d.spacing(4)};
  `});var z=e(56375),M=e(91),F=e(79468),b=e(53285),se=e(30694),te=e(16088),Ee=e(90857),ye=e(74042),ue=e(75682),me=e(50263),h=e(13086),$=e(77980),ne=e(37870),j=e(93991),le=e(49683),c=e(95500),T=e(763),E=e(34456),B=e(92746),_=e(5970),N=e(20304),de=e(30422),Y=e(38884),Pe=e(60956),$e=e(14411),Be=e(27908),ge=e(29657),Te=e(23694);const S=({alertUid:d,exportFormat:P,onClose:pe})=>{const{currentData:he="",isFetching:xe}=$e.alertRuleApi.endpoints.exportRules.useQuery({ruleUid:d,format:P}),ce=`${d}-${new Date().getTime()}`;return xe?n.createElement(F.u,{text:"Loading...."}):n.createElement(Be.u,{format:P,textDefinition:he,downloadFileName:ce,onClose:pe})},K=({onClose:d,alertUid:P})=>{const[pe,he]=(0,n.useState)("yaml");return n.createElement(ge.i,{activeTab:pe,onTabChange:he,onClose:d,formatProviders:Object.values(Te.uN)},n.createElement(S,{alertUid:P,exportFormat:pe,onClose:d}))};var G=e(92237),ae=e(55822),x=e(20519),H=e(24956),L=e(96130),I=e(27436),J=e(47689),ie=e(90943);const Se=({rulesSourceName:d})=>{const{control:P,watch:pe,formState:{errors:he},setValue:xe}=(0,b.Gc)(),ce=(0,u.wW)(Ce),be=(0,B._)(Ne=>Ne.rulerRules),Ae=(0,w.useDispatch)();(0,n.useEffect)(()=>{Ae((0,_.UR)({rulesSourceName:d}))},[d,Ae]);const Me=be[d]?.result,We=pe("namespace"),Ge=(0,n.useMemo)(()=>Me?Object.keys(Me).map(Ne=>({label:Ne,value:Ne})):[],[Me]),rt=(0,n.useMemo)(()=>We&&Me?.[We]?.map(Ne=>({label:Ne.name,value:Ne.name}))||[],[We,Me]);return n.createElement("div",{className:ce.flexRow},n.createElement(x.g,{"data-testid":"namespace-picker",label:"Namespace",error:he.namespace?.message,invalid:!!he.namespace?.message},n.createElement(L.g,{render:({field:{onChange:Ne,ref:pt,...De}})=>n.createElement(I.LT,{...De,allowCustomValue:!0,className:ce.input,onChange:St=>{xe("group",""),Ne(St.value)},options:Ge,width:42}),name:"namespace",control:P,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:ie.p0}}})),n.createElement(x.g,{"data-testid":"group-picker",label:"Group",error:he.group?.message,invalid:!!he.group?.message},n.createElement(L.g,{render:({field:{ref:Ne,...pt}})=>n.createElement(I.LT,{...pt,allowCustomValue:!0,options:rt,width:42,onChange:De=>{xe("group",De.value??"")},className:ce.input}),name:"group",control:P,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:ie.p0}}})))},Ce=d=>({flexRow:(0,y.css)`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;

    & > * + * {
      margin-left: ${d.spacing(3)};
    }
  `,input:(0,y.css)`
    width: 330px !important;
  `});var ke=e(69655),Ke=e(78985);const Et=()=>{const d=(0,u.wW)(mt),{register:P,control:pe,watch:he,formState:{errors:xe}}=(0,b.Gc)(),ce=he("type"),be=he("dataSourceName");return n.createElement(Ke.z,{stepNo:3,title:"Set evaluation behavior"},n.createElement(x.g,{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:d.flexRow},n.createElement(x.g,{invalid:!!xe.forTime?.message,error:xe.forTime?.message,className:d.inlineField},n.createElement(H.I,{...P("forTime",{pattern:{value:/^\d+$/,message:"Must be a positive integer."}}),width:8})),n.createElement(L.g,{name:"forTimeUnit",render:({field:{onChange:Ae,ref:Me,...We}})=>n.createElement(I.Ph,{...We,options:J.qr,onChange:Ge=>Ae(Ge?.value),width:15,className:d.timeUnit}),control:pe}))),ce===N.$.cloudAlerting&&be&&n.createElement(Se,{rulesSourceName:be}),n.createElement(ke.Y,null))},mt=d=>({inlineField:(0,y.css)`
    margin-bottom: 0;
  `,flexRow:(0,y.css)`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
  `,timeUnit:(0,y.css)`
    margin-left: ${d.spacing(.5)};
  `});var lt=e(8944),gt=e(46350);function Ue(){const{watch:d}=(0,b.Gc)(),P=d("dataSourceName");return P?n.createElement(Ke.z,{stepNo:3,title:"Add namespace and group",description:"Select the Namespace and Group for your recording rule."},n.createElement(Se,{rulesSourceName:P})):null}var Ct=e(47831),Pt=e(1765);const ht=({existing:d,prefill:P})=>{const pe=(0,u.wW)(ee),he=(0,w.useDispatch)(),xe=(0,j.iG)(),[ce]=(0,T.K)(),[be,Ae]=(0,n.useState)(!1),[Me,We]=(0,n.useState)(d?.group.interval??Y.EB),Ge=(0,se.UO)(),rt=(0,ie.KP)(Ge.type),Ne=Ge.id,pt=ce.returnTo?String(ce.returnTo):"/alerting/list",[De,St]=(0,n.useState)(!1),Dt=(0,n.useMemo)(()=>d?(0,Y.eZ)(d):P?O(P):typeof ce.defaults=="string"?i(ce.defaults,rt):{...(0,Y.uZ)(),condition:"C",queries:(0,Y.s0)(),type:rt||N.$.grafana,evaluateEvery:Me},[d,P,ce,Me,rt]),It=(0,b.cI)({mode:"onSubmit",defaultValues:Dt,shouldFocusError:!0}),{handleSubmit:Tt,watch:Rt}=It,ot=Rt("type"),Vt=Rt("dataSourceName"),$t=!!(ot&&(ot===N.$.grafana||Vt)),ct=(0,B._)(Ie=>Ie.ruleForm.saveRule)||de.oq;(0,c.x)(Ie=>Ie.unifiedAlerting.ruleForm.saveRule=de.oq);const[xt,Lt]=(0,n.useState)(""),Wt=(Ie="")=>{Lt(Ie)},At=(Ie,Kt)=>{if(xt!==""){xe.error(xt);return}he((0,_.wy)({values:{...Dt,...Ie,annotations:Ie.annotations?.map(({key:ut,value:dt})=>({key:ut.trim(),value:dt.trim()})).filter(({key:ut,value:dt})=>!!ut&&!!dt)??[],labels:Ie.labels?.map(({key:ut,value:dt})=>({key:ut.trim(),value:dt.trim()})).filter(({key:ut})=>!!ut)??[]},existing:d,redirectOnSave:Kt?pt:void 0,initialAlertRuleName:Dt.name,evaluateEvery:Me}))},wt=()=>{if(d){const Ie=Pe.Zk(d.ruleSourceName,d.namespace,d.group.name,d.rule);he((0,_.hS)(Ie,{navigateTo:"/alerting/list"}))}},Mt=Ie=>{d||(0,E.Z0)({grafana_version:Ee.config.buildInfo.version,org_id:le.Vt.user.orgId,user_id:le.Vt.user.id,error:Object.keys(Ie).toString()}),xe.error("There are errors in the form. Please correct them and try again!")},bt=()=>{(0,E.PN)(E.z7.cancelSavingAlertRule)},Nt=Rt("evaluateEvery");(0,n.useEffect)(()=>We(Nt),[Nt]);const Gt=n.createElement(ye.Lh,{height:"auto",justify:"flex-end"},d&&n.createElement(A.zx,{variant:"primary",type:"button",size:"sm",onClick:Tt(Ie=>At(Ie,!1),Mt),disabled:ct.loading},ct.loading&&n.createElement(ue.$,{className:pe.buttonSpinner,inline:!0}),"Save rule"),n.createElement(A.zx,{variant:"primary",type:"button",size:"sm",onClick:Tt(Ie=>At(Ie,!0),Mt),disabled:ct.loading},ct.loading&&n.createElement(ue.$,{className:pe.buttonSpinner,inline:!0}),"Save rule and exit"),n.createElement(te.Link,{to:pt},n.createElement(A.zx,{variant:"secondary",disabled:ct.loading,type:"button",onClick:bt,size:"sm"},"Cancel")),d?n.createElement(A.zx,{fill:"outline",variant:"destructive",type:"button",onClick:()=>St(!0),size:"sm"},"Delete"):null,d&&yt(Rt)&&n.createElement(A.zx,{variant:"secondary",type:"button",onClick:()=>Ae(!0),disabled:ct.loading,size:"sm"},"Edit YAML"));return n.createElement(b.RV,{...It},n.createElement(ne.A,{actions:Gt}),n.createElement("form",{onSubmit:Ie=>Ie.preventDefault(),className:pe.form},n.createElement("div",{className:pe.contentOuter},n.createElement(me.$,{autoHeightMin:"100%",hideHorizontalTrack:!0},n.createElement(h.K,{direction:"column",gap:3},n.createElement(G.n,null),n.createElement(Pt.V,{editingExistingRule:!!d,onDataChange:Wt}),$t&&n.createElement(n.Fragment,null,ot===N.$.grafana&&n.createElement(lt.w,{evaluateEvery:Me,setEvaluateEvery:We,existing:!!d,enableProvisionedGroups:!1}),ot===N.$.cloudAlerting&&n.createElement(Et,null),ot===N.$.cloudRecording&&n.createElement(Ue,null),ot!==N.$.cloudRecording&&n.createElement(ae.Z,null),n.createElement(gt.v,{alertUid:Ne})))))),De?n.createElement($.s,{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:wt,onDismiss:()=>St(!1)}):null,be?ot===N.$.grafana?n.createElement(K,{alertUid:Ne,onClose:()=>Ae(!1)}):n.createElement(Ct.CU,{onClose:()=>Ae(!1)}):null)},yt=d=>{const[P,pe]=d(["type","dataSourceName"]);return(P===N.$.cloudAlerting||P===N.$.cloudRecording)&&pe!==""};function i(d,P){let pe;try{pe=JSON.parse(d)}catch{return{...(0,Y.uZ)(),queries:(0,Y.s0)()}}return(0,Y.QN)({...(0,Y.uZ)(),...pe,annotations:(0,Y.TN)(pe.annotations??[]),queries:pe.queries??(0,Y.s0)(),type:P||N.$.grafana,evaluateEvery:Y.EB})}function O(d){return(0,Y.QN)({...(0,Y.uZ)(),...d})}const ee=d=>({buttonSpinner:(0,y.css)({marginRight:d.spacing(1)}),form:(0,y.css)({width:"100%",height:"100%",display:"flex",flexDirection:"column"}),contentOuter:(0,y.css)({background:d.colors.background.primary,overflow:"hidden",flex:1}),flexRow:(0,y.css)({display:"flex",flexDirection:"row",justifyContent:"flex-start"})});var U=e(77250),X=e(9001),Re=e(87873);function re({sourceRuleId:d}){const P=(0,w.useDispatch)(),{loading:pe,value:he,error:xe}=(0,a.Z)(()=>P((0,_.on)(d)).unwrap(),[d]);if(pe)return n.createElement(F.u,{text:"Loading the rule"});if(he){const ce=Ve(he),be=(0,Y.DQ)(ce);return n.createElement(ht,{prefill:be})}return xe?n.createElement(C.b,{title:"Error",severity:"error"},xe.message):n.createElement(C.b,{title:"Cannot copy the rule. The rule does not exist",buttonContent:"Go back to alert list",onRemove:()=>M.E1.replace((0,Re.u)("/alerting/list"))})}function oe(d,P){(0,X.Pc)(d)&&(d.grafana_alert.title=P),(0,X.cG)(d)&&(d.alert=P),(0,X.yF)(d)&&(d.record=P)}function Ve(d){const P=(0,z.cloneDeep)(d);return oe(P.rule,(0,U.G)((0,X.PW)(P.rule),P.group.rules.map(X.PW))),(0,X.Pc)(P.rule)&&(P.rule.grafana_alert.uid="",P.rule.grafana_alert.provenance&&(P.group={name:"",rules:P.group.rules})),P}var qe=e(49627);function _e({identifier:d,id:P}){(0,c.x)(Ge=>Ge.unifiedAlerting.ruleForm.existingRule=de.oq);const{loading:pe,result:he,error:xe,dispatched:ce}=(0,B._)(Ge=>Ge.ruleForm.existingRule),be=(0,w.useDispatch)(),{isEditable:Ae,loading:Me}=(0,qe.M)(Pe.s0(d),he?.rule),We=pe||Me;return(0,n.useEffect)(()=>{ce||be((0,_.on)(d))},[ce,be,d]),We||Ae===void 0?n.createElement(F.u,{text:"Loading rule..."}):xe?n.createElement(C.b,{severity:"error",title:"Failed to load rule"},xe.message):he?Ae===!1?n.createElement(R,{title:"Cannot edit rule"},"Sorry! You do not have permission to edit this rule."):n.createElement(ht,{existing:he}):n.createElement(R,{title:"Rule not found"},"Sorry! This rule does not exist.")}var Le=e(65892),ze=e(75636),je=e(44097);const Xe={icon:"bell",id:"alert-rule-view"},nt=(d,P)=>P==="recording"?d?{...Xe,id:"alert-rule-edit",text:"Edit recording rule"}:{...Xe,id:"alert-rule-add",text:"New recording rule"}:d?{...Xe,id:"alert-rule-edit",text:"Edit rule"}:{...Xe,id:"alert-rule-add",text:"New alert rule"},it=({match:d})=>{const P=(0,w.useDispatch)(),[pe]=(0,ze.j)(),{type:he}=d.params,xe=Pe.s4(d.params),ce=Pe.OA(xe,!0),be=pe.get("copyFrom")??void 0,Ae=Pe.OA(be),{loading:Me=!0}=(0,a.Z)(async()=>{ce&&await P((0,_.nw)({rulesSourceName:ce.ruleSourceName})),Ae&&await P((0,_.nw)({rulesSourceName:Ae.ruleSourceName}))},[P]),{canCreateGrafanaRules:We,canCreateCloudRules:Ge,canEditRules:rt}=(0,je.B)(),Ne=(0,n.useCallback)(()=>{if(!Me)return!ce&&!We&&!Ge?n.createElement(R,{title:"Cannot create rules"},"Sorry! You are not allowed to create rules."):ce&&!rt(ce.ruleSourceName)?n.createElement(R,{title:"Cannot edit rules"},"Sorry! You are not allowed to edit rules."):ce?n.createElement(_e,{key:xe,identifier:ce,id:xe}):Ae?n.createElement(re,{sourceRuleId:Ae}):n.createElement(ht,null)},[Ge,We,rt,Ae,xe,ce,Me]);return n.createElement(Le.J,{isLoading:Me,navId:"alert-list",pageNav:nt(ce,he)},Ne())},at=(0,t.Pf)(it,{style:"page"})},80448:(Oe,Z,e)=>{e.r(Z),e.d(Z,{default:()=>Te});var n=e(85960),a=e(81445),t=e(91),w=e(79468),y=e(49199),C=e(95162),u=e(5970),A=e(38884),R=e(60956),f=e(9001),z=e(87873),M=e(65892),F=e(53285),b=e(29165),se=e(50263),te=e(13086),Ee=e(93991),ye=e(763),ue=e(37870),me=e(14411),h=e(30264),$=e(94498),ne=e(76679),j=e(27908),le=e(29657),c=e(23694),T=e(92237),E=e(55822),B=e(8944),_=e(46350),N=e(1765);function de({ruleForm:S,alertUid:K}){const G=(0,F.cI)({mode:"onSubmit",defaultValues:S,shouldFocusError:!0}),[ae]=(0,ye.K)(),x=!!S,H=(0,Ee.iG)(),L=ae.returnTo?String(ae.returnTo):"/alerting/list",[I,J]=(0,n.useState)(void 0),[ie,Se]=(0,n.useState)(""),[Ce,ke]=(0,n.useState)(S?.evaluateEvery??A.EB),Ke=()=>{H.error("There are errors in the form. Please correct them and try again!")},Et=(Ue="")=>{Se(Ue)},mt=Ue=>{if(ie!==""){H.error(ie);return}J(Ue)},lt=(0,n.useCallback)(()=>{J(void 0)},[J]),gt=[n.createElement(b.Qj,{href:L,key:"cancel",size:"sm",variant:"secondary",onClick:()=>mt(void 0)},"Cancel"),n.createElement(b.zx,{key:"export-rule",size:"sm",onClick:G.handleSubmit(Ue=>mt(Ue),Ke)},"Export")];return n.createElement(n.Fragment,null,n.createElement(F.RV,{...G},n.createElement(ue.A,{actions:gt}),n.createElement("form",{onSubmit:Ue=>Ue.preventDefault()},n.createElement("div",null,n.createElement(se.$,{autoHeightMin:"100%",hideHorizontalTrack:!0},n.createElement(te.K,{direction:"column",gap:3},n.createElement(T.n,null),n.createElement(N.V,{editingExistingRule:x,onDataChange:Et}),n.createElement(B.w,{evaluateEvery:Ce,setEvaluateEvery:ke,existing:!!x,enableProvisionedGroups:!0}),n.createElement(E.Z,null),n.createElement(_.v,{alertUid:K}))))),I&&n.createElement(ge,{exportValues:I,onClose:lt,uid:K})))}const Y=(S,K)=>{const{dsFeatures:G}=(0,$.eq)(ne.GC),ae=G?.rulerConfig;return(0,a.Z)(async()=>ae?await(0,h.jJ)(ae,S,K):void 0,[ae,S,K])},Pe=(S,K,G)=>{const ae=(0,A.mI)(K),x={...ae,grafana_alert:{...ae.grafana_alert,uid:S}};if(G?.rules){let H=!1;const L=G.rules.map(I=>(0,f.Pc)(I)&&I.grafana_alert.uid===S?(H=!0,x):I);return H||L.push(x),{...G,rules:L}}else return{name:G?.name??"",rules:[x]}},$e=(S,K)=>{const G=Y(S.folder?.title??"",S.group);return{payload:(0,n.useMemo)(()=>Pe(K,S,G?.value),[K,G,S]),loadingGroup:G.loading}},Be=({exportFormat:S,exportValues:K,onClose:G,uid:ae})=>{const[x,H]=me.alertRuleApi.endpoints.exportModifiedRuleGroup.useMutation(),{loadingGroup:L,payload:I}=$e(K,ae),J=K.folder?.title??"";if((0,n.useEffect)(()=>{!L&&x({payload:I,format:S,nameSpace:J})},[J,S,I,x,L]),H.isLoading)return n.createElement(w.u,{text:"Loading...."});const ie=`modify-export-${I.name}-${ae}-${new Date().getTime()}`;return n.createElement(j.u,{format:S,textDefinition:H.data??"",downloadFileName:ie,onClose:G})},ge=n.memo(({onClose:S,exportValues:K,uid:G})=>{const[ae,x]=(0,n.useState)("yaml");return n.createElement(le.i,{title:"Export Group",activeTab:ae,onTabChange:x,onClose:S,formatProviders:Object.values(c.uN)},n.createElement(Be,{exportFormat:ae,onClose:S,exportValues:K,uid:G}))});ge.displayName="GrafanaRuleDesignExporter";function Te({match:S}){const K=(0,C.useDispatch)(),[G,ae]=(0,n.useState)(void 0);(0,n.useEffect)(()=>{const J=R.OA(S.params.id,!0);ae(J)},[S.params.id]);const{loading:x=!0}=(0,a.Z)(async()=>{G&&await K((0,u.nw)({rulesSourceName:G.ruleSourceName}))},[K,G]),{loading:H,value:L,error:I}=(0,a.Z)(async()=>{if(G)return await K((0,u.on)(G)).unwrap()},[G,x]);return G?H?n.createElement(w.u,{text:"Loading the rule"}):I?n.createElement(y.b,{title:"Cannot load modify export",severity:"error"},I.message):!L&&!H&&!x?n.createElement(M.J,{isLoading:H,navId:"alert-list",pageNav:{text:"Modify export"}},n.createElement(y.b,{title:"Cannot load the rule. The rule does not exist",buttonContent:"Go back to alert list",onRemove:()=>t.E1.replace((0,z.u)("/alerting/list"))})):L&&!(0,f.Pc)(L.rule)?n.createElement(M.J,{isLoading:H,navId:"alert-list",pageNav:{text:"Modify export"}},n.createElement(y.b,{title:"This rule is not a Grafana-managed alert rule",buttonContent:"Go back to alert list",onRemove:()=>t.E1.replace((0,z.u)("/alerting/list"))})):n.createElement(M.J,{isLoading:H,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."}},L&&n.createElement(de,{ruleForm:(0,A.eZ)(L),alertUid:S.params.id??""})):n.createElement("div",null,"Rule not found")}},18649:(Oe,Z,e)=>{e.d(Z,{N:()=>z});var n=e(85960),a=e(24956),t=e(97666),w=e(23595),y=e(66681),C=e(47257),u=e(36860);function A(){const M=(0,C.wW)(f);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:M.list},n.createElement("div",{className:M.header},n.createElement("div",null,"Symbol"),n.createElement("div",null,"Time unit"),n.createElement("div",null,"Example")),n.createElement(R,{unit:u.t.seconds,name:"seconds",example:"20s"}),n.createElement(R,{unit:u.t.minutes,name:"minutes",example:"10m"}),n.createElement(R,{unit:u.t.hours,name:"hours",example:"4h"}),n.createElement(R,{unit:u.t.days,name:"days",example:"3d"}),n.createElement(R,{unit:u.t.weeks,name:"weeks",example:"2w"}),n.createElement("div",{className:M.examples},n.createElement("div",null,"Multiple units combined"),n.createElement("code",null,"1m30s, 2h30m20s, 1w2d"))))}function R({unit:M,name:F,example:b}){const se=(0,C.wW)(f);return n.createElement(n.Fragment,null,n.createElement("div",{className:se.unit},M),n.createElement("div",null,F),n.createElement("code",null,b))}const f=M=>({unit:(0,y.css)`
    font-weight: ${M.typography.fontWeightBold};
  `,list:(0,y.css)`
    display: grid;
    grid-template-columns: max-content 1fr 2fr;
    gap: ${M.spacing(1,3)};
  `,header:(0,y.css)`
    display: contents;
    font-weight: ${M.typography.fontWeightBold};
  `,examples:(0,y.css)`
    display: contents;
    & > div {
      grid-column: 1 / span 2;
    }
  `}),z=n.forwardRef((M,F)=>n.createElement(a.I,{suffix:n.createElement(w.z,{content:n.createElement(A,null),disabled:!1},n.createElement(t.J,{name:"info-circle",size:"lg"})),...M,ref:F}));z.displayName="PromDurationInput"},6681:(Oe,Z,e)=>{e.d(Z,{S:()=>a});var n=e(66681);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};
    `})},76532:(Oe,Z,e)=>{e.d(Z,{j:()=>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"}}},49131:(Oe,Z,e)=>{e.d(Z,{M:()=>n});const n={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"}},92237:(Oe,Z,e)=>{e.d(Z,{n:()=>R});var n=e(85960),a=e(53285),t=e(40377),w=e(20519),y=e(24956),C=e(20304),u=e(78985);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_:]*$/},R=()=>{const{register:f,watch:z,formState:{errors:M}}=(0,a.Gc)(),F=z("type"),b=F===C.$.cloudRecording?"recording rule":"alert rule";return n.createElement(u.z,{stepNo:1,title:`Enter ${b} name`,description:n.createElement(t.x,{variant:"bodySmall",color:"secondary"},"Enter a name to identify your ",b,".")},n.createElement(w.g,{label:"Name",error:M?.name?.message,invalid:!!M.name?.message},n.createElement(y.I,{id:"name",width:35,...f("name",{required:{value:!0,message:"Must enter a name"},pattern:F===C.$.cloudRecording?A:void 0}),"aria-label":"name",placeholder:`Give your ${b} a name`})))}},46350:(Oe,Z,e)=>{e.d(Z,{v:()=>lt});var n=e(66681),a=e(85960),t=e(53285),w=e(90857),y=e(47257),C=e(13086),u=e(40377),A=e(5106),R=e(97666),f=e(20304),z=e(76679),M=e(124),F=e(21863),b=e(78985),se=e(84954),te=e(49199),Ee=e(79468),ye=e(96525),ue=e(59672),me=e(87873),h=e(7038),$=e(35970),ne=e(16859);const j=({receivers:i})=>a.createElement(C.K,{direction:"column",gap:0},a.createElement("div",null,i.map((O,ee)=>{const U=O[h.qs],X=O[h.pY],Re=U.name+ee;return a.createElement($.ContactPointReceiverTitleRow,{key:Re,name:U.name,type:O.type,description:(0,ne.tS)(O),pluginMetadata:X})})));var le=e(20519),c=e(96130),T=e(27436),E=e(74321);function B({alertManager:i,contactPoints:O,onSelectContactPoint:ee}){const U=(0,y.wW)(_),{register:X,control:Re,formState:{errors:re},watch:oe}=(0,t.Gc)(),Ve=O.map(Le=>{const ze=Le?.grafana_managed_receiver_configs,je=a.createElement($.ContactPointReceiverSummary,{receivers:ze??[]});return{label:Le.name,value:Le,description:je}}),qe=Ve.find(Le=>Le.value.name===oe(`contactPoints.${i}.selectedContactPoint`))?.value,_e=qe?{value:qe,label:qe.name}:void 0;return a.createElement(C.K,{direction:"column"},a.createElement(le.g,{label:"Contact point",...X(`contactPoints.${i}.selectedContactPoint`,{required:!0}),invalid:!!re.contactPoints?.[i]?.selectedContactPoint},a.createElement(c.g,{render:({field:{onChange:Le,ref:ze,...je},fieldState:{error:Xe}})=>a.createElement(a.Fragment,null,a.createElement("div",{className:U.contactPointsSelector},a.createElement(T.Ph,{...je,defaultValue:_e,"aria-label":"Contact point",onChange:(nt,it)=>{Le(nt?.value?.name),ee(nt?.value)},options:Ve,width:50})),Xe&&a.createElement(E.S,null,"Contact point is required.")),control:Re,name:`contactPoints.${i}.selectedContactPoint`})))}const _=i=>({contactPointsSelector:(0,n.css)({marginTop:i.spacing(1)})});var N=e(62208),de=e(71803),Y=e(6681);function Pe({alertManager:i}){const O=(0,y.wW)(Y.S),{control:ee,formState:{errors:U}}=(0,t.Gc)(),X=(0,N.s)();return a.createElement(le.g,{label:"Mute timings","data-testid":"am-mute-timing-select",description:"Add mute timing to policy",invalid:!!U.contactPoints?.[i]?.muteTimeIntervals},a.createElement(c.g,{render:({field:{onChange:Re,ref:re,...oe}})=>a.createElement(T.NU,{"aria-label":"Mute timings",...oe,className:O.input,onChange:Ve=>Re((0,de.bi)(Ve)),options:X}),control:ee,name:`contactPoints.${i}.muteTimeIntervals`}))}var $e=e(5999),Be=e(70335),ge=e(49131),Te=e(18649),S=e(76532);function K({alertManager:i}){const O=(0,y.wW)(Y.S),{register:ee,formState:{errors:U},getValues:X}=(0,t.Gc)();return a.createElement(a.Fragment,null,a.createElement(le.g,{label:S.j.groupWait.label,description:S.j.groupWait.description,invalid:!!U.contactPoints?.[i]?.groupWaitValue,error:U.contactPoints?.[i]?.groupWaitValue?.message},a.createElement(Te.N,{...ee(`contactPoints.${i}.groupWaitValue`,{validate:de.Oy}),"aria-label":S.j.groupWait.ariaLabel,className:O.promDurationInput,placeholder:ge.M.group_wait})),a.createElement(le.g,{label:S.j.groupInterval.label,description:S.j.groupInterval.description,invalid:!!U.contactPoints?.[i]?.groupIntervalValue,error:U.contactPoints?.[i]?.groupIntervalValue?.message},a.createElement(Te.N,{...ee(`contactPoints.${i}.groupIntervalValue`,{validate:de.Oy}),"aria-label":S.j.groupInterval.ariaLabel,className:O.promDurationInput,placeholder:ge.M.group_interval})),a.createElement(le.g,{label:S.j.repeatInterval.label,description:S.j.repeatInterval.description,invalid:!!U.contactPoints?.[i]?.repeatIntervalValue,error:U.contactPoints?.[i]?.repeatIntervalValue?.message},a.createElement(Te.N,{...ee(`contactPoints.${i}.repeatIntervalValue`,{validate:Re=>{const re=X(`contactPoints.${i}.repeatIntervalValue`);return(0,de.eP)(Re,re)}}),"aria-label":S.j.repeatInterval.ariaLabel,className:O.promDurationInput,placeholder:ge.M.repeat_interval})))}const G=({alertManager:i})=>{const O=(0,y.wW)(Y.S),{control:ee,watch:U,register:X,formState:{errors:Re}}=(0,t.Gc)(),[re,oe]=(0,a.useState)((0,de.eh)([])),{groupBy:Ve,groupIntervalValue:qe,groupWaitValue:_e,repeatIntervalValue:Le}=ae(),ze=U(`contactPoints.${i}.overrideGrouping`),je=U(`contactPoints.${i}.overrideTimings`);return a.createElement(C.K,{direction:"column"},a.createElement(C.K,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between"},a.createElement(le.g,{label:"Override grouping"},a.createElement($e.r,{id:"override-grouping-toggle",...X(`contactPoints.${i}.overrideGrouping`)})),!ze&&a.createElement(u.x,{variant:"body",color:"secondary"},"Grouping: ",a.createElement("strong",null,Ve.join(", ")))),ze&&a.createElement(le.g,{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.",...X(`contactPoints.${i}.groupBy`,{required:!0}),invalid:!!Re.contactPoints?.[i]?.groupBy},a.createElement(c.g,{render:({field:{onChange:Xe,ref:nt,...it},fieldState:{error:at}})=>a.createElement(a.Fragment,null,a.createElement(T.NU,{"aria-label":"Group by",...it,allowCustomValue:!0,className:O.input,onCreateOption:d=>{oe(P=>[...P,(0,de.T0)(d)]),setValue(`contactPoints.${i}.groupBy`,[...it.value,d])},onChange:d=>Xe((0,de.bi)(d)),options:[...de.dO,...re]}),at&&a.createElement(E.S,null,"At least one group by option is required")),name:`contactPoints.${i}.groupBy`,control:ee})),a.createElement(C.K,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between"},a.createElement(le.g,{label:"Override timings"},a.createElement($e.r,{id:"override-timings-toggle",...X(`contactPoints.${i}.overrideTimings`)})),!je&&a.createElement(u.x,{variant:"body",color:"secondary"},"Group wait: ",a.createElement("strong",null,_e,", "),"Group interval: ",a.createElement("strong",null,qe,", "),"Repeat interval: ",a.createElement("strong",null,Le))),je&&a.createElement(K,{alertManager:i}))};function ae(){const{selectedAlertmanager:i}=(0,se.ZA)(),{currentData:O}=(0,Be.W)(i),ee=O?.alertmanager_config;return a.useMemo(()=>({groupWaitValue:ge.M.group_wait,groupIntervalValue:ge.M.group_interval,repeatIntervalValue:ge.M.repeat_interval,groupBy:ee?.route?.group_by??[]}),[ee])}function x({alertManager:i}){const O=(0,y.wW)(L),ee=i.name,{isLoading:U,error:X,contactPoints:Re}=(0,h.ce)(),re=!0,[oe,Ve]=(0,a.useState)();return X?a.createElement(te.b,{title:"Failed to fetch contact points",severity:"error"}):U?a.createElement(Ee.u,{text:"Loading..."}):a.createElement(C.K,{direction:"column"},re&&a.createElement(C.K,{direction:"row",alignItems:"center"},a.createElement("div",{className:O.firstAlertManagerLine}),a.createElement("div",{className:O.alertManagerName},"Alert manager:",a.createElement("img",{src:i.imgUrl,alt:"Alert manager logo",className:O.img}),ee),a.createElement("div",{className:O.secondAlertManagerLine})),a.createElement(C.K,{direction:"row",gap:1,alignItems:"center"},a.createElement(B,{alertManager:ee,contactPoints:Re,onSelectContactPoint:Ve}),a.createElement(H,null)),oe?.grafana_managed_receiver_configs&&a.createElement(j,{receivers:oe.grafana_managed_receiver_configs}),a.createElement("div",{className:O.routingSection},a.createElement(ye.s,{label:"Muting, grouping and timings",isOpen:!1,className:O.collapsableSection},a.createElement(C.K,{direction:"column",gap:1},a.createElement(Pe,{alertManager:ee}),a.createElement(G,{alertManager:ee})))))}function H(){const i="/alerting/notifications";return a.createElement(ue.r,{target:"_blank",href:(0,me.u)(i),rel:"noopener","aria-label":"View alert rule"},a.createElement(C.K,{direction:"row",gap:1,alignItems:"center",justifyContent:"center"},a.createElement(u.x,{color:"secondary"},"To browse contact points and create new ones go to"),a.createElement(u.x,{color:"link"},"Contact points"),a.createElement(R.J,{name:"external-link-alt",size:"sm",color:"link"})))}const L=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 I(){const{getValues:i}=(0,t.Gc)(),O=i("contactPoints"),X=(0,z.LE)("notification").availableInternalDataSources.filter(re=>re.hasConfigurationAPI);return(0,a.useMemo)(()=>X.map(re=>{const oe=O?O[re.name]:void 0;return{alertManager:re,selectedContactPoint:oe?.selectedContactPoint??"",routeSettings:{muteTimeIntervals:oe?.muteTimeIntervals??[],overrideGrouping:oe?.overrideGrouping??!1,groupBy:oe?.groupBy??[],overrideTimings:oe?.overrideTimings??!1,groupWaitValue:oe?.groupWaitValue??"",groupIntervalValue:oe?.groupIntervalValue??"",repeatIntervalValue:oe?.repeatIntervalValue??""}}}),[X,O]).map((re,oe)=>a.createElement(se.h5,{accessType:"notification",alertmanagerSourceName:re.alertManager.name,key:re.alertManager.name+oe},a.createElement(x,{alertManager:re.alertManager})))}var J=e(56375),ie=e(29165),Se=e(14411),Ce=e(34554);const ke=(0,a.lazy)(()=>e.e(1816).then(e.bind(e,51816))),Ke=({alertQueries:i,customLabels:O,condition:ee,folder:U,alertName:X,alertUid:Re})=>{const re=(0,y.wW)(Et),oe=!ee||!U,Ve=Se.alertRuleApi.endpoints.preview,[qe,{data:_e=[],isLoading:Le,isUninitialized:ze}]=Ve.useMutation(),je=(0,J.compact)(_e.flatMap(at=>at?.labels)),Xe=()=>{!U||!ee||qe({alertQueries:i,condition:ee,customLabels:O,folder:U,alertName:X,alertUid:Re})},nt=(0,z.$$)("notification"),it=nt.length===1;return a.createElement(Ce.K,{direction:"column"},a.createElement("div",{className:re.routePreviewHeaderRow},a.createElement("div",{className:re.previewHeader},a.createElement(u.x,{element:"h4"},"Alert instance routing preview"),Le&&ze&&a.createElement(u.x,{color:"secondary",variant:"bodySmall"},"Loading..."),ze?a.createElement(u.x,{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(u.x,{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:re.button},a.createElement(ie.zx,{icon:"sync",variant:"secondary",type:"button",onClick:Xe,disabled:oe},"Preview routing"))),!Le&&!ze&&je.length>0&&a.createElement(a.Suspense,{fallback:a.createElement(Ee.u,{text:"Loading preview..."})},nt.map(at=>a.createElement(ke,{alertManagerSource:at,potentialInstances:je,onlyOneAM:it,key:at.name}))))},Et=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;
  `,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 mt=(i=>(i.NotificationPolicy="notification policy",i.ContactPoint="contact point",i))(mt||{});const lt=({alertUid:i})=>{const{watch:O}=(0,t.Gc)(),ee=(0,y.wW)(yt),[U]=O(["type","labels","queries","condition","folder","name","manualRouting"]),X=O("dataSourceName")??z.GC,Re=w.config.featureToggles.alertingSimplifiedRouting??!1,re=U===f.$.grafana,oe=U===f.$.grafana&&Re;return a.createElement(b.z,{stepNo:U===f.$.cloudRecording?4:5,title:U===f.$.cloudRecording?"Add labels":"Labels and notifications",description:a.createElement(C.K,{direction:"row",gap:.5,alignItems:"baseline"},U===f.$.cloudRecording?a.createElement(u.x,{variant:"bodySmall",color:"secondary"},"Add labels to help you better manage your recording rules"):oe&&a.createElement(u.x,{variant:"bodySmall",color:"secondary"},"Select who should receive a notification when an alert rule fires.")),fullWidth:!0},a.createElement(M.Z,{dataSourceName:X}),oe&&a.createElement("div",{className:ee.configureNotifications},a.createElement(u.x,{element:"h5"},"Configure notifications"),a.createElement(u.x,{variant:"bodySmall",color:"secondary"},"Select who should receive a notification when an alert rule fires.")),oe?a.createElement(gt,{alertUid:i}):re?a.createElement(Ue,{alertUid:i}):null)};function gt({alertUid:i}){const{watch:O,setValue:ee}=(0,t.Gc)(),U=(0,y.wW)(yt),[X]=O(["manualRouting"]),Re=[{label:"Manually select contact point",value:"contact point"},{label:"Auto-select contact point",value:"notification policy"}],re=oe=>{ee("manualRouting",oe==="contact point")};return a.createElement(C.K,{direction:"column"},a.createElement(C.K,{direction:"column"},a.createElement(A.S,{options:Re,value:X?"contact point":"notification policy",onChange:re,className:U.routingOptions})),a.createElement(ht,{manualRouting:X}),X?a.createElement(I,null):a.createElement(Ue,{alertUid:i}))}function Ue({alertUid:i}){const{watch:O}=(0,t.Gc)(),[ee,U,X,Re,re]=O(["labels","queries","condition","folder","name","manualRouting"]);return a.createElement(Ke,{alertQueries:U,customLabels:ee,condition:X,folder:Re,alertName:re,alertUid:i})}function Ct(){return a.createElement(F.h,{contentText:a.createElement(C.K,{gap:1,direction:"column"},a.createElement(C.K,{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(u.x,{color:"link"},"Read about notification routing. ",a.createElement(R.J,{name:"external-link-alt"})))),a.createElement(C.K,{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(u.x,{color:"link"},"Read about Labels and annotations. ",a.createElement(R.J,{name:"external-link-alt"}))))),title:"Notification routing"})}function Pt(){return a.createElement(F.h,{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 ht=({manualRouting:i})=>{const O=(0,y.wW)(yt);return a.createElement("div",{className:O.notificationsOptionDescription},a.createElement(u.x,{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."),i?a.createElement(Pt,null):a.createElement(Ct,null))},yt=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)})})},69655:(Oe,Z,e)=>{e.d(Z,{Y:()=>Te,u:()=>S});var n=e(66681),a=e(85960),t=e(53285),w=e(79088),y=e(72336),C=e(12537),u=e(23757),A=e(81502),R=e(47257),f=e(74042),z=e(29165),M=e(49199),F=e(21964),b=e(98231),se=e(85431),te=e(95135),Ee=e(31902),ye=e(79739),ue=e(9833),me=e(85445),h=e(4479);function $(x){return"expr"in x}function ne(x){return"grafana_condition"in x}var j=e(20304),le=e(76679);function c(x){if($(x))return T(x,x.dataSourceUid,j.$.cloudAlerting);if(ne(x))return T(x,le.GC,j.$.grafana);throw new Error("unsupported preview rule request")}function T(x,H,L){return(0,Ee.x)({whileLoading:E(L),source:(0,me.i)().fetch({method:"POST",url:`/api/v1/rule/test/${H}`,data:x}).pipe((0,b.U)(({data:I})=>E(L,{state:u.Gu.Done,series:I.instances.map(ye.vP)})),(0,se.K)(I=>(0,F.of)(E(L,{state:u.Gu.Error,error:(0,h.P)(I)}))),(0,te.B)())})}function E(x,H={}){return{ruleType:x,data:{state:u.Gu.Loading,series:[],timeRange:(0,ue.JK)(),...H}}}var B=e(93260),_=e(53565),N=e(70274),de=e(12593),Y=e(1713),Pe=e(30422);function $e(x){const{preview:H}=x,L=(0,R.wW)(Be),I={defaults:{},overrides:[{matcher:{id:N.mi.byName,options:"Info"},properties:[{id:"custom.displayMode",value:Y.h2.JSONView}]}]};if(!H)return null;const{data:J,ruleType:ie}=H;return J.state===u.Gu.Loading?a.createElement("div",{className:L.container},a.createElement("span",null,"Loading preview...")):J.state===u.Gu.Error?a.createElement("div",{className:L.container},J.error?(0,Pe.kk)(J.error):"Failed to preview alert rule"):a.createElement("div",{className:L.container},a.createElement("span",null,"Preview based on the result of running the query, for this moment."," ",ie===j.$.grafana?"Configuration for `no data` and `error handling` is not applied.":null),a.createElement("div",{className:L.table},a.createElement(_.Z,null,({width:Se,height:Ce})=>a.createElement("div",{style:{width:`${Se}px`,height:`${Ce}px`}},a.createElement(de.$,{title:"",width:Se,height:Ce,pluginId:"table",data:J,fieldConfig:I})))))}function Be(x){return{container:(0,n.css)`
      margin: ${x.spacing(2)} 0;
    `,table:(0,n.css)`
      flex: 1 1 auto;
      height: 135px;
      margin-top: ${x.spacing(2)};
      border: 1px solid ${x.colors.border.medium};
      border-radius: ${x.shape.radius.default};
    `}}const ge=["type","dataSourceName","condition","queries","expression"];function Te(){const x=(0,R.wW)(ae),[H,L]=S(),{watch:I}=(0,t.Gc)(),[J,ie,Se]=I(["type","condition","queries"]),{allDataSourcesAvailable:Ce}=(0,B.S)(Se);if(J===j.$.cloudRecording||J===j.$.cloudAlerting)return null;const ke=!!ie&&Ce;return a.createElement("div",{className:x.container},a.createElement(f.Lh,null,Ce&&a.createElement(z.zx,{disabled:!ke,type:"button",variant:"primary",onClick:L},"Preview alerts"),!Ce&&a.createElement(M.b,{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($e,{preview:H}))}function S(){const[x,H]=(0,a.useState)(),{getValues:L}=(0,t.Gc)(),I=(0,w.Z)(),J=(0,a.useCallback)(()=>{const ie=L(ge),Se=K(ie);c(Se).pipe((0,y.o)(Ce=>!G(Ce),!0)).subscribe(Ce=>{I()&&H(Ce)})},[L,I]);return[x,J]}function K(x){const[H,L,I,J,ie]=x,Se=(0,A.F)().getInstanceSettings(L);if(!Se)throw new Error(`Cannot find data source settings for ${L}`);switch(H){case j.$.cloudAlerting:return{dataSourceUid:Se.uid,dataSourceName:L,expr:ie};case j.$.grafana:return{grafana_condition:{condition:I,data:J,now:(0,C.lf)(Date.now())}};default:throw new Error(`Alert type ${H} not supported by preview.`)}}function G(x){switch(x.data.state){case u.Gu.Done:case u.Gu.Error:return!0;default:return!1}}function ae(x){return{container:(0,n.css)`
      margin-top: ${x.spacing(2)};
      max-width: ${x.breakpoints.values.xxl}px;
    `}}},1765:(Oe,Z,e)=>{e.d(Z,{V:()=>rn});var n=e(66681),a=e(56375),t=e(85960),w=e(53285),y=e(9833),C=e(92369),u=e(81502),A=e(90857),R=e(47257),f=e(13086),z=e(20519),M=e(96130),F=e(14607),b=e(29165),se=e(49199),te=e(54635),Ee=e(69707),ye=e(44839),ue=e(97666),me=e(40377),h=e(31476),$=e(36530),ne=e(95162),j=e(76679),le=e(92746);function c(){const o=(0,le._)(r=>r.dataSources);return Object.values(o).map(r=>r.result).filter(r=>!!r?.rulerConfig).map(r=>(0,j.c$)(r.name)).filter(r=>!!r)}var T=e(5970),E=e(20304),B=e(38884),_=e(81445),N=e(23757),de=e(93821),Y=e(81223),Pe=e(7042),$e=e(658),Be=e(14591),ge=e(25119);function Te({fields:o}){const s=o.filter(p=>!["State","Info"].includes(p.name)),r=o.findIndex(p=>p.name==="State"),l=o.findIndex(p=>p.name==="Info"),m=s.map(p=>o.indexOf(p)),g=o[r]?.values.length??0,v=[];for(let p=0;p<g;p++){const W=m.map(ve=>[o[ve].name,o[ve].values[p]]),fe=o[r]?.values?.[p],V=o[l]?.values?.[p];(0,ge.Yb)(fe)&&v.push({state:fe,info:V,labels:Object.fromEntries(W)})}return{instances:v}}function S({preview:o}){const s=(0,R.wW)(K),r=Te(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:m,labels:g},v)=>{const p=(0,$e.P3)(g);return t.createElement("tr",{key:v},t.createElement("td",null,t.createElement(Be.l,{state:l})),t.createElement("td",null,t.createElement(Pe.P,{tags:p,className:s.tagList})),t.createElement("td",null,m&&t.createElement(F.u,{content:m},t.createElement(ue.J,{name:"info-circle"}))))})))}const K=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 G=e(69655);const ae=({value:o,onChange:s,dataSourceName:r,showPreviewAlertsButton:l=!0})=>{const m=(0,R.wW)(x),{mapToValue:g,mapToQuery:v}=H(r),p=v({refId:"A",hide:!1},o),{error:W,loading:fe,value:V}=(0,_.Z)(()=>(0,u.F)().get(r),[r]),ve=(0,t.useCallback)(Ye=>{s(g(Ye))},[s,g]),[He,k]=(0,G.u)(),Q=async()=>{k()};if(fe||V?.name!==r)return null;const Qe=(0,u.F)().getInstanceSettings(r);if(W||!V||!V?.components?.QueryEditor||!Qe){const Ye=W?.message||"Data source plugin does not export any Query Editor component";return t.createElement("div",null,"Could not load query editor due to: ",Ye)}const Fe=He?.data.state===N.Gu.Done,Ze=V?.components?.QueryEditor,et=He?.data?.series?.find(Ye=>Ye.name==="evaluation results"),ft=et&&et.fields.some(Ye=>Ye.values.length>0);return t.createElement(t.Fragment,null,t.createElement(de.n,{instanceSettings:Qe},t.createElement(Ze,{query:p,queries:[p],app:Y.zj.CloudAlerting,onChange:ve,onRunQuery:a.noop,datasource:V})),l&&t.createElement("div",{className:m.preview},t.createElement(b.zx,{type:"button",onClick:Q,disabled:He?.data.state===N.Gu.Loading},"Preview alerts"),Fe&&!ft&&t.createElement(se.b,{title:"Alerts preview",severity:"info",className:m.previewAlert},"There are no firing alerts for your query."),ft&&t.createElement(S,{preview:et})))},x=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 H(o){return(0,t.useMemo)(()=>{switch((0,u.F)().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 L=e(23796),I=e(90943);const J=({condition:o,onSetCondition:s,queries:r,panelData:l,onUpdateRefId:m,onRemoveExpression:g,onUpdateExpressionType:v,onUpdateQueryExpression:p})=>{const W=(0,t.useMemo)(()=>r.reduce((V,ve)=>(0,h.j)(ve.model)?V.concat(ve.model):V,[]),[r]),fe=(0,R.wW)(ie);return t.createElement("div",{className:fe.wrapper},W.map(V=>{const ve=l[V.refId],He=o===V.refId,k=ve?(0,I._m)(ve):void 0,Q=ve?(0,I.Yq)(ve.series):void 0;return t.createElement(L.A2,{key:V.refId,isAlertCondition:He,data:ve,error:k,warning:Q,queries:r,query:V,onSetCondition:s,onRemoveExpression:g,onUpdateRefId:m,onUpdateExpressionType:v,onChangeQuery:p})}))},ie=o=>({wrapper:(0,n.css)`
    display: flex;
    gap: ${o.spacing(2)};
    align-content: stretch;
    flex-wrap: wrap;
  `});var Se=e(21863),Ce=e(31173),ke=e(71244),Ke=e(72435),Et=e(61387),mt=e(65512),lt=e(84933),gt=e(24956),Ue=e(84457),Ct=e(47689),Pt=e(11462),ht=e(85745),yt=e(57652),i=e(78136);const O=({query:o,queryOptions:s,onChangeTimeRange:r,onChangeQueryOptions:l,index:m})=>{const g=(0,R.wW)(ee),[v,p]=(0,t.useState)(!1),W=o.relativeTimeRange?(0,ke.relativeToTimeRange)(o.relativeTimeRange):void 0;return t.createElement(t.Fragment,null,t.createElement(yt.P,{content:t.createElement("div",{className:g.queryOptions},r&&t.createElement(lt._,{label:"Time Range"},t.createElement(i.x,{timeRange:o.relativeTimeRange??(0,y.Rr)(),onChange:fe=>r(fe,m)})),t.createElement(Ve,{options:s,onChange:fe=>l(fe,m)}),t.createElement(qe,{options:s,onChange:fe=>l(fe,m)})),closeButton:!0,placement:"bottom-start"},t.createElement("button",{type:"button",className:g.actionLink,onClick:()=>p(!v)},"Options ",v?t.createElement(ue.J,{name:"angle-right"}):t.createElement(ue.J,{name:"angle-down"}))),t.createElement("div",{className:g.staticValues},t.createElement("span",null,(0,ht.CQ)(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)))},ee=o=>{const s=(0,b.gN)(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 U=e(49004);const X=43200,Re="1s",re=({data:o,error:s,dsSettings:r,index:l,onChangeDataSource:m,onChangeQuery:g,onChangeTimeRange:v,onRunQueries:p,onRemoveQuery:W,onDuplicateQuery:fe,query:V,queries:ve,thresholds:He,thresholdsType:k,onChangeThreshold:Q,condition:Qe,onSetCondition:Fe,onChangeQueryOptions:Ze})=>{const et=(0,R.wW)(_e),[ft,Ye]=(0,t.useState)(),Ot={...ft?.getDefaultQuery?ft.getDefaultQuery(Y.zj.UnifiedAlerting):{},...(0,a.cloneDeep)(V.model)};function st(){const we=(0,R.wW)(_e);return t.createElement("div",{className:we.dsTooltip},t.createElement(F.u,{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(ue.J,{name:"info-circle",onClick:()=>window.open(" https://grafana.com/docs/grafana/latest/alerting/fundamentals/data-source-alerting/","_blank")})))}function Qt({query:we,error:Ft,index:vt}){const Bt={maxDataPoints:we.model.maxDataPoints,minInterval:we.model.intervalMs?(0,Ct.gS)(we.model.intervalMs):void 0},tt={maxDataPoints:Bt.maxDataPoints,minInterval:Bt.minInterval},Zt=Qe===we.refId;return t.createElement(f.K,{direction:"row",alignItems:"center",gap:1},t.createElement(st,null),t.createElement(O,{onChangeTimeRange:v,query:we,queryOptions:tt,onChangeQueryOptions:Ze,index:vt}),t.createElement(Pt.H,{error:Ft,onSetCondition:()=>Fe(we.refId),isCondition:Zt}))}const Ht=o.state!==N.Gu.NotStarted;return t.createElement(f.K,{direction:"column",gap:.5},t.createElement("div",{className:et.wrapper},t.createElement(Ue.x,{alerting:!0,collapsable:!1,dataSource:r,onDataSourceLoaded:Ye,onChangeDataSource:we=>m(we,l),id:V.refId,index:l,key:V.refId,data:o,query:Ot,onChange:we=>g(we,l),onRemoveQuery:W,onAddQuery:()=>fe((0,a.cloneDeep)(V)),onRunQuery:p,queries:ve,renderHeaderExtras:()=>t.createElement(Qt,{query:V,index:l,error:s}),app:Y.zj.UnifiedAlerting,hideDisableQuery:!0})),Ht&&t.createElement(U.l,{data:o,thresholds:He,thresholdsType:k,onThresholdsChange:Q?we=>Q(we,l):void 0}))},oe=({children:o})=>{const s=(0,R.wW)(_e);return t.createElement("div",{className:s.wrapper},o)};function Ve({options:o,onChange:s}){const r=o.maxDataPoints??"",l=m=>{const g=parseInt(m.target.value,10),v=isNaN(g)||g===0?void 0:g;v!==o.maxDataPoints&&s({...o,maxDataPoints:v})};return t.createElement(lt._,{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(gt.I,{type:"number",width:10,placeholder:X.toString(),spellCheck:!1,onBlur:l,defaultValue:r}))}function qe({options:o,onChange:s}){const r=o.minInterval??"",l=m=>{const g=m.target.value;g!==r&&s({...o,minInterval:g})};return t.createElement(lt._,{label:"Min interval",labelWidth:24,tooltip:t.createElement(t.Fragment,null,"A lower limit for the interval. Recommended to be set to write frequency, for example ",t.createElement("code",null,"1m")," if your data is written every minute.")},t.createElement(gt.I,{type:"text",width:10,placeholder:Re,spellCheck:!1,onBlur:l,defaultValue:r}))}const _e=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 Le extends t.PureComponent{constructor(s){super(s),this.onRemoveQuery=r=>{const{queries:l,onQueriesChange:m}=this.props;m(l.filter(g=>g.refId!==r.refId))},this.onChangeTimeRange=(r,l)=>{const{queries:m,onQueriesChange:g}=this.props;g(m.map((v,p)=>p!==l?v:{...v,relativeTimeRange:r}))},this.onChangeQueryOptions=(r,l)=>{const{queries:m,onQueriesChange:g}=this.props;g(m.map((v,p)=>p!==l?v:{...v,model:{...v.model,maxDataPoints:r.maxDataPoints,intervalMs:r.minInterval?ke.intervalToMs(r.minInterval):void 0}}))},this.onChangeDataSource=(r,l)=>{const{queries:m,onQueriesChange:g}=this.props,v=m.map((p,W)=>{if(W!==l)return p;const fe=this.getDataSourceSettings(p);return r.type===fe?.type?ze(p,r):je(p,r)});g(v)},this.onChangeQuery=(r,l)=>{const{queries:m,onQueriesChange:g}=this.props;g(m.map((v,p)=>p!==l?v:{...v,refId:r.refId,queryType:v.model.queryType??"",model:{...v.model,...r,datasource:r.datasource}}))},this.onDragEnd=r=>{const{queries:l,onQueriesChange:m}=this.props;if(!r||!r.destination)return;const g=r.source.index,v=r.destination.index;if(g===v)return;const p=Array.from(l),[W]=p.splice(g,1);p.splice(v,0,W),m(p)},this.getDataSourceSettings=r=>(0,u.F)().getInstanceSettings(r.datasourceUid)}render(){const{queries:s,expressions:r}=this.props,l=(0,I.Fu)([...s,...r]);return t.createElement(Ce.Z5,{onDragEnd:this.onDragEnd},t.createElement(Ce.bK,{droppableId:"alerting-queries",direction:"vertical"},m=>t.createElement("div",{ref:m.innerRef,...m.droppableProps},t.createElement(f.K,{direction:"column"},s.map((g,v)=>{const p=this.props.condition===g.refId,W=this.props.data?.[g.refId]??{series:[],state:N.Gu.NotStarted},fe=this.getDataSourceSettings(g);let V;return W&&p?V=(0,I.Ps)(W):W&&(V=(0,I._m)(W)),fe?t.createElement(re,{index:v,key:g.refId,dsSettings:fe,data:W,error:V,query:g,onChangeQuery:this.onChangeQuery,onRemoveQuery:this.onRemoveQuery,queries:[...s,...r],onChangeDataSource:this.onChangeDataSource,onDuplicateQuery:this.props.onDuplicateQuery,onChangeTimeRange:this.onChangeTimeRange,onChangeQueryOptions:this.onChangeQueryOptions,thresholds:l[g.refId]?.config,thresholdsType:l[g.refId]?.mode,onRunQueries:this.props.onRunQueries,condition:this.props.condition,onSetCondition:this.props.onSetCondition}):t.createElement(Xe,{key:`${g.refId}-${v}`,index:v,model:g.model,onUpdateDatasource:()=>{const ve=(0,mt.ak)().getInstanceSettings(null);ve&&this.onChangeDataSource(ve,v)},onRemoveQuery:()=>{this.onRemoveQuery(g)}})}),m.placeholder))))}}function ze(o,s){return{...o,model:{...(0,a.omit)(o.model,"datasource"),datasource:{type:s.type,uid:s.uid}},datasourceUid:s.uid}}function je(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 Xe=({index:o,onUpdateDatasource:s,onRemoveQuery:r,model:l})=>{const m=l.refId,[g,v]=(0,t.useState)(!1),p=()=>{v(fe=>!fe)},W=()=>{s()};return t.createElement(oe,null,t.createElement(Et.t,{title:m,draggable:!0,index:o,id:m,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(ue.J,{name:"question-circle"})),t.createElement(Ke.Z.Actions,null,t.createElement(b.zx,{key:"update",variant:"secondary",onClick:W},"Update datasource"),t.createElement(b.zx,{key:"remove",variant:"destructive",onClick:r},"Remove query")),t.createElement(Ke.Z.SecondaryActions,null,t.createElement(b.zx,{key:"details",onClick:p,icon:g?"angle-up":"angle-down",fill:"text",size:"sm"},"Show details"))),g&&t.createElement("div",null,t.createElement("pre",null,t.createElement("code",null,JSON.stringify(l,null,2))))))},nt=({queries:o,expressions:s,panelData:r,onRunQueries:l,onChangeQueries:m,onDuplicateQuery:g,condition:v,onSetCondition:p})=>{const W=(0,R.wW)(it);return t.createElement("div",{className:W.container},t.createElement(Le,{data:r,queries:o,expressions:s,onRunQueries:l,onQueriesChange:m,onDuplicateQuery:g,condition:v,onSetCondition:p}))},it=o=>({container:(0,n.css)`
    background-color: ${o.colors.background.primary};
    height: 100%;
  `});var at=e(45864);const d=({queries:o,onChangeQuery:s,runQueries:r,panelData:l,dataSourceName:m})=>{const[g,v]=(0,t.useState)({series:[],state:N.Gu.NotStarted,timeRange:(0,at.$t)().timeRange()}),p=(0,R.wW)(P);(0,t.useEffect)(()=>{v(l?.[o[0]?.refId])},[l,o]);const{error:W,loading:fe,value:V}=(0,_.Z)(()=>(0,u.F)().get(m),[m]),ve=Q=>{const Qe=o[0],Fe=(0,u.F)().getInstanceSettings(m)?.uid;if(!(0,B.tO)(Q)||!Fe)return;const Ze=Q.expr,et={...Qe,...Q,datasourceUid:Fe,expr:Ze,model:{expr:Ze,datasource:Q.datasource,refId:Q.refId,editorMode:Q.editorMode,instant:!!Q.instant,range:!!Q.range,legendFormat:Q.legendFormat}};s([et])};if(fe||V?.name!==m)return null;const He=(0,u.F)().getInstanceSettings(m);if(W||!V||!V?.components?.QueryEditor||!He){const Q=W?.message||"Data source plugin does not export any Query Editor component";return t.createElement("div",null,"Could not load query editor due to: ",Q)}const k=V.components.QueryEditor;return t.createElement(t.Fragment,null,o.length&&t.createElement(k,{query:o[0],queries:o,app:Y.zj.UnifiedAlerting,onChange:ve,onRunQuery:r,datasource:V}),g&&t.createElement("div",{className:p.vizWrapper},t.createElement(U.l,{data:g})))},P=o=>({vizWrapper:(0,n.css)`
    margin: ${o.spacing(1,0)};
  `});var pe=e(78985),he=e(40715),xe=e(59767);function ce({value:o,disabled:s,...r}){const l=c(),{loading:m=!0}=(0,_.Z)(()=>(0,xe.WI)((0,T.dV)()),[xe.WI]),g=(0,t.useCallback)(v=>!!l.find(({id:p})=>p===v.id),[l]);return t.createElement(he.q,{disabled:m||s,noDefault:!0,alerting:!0,filter:g,current:o,...r})}const be=({disabled:o,onChangeCloudDatasource:s})=>{const{control:r,formState:{errors:l},setValue:m,watch:g}=(0,w.Gc)(),v=(0,R.wW)(Ae),p=g("type");return t.createElement(t.Fragment,null,t.createElement("div",{className:v.flexRow},(p===E.$.cloudAlerting||p===E.$.cloudRecording)&&t.createElement(z.g,{className:v.formInput,label:o?"Data source":"Select data source",error:l.dataSourceName?.message,invalid:!!l.dataSourceName?.message,"data-testid":"datasource-picker"},t.createElement(M.g,{render:({field:{onChange:W,ref:fe,...V}})=>t.createElement(ce,{...V,disabled:o,onChange:ve=>{m("expression",""),W(ve?.name??null),s(ve?.uid??null)}}),name:"dataSourceName",control:r,rules:{required:{value:!0,message:"Please select a data source"}}}))))},Ae=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 Me=e(5106),We=e(49683);function Ge(){const o=We.Vt.hasPermission(ne.AccessControlAction.AlertingRuleCreate),s=We.Vt.hasPermission(ne.AccessControlAction.AlertingRuleExternalWrite),r=o?E.$.grafana:E.$.cloudAlerting,l=[];return o&&l.push(E.$.grafana),s&&l.push(E.$.cloudAlerting,E.$.cloudRecording),{enabledRuleTypes:l,defaultRuleType:r}}const rt=o=>o.filter(s=>s.datasourceUid!==$.Yq).length===1,Ne=({queries:o,ruleFormType:s,rulesSourcesWithRuler:r})=>{const l=Ge(),m=rt(o),g=o[0]?.datasourceUid??"",v=s===E.$.cloudRecording,p=!v&&m&&r.some(k=>k.uid===g),W=!v,fe=l.enabledRuleTypes.includes(E.$.grafana),V=l.enabledRuleTypes.includes(E.$.cloudAlerting),ve=s===E.$.cloudAlerting&&fe&&W,He=s===E.$.grafana&&p&&V&&p;return ve||He};function pt({editingExistingRule:o,rulesSourcesWithRuler:s,queries:r,onClickSwitch:l}){const{getValues:m}=(0,w.Gc)(),[g]=m(["type"]),v=Ne({queries:r,ruleFormType:g,rulesSourcesWithRuler:s}),p=[{label:"Grafana-managed",value:E.$.grafana},{label:"Data source-managed",value:E.$.cloudAlerting}],W=v?[]:[E.$.cloudAlerting];return t.createElement(f.K,{direction:"column",gap:1,alignItems:"flex-start"},t.createElement(f.K,{direction:"column",gap:0},t.createElement(me.x,{variant:"h5"},"Rule type"),t.createElement(f.K,{direction:"row",gap:.5,alignItems:"baseline"},t.createElement(me.x,{variant:"bodySmall",color:"secondary"},"Select where the alert rule will be managed."),t.createElement(Se.h,{contentText:t.createElement(t.Fragment,null,t.createElement(me.x,{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(me.x,{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(Me.S,{options:p,disabled:o,disabledOptions:W,value:g,onChange:l}),o&&t.createElement(me.x,{color:"secondary"},"The alert rule type cannot be changed for an existing rule."),!o&&t.createElement(t.Fragment,null,v?t.createElement(me.x,{color:"secondary"},g===E.$.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(me.x,{color:"secondary"},"Based on the selected data sources this alert rule will be Grafana-managed.")))}var De=e(20079),St=e(21871);const Dt=o=>{try{return JSON.stringify(o),!1}catch{return!0}},It=(o,s)=>{if(Dt(o))return null;if(s.datasourceUid!==$.Yq)return s;{const r=o.find(l=>l.refId===s.model.expression);return r?It(o,r):null}};var Tt=e(15013),Rt=e(92731);const ot=(o,s)=>{const r=o.find(m=>m.refId===s);return r&&It(o,r)},Vt={queries:[]},$t=(0,De.PH)("duplicateQuery"),ct=(0,De.PH)("addNewDataQuery"),xt=(0,De.PH)("setDataQueries"),Lt=(0,De.PH)("addNewExpression"),Wt=(0,De.PH)("removeExpression"),At=(0,De.PH)("removeExpressions"),wt=(0,De.PH)("addExpressions"),Mt=(0,De.PH)("updateExpression"),bt=(0,De.PH)("updateExpressionRefId"),Nt=(0,De.PH)("rewireExpressions"),Gt=(0,De.PH)("updateExpressionType"),Ie=(0,De.PH)("updateExpressionTimeRange"),Kt=(0,De.PH)("updateMaxDataPoints"),ut=(0,De.PH)("updateMinInterval"),dt=(0,De.PH)("setRecordingRulesQueries"),en=(0,De.Lq)(Vt,o=>{o.addCase($t,(s,{payload:r})=>{s.queries=zt(s.queries,r)}).addCase(ct,s=>{const r=(0,j.P)();r&&(s.queries=zt(s.queries,{datasourceUid:r.uid,model:{refId:"",datasource:{type:r.type,uid:r.uid}}}))}).addCase(xt,(s,{payload:r})=>{const l=s.queries.filter(m=>(0,h.j)(m.model));s.queries=[...r,...l]}).addCase(dt,(s,{payload:r})=>{const l=r.recordingRuleQueries[0],m={...l,expr:r.expression,model:l?.model};s.queries=[m]}).addCase(Kt,(s,r)=>{s.queries=s.queries.map(l=>l.refId===r.payload.refId?{...l,model:{...l.model,maxDataPoints:r.payload.maxDataPoints}}:l)}).addCase(ut,(s,r)=>{s.queries=s.queries.map(l=>l.refId===r.payload.refId?{...l,model:{...l.model,intervalMs:r.payload.minInterval?ke.intervalToMs(r.payload.minInterval):void 0}}:l)}),o.addCase(Lt,(s,{payload:r})=>{s.queries=zt(s.queries,{datasourceUid:$.Yq,model:Tt.mV.newQuery({type:r,conditions:[{...Rt.R,query:{params:[]}}],expression:""})})}).addCase(Wt,(s,{payload:r})=>{s.queries=s.queries.filter(l=>l.refId!==r)}).addCase(At,s=>{s.queries=s.queries.filter(r=>!(0,h.j)(r.model))}).addCase(wt,(s,{payload:r})=>{s.queries=[...s.queries,...r]}).addCase(Mt,(s,{payload:r})=>{s.queries=s.queries.map(l=>{const m=ot(s.queries,r.expression),g=m?m.relativeTimeRange:(0,y.Rr)();return l.refId===r.refId&&(l.model=r,r.type===$.Us.resample&&(l.relativeTimeRange=g)),l})}).addCase(Ie,s=>{const r=s.queries.map(l=>{if(l.datasourceUid===$.Yq){const m=ot(s.queries,l.model.expression),g=m?m.relativeTimeRange:(0,y.Rr)();l.relativeTimeRange=g}return l});s.queries=r}).addCase(bt,(s,{payload:r})=>{const{newRefId:l,oldRefId:m}=r;if((0,I.Dr)(s.queries,l))return;const v=(0,I.Ry)(s.queries,m,l);s.queries=v.map(p=>p.refId===m?{...p,refId:l,model:{...p.model,refId:l}}:p)}).addCase(Nt,(s,{payload:r})=>{s.queries=(0,I.Ry)(s.queries,r.oldRefId,r.newRefId)}).addCase(Gt,(s,r)=>{s.queries=s.queries.map(l=>l.refId===r.payload.refId?{...l,model:{...Tt.mV.newQuery({type:r.payload.type,conditions:[{...Rt.R,query:{params:[]}}],expression:""}),refId:r.payload.refId}}:l)})}),zt=(o,s)=>{const r=(0,St.Hs)(o),l={...s,refId:r,queryType:"",model:{...s.model,hide:!1,refId:r},relativeTimeRange:s.relativeTimeRange??tn(s.model)};return[...o,l]},tn=o=>{if(!(0,h.j)(o))return(0,y.Rr)()};var nn=e(98187);function an(){const[o,s]=(0,t.useState)({}),r=(0,t.useRef)(new nn.v);(0,t.useEffect)(()=>{const p=r.current;return p.get().subscribe(W=>{s(W)}),()=>{p.destroy()}},[]);const l=(0,t.useCallback)(()=>{s({})},[]),m=(0,t.useCallback)(()=>{r.current.cancel()},[]),g=(0,t.useCallback)((p,W)=>{r.current.run(p,W)},[]),v=(0,t.useMemo)(()=>Object.values(o).some(p=>p.state===N.Gu.Loading),[o]);return{queryPreviewData:o,runQueries:g,cancelQueries:m,isPreviewLoading:v,clearPreviewData:l}}const rn=({editingExistingRule:o,onDataChange:s})=>{const{setValue:r,getValues:l,watch:m,formState:{errors:g},control:v}=(0,w.Gc)(),{queryPreviewData:p,runQueries:W,cancelQueries:fe,isPreviewLoading:V,clearPreviewData:ve}=an(),He={queries:l("queries")},[{queries:k},Q]=(0,t.useReducer)(en,He),[Qe,Fe,Ze]=m(["type","condition","dataSourceName"]),et=Qe===E.$.grafana,ft=Qe===E.$.cloudRecording,Ye=Qe===E.$.cloudAlerting,jt=(0,ne.useDispatch)();(0,t.useEffect)(()=>{jt((0,T.dV)())},[jt]);const Ot=c(),st=(0,t.useCallback)(D=>{Ye||W(l("queries"),D||(l("condition")??""))},[Ye,W,l]);(0,t.useEffect)(()=>{r("queries",k,{shouldValidate:!1})},[k,W,r]);const Qt=(0,j.P)()===void 0,Ht=(0,t.useMemo)(()=>k.filter(D=>!(0,h.j)(D.model)),[k]),we=(0,t.useMemo)(()=>k.filter(D=>(0,h.j)(D.model)),[k]),Ft=k.length===0;(0,t.useEffect)(()=>{if(!et)return;const D=l("condition");if(!D)return;const q=p[D];if(!q)return;const Je=(0,I._m)(q)??(0,I.Ps)(q);s(Je?.message||"")},[p,l,s,et]);const vt=(0,t.useCallback)(D=>{D&&(st(D),r("condition",D))},[st,r]),Bt=(0,t.useCallback)((D,q)=>{(0,I.Dr)(k,q)||(Q(bt({oldRefId:D,newRefId:q})),Fe===D&&vt(q))},[Fe,k,vt]),tt=ln(),Zt=(0,t.useCallback)(D=>{r("queries",D,{shouldValidate:!1}),tt(D),Q(xt(D)),Q(Ie());const[q,Je]=(0,I.eW)(k,D);q&&Je&&Q(Nt({oldRefId:q,newRefId:Je}))},[k,r,tt]),cn=(0,t.useCallback)(D=>{const q=D[0];if(!(0,B.tO)(q.model))return;const Je=q.model.expr;r("queries",D,{shouldValidate:!1}),tt(D),Q(dt({recordingRuleQueries:D,expression:Je})),st()},[st,r,tt]),Yt=Ot[0];(0,t.useEffect)(()=>{if(ve(),Qe===E.$.cloudRecording){const D=l("expression");if(!Yt)return;const Je={refId:"A",datasourceUid:o&&(0,u.F)().getInstanceSettings(Ze)?.uid||Yt.uid,queryType:"",relativeTimeRange:(0,y.Rr)(),expr:D,model:{refId:"A",hide:!1,expr:D}};Q(dt({recordingRuleQueries:[Je],expression:D}))}},[Qe,Yt,o,l,Ze,ve]);const un=(0,t.useCallback)(D=>{Q($t(D))},[]);(0,t.useEffect)(()=>{if(!(0,I.Dr)(k,Fe)){const D=k.at(-1)?.refId??null;vt(D)}},[Fe,k,vt]);const dn=(0,t.useCallback)(D=>{Q(Lt(D))},[Q]),mn=(0,R.wW)(sn),gn=(0,t.useCallback)(D=>{const q=(0,a.cloneDeep)(k);q[0].datasourceUid=D,r("queries",q,{shouldValidate:!1}),tt(q),Q(xt(q))},[k,r,tt,Q]),pn=D=>{const q=(0,a.cloneDeep)(k);if(q[0].model)if((0,B.tO)(q[0].model))q[0].model.expr=D;else{const Je={...(0,a.cloneDeep)(q[0].model),expr:D};q[0].model=Je}r("queries",q,{shouldValidate:!1}),tt(q),Q(xt(q)),st()},Xt=(0,t.useCallback)(()=>Q(At()),[Q]),kt=(0,t.useCallback)(D=>Q(wt(D)),[Q]),[Ut,fn]=(0,t.useState)([]),[Jt,vn]=(0,t.useState)(null),qt=(0,t.useCallback)(()=>{kt(Ut)},[Ut,kt]),_t=(0,t.useCallback)(()=>{if(l("type")===E.$.cloudAlerting)r("type",E.$.grafana),r("dataSourceName",null),Ut.length>0&&qt(),Jt&&r("condition",Jt);else{r("type",E.$.cloudAlerting);const q=(0,u.F)().getInstanceSettings(k[0].datasourceUid)?.name;q&&r("dataSourceName",q),tt(k);const Je=k.filter(En=>En.datasourceUid===$.Yq);fn(Je),Xt(),vn(Fe)}},[l,r,Ut.length,qt,Jt,tt,k,Xt,Fe]);return t.createElement(pe.z,{stepNo:2,title:Qe!==E.$.cloudRecording?"Define query and alert condition":"Define query",description:t.createElement(f.K,{direction:"row",gap:.5,alignItems:"baseline"},t.createElement(me.x,{variant:"bodySmall",color:"secondary"},"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."),t.createElement(Se.h,{contentText:`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.`,externalLink:"https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/",linkText:"Read about query and condition",title:"Define query and alert condition"}))},(Qe===E.$.cloudRecording||Qe===E.$.cloudAlerting)&&t.createElement(be,{onChangeCloudDatasource:gn,disabled:o}),ft&&Ze&&t.createElement(z.g,{error:g.expression?.message,invalid:!!g.expression?.message},t.createElement(d,{dataSourceName:Ze,queries:k,runQueries:st,onChangeQuery:cn,panelData:p})),Ye&&Ze&&t.createElement(f.K,{direction:"column"},t.createElement(z.g,{error:g.expression?.message,invalid:!!g.expression?.message},t.createElement(M.g,{name:"expression",render:({field:{ref:D,...q}})=>t.createElement(ae,{...q,dataSourceName:Ze,showPreviewAlertsButton:!ft,onChange:pn}),control:v,rules:{required:{value:!0,message:"A valid expression is required"}}})),t.createElement(pt,{editingExistingRule:o,queries:k,rulesSourcesWithRuler:Ot,onClickSwitch:_t})),et&&t.createElement(f.K,{direction:"column"},t.createElement(nt,{queries:Ht,expressions:we,onRunQueries:()=>st(),onChangeQueries:Zt,onDuplicateQuery:un,panelData:p,condition:Fe,onSetCondition:vt}),t.createElement(F.u,{content:"You appear to have no compatible data sources",show:Qt},t.createElement(b.zx,{type:"button",onClick:()=>{Q(ct())},variant:"secondary","data-testid":C.wl.components.QueryTab.addQuery,disabled:Qt,className:mn.addQueryButton},"Add query")),t.createElement(pt,{editingExistingRule:o,rulesSourcesWithRuler:Ot,queries:k,onClickSwitch:_t}),t.createElement(f.K,{direction:"column",gap:0},t.createElement(me.x,{element:"h5"},"Expressions"),t.createElement(me.x,{variant:"bodySmall",color:"secondary"},"Manipulate data returned from queries with math and other operations.")),t.createElement(J,{queries:k,panelData:p,condition:Fe,onSetCondition:vt,onRemoveExpression:D=>{Q(Wt(D))},onUpdateRefId:Bt,onUpdateExpressionType:(D,q)=>{Q(Gt({refId:D,type:q}))},onUpdateQueryExpression:D=>{Q(Mt(D))}}),t.createElement(f.K,{direction:"row"},A.config.expressionsEnabled&&t.createElement(on,{onClickType:dn}),V&&t.createElement(b.zx,{icon:"spinner",type:"button",variant:"destructive",onClick:fe},"Cancel"),!V&&t.createElement(b.zx,{icon:"sync",type:"button",onClick:()=>st(),disabled:Ft},"Preview")),Ft&&t.createElement(se.b,{title:"No queries or expressions have been configured",severity:"warning"},"Create at least one query or expression to be alerted on")))};function on({onClickType:o}){const s=t.createElement(te.v,null,$.EJ.map(r=>t.createElement(F.u,{key:r.value,content:r.description??"",placement:"right"},t.createElement(Ee.s,{key:r.value,onClick:()=>o(r.value??$.Us.math),label:r.label??""}))));return t.createElement(ye.L,{overlay:s},t.createElement(b.zx,{variant:"secondary"},"Add expression",t.createElement(ue.J,{name:"angle-down"})))}const sn=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};
  `}),ln=()=>{const{setValue:o}=(0,w.Gc)();return s=>{const r=s[0];if(!r)return;if(!(0,u.F)().getInstanceSettings(r.datasourceUid))throw new Error("The Data source has not been defined.");if((0,B.tO)(r.model)){const m=r.model.expr;o("expression",m)}}}},94498:(Oe,Z,e)=>{e.d(Z,{F3:()=>b,HO:()=>Ee,eq:()=>me});var n=e(85960),a=e(81445),t=e(95162),w=e(14411),y=e(80679),C=e(5970),u=e(76679),A=e(30422),R=e(60956),f=e(9001),z=e(68700),M=e(92746);function F(h,$){const ne=se($),j=useCombinedRuleNamespaces($),le=useMemo(()=>{if(!h||!$||j.length===0)return[];const c=[];for(const T of j)for(const E of T.groups)for(const B of E.rules)B.name===h&&c.push(B);return c},[h,$,j]);return{...ne,result:le}}function b(h,$,ne){const j=(0,u.c$)($),{dsFeatures:le,isLoadingDsFeatures:c}=me($),{currentData:T=[],isLoading:E,error:B}=w.alertRuleApi.endpoints.prometheusRuleNamespaces.useQuery({ruleSourceName:$,ruleName:h,namespace:ne?.namespace,groupName:ne?.groupName}),[_]=w.alertRuleApi.endpoints.rulerRuleGroup.useLazyQuery(),{loading:N,error:de,value:Y}=(0,a.Z)(async()=>{if(!j)throw new Error("Unable to obtain data source settings");if(B)throw new Error("Unable to obtain Prometheus rules");const Pe=[];if(le?.rulerConfig){const ge=le.rulerConfig,Te=T.map(S=>S.groups.map(K=>({namespace:S,group:K}))).flat();await Promise.allSettled(Te.map(async S=>{const K=await _({rulerConfig:ge,namespace:S.namespace.name,group:S.group.name}).unwrap();Pe.push(K)}))}return T.map(ge=>(0,z.K$)(j,ge,Pe)).flatMap(ge=>ge.groups.flatMap(Te=>Te.rules))},[j,le,E,B,T,_]);return{loading:c||N,error:de,rules:Y}}function se(h,$){const ne=useDispatch(),j=useUnifiedAlertingSelector(B=>B.promRules),le=te(h,j),c=useUnifiedAlertingSelector(B=>B.rulerRules),T=te(h,c),{loading:E}=useAsync(async()=>{h&&await ne(fetchPromAndRulerRulesAction({rulesSourceName:h,identifier:$}))},[ne,h]);return{loading:E,error:le.error??isRulerNotSupportedResponse(T)?void 0:T.error,dispatched:le.dispatched&&T.dispatched}}function te(h,$){if(!h)return initialAsyncRequestState;const ne=$[h];return ne||initialAsyncRequestState}function Ee({ruleIdentifier:h}){const{ruleSourceName:$}=h,ne=(0,u.c$)($),{dsFeatures:j,isLoadingDsFeatures:le}=me($),{currentData:c,isLoading:T,error:E}=w.alertRuleApi.endpoints.prometheusRuleNamespaces.useQuery({ruleSourceName:h.ruleSourceName,namespace:(0,f.qE)(h)||(0,f.E4)(h)?h.namespace:void 0,groupName:(0,f.qE)(h)||(0,f.E4)(h)?h.groupName:void 0,ruleName:(0,f.qE)(h)||(0,f.E4)(h)?h.ruleName:void 0}),[B,{currentData:_,isLoading:N,error:de}]=w.alertRuleApi.endpoints.rulerRuleGroup.useLazyQuery(),[Y,{currentData:Pe,isLoading:$e,error:Be}]=w.alertRuleApi.endpoints.rulerRules.useLazyQuery();(0,n.useEffect)(()=>{j?.rulerConfig&&(j.rulerConfig&&(0,f.E4)(h)?B({rulerConfig:j.rulerConfig,namespace:h.namespace,group:h.groupName}):(0,f.Kl)(h)&&Y({rulerConfig:j.rulerConfig}))},[j,B,Y,h]);const ge=(0,n.useMemo)(()=>{if(c){if((0,f.Kl)(h)){const Te=(0,z.bU)("grafana",c,Pe);for(const S of Te)for(const K of S.groups)for(const G of K.rules){const ae=R.Yd($,G);if(R.Dg(ae,h))return G}}if(ne&&c.length>0&&((0,f.E4)(h)||(0,f.qE)(h))){const Te=c.map(S=>(0,z.K$)(ne,S,_?[_]:[]));for(const S of Te)for(const K of S.groups)for(const G of K.rules){const ae=R.Yd($,G);if(R.Dg(ae,h))return G}}}},[h,$,c,_,Pe,ne]);return{loading:le||T||N||$e,error:E??de??Be,result:ge}}const ue={rulerConfig:{dataSourceName:u.GC,apiVersion:"legacy"}};function me(h){const $=(0,u.HY)(h),{currentData:ne,isLoading:j}=y.T.endpoints.discoverDsFeatures.useQuery({rulesSourceName:h},{skip:$});return $?{isLoadingDsFeatures:!1,dsFeatures:ue}:{isLoadingDsFeatures:j,dsFeatures:ne}}},62208:(Oe,Z,e)=>{e.d(Z,{s:()=>y});var n=e(85960),a=e(84954),t=e(98724),w=e(70335);function y(){const{selectedAlertmanager:C}=(0,a.ZA)(),{currentData:u}=(0,w.W)(C),A=u?.alertmanager_config;return(0,n.useMemo)(()=>A?.mute_time_intervals?.map(f=>({value:f.name,label:f.name,description:f.time_intervals.map(z=>(0,t.uK)(z)).join(", AND ")}))??[],[A])}},71803:(Oe,Z,e)=>{e.d(Z,{Oy:()=>ne,T0:()=>ue,Yg:()=>ye,ZS:()=>Ee,bi:()=>$,br:()=>te,dO:()=>b,eP:()=>le,eh:()=>me,fx:()=>M,mJ:()=>h});var n=e(56375),a=e.n(n),t=e(16901),w=e(98724),y=e(76679),C=e(41460),u=e(5476),A=e(47689);const R=(c,T)=>Object.entries(c??{}).reduce((E,[B,_])=>[...E,{name:B,value:_,operator:T?t._M.regex:t._M.equal}],[]),f=c=>c.value,z=c=>(c??[]).map(f),M={name:"",value:"",operator:t._M.equal},F=["grafana_folder","alertname"],b=[{label:"grafana_folder",value:"grafana_folder"},{label:"alertname",value:"alertname"},{label:"Disable (...)",value:"..."}],se={id:"",overrideGrouping:!1,groupBy:F,object_matchers:[],routes:[],continue:!1,receiver:"",overrideTimings:!1,groupWaitValue:"",groupIntervalValue:"",repeatIntervalValue:"",muteTimeIntervals:[]};function te(c){return{id:(0,n.uniqueId)("route-"),...c,routes:(c.routes??[]).map(te)}}const Ee=c=>{if(!c)return se;const T="id"in c?c.id:(0,n.uniqueId)("route-");if(Object.keys(c).length===0)return{...se,id:T};const E=[];c.routes?.forEach(N=>{const de=Ee(N);E.push(de)});const B=c.object_matchers?.map(N=>({name:N[0],operator:N[1],value:N[2]}))??[],_=c.matchers?.map(N=>(0,w.cm)((0,C.tC)(N)))??[];return{id:T,object_matchers:[..._,...B,...R(c.match,!1),...R(c.match_re,!0)],continue:c.continue??!1,receiver:c.receiver??"",overrideGrouping:Array.isArray(c.group_by)&&c.group_by.length>0,groupBy:c.group_by??void 0,overrideTimings:[c.group_wait,c.group_interval,c.repeat_interval].some(Boolean),groupWaitValue:c.group_wait??"",groupIntervalValue:c.group_interval??"",repeatIntervalValue:c.repeat_interval??"",routes:E,muteTimeIntervals:c.mute_time_intervals??[]}},ye=(c,T,E)=>{const B=(0,u.Tx)(T.id??"",E),{overrideGrouping:_,groupBy:N,overrideTimings:de,groupWaitValue:Y,groupIntervalValue:Pe,repeatIntervalValue:$e,receiver:Be}=T,ge=void 0,Te=_?N:ge,K=de&&Y?Y:ge,ae=de&&Pe?Pe:ge,H=de&&$e?$e:ge,L=T.object_matchers?.filter(ie=>ie.name&&ie.value&&ie.operator).map(({name:ie,operator:Se,value:Ce})=>[ie,Se,Ce]),I=T.routes?.map(ie=>ye(c,ie,E)),J={...B??{},continue:T.continue,group_by:Te,object_matchers:L,match:void 0,match_re:void 0,group_wait:K,group_interval:ae,repeat_interval:H,routes:I,mute_time_intervals:T.muteTimeIntervals,receiver:Be};return c!==y.GC?(J.matchers=T.object_matchers?.map(({name:ie,operator:Se,value:Ce})=>`${ie}${Se}${Ce}`),J.object_matchers=void 0):(J.object_matchers=(0,C.QO)(J),J.matchers=void 0),T.receiver&&(J.receiver=T.receiver),J},ue=c=>({label:c,value:c}),me=c=>(c??[]).map(ue),h=c=>{if(c!==null)return c?f(c)??"":""},$=c=>c?z(c):[];function ne(c){return!c||c.length===0?!0:(0,A.wd)(c)||"Invalid duration format. Must be {number}{time_unit}"}const j=c=>c.map(T=>{const[E,B,_]=T;return`${E}${B}${_}`}),le=(c,T="")=>{if(c.length===0)return!0;const E=ne(c),B=ne(T);if(E!==!0)return E;if(B!==!0)return B;const _=(0,A.Bg)(c),N=(0,A.Bg)(T);return N!==0&&_<N?"Repeat interval should be higher or equal to Group interval":!0}},77250:(Oe,Z,e)=>{e.d(Z,{G:()=>n});function n(a,t){const w=a.replace(/\(copy( [0-9]+)?\)$/,"").trim();let y=`${w} (copy)`;for(let C=2;t.includes(y);C++)y=`${w} (copy ${C})`;return y}},5476:(Oe,Z,e)=>{e.d(Z,{SF:()=>w,Tx:()=>u,_P:()=>C,wB:()=>y});var n=e(56375),a=e.n(n),t=e(71803);const w=(A,R,f)=>{if(!u(R.id??"",f))throw new Error(`No such route with ID '${R.id}'`);function M(F){let b=F;if(F.id===R.id){const se=(0,t.Yg)(A,R,f);b=(0,n.omit)({...F,...se},"id")}return(0,n.omit)({...b,routes:F.routes?.map(M)},"id")}return M(f)},y=(A,R)=>{if(A.id===R.id)throw new Error("You cant remove the root policy");function f(z){return(0,n.omit)({...z,routes:z.routes?.reduce((M=[],F)=>(F.id===A.id||M.push(f(F)),M),[])},"id")}return f(R)},C=(A,R,f,z)=>{const M=(0,t.Yg)(A,R,z);function F(se){return se.id===f.id?{...se,routes:se.routes?.concat(M)}:{...se,routes:se.routes?.map(F)}}function b(se){return(0,n.omit)({...se,routes:se.routes?.map(b)},"id")}return b(F(z))};function u(A,R){return R.id===A?R:R.routes?.find(f=>u(A,f))}},34554:(Oe,Z,e)=>{e.d(Z,{K:()=>w});var n=e(66681),a=e(85960),t=e(53734);function w(C){const u=(0,t.wW)(y,C);return a.createElement("div",{className:u.root},C.children)}const y=(C,u)=>({root:(0,n.css)({display:"flex",flexDirection:u.direction??"row",flexWrap:u.wrap??!0?"wrap":void 0,alignItems:u.alignItems,gap:C.spacing(u.gap??2),flexGrow:u.flexGrow})})}}]);

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