"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7918],{96146:(e,r,n)=>{n.r(r),n.d(r,{RedirectToRuleViewer:()=>x,default:()=>v});var s,a,t,l,o=n(68490),u=(n(76687),n(59163)),i=n(70534),c=n(11676),d=n(14647),p=n(62605),m=n(11126),f=n(5504),g=n(52010);const h="Alerting / Find rule";function x(e){const{name:r,sourceName:n}=e.match.params,o=(0,i.useStyles2)(j),{error:x,loading:v,result:b,dispatched:y}=(0,p.X)(r,n);if(x)return(0,g.jsx)(d.$,{title:h,children:(0,g.jsx)(i.Alert,{title:`Failed to load rules from ${n}`,children:(0,g.jsxs)("details",{className:o.errorMessage,children:[x.message,s||(s=(0,g.jsx)("br",{})),!(null==x||!x.stack)&&x.stack]})})});if(v||!y||!Array.isArray(b))return a||(a=(0,g.jsx)(d.$,{title:h,children:(0,g.jsx)(i.LoadingPlaceholder,{text:"Loading rule..."})}));if(!r||!n)return t||(t=(0,g.jsx)(u.l_,{to:"/notfound"}));const $=(0,m.o_)(n);if(!$)return(0,g.jsx)(d.$,{title:h,children:(0,g.jsx)(i.Alert,{title:"Could not view rule",children:(0,g.jsx)("details",{className:o.errorMessage,children:`Could not find data source with name: ${n}.`})})});if(1===b.length){const[e]=b;return(0,g.jsx)(u.l_,{to:(0,f.V2)($,e,"/alerting/list")})}return(0,g.jsxs)(d.$,{title:h,children:[(0,g.jsxs)("div",{children:["Several rules in ",(0,g.jsx)("span",{className:o.param,children:n})," matched the name"," ",(0,g.jsx)("span",{className:o.param,children:r}),", please select the rule you want to view."]}),(0,g.jsx)("div",{className:o.rules,children:b.map(((e,r)=>(0,g.jsxs)(i.Card,{href:(0,f.V2)($,e,"/alerting/list"),children:[(0,g.jsx)(i.Card.Heading,{children:e.name}),(0,g.jsxs)(i.Card.Meta,{separator:"",children:[l||(l=(0,g.jsx)(i.Icon,{name:"folder"})),(0,g.jsx)("span",{className:o.namespace,children:`${e.namespace.name} / ${e.group.name}`})]}),(0,g.jsx)(i.Card.Tags,{children:(0,g.jsx)(c.s,{labels:e.labels})})]},`${e.name}-${r}`)))})]})}function j(e){return{param:o.css`
      font-style: italic;
      color: ${e.colors.text.secondary};
    `,rules:o.css`
      margin-top: ${e.spacing(2)};
    `,namespace:o.css`
      margin-left: ${e.spacing(1)};
    `,errorMessage:o.css`
      white-space: pre-wrap;
    `}}const v=(0,i.withErrorBoundary)(x,{style:"page"})},14647:(e,r,n)=>{n.d(r,{$:()=>u,l:()=>i});var s=n(68490),a=(n(76687),n(10967)),t=n(70534),l=n(36131),o=n(52010);function u(e){const{wrapInContent:r=!0,children:n,title:s}=e,u=(0,t.useStyles2)(c);return(0,o.jsxs)(l.T,{children:[(0,o.jsx)(t.PageToolbar,{title:s,pageIcon:"bell",onGoBack:()=>a.locationService.push("/alerting/list")}),(0,o.jsx)("div",{className:u.content,children:r?(0,o.jsx)(i,Object.assign({},e)):n})]})}function i(e){let{children:r,padding:n=2}=e;const s=(0,t.useStyles2)(d(n));return(0,o.jsx)("div",{className:s.wrapper,children:r})}const c=e=>({content:s.css`
      margin: ${e.spacing(0,2,2)};
      max-width: ${e.breakpoints.values.xxl}px;
    `}),d=e=>r=>({wrapper:s.css`
      background: ${r.colors.background.primary};
      border: 1px solid ${r.colors.border.weak};
      border-radius: ${r.shape.borderRadius()};
      padding: ${r.spacing(e)};
    `})},62605:(e,r,n)=>{n.d(r,{H:()=>p,X:()=>m});var s=n(76687),a=n(46958),t=n(8650),l=n(68175),o=n(27121),u=n(42673),i=n(18077),c=n(63373),d=n(7566);function p(e,r){const n=f(r),a=(0,c.Zo)(r),t=(0,s.useMemo)((()=>{if(e&&r&&0!==a.length)for(const n of a)for(const s of n.groups)for(const n of s.rules){const s=u.Yd(r,n);if(u.Dg(s,e))return n}}),[e,r,a]);return Object.assign({},n,{result:t})}function m(e,r){const n=f(r),a=(0,c.Zo)(r),t=(0,s.useMemo)((()=>{if(!e||!r||0===a.length)return[];const n=[];for(const r of a)for(const s of r.groups)for(const r of s.rules)r.name===e&&n.push(r);return n}),[e,r,a]);return Object.assign({},n,{result:t})}function f(e){var r;const n=(0,a.useDispatch)(),s=(0,d._)((e=>e.promRules)),o=g(e,s),u=(0,d._)((e=>e.rulerRules)),c=g(e,u),{loading:p}=(0,t.Z)((async()=>{e&&await n((0,l.dn)({rulesSourceName:e}))}),[n,e]);return{loading:p,error:(null!==(r=o.error)&&void 0!==r?r:(0,i.m$)(c))?void 0:c.error,dispatched:o.dispatched&&c.dispatched}}function g(e,r){if(!e)return o.oq;const n=r[e];return n||o.oq}},63373:(e,r,n)=>{n.d(r,{Kd:()=>u,Zo:()=>o});var s=n(76687),a=n(11126),t=n(18077),l=n(7566);function o(e){const r=(0,l._)((e=>e.promRules)),n=(0,l._)((e=>e.rulerRules)),o=(0,s.useRef)({}),u=(0,s.useMemo)((()=>{if(e){const r=(0,a.o_)(e);if(!r)throw new Error(`Unknown rules source: ${e}`);return[r]}return(0,a.h_)()}),[e]);return(0,s.useMemo)((()=>u.map((e=>{var s,l;const u=(0,a.jq)(e)?e.name:e,d=null===(s=r[u])||void 0===s?void 0:s.result,p=null===(l=n[u])||void 0===l?void 0:l.result,m=o.current[u];if(m&&m.promRules===d&&m.rulerRules===p)return m.result;const f={};Object.entries(p||{}).forEach((r=>{let[n,s]=r;const a={rulesSource:e,name:n,groups:[]};f[n]=a,function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];e.groups=r.map((r=>{const n={name:r.name,interval:r.interval,source_tenants:r.source_tenants,rules:[]};return n.rules=r.rules.map((r=>i(r,e,n))),n}))}(a,s)})),null==d||d.forEach((r=>{let{name:n,groups:s}=r;!function(e,r){r.forEach((r=>{var n;let s=e.groups.find((e=>e.name===r.name));s||(s={name:r.name,rules:[]},e.groups.push(s)),(null!==(n=r.rules)&&void 0!==n?n:[]).forEach((r=>{const n=function(e,r,n){var s;if((0,a.HY)(n))return r.rules.find((r=>r.name===e.name));return null!==(s=r.rules.find((r=>!r.promRule&&c(r,e,!0))))&&void 0!==s?s:r.rules.find((r=>!r.promRule&&c(r,e,!1)))}(r,s,e.rulesSource);n?n.promRule=r:s.rules.push(function(e,r,n){return{name:e.name,query:e.query,labels:e.labels||{},annotations:(0,t.x_)(e)&&e.annotations||{},promRule:e,namespace:r,group:n}}(r,e,s))}))}))}(f[n]=f[n]||{rulesSource:e,name:n,groups:[]},s)}));const g=Object.values(f);return o.current[u]={promRules:d,rulerRules:p,result:g},g})).flat()),[r,n,u])}function u(e){return e.map((e=>{const r=Object.assign({},e,{groups:[]});var n;return r.groups.push({name:"default",rules:(n=e.groups.flatMap((e=>e.rules)),n.sort(((e,r)=>e.name.localeCompare(r.name))))}),r}))}function i(e,r,n){return(0,t.cG)(e)?{name:e.alert,query:e.expr,labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:r,group:n}:(0,t.yF)(e)?{name:e.record,query:e.expr,labels:e.labels||{},annotations:{},rulerRule:e,namespace:r,group:n}:{name:e.grafana_alert.title,query:"",labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:r,group:n}}function c(e,r){let n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.name===r.name&&JSON.stringify([n?d(e.query):"",e.labels,e.annotations])===JSON.stringify([n?d(r.query):"",r.labels||{},(0,t.x_)(r)&&r.annotations||{}])}function d(e){return e.length>1&&"("===e[0]&&")"===e[e.length-1]&&(e=e.slice(1,-1)),(e=e.replace(/\s|\n/g,"")).split("").sort().join("")}}}]);
//# sourceMappingURL=AlertingRedirectToRule.89468ea576484affbc0a.js.map