"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4009],{50166:(Ve,re,e)=>{e.r(re),e.d(re,{default:()=>je});var n=e(96540),a=e(16817),t=e(66602),H=e(31678),x=e(32196),S=e(42418),g=e(40845),me=e(55852);function $({title:c,children:y}){return n.createElement(S.F,{className:(0,g.of)(U).warning,severity:"warning",title:c},n.createElement("p",null,y),n.createElement(me.z9,{href:"alerting/list"},"To rule list"))}const U=c=>({warning:(0,x.css)`
    margin: ${c.spacing(4)};
  `});var ve=e(2543),C=e(12131),R=e(39558),A=e(49785),Ee=e(58476),fe=e(52594),oe=e(32264),ce=e(66864),k=e(62930),ue=e(40276),ye=e(67061),Oe=e(96374),Pe=e(75269),Ne=e(3169),We=e(10096),m=e(40715),E=e(83277),_=e(25027),he=e(61410),ne=e(23770),V=e(86590),Ie=e(88467),se=e(63066),Be=e(18461),Te=e(79938),Ue=e(16293),we=e(76648),Je=e(84029);const F=({alertUid:c,exportFormat:y,onClose:N})=>{const{currentData:M="",isFetching:J}=Te.hK.endpoints.exportRules.useQuery({ruleUid:c,format:y}),T=`${c}-${new Date().getTime()}`;return J?n.createElement(R._,{text:"Loading...."}):n.createElement(Ue.J,{format:y,textDefinition:M,downloadFileName:T,onClose:N})},ae=({onClose:c,alertUid:y})=>{const[N,M]=(0,n.useState)("yaml");return n.createElement(we.m,{activeTab:N,onTabChange:M,onClose:c,formatProviders:Object.values(Je.sl)},n.createElement(F,{alertUid:y,exportFormat:N,onClose:c}))};var Z=e(53534),K=e(31099),v=e(88575),D=e(10354),h=e(88323),O=e(25968),w=e(7921);const ee=({rulesSourceName:c})=>{const{control:y,watch:N,formState:{errors:M},setValue:J}=(0,A.xW)(),T=(0,g.of)(Re),de=(0,he.$)(Me=>Me.rulerRules),z=(0,H.useDispatch)();(0,n.useEffect)(()=>{z((0,ne.eB)({rulesSourceName:c}))},[c,z]);const le=de[c]?.result,De=N("namespace"),ge=(0,n.useMemo)(()=>le?Object.keys(le).map(Me=>({label:Me,value:Me})):[],[le]),be=(0,n.useMemo)(()=>De&&le?.[De]?.map(Me=>({label:Me.name,value:Me.name}))||[],[De,le]);return n.createElement("div",{className:T.flexRow},n.createElement(v.D,{"data-testid":"namespace-picker",label:"Namespace",error:M.namespace?.message,invalid:!!M.namespace?.message},n.createElement(A.xI,{render:({field:{onChange:Me,ref:rt,...mt}})=>n.createElement(h.ip,{...mt,allowCustomValue:!0,className:T.input,onChange:Ce=>{J("group",""),Me(Ce.value)},options:ge,width:42}),name:"namespace",control:y,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:w.G0}}})),n.createElement(v.D,{"data-testid":"group-picker",label:"Group",error:M.group?.message,invalid:!!M.group?.message},n.createElement(A.xI,{render:({field:{ref:Me,...rt}})=>n.createElement(h.ip,{...rt,allowCustomValue:!0,options:be,width:42,onChange:mt=>{J("group",mt.value??"")},className:T.input}),name:"group",control:y,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:w.G0}}})))},Re=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 xe=e(67986),Qe=e(271);const st=()=>{const c=(0,g.of)(lt),{register:y,control:N,watch:M,formState:{errors:J}}=(0,A.xW)(),T=M("type"),de=M("dataSourceName");return n.createElement(Qe.P,{stepNo:3,title:"Set evaluation behavior"},n.createElement(v.D,{label:"Pending period",description:"Period in which an alert rule can be in breach of the condition until the alert rule fires."},n.createElement("div",{className:c.flexRow},n.createElement(v.D,{invalid:!!J.forTime?.message,error:J.forTime?.message,className:c.inlineField},n.createElement(D.p,{...y("forTime",{pattern:{value:/^\d+$/,message:"Must be a positive integer."}}),width:8})),n.createElement(A.xI,{name:"forTimeUnit",render:({field:{onChange:z,ref:le,...De}})=>n.createElement(h.l6,{...De,options:O.sc,onChange:ge=>z(ge?.value),width:15,className:c.timeUnit}),control:N}))),T===V.Z.cloudAlerting&&de&&n.createElement(ee,{rulesSourceName:de}),n.createElement(xe.L,null))},lt=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 ke=e(74400),at=e(9267);function it(){const{watch:c}=(0,A.xW)(),y=c("dataSourceName");return y?n.createElement(Qe.P,{stepNo:3,title:"Add namespace and group",description:"Select the Namespace and Group for your recording rule."},n.createElement(ee,{rulesSourceName:y})):null}var Ze=e(73716),Et=e(87855);const ct=({existing:c,prefill:y})=>{const N=(0,g.of)(St),M=(0,H.useDispatch)(),J=(0,Ne._2)(),[T]=(0,E.s)(),[de,z]=(0,n.useState)(!1),[le,De]=(0,n.useState)(c?.group.interval??se.pY),ge=(0,Ee.g)(),be=(0,w._u)(ge.type),Me=ge.id,rt=T.returnTo?String(T.returnTo):"/alerting/list",[mt,Ce]=(0,n.useState)(!1),Ct=(0,n.useMemo)(()=>c?(0,se.ir)(c):y?xt(y):typeof T.defaults=="string"?ht(T.defaults,be):{...(0,se.IJ)(),condition:"C",queries:(0,se.qO)(),type:be||V.Z.grafana,evaluateEvery:le},[c,y,T,le,be]),bt=(0,A.mN)({mode:"onSubmit",defaultValues:Ct,shouldFocusError:!0}),{handleSubmit:Pt,watch:ft}=bt,_e=ft("type"),Bt=ft("dataSourceName"),Wt=!!(_e&&(_e===V.Z.grafana||Bt)),tt=(0,he.$)(Se=>Se.ruleForm.saveRule)||Ie.jA;(0,m.o)(Se=>Se.unifiedAlerting.ruleForm.saveRule=Ie.jA);const[Dt,vt]=(0,n.useState)(""),Gt=(Se="")=>{vt(Se)},Tt=(Se,Qt)=>{if(Dt!==""){J.error(Dt);return}(0,_.nf)({formAction:c?"update":"create",ruleType:Se.type}),c||(Se.manualRouting?localStorage.setItem(se.Q8,"true"):localStorage.setItem(se.Q8,"false")),M((0,ne._$)({values:{...Ct,...Se,annotations:Se.annotations?.map(({key:nt,value:pt})=>({key:nt.trim(),value:pt.trim()})).filter(({key:nt,value:pt})=>!!nt&&!!pt)??[],labels:Se.labels?.map(({key:nt,value:pt})=>({key:nt.trim(),value:pt.trim()})).filter(({key:nt})=>!!nt)??[]},existing:c,redirectOnSave:Qt?rt:void 0,initialAlertRuleName:Ct.name,evaluateEvery:le}))},$t=()=>{if(c){const Se=Be.P1(c.ruleSourceName,c.namespace,c.group.name,c.rule);M((0,ne.KH)(Se,{navigateTo:"/alerting/list"}))}},At=Se=>{(0,_.IR)({grafana_version:oe.$.buildInfo.version,org_id:We.TP.user.orgId,user_id:We.TP.user.id,error:Object.keys(Se).toString(),formAction:c?"update":"create"}),J.error("There are errors in the form. Please correct them and try again!")},Ot=()=>{(0,_.fH)(_.le.cancelSavingAlertRule),(0,_.Rk)({formAction:c?"update":"create"})},Nt=ft("evaluateEvery");(0,n.useEffect)(()=>De(Nt),[Nt]);const wt=n.createElement(ce.Gy,{height:"auto",justify:"flex-end"},c&&n.createElement(me.$n,{variant:"primary",type:"button",size:"sm",onClick:Pt(Se=>Tt(Se,!1),At),disabled:tt.loading},tt.loading&&n.createElement(k.y,{className:N.buttonSpinner,inline:!0}),"Save rule"),n.createElement(me.$n,{variant:"primary",type:"button",size:"sm",onClick:Pt(Se=>Tt(Se,!0),At),disabled:tt.loading},tt.loading&&n.createElement(k.y,{className:N.buttonSpinner,inline:!0}),"Save rule and exit"),n.createElement(fe.Link,{to:rt},n.createElement(me.$n,{variant:"secondary",disabled:tt.loading,type:"button",onClick:Ot,size:"sm"},"Cancel")),c?n.createElement(me.$n,{fill:"outline",variant:"destructive",type:"button",onClick:()=>Ce(!0),size:"sm"},"Delete"):null,c&&yt(ft)&&n.createElement(me.$n,{variant:"secondary",type:"button",onClick:()=>z(!0),disabled:tt.loading,size:"sm"},"Edit YAML"));return n.createElement(A.Op,{...bt},n.createElement(Pe.H,{actions:wt}),n.createElement("form",{onSubmit:Se=>Se.preventDefault(),className:N.form},n.createElement("div",{className:N.contentOuter},n.createElement(ue.E,{autoHeightMin:"100%",hideHorizontalTrack:!0},n.createElement(ye.B,{direction:"column",gap:3},n.createElement(Z.G,null),n.createElement(Et.N,{editingExistingRule:!!c,onDataChange:Gt}),Wt&&n.createElement(n.Fragment,null,_e===V.Z.grafana&&n.createElement(ke.R,{evaluateEvery:le,setEvaluateEvery:De,existing:!!c,enableProvisionedGroups:!1}),_e===V.Z.cloudAlerting&&n.createElement(st,null),_e===V.Z.cloudRecording&&n.createElement(it,null),n.createElement(at.N,{alertUid:Me}),_e!==V.Z.cloudRecording&&n.createElement(K.A,null)))))),mt?n.createElement(Oe.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:$t,onDismiss:()=>Ce(!1)}):null,de?_e===V.Z.grafana?n.createElement(ae,{alertUid:Me,onClose:()=>z(!1)}):n.createElement(Ze.G_,{onClose:()=>z(!1)}):null)},yt=c=>{const[y,N]=c(["type","dataSourceName"]);return(y===V.Z.cloudAlerting||y===V.Z.cloudRecording)&&N!==""};function ht(c,y){let N;try{N=JSON.parse(c)}catch{return{...(0,se.IJ)(),queries:(0,se.qO)()}}return(0,se.Rk)({...(0,se.IJ)(),...N,annotations:(0,se.JE)(N.annotations??[]),queries:N.queries??(0,se.qO)(),type:y||V.Z.grafana,evaluateEvery:se.pY})}function xt(c){return(0,se.Rk)({...(0,se.IJ)(),...c})}const St=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 ut=e(79944),qe=e(23662),It=e(3704);function Rt({sourceRuleId:c}){const y=(0,H.useDispatch)(),{loading:N,value:M,error:J}=(0,a.A)(()=>y((0,ne.pT)(c)).unwrap(),[c]);if(N)return n.createElement(R._,{text:"Loading the rule"});if(M){const T=i(M),de=(0,se.QX)(T);return n.createElement(ct,{prefill:de})}return J?n.createElement(S.F,{title:"Error",severity:"error"},J.message):n.createElement(S.F,{title:"Cannot copy the rule. The rule does not exist",buttonContent:"Go back to alert list",onRemove:()=>C.Ny.replace((0,It.c)("/alerting/list"))})}function dt(c,y){(0,qe.lT)(c)&&(c.grafana_alert.title=y),(0,qe.$y)(c)&&(c.alert=y),(0,qe.i7)(c)&&(c.record=y)}function i(c){const y=(0,ve.cloneDeep)(c);return dt(y.rule,(0,ut.V)((0,qe.qz)(y.rule),y.group.rules.map(qe.qz))),(0,qe.lT)(y.rule)&&(y.rule.grafana_alert.uid="",y.rule.grafana_alert.provenance&&(y.group={name:"",rules:y.group.rules})),y}var P=e(97009);function b({identifier:c,id:y}){(0,m.o)(ge=>ge.unifiedAlerting.ruleForm.existingRule=Ie.jA);const{loading:N,result:M,error:J,dispatched:T}=(0,he.$)(ge=>ge.ruleForm.existingRule),de=(0,H.useDispatch)(),{isEditable:z,loading:le}=(0,P.g)(Be.VY(c),M?.rule),De=N||le;return(0,n.useEffect)(()=>{T||de((0,ne.pT)(c))},[T,de,c]),De||z===void 0?n.createElement(R._,{text:"Loading rule..."}):J?n.createElement(S.F,{severity:"error",title:"Failed to load rule"},J.message):M?z===!1?n.createElement($,{title:"Cannot edit rule"},"Sorry! You do not have permission to edit this rule."):n.createElement(ct,{existing:M}):n.createElement($,{title:"Rule not found"},"Sorry! This rule does not exist.")}var G=e(37959),Y=e(39964),pe=e(41520);const j={icon:"bell",id:"alert-rule-view"},q=(c,y)=>y==="recording"?c?{...j,id:"alert-rule-edit",text:"Edit recording rule"}:{...j,id:"alert-rule-add",text:"New recording rule"}:c?{...j,id:"alert-rule-edit",text:"Edit rule"}:{...j,id:"alert-rule-add",text:"New alert rule"},Ge=({match:c})=>{const y=(0,H.useDispatch)(),[N]=(0,Y.l)(),{type:M}=c.params,J=Be.uE(c.params),T=Be.x6(J,!0),de=N.get("copyFrom")??void 0,z=Be.x6(de),{loading:le=!0}=(0,a.A)(async()=>{T&&await y((0,ne.DC)({rulesSourceName:T.ruleSourceName})),z&&await y((0,ne.DC)({rulesSourceName:z.ruleSourceName}))},[y]),{canCreateGrafanaRules:De,canCreateCloudRules:ge,canEditRules:be}=(0,pe.V)(),Me=(0,n.useCallback)(()=>{if(!le)return!T&&!De&&!ge?n.createElement($,{title:"Cannot create rules"},"Sorry! You are not allowed to create rules."):T&&!be(T.ruleSourceName)?n.createElement($,{title:"Cannot edit rules"},"Sorry! You are not allowed to edit rules."):T?n.createElement(b,{key:J,identifier:T,id:J}):z?n.createElement(Rt,{sourceRuleId:z}):n.createElement(ct,null)},[ge,De,be,z,J,T,le]);return n.createElement(G.d,{isLoading:le,navId:"alert-list",pageNav:q(T,M)},Me())},je=(0,t.Xc)(Ge,{style:"page"})},69179:(Ve,re,e)=>{e.r(re),e.d(re,{default:()=>Je});var n=e(96540),a=e(16817),t=e(12131),H=e(39558),x=e(42418),S=e(31678),g=e(23770),me=e(63066),$=e(18461),U=e(23662),ve=e(3704),C=e(37959),R=e(49785),A=e(55852),Ee=e(40276),fe=e(67061),oe=e(3169),ce=e(83277),k=e(75269),ue=e(79938),ye=e(28220),Oe=e(730),Pe=e(57220),Ne=e(16293),We=e(76648),m=e(84029),E=e(53534),_=e(31099),he=e(74400),ne=e(9267),V=e(87855);function Ie({ruleForm:F,alertUid:ae}){const Z=(0,R.mN)({mode:"onSubmit",defaultValues:F,shouldFocusError:!0}),[K]=(0,ce.s)(),v=!!F,D=(0,oe._2)(),h=K.returnTo?String(K.returnTo):"/alerting/list",[O,w]=(0,n.useState)(void 0),[ee,Re]=(0,n.useState)(""),[xe,Qe]=(0,n.useState)(F?.evaluateEvery??me.pY),st=()=>{D.error("There are errors in the form. Please correct them and try again!")},lt=(Ze="")=>{Re(Ze)},ke=Ze=>{if(ee!==""){D.error(ee);return}w(Ze)},at=(0,n.useCallback)(()=>{w(void 0)},[w]),it=[n.createElement(A.z9,{href:h,key:"cancel",size:"sm",variant:"secondary",onClick:()=>ke(void 0)},"Cancel"),n.createElement(A.$n,{key:"export-rule",size:"sm",onClick:Z.handleSubmit(Ze=>ke(Ze),st)},"Export")];return n.createElement(n.Fragment,null,n.createElement(R.Op,{...Z},n.createElement(k.H,{actions:it}),n.createElement("form",{onSubmit:Ze=>Ze.preventDefault()},n.createElement("div",null,n.createElement(Ee.E,{autoHeightMin:"100%",hideHorizontalTrack:!0},n.createElement(fe.B,{direction:"column",gap:3},n.createElement(E.G,null),n.createElement(V.N,{editingExistingRule:v,onDataChange:lt}),n.createElement(he.R,{evaluateEvery:xe,setEvaluateEvery:Qe,existing:!!v,enableProvisionedGroups:!0}),n.createElement(ne.N,{alertUid:ae}),n.createElement(_.A,null))))),O&&n.createElement(we,{exportValues:O,onClose:at,uid:ae})))}const se=(F,ae)=>{const{dsFeatures:Z}=(0,Oe.O3)(Pe.hY),K=Z?.rulerConfig;return(0,a.A)(async()=>K?await(0,ye.HO)(K,F,ae):void 0,[K,F,ae])},Be=(F,ae,Z)=>{const K=(0,me.Z9)(ae),v={...K,grafana_alert:{...K.grafana_alert,uid:F}};if(Z?.rules){let D=!1;const h=Z.rules.map(O=>(0,U.lT)(O)&&O.grafana_alert.uid===F?(D=!0,v):O);return D||h.push(v),{...Z,rules:h}}else return{name:Z?.name??"",rules:[v]}},Te=(F,ae)=>{const Z=se(F.folder?.uid??"",F.group);return{payload:(0,n.useMemo)(()=>Be(ae,F,Z?.value),[ae,Z,F]),loadingGroup:Z.loading}},Ue=({exportFormat:F,exportValues:ae,onClose:Z,uid:K})=>{const[v,D]=ue.hK.endpoints.exportModifiedRuleGroup.useMutation(),{loadingGroup:h,payload:O}=Te(ae,K),w=ae.folder?.uid??"";if((0,n.useEffect)(()=>{!h&&v({payload:O,format:F,nameSpaceUID:w})},[w,F,O,v,h]),D.isLoading)return n.createElement(H._,{text:"Loading...."});const ee=`modify-export-${O.name}-${K}-${new Date().getTime()}`;return n.createElement(Ne.J,{format:F,textDefinition:D.data??"",downloadFileName:ee,onClose:Z})},we=n.memo(({onClose:F,exportValues:ae,uid:Z})=>{const[K,v]=(0,n.useState)("yaml");return n.createElement(We.m,{title:"Export Group",activeTab:K,onTabChange:v,onClose:F,formatProviders:Object.values(m.sl)},n.createElement(Ue,{exportFormat:K,onClose:F,exportValues:ae,uid:Z}))});we.displayName="GrafanaRuleDesignExporter";function Je({match:F}){const ae=(0,S.useDispatch)(),[Z,K]=(0,n.useState)(void 0);(0,n.useEffect)(()=>{const w=$.x6(F.params.id,!0);K(w)},[F.params.id]);const{loading:v=!0}=(0,a.A)(async()=>{Z&&await ae((0,g.DC)({rulesSourceName:Z.ruleSourceName}))},[ae,Z]),{loading:D,value:h,error:O}=(0,a.A)(async()=>{if(Z)return await ae((0,g.pT)(Z)).unwrap()},[Z,v]);return Z?D?n.createElement(H._,{text:"Loading the rule"}):O?n.createElement(x.F,{title:"Cannot load modify export",severity:"error"},O.message):!h&&!D&&!v?n.createElement(C.d,{isLoading:D,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,ve.c)("/alerting/list"))})):h&&!(0,U.lT)(h.rule)?n.createElement(C.d,{isLoading:D,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,ve.c)("/alerting/list"))})):n.createElement(C.d,{isLoading:D,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."}},h&&n.createElement(Ie,{ruleForm:(0,me.ir)(h),alertUid:F.params.id??""})):n.createElement("div",null,"Rule not found")}},33915:(Ve,re,e)=>{e.d(re,{V:()=>ve});var n=e(96540),a=e(10354),t=e(14578),H=e(35108),x=e(32196),S=e(40845),g=e(41068);function me(){const C=(0,S.of)(U);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:C.list},n.createElement("div",{className:C.header},n.createElement("div",null,"Symbol"),n.createElement("div",null,"Time unit"),n.createElement("div",null,"Example")),n.createElement($,{unit:g.y.seconds,name:"seconds",example:"20s"}),n.createElement($,{unit:g.y.minutes,name:"minutes",example:"10m"}),n.createElement($,{unit:g.y.hours,name:"hours",example:"4h"}),n.createElement($,{unit:g.y.days,name:"days",example:"3d"}),n.createElement($,{unit:g.y.weeks,name:"weeks",example:"2w"}),n.createElement("div",{className:C.examples},n.createElement("div",null,"Multiple units combined"),n.createElement("code",null,"1m30s, 2h30m20s, 1w2d"))))}function $({unit:C,name:R,example:A}){const Ee=(0,S.of)(U);return n.createElement(n.Fragment,null,n.createElement("div",{className:Ee.unit},C),n.createElement("div",null,R),n.createElement("code",null,A))}const U=C=>({unit:(0,x.css)`
    font-weight: ${C.typography.fontWeightBold};
  `,list:(0,x.css)`
    display: grid;
    grid-template-columns: max-content 1fr 2fr;
    gap: ${C.spacing(1,3)};
  `,header:(0,x.css)`
    display: contents;
    font-weight: ${C.typography.fontWeightBold};
  `,examples:(0,x.css)`
    display: contents;
    & > div {
      grid-column: 1 / span 2;
    }
  `}),ve=n.forwardRef((C,R)=>n.createElement(a.p,{suffix:n.createElement(H.j,{content:n.createElement(me,null),disabled:!1},n.createElement(t.I,{name:"info-circle",size:"lg"})),...C,ref:R}));ve.displayName="PromDurationInput"},99903:(Ve,re,e)=>{e.d(re,{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:(Ve,re,e)=>{e.d(re,{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:(Ve,re,e)=>{e.d(re,{H:()=>n});const n={group_wait:"30s",group_interval:"5m",repeat_interval:"4h"}},53534:(Ve,re,e)=>{e.d(re,{G:()=>$});var n=e(96540),a=e(49785),t=e(94753),H=e(88575),x=e(10354),S=e(86590),g=e(271);const me={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_:]*$/},$=()=>{const{register:U,watch:ve,formState:{errors:C}}=(0,a.xW)(),R=ve("type"),A=R===S.Z.cloudRecording?"recording rule":"alert rule";return n.createElement(g.P,{stepNo:1,title:`Enter ${A} name`,description:n.createElement(t.E,{variant:"bodySmall",color:"secondary"},"Enter a name to identify your ",A,".")},n.createElement(H.D,{label:"Name",error:C?.name?.message,invalid:!!C.name?.message},n.createElement(x.p,{id:"name",width:35,...U("name",{required:{value:!0,message:"Must enter a name"},pattern:R===S.Z.cloudRecording?me:void 0}),"aria-label":"name",placeholder:`Give your ${A} a name`})))}},9267:(Ve,re,e)=>{e.d(re,{N:()=>xt});var n=e(32196),a=e(96540),t=e(49785),H=e(32264),x=e(40845),S=e(67061),g=e(94753),me=e(94354),$=e(14578),U=e(86590),ve=e(57220),C=e(54749),R=e(64100),A=e(271),Ee=e(70383),fe=e(42418),oe=e(39558),ce=e(57418),k=e(13726),ue=e(79381),ye=e(77141);const Oe=({receivers:i})=>a.createElement(S.B,{direction:"column",gap:0},a.createElement("div",null,i.map((P,b)=>{const G=P[ue.MX],Y=P[ue.sW],pe=G.name+b;return a.createElement(k.ContactPointReceiverTitleRow,{key:pe,name:G.name,type:P.type,description:(0,ye.aM)(P),pluginMetadata:Y})})));var Pe=e(88575),Ne=e(88323),We=e(29158),m=e(72093),E=e(72109),_=e(3704);const he=500;function ne({alertManager:i,options:P,onSelectContactPoint:b,refetchReceivers:G}){const Y=(0,x.of)(Ie),{control:pe,watch:j,trigger:q}=(0,t.xW)(),Ge=j(`contactPoints.${i}.selectedContactPoint`),je=P.find(z=>z.value.name===Ge)?.value,c=je?{value:je,label:je.name}:{value:void 0,label:""},y=1e3,[N,M]=(0,a.useState)(!1),J=z=>new Promise(le=>setTimeout(le,z)),T=(0,a.useCallback)(()=>{Ge&&q(`contactPoints.${i}.selectedContactPoint`,{shouldFocus:!0})},[i,Ge,q]),de=()=>{M(!0),Promise.all([G(),J(y)]).finally(()=>{M(!1),T()})};return(0,a.useEffect)(()=>{T()},[T]),a.createElement(S.B,{direction:"column"},a.createElement(S.B,{direction:"row",alignItems:"center"},a.createElement(Pe.D,{label:"Contact point","data-testid":"contact-point-picker"},a.createElement(t.xI,{render:({field:{onChange:z,ref:le,...De},fieldState:{error:ge}})=>a.createElement(a.Fragment,null,a.createElement("div",{className:Y.contactPointsSelector},a.createElement(Ne.l6,{virtualized:P.length>he,"aria-label":"Contact point",defaultValue:c,onChange:(be,Me)=>{z(be?.value?.name),b(be?.value)},options:P,width:50}),a.createElement("div",{className:Y.contactPointsInfo},a.createElement(We.K,{name:"sync",onClick:de,"aria-label":"Refresh contact points",tooltip:"Refresh contact points list",className:(0,n.cx)(Y.refreshButton,{[Y.loading]:N})}),a.createElement(V,null))),ge&&a.createElement(m.P,null,ge?.message)),rules:{required:{value:!0,message:"Contact point is required."},validate:{contactPointExists:z=>P.some(le=>le.value.name===z)?!0:`Contact point ${Ge} does not exist.`}},control:pe,name:`contactPoints.${i}.selectedContactPoint`}))))}function V(){return a.createElement(E.Y,{external:!0,href:(0,_.c)("/alerting/notifications"),"aria-label":"View or create contact points"},"View or create contact points")}const Ie=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 se=e(82843),Be=e(98164),Te=e(79657),Ue=e(99903);function we({alertManager:i}){const P=(0,x.of)(Ue.t),{control:b,formState:{errors:G}}=(0,t.xW)(),Y=Je();return a.createElement(Pe.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(t.xI,{render:({field:{onChange:pe,ref:j,...q}})=>a.createElement(Ne.KF,{"aria-label":"Mute timings",...q,className:P.input,onChange:Ge=>pe((0,Te.ie)(Ge)),options:Y,placeholder:"Select mute timings..."}),control:b,name:`contactPoints.${i}.muteTimeIntervals`}))}function Je(){return se.m.endpoints.getMuteTimingList.useQuery(void 0,{refetchOnFocus:!0,refetchOnReconnect:!0,selectFromResult:P=>({...P,mutetimings:P.data?P.data.map(b=>({value:b.name,label:b.name,description:b.time_intervals.map(G=>(0,Be.LF)(G)).join(", AND ")})):[]})}).mutetimings}var F=e(14186),ae=e(15292),Z=e(5342),K=e(27835),v=e(33915),D=e(97174);function h({alertManager:i}){const P=(0,x.of)(Ue.t),{register:b,formState:{errors:G},getValues:Y}=(0,t.xW)();return a.createElement(a.Fragment,null,a.createElement(Pe.D,{label:D.G.groupWait.label,description:D.G.groupWait.description,invalid:!!G.contactPoints?.[i]?.groupWaitValue,error:G.contactPoints?.[i]?.groupWaitValue?.message},a.createElement(v.V,{...b(`contactPoints.${i}.groupWaitValue`,{validate:Te.hH}),"aria-label":D.G.groupWait.ariaLabel,className:P.promDurationInput,placeholder:K.H.group_wait})),a.createElement(Pe.D,{label:D.G.groupInterval.label,description:D.G.groupInterval.description,invalid:!!G.contactPoints?.[i]?.groupIntervalValue,error:G.contactPoints?.[i]?.groupIntervalValue?.message},a.createElement(v.V,{...b(`contactPoints.${i}.groupIntervalValue`,{validate:Te.hH}),"aria-label":D.G.groupInterval.ariaLabel,className:P.promDurationInput,placeholder:K.H.group_interval})),a.createElement(Pe.D,{label:D.G.repeatInterval.label,description:D.G.repeatInterval.description,invalid:!!G.contactPoints?.[i]?.repeatIntervalValue,error:G.contactPoints?.[i]?.repeatIntervalValue?.message},a.createElement(v.V,{...b(`contactPoints.${i}.repeatIntervalValue`,{validate:pe=>{const j=Y(`contactPoints.${i}.repeatIntervalValue`);return(0,Te.DY)(pe,j)}}),"aria-label":D.G.repeatInterval.ariaLabel,className:P.promDurationInput,placeholder:K.H.repeat_interval})))}const O=["grafana_folder","alertname"],w={groupWaitValue:K.H.group_wait,groupIntervalValue:K.H.group_interval,repeatIntervalValue:K.H.repeat_interval},ee="...",Re=({alertManager:i})=>{const P=(0,x.of)(Ue.t),{control:b,watch:G,register:Y,setValue:pe,formState:{errors:j}}=(0,t.xW)(),[q,Ge]=(0,a.useState)((0,Te.gY)([])),{groupIntervalValue:je,groupWaitValue:c,repeatIntervalValue:y}=w,N=G(`contactPoints.${i}.overrideGrouping`),M=G(`contactPoints.${i}.overrideTimings`),J=G(`contactPoints.${i}.groupBy`)?.length??0,T=(0,x.of)(xe);return(0,a.useEffect)(()=>{N&&J===0&&pe(`contactPoints.${i}.groupBy`,O)},[N,pe,i,J]),a.createElement(S.B,{direction:"column"},a.createElement(S.B,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between"},a.createElement(F.I,{label:"Override grouping",transparent:!0,className:T.switchElement},a.createElement(ae.d,{id:"override-grouping-toggle",...Y(`contactPoints.${i}.overrideGrouping`)})),!N&&a.createElement(g.E,{variant:"body",color:"secondary"},"Grouping: ",a.createElement("strong",null,O.join(", ")))),N&&a.createElement(Pe.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.",...Y(`contactPoints.${i}.groupBy`),invalid:!!j.contactPoints?.[i]?.groupBy,className:T.optionalContent},a.createElement(t.xI,{rules:{validate:de=>!de||de.length===0?"At least one group by option is required.":de.length===1&&de[0]===ee||O.every(le=>de.includes(le))?!0:`Group by must include ${O.join(", ")}`},render:({field:{onChange:de,ref:z,...le},fieldState:{error:De}})=>a.createElement(a.Fragment,null,a.createElement(Ne.KF,{"aria-label":"Group by",...le,allowCustomValue:!0,className:P.input,onCreateOption:ge=>{Ge(be=>[...be,(0,Te.Mk)(ge)]),pe(`contactPoints.${i}.groupBy`,[...le.value,ge])},onChange:ge=>de((0,Te.ie)(ge)),options:[...Te.Yl,...q],components:{MultiValueRemove(ge){const{data:be}=ge;return be.isFixed?null:(0,Z.p)(ge)}}}),De&&a.createElement(m.P,null,De.message)),name:`contactPoints.${i}.groupBy`,control:b})),a.createElement(S.B,{direction:"row",gap:1,alignItems:"center",justifyContent:"space-between"},a.createElement(F.I,{label:"Override timings",transparent:!0,className:T.switchElement},a.createElement(ae.d,{id:"override-timings-toggle",...Y(`contactPoints.${i}.overrideTimings`)})),!M&&a.createElement(g.E,{variant:"body",color:"secondary"},"Group wait: ",a.createElement("strong",null,c,", "),"Group interval: ",a.createElement("strong",null,je,", "),"Repeat interval: ",a.createElement("strong",null,y))),M&&a.createElement("div",{className:T.optionalContent},a.createElement(h,{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 Qe({alertManager:i}){const P=(0,x.of)(st),b=i.name,{isLoading:G,error:Y,contactPoints:pe,refetchReceivers:j}=(0,ue.dK)({includePoliciesCount:!1,receiverStatusPollingInterval:0}),[q,Ge]=(0,a.useState)(),je=M=>{Ge(M)},{watch:c}=(0,t.xW)(),y=c(`contactPoints.${b}.overrideGrouping`)||c(`contactPoints.${b}.overrideTimings`)||c(`contactPoints.${b}.muteTimeIntervals`)?.length>0,N=pe.map(M=>{const J=M?.grafana_managed_receiver_configs,T=a.createElement(k.ContactPointReceiverSummary,{receivers:J??[]});return{label:M.name,value:M,description:T}});return Y?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:P.firstAlertManagerLine}),a.createElement("div",{className:P.alertManagerName},"Alert manager:",a.createElement("img",{src:i.imgUrl,alt:"Alert manager logo",className:P.img}),b),a.createElement("div",{className:P.secondAlertManagerLine})),a.createElement(S.B,{direction:"row",gap:1,alignItems:"center"},a.createElement(ne,{alertManager:b,options:N,onSelectContactPoint:je,refetchReceivers:j})),q?.grafana_managed_receiver_configs&&a.createElement(Oe,{receivers:q.grafana_managed_receiver_configs}),a.createElement("div",{className:P.routingSection},a.createElement(ce.M,{label:"Muting, grouping and timings (optional)",isOpen:y,className:P.collapsableSection},a.createElement(S.B,{direction:"column",gap:1},a.createElement(we,{alertManager:b}),a.createElement(Re,{alertManager:b})))))}const st=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 lt(){const{getValues:i}=(0,t.xW)(),P=i("contactPoints"),Y=(0,ve.sq)("notification").availableInternalDataSources.filter(j=>j.hasConfigurationAPI);return(0,a.useMemo)(()=>Y.map(j=>{const q=P?P[j.name]:void 0;return{alertManager:j,selectedContactPoint:q?.selectedContactPoint??"",routeSettings:{muteTimeIntervals:q?.muteTimeIntervals??[],overrideGrouping:q?.overrideGrouping??!1,groupBy:q?.groupBy??[],overrideTimings:q?.overrideTimings??!1,groupWaitValue:q?.groupWaitValue??"",groupIntervalValue:q?.groupIntervalValue??"",repeatIntervalValue:q?.repeatIntervalValue??""}}}),[Y,P]).map((j,q)=>a.createElement(Ee.b9,{accessType:"notification",alertmanagerSourceName:j.alertManager.name,key:j.alertManager.name+q},a.createElement(Qe,{alertManager:j.alertManager})))}var ke=e(2543),at=e(55852),it=e(79938),Ze=e(87286);const Et=(0,a.lazy)(()=>e.e(9711).then(e.bind(e,39711))),ct=({alertQueries:i,customLabels:P,condition:b,folder:G,alertName:Y,alertUid:pe})=>{const j=(0,x.of)(yt),q=!b||!G,Ge=it.hK.endpoints.preview,[je,{data:c=[],isLoading:y,isUninitialized:N}]=Ge.useMutation(),M=(0,ke.compact)(c.flatMap(z=>z?.labels)),J=()=>{!G||!b||je({alertQueries:i,condition:b,customLabels:P,folder:G,alertName:Y,alertUid:pe})},T=(0,ve.cy)("notification"),de=T.length===1;return a.createElement(Ze.B,{direction:"column"},a.createElement("div",{className:j.routePreviewHeaderRow},a.createElement("div",{className:j.previewHeader},a.createElement(g.E,{element:"h5"},"Alert instance routing preview"),y&&N&&a.createElement(g.E,{color:"secondary",variant:"bodySmall"},"Loading..."),N?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:j.button},a.createElement(at.$n,{icon:"sync",variant:"secondary",type:"button",onClick:J,disabled:q},"Preview routing"))),!y&&!N&&M.length>0&&a.createElement(a.Suspense,{fallback:a.createElement(oe._,{text:"Loading preview..."})},T.map(z=>a.createElement(Et,{alertManagerSource:z,potentialInstances:M,onlyOneAM:de,key:z.name}))))},yt=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 ht=(i=>(i.NotificationPolicy="notification policy",i.ContactPoint="contact point",i))(ht||{});const xt=({alertUid:i})=>{const{watch:P}=(0,t.xW)(),b=(0,x.of)(dt),[G]=P(["type","labels","queries","condition","folder","name","manualRouting"]),Y=P("dataSourceName")??ve.hY,pe=H.$.featureToggles.alertingSimplifiedRouting??!1,j=G===U.Z.grafana,q=G===U.Z.grafana&&pe;return a.createElement(A.P,{stepNo:4,title:G===U.Z.cloudRecording?"Add labels":"Configure labels and notifications",description:a.createElement(S.B,{direction:"row",gap:.5,alignItems:"baseline"},G===U.Z.cloudRecording?a.createElement(g.E,{variant:"bodySmall",color:"secondary"},"Add labels to help you better manage your recording rules"):q&&a.createElement(g.E,{variant:"bodySmall",color:"secondary"},"Select who should receive a notification when an alert rule fires.")),fullWidth:!0},a.createElement(C.A,{dataSourceName:Y}),q&&a.createElement("div",{className:b.configureNotifications},a.createElement(g.E,{element:"h5"},"Notifications"),a.createElement(g.E,{variant:"bodySmall",color:"secondary"},"Select who should receive a notification when an alert rule fires.")),q?a.createElement(St,{alertUid:i}):j?a.createElement(ut,{alertUid:i}):null)};function St({alertUid:i}){const{watch:P,setValue:b}=(0,t.xW)(),G=(0,x.of)(dt),[Y]=P(["manualRouting"]),pe=[{label:"Select contact point",value:"contact point"},{label:"Use notification policy",value:"notification policy"}],j=q=>{b("manualRouting",q==="contact point")};return a.createElement(S.B,{direction:"column"},a.createElement(S.B,{direction:"column"},a.createElement(me.z,{options:pe,value:Y?"contact point":"notification policy",onChange:j,className:G.routingOptions})),a.createElement(Rt,{manualRouting:Y}),Y?a.createElement(lt,null):a.createElement(ut,{alertUid:i}))}function ut({alertUid:i}){const{watch:P}=(0,t.xW)(),[b,G,Y,pe,j]=P(["labels","queries","condition","folder","name","manualRouting"]);return a.createElement(ct,{alertQueries:G,customLabels:b,condition:Y,folder:pe,alertName:j,alertUid:i})}function qe(){return a.createElement(R.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($.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($.I,{name:"external-link-alt"}))))),title:"Notification routing"})}function It(){return a.createElement(R.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 Rt=({manualRouting:i})=>{const P=(0,x.of)(dt);return a.createElement("div",{className:P.notificationsOptionDescription},a.createElement(g.E,{variant:"bodySmall",color:"secondary"},i?"Notifications for firing alerts are routed to a selected contact point.":"Notifications for firing alerts are routed to contact points based on matching labels and the notification policy tree."),i?a.createElement(It,null):a.createElement(qe,null))},dt=i=>({routingOptions:(0,n.css)({marginTop:i.spacing(2),width:"fit-content"}),configureNotifications:(0,n.css)({display:"flex",flexDirection:"column",gap:i.spacing(1),marginTop:i.spacing(2)}),notificationsOptionDescription:(0,n.css)({marginTop:i.spacing(1),display:"flex",flexDirection:"row",alignItems:"baseline",gap:i.spacing(.5)})})},67986:(Ve,re,e)=>{e.d(re,{L:()=>Je,g:()=>F});var n=e(32196),a=e(96540),t=e(49785),H=e(1604),x=e(46662),S=e(72724),g=e(39070),me=e(19347),$=e(40845),U=e(66864),ve=e(55852),C=e(42418),R=e(62467),A=e(81160),Ee=e(66847),fe=e(1005),oe=e(72495),ce=e(89667),k=e(43127),ue=e(17172),ye=e(12091);function Oe(v){return"expr"in v}function Pe(v){return"grafana_condition"in v}var Ne=e(86590),We=e(57220);function m(v){if(Oe(v))return E(v,v.dataSourceUid,Ne.Z.cloudAlerting);if(Pe(v))return E(v,We.hY,Ne.Z.grafana);throw new Error("unsupported preview rule request")}function E(v,D,h){return(0,oe.k)({whileLoading:_(h),source:(0,ue.AI)().fetch({method:"POST",url:`/api/v1/rule/test/${D}`,data:v}).pipe((0,A.T)(({data:O})=>_(h,{state:g.Gu.Done,series:O.instances.map(ce.or)})),(0,Ee.W)(O=>(0,R.of)(_(h,{state:g.Gu.Error,error:(0,ye.u)(O)}))),(0,fe.u)())})}function _(v,D={}){return{ruleType:v,data:{state:g.Gu.Loading,series:[],timeRange:(0,k.E2)(),...D}}}var he=e(36135),ne=e(70713),V=e(1173),Ie=e(24308),se=e(52622),Be=e(88467);function Te(v){const{preview:D}=v,h=(0,$.of)(Ue),O={defaults:{},overrides:[{matcher:{id:V.Ct.byName,options:"Info"},properties:[{id:"custom.displayMode",value:se.ob.JSONView}]}]};if(!D)return null;const{data:w,ruleType:ee}=D;return w.state===g.Gu.Loading?a.createElement("div",{className:h.container},a.createElement("span",null,"Loading preview...")):w.state===g.Gu.Error?a.createElement("div",{className:h.container},w.error?(0,Be.CZ)(w.error):"Failed to preview alert rule"):a.createElement("div",{className:h.container},a.createElement("span",null,"Preview based on the result of running the query, for this moment."," ",ee===Ne.Z.grafana?"Configuration for `no data` and `error handling` is not applied.":null),a.createElement("div",{className:h.table},a.createElement(ne.Ay,null,({width:Re,height:xe})=>a.createElement("div",{style:{width:`${Re}px`,height:`${xe}px`}},a.createElement(Ie.m,{title:"",width:Re,height:xe,pluginId:"table",data:w,fieldConfig:O})))))}function Ue(v){return{container:(0,n.css)`
      margin: ${v.spacing(2)} 0;
    `,table:(0,n.css)`
      flex: 1 1 auto;
      height: 135px;
      margin-top: ${v.spacing(2)};
      border: 1px solid ${v.colors.border.medium};
      border-radius: ${v.shape.radius.default};
    `}}const we=["type","dataSourceName","condition","queries","expression"];function Je(){const v=(0,$.of)(K),[D,h]=F(),{watch:O}=(0,t.xW)(),[w,ee,Re]=O(["type","condition","queries"]),{allDataSourcesAvailable:xe}=(0,he.g)(Re);if(w===Ne.Z.cloudRecording||w===Ne.Z.cloudAlerting)return null;const Qe=!!ee&&xe;return a.createElement("div",{className:v.container},a.createElement(U.Gy,null,xe&&a.createElement(ve.$n,{disabled:!Qe,type:"button",variant:"primary",onClick:h},"Preview alerts"),!xe&&a.createElement(C.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(Te,{preview:D}))}function F(){const[v,D]=(0,a.useState)(),{getValues:h}=(0,t.xW)(),O=(0,H.A)(),w=(0,a.useCallback)(()=>{const ee=h(we),Re=ae(ee);m(Re).pipe((0,x.v)(xe=>!Z(xe),!0)).subscribe(xe=>{O()&&D(xe)})},[h,O]);return[v,w]}function ae(v){const[D,h,O,w,ee]=v,Re=(0,me.l)().getInstanceSettings(h);if(!Re)throw new Error(`Cannot find data source settings for ${h}`);switch(D){case Ne.Z.cloudAlerting:return{dataSourceUid:Re.uid,dataSourceName:h,expr:ee};case Ne.Z.grafana:return{grafana_condition:{condition:O,data:w,now:(0,S.M7)(Date.now())}};default:throw new Error(`Alert type ${D} not supported by preview.`)}}function Z(v){switch(v.data.state){case g.Gu.Done:case g.Gu.Error:return!0;default:return!1}}function K(v){return{container:(0,n.css)`
      margin-top: ${v.spacing(2)};
      max-width: ${v.breakpoints.values.xxl}px;
    `}}},87855:(Ve,re,e)=>{e.d(re,{N:()=>cn});var n=e(32196),a=e(2543),t=e(96540),H=e(49785),x=e(43127),S=e(13544),g=e(19347),me=e(32264),$=e(40845),U=e(67061),ve=e(88575),C=e(56034),R=e(55852),A=e(42418),Ee=e(38138),fe=e(64539),oe=e(83122),ce=e(14578),k=e(94753),ue=e(69437),ye=e(66718),Oe=e(31678),Pe=e(57220),Ne=e(61410);function We(){const o=(0,Ne.$)(r=>r.dataSources);return Object.values(o).map(r=>r.result).filter(r=>!!r?.rulerConfig).map(r=>(0,Pe.oh)(r.name)).filter(r=>!!r)}var m=e(23770),E=e(86590),_=e(63066),he=e(16817),ne=e(39070),V=e(76287),Ie=e(41987),se=e(64149),Be=e(75214),Te=e(30423),Ue=e(94822);function we({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)),f=o[r]?.values.length??0,p=[];for(let u=0;u<f;u++){const Q=d.map(ie=>[o[ie].name,o[ie].values[u]]),te=o[r]?.values?.[u],L=o[l]?.values?.[u];(0,Ue.s1)(te)&&p.push({state:te,info:L,labels:Object.fromEntries(Q)})}return{instances:p}}function Je({preview:o}){const s=(0,$.of)(F),r=we(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:f},p)=>{const u=(0,Be.M4)(f);return t.createElement("tr",{key:p},t.createElement("td",null,t.createElement(Te.C,{state:l})),t.createElement("td",null,t.createElement(se.L,{tags:u,className:s.tagList})),t.createElement("td",null,d&&t.createElement(C.m,{content:d},t.createElement(ce.I,{name:"info-circle"}))))})))}const F=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 ae=e(67986);const Z=({value:o,onChange:s,dataSourceName:r,showPreviewAlertsButton:l=!0})=>{const d=(0,$.of)(K),{mapToValue:f,mapToQuery:p}=v(r),u=p({refId:"A",hide:!1},o),{error:Q,loading:te,value:L}=(0,he.A)(()=>(0,g.l)().get(r),[r]),ie=(0,t.useCallback)(He=>{s(f(He))},[s,f]),[$e,W]=(0,ae.g)(),B=async()=>{W()};if(te||L?.name!==r)return null;const Le=(0,g.l)().getInstanceSettings(r);if(Q||!L||!L?.components?.QueryEditor||!Le){const He=Q?.message||"Data source plugin does not export any Query Editor component";return t.createElement("div",null,"Could not load query editor due to: ",He)}const Fe=$e?.data.state===ne.Gu.Done,ze=L?.components?.QueryEditor,Xe=$e?.data?.series?.find(He=>He.name==="evaluation results"),ot=Xe&&Xe.fields.some(He=>He.values.length>0);return t.createElement(t.Fragment,null,t.createElement(V.p,{instanceSettings:Le},t.createElement(ze,{query:u,queries:[u],app:Ie.Jk.CloudAlerting,onChange:ie,onRunQuery:a.noop,datasource:L})),l&&t.createElement("div",{className:d.preview},t.createElement(R.$n,{type:"button",onClick:B,disabled:$e?.data.state===ne.Gu.Loading},"Preview alerts"),Fe&&!ot&&t.createElement(A.F,{title:"Alerts preview",severity:"info",className:d.previewAlert},"There are no firing alerts for your query."),ot&&t.createElement(Je,{preview:Xe})))},K=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 v(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 D=e(56528),h=e(7921);const O=({condition:o,onSetCondition:s,queries:r,panelData:l,onUpdateRefId:d,onRemoveExpression:f,onUpdateExpressionType:p,onUpdateQueryExpression:u})=>{const Q=(0,t.useMemo)(()=>r.reduce((L,ie)=>(0,ue.f)(ie.model)?L.concat(ie.model):L,[]),[r]),te=(0,$.of)(w);return t.createElement("div",{className:te.wrapper},Q.map(L=>{const ie=l[L.refId],$e=o===L.refId,W=ie?(0,h.lb)(ie):void 0,B=ie?(0,h.yr)(ie.series):void 0;return t.createElement(D.r4,{key:L.refId,isAlertCondition:$e,data:ie,error:W,warning:B,queries:r,query:L,onSetCondition:s,onRemoveExpression:f,onUpdateRefId:d,onUpdateExpressionType:p,onChangeQuery:u})}))},w=o=>({wrapper:(0,n.css)`
    display: flex;
    gap: ${o.spacing(2)};
    align-content: stretch;
    flex-wrap: wrap;
  `});var ee=e(64100),Re=e(55244),xe=e(65879),Qe=e(10860),st=e(7788),lt=e(31193),ke=e(14186),at=e(10354),it=e(65160),Ze=e(25968),Et=e(81875),ct=e(47232),yt=e(60782),ht=e(5308);const xt=({query:o,queryOptions:s,onChangeTimeRange:r,onChangeQueryOptions:l,index:d})=>{const f=(0,$.of)(St),[p,u]=(0,t.useState)(!1),Q=o.relativeTimeRange?(0,xe.relativeToTimeRange)(o.relativeTimeRange):void 0;return t.createElement(t.Fragment,null,t.createElement(yt.G,{content:t.createElement("div",{className:f.queryOptions},r&&t.createElement(ke.I,{label:"Time Range"},t.createElement(ht.N,{timeRange:o.relativeTimeRange??(0,x.Cn)(),onChange:te=>r(te,d)})),t.createElement(i,{options:s,onChange:te=>l(te,d)}),t.createElement(P,{options:s,onChange:te=>l(te,d)})),closeButton:!0,placement:"bottom-start"},t.createElement("button",{type:"button",className:f.actionLink,onClick:()=>u(!p)},"Options ",p?t.createElement(ce.I,{name:"angle-right"}):t.createElement(ce.I,{name:"angle-down"}))),t.createElement("div",{className:f.staticValues},t.createElement("span",null,(0,ct.KQ)(Q?.from).locale("en").fromNow(!0)),s.maxDataPoints&&t.createElement("span",null,", MD = ",s.maxDataPoints),s.minInterval&&t.createElement("span",null,", Min. Interval = ",s.minInterval)))},St=o=>{const s=(0,R.my)(o);return{queryOptions:(0,n.css)`
      > div {
        justify-content: space-between;
      }
    `,staticValues:(0,n.css)`
      color: ${o.colors.text.secondary};
      margin-right: ${o.spacing(1)};
    `,actionLink:(0,n.css)`
      ${s};
      color: ${o.colors.text.link};
      cursor: pointer;

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