"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5516],{32606:(D,p,a)=>{a.r(p),a.d(p,{RedirectToRuleViewer:()=>S,default:()=>W});var e=a(74848),l=a(22803),$=a(96540),j=a(54148),L=a(87586),P=a(32370),T=a(28082),g=a(29675),f=a(37e3),F=a(81876),m=a(6210),I=a(79784),M=a(3429),N=a(54122);const U={icon:"bell",id:"alert-rule-view"};function c(s){const{wrapInContent:n=!0,children:t,title:d,renderTitle:o}=s,u=(0,g.of)(Z);return(0,e.jsx)(N.Y,{pageNav:{...U,text:d},renderTitle:o,navId:"alert-list",children:(0,e.jsx)(N.Y.Contents,{children:(0,e.jsx)("div",{className:u.content,children:n?(0,e.jsx)(V,{...s}):t})})})}function V({children:s,padding:n=2}){const t=(0,g.of)(w(n));return(0,e.jsx)("div",{className:t.wrapper,children:s})}const Z=s=>({content:(0,l.css)({maxWidth:`${s.breakpoints.values.xxl}px`})}),w=s=>n=>({wrapper:(0,l.css)({background:n.colors.background.primary,border:`1px solid ${n.colors.border.weak}`,borderRadius:n.shape.radius.default,padding:n.spacing(s)})});var A=a(8276),Y=a(88214),C=a(85651),R=a(68639),B=a(37104);const i="Find rule",y=P.$.appSubUrl;function E(){const s=(0,L.A)();return(0,$.useMemo)(()=>{const n=s.pathname?.replace(y,"").split("/")??[],t=(0,R.c)(decodeURIComponent((0,R.c)(n[3]))),d=decodeURIComponent(n[2]),o=new URLSearchParams(s.search);return{name:t,sourceName:d,namespace:o.get("namespace")??void 0,group:o.get("group")??void 0}},[s])}function S(){const s=(0,g.of)(H),{name:n,sourceName:t,namespace:d,group:o}=E(),{error:u,loading:z,rules:h=[]}=(0,A.we)(n,t,{namespace:d,groupName:o});if(!n||!t)return(0,e.jsx)(j.C5,{replace:!0,to:"/notfound"});if(u)return(0,e.jsx)(c,{title:i,children:(0,e.jsx)(f.F,{title:`Failed to load rules from ${t}`,children:(0,T.NF)(u)&&(0,e.jsxs)("details",{className:s.errorMessage,children:[u.message,(0,e.jsx)("br",{})]})})});if(z)return(0,e.jsx)(c,{title:i,children:(0,e.jsx)(F._,{text:"Loading rule..."})});const x=(0,Y.Zw)(t);if(!x)return(0,e.jsx)(c,{title:i,children:(0,e.jsx)(f.F,{title:"Could not view rule",children:(0,e.jsx)("details",{className:s.errorMessage,children:`Could not find data source with name: ${t}.`})})});if(h.length===1){const[r]=h,v=(0,C.w$)(x,r,"/alerting/list").replace(y,"");return(0,e.jsx)(j.C5,{replace:!0,to:v})}return h.length===0?(0,e.jsx)(c,{title:i,children:(0,e.jsxs)("div",{"data-testid":"no-rules",children:["No rules in ",(0,e.jsx)("span",{className:s.param,children:t})," matched the name"," ",(0,e.jsx)("span",{className:s.param,children:n})]})}):(0,e.jsxs)(c,{title:i,children:[(0,e.jsxs)("div",{children:["Several rules in ",(0,e.jsx)("span",{className:s.param,children:t})," matched the name"," ",(0,e.jsx)("span",{className:s.param,children:n}),", please select the rule you want to view."]}),(0,e.jsx)("div",{className:s.rules,children:h.map((r,v)=>(0,e.jsxs)(m.Z,{href:(0,C.w$)(x,r,"/alerting/list"),children:[(0,e.jsx)(m.Z.Heading,{children:r.name}),(0,e.jsxs)(m.Z.Meta,{separator:"",children:[(0,e.jsx)(I.I,{name:"folder"}),(0,e.jsx)("span",{className:s.namespace,children:`${r.namespace.name} / ${r.group.name}`})]}),(0,e.jsx)(m.Z.Tags,{children:(0,e.jsx)(M.m,{labels:r.labels})})]},`${r.name}-${v}`))})]})}function H(s){return{param:(0,l.css)({fontStyle:"italic",color:s.colors.text.secondary}),rules:(0,l.css)({marginTop:s.spacing(2)}),namespace:(0,l.css)({marginLeft:s.spacing(1)}),errorMessage:(0,l.css)({whiteSpace:"pre-wrap"})}}const W=(0,B.S)(S)}}]);

//# sourceMappingURL=AlertingRedirectToRule.30d4fd011b71b11ebbfa.js.map