"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7918],{46704:(Z,U,t)=>{t.r(U),t.d(U,{RedirectToRuleViewer:()=>n,default:()=>u});var g=t(41407),a=t(39953),T=t(53721),d=t(12573),B=t(32688),F=t(4148),f=t(82803),y=t(33155),P=t(84766),r=t(4236),E=t(12190),K=t(41393),I=t(4353),D=t(12942),x=t(75690),S=t(95712),G=t(76716),V=t(30391);const C="Find rule",W=B.config.appSubUrl;function e(){const s=(0,d.Z)();return(0,a.useMemo)(()=>{const l=s.pathname?.replace(W,"").split("/")??[],o=(0,V.d3)(decodeURIComponent((0,V.d3)(l[3]))),m=decodeURIComponent(l[2]),i=new URLSearchParams(s.search);return{name:o,sourceName:m,namespace:i.get("namespace")??void 0,group:i.get("group")??void 0}},[s])}function n(){const s=(0,f.wW)(c),{name:l,sourceName:o,namespace:m,group:i}=e(),{error:R,loading:N,rules:M=[]}=(0,x.F3)(l,o,{namespace:m,groupName:i});if(!l||!o)return a.createElement(T.l_,{to:"/notfound"});if(R)return a.createElement(D.$,{title:C},a.createElement(y.b,{title:`Failed to load rules from ${o}`},(0,F.kW)(R)&&a.createElement("details",{className:s.errorMessage},R.message,a.createElement("br",null))));if(N)return a.createElement(D.$,{title:C},a.createElement(P.u,{text:"Loading rule..."}));const O=(0,S.o_)(o);if(!O)return a.createElement(D.$,{title:C},a.createElement(y.b,{title:"Could not view rule"},a.createElement("details",{className:s.errorMessage},`Could not find data source with name: ${o}.`)));if(M.length===1){const[_]=M,h=(0,G.V2)(O,_,"/alerting/list").replace(W,"");return a.createElement(T.l_,{to:h})}return M.length===0?a.createElement(D.$,{title:C},a.createElement("div",{"data-testid":"no-rules"},"No rules in ",a.createElement("span",{className:s.param},o)," matched the name"," ",a.createElement("span",{className:s.param},l))):a.createElement(D.$,{title:C},a.createElement("div",null,"Several rules in ",a.createElement("span",{className:s.param},o)," matched the name"," ",a.createElement("span",{className:s.param},l),", please select the rule you want to view."),a.createElement("div",{className:s.rules},M.map((_,h)=>a.createElement(r.Z,{key:`${_.name}-${h}`,href:(0,G.V2)(O,_,"/alerting/list")},a.createElement(r.Z.Heading,null,_.name),a.createElement(r.Z.Meta,{separator:""},a.createElement(E.J,{name:"folder"}),a.createElement("span",{className:s.namespace},`${_.namespace.name} / ${_.group.name}`)),a.createElement(r.Z.Tags,null,a.createElement(I.s,{labels:_.labels}))))))}function c(s){return{param:(0,g.css)`
      font-style: italic;
      color: ${s.colors.text.secondary};
    `,rules:(0,g.css)`
      margin-top: ${s.spacing(2)};
    `,namespace:(0,g.css)`
      margin-left: ${s.spacing(1)};
    `,errorMessage:(0,g.css)`
      white-space: pre-wrap;
    `}}const u=(0,K.Pf)(n,{style:"page"})},12942:(Z,U,t)=>{t.d(U,{$:()=>F,l:()=>f});var g=t(41407),a=t(39953),T=t(82803),d=t(13253);const B={icon:"bell",id:"alert-rule-view"};function F(r){const{wrapInContent:E=!0,children:K,title:I}=r,D=(0,T.wW)(y);return a.createElement(d.T,{pageNav:{...B,text:I},navId:"alert-list"},a.createElement(d.T.Contents,null,a.createElement("div",{className:D.content},E?a.createElement(f,{...r}):K)))}function f({children:r,padding:E=2}){const K=(0,T.wW)(P(E));return a.createElement("div",{className:K.wrapper},r)}const y=r=>({content:(0,g.css)`
      max-width: ${r.breakpoints.values.xxl}px;
    `}),P=r=>E=>({wrapper:(0,g.css)`
      background: ${E.colors.background.primary};
      border: 1px solid ${E.colors.border.weak};
      border-radius: ${E.shape.radius.default};
      padding: ${E.spacing(r)};
    `})},75690:(Z,U,t)=>{t.d(U,{F3:()=>D,HO:()=>G,eq:()=>W});var g=t(39953),a=t(20653),T=t(57721),d=t(26516),B=t(14055),F=t(79493),f=t(95712),y=t(57675),P=t(30391),r=t(15032),E=t(52106),K=t(26544);function I(e,n){const c=x(n),u=useCombinedRuleNamespaces(n),s=useMemo(()=>{if(!e||!n||u.length===0)return[];const l=[];for(const o of u)for(const m of o.groups)for(const i of m.rules)i.name===e&&l.push(i);return l},[e,n,u]);return{...c,result:s}}function D(e,n,c){const u=(0,f.c$)(n),{dsFeatures:s,isLoadingDsFeatures:l}=W(n),{currentData:o=[],isLoading:m,error:i}=d.alertRuleApi.endpoints.prometheusRuleNamespaces.useQuery({ruleSourceName:n,ruleName:e,namespace:c?.namespace,groupName:c?.groupName}),[R]=d.alertRuleApi.endpoints.rulerRuleGroup.useLazyQuery(),{loading:N,error:M,value:O}=(0,a.Z)(async()=>{if(!u)throw new Error("Unable to obtain data source settings");if(i)throw new Error("Unable to obtain Prometheus rules");const _=[];if(s?.rulerConfig){const L=s.rulerConfig,v=o.map(p=>p.groups.map(A=>({namespace:p,group:A}))).flat();await Promise.allSettled(v.map(async p=>{const A=await R({rulerConfig:L,namespace:p.namespace.name,group:p.group.name}).unwrap();_.push(A)}))}return o.map(L=>(0,E.K$)(u,L,_)).flatMap(L=>L.groups.flatMap(v=>v.rules))},[u,s,m,i,o,R]);return{loading:l||N,error:M,rules:O}}function x(e,n){const c=useDispatch(),u=useUnifiedAlertingSelector(i=>i.promRules),s=S(e,u),l=useUnifiedAlertingSelector(i=>i.rulerRules),o=S(e,l),{loading:m}=useAsync(async()=>{e&&await c(fetchPromAndRulerRulesAction({rulesSourceName:e,identifier:n}))},[c,e]);return{loading:m,error:s.error??isRulerNotSupportedResponse(o)?void 0:o.error,dispatched:s.dispatched&&o.dispatched}}function S(e,n){if(!e)return initialAsyncRequestState;const c=n[e];return c||initialAsyncRequestState}function G({ruleIdentifier:e}){const{ruleSourceName:n}=e,c=(0,f.c$)(n),{dsFeatures:u,isLoadingDsFeatures:s}=W(n),{currentData:l,isLoading:o,error:m}=d.alertRuleApi.endpoints.prometheusRuleNamespaces.useQuery({ruleSourceName:e.ruleSourceName,namespace:(0,r.qE)(e)||(0,r.E4)(e)?e.namespace:void 0,groupName:(0,r.qE)(e)||(0,r.E4)(e)?e.groupName:void 0,ruleName:(0,r.qE)(e)||(0,r.E4)(e)?e.ruleName:void 0}),[i,{currentData:R,isLoading:N,error:M}]=d.alertRuleApi.endpoints.rulerRuleGroup.useLazyQuery(),[O,{currentData:_,isLoading:h,error:z}]=d.alertRuleApi.endpoints.rulerRules.useLazyQuery();(0,g.useEffect)(()=>{u?.rulerConfig&&(u.rulerConfig&&(0,r.E4)(e)?i({rulerConfig:u.rulerConfig,namespace:e.namespace,group:e.groupName}):(0,r.Kl)(e)&&O({rulerConfig:u.rulerConfig}))},[u,i,O,e]);const L=(0,g.useMemo)(()=>{if(l){if((0,r.Kl)(e)){const v=(0,E.bU)("grafana",l,_);for(const p of v)for(const A of p.groups)for(const $ of A.rules){const Q=P.Yd(n,$);if(P.Dg(Q,e))return $}}if(c&&l.length>0&&((0,r.E4)(e)||(0,r.qE)(e))){const v=l.map(p=>(0,E.K$)(c,p,R?[R]:[]));for(const p of v)for(const A of p.groups)for(const $ of A.rules){const Q=P.Yd(n,$);if(P.Dg(Q,e))return $}}}},[e,n,l,R,_,c]);return{loading:s||o||N||h,error:m??M??z,result:L}}const C={rulerConfig:{dataSourceName:f.GC,apiVersion:"legacy"}};function W(e){const n=(0,f.HY)(e),{currentData:c,isLoading:u}=B.T.endpoints.discoverDsFeatures.useQuery({rulesSourceName:e},{skip:n});return n?{isLoadingDsFeatures:!1,dsFeatures:C}:{isLoadingDsFeatures:u,dsFeatures:c}}}}]);

//# sourceMappingURL=AlertingRedirectToRule.deaaae1e6e9ed8015c9b.js.map