"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[1324],{75678:(e,n,r)=>{r.d(n,{Kd:()=>u,Zo:()=>o});var a=r(68404),t=r(19462),l=r(86647),s=r(33899);function o(e){const n=(0,s._)((e=>e.promRules)),r=(0,s._)((e=>e.rulerRules)),o=(0,a.useRef)({}),u=(0,a.useMemo)((()=>{if(e){const n=(0,t.o_)(e);if(!n)throw new Error(`Unknown rules source: ${e}`);return[n]}return(0,t.h_)()}),[e]);return(0,a.useMemo)((()=>u.map((e=>{var a,s;const u=(0,t.jq)(e)?e.name:e,c=null===(a=n[u])||void 0===a?void 0:a.result,d=null===(s=r[u])||void 0===s?void 0:s.result,g=o.current[u];if(g&&g.promRules===c&&g.rulerRules===d)return g.result;const m={};Object.entries(d||{}).forEach((n=>{let[r,a]=n;const t={rulesSource:e,name:r,groups:[]};m[r]=t,function(e,n){e.groups=n.map((n=>{const r={name:n.name,interval:n.interval,source_tenants:n.source_tenants,rules:[]};return r.rules=n.rules.map((n=>function(e,n,r){return(0,l.cG)(e)?{name:e.alert,query:e.expr,labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:n,group:r}:(0,l.yF)(e)?{name:e.record,query:e.expr,labels:e.labels||{},annotations:{},rulerRule:e,namespace:n,group:r}:{name:e.grafana_alert.title,query:"",labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:n,group:r}}(n,e,r))),r}))}(t,a)})),null==c||c.forEach((n=>{let{name:r,groups:a}=n;!function(e,n){n.forEach((n=>{var r;let a=e.groups.find((e=>e.name===n.name));a||(a={name:n.name,rules:[]},e.groups.push(a)),(null!==(r=n.rules)&&void 0!==r?r:[]).forEach((n=>{const r=function(e,n,r){var a;if((0,t.HY)(r))return n.rules.find((n=>n.name===e.name));return null!==(a=n.rules.find((n=>!n.promRule&&i(n,e,!0))))&&void 0!==a?a:n.rules.find((n=>!n.promRule&&i(n,e,!1)))}(n,a,e.rulesSource);r?r.promRule=n:a.rules.push(function(e,n,r){return{name:e.name,query:e.query,labels:e.labels||{},annotations:(0,l.x_)(e)&&e.annotations||{},promRule:e,namespace:n,group:r}}(n,e,a))}))}))}(m[r]=m[r]||{rulesSource:e,name:r,groups:[]},a)}));const p=Object.values(m);return o.current[u]={promRules:c,rulerRules:d,result:p},p})).flat()),[n,r,u])}function u(e){return e.map((e=>{const n=Object.assign({},e,{groups:[]});var r;return n.groups.push({name:"default",rules:(r=e.groups.flatMap((e=>e.rules)),r.sort(((e,n)=>e.name.localeCompare(n.name))))}),n}))}function i(e,n){let r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.name===n.name&&JSON.stringify([r?c(e.query):"",e.labels,e.annotations])===JSON.stringify([r?c(n.query):"",n.labels||{},(0,l.x_)(n)&&n.annotations||{}])}function c(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("")}},28410:(e,n,r)=>{r.d(n,{j:()=>s});var a=r(68404),t=r(42326),l=r(90923);function s(){const{search:e}=(0,t.TH)();return[(0,a.useMemo)((()=>new URLSearchParams(e)),[e]),(0,a.useCallback)(((e,n)=>{l.locationService.partial(e,n)}),[])]}},77325:(e,n,r)=>{r.r(n),r.d(n,{default:()=>A});var a=r(68404),t=r(18745),l=r(94087),s=r(33801),o=r(8674),u=r(36636),i=r(82897),c=r(17873),d=r(90747),g=r(69783),m=r(65747),p=r(65184),f=r(75678);var h,b,v=r(28410),j=r(83809),x=r(82139),S=r(19462),C=r(39357),y=r(45916);!function(e){e.Ascending="alpha-asc",e.Descending="alpha-desc"}(b||(b={}));const F=[{label:"Alphabetically [A-Z]",value:b.Ascending},{label:"Alphabetically [Z-A]",value:b.Descending}],R=e=>{var n;let{folder:r}=e;const l=(0,g.useStyles2)(w),s=(0,t.useDispatch)(),o=e=>{const n=(0,x.Zh)(N),r=(0,x.tC)(e),a=(0,i.uniqWith)([...n,r],i.isEqual),t=(0,x.oI)(a);P(t)};(0,a.useEffect)((()=>{s((0,j.y6)({rulesSourceName:S.GC})),s((0,j.UR)({rulesSourceName:S.GC}))}),[s]);const u=(0,f.Zo)(S.GC),{nameFilter:R,labelFilter:N,sortOrder:k,setNameFilter:A,setLabelFilter:P,setSortOrder:Z}=function(){var e,n;const[r,t]=(0,v.j)(),[l,s]=(0,a.useState)(null!==(e=r.get(O.nameFilter))&&void 0!==e?e:""),[o,u]=(0,a.useState)(null!==(n=r.get(O.labelFilter))&&void 0!==n?n:""),i=r.get(O.sortOrder),[d,g]=(0,a.useState)(i===b.Ascending?b.Ascending:i===b.Descending?b.Descending:void 0);return(0,c.Z)((()=>t({[O.nameFilter]:(0,p.sB)(l),[O.labelFilter]:(0,p.sB)(o),[O.sortOrder]:(0,p.sB)(d)},!0)),400,[l,o,d]),{nameFilter:l,labelFilter:o,sortOrder:d,setNameFilter:s,setLabelFilter:u,setSortOrder:g}}(),q=u.find((e=>e.name===r.title)),I=null!==(n=null==q?void 0:q.groups.flatMap((e=>e.rules)))&&void 0!==n?n:[],L=function(e,n,r,a){const t=(0,x.Zh)(r);let l=e.filter((e=>e.name.toLowerCase().includes(n.toLowerCase())&&(0,x.eD)(e.labels,t)));return(0,i.orderBy)(l,(e=>e.name.toLowerCase()),[a===b.Ascending?"asc":"desc"])}(I,R,N,null!=k?k:b.Ascending),_=0===I.length||0===L.length,{page:D,numberOfPages:E,onPageChange:M,pageItems:$}=function(e,n,r){const[t,l]=(0,a.useState)(n),s=Math.ceil(e.length/r),o=r*(t-1),u=e.slice(o,o+r);return(0,a.useEffect)((()=>l(1)),[s]),{page:t,onPageChange:e=>{l(e)},numberOfPages:s,pageItems:u}}(L,1,m.gN);return(0,y.jsx)("div",{className:l.container,children:(0,y.jsxs)(d.Stack,{direction:"column",gap:3,children:[(0,y.jsx)(g.FilterInput,{value:R,onChange:A,placeholder:"Search alert rules by name","data-testid":"name-filter"}),(0,y.jsxs)(d.Stack,{direction:"row",children:[(0,y.jsx)(g.Select,{value:k,onChange:e=>{let{value:n}=e;return n&&Z(n)},options:F,width:25,"aria-label":"Sort",placeholder:"Sort (Default A-Z)",prefix:(0,y.jsx)(g.Icon,{name:k===b.Ascending?"sort-amount-up":"sort-amount-down"})}),(0,y.jsx)(g.FilterInput,{value:N,onChange:P,placeholder:"Search alerts by labels",className:l.filterLabelsInput,"data-testid":"label-filter"})]}),(0,y.jsx)(d.Stack,{gap:1,children:$.map((e=>(0,y.jsxs)(g.Card,{href:(0,C.V2)("grafana",e,""),className:l.card,"data-testid":"alert-card-row",children:[(0,y.jsx)(g.Card.Heading,{children:e.name}),(0,y.jsx)(g.Card.Tags,{children:(0,y.jsx)(g.TagList,{onClick:o,tags:Object.entries(e.labels).map((e=>{let[n,r]=e;return`${n}=${r}`}))})}),(0,y.jsx)(g.Card.Meta,{children:(0,y.jsxs)("div",{children:[h||(h=(0,y.jsx)(g.Icon,{name:"folder"}))," ",r.title]})})]},e.name)))}),_&&(0,y.jsx)("div",{className:l.noResults,children:"No alert rules found"}),(0,y.jsx)("div",{className:l.pagination,children:(0,y.jsx)(g.Pagination,{currentPage:D,numberOfPages:E,onNavigate:M,hideWhenSinglePage:!0})})]})})};var O;!function(e){e.nameFilter="nameFilter",e.labelFilter="labelFilter",e.sortOrder="sort"}(O||(O={}));const w=e=>({container:u.css` padding: ${e.spacing(1)}; `,card:u.css` grid-template-columns: auto 1fr 2fr; margin: 0; `,pagination:u.css` align-self: center; `,filterLabelsInput:u.css` flex: 1; width: auto; min-width: 240px; `,noResults:u.css` padding: ${e.spacing(2)}; background-color: ${e.colors.background.secondary}; font-style: italic; `});var N=r(87413),k=r(49545);const A=e=>{let{match:n}=e;const r=(0,t.useDispatch)(),a=(0,t.useSelector)((e=>e.navIndex)),u=(0,t.useSelector)((e=>e.folder)),i=n.params.uid,c=(0,o.h)(a,`folder-alerting-${i}`,(0,k._)(1)),{loading:d}=(0,l.Z)((async()=>r((0,N.Pb)(i))),[N.Pb,i]);return(0,y.jsx)(s.Z,{navModel:c,children:(0,y.jsx)(s.Z.Contents,{isLoading:d,children:(0,y.jsx)(R,{folder:u})})})}}}]); //# sourceMappingURL=FolderAlerting.cf636db5eef730ed8461.js.map