"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[3044],{99355:(e,t,n)=>{n.d(t,{z:()=>a});const a={filterByLabel:"filtering alert instances by label",loadedList:"loaded Alert Rules list",leavingRuleGroupEdit:"leaving rule group edit without saving"}},78391:(e,t,n)=>{n.d(t,{C0:()=>c,Uv:()=>i,Xq:()=>o});n(76687);var a,r=n(35562),s=n(94903),l=n(52010);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)(r.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=()=>a||(a=(0,l.jsx)(s.C,{text:"Provisioned",color:"purple"}))},24202:(e,t,n)=>{n.d(t,{F:()=>v});var a,r,s,l=n(77813),i=n(86832),o=n(76687),c=n(95129),u=n(58490),d=n(27668),m=n(39756),p=n(13627),h=n(33097),g=n(9120),x=n(99355),f=n(52010);const v=e=>{let{className:t,onFilterChange:n,defaultQueryString:l}=e;const v=(0,d.wW)(j),b=(0,o.useMemo)((()=>(0,i.debounce)((e=>{(0,u.PN)(x.z.filterByLabel);const t=e.target;n(t.value)}),600)),[n]);(0,o.useEffect)((()=>b.cancel()),[b]);const y=a||(a=(0,f.jsx)(m.J,{name:"search"}));return(0,f.jsxs)("div",{className:t,children:[(0,f.jsx)(p._,{children:(0,f.jsxs)(c.Stack,{gap:.5,children:[r||(r=(0,f.jsx)("span",{children:"Search by label"})),(0,f.jsx)(h.u,{content:s||(s=(0,f.jsxs)("div",{children:["Filter alerts using label querying, ex:",(0,f.jsx)("pre",{children:'{severity="critical", instance=~"cluster-us-.+"}'})]})),children:(0,f.jsx)(m.J,{className:v.icon,name:"info-circle",size:"sm"})})]})}),(0,f.jsx)(g.I,{placeholder:"Search",defaultValue:l,onChange:b,"data-testid":"search-query-input",prefix:y,className:v.inputWidth})]})},j=e=>({icon:l.css`
    margin-right: ${e.spacing(.5)};
  `,inputWidth:l.css`
    width: 340px;
    flex-grow: 0;
  `})},75520:(e,t,n)=>{n.d(t,{f:()=>X});var a=n(77813),r=n(76687),s=n(63322),l=n(54675),i=n(85994),o=n(67273),c=n(27668),u=n(55312),d=n(63352),m=n(7053),p=n(97867),h=n(94843),g=n(69369),x=n(352),f=n(69751),v=n(99397),j=n(86832),b=n(84738),y=n(95129),w=n(42384),S=n(35562),R=n(45550),C=n(13627),_=n(33097),$=n(39756),N=n(9120),I=n(68175),E=n(7566);var q,k,z,M=n(28660),F=n(24301),U=n(85365),P=n(52010);const V=e=>{let{alertId:t}=e;const[n,a]=(0,r.useState)(""),s=(0,r.useCallback)((e=>{a(e.currentTarget.value)}),[]),{loading:l,error:i,result:o=[]}=function(e){const t=(0,x.I0)(),n=(0,E._)((e=>e.managedAlertStateHistory));return(0,r.useEffect)((()=>{t((0,I.Ms)(e))}),[t,e]),n}(t),u=(0,c.wW)(A);if(l&&!i)return q||(q=(0,P.jsx)(w.u,{text:"Loading history..."}));if(i&&!l)return(0,P.jsx)(S.b,{title:"Failed to fetch alert state history",children:i.message});const d=[{id:"state",label:"State",size:"max-content",renderCell:W},{id:"value",label:"",size:"auto",renderCell:L},{id:"timestamp",label:"Time",size:"max-content",renderCell:D}],m=Object.entries(function(e){const t=e.map((e=>{var t,n;const a=/{.*?}/g,r=null!==(t=null===(n=e.text.match(a))||void 0===n?void 0:n.at(-1))&&void 0!==t?t:"";return{id:String(e.id),state:e.newState,text:e.text.replace(r,""),data:e.data,timestamp:e.updated,stringifiedLabels:r}}));return(0,j.groupBy)(t,(e=>e.stringifiedLabels))}(o)).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 a=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)(F.t,{cols:d,items:a})]},t)}));return(0,P.jsxs)("div",{children:[(0,P.jsx)("nav",{children:(0,P.jsx)(R.g,{label:k||(k=(0,P.jsx)(C._,{children:(0,P.jsxs)(y.Stack,{gap:.5,children:[(0,P.jsx)("span",{children:"Filter group"}),(0,P.jsx)(_.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)(N.I,{prefix:z||(z=(0,P.jsx)($.J,{name:"search"})),onChange:s,placeholder:"Search"})})}),m]})};function L(e){var t,n;const a=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)(T,{children:a.map((e=>(0,P.jsx)(M.i,{labelKey:e.metric,value:String(e.value)},e.metric)))})]})}function W(e){return(0,P.jsx)(U.l,{state:e.data.state})}function D(e){return(0,P.jsx)("div",{className:O,children:e.data.timestamp&&(0,P.jsx)("span",{children:(0,b.dq)(e.data.timestamp)})})}const T=e=>{let{children:t}=e;const{wrapper:n}=(0,c.wW)(A);return(0,P.jsx)("div",{className:n,children:t})},O=a.css`
  display: flex;
  align-items: flex-end;
  flex-direction: column;
`,A=e=>({wrapper:a.css`
    & > * {
      margin-right: ${e.spacing(1)};
    }
  `,tableGroupKey:a.css`
    margin-top: ${e.spacing(2)};
    margin-bottom: ${e.spacing(2)};
  `});var G,H,Q=n(13698),B=n(73285),K=n(11126),Z=n(5504),J=n(42673),Y=n(18077);const X=e=>{var t,n;let{rule:a,rulesSource:j}=e;const b=(0,x.I0)(),y=(0,s.TH)(),w=(0,h.iG)(),S=(0,c.wW)(ee),{namespace:R,group:C,rulerRule:_}=a,[$,N]=(0,r.useState)(),E=(0,Y.Pc)(a.rulerRule)&&null!==(t=a.rulerRule.grafana_alert.id)&&void 0!==t?t:"",{StateHistoryModal:q,showStateHistoryModal:k}=function(e){var t;const[n,a]=(0,r.useState)(!1);return{StateHistoryModal:(0,r.useMemo)((()=>(0,P.jsx)(v.u,{isOpen:n,onDismiss:()=>a(!1),closeOnBackdropClick:!0,closeOnEscape:!0,title:"State history",children:t||(t=(0,P.jsx)(V,{alertId:e}))})),[e,n]),showStateHistoryModal:()=>a(!0),hideStateHistoryModal:()=>a(!1)}}(E),z=(0,K.HY)(j)?j:null===(n=(0,Q.Xy)(j.jsonData.alertmanagerUid))||void 0===n?void 0:n.name,M=(0,K.EG)(j),F=g.Vt.hasPermission(x.bW.DataSourcesExplore),U=(0,Y.Pc)(a.rulerRule)&&Boolean(a.rulerRule.grafana_alert.provenance),L=[],W=[],D=(0,Y.Jq)(C),{isEditable:T,isRemovable:O}=(0,f.M)(M,_),A=y.pathname+y.search,X=y.pathname.endsWith("/view");const te=()=>{if($&&$.rulerRule){const e=J.Zk((0,K.EG)($.namespace.rulesSource),$.namespace.name,$.group.name,$.rulerRule);b((0,I.hS)(e,{navigateTo:X?"/alerting/list":void 0})),N(void 0)}},ne=()=>{if((0,K.jq)(j)){const{appUrl:e,appSubUrl:t}=o.v;return`${""!==t?`${e}${t}/`:o.v.appUrl}alerting/${`${encodeURIComponent(j.name)}/${encodeURIComponent(a.name)}`}/find`}return window.location.href.split("?")[0]};if((0,K.jq)(j)&&F&&!D&&L.push((0,P.jsx)(u.Qj,{className:S.button,size:"xs",variant:"primary",icon:"chart-line",target:"__blank",href:(0,Z.mH)(j.name,a.query),children:"See graph"},"explore")),a.annotations[B.q6.runbookURL]&&L.push((0,P.jsx)(u.Qj,{className:S.button,size:"xs",variant:"primary",icon:"book",target:"__blank",href:l.QX.sanitizeUrl(a.annotations[B.q6.runbookURL]),children:"View runbook"},"runbook")),a.annotations[B.q6.dashboardUID]){const e=a.annotations[B.q6.dashboardUID];if(e){L.push((0,P.jsx)(u.Qj,{className:S.button,size:"xs",variant:"primary",icon:"apps",target:"__blank",href:`d/${encodeURIComponent(e)}`,children:"Go to dashboard"},"dashboard"));const t=a.annotations[B.q6.panelID];t&&L.push((0,P.jsx)(u.Qj,{className:S.button,size:"xs",variant:"primary",icon:"apps",target:"__blank",href:`d/${encodeURIComponent(e)}?viewPanel=${encodeURIComponent(t)}`,children:"Go to panel"},"panel"))}}if(z&&g.Vt.hasAccess(x.bW.AlertingInstanceCreate,g.Vt.isEditor)&&L.push((0,P.jsx)(u.Qj,{className:S.button,size:"xs",icon:"bell-slash",target:"__blank",href:(0,Z.Vv)(z,a),children:"Silence"},"silence")),E&&L.push((0,P.jsxs)(r.Fragment,{children:[(0,P.jsx)(u.zx,{className:S.button,size:"xs",icon:"history",onClick:()=>k(),children:"Show state history"}),q]},"history")),X||W.push((0,P.jsx)(u.Qj,{className:S.button,size:"xs",variant:"secondary",icon:"eye",href:(0,Z.V2)(j,a,A),children:"View"},"view")),T&&_&&!D&&!U){const e=(0,K.EG)(j),t=J.Zk(e,R.name,C.name,_),n=i.Cj.renderUrl(`${o.v.appSubUrl}/alerting/${encodeURIComponent(J.$V(t))}/edit`,{returnTo:A});X&&W.push((0,P.jsx)(d.m,{icon:"copy",onClipboardError:e=>{w.error("Error while copying URL",e)},className:S.button,size:"sm",getText:ne,children:"Copy link to rule"},"copy")),W.push((0,P.jsx)(u.Qj,{className:S.button,size:"xs",variant:"secondary",icon:"pen",href:n,children:"Edit"},"edit"))}return O&&_&&!D&&!U&&W.push((0,P.jsx)(u.zx,{className:S.button,size:"xs",type:"button",variant:"secondary",icon:"trash-alt",onClick:()=>N(a),children:"Delete"},"delete")),L.length||W.length?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)("div",{className:S.wrapper,children:[(0,P.jsx)(m.Lh,{width:"auto",children:L.length?L:G||(G=(0,P.jsx)("div",{}))}),(0,P.jsx)(m.Lh,{width:"auto",children:W.length?W:H||(H=(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:te,onDismiss:()=>N(void 0)})]}):null};const ee=e=>({wrapper:a.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:a.css`
    height: 24px;
    margin-top: ${e.spacing(1)};
    font-size: ${e.typography.size.sm};
  `})},2291:(e,t,n)=>{n.d(t,{J:()=>i});var a=n(77813),r=(n(76687),n(27668)),s=n(39e3),l=n(52010);function i(e){const{annotations:t}=e,n=(0,r.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:a.css`
    margin-top: 46px;
  `})},26160:(e,t,n)=>{n.d(t,{C:()=>m});var a=n(77813),r=n(76687),s=n(2343),l=n(27668),i=n(79544),o=n(11126),c=n(18077),u=n(94528),d=n(52010);function m(e){const{rulesSource:t,rule:n}=e,a=(0,l.wW)(p),m=(0,r.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===m.length?null:(0,d.jsx)(u.C,{label:"Data source",children:m.map(((e,t)=>{let{name:n,icon:r}=e;return(0,d.jsxs)("div",{children:[r&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("img",{alt:`${n} datasource logo`,className:a.dataSourceIcon,src:r})," "]}),n]},n)}))})}function p(e){const t=e.spacing(2);return{dataSourceIcon:a.css`
      width: ${t};
      height: ${t};
    `}}},72578:(e,t,n)=>{n.d(t,{C:()=>j});var a=n(77813),r=n(76687),s=n(11126),l=n(94528),i=n(10963),o=n(87993),c=n(16417),u=n(75555),d=n(27668),m=n(90642),p=n(55704),h=n(97487),g=n(52010);const x=e=>{let{language:t,expr:n}=e;const a=(0,r.useMemo)((()=>[(0,c.Z)({onlyIn:e=>"code_block"===e.type,getSyntax:()=>t},Object.assign({},i.languages,{[t]:"logql"===t?m.ZP:p.ZP}))]),[t]),s=(0,r.useMemo)((()=>(0,u.l1)(n)),[n]);return(0,g.jsx)(o.ML,{plugins:a,value:s,readOnly:!0})},f=e=>{let{expression:t,rulesSource:n}=e;const r=(0,d.yK)(v);return(0,g.jsx)(h.t,{className:(0,a.cx)(r.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:a.css`
    font-family: ${e.typography.fontFamily.monospace};
  `});function j(e){const{annotations:t,rulesSource:n,rule:r}=e,i=b();return(0,s.jq)(n)?(0,g.jsx)(l.C,{label:"Expression",horizontal:!0,className:(0,a.cx)({[i.exprRow]:!!t.length}),children:(0,g.jsx)(f,{expression:r.query,rulesSource:n})}):null}const b=()=>({exprRow:a.css`
    margin-bottom: 46px;
  `})},15738:(e,t,n)=>{n.d(t,{M:()=>C});var a,r=n(77813),s=n(86832),l=n(76687),i=n(27668),o=n(55312),c=n(24202),u=n(29327),d=n(13627),m=n(81377),p=n(23697),h=n(52010);const g=e=>{let{className:t,onStateFilterChange:n,stateFilter:r,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(p.bj).map((e=>({label:e,value:e,component:g(e)}))),v=[p.x_.Firing,p.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:[a||(a=(0,h.jsx)(d._,{children:"State"})),(0,h.jsx)(m.S,{options:j,value:r,onChange:n,onClick:e=>{e===r&&n(void 0)}})]})};function x(e){return{tag:r.css`
      font-size: 11px;
      font-weight: normal;
      padding: ${e.spacing(.25,.5)};
      vertical-align: middle;
      margin-left: ${e.spacing(.5)};
    `}}var f=n(13698),v=n(5504),j=n(65216),b=n(11126),y=n(18077),w=n(94528),S=n(5538);function R(e){const t=(0,i.yK)(_),{ruleViewPageLink:n,stats:a}=e;return(0,h.jsxs)("div",{className:t.footerRow,children:[(0,h.jsxs)("div",{children:["Showing ",a.visibleItemsCount," out of ",a.totalItemsCount," instances"]}),n&&(0,h.jsxs)(o.Qj,{href:n,size:"sm",variant:"secondary",children:["Show all ",a.totalItemsCount," alert instances"]})]})}function C(e){const{rule:{promRule:t,namespace:n},itemsDisplayLimit:a=Number.POSITIVE_INFINITY,pagination:o}=e,[u,d]=(0,l.useState)(),[m,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",E=(0,l.useMemo)((()=>{var e;return(0,y.x_)(t)&&null!==(e=t.alerts)&&void 0!==e&&e.length?function(e,t,n){let a=[...n];if(e){const t=(0,f.Zh)(e||"");a=a.filter((e=>{let{labels:n}=e;return(0,f.eD)(n,t)}))}t&&(a=a.filter((e=>(0,p.ED)(e.state)===t)));return a}(u,m,(0,v.Zl)(j.As.Importance,t.alerts)):[]}),[t,m,u]);if(!(0,y.x_)(t))return null;const q=E.slice(0,a),k=(0,s.countBy)(t.alerts,(e=>(0,p.ED)(e.state))),z=E.length-q.length,M={totalItemsCount:E.length,visibleItemsCount:q.length},F=(0,v.V2)(n.rulesSource,e.rule,location.pathname+location.search),U=z?(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,r.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:m,onStateFilterChange:x,itemPerStateStats:k})]})}),(0,h.jsx)(S.o,{instances:q,pagination:o,footerRow:U})]})}const _=e=>({flexRow:r.css`
      display: flex;
      flex-direction: row;
      align-items: flex-end;
      width: 100%;
      flex-wrap: wrap;
      margin-bottom: ${e.spacing.sm};
    `,spaceBetween:r.css`
      justify-content: space-between;
    `,rowChild:r.css`
      margin-right: ${e.spacing.sm};
    `,footerRow:r.css`
      display: flex;
      flex-direction: column;
      gap: ${e.spacing.sm};
      justify-content: space-between;
      align-items: center;
      width: 100%;
    `})},52238:(e,t,n)=>{n.d(t,{V:()=>u});var a,r,s=n(77813),l=(n(76687),n(27668)),i=n(33097),o=n(39756),c=n(52010);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:[a||(a=(0,c.jsx)(o.J,{name:"exclamation-triangle"})),r||(r=(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};
  `})},24045:(e,t,n)=>{n.d(t,{p:()=>g});var a,r,s=n(77813),l=n(76687),i=n(70392),o=n(27668),c=n(7053),u=n(55816),d=n(23697),m=n(18077),p=n(85365),h=n(52010);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,m.x_)(f)&&null!==(e=f.alerts)&&void 0!==e&&e.length&&f.state!==d.x_.Inactive){const e=(0,m.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?a||(a=(0,h.jsxs)(c.Lh,{align:"flex-start",children:[(0,h.jsx)(u.$,{}),"deleting"]})):s?r||(r=(0,h.jsxs)(c.Lh,{align:"flex-start",children:[" ",(0,h.jsx)(u.$,{}),"creating"]})):f&&(0,m.x_)(f)?(0,h.jsxs)(c.Lh,{align:"flex-start",children:[(0,h.jsx)(p.l,{state:f.state}),v]}):f&&(0,m.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;
  `})},63373:(e,t,n)=>{n.d(t,{Kd:()=>c,Zo:()=>o});var a=n(86832),r=n(76687),s=n(11126),l=n(18077),i=n(7566);function o(e){const t=(0,i._)((e=>e.promRules)),n=(0,i._)((e=>e.rulerRules)),a=(0,r.useRef)({}),o=(0,r.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,r.useMemo)((()=>o.map((e=>{var r,i;const o=(0,s.jq)(e)?e.name:e,c=null===(r=t[o])||void 0===r?void 0:r.result,m=null===(i=n[o])||void 0===i?void 0:i.result,p=a.current[o];if(p&&p.promRules===c&&p.rulerRules===m)return p.result;const h={};Object.entries(m||{}).forEach((t=>{let[n,a]=t;const r={rulesSource:e,name:n,groups:[]};h[n]=r,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}))}(r,a)})),null==c||c.forEach((t=>{let{name:n,groups:a}=t;!function(e,t){const n=new Map;e.groups.forEach((e=>n.set(e.name,e))),t.forEach((t=>{var a;let r=n.get(t.name);r||(r={name:t.name,rules:[]},e.groups.push(r),n.set(t.name,r));const i=new Map;r.rules.forEach((e=>{const t=i.get(e.name);t?t.push(e):i.set(e.name,[e])})),(null!==(a=t.rules)&&void 0!==a?a:[]).forEach((t=>{const n=function(e,t,n){const a=t.get(e.name);if(!a)return;if((0,s.HY)(n))return a[0];const r=a.find((t=>!t.promRule&&d(t,e,!0)));if(r)return r;const l=a.find((t=>!t.promRule&&d(t,e,!1)));if(l)return l;return}(t,i,e.rulesSource);n?n.promRule=t:r.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,r))}))}))}(h[n]=h[n]||{rulesSource:e,name:n,groups:[]},a)}));const g=Object.values(h);return a.current[o]={promRules:c,rulerRules:m,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,a.isEqual)([n?m(e.query):"",e.labels,e.annotations],[n?m(t.query):"",t.labels||{},(0,l.x_)(t)&&t.annotations||{}])}function m(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("")}},39072:(e,t,n)=>{n.d(t,{W:()=>o});var a=n(76687),r=n(352),s=n(68175),l=n(27121),i=n(7566);function o(e){const t=(0,r.I0)(),n=(0,i._)((e=>e.folders));if((0,a.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}}},69751:(e,t,n)=>{n.d(t,{M:()=>o});var a=n(69369),r=n(72721),s=n(18077),l=n(39072),i=n(7566);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,m=(0,r.Bz)(e),{folder:p,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(!p)return{isEditable:!1,isRemovable:!1,loading:h};const e=p.canSave;return{isEditable:a.Vt.hasAccessInMetadata(m.update,p,e),isRemovable:a.Vt.hasAccessInMetadata(m.delete,p,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:a.Vt.hasAccess(m.update,a.Vt.isEditor)&&g,isRemovable:a.Vt.hasAccess(m.delete,a.Vt.isEditor)&&g,loading:null===(c=u[e])||void 0===c?void 0:c.loading}}}}]);
//# sourceMappingURL=3044.198e3279ca40fc1d095c.js.map