"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7918],{"./public/app/features/alerting/unified/RedirectToRuleViewer.tsx":(e,r,s)=>{s.r(r),s.d(r,{RedirectToRuleViewer:()=>x,default:()=>j});s("./node_modules/react/index.js");var n,a,t,u,l=s("./node_modules/react-router/esm/react-router.js"),i=s("./node_modules/@emotion/css/dist/emotion-css.esm.js"),o=s("./packages/grafana-ui/src/index.ts"),c=s("./public/app/features/alerting/unified/hooks/useCombinedRule.ts"),d=s("./public/app/features/alerting/unified/utils/misc.ts"),p=s("./public/app/features/alerting/unified/utils/datasource.ts"),f=s("./public/app/features/alerting/unified/components/rule-viewer/RuleViewerLayout.tsx"),m=s("./public/app/features/alerting/unified/components/AlertLabels.tsx"),g=s("./node_modules/react/jsx-runtime.js");const h="Alerting / Find rule";function x(e){const{name:r,sourceName:s}=e.match.params,i=(0,o.useStyles2)(b),{error:x,loading:j,result:v,dispatched:R}=(0,c.X)(r,s);if(x)return(0,g.jsx)(f.$,{title:h,children:(0,g.jsx)(o.Alert,{title:`Failed to load rules from ${s}`,children:(0,g.jsxs)("details",{className:i.errorMessage,children:[x.message,n||(n=(0,g.jsx)("br",{})),!(null==x||!x.stack)&&x.stack]})})});if(j||!R||!Array.isArray(v))return a||(a=(0,g.jsx)(f.$,{title:h,children:(0,g.jsx)(o.LoadingPlaceholder,{text:"Loading rule..."})}));if(!r||!s)return t||(t=(0,g.jsx)(l.l_,{to:"/notfound"}));const y=(0,p.o_)(s);if(!y)return(0,g.jsx)(f.$,{title:h,children:(0,g.jsx)(o.Alert,{title:"Could not view rule",children:(0,g.jsx)("details",{className:i.errorMessage,children:`Could not find data source with name: ${s}.`})})});if(1===v.length){const[e]=v;return(0,g.jsx)(l.l_,{to:(0,d.V2)(y,e,"/alerting/list")})}return(0,g.jsxs)(f.$,{title:h,children:[(0,g.jsxs)("div",{children:["Several rules in ",(0,g.jsx)("span",{className:i.param,children:s})," matched the name"," ",(0,g.jsx)("span",{className:i.param,children:r}),", please select the rule you want to view."]}),(0,g.jsx)("div",{className:i.rules,children:v.map(((e,r)=>(0,g.jsxs)(o.Card,{heading:e.name,href:(0,d.V2)(y,e,"/alerting/list"),children:[(0,g.jsxs)(o.Card.Meta,{separator:"",children:[u||(u=(0,g.jsx)(o.Icon,{name:"folder"})),(0,g.jsx)("span",{className:i.namespace,children:`${e.namespace.name} / ${e.group.name}`})]}),(0,g.jsx)(o.Card.Tags,{children:(0,g.jsx)(m.s,{labels:e.labels})})]},`${e.name}-${r}`)))})]})}function b(e){return{param:i.css`
      font-style: italic;
      color: ${e.colors.text.secondary};
    `,rules:i.css`
      margin-top: ${e.spacing(2)};
    `,namespace:i.css`
      margin-left: ${e.spacing(1)};
    `,errorMessage:i.css`
      white-space: pre-wrap;
    `}}const j=(0,o.withErrorBoundary)(x,{style:"page"})},"./public/app/features/alerting/unified/components/rule-viewer/RuleViewerLayout.tsx":(e,r,s)=>{s.d(r,{$:()=>i,l:()=>o});s("./node_modules/react/index.js");var n=s("./node_modules/@emotion/css/dist/emotion-css.esm.js"),a=s("./packages/grafana-runtime/src/index.ts"),t=s("./packages/grafana-ui/src/index.ts"),u=s("./public/app/core/components/Page/Page.tsx"),l=s("./node_modules/react/jsx-runtime.js");function i(e){const{wrapInContent:r=!0,children:s,title:n}=e,i=(0,t.useStyles2)(c);return(0,l.jsxs)(u.T,{children:[(0,l.jsx)(t.PageToolbar,{title:n,pageIcon:"bell",onGoBack:()=>a.locationService.push("/alerting/list")}),(0,l.jsx)("div",{className:i.content,children:r?(0,l.jsx)(o,Object.assign({},e)):s})]})}function o({children:e,padding:r=2}){const s=(0,t.useStyles2)(d(r));return(0,l.jsx)("div",{className:s.wrapper,children:e})}const c=e=>({content:n.css`
      margin: ${e.spacing(0,2,2)};
      max-width: ${e.breakpoints.values.xxl}px;
    `}),d=e=>r=>({wrapper:n.css`
      background: ${r.colors.background.primary};
      border: 1px solid ${r.colors.border.weak};
      border-radius: ${r.shape.borderRadius()};
      padding: ${r.spacing(e)};
    `})},"./public/app/features/alerting/unified/hooks/useCombinedRule.ts":(e,r,s)=>{s.d(r,{H:()=>d,X:()=>p});var n=s("./node_modules/react/index.js"),a=s("./node_modules/react-redux/es/index.js"),t=s("./public/app/features/alerting/unified/utils/redux.ts"),u=s("./public/app/features/alerting/unified/hooks/useCombinedRuleNamespaces.ts"),l=s("./public/app/features/alerting/unified/hooks/useUnifiedAlertingSelector.ts"),i=s("./public/app/features/alerting/unified/state/actions.ts"),o=s("./public/app/features/alerting/unified/utils/rule-id.ts"),c=s("./public/app/features/alerting/unified/utils/rules.ts");function d(e,r){const s=f(r),a=(0,u.Z)(r),t=(0,n.useMemo)((()=>{if(e&&r&&0!==a.length)for(const s of a)for(const n of s.groups)for(const s of n.rules){const n=o.Yd(r,s);if(o.Dg(n,e))return s}}),[e,r,a]);return Object.assign({},s,{result:t})}function p(e,r){const s=f(r),a=(0,u.Z)(r),t=(0,n.useMemo)((()=>{if(!e||!r||0===a.length)return[];const s=[];for(const r of a)for(const n of r.groups)for(const r of n.rules)r.name===e&&s.push(r);return s}),[e,r,a]);return Object.assign({},s,{result:t})}function f(e){var r;const s=(0,a.useDispatch)(),t=(0,l._)((e=>e.promRules)),u=m(e,t),o=(0,l._)((e=>e.rulerRules)),d=m(e,o);return(0,n.useEffect)((()=>{e&&(s((0,i.y6)(e)),s((0,i.UR)(e)))}),[s,e]),{loading:u.loading||d.loading,error:(null!==(r=u.error)&&void 0!==r?r:(0,c.m$)(d))?void 0:d.error,dispatched:u.dispatched&&d.dispatched}}function m(e,r){if(!e)return t.oq;const s=r[e];return s||t.oq}},"./public/app/features/alerting/unified/hooks/useCombinedRuleNamespaces.ts":(e,r,s)=>{s.d(r,{Z:()=>l});var n=s("./node_modules/react/index.js"),a=s("./public/app/features/alerting/unified/utils/datasource.ts"),t=s("./public/app/features/alerting/unified/utils/rules.ts"),u=s("./public/app/features/alerting/unified/hooks/useUnifiedAlertingSelector.ts");function l(e){const r=(0,u._)((e=>e.promRules)),s=(0,u._)((e=>e.rulerRules)),l=(0,n.useRef)({}),o=(0,n.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,n.useMemo)((()=>o.map((e=>{var n,u;const o=(0,a.jq)(e)?e.name:e,c=null===(n=r[o])||void 0===n?void 0:n.result,d=null===(u=s[o])||void 0===u?void 0:u.result,p=l.current[o];if(p&&p.promRules===c&&p.rulerRules===d)return p.result;const f={};Object.entries(d||{}).forEach((([r,s])=>{const n={rulesSource:e,name:r,groups:[]};f[r]=n,function(e,r){e.groups=r.map((r=>{const s={name:r.name,interval:r.interval,rules:[]};return s.rules=r.rules.map((r=>function(e,r,s){return(0,t.cG)(e)?{name:e.alert,query:e.expr,labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:r,group:s}:(0,t.yF)(e)?{name:e.record,query:e.expr,labels:e.labels||{},annotations:{},rulerRule:e,namespace:r,group:s}:{name:e.grafana_alert.title,query:"",labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:r,group:s}}(r,e,s))),s}))}(n,s)})),null==c||c.forEach((({name:r,groups:s})=>{!function(e,r){r.forEach((r=>{var s;let n=e.groups.find((e=>e.name===r.name));n||(n={name:r.name,rules:[]},e.groups.push(n)),(null!==(s=r.rules)&&void 0!==s?s:[]).forEach((r=>{const s=function(e,r,s){var n;if((0,a.HY)(s))return r.rules.find((r=>r.name===e.name));return null!==(n=r.rules.find((r=>!r.promRule&&i(r,e,!0))))&&void 0!==n?n:r.rules.find((r=>!r.promRule&&i(r,e,!1)))}(r,n,e.rulesSource);s?s.promRule=r:n.rules.push(function(e,r,s){return{name:e.name,query:e.query,labels:e.labels||{},annotations:(0,t.x_)(e)&&e.annotations||{},promRule:e,namespace:r,group:s}}(r,e,n))}))}))}(f[r]=f[r]||{rulesSource:e,name:r,groups:[]},s)}));const m=Object.values(f);return(0,a.HY)(e)&&m.forEach((e=>{e.groups=[{name:"default",rules:e.groups.flatMap((e=>e.rules)).sort(((e,r)=>e.name.localeCompare(r.name)))}]})),l.current[o]={promRules:c,rulerRules:d,result:m},m})).flat()),[r,s,o])}function i(e,r,s=!0){return e.name===r.name&&JSON.stringify([s?o(e.query):"",e.labels,e.annotations])===JSON.stringify([s?o(r.query):"",r.labels||{},(0,t.x_)(r)&&r.annotations||{}])}function o(e){return e.length>1&&"("===e[0]&&")"===e[e.length-1]&&(e=e.substr(1,e.length-2)),(e=e.replace(/\s|\n/g,"")).split("").sort().join("")}}}]);
//# sourceMappingURL=AlertingRedirectToRule.8128b05ac04b15cbf98d.js.map