"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7918],{78272:(Z,U,t)=>{t.r(U),t.d(U,{RedirectToRuleViewer:()=>n,default:()=>u});var g=t(66681),a=t(85960),T=t(30694),d=t(8134),B=t(90857),I=t(85445),D=t(47257),y=t(49199),P=t(79468),r=t(72435),E=t(97666),K=t(8958),S=t(2698),f=t(90028),N=t(94498),G=t(76679),x=t(77294),V=t(60956);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,D.wW)(c),{name:l,sourceName:o,namespace:m,group:i}=e(),{error:R,loading:$,rules:M=[]}=(0,N.F3)(l,o,{namespace:m,groupName:i});if(!l||!o)return a.createElement(T.l_,{to:"/notfound"});if(R)return a.createElement(f.$,{title:C},a.createElement(y.b,{title:`Failed to load rules from ${o}`},(0,I.kW)(R)&&a.createElement("details",{className:s.errorMessage},R.message,a.createElement("br",null))));if($)return a.createElement(f.$,{title:C},a.createElement(P.u,{text:"Loading rule..."}));const O=(0,G.o_)(o);if(!O)return a.createElement(f.$,{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,x.V2)(O,_,"/alerting/list").replace(W,"");return a.createElement(T.l_,{to:h})}return M.length===0?a.createElement(f.$,{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(f.$,{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,x.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(S.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"})},90028:(Z,U,t)=>{t.d(U,{$:()=>I});var g=t(66681),a=t(85960),T=t(47257),d=t(20989);const B={icon:"bell",id:"alert-rule-view"};function I(r){const{wrapInContent:E=!0,children:K,title:S,renderTitle:f}=r,N=(0,T.wW)(y);return a.createElement(d.T,{pageNav:{...B,text:S},renderTitle:f,navId:"alert-list"},a.createElement(d.T.Contents,null,a.createElement("div",{className:N.content},E?a.createElement(D,{...r}):K)))}function D({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)};
    `})},94498:(Z,U,t)=>{t.d(U,{F3:()=>f,HO:()=>x,eq:()=>W});var g=t(85960),a=t(81445),T=t(95162),d=t(14411),B=t(80679),I=t(5970),D=t(76679),y=t(30422),P=t(60956),r=t(9001),E=t(68700),K=t(92746);function S(e,n){const c=N(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 f(e,n,c){const u=(0,D.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:$,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||$,error:M,rules:O}}function N(e,n){const c=useDispatch(),u=useUnifiedAlertingSelector(i=>i.promRules),s=G(e,u),l=useUnifiedAlertingSelector(i=>i.rulerRules),o=G(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 G(e,n){if(!e)return initialAsyncRequestState;const c=n[e];return c||initialAsyncRequestState}function x({ruleIdentifier:e}){const{ruleSourceName:n}=e,c=(0,D.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:$,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 F of A.rules){const Q=P.Yd(n,F);if(P.Dg(Q,e))return F}}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 F of A.rules){const Q=P.Yd(n,F);if(P.Dg(Q,e))return F}}}},[e,n,l,R,_,c]);return{loading:s||o||$||h,error:m??M??z,result:L}}const C={rulerConfig:{dataSourceName:D.GC,apiVersion:"legacy"}};function W(e){const n=(0,D.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.e408a3d0ea076a351f26.js.map