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

//# sourceMappingURL=AlertingRuleForm.6ef06d41dd6912a31135.js.map