"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7062],{90588:(e,t,n)=>{n.d(t,{z:()=>r});const r={filterByLabel:"filtering alert instances by label",loadedList:"loaded Alert Rules list",leavingRuleGroupEdit:"leaving rule group edit without saving"}},73358:(e,t,n)=>{n.d(t,{C0:()=>c,Uv:()=>i,Xq:()=>o});n(68404);var r,a=n(8771),s=n(87885),l=n(45916);let i;!function(e){e.ContactPoint="contact point",e.Template="template",e.MuteTiming="mute timing",e.AlertRule="alert rule",e.RootNotificationPolicy="root notification policy"}(i||(i={}));const o=e=>{let{resource:t}=e;return(0,l.jsxs)(a.b,{title:`This ${t} cannot be edited through the UI`,severity:"info",children:["This ",t," has been provisioned, that means it was created by config. Please contact your server admin to update this ",t,"."]})},c=()=>r||(r=(0,l.jsx)(s.C,{text:"Provisioned",color:"purple"}))},16905:(e,t,n)=>{n.d(t,{F:()=>f});var r,a,s,l=n(27549),i=n(82897),o=(n(68404),n(72698)),c=n(9617),u=n(24085),d=n(4546),p=n(74025),m=n(9442),h=n(1652),g=n(90588),x=n(45916);const f=e=>{let{className:t,onFilterChange:n,defaultQueryString:l,queryString:f}=e;const j=(0,c.wW)(v),b=(0,i.debounce)((e=>{(0,o.PN)(g.z.filterByLabel);const t=e.target;n(t.value)}),600),y=r||(r=(0,x.jsx)(u.J,{name:"search"}));return(0,x.jsxs)("div",{className:t,children:[(0,x.jsx)(d._,{children:(0,x.jsxs)(p.K,{gap:.5,children:[a||(a=(0,x.jsx)("span",{children:"Search by label"})),(0,x.jsx)(m.u,{content:s||(s=(0,x.jsxs)("div",{children:["Filter alerts using label querying, ex:",(0,x.jsx)("pre",{children:'{severity="critical", instance=~"cluster-us-.+"}'})]})),children:(0,x.jsx)(u.J,{className:j.icon,name:"info-circle",size:"sm"})})]})}),(0,x.jsx)(h.I,{placeholder:"Search",defaultValue:l,value:f,onChange:b,"data-testid":"search-query-input",prefix:y,className:j.inputWidth})]})},v=e=>({icon:l.css`
    margin-right: ${e.spacing(.5)};
  `,inputWidth:l.css`
    width: 340px;
    flex-grow: 0;
  `})},83039:(e,t,n)=>{n.d(t,{f:()=>Y});var r=n(27549),a=n(68404),s=n(70356),l=n(87982),i=n(48147),o=n(9617),c=n(40920),u=n(18625),d=n(25049),p=n(95378),m=n(58257),h=n(61959),g=n(47570),x=n(78567),f=n(59385),v=n(82897),j=n(27494),b=n(95967),y=n(8771),w=n(84719),S=n(4546),R=n(74025),C=n(9442),_=n(24085),$=n(1652),N=n(83809),I=n(33899);var q,E,z,k=n(23906),M=n(9019),F=n(69357),P=n(45916);const U=e=>{let{alertId:t}=e;const[n,r]=(0,a.useState)(""),s=(0,a.useCallback)((e=>{r(e.currentTarget.value)}),[]),{loading:l,error:i,result:c=[]}=function(e){const t=(0,g.I0)(),n=(0,I._)((e=>e.managedAlertStateHistory));return(0,a.useEffect)((()=>{t((0,N.Ms)(e))}),[t,e]),n}(t),u=(0,o.wW)(O);if(l&&!i)return q||(q=(0,P.jsx)(b.u,{text:"Loading history..."}));if(i&&!l)return(0,P.jsx)(y.b,{title:"Failed to fetch alert state history",children:i.message});const d=[{id:"state",label:"State",size:"max-content",renderCell:L},{id:"value",label:"",size:"auto",renderCell:V},{id:"timestamp",label:"Time",size:"max-content",renderCell:W}],p=Object.entries(function(e){const t=e.map((e=>{var t,n;const r=/{.*?}/g,a=null!==(t=null===(n=e.text.match(r))||void 0===n?void 0:n.at(-1))&&void 0!==t?t:"";return{id:String(e.id),state:e.newState,text:e.text.replace(a,""),data:e.data,timestamp:e.updated,stringifiedLabels:a}}));return(0,v.groupBy)(t,(e=>e.stringifiedLabels))}(c)).sort().filter((e=>{let[t]=e;return function(e,t){if(""===t)return!0;if(!t.startsWith("/")||!t.endsWith("/"))return e.includes(t);try{return new RegExp(t.slice(1,-1)).test(e)}catch(e){return!1}}(t,n)})).map((e=>{let[t,n]=e;const r=n.map((e=>({id:e.id,data:e})));return(0,P.jsxs)("div",{children:[(0,P.jsx)("header",{className:u.tableGroupKey,children:(0,P.jsx)("code",{children:t})}),(0,P.jsx)(M.t,{cols:d,items:r})]},t)}));return(0,P.jsxs)("div",{children:[(0,P.jsx)("nav",{children:(0,P.jsx)(w.g,{label:E||(E=(0,P.jsx)(S._,{children:(0,P.jsxs)(R.K,{gap:.5,children:[(0,P.jsx)("span",{children:"Filter group"}),(0,P.jsx)(C.u,{content:(0,P.jsxs)("div",{children:["Filter each state history group either by exact match or a regular expression, ex:"," ",(0,P.jsx)("code",{children:"region=eu-west-1"})," or ",(0,P.jsx)("code",{children:"/region=us-.+/"})]}),children:(0,P.jsx)(_.J,{name:"info-circle",size:"sm"})})]})})),children:(0,P.jsx)($.I,{prefix:z||(z=(0,P.jsx)(_.J,{name:"search"})),onChange:s,placeholder:"Search"})})}),p]})};function V(e){var t,n;const r=null!==(t=null===(n=e.data.data)||void 0===n?void 0:n.evalMatches)&&void 0!==t?t:[];return(0,P.jsxs)(P.Fragment,{children:[e.data.text,(0,P.jsx)(D,{children:r.map((e=>(0,P.jsx)(k.i,{labelKey:e.metric,value:String(e.value)},e.metric)))})]})}function L(e){return(0,P.jsx)(F.l,{state:e.data.state})}function W(e){return(0,P.jsx)("div",{className:T,children:e.data.timestamp&&(0,P.jsx)("span",{children:(0,j.dq)(e.data.timestamp)})})}const D=e=>{let{children:t}=e;const{wrapper:n}=(0,o.wW)(O);return(0,P.jsx)("div",{className:n,children:t})},T=r.css`
  display: flex;
  align-items: flex-end;
  flex-direction: column;
`,O=e=>({wrapper:r.css`
    & > * {
      margin-right: ${e.spacing(1)};
    }
  `,tableGroupKey:r.css`
    margin-top: ${e.spacing(2)};
    margin-bottom: ${e.spacing(2)};
  `});var A,G,H=n(82139),B=n(85464),K=n(19462),Q=n(39357),Z=n(59940),J=n(86647);const Y=e=>{var t,n;let{rule:r,rulesSource:v}=e;const j=(0,g.I0)(),b=(0,s.TH)(),y=(0,m.iG)(),w=(0,o.wW)(X),{namespace:S,group:R,rulerRule:C}=r,[_,$]=(0,a.useState)(),I=(0,J.Pc)(r.rulerRule)&&null!==(t=r.rulerRule.grafana_alert.id)&&void 0!==t?t:"",{StateHistoryModal:q,showStateHistoryModal:E}=function(e){var t;const[n,r]=(0,a.useState)(!1);return{StateHistoryModal:(0,a.useMemo)((()=>(0,P.jsx)(f.u,{isOpen:n,onDismiss:()=>r(!1),closeOnBackdropClick:!0,closeOnEscape:!0,title:"State history",children:t||(t=(0,P.jsx)(U,{alertId:e}))})),[e,n]),showStateHistoryModal:()=>r(!0),hideStateHistoryModal:()=>r(!1)}}(I),z=(0,K.HY)(v)?v:null===(n=(0,H.Xy)(v.jsonData.alertmanagerUid))||void 0===n?void 0:n.name,k=(0,K.EG)(v),M=h.Vt.hasPermission(g.bW.DataSourcesExplore),F=(0,J.Pc)(r.rulerRule)&&Boolean(r.rulerRule.grafana_alert.provenance),V=[],L=[],W=(0,J.Jq)(R),{isEditable:D,isRemovable:T}=(0,x.M)(k,C),O=b.pathname+b.search,Y=b.pathname.endsWith("/view");const ee=()=>{if(_&&_.rulerRule){const e=Z.Zk((0,K.EG)(_.namespace.rulesSource),_.namespace.name,_.group.name,_.rulerRule);j((0,N.hS)(e,{navigateTo:Y?"/alerting/list":void 0})),$(void 0)}},te=()=>{if((0,K.jq)(v)){const{appUrl:e,appSubUrl:t}=i.v;return`${""!==t?`${e}${t}/`:i.v.appUrl}alerting/${`${encodeURIComponent(v.name)}/${encodeURIComponent(r.name)}`}/find`}return window.location.href.split("?")[0]};if((0,K.jq)(v)&&M&&!W&&V.push((0,P.jsx)(c.Qj,{className:w.button,size:"xs",variant:"primary",icon:"chart-line",target:"__blank",href:(0,Q.mH)(v.name,r.query),children:"See graph"},"explore")),r.annotations[B.q6.runbookURL]&&V.push((0,P.jsx)(c.Qj,{className:w.button,size:"xs",variant:"primary",icon:"book",target:"__blank",href:r.annotations[B.q6.runbookURL],children:"View runbook"},"runbook")),r.annotations[B.q6.dashboardUID]){const e=r.annotations[B.q6.dashboardUID];if(e){V.push((0,P.jsx)(c.Qj,{className:w.button,size:"xs",variant:"primary",icon:"apps",target:"__blank",href:`d/${encodeURIComponent(e)}`,children:"Go to dashboard"},"dashboard"));const t=r.annotations[B.q6.panelID];t&&V.push((0,P.jsx)(c.Qj,{className:w.button,size:"xs",variant:"primary",icon:"apps",target:"__blank",href:`d/${encodeURIComponent(e)}?viewPanel=${encodeURIComponent(t)}`,children:"Go to panel"},"panel"))}}if(z&&h.Vt.hasAccess(g.bW.AlertingInstanceCreate,h.Vt.isEditor)&&V.push((0,P.jsx)(c.Qj,{className:w.button,size:"xs",icon:"bell-slash",target:"__blank",href:(0,Q.Vv)(z,r),children:"Silence"},"silence")),I&&V.push((0,P.jsxs)(a.Fragment,{children:[(0,P.jsx)(c.zx,{className:w.button,size:"xs",icon:"history",onClick:()=>E(),children:"Show state history"}),q]},"history")),Y||L.push((0,P.jsx)(c.Qj,{className:w.button,size:"xs",variant:"secondary",icon:"eye",href:(0,Q.V2)(v,r,O),children:"View"},"view")),D&&C&&!W&&!F){const e=(0,K.EG)(v),t=Z.Zk(e,S.name,R.name,C),n=l.Cj.renderUrl(`${i.v.appSubUrl}/alerting/${encodeURIComponent(Z.$V(t))}/edit`,{returnTo:O});Y&&L.push((0,P.jsx)(u.m,{icon:"copy",onClipboardError:e=>{y.error("Error while copying URL",e)},className:w.button,size:"sm",getText:te,children:"Copy link to rule"},"copy")),L.push((0,P.jsx)(c.Qj,{className:w.button,size:"xs",variant:"secondary",icon:"pen",href:n,children:"Edit"},"edit"))}return T&&C&&!W&&!F&&L.push((0,P.jsx)(c.zx,{className:w.button,size:"xs",type:"button",variant:"secondary",icon:"trash-alt",onClick:()=>$(r),children:"Delete"},"delete")),V.length||L.length?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)("div",{className:w.wrapper,children:[(0,P.jsx)(d.Lh,{width:"auto",children:V.length?V:A||(A=(0,P.jsx)("div",{}))}),(0,P.jsx)(d.Lh,{width:"auto",children:L.length?L:G||(G=(0,P.jsx)("div",{}))})]}),!!_&&(0,P.jsx)(p.s,{isOpen:!0,title:"Delete rule",body:"Deleting this rule will permanently remove it from your alert rule list. Are you sure you want to delete this rule?",confirmText:"Yes, delete",icon:"exclamation-triangle",onConfirm:ee,onDismiss:()=>$(void 0)})]}):null};const X=e=>({wrapper:r.css`
    padding: ${e.spacing(2)} 0;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    flex-wrap: wrap;
    border-bottom: solid 1px ${e.colors.border.medium};
  `,button:r.css`
    height: 24px;
    margin-top: ${e.spacing(1)};
    font-size: ${e.typography.size.sm};
  `})},97292:(e,t,n)=>{n.d(t,{J:()=>i});var r=n(27549),a=(n(68404),n(9617)),s=n(212),l=n(45916);function i(e){const{annotations:t}=e,n=(0,a.wW)(o);return 0===t.length?null:(0,l.jsx)("div",{className:n.annotations,children:t.map((e=>{let[t,n]=e;return(0,l.jsx)(s.a,{annotationKey:t,value:n},t)}))})}const o=()=>({annotations:r.css`
    margin-top: 46px;
  `})},79842:(e,t,n)=>{n.d(t,{C:()=>p});var r=n(27549),a=n(68404),s=n(7501),l=n(9617),i=n(86551),o=n(19462),c=n(86647),u=n(52510),d=n(45916);function p(e){const{rulesSource:t,rule:n}=e,r=(0,l.wW)(m),p=(0,a.useMemo)((()=>{if((0,o.jq)(t))return[{name:t.name,icon:t.meta.info.logos.small}];if((0,c.Pc)(n.rulerRule)){const{data:e}=n.rulerRule.grafana_alert,t=e.reduce(((e,t)=>{const n=(0,s.F)().getInstanceSettings(t.datasourceUid);return n&&n.uid!==i.Yq?(e[n.name]={name:n.name,icon:n.meta.info.logos.small},e):e}),{});return Object.values(t)}return[]}),[n,t]);return 0===p.length?null:(0,d.jsx)(u.C,{label:"Data source",children:p.map(((e,t)=>{let{name:n,icon:a}=e;return(0,d.jsxs)("div",{children:[a&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("img",{alt:`${n} datasource logo`,className:r.dataSourceIcon,src:a})," "]}),n]},n)}))})}function m(e){const t=e.spacing(2);return{dataSourceIcon:r.css`
      width: ${t};
      height: ${t};
    `}}},85351:(e,t,n)=>{n.d(t,{C:()=>j});var r=n(27549),a=n(68404),s=n(19462),l=n(52510),i=n(57706),o=n(25942),c=n(13093),u=n(59178),d=n(9617),p=n(17245),m=n(85548),h=n(38708),g=n(45916);const x=e=>{let{language:t,expr:n}=e;const r=(0,a.useMemo)((()=>[(0,c.Z)({onlyIn:e=>"code_block"===e.type,getSyntax:()=>t},Object.assign({},i.languages,{[t]:"logql"===t?p.ZP:m.ZP}))]),[t]),s=(0,a.useMemo)((()=>(0,u.l1)(n)),[n]);return(0,g.jsx)(o.ML,{plugins:r,value:s,readOnly:!0})},f=e=>{let{expression:t,rulesSource:n}=e;const a=(0,d.yK)(v);return(0,g.jsx)(h.t,{className:(0,r.cx)(a.well,"slate-query-field"),children:(0,s.jq)(n)?(0,g.jsx)(x,{expr:t,language:n.type===s.ye.Loki?"logql":"promql"}):t})},v=e=>({well:r.css`
    font-family: ${e.typography.fontFamily.monospace};
  `});function j(e){const{annotations:t,rulesSource:n,rule:a}=e,i=b();return(0,s.jq)(n)?(0,g.jsx)(l.C,{label:"Expression",horizontal:!0,className:(0,r.cx)({[i.exprRow]:!!t.length}),children:(0,g.jsx)(f,{expression:a.query,rulesSource:n})}):null}const b=()=>({exprRow:r.css`
    margin-bottom: 46px;
  `})},12135:(e,t,n)=>{n.d(t,{M:()=>C});var r,a=n(27549),s=n(82897),l=n(68404),i=n(9617),o=n(40920),c=n(16905),u=n(74410),d=n(4546),p=n(96380),m=n(51542),h=n(45916);const g=e=>{let{className:t,onStateFilterChange:n,stateFilter:a,filterType:l,itemPerStateStats:o}=e;const c=(0,i.wW)(x),g=e=>function(){return o&&o[e]?(0,h.jsx)(u.V,{name:o[e].toFixed(0),colorIndex:9,className:c.tag}):null},f=Object.values(m.bj).map((e=>({label:e,value:e,component:g(e)}))),v=[m.x_.Firing,m.x_.Pending].map((e=>({label:(0,s.capitalize)(e),value:e,component:g(e)}))),j="grafana"===l?f:v;return(0,h.jsxs)("div",{className:t,"data-testid":"alert-instance-state-filter",children:[r||(r=(0,h.jsx)(d._,{children:"State"})),(0,h.jsx)(p.S,{options:j,value:a,onChange:n,onClick:e=>{e===a&&n(void 0)}})]})};function x(e){return{tag:a.css`
      font-size: 11px;
      font-weight: normal;
      padding: ${e.spacing(.25,.5)};
      vertical-align: middle;
      margin-left: ${e.spacing(.5)};
    `}}var f=n(82139),v=n(39357),j=n(40206),b=n(19462),y=n(86647),w=n(52510),S=n(9290);function R(e){const t=(0,i.yK)(_),{ruleViewPageLink:n,stats:r}=e;return(0,h.jsxs)("div",{className:t.footerRow,children:[(0,h.jsxs)("div",{children:["Showing ",r.visibleItemsCount," out of ",r.totalItemsCount," instances"]}),n&&(0,h.jsxs)(o.Qj,{href:n,size:"sm",variant:"secondary",children:["Show all ",r.totalItemsCount," alert instances"]})]})}function C(e){const{rule:{promRule:t,namespace:n},itemsDisplayLimit:r=Number.POSITIVE_INFINITY,pagination:o}=e,[u,d]=(0,l.useState)(),[p,x]=(0,l.useState)(),[C]=(0,l.useState)(Math.floor(100*Math.random())),$=`queryString-${C}`,N=(0,i.yK)(_),I=(0,b.HY)(n.rulesSource)?b.GC:"prometheus",q=(0,l.useMemo)((()=>{var e;return(0,y.x_)(t)&&null!==(e=t.alerts)&&void 0!==e&&e.length?function(e,t,n){let r=[...n];if(e){const t=(0,f.Zh)(e||"");r=r.filter((e=>{let{labels:n}=e;return(0,f.eD)(n,t)}))}t&&(r=r.filter((e=>(0,m.ED)(e.state)===t)));return r}(u,p,(0,v.Zl)(j.As.Importance,t.alerts)):[]}),[t,p,u]);if(!(0,y.x_)(t))return null;const E=q.slice(0,r),z=(0,s.countBy)(t.alerts,(e=>(0,m.ED)(e.state))),k=q.length-E.length,M={totalItemsCount:q.length,visibleItemsCount:E.length},F=(0,v.V2)(n.rulesSource,e.rule,location.pathname+location.search),P=k?(0,h.jsx)(R,{stats:M,ruleViewPageLink:F}):void 0;return(0,h.jsxs)(w.C,{label:"Matching instances",horizontal:!0,children:[(0,h.jsx)("div",{className:(0,a.cx)(N.flexRow,N.spaceBetween),children:(0,h.jsxs)("div",{className:N.flexRow,children:[(0,h.jsx)(c.F,{className:N.rowChild,defaultQueryString:u,onFilterChange:e=>d(e)},$),(0,h.jsx)(g,{className:N.rowChild,filterType:I,stateFilter:p,onStateFilterChange:x,itemPerStateStats:z})]})}),(0,h.jsx)(S.o,{instances:E,pagination:o,footerRow:P})]})}const _=e=>({flexRow:a.css`
      display: flex;
      flex-direction: row;
      align-items: flex-end;
      width: 100%;
      flex-wrap: wrap;
      margin-bottom: ${e.spacing.sm};
    `,spaceBetween:a.css`
      justify-content: space-between;
    `,rowChild:a.css`
      margin-right: ${e.spacing.sm};
    `,footerRow:a.css`
      display: flex;
      flex-direction: column;
      gap: ${e.spacing.sm};
      justify-content: space-between;
      align-items: center;
      width: 100%;
    `})},82434:(e,t,n)=>{n.d(t,{V:()=>u});var r,a,s=n(27549),l=(n(68404),n(9617)),i=n(9442),o=n(24085),c=n(45916);const u=e=>{let{rule:t}=e;const n=(0,l.wW)(d);return"err"===t.health||"error"===t.health?(0,c.jsx)(i.u,{theme:"error",content:t.lastError||"No error message provided.",children:(0,c.jsxs)("div",{className:n.warn,children:[r||(r=(0,c.jsx)(o.J,{name:"exclamation-triangle"})),a||(a=(0,c.jsx)("span",{children:"error"}))]})}):(0,c.jsx)(c.Fragment,{children:t.health})},d=e=>({warn:s.css`
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: ${e.spacing(1)};

    color: ${e.colors.warning.text};
  `})},18181:(e,t,n)=>{n.d(t,{p:()=>g});var r,a,s=n(27549),l=n(68404),i=n(90915),o=n(9617),c=n(25049),u=n(98134),d=n(51542),p=n(86647),m=n(69357),h=n(45916);const g=e=>{let{rule:t,isDeleting:n,isCreating:s}=e;const g=(0,o.wW)(x),{promRule:f}=t,v=(0,l.useMemo)((()=>{var e;if(f&&(0,p.x_)(f)&&null!==(e=f.alerts)&&void 0!==e&&e.length&&f.state!==d.x_.Inactive){const e=(0,p.ub)(f);if(e)return(0,h.jsxs)("span",{title:String(e),className:g.for,children:["for"," ",(0,i.vT)({start:e,end:new Date},!1)]})}return null}),[f,g]);return n?r||(r=(0,h.jsxs)(c.Lh,{align:"flex-start",children:[(0,h.jsx)(u.$,{}),"deleting"]})):s?a||(a=(0,h.jsxs)(c.Lh,{align:"flex-start",children:[" ",(0,h.jsx)(u.$,{}),"creating"]})):f&&(0,p.x_)(f)?(0,h.jsxs)(c.Lh,{align:"flex-start",children:[(0,h.jsx)(m.l,{state:f.state}),v]}):f&&(0,p.OP)(f)?(0,h.jsx)(h.Fragment,{children:"Recording rule"}):(0,h.jsx)(h.Fragment,{children:"n/a"})},x=e=>({for:s.css`
    font-size: ${e.typography.bodySmall.fontSize};
    color: ${e.colors.text.secondary};
    white-space: nowrap;
    padding-top: 2px;
  `})},75678:(e,t,n)=>{n.d(t,{Kd:()=>c,Zo:()=>o});var r=n(82897),a=n(68404),s=n(19462),l=n(86647),i=n(33899);function o(e){const t=(0,i._)((e=>e.promRules)),n=(0,i._)((e=>e.rulerRules)),r=(0,a.useRef)({}),o=(0,a.useMemo)((()=>{if(e){const t=(0,s.o_)(e);if(!t)throw new Error(`Unknown rules source: ${e}`);return[t]}return(0,s.h_)()}),[e]);return(0,a.useMemo)((()=>o.map((e=>{var a,i;const o=(0,s.jq)(e)?e.name:e,c=null===(a=t[o])||void 0===a?void 0:a.result,p=null===(i=n[o])||void 0===i?void 0:i.result,m=r.current[o];if(m&&m.promRules===c&&m.rulerRules===p)return m.result;const h={};Object.entries(p||{}).forEach((t=>{let[n,r]=t;const a={rulesSource:e,name:n,groups:[]};h[n]=a,function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];e.groups=t.map((t=>{const n={name:t.name,interval:t.interval,source_tenants:t.source_tenants,rules:[]};return n.rules=t.rules.map((t=>u(t,e,n))),n}))}(a,r)})),null==c||c.forEach((t=>{let{name:n,groups:r}=t;!function(e,t){const n=new Map;e.groups.forEach((e=>n.set(e.name,e))),t.forEach((t=>{var r;let a=n.get(t.name);a||(a={name:t.name,rules:[]},e.groups.push(a),n.set(t.name,a));const i=new Map;a.rules.forEach((e=>{const t=i.get(e.name);t?t.push(e):i.set(e.name,[e])})),(null!==(r=t.rules)&&void 0!==r?r:[]).forEach((t=>{const n=function(e,t,n){const r=t.get(e.name);if(!r)return;if((0,s.HY)(n))return r[0];const a=r.find((t=>!t.promRule&&d(t,e,!0)));if(a)return a;const l=r.find((t=>!t.promRule&&d(t,e,!1)));if(l)return l;return}(t,i,e.rulesSource);n?n.promRule=t:a.rules.push(function(e,t,n){return{name:e.name,query:e.query,labels:e.labels||{},annotations:(0,l.x_)(e)&&e.annotations||{},promRule:e,namespace:t,group:n}}(t,e,a))}))}))}(h[n]=h[n]||{rulesSource:e,name:n,groups:[]},r)}));const g=Object.values(h);return r.current[o]={promRules:c,rulerRules:p,result:g},g})).flat()),[t,n,o])}function c(e){return e.map((e=>{const t=Object.assign({},e,{groups:[]});var n;return t.groups.push({name:"default",rules:(n=e.groups.flatMap((e=>e.rules)),n.sort(((e,t)=>e.name.localeCompare(t.name))))}),t}))}function u(e,t,n){return(0,l.cG)(e)?{name:e.alert,query:e.expr,labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:t,group:n}:(0,l.yF)(e)?{name:e.record,query:e.expr,labels:e.labels||{},annotations:{},rulerRule:e,namespace:t,group:n}:{name:e.grafana_alert.title,query:"",labels:e.labels||{},annotations:e.annotations||{},rulerRule:e,namespace:t,group:n}}function d(e,t){let n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return e.name===t.name&&(0,r.isEqual)([n?p(e.query):"",e.labels,e.annotations],[n?p(t.query):"",t.labels||{},(0,l.x_)(t)&&t.annotations||{}])}function p(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("")}},13309:(e,t,n)=>{n.d(t,{W:()=>o});var r=n(68404),a=n(47570),s=n(83809),l=n(8455),i=n(33899);function o(e){const t=(0,a.I0)(),n=(0,i._)((e=>e.folders));if((0,r.useEffect)((()=>{e&&t((0,s.sw)(e))}),[t,e]),e){const t=n[e]||l.oq;return{folder:t.result,loading:t.loading}}return{loading:!1}}},78567:(e,t,n)=>{n.d(t,{M:()=>o});var r=n(61959),a=n(82969),s=n(86647),l=n(13309),i=n(33899);function o(e,t){var n,o,c;const u=(0,i._)((e=>e.dataSources)),d=t&&(0,s.Pc)(t)?t.grafana_alert.namespace_uid:void 0,p=(0,a.Bz)(e),{folder:m,loading:h}=(0,l.W)(d);if(!t)return{isEditable:!1,isRemovable:!1,loading:!1};if((0,s.Pc)(t)){if(!d)throw new Error(`Rule ${t.grafana_alert.title} does not have a folder uid, cannot determine if it is editable.`);if(!m)return{isEditable:!1,isRemovable:!1,loading:h};const e=m.canSave;return{isEditable:r.Vt.hasAccessInMetadata(p.update,m,e),isRemovable:r.Vt.hasAccessInMetadata(p.delete,m,e),loading:h}}const g=Boolean(null===(n=u[e])||void 0===n||null===(o=n.result)||void 0===o?void 0:o.rulerConfig);return{isEditable:r.Vt.hasAccess(p.update,r.Vt.isEditor)&&g,isRemovable:r.Vt.hasAccess(p.delete,r.Vt.isEditor)&&g,loading:null===(c=u[e])||void 0===c?void 0:c.loading}}}}]);
//# sourceMappingURL=7062.b37626025168884e816b.js.map