"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[4333],{85185(ua,L,a){a.r(L),a.d(L,{BrowseFolderAlertingPage:()=>T,default:()=>oa});var t=a(74848),x=a(96540),D=a(54148),u=a(92745),P=a(34999),N=a(98970),b=a(13791),R=a(66198),v=a(22803),B=a(2543),E=a(40996),Y=a(63142),S=a(41654),Z=a(12737),U=a(68509),I=a(30703),j=a(8073),W=a(37658),$=a(34213),G=a(95943),C=a(1404),H=a(74048),K=a(20962),O=a(24610),M=a(52161),z=a(63895),J=a(29442),Q=(e=>(e.Ascending="alpha-asc",e.Descending="alpha-desc",e))(Q||{});const V=[{label:"Alphabetically [A-Z]",value:"alpha-asc"},{label:"Alphabetically [Z-A]",value:"alpha-desc"}],X=({folder:e,rules:s})=>{const r=(0,Y.of)(aa),g=c=>{const A=(0,O.EU)(o,c);i(A)},{nameFilter:n,labelFilter:o,sortOrder:l,setNameFilter:h,setLabelFilter:i,setSortOrder:m}=k(),F=q(s,n,o,l??"alpha-asc"),d=F.length===0,{page:f,numberOfPages:p,onPageChange:y,pageItems:ia}=(0,H.W)(F,1,G.FG);return(0,t.jsx)("div",{className:r.container,children:(0,t.jsxs)(S.B,{direction:"column",gap:3,children:[(0,t.jsx)(Z.Z,{value:n,onChange:h,placeholder:(0,u.t)("alerting.alerts-folder-view.name-filter-placeholder-search-alert-rules-by-name","Search alert rules by name"),"data-testid":"name-filter"}),(0,t.jsxs)(S.B,{direction:"row",children:[(0,t.jsx)(U.l6,{value:l,onChange:({value:c})=>c&&m(c),options:V,width:25,"aria-label":(0,u.t)("alerting.alerts-folder-view.aria-label-sort","Sort"),placeholder:(0,u.t)("alerting.alerts-folder-view.placeholder-sort-default-az","Sort (Default A-Z)"),prefix:(0,t.jsx)(I.I,{name:l==="alpha-asc"?"sort-amount-up":"sort-amount-down"})}),(0,t.jsx)(Z.Z,{value:o,onChange:i,placeholder:(0,u.t)("alerting.alerts-folder-view.label-filter-placeholder-search-alerts-by-labels","Search alerts by labels"),className:r.filterLabelsInput,"data-testid":"label-filter"})]}),(0,t.jsx)(S.B,{direction:"column",children:ia.map(({grafana_alert:c,labels:A={}})=>(0,t.jsxs)(j.Z,{noMargin:!0,href:_(c),className:r.card,"data-testid":"alert-card-row",children:[(0,t.jsx)(j.Z.Heading,{children:c.title}),(0,t.jsx)(j.Z.Tags,{children:(0,t.jsx)(W.L,{onClick:g,tags:Object.entries(A).map(([da,ca])=>`${da}=${ca}`)})}),(0,t.jsx)(j.Z.Meta,{children:(0,t.jsxs)("div",{children:[(0,t.jsx)(I.I,{name:"folder"})," ",e.title]})})]},c.uid))}),d&&(0,t.jsx)("div",{className:r.noResults,children:(0,t.jsx)(u.x6,{i18nKey:"alerting.alerts-folder-view.no-alert-rules-found",children:"No alert rules found"})}),(0,t.jsx)("div",{className:r.pagination,children:(0,t.jsx)($.d,{currentPage:f,numberOfPages:p,onNavigate:y,hideWhenSinglePage:!0})})]})})};var w=(e=>(e.nameFilter="nameFilter",e.labelFilter="labelFilter",e.sortOrder="sort",e))(w||{});function k(){const[e,s]=(0,K.l)(),[r,g]=(0,x.useState)(e.get("nameFilter")??""),[n,o]=(0,x.useState)(e.get("labelFilter")??""),l=e.get("sort"),h=(()=>{if(l==="alpha-asc")return"alpha-asc";if(l==="alpha-desc")return"alpha-desc"})(),[i,m]=(0,x.useState)(h);return(0,E.A)(()=>s({nameFilter:(0,C.fE)(r),labelFilter:(0,C.fE)(n),sort:(0,C.fE)(i)},!0),400,[r,n,i]),{nameFilter:r,labelFilter:n,sortOrder:i,setNameFilter:g,setLabelFilter:o,setSortOrder:m}}function q(e,s,r,g){const n=(0,z.Zc)(r),o=e.filter(l=>{const h=l.grafana_alert.title.toLowerCase().includes(s.toLowerCase()),i=(0,O.Av)(l.labels??{},n);return h&&i});return(0,B.orderBy)(o,l=>l.grafana_alert.title.toLowerCase(),[g==="alpha-asc"?"asc":"desc"])}function _(e){return J.PP.detailsPageLink(M.hY,{uid:e.uid,ruleSourceName:M.hY},void 0)}const aa=e=>({container:(0,v.css)({padding:e.spacing(1)}),card:(0,v.css)({gridTemplateColumns:"auto 1fr 2fr"}),pagination:(0,v.css)({alignSelf:"center"}),filterLabelsInput:(0,v.css)({flex:1,width:"auto",minWidth:"240px"}),noResults:(0,v.css)({padding:e.spacing(2),backgroundColor:e.colors.background.secondary,borderRadius:e.shape.radius.lg,fontStyle:"italic"})});var ea=a(70327),ta=a(55143),sa=a(77256),ra=a(29609),la=a(74286);const{useRulerNamespaceQuery:na}=ea.hK;function T(){const{uid:e=""}=(0,D.g)(),{data:s,isLoading:r}=(0,N.u$)(e),{data:g={},isLoading:n,error:o}=na({rulerConfig:ta.b,namespace:e}),[l]=(0,N.HP)(),h=(0,x.useMemo)(()=>{if(!s)return;const d=(0,R.R4)(s),f=(0,R.Fk)(s.uid),p=d.children?.find(y=>y.id===f);return p&&(p.active=!0),d},[s]),i=e?async d=>{if(s){const f=await l({...s,title:d});if("error"in f)throw f.error}}:void 0,m=r||n,F=Object.values(g).flatMap(d=>d).flatMap(d=>d.rules).filter(ra.p.grafana.rule);return(0,t.jsx)(b.Y,{navId:"dashboards/browse",pageNav:h,onEditTitle:i,actions:s&&(0,t.jsx)(la.A,{folderDTO:s}),children:(0,t.jsxs)(b.Y.Contents,{isLoading:m,children:[!s&&(0,t.jsx)(P.F,{title:(0,u.t)("browse-dashboards.browse-folder-alerting-page.title-folder-not-found","Folder not found")}),!!o&&(0,t.jsx)(P.F,{title:(0,u.t)("browse-dashboards.browse-folder-alerting-page.title-ruler-namespace-error","Cannot load rules"),severity:"error",children:(0,sa.JZ)(o)}),s&&(0,t.jsx)(X,{folder:s,rules:F})]})})}const oa=T}}]);

//# sourceMappingURL=FolderAlerting.5d5a5358255c59b4b020.js.map