"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5372],{85670:(C,i,e)=>{e.r(i),e.d(i,{default:()=>V});var t=e(66111),c=e(59679),f=e(53546),d=e(27876),m=e(9892),o=e(45253),y=e(72648),A=e(31403);function E({title:r,children:a}){return t.createElement(o.b,{className:(0,y.wW)(O).warning,severity:"warning",title:r},t.createElement("p",null,a),t.createElement(A.Qj,{href:"alerting/list"},"To rule list"))}const O=r=>({warning:m.css`
    margin: ${r.spacing(4)};
  `});var B=e(82897),T=e(37932),M=e(61744),p=e(32139),D=e(72004),W=e(35918),I=e(21767),v=e(79662),N=e(93411);function U({sourceRuleId:r}){const a=(0,d.useDispatch)(),{loading:g,value:l,error:n}=(0,c.Z)(()=>a((0,D.on)(r)).unwrap(),[r]);if(g)return t.createElement(M.u,{text:"Loading the rule"});if(l){const s=(0,B.cloneDeep)(l);F(s.rule,(0,W.G)((0,v.PW)(s.rule),s.group.rules.map(v.PW)));const u=(0,I.DQ)(s);return(0,v.Pc)(l.rule)&&Boolean(l.rule.grafana_alert.provenance)&&(u.group=""),t.createElement(p.p,{prefill:u})}return n?t.createElement(o.b,{title:"Error",severity:"error"},n.message):t.createElement(o.b,{title:"Cannot copy the rule. The rule does not exist",buttonContent:"Go back to alert list",onRemove:()=>T.E1.replace((0,N.u)("/alerting/list"))})}function F(r,a){(0,v.Pc)(r)&&(r.grafana_alert.title=a),(0,v.cG)(r)&&(r.alert=a),(0,v.yF)(r)&&(r.record=a)}var G=e(40014),K=e(44391),$=e(69945),j=e(46818),L=e(60048);function Y({identifier:r}){(0,G.x)(h=>h.unifiedAlerting.ruleForm.existingRule=j.oq);const{loading:a,result:g,error:l,dispatched:n}=(0,$._)(h=>h.ruleForm.existingRule),s=(0,d.useDispatch)(),{isEditable:u,loading:P}=(0,K.M)(L.s0(r),g?.rule),R=a||P;return(0,t.useEffect)(()=>{n||s((0,D.on)(r))},[n,s,r]),R||u===void 0?t.createElement(M.u,{text:"Loading rule..."}):l?t.createElement(o.b,{severity:"error",title:"Failed to load rule"},l.message):g?u===!1?t.createElement(E,{title:"Cannot edit rule"},"Sorry! You do not have permission to edit this rule."):t.createElement(p.p,{existing:g}):t.createElement(E,{title:"Rule not found"},"Sorry! This rule does not exist.")}var H=e(45524),Q=e(31808),Z=e(39910);const S={icon:"bell",id:"alert-rule-view",breadcrumbs:[{title:"Alert rules",url:"alerting/list"}]},J=r=>{if(r==="edit")return{...S,id:"alert-rule-edit",text:"Edit rule"};if(r==="add")return{...S,id:"alert-rule-add",text:"Add rule"}},z=({match:r})=>{const a=(0,d.useDispatch)(),[g]=(0,Q.j)(),{id:l}=r.params,n=L.OA(l,!0),s=g.get("copyFrom")??void 0,u=L.OA(s),{loading:P=!0}=(0,c.Z)(async()=>{n&&await a((0,D.nw)({rulesSourceName:n.ruleSourceName}))},[a]),{canCreateGrafanaRules:R,canCreateCloudRules:h,canEditRules:x}=(0,Z.B)(),X=(0,t.useCallback)(()=>{if(!P)return!n&&!R&&!h?t.createElement(E,{title:"Cannot create rules"},"Sorry! You are not allowed to create rules."):n&&!x(n.ruleSourceName)?t.createElement(E,{title:"Cannot edit rules"},"Sorry! You are not allowed to edit rules."):n?t.createElement(Y,{key:l,identifier:n}):u?t.createElement(U,{sourceRuleId:u}):t.createElement(p.p,null)},[h,R,x,u,l,n,P]);return t.createElement(H.J,{isLoading:P,pageId:"alert-list",pageNav:J(n?"edit":"add")},X())},V=(0,f.Pf)(z,{style:"page"})},31808:(C,i,e)=>{e.d(i,{j:()=>d});var t=e(66111),c=e(56895),f=e(37932);function d(){const{search:m}=(0,c.TH)(),o=(0,t.useMemo)(()=>new URLSearchParams(m),[m]),y=(0,t.useCallback)((A,E)=>{f.E1.partial(A,E)},[]);return[o,y]}},39910:(C,i,e)=>{e.d(i,{B:()=>f});var t=e(66111),c=e(97953);function f(){return(0,t.useMemo)(()=>(0,c.Rv)(),[])}},35918:(C,i,e)=>{e.d(i,{G:()=>t});function t(c,f){const d=c.replace(/\(copy( [0-9]+)?\)$/,"").trim();let m=`${d} (copy)`;for(let o=2;f.includes(m);o++)m=`${d} (copy ${o})`;return m}}}]);

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