"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7918],{81471:(G,I,e)=>{e.r(I),e.d(I,{RedirectToRuleViewer:()=>$,default:()=>_});var g=e(52423),s=e(68404),O=e(70356),f=e(44870),P=function(l){var E=window.history,m=E[l];E[l]=function(M){var p=m.apply(this,arguments),D=new Event(l.toLowerCase());return D.state=M,window.dispatchEvent(D),p}};f.jU&&(P("pushState"),P("replaceState"));var U=function(){return{trigger:"load",length:1}},T=function(l){var E=window.history,m=E.state,M=E.length,p=window.location,D=p.hash,V=p.host,x=p.hostname,L=p.href,b=p.origin,Z=p.pathname,j=p.port,S=p.protocol,F=p.search;return{trigger:l,state:m,length:M,hash:D,host:V,hostname:x,href:L,origin:b,pathname:Z,port:j,protocol:S,search:F}},B=function(){var l=(0,s.useState)(T("load")),E=l[0],m=l[1];return(0,s.useEffect)(function(){var M=function(){return m(T("popstate"))},p=function(){return m(T("pushstate"))},D=function(){return m(T("replacestate"))};return(0,f.on)(window,"popstate",M),(0,f.on)(window,"pushstate",p),(0,f.on)(window,"replacestate",D),function(){(0,f.S1)(window,"popstate",M),(0,f.S1)(window,"pushstate",p),(0,f.S1)(window,"replacestate",D)}},[]),E},W=typeof Event=="function";const R=f.jU&&W?B:U;var h=e(35645),y=e(72648),A=e(45253),d=e(61744),i=e(72948),v=e(39904),t=e(53546),a=e(52694),n=e(28104),o=e(76277),u=e(45849),r=e(10505);const c="Find rule",C=h.v.appSubUrl;function K(){const E=R().pathname?.replace(C,"").split("/")??[],m=decodeURIComponent(E[3]),M=decodeURIComponent(E[2]);return{name:m,sourceName:M}}function $(){const l=(0,y.wW)(w),{name:E,sourceName:m}=K(),{error:M,loading:p,result:D,dispatched:V}=(0,o.X)(E,m);if(M)return s.createElement(n.$,{title:c},s.createElement(A.b,{title:`Failed to load rules from ${m}`},s.createElement("details",{className:l.errorMessage},M.message,s.createElement("br",null),!!M?.stack&&M.stack)));if(p||!V||!Array.isArray(D))return s.createElement(n.$,{title:c},s.createElement(d.u,{text:"Loading rule..."}));if(!E||!m)return s.createElement(O.l_,{to:"/notfound"});const x=(0,u.o_)(m);if(!x)return s.createElement(n.$,{title:c},s.createElement(A.b,{title:"Could not view rule"},s.createElement("details",{className:l.errorMessage},`Could not find data source with name: ${m}.`)));if(D.length===1){const[L]=D,b=(0,r.V2)(x,L,"/alerting/list").replace(C,"");return s.createElement(O.l_,{to:b})}return s.createElement(n.$,{title:c},s.createElement("div",null,"Several rules in ",s.createElement("span",{className:l.param},m)," matched the name"," ",s.createElement("span",{className:l.param},E),", please select the rule you want to view."),s.createElement("div",{className:l.rules},D.map((L,b)=>s.createElement(i.Z,{key:`${L.name}-${b}`,href:(0,r.V2)(x,L,"/alerting/list")},s.createElement(i.Z.Heading,null,L.name),s.createElement(i.Z.Meta,{separator:""},s.createElement(v.J,{name:"folder"}),s.createElement("span",{className:l.namespace},`${L.namespace.name} / ${L.group.name}`)),s.createElement(i.Z.Tags,null,s.createElement(a.s,{labels:L.labels}))))))}function w(l){return{param:g.css`
      font-style: italic;
      color: ${l.colors.text.secondary};
    `,rules:g.css`
      margin-top: ${l.spacing(2)};
    `,namespace:g.css`
      margin-left: ${l.spacing(1)};
    `,errorMessage:g.css`
      white-space: pre-wrap;
    `}}const _=(0,t.Pf)($,{style:"page"})},28104:(G,I,e)=>{e.d(I,{$:()=>U,l:()=>T});var g=e(52423),s=e(68404),O=e(72648),f=e(79396);const P={icon:"bell",id:"alert-rule-view",breadcrumbs:[{title:"Alert rules",url:"alerting/list"}]};function U(R){const{wrapInContent:h=!0,children:y,title:A}=R,d=(0,O.wW)(B);return s.createElement(f.T,{pageNav:{...P,text:A},navId:"alert-list"},s.createElement(f.T.Contents,null,s.createElement("div",{className:d.content},h?s.createElement(T,{...R}):y)))}function T({children:R,padding:h=2}){const y=(0,O.wW)(W(h));return s.createElement("div",{className:y.wrapper},R)}const B=R=>({content:g.css`
      max-width: ${R.breakpoints.values.xxl}px;
    `}),W=R=>h=>({wrapper:g.css`
      background: ${h.colors.background.primary};
      border: 1px solid ${h.colors.border.weak};
      border-radius: ${h.shape.borderRadius()};
      padding: ${h.spacing(R)};
    `})},76277:(G,I,e)=>{e.d(I,{H:()=>R,X:()=>h});var g=e(68404),s=e(22350),O=e(81168),f=e(72004),P=e(46818),U=e(60048),T=e(79662),B=e(61627),W=e(69945);function R(d,i){const v=y(i),t=(0,B.Zo)(i),a=(0,g.useMemo)(()=>{if(!(!d||!i||t.length===0))for(const n of t)for(const o of n.groups)for(const u of o.rules){const r=U.Yd(i,u);if(U.Dg(r,d))return u}},[d,i,t]);return{...v,result:a}}function h(d,i){const v=y(i),t=(0,B.Zo)(i),a=(0,g.useMemo)(()=>{if(!d||!i||t.length===0)return[];const n=[];for(const o of t)for(const u of o.groups)for(const r of u.rules)r.name===d&&n.push(r);return n},[d,i,t]);return{...v,result:a}}function y(d){const i=(0,O.useDispatch)(),v=(0,W._)(u=>u.promRules),t=A(d,v),a=(0,W._)(u=>u.rulerRules),n=A(d,a),{loading:o}=(0,s.Z)(async()=>{d&&await i((0,f.dn)({rulesSourceName:d}))},[i,d]);return{loading:o,error:t.error??(0,T.m$)(n)?void 0:n.error,dispatched:t.dispatched&&n.dispatched}}function A(d,i){if(!d)return P.oq;const v=i[d];return v||P.oq}},61627:(G,I,e)=>{e.d(I,{Kd:()=>B,Zo:()=>T});var g=e(82897),s=e.n(g),O=e(68404),f=e(45849),P=e(79662),U=e(69945);function T(t){const a=(0,U._)(r=>r.promRules),n=(0,U._)(r=>r.rulerRules),o=(0,O.useRef)({}),u=(0,O.useMemo)(()=>{if(t){const r=(0,f.o_)(t);if(!r)throw new Error(`Unknown rules source: ${t}`);return[r]}return(0,f.h_)()},[t]);return(0,O.useMemo)(()=>u.map(r=>{const c=(0,f.jq)(r)?r.name:r,C=a[c]?.result,K=n[c]?.result,$=o.current[c];if($&&$.promRules===C&&$.rulerRules===K)return $.result;const w={};Object.entries(K||{}).forEach(([l,E])=>{const m={rulesSource:r,name:l,groups:[]};w[l]=m,R(m,E)}),C?.forEach(({name:l,groups:E})=>{const m=w[l]=w[l]||{rulesSource:r,name:l,groups:[]};h(m,E)});const _=Object.values(w);return o.current[c]={promRules:C,rulerRules:K,result:_},_}).flat(),[a,n,u])}function B(t){return t.map(a=>{const n={...a,groups:[]};return n.groups.push({name:"default",rules:W(a.groups.flatMap(o=>o.rules))}),n})}function W(t){return t.sort((a,n)=>a.name.localeCompare(n.name))}function R(t,a=[]){t.groups=a.map(n=>{const o={name:n.name,interval:n.interval,source_tenants:n.source_tenants,rules:[]};return o.rules=n.rules.map(u=>A(u,t,o)),o})}function h(t,a){const n=new Map;t.groups.forEach(o=>n.set(o.name,o)),a.forEach(o=>{let u=n.get(o.name);u||(u={name:o.name,rules:[]},t.groups.push(u),n.set(o.name,u));const r=new Map;u.rules.forEach(c=>{const C=r.get(c.name);C?C.push(c):r.set(c.name,[c])}),(o.rules??[]).forEach(c=>{const C=d(c,r,t.rulesSource);C?C.promRule=c:u.rules.push(y(c,t,u))})})}function y(t,a,n){return{name:t.name,query:t.query,labels:t.labels||{},annotations:(0,P.x_)(t)?t.annotations||{}:{},promRule:t,namespace:a,group:n}}function A(t,a,n){return(0,P.cG)(t)?{name:t.alert,query:t.expr,labels:t.labels||{},annotations:t.annotations||{},rulerRule:t,namespace:a,group:n}:(0,P.yF)(t)?{name:t.record,query:t.expr,labels:t.labels||{},annotations:{},rulerRule:t,namespace:a,group:n}:{name:t.grafana_alert.title,query:"",labels:t.labels||{},annotations:t.annotations||{},rulerRule:t,namespace:a,group:n}}function d(t,a,n){const o=a.get(t.name);if(!o)return;if((0,f.HY)(n))return o[0];const u=o.find(c=>!c.promRule&&i(c,t,!0));if(u)return u;const r=o.find(c=>!c.promRule&&i(c,t,!1));if(r)return r}function i(t,a,n=!0){return t.name===a.name?(0,g.isEqual)([n?v(t.query):"",t.labels,t.annotations],[n?v(a.query):"",a.labels||{},(0,P.x_)(a)?a.annotations||{}:{}]):!1}function v(t){return t.length>1&&t[0]==="("&&t[t.length-1]===")"&&(t=t.slice(1,-1)),t=t.replace(/\s|\n/g,""),t.split("").sort().join("")}}}]);

//# sourceMappingURL=AlertingRedirectToRule.027e80566c6d5450b22b.js.map