"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5372],{"./public/app/core/hooks/useCleanup.ts":(e,t,n)=>{n.d(t,{x:()=>i});var r=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),a=n("./.yarn/__virtual__/react-redux-virtual-7ad20a440e/3/opt/drone/yarncache/react-redux-npm-7.2.6-134f5ed64d-0bf142ce0d.zip/node_modules/react-redux/es/index.js"),s=n("./public/app/core/actions/cleanUp.ts");function i(e){const t=(0,a.useDispatch)(),n=(0,r.useRef)(e);n.current=e,(0,r.useEffect)((()=>()=>{t((0,s.e)({stateSelector:n.current}))}),[t])}},"./public/app/features/alerting/unified/RuleEditor.tsx":(e,t,n)=>{n.r(t),n.d(t,{default:()=>Qt});var r=n("./.yarn/__virtual__/@emotion-css-virtual-72c314ddb1/3/opt/drone/yarncache/@emotion-css-npm-11.7.1-25ff8755a7-ac1f56656f.zip/node_modules/@emotion/css/dist/emotion-css.esm.js"),a=n("./packages/grafana-ui/src/index.ts"),s=n("./public/app/core/components/Page/Page.tsx"),i=n("./public/app/core/services/context_srv.ts"),o=n("./public/app/core/hooks/useCleanup.ts"),l=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),u=n("./.yarn/__virtual__/react-redux-virtual-7ad20a440e/3/opt/drone/yarncache/react-redux-npm-7.2.6-134f5ed64d-0bf142ce0d.zip/node_modules/react-redux/es/index.js"),d=n("./packages/grafana-data/src/index.ts"),c=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");const p=e=>{let{title:t,stepNo:n,children:r,description:s}=e;const i=(0,a.useStyles2)(m);return(0,c.jsxs)("div",{className:i.parent,children:[(0,c.jsx)("div",{children:(0,c.jsx)("span",{className:i.stepNo,children:n})}),(0,c.jsx)("div",{className:i.content,children:(0,c.jsxs)(a.FieldSet,{label:t,className:i.fieldset,children:[s&&(0,c.jsx)("p",{className:i.description,children:s}),r]})})]})},m=e=>({fieldset:r.css`
    legend {
      font-size: 16px;
      padding-top: ${e.spacing(.5)};
    }
  `,parent:r.css`
    display: flex;
    flex-direction: row;
    max-width: ${e.breakpoints.values.xl};
    & + & {
      margin-top: ${e.spacing(4)};
    }
  `,description:r.css`
    margin-top: -${e.spacing(2)};
  `,stepNo:r.css`
    display: inline-block;
    width: ${e.spacing(4)};
    height: ${e.spacing(4)};
    line-height: ${e.spacing(4)};
    border-radius: ${e.spacing(4)};
    text-align: center;
    color: ${e.colors.text.maxContrast};
    background-color: ${e.colors.background.canvas};
    font-size: ${e.typography.size.lg};
    margin-right: ${e.spacing(2)};
  `,content:r.css`
    flex: 1;
  `});var g=n("./.yarn/__virtual__/react-hook-form-virtual-92b6119fd4/3/opt/drone/yarncache/react-hook-form-npm-7.5.3-f9cc466c62-fbfaa3b664.zip/node_modules/react-hook-form/dist/index.esm.js"),f=n("./public/app/features/alerting/unified/types/rule-form.ts"),h=n("./public/app/features/alerting/unified/components/rule-editor/RuleFolderPicker.tsx"),v=n("./public/app/features/alerting/unified/hooks/useUnifiedAlertingSelector.ts"),x=n("./public/app/features/alerting/unified/state/actions.ts"),b=n("./public/app/features/alerting/unified/components/rule-editor/SelectWIthAdd.tsx"),j=n("./public/app/features/expressions/guards.ts");function y(e,t,n){const r=new RegExp("(\\$"+t+"\\b)|(\\${"+t+"})","gm"),a="${"+n+"}";return e.replace(r,a)}function w(e){return!(e.includes("/")||e.includes("\\"))||'Cannot contain "/" or "\\" characters'}const S=["onChange","ref"],C=["ref"];function R(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}const _=e=>{var t,n,r,s,i;let{rulesSourceName:o}=e;const{control:d,watch:p,formState:{errors:m},setValue:f}=(0,g.Gc)(),h=(0,a.useStyles2)(k),[j,y]=(0,l.useState)(!1),_=(0,v._)((e=>e.rulerRules)),O=(0,u.useDispatch)();(0,l.useEffect)((()=>{O((0,x.UR)({rulesSourceName:o}))}),[o,O]);const N=null===(t=_[o])||void 0===t?void 0:t.result,I=p("namespace"),$=(0,l.useMemo)((()=>N?Object.keys(N).map((e=>({label:e,value:e}))):[]),[N]),q=(0,l.useMemo)((()=>{var e;return I&&(null==N||null===(e=N[I])||void 0===e?void 0:e.map((e=>({label:e.name,value:e.name}))))||[]}),[I,N]);return(0,c.jsxs)("div",{className:h.flexRow,children:[(0,c.jsx)(a.Field,{"data-testid":"namespace-picker",label:"Namespace",error:null===(n=m.namespace)||void 0===n?void 0:n.message,invalid:!(null===(r=m.namespace)||void 0===r||!r.message),children:(0,c.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=R(e.field,S);return(0,c.jsx)(b.P,Object.assign({},n,{className:h.input,onChange:e=>{f("group",""),t(e)},onCustomChange:e=>{e&&y(!0)},options:$,width:42}))},name:"namespace",control:d,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:w}}})}),(0,c.jsx)(a.Field,{"data-testid":"group-picker",label:"Group",error:null===(s=m.group)||void 0===s?void 0:s.message,invalid:!(null===(i=m.group)||void 0===i||!i.message),children:(0,c.jsx)(a.InputControl,{render:e=>{let{}=e,t=R(e.field,C);return(0,c.jsx)(b.P,Object.assign({},t,{options:q,width:42,custom:j,className:h.input}))},name:"group",control:d,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:w}}})})]})},k=e=>({flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;

    & > * + * {
      margin-left: ${e.spacing(3)};
    }
  `,input:r.css`
    width: 330px !important;
  `});var O=n("./packages/grafana-runtime/src/index.ts"),N=n("./public/app/features/alerting/unified/utils/datasource.ts");const I=["value"];function $(e){let{value:t}=e,n=function(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,I);const r=function(){const e=(0,v._)((e=>e.lotexSupportsRuleEditing)),t=(0,u.useDispatch)();return(0,l.useEffect)((()=>{(0,N.Eu)().filter((t=>void 0===e[t.name])).forEach((e=>t((0,x.Yb)(e.name))))}),[t,e]),(0,l.useMemo)((()=>(0,N.Eu)().filter((t=>{var n;return null===(n=e[t.name])||void 0===n?void 0:n.result}))),[e])}(),a=(0,l.useCallback)((e=>!!r.find((t=>{let{id:n}=t;return n===e.id}))),[r]);return(0,c.jsx)(O.DataSourcePicker,Object.assign({noDefault:!0,alerting:!0,filter:a,current:t},n))}const q=["onChange","ref"],D=["onChange","ref"],Q=["ref"];function E(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}const T={message:"Recording rule name must be valid metric name. It may only contain letters, numbers, and colons. It may not contain whitespace.",value:/^[a-zA-Z_:][a-zA-Z0-9_:]*$/},F=e=>{var t,n,r,s,o,u,d,m;let{editingExistingRule:v}=e;const x=(0,a.useStyles2)(A),{register:b,control:j,watch:y,formState:{errors:S},setValue:C}=(0,g.Gc)(),R=y("type"),k=y("dataSourceName"),O=(0,l.useMemo)((()=>{const e=[{label:"Grafana managed alert",value:f.$.grafana,description:"Classic Grafana alerts based on thresholds."}];return i.Vt.isEditor&&(e.push({label:"Cortex/Loki managed alert",value:f.$.cloudAlerting,description:"Alert based on a system or application behavior. Based on Prometheus."}),e.push({label:"Cortex/Loki managed recording rule",value:f.$.cloudRecording,description:"Recording rule to pre-compute frequently needed or expensive calculations. Based on Prometheus."})),e}),[]);return(0,c.jsxs)(p,{stepNo:1,title:"Rule type",children:[(0,c.jsx)(a.Field,{className:x.formInput,label:"Rule name",error:null==S||null===(t=S.name)||void 0===t?void 0:t.message,invalid:!(null===(n=S.name)||void 0===n||!n.message),children:(0,c.jsx)(a.Input,Object.assign({id:"name"},b("name",{required:{value:!0,message:"Must enter an alert name"},pattern:R===f.$.cloudRecording?T:void 0,validate:{pathSeparator:e=>R!==f.$.grafana||w(e)}}),{autoFocus:!0}))}),(0,c.jsxs)("div",{className:x.flexRow,children:[(0,c.jsx)(a.Field,{disabled:v,label:"Rule type",className:x.formInput,error:null===(r=S.type)||void 0===r?void 0:r.message,invalid:!(null===(s=S.type)||void 0===s||!s.message),"data-testid":"alert-type-picker",children:(0,c.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=E(e.field,q);return(0,c.jsx)(a.Select,Object.assign({menuShouldPortal:!0,"aria-label":"Rule type"},n,{options:O,onChange:e=>t(null==e?void 0:e.value)}))},name:"type",control:j,rules:{required:{value:!0,message:"Please select alert type"}}})}),(R===f.$.cloudRecording||R===f.$.cloudAlerting)&&(0,c.jsx)(a.Field,{className:x.formInput,label:"Select data source",error:null===(o=S.dataSourceName)||void 0===o?void 0:o.message,invalid:!(null===(u=S.dataSourceName)||void 0===u||!u.message),"data-testid":"datasource-picker",children:(0,c.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=E(e.field,D);return(0,c.jsx)($,Object.assign({},n,{onChange:e=>{var n;C("location",void 0),t(null!==(n=null==e?void 0:e.name)&&void 0!==n?n:null)}}))},name:"dataSourceName",control:j,rules:{required:{value:!0,message:"Please select a data source"}}})})]}),(R===f.$.cloudRecording||R===f.$.cloudAlerting)&&k&&(0,c.jsx)(_,{rulesSourceName:k}),R===f.$.grafana&&(0,c.jsx)(a.Field,{label:"Folder",className:x.formInput,error:null===(d=S.folder)||void 0===d?void 0:d.message,invalid:!(null===(m=S.folder)||void 0===m||!m.message),"data-testid":"folder-picker",children:(0,c.jsx)(a.InputControl,{render:e=>{let{}=e,t=E(e.field,Q);return(0,c.jsx)(h.W,Object.assign({},t,{enableCreateNew:!0,enableReset:!0}))},name:"folder",rules:{required:{value:!0,message:"Please select a folder"},validate:{pathSeparator:e=>w(e.title)}}})})]})},A=e=>({formInput:r.css`
    width: 330px;
    & + & {
      margin-left: ${e.spacing(3)};
    }
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
  `});var z,L,P=n("./public/app/features/alerting/unified/components/rule-editor/LabelsField.tsx"),B=n("./public/app/features/alerting/unified/components/rule-editor/AnnotationsField.tsx");const M=()=>{const{watch:e}=(0,g.Gc)(),t=e("type");return(0,c.jsxs)(p,{stepNo:t===f.$.cloudRecording?3:4,title:t===f.$.cloudRecording?"Add details for your recording rule":"Add details for your alert",description:t===f.$.cloudRecording?"Add labels to help you better manage your rules":"Write a summary and add labels to help you better manage your alerts",children:[t!==f.$.cloudRecording&&(z||(z=(0,c.jsx)(B.Z,{}))),L||(L=(0,c.jsx)(P.Z,{}))]})};var U=n("../../opt/drone/yarncache/lodash-npm-4.17.21-6382451519-eb835a2e51.zip/node_modules/lodash/lodash.js"),G=n("./.yarn/__virtual__/react-use-virtual-00326e70ba/3/opt/drone/yarncache/react-use-npm-17.3.2-a032cbeb01-7379460f51.zip/node_modules/react-use/esm/useAsync.js");const V=e=>{var t,n;let{value:r,onChange:a,dataSourceName:s}=e;const{mapToValue:i,mapToQuery:o}=function(e){return(0,l.useMemo)((()=>{const t=(0,O.getDataSourceSrv)().getInstanceSettings(e);switch(null==t?void 0:t.type){case"loki":case"prometheus":return{mapToValue:e=>e.expr,mapToQuery:(e,t)=>Object.assign({},e,{expr:t})};default:throw new Error(`${e} is not supported as an expression editor`)}}),[e])}(s),[u,p]=(0,l.useState)(o({refId:"A",hide:!1},r)),{error:m,loading:g,value:f}=(0,G.Z)((()=>(0,O.getDataSourceSrv)().get(s)),[s]),h=(0,l.useCallback)((e=>{p(e),a(i(e))}),[a,i]);if(g||(null==f?void 0:f.name)!==s)return null;if(m||!f||null==f||null===(t=f.components)||void 0===t||!t.QueryEditor){const e=(null==m?void 0:m.message)||"Data source plugin does not export any Query Editor component";return(0,c.jsxs)("div",{children:["Could not load query editor due to: ",e]})}const v=null==f||null===(n=f.components)||void 0===n?void 0:n.QueryEditor;return(0,c.jsx)(v,{query:u,queries:[u],app:d.CoreApp.CloudAlerting,onChange:h,onRunQuery:U.noop,datasource:f})};var Z=n("./packages/grafana-e2e-selectors/src/index.ts"),W=n("./.yarn/__virtual__/react-beautiful-dnd-virtual-27e4b658e7/3/opt/drone/yarncache/react-beautiful-dnd-npm-13.1.0-fcf5568b1c-12b7e9fbe8.zip/node_modules/react-beautiful-dnd/dist/react-beautiful-dnd.esm.js"),K=n("./public/app/features/query/components/QueryEditorRow.tsx"),H=n("./.yarn/__virtual__/react-virtualized-auto-sizer-virtual-b5ab366cb0/3/opt/drone/yarncache/react-virtualized-auto-sizer-npm-1.0.6-50869b8392-81270e9d32.zip/node_modules/react-virtualized-auto-sizer/dist/index.esm.js"),Y=n("./packages/grafana-schema/src/index.ts"),J=n("./public/app/features/alerting/unified/utils/constants.ts");var X=n("./public/app/features/alerting/unified/components/PanelPluginsButtonGroup.tsx"),ee=n("./public/app/core/app_events.ts");const te=e=>{let{data:t,currentPanel:n,changePanel:r,onThresholdsChange:s,thresholds:i}=e;const[o,u]=(0,l.useState)({frameIndex:0,showHeader:!0}),d=function(e,t,n){const r=(0,a.useTheme2)();if(t===J.GC||t===J.Kd||function(e){return!(e&&e.series[0]&&e.series[0].fields[0]&&e.series[0].fields[0].values)}(e))return 200;const s=e.series[n].fields[0].values.length,i=5*r.spacing.gridSize,o=s*i+i;return o>=200?200:o}(t,n,o.frameIndex),p=(0,a.useStyles2)(ne(d)),[m,g]=(0,l.useState)(function(e,t){if(!e)return{defaults:{},overrides:[]};return{defaults:{thresholds:e,unit:re(t),custom:{thresholdsStyle:{mode:Y.i3.Line}}},overrides:[]}}(i,t));(0,l.useEffect)((()=>{g((e=>Object.assign({},e,{defaults:Object.assign({},e.defaults,{thresholds:i,unit:re(t),custom:Object.assign({},e.defaults.custom,{thresholdsStyle:{mode:Y.i3.Line}})})})))}),[i,g,t]);const f=(0,l.useMemo)((()=>({eventBus:ee.Z,canEditThresholds:!0,onThresholdsChange:s})),[s]);return o&&t?(0,c.jsxs)("div",{className:p.wrapper,children:[(0,c.jsx)("div",{className:p.buttonGroup,children:(0,c.jsx)(X.j,{onChange:r,value:n})}),(0,c.jsx)(H.Z,{children:e=>{let{width:r}=e;return 0===r?null:(0,c.jsx)("div",{style:{height:`${d}px`,width:`${r}px`},children:(0,c.jsx)(a.PanelContextProvider,{value:f,children:(0,c.jsx)(O.PanelRenderer,{height:d,width:r,data:t,pluginId:n,title:"title",onOptionsChange:u,options:o,fieldConfig:m})})})}})]}):null},ne=e=>t=>({wrapper:r.css`
    padding: 0 ${t.spacing(2)};
    height: ${e+4*t.spacing.gridSize}px;
  `,buttonGroup:r.css`
    display: flex;
    justify-content: flex-end;
  `});function re(e){var t,n;return null===(t=e.series[0])||void 0===t||null===(n=t.fields.find((e=>"number"===e.type)))||void 0===n?void 0:n.config.unit}const ae=e=>{let{data:t,dsSettings:n,index:r,onChangeDataSource:s,onChangeQuery:i,onChangeTimeRange:o,onRunQueries:u,onRemoveQuery:p,onDuplicateQuery:m,query:g,queries:f,thresholds:h,onChangeThreshold:v}=e;const x=(0,a.useStyles2)(ie),b=(0,j.j)(g.model),[y,w]=(0,l.useState)(b?J.Fe:J.GC);return(0,c.jsx)("div",{className:x.wrapper,children:(0,c.jsx)(K.x,{alerting:!0,dataSource:n,onChangeDataSource:b?void 0:e=>s(e,r),id:g.refId,index:r,data:t,query:(0,U.cloneDeep)(g.model),onChange:e=>i(e,r),onRemoveQuery:p,onAddQuery:()=>m((0,U.cloneDeep)(g)),onRunQuery:u,queries:f,renderHeaderExtras:()=>((e,t)=>{var n;return(0,j.j)(e.model)||!o?null:(0,c.jsx)(a.RelativeTimeRangePicker,{timeRange:null!==(n=e.relativeTimeRange)&&void 0!==n?n:(0,d.getDefaultRelativeTimeRange)(),onChange:e=>o(e,t)})})(g,r),app:d.CoreApp.UnifiedAlerting,visualization:t.state!==d.LoadingState.NotStarted?(0,c.jsx)(te,{data:t,changePanel:w,currentPanel:y,thresholds:h,onThresholdsChange:e=>v(e,r)}):null,hideDisableQuery:!0},g.refId)})},se=e=>{let{children:t}=e;const n=(0,a.useStyles2)(ie);return(0,c.jsx)("div",{className:n.wrapper,children:t})},ie=e=>({wrapper:r.css`
    label: AlertingQueryWrapper;
    margin-bottom: ${e.spacing(1)};
    border: 1px solid ${e.colors.border.medium};
    border-radius: ${e.shape.borderRadius(1)};
  `});var oe,le=n("./public/app/core/components/QueryOperationRow/QueryOperationRow.tsx"),ue=n("./public/app/features/plugins/datasource_srv.ts");function de(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class ce extends l.PureComponent{constructor(e){super(e),de(this,"onRemoveQuery",(e=>{this.props.onQueriesChange(this.props.queries.filter((t=>t.model.refId!==e.refId)))})),de(this,"onChangeTimeRange",((e,t)=>{const{queries:n,onQueriesChange:r}=this.props;r(n.map(((n,r)=>r!==t?n:Object.assign({},n,{relativeTimeRange:e}))))})),de(this,"onChangeThreshold",((e,t)=>{const{queries:n,onQueriesChange:r}=this.props,a=n[t].refId;r(n.map((t=>(0,j.j)(t.model)&&t.model.conditions&&t.model.conditions[0].query.params[0]===a?Object.assign({},t,{model:Object.assign({},t.model,{conditions:t.model.conditions.map(((t,n)=>t.query.params[0]===a&&0===n?Object.assign({},t,{evaluator:Object.assign({},t.evaluator,{params:[parseFloat(e.steps[1].value.toPrecision(3))]})}):t))})}):t)))})),de(this,"onChangeDataSource",((e,t)=>{const{queries:n,onQueriesChange:r}=this.props;r(n.map(((n,r)=>r!==t?n:function(e,t){return Object.assign({},e,{model:(0,U.omit)(e.model,"datasource"),datasourceUid:t})}(n,e.uid))))})),de(this,"onChangeQuery",((e,t)=>{const{queries:n,onQueriesChange:r}=this.props;r(function(e,t,n){return e.map((e=>{if(t===n)return e;if(!(0,j.j)(e.model))return e;const r="math"===e.model.type,a="reduce"===e.model.type,s="resample"===e.model.type,i="classic_conditions"===e.model.type;var o;if(r)return Object.assign({},e,{model:Object.assign({},e.model,{expression:y(null!==(o=e.model.expression)&&void 0!==o?o:"",t,n)})});if(s||a){const r=e.model.expression===t;return Object.assign({},e,{model:Object.assign({},e.model,{expression:r?n:e.model.expression})})}if(i){var l;const r=null===(l=e.model.conditions)||void 0===l?void 0:l.map((e=>Object.assign({},e,{query:Object.assign({},e.query,{params:e.query.params.map((e=>e===t?n:e))})})));return Object.assign({},e,{model:Object.assign({},e.model,{conditions:r})})}return e}))}(n,n[t].refId,e.refId).map(((n,r)=>{var a;return r!==t?n:Object.assign({},n,{refId:e.refId,queryType:null!==(a=n.model.queryType)&&void 0!==a?a:"",model:Object.assign({},n.model,e,{datasource:e.datasource})})})))})),de(this,"onDragEnd",(e=>{const{queries:t,onQueriesChange:n}=this.props;if(!e||!e.destination)return;const r=e.source.index,a=e.destination.index;if(r===a)return;const s=Array.from(t),[i]=s.splice(r,1);s.splice(a,0,i),n(s)})),de(this,"onDuplicateQuery",((e,t)=>{this.props.onDuplicateQuery(Object.assign({},t,{model:e}))})),de(this,"getDataSourceSettings",(e=>(0,O.getDataSourceSrv)().getInstanceSettings(e.datasourceUid))),de(this,"getThresholdsForQueries",(e=>{const t={};for(const n of e)(0,j.j)(n.model)&&Array.isArray(n.model.conditions)&&n.model.conditions.forEach(((e,n)=>{if(n>0)return;const r=e.evaluator.params[0],a=e.query.params[0];"outside_range"!==e.evaluator.type&&"within_range"!==e.evaluator.type&&(t[a]||(t[a]={mode:d.ThresholdsMode.Absolute,steps:[{value:-1/0,color:O.config.theme2.colors.success.main}]}),t[a].steps.push({value:r,color:O.config.theme2.colors.error.main}))}));return t})),this.state={dataPerQuery:{}}}render(){const{onDuplicateQuery:e,onRunQueries:t,queries:n}=this.props,r=this.getThresholdsForQueries(n);return(0,c.jsx)(W.Z5,{onDragEnd:this.onDragEnd,children:(0,c.jsx)(W.bK,{droppableId:"alerting-queries",direction:"vertical",children:a=>(0,c.jsxs)("div",Object.assign({ref:a.innerRef},a.droppableProps,{children:[n.map(((a,s)=>{var i,o;const l=null!==(i=null===(o=this.props.data)||void 0===o?void 0:o[a.refId])&&void 0!==i?i:{series:[],state:d.LoadingState.NotStarted},u=this.getDataSourceSettings(a);return u?(0,c.jsx)(ae,{index:s,dsSettings:u,data:l,query:a,onChangeQuery:this.onChangeQuery,onRemoveQuery:this.onRemoveQuery,queries:n,onChangeDataSource:this.onChangeDataSource,onDuplicateQuery:e,onRunQueries:t,onChangeTimeRange:this.onChangeTimeRange,thresholds:r[a.refId],onChangeThreshold:this.onChangeThreshold},`${a.refId}-${s}`):(0,c.jsx)(pe,{index:s,model:a.model,onUpdateDatasource:()=>{const e=(0,ue.ak)().getInstanceSettings(null);e&&this.onChangeDataSource(e,s)},onRemoveQuery:()=>{this.onRemoveQuery(a)}},`${a.refId}-${s}`)})),a.placeholder]}))})})}}const pe=e=>{let{index:t,onUpdateDatasource:n,onRemoveQuery:r,model:s}=e;const i=s.refId,[o,u]=(0,l.useState)(!1);return(0,c.jsx)(se,{children:(0,c.jsxs)(le.t,{title:i,draggable:!0,index:t,id:i,isOpen:!0,children:[(0,c.jsxs)(a.Card,{heading:"This datasource has been removed",description:"The datasource for this query was not found, it was either removed or is not installed correctly.",children:[oe||(oe=(0,c.jsx)(a.Card.Figure,{children:(0,c.jsx)(a.Icon,{name:"question-circle"})})),(0,c.jsxs)(a.Card.Actions,{children:[(0,c.jsx)(a.Button,{variant:"secondary",onClick:()=>{n()},children:"Update datasource"},"update"),(0,c.jsx)(a.Button,{variant:"destructive",onClick:r,children:"Remove query"},"remove")]}),(0,c.jsx)(a.Card.SecondaryActions,{children:(0,c.jsx)(a.Button,{onClick:()=>{u((e=>!e))},icon:o?"angle-up":"angle-down",fill:"text",size:"sm",children:"Show details"},"details")})]}),o&&(0,c.jsx)("div",{children:(0,c.jsx)("pre",{children:(0,c.jsx)("code",{children:JSON.stringify(s,null,2)})})})]})})};var me,ge=n("./public/app/features/expressions/ExpressionDatasource.ts"),fe=n("./public/app/core/utils/query.ts"),he=n("./public/app/features/expressions/utils/expressionTypes.ts"),ve=n("./public/app/features/expressions/types.ts"),xe=n("./public/app/features/alerting/unified/state/AlertingQueryRunner.ts");function be(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class je extends l.PureComponent{constructor(e){var t;super(e),be(this,"runner",void 0),be(this,"queries",void 0),be(this,"onRunQueries",(()=>{const{queries:e}=this;this.runner.run(e)})),be(this,"onCancelQueries",(()=>{this.runner.cancel()})),be(this,"onChangeQueries",(e=>{this.queries=e,this.props.onChange(e)})),be(this,"onDuplicateQuery",(e=>{const{queries:t}=this;this.onChangeQueries(ye(t,e))})),be(this,"onNewAlertingQuery",(()=>{const{queries:e}=this,t=(0,ue.ak)().getInstanceSettings("default");t&&this.onChangeQueries(ye(e,{datasourceUid:t.uid,model:{refId:"",datasource:{type:t.type,uid:t.uid}}}))})),be(this,"onNewExpressionQuery",(()=>{const{queries:e}=this;this.onChangeQueries(ye(e,{datasourceUid:ge.Yq,model:ge.mV.newQuery({type:ve.Us.classic,conditions:[he.R]})}))})),this.state={panelDataByRefId:{}},this.runner=new xe.v,this.queries=null!==(t=e.value)&&void 0!==t?t:[]}componentDidMount(){this.runner.get().subscribe((e=>{this.setState({panelDataByRefId:e})}))}componentWillUnmount(){this.runner.destroy()}renderAddQueryRow(e){return(0,c.jsxs)(a.HorizontalGroup,{spacing:"md",align:"flex-start",children:[(0,c.jsx)(a.Button,{type:"button",icon:"plus",onClick:this.onNewAlertingQuery,variant:"secondary","aria-label":Z.wl.components.QueryTab.addQuery,children:"Query"}),O.config.expressionsEnabled&&(0,c.jsx)(a.Button,{type:"button",icon:"plus",onClick:this.onNewExpressionQuery,variant:"secondary",className:e.expressionButton,children:me||(me=(0,c.jsx)("span",{children:"Expression "}))})]})}isRunning(){const e=Object.values(this.state.panelDataByRefId).find((e=>Boolean(e)));return(null==e?void 0:e.state)===d.LoadingState.Loading}renderRunQueryButton(){const e=this.isRunning(),t=Se(O.config.theme2);return e?(0,c.jsx)("div",{className:t.runWrapper,children:(0,c.jsx)(a.Button,{icon:"fa fa-spinner",type:"button",variant:"destructive",onClick:this.onCancelQueries,children:"Cancel"})}):(0,c.jsx)("div",{className:t.runWrapper,children:(0,c.jsx)(a.Button,{icon:"sync",type:"button",onClick:this.onRunQueries,children:"Run queries"})})}render(){const{value:e=[]}=this.props,{panelDataByRefId:t}=this.state,n=Se(O.config.theme2);return(0,c.jsxs)("div",{className:n.container,children:[(0,c.jsx)(ce,{data:t,queries:e,onQueriesChange:this.onChangeQueries,onDuplicateQuery:this.onDuplicateQuery,onRunQueries:this.onRunQueries}),this.renderAddQueryRow(n),this.renderRunQueryButton()]})}}const ye=(e,t)=>{const n=(0,fe.Hs)(e),r=Object.assign({},t,{refId:n,queryType:"",model:Object.assign({},t.model,{hide:!1,refId:n}),relativeTimeRange:we(t.model)});return[...e,r]},we=e=>{if(!(0,j.j)(e))return(0,d.getDefaultRelativeTimeRange)()},Se=(0,a.stylesFactory)((e=>({container:r.css`
      background-color: ${e.colors.background.primary};
      height: 100%;
      max-width: ${e.breakpoints.values.xxl}px;
    `,runWrapper:r.css`
      margin-top: ${e.spacing(1)};
    `,editorWrapper:r.css`
      border: 1px solid ${e.colors.border.medium};
      border-radius: ${e.shape.borderRadius()};
    `,expressionButton:r.css`
      margin-right: ${e.spacing(.5)};
    `}))),Ce=["ref"],Re=["ref"];function _e(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}const ke=()=>{var e,t;const{control:n,watch:r,formState:{errors:s}}=(0,g.Gc)(),i=r("type"),o=r("dataSourceName");return(0,c.jsxs)(p,{stepNo:2,title:i===f.$.cloudRecording?"Create a query to be recorded":"Create a query to be alerted on",children:[(i===f.$.cloudRecording||i===f.$.cloudAlerting)&&o&&(0,c.jsx)(a.Field,{error:null===(e=s.expression)||void 0===e?void 0:e.message,invalid:!(null===(t=s.expression)||void 0===t||!t.message),children:(0,c.jsx)(a.InputControl,{name:"expression",render:e=>{let{}=e,t=_e(e.field,Ce);return(0,c.jsx)(V,Object.assign({},t,{dataSourceName:o}))},control:n,rules:{required:{value:!0,message:"A valid expression is required"}}})}),i===f.$.grafana&&(0,c.jsx)(a.Field,{invalid:!!s.queries,error:!s.queries?void 0:"Must provide at least one valid query.",children:(0,c.jsx)(a.InputControl,{name:"queries",render:e=>{let{}=e,t=_e(e.field,Re);return(0,c.jsx)(je,Object.assign({},t))},control:n,rules:{validate:e=>Array.isArray(e)&&!!e.length}})})]})};var Oe,Ne=n("./public/app/features/alerting/unified/utils/redux.ts"),Ie=n("./public/app/features/alerting/unified/utils/rule-form.ts"),$e=n("./.yarn/__virtual__/react-router-dom-virtual-e45eb1b58b/3/opt/drone/yarncache/react-router-dom-npm-5.3.0-aa9adb5bec-47584fd629.zip/node_modules/react-router-dom/esm/react-router-dom.js"),qe=n("./public/app/core/hooks/useQueryParams.ts"),De=n("./public/app/core/core.ts"),Qe=n("./public/app/features/alerting/unified/utils/time.ts"),Ee=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/takeWhile.js"),Te=n("./.yarn/__virtual__/react-use-virtual-00326e70ba/3/opt/drone/yarncache/react-use-npm-17.3.2-a032cbeb01-7379460f51.zip/node_modules/react-use/esm/useMountedState.js"),Fe=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/observable/of.js"),Ae=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/map.js"),ze=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/catchError.js"),Le=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/share.js");function Pe(e){if(function(e){return"expr"in e}(e))return function(e){throw new Error("preview for cloud alerting rules is not implemented")}();if(function(e){return"grafana_condition"in e}(e))return function(e){const t=f.$.grafana;return(0,d.withLoadingIndicator)({whileLoading:Be(t),source:(0,O.getBackendSrv)().fetch({method:"POST",url:"/api/v1/rule/test/grafana",data:e}).pipe((0,Ae.U)((e=>{let{data:n}=e;return Be(t,{state:d.LoadingState.Done,series:n.instances.map(d.dataFrameFromJSON)})})),(0,ze.K)((e=>(0,Fe.of)(Be(t,{state:d.LoadingState.Error,error:(0,O.toDataQueryError)(e)})))),(0,Le.B)())})}(e);throw new Error("unsupported preview rule request")}function Be(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return{ruleType:e,data:Object.assign({state:d.LoadingState.Loading,series:[],timeRange:(0,d.getDefaultTimeRange)()},t)}}function Me(e){const{preview:t}=e,n=(0,a.useStyles2)(Ue),r={defaults:{},overrides:[{matcher:{id:d.FieldMatcherID.byName,options:"Info"},properties:[{id:"custom.displayMode",value:a.TableCellDisplayMode.JSONView}]}]};if(!t)return null;const{data:s,ruleType:i}=t;return s.state===d.LoadingState.Loading?(0,c.jsx)("div",{className:n.container,children:Oe||(Oe=(0,c.jsx)("span",{children:"Loading preview..."}))}):s.state===d.LoadingState.Error?(0,c.jsx)("div",{className:n.container,children:s.error?(0,Ne.kk)(s.error):"Failed to preview alert rule"}):(0,c.jsxs)("div",{className:n.container,children:[(0,c.jsxs)("span",{children:["Preview based on the result of running the query, for this moment."," ",i===f.$.grafana?"Configuration for `no data` and `error handling` is not applied.":null]}),(0,c.jsx)("div",{className:n.table,children:(0,c.jsx)(H.Z,{children:e=>{let{width:t,height:n}=e;return(0,c.jsx)("div",{style:{width:`${t}px`,height:`${n}px`},children:(0,c.jsx)(O.PanelRenderer,{title:"",width:t,height:n,pluginId:"table",data:s,fieldConfig:r})})}})})]})}function Ue(e){return{container:r.css`
      margin: ${e.spacing(2)} 0;
    `,table:r.css`
      flex: 1 1 auto;
      height: 135px;
      margin-top: ${e.spacing(2)};
      border: 1px solid ${e.colors.border.medium};
      border-radius: ${e.shape.borderRadius(1)};
    `}}const Ge=["type","dataSourceName","condition","queries","expression"];function Ve(){const e=(0,a.useStyles2)(Ze),[t,n]=function(){const[e,t]=(0,l.useState)(),{getValues:n}=(0,g.Gc)(),r=(0,Te.Z)(),a=(0,l.useCallback)((()=>{const e=function(e){const[t,n,r,a,s]=e;switch(t){case f.$.cloudAlerting:return{dataSourceName:n,expr:s};case f.$.grafana:return{grafana_condition:{condition:r,data:a,now:(0,d.dateTimeFormatISO)(Date.now())}};default:throw new Error(`Alert type ${t} not supported by preview.`)}}(n(Ge));Pe(e).pipe((0,Ee.o)((e=>!function(e){switch(e.data.state){case d.LoadingState.Done:case d.LoadingState.Error:return!0;default:return!1}}(e)),!0)).subscribe((e=>{r()&&t(e)}))}),[n,r]);return[e,a]}(),{watch:r}=(0,g.Gc)(),[s,i]=r(["type","condition"]);return s===f.$.cloudRecording||s===f.$.cloudAlerting?null:(0,c.jsxs)("div",{className:e.container,children:[(0,c.jsx)(a.HorizontalGroup,{children:(0,c.jsx)(a.Button,{disabled:!i,type:"button",variant:"primary",onClick:n,children:"Preview alerts"})}),(0,c.jsx)(Me,{preview:t})]})}function Ze(e){return{container:r.css`
      margin-top: ${e.spacing(2)};
      max-width: ${e.breakpoints.values.xxl}px;
    `}}var We;const Ke=["onChange","ref"];const He=()=>{var e,t;const n=(0,a.useStyles)(Ye),{register:r,control:s,watch:i,formState:{errors:o}}=(0,g.Gc)();return i("type")===f.$.cloudRecording?null:(0,c.jsxs)(p,{stepNo:3,title:"Define alert conditions",children:[(0,c.jsx)(a.Field,{label:"For",description:"Expression has to be true for this long for the alert to be fired.",children:(0,c.jsxs)("div",{className:n.flexRow,children:[(0,c.jsx)(a.Field,{invalid:!(null===(e=o.forTime)||void 0===e||!e.message),error:null===(t=o.forTime)||void 0===t?void 0:t.message,className:n.inlineField,children:(0,c.jsx)(a.Input,Object.assign({},r("forTime",{pattern:{value:/^\d+$/,message:"Must be a positive integer."}}),{width:8}))}),(0,c.jsx)(a.InputControl,{name:"forTimeUnit",render:e=>{let{field:{onChange:t}}=e,r=function(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e.field,Ke);return(0,c.jsx)(a.Select,Object.assign({menuShouldPortal:!0},r,{options:Qe.qr,onChange:e=>t(null==e?void 0:e.value),width:15,className:n.timeUnit}))},control:s})]})}),We||(We=(0,c.jsx)(Ve,{}))]})},Ye=e=>({inlineField:r.css`
    margin-bottom: 0;
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
  `,timeUnit:r.css`
    margin-left: ${e.spacing.xs};
  `}),Je=["onChange","ref"];const Xe=()=>{var e,t;const{watch:n,setValue:r,formState:{errors:s}}=(0,g.Gc)(),i=n("queries"),o=n("condition"),u=(0,l.useMemo)((()=>i.filter((e=>!!e.refId)).map((e=>({value:e.refId,label:e.refId})))),[i]);return(0,l.useEffect)((()=>{const e=i.filter((e=>e.datasourceUid===ge.Yq));o&&!u.find((e=>{let{value:t}=e;return t===o}))?r("condition",e.length?e[e.length-1].refId:null):!o&&e.length&&r("condition",e[e.length-1].refId)}),[o,u,i,r]),(0,c.jsx)(a.Field,{label:"Condition",description:"The query or expression that will be alerted on",error:null===(e=s.condition)||void 0===e?void 0:e.message,invalid:!(null===(t=s.condition)||void 0===t||!t.message),children:(0,c.jsx)(a.InputControl,{name:"condition",render:e=>{let{field:{onChange:t}}=e,n=function(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e.field,Je);return(0,c.jsx)(a.Select,Object.assign({menuShouldPortal:!0,"aria-label":"Condition"},n,{width:42,options:u,onChange:e=>{var n;return t(null!==(n=null==e?void 0:e.value)&&void 0!==n?n:null)},noOptionsMessage:"No queries defined"}))},rules:{required:{value:!0,message:"Please select the condition to alert on"}}})})};var et=n("./public/app/types/unified-alerting-dto.ts");const tt=["includeNoData","includeError"];const nt=[{value:et.g0.Alerting,label:"Alerting"},{value:et.g0.NoData,label:"No Data"},{value:et.g0.OK,label:"OK"},{value:et.g0.Error,label:"Error"}],rt=e=>{let{includeNoData:t,includeError:n}=e,r=function(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,tt);const s=(0,l.useMemo)((()=>t?n?nt:nt.filter((e=>e.value!==et.g0.Error)):nt.filter((e=>e.value!==et.g0.NoData))),[t,n]);return(0,c.jsx)(a.Select,Object.assign({menuShouldPortal:!0,options:s},r))};var at;const st=()=>{const{watch:e}=(0,g.Gc)(),t=e("evaluateFor"),n=e("evaluateEvery");if("0"===t)return null;const r=(0,d.parseDuration)(t),s=(0,d.parseDuration)(n);if((0,U.isEmpty)(r)||(0,U.isEmpty)(s))return null;const i=(0,d.durationToMilliseconds)(r),o=(0,d.durationToMilliseconds)(s);return i&&o&&i<=o?at||(at=(0,c.jsx)(a.Alert,{severity:"warning",title:"",children:'Setting a "for" duration that is less than or equal to the evaluation interval will result in the evaluation interval being used to calculate when an alert that has stopped receiving data will be closed.'})):null};var it=n("./public/app/features/alerting/unified/components/CollapseToggle.tsx");const ot=["onChange","ref"],lt=["onChange","ref"];var ut,dt,ct;function pt(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}const mt={required:{value:!0,message:"Required."},pattern:Qe.lR},gt={required:{value:!0,message:"Required."},pattern:Qe.O8,validate:e=>{const t=(0,d.parseDuration)(e);if(Object.keys(t).length){const e=(0,d.durationToMilliseconds)(t);if(e<1e4)return"Cannot be less than 10 seconds.";if(e%1e4!=0)return"Must be a multiple of 10 seconds."}return!0}},ft=()=>{var e,t,n,r;const s=(0,a.useStyles2)(ht),[i,o]=(0,l.useState)(!1),{register:u,formState:{errors:d}}=(0,g.Gc)(),m="eval-every-input",f="eval-for-input";return(0,c.jsxs)(p,{stepNo:3,title:"Define alert conditions",children:[ut||(ut=(0,c.jsx)(Xe,{})),(0,c.jsx)(a.Field,{label:"Evaluate",children:(0,c.jsxs)("div",{className:s.flexRow,children:[(0,c.jsx)(a.InlineLabel,{htmlFor:m,width:16,tooltip:"How often the alert will be evaluated to see if it fires",children:"Evaluate every"}),(0,c.jsx)(a.Field,{className:s.inlineField,error:null===(e=d.evaluateEvery)||void 0===e?void 0:e.message,invalid:!(null===(t=d.evaluateEvery)||void 0===t||!t.message),validationMessageHorizontalOverflow:!0,children:(0,c.jsx)(a.Input,Object.assign({id:m,width:8},u("evaluateEvery",gt)))}),(0,c.jsx)(a.InlineLabel,{htmlFor:f,width:7,tooltip:'Once condition is breached, alert will go into pending state. If it is pending for longer than the "for" value, it will become a firing alert.',children:"for"}),(0,c.jsx)(a.Field,{className:s.inlineField,error:null===(n=d.evaluateFor)||void 0===n?void 0:n.message,invalid:!(null===(r=d.evaluateFor)||void 0===r||!r.message),validationMessageHorizontalOverflow:!0,children:(0,c.jsx)(a.Input,Object.assign({id:f,width:8},u("evaluateFor",mt)))})]})}),dt||(dt=(0,c.jsx)(st,{})),(0,c.jsx)(it.U,{isCollapsed:!i,onToggle:e=>o(!e),text:"Configure no data and error handling",className:s.collapseToggle}),i&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(a.Field,{htmlFor:"no-data-state-input",label:"Alert state if no data or all values are null",children:(0,c.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=pt(e.field,ot);return(0,c.jsx)(rt,Object.assign({},n,{inputId:"no-data-state-input",width:42,includeNoData:!0,includeError:!1,onChange:e=>t(null==e?void 0:e.value)}))},name:"noDataState"})}),(0,c.jsx)(a.Field,{htmlFor:"exec-err-state-input",label:"Alert state if execution error or timeout",children:(0,c.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=pt(e.field,lt);return(0,c.jsx)(rt,Object.assign({},n,{inputId:"exec-err-state-input",width:42,includeNoData:!1,includeError:!0,onChange:e=>t(null==e?void 0:e.value)}))},name:"execErrState"})})]}),ct||(ct=(0,c.jsx)(Ve,{}))]})},ht=e=>({inlineField:r.css`
    margin-bottom: 0;
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-start;
  `,collapseToggle:r.css`
    margin: ${e.spacing(2,0,2,-1)};
  `});var vt,xt,bt,jt,yt=n("./public/app/features/alerting/unified/utils/rule-id.ts");const wt=e=>{var t;let{existing:n}=e;const r=(0,a.useStyles2)(St),s=(0,u.useDispatch)(),[i]=(0,qe.K)(),p=null!==(t=i.returnTo)&&void 0!==t?t:"/alerting/list",[m,h]=(0,l.useState)(!1),b=(0,l.useMemo)((()=>n?(0,Ie.DQ)(n):Object.assign({},(0,Ie.uZ)(),{queries:(0,Ie.s0)()},i.defaults?JSON.parse(i.defaults):{})),[n,i]),j=(0,g.cI)({mode:"onSubmit",defaultValues:b,shouldFocusError:!0}),{handleSubmit:y,watch:w}=j,S=w("type"),C=w("dataSourceName"),R=Boolean(S&&(S===f.$.grafana||!!C)),_=(0,v._)((e=>e.ruleForm.saveRule))||Ne.oq;(0,o.x)((e=>e.unifiedAlerting.ruleForm.saveRule));const k=(e,t)=>{var r,a,i,o;s((0,x.wy)({values:Object.assign({},b,e,{annotations:null!==(r=null===(a=e.annotations)||void 0===a?void 0:a.map((e=>{let{key:t,value:n}=e;return{key:t.trim(),value:n.trim()}})).filter((e=>{let{key:t,value:n}=e;return!!t&&!!n})))&&void 0!==r?r:[],labels:null!==(i=null===(o=e.labels)||void 0===o?void 0:o.map((e=>{let{key:t,value:n}=e;return{key:t.trim(),value:n.trim()}})).filter((e=>{let{key:t}=e;return!!t})))&&void 0!==i?i:[]}),existing:n,redirectOnSave:t?p:void 0}))},O=()=>{De.h$.emit(d.AppEvents.alertError,["There are errors in the form. Please correct them and try again!"])};return(0,c.jsxs)(g.RV,Object.assign({},j,{children:[(0,c.jsxs)("form",{onSubmit:e=>e.preventDefault(),className:r.form,children:[(0,c.jsxs)(a.PageToolbar,{title:"Create alert rule",pageIcon:"bell",children:[(0,c.jsx)($e.Link,{to:p,children:(0,c.jsx)(a.Button,{variant:"secondary",disabled:_.loading,type:"button",fill:"outline",children:"Cancel"})}),n?(0,c.jsx)(a.Button,{variant:"destructive",type:"button",onClick:()=>h(!0),children:"Delete"}):null,(0,c.jsxs)(a.Button,{variant:"primary",type:"button",onClick:y((e=>k(e,!1)),O),disabled:_.loading,children:[_.loading&&(0,c.jsx)(a.Spinner,{className:r.buttonSpinner,inline:!0}),"Save"]}),(0,c.jsxs)(a.Button,{variant:"primary",type:"button",onClick:y((e=>k(e,!0)),O),disabled:_.loading,children:[_.loading&&(0,c.jsx)(a.Spinner,{className:r.buttonSpinner,inline:!0}),"Save and exit"]})]}),(0,c.jsx)("div",{className:r.contentOuter,children:(0,c.jsx)(a.CustomScrollbar,{autoHeightMin:"100%",hideHorizontalTrack:!0,children:(0,c.jsxs)("div",{className:r.contentInner,children:[(0,c.jsx)(F,{editingExistingRule:!!n}),R&&(0,c.jsxs)(c.Fragment,{children:[vt||(vt=(0,c.jsx)(ke,{})),S===f.$.grafana?xt||(xt=(0,c.jsx)(ft,{})):bt||(bt=(0,c.jsx)(He,{})),jt||(jt=(0,c.jsx)(M,{}))]})]})})})]}),m?(0,c.jsx)(a.ConfirmModal,{isOpen:!0,title:"Delete rule",body:"Deleting this rule will permanently remove it. Are you sure you want to delete this rule?",confirmText:"Yes, delete",icon:"exclamation-triangle",onConfirm:()=>{if(n){const e=yt.Zk(n.ruleSourceName,n.namespace,n.group.name,n.rule);s((0,x.hS)(e,{navigateTo:"/alerting/list"}))}},onDismiss:()=>h(!1)}):null]}))},St=e=>({buttonSpinner:r.css`
      margin-right: ${e.spacing(1)};
    `,form:r.css`
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
    `,contentInner:r.css`
      flex: 1;
      padding: ${e.spacing(2)};
    `,contentOuter:r.css`
      background: ${e.colors.background.primary};
      border: 1px solid ${e.colors.border.weak};
      border-radius: ${e.shape.borderRadius()};
      margin: ${e.spacing(0,2,2)};
      overflow: hidden;
      flex: 1;
    `,flexRow:r.css`
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
    `});var Ct,Rt,_t,kt,Ot,Nt,It=n("./public/app/features/alerting/unified/hooks/useIsRuleEditable.ts");const $t=e=>{let{identifier:t}=e;(0,o.x)((e=>e.unifiedAlerting.ruleForm.existingRule));const{loading:n,result:r,error:i,dispatched:d}=(0,v._)((e=>e.ruleForm.existingRule)),p=(0,u.useDispatch)(),{isEditable:m}=(0,It.M)(yt.s0(t),null==r?void 0:r.rule);return(0,l.useEffect)((()=>{d||p((0,x.on)(t))}),[d,p,t]),n||void 0===m?Ct||(Ct=(0,c.jsx)(s.Z.Contents,{children:(0,c.jsx)(a.LoadingPlaceholder,{text:"Loading rule..."})})):i?(0,c.jsx)(s.Z.Contents,{children:(0,c.jsx)(a.Alert,{severity:"error",title:"Failed to load rule",children:i.message})}):r?!1===m?_t||(_t=(0,c.jsx)(qt,{title:"Cannot edit rule",children:"Sorry! You do not have permission to edit this rule."})):(0,c.jsx)(wt,{existing:r}):Rt||(Rt=(0,c.jsx)(qt,{title:"Rule not found",children:"Sorry! This rule does not exist."}))},qt=e=>{let{title:t,children:n}=e;return(0,c.jsxs)(a.Alert,{className:(0,a.useStyles2)(Dt).warning,severity:"warning",title:t,children:[(0,c.jsx)("p",{children:n}),Nt||(Nt=(0,c.jsx)(a.LinkButton,{href:"alerting/list",children:"To rule list"}))]})},Dt=e=>({warning:r.css`
    margin: ${e.spacing(4)};
  `}),Qt=(0,a.withErrorBoundary)((e=>{let{match:t}=e;const{id:n}=t.params,r=yt.OA(n,!0);return r?(0,c.jsx)($t,{identifier:r},n):i.Vt.hasEditPermissionInFolders||i.Vt.isEditor?Ot||(Ot=(0,c.jsx)(wt,{})):kt||(kt=(0,c.jsx)(qt,{title:"Cannot create rules",children:"Sorry! You are not allowed to create rules."}))}),{style:"page"})},"./public/app/features/alerting/unified/components/PanelPluginsButtonGroup.tsx":(e,t,n)=>{n.d(t,{j:()=>l});var r=n("./packages/grafana-runtime/src/index.ts"),a=n("./packages/grafana-ui/src/index.ts"),s=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),i=n("./public/app/features/alerting/unified/utils/constants.ts"),o=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");function l(e){const{value:t,onChange:n,size:l="md"}=e,u=(0,s.useMemo)((()=>Object.values(r.config.panels).reduce(((e,t)=>(function(e){switch(e){case i.GC:case i.Fe:case i.Kd:return!0;default:return!1}}(t.id)&&e.push({value:t.id,label:t.name,imgUrl:t.info.logos.small}),e)),[])),[]);return(0,o.jsx)(a.RadioButtonGroup,{options:u,value:t,onChange:n,size:l})}},"./public/app/features/alerting/unified/components/rule-editor/AnnotationsField.tsx":(e,t,n)=>{n.d(t,{Z:()=>f});var r=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),a=n("./packages/grafana-ui/src/index.ts"),s=n("./.yarn/__virtual__/@emotion-css-virtual-72c314ddb1/3/opt/drone/yarncache/@emotion-css-npm-11.7.1-25ff8755a7-ac1f56656f.zip/node_modules/@emotion/css/dist/emotion-css.esm.js"),i=n("./.yarn/__virtual__/react-hook-form-virtual-92b6119fd4/3/opt/drone/yarncache/react-hook-form-npm-7.5.3-f9cc466c62-fbfaa3b664.zip/node_modules/react-hook-form/dist/index.esm.js"),o=n("./public/app/features/alerting/unified/components/rule-editor/SelectWIthAdd.tsx"),l=n("./public/app/features/alerting/unified/utils/constants.ts"),u=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");const d=["value","existingKeys","aria-label"];const c=e=>{let{value:t,existingKeys:n,"aria-label":a}=e,s=function(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,d);const i=(0,r.useMemo)((()=>Object.values(l.q6).filter((e=>!n.includes(e))).map((e=>({value:e,label:l.vY[e]})))),[n]);return(0,u.jsx)(o.P,Object.assign({"aria-label":a,value:t,options:i,custom:!!t&&!Object.values(l.q6).includes(t)},s))},p=["ref"];var m;const g=e=>({annotationValueInput:s.css`
    width: 426px;
  `,textarea:s.css`
    height: 76px;
  `,addAnnotationsButton:s.css`
    flex-grow: 0;
    align-self: flex-start;
    margin-left: 148px;
  `,flexColumn:s.css`
    display: flex;
    flex-direction: column;
  `,field:s.css`
    margin-bottom: ${e.spacing.xs};
  `,flexRow:s.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
  `,flexRowItemMargin:s.css`
    margin-left: ${e.spacing.xs};
  `}),f=()=>{const e=(0,a.useStyles)(g),{control:t,register:n,watch:o,formState:{errors:l}}=(0,i.Gc)(),d=o("annotations"),f=(0,r.useCallback)((e=>d.filter(((t,n)=>n!==e)).map((e=>{let{key:t}=e;return t}))),[d]);return(0,u.jsxs)(u.Fragment,{children:[m||(m=(0,u.jsx)(a.Label,{children:"Summary and annotations"})),(0,u.jsx)(a.FieldArray,{name:"annotations",control:t,children:r=>{let{fields:i,append:o,remove:m}=r;return(0,u.jsxs)("div",{className:e.flexColumn,children:[i.map(((r,i)=>{var o,g,h,v,x,b,j,y,w,S,C,R,_,k,O;const N=null===(o=d[i])||void 0===o||null===(g=o.key)||void 0===g?void 0:g.toLocaleLowerCase().endsWith("url"),I=N?a.Input:a.TextArea;return(0,u.jsxs)("div",{className:e.flexRow,children:[(0,u.jsx)(a.Field,{className:e.field,invalid:!(null===(h=l.annotations)||void 0===h||null===(v=h[i])||void 0===v||null===(x=v.key)||void 0===x||!x.message),error:null===(b=l.annotations)||void 0===b||null===(j=b[i])||void 0===j||null===(y=j.key)||void 0===y?void 0:y.message,"data-testid":`annotation-key-${i}`,children:(0,u.jsx)(a.InputControl,{name:`annotations[${i}].key`,render:e=>{let{}=e,t=function(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e.field,p);return(0,u.jsx)(c,Object.assign({},t,{"aria-label":`Annotation detail ${i+1}`,existingKeys:f(i),width:18}))},control:t,rules:{required:{value:!(null===(w=d[i])||void 0===w||!w.value),message:"Required."}}})}),(0,u.jsx)(a.Field,{className:(0,s.cx)(e.flexRowItemMargin,e.field),invalid:!(null===(S=l.annotations)||void 0===S||null===(C=S[i])||void 0===C||null===(R=C.value)||void 0===R||!R.message),error:null===(_=l.annotations)||void 0===_||null===(k=_[i])||void 0===k||null===(O=k.value)||void 0===O?void 0:O.message,children:(0,u.jsx)(I,Object.assign({"data-testid":`annotation-value-${i}`,className:(0,s.cx)(e.annotationValueInput,{[e.textarea]:!N})},n(`annotations[${i}].value`),{placeholder:N?"https://":"Text",defaultValue:r.value}))}),(0,u.jsx)(a.Button,{type:"button",className:e.flexRowItemMargin,"aria-label":"delete annotation",icon:"trash-alt",variant:"secondary",onClick:()=>m(i)})]},r.id)})),(0,u.jsx)(a.Button,{className:e.addAnnotationsButton,icon:"plus-circle",type:"button",variant:"secondary",onClick:()=>{o({key:"",value:""})},children:"Add info"})]})}})]})}},"./public/app/features/alerting/unified/components/rule-editor/LabelsField.tsx":(e,t,n)=>{n.d(t,{Z:()=>d});n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js");var r,a,s=n("./packages/grafana-ui/src/index.ts"),i=n("./.yarn/__virtual__/@emotion-css-virtual-72c314ddb1/3/opt/drone/yarncache/@emotion-css-npm-11.7.1-25ff8755a7-ac1f56656f.zip/node_modules/@emotion/css/dist/emotion-css.esm.js"),o=n("./.yarn/__virtual__/react-hook-form-virtual-92b6119fd4/3/opt/drone/yarncache/react-hook-form-npm-7.5.3-f9cc466c62-fbfaa3b664.zip/node_modules/react-hook-form/dist/index.esm.js"),l=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");const u=e=>({wrapper:i.css`
      margin-top: ${e.spacing.md};
    `,flexColumn:i.css`
      display: flex;
      flex-direction: column;
    `,flexRow:i.css`
      display: flex;
      flex-direction: row;
      justify-content: flex-start;

      & + button {
        margin-left: ${e.spacing.xs};
      }
    `,deleteLabelButton:i.css`
      margin-left: ${e.spacing.xs};
      align-self: flex-start;
    `,addLabelButton:i.css`
      flex-grow: 0;
      align-self: flex-start;
    `,centerAlignRow:i.css`
      align-items: baseline;
    `,equalSign:i.css`
      align-self: flex-start;
      width: 28px;
      justify-content: center;
      margin-left: ${e.spacing.xs};
    `,labelInput:i.css`
      width: 183px;
      margin-bottom: ${e.spacing.sm};
      & + & {
        margin-left: ${e.spacing.sm};
      }
    `}),d=e=>{let{className:t}=e;const n=(0,s.useStyles)(u),{register:d,control:c,watch:p,formState:{errors:m}}=(0,o.Gc)(),g=p("labels");return(0,l.jsxs)("div",{className:(0,i.cx)(t,n.wrapper),children:[r||(r=(0,l.jsx)(s.Label,{children:"Custom Labels"})),(0,l.jsx)(s.FieldArray,{control:c,name:"labels",children:e=>{let{fields:t,append:r,remove:o}=e;return(0,l.jsx)(l.Fragment,{children:(0,l.jsxs)("div",{className:n.flexRow,children:[a||(a=(0,l.jsx)(s.InlineLabel,{width:18,children:"Labels"})),(0,l.jsxs)("div",{className:n.flexColumn,children:[t.map(((e,t)=>{var r,a,u,c,p,f,h,v,x,b,j,y,w,S;return(0,l.jsx)("div",{children:(0,l.jsxs)("div",{className:(0,i.cx)(n.flexRow,n.centerAlignRow),children:[(0,l.jsx)(s.Field,{className:n.labelInput,invalid:!(null===(r=m.labels)||void 0===r||null===(a=r[t])||void 0===a||null===(u=a.key)||void 0===u||!u.message),error:null===(c=m.labels)||void 0===c||null===(p=c[t])||void 0===p||null===(f=p.key)||void 0===f?void 0:f.message,children:(0,l.jsx)(s.Input,Object.assign({},d(`labels[${t}].key`,{required:{value:!(null===(h=g[t])||void 0===h||!h.value),message:"Required."}}),{placeholder:"key","data-testid":`label-key-${t}`,defaultValue:e.key}))}),(0,l.jsx)(s.InlineLabel,{className:n.equalSign,children:"="}),(0,l.jsx)(s.Field,{className:n.labelInput,invalid:!(null===(v=m.labels)||void 0===v||null===(x=v[t])||void 0===x||null===(b=x.value)||void 0===b||!b.message),error:null===(j=m.labels)||void 0===j||null===(y=j[t])||void 0===y||null===(w=y.value)||void 0===w?void 0:w.message,children:(0,l.jsx)(s.Input,Object.assign({},d(`labels[${t}].value`,{required:{value:!(null===(S=g[t])||void 0===S||!S.key),message:"Required."}}),{placeholder:"value","data-testid":`label-value-${t}`,defaultValue:e.value}))}),(0,l.jsx)(s.Button,{className:n.deleteLabelButton,"aria-label":"delete label",icon:"trash-alt",variant:"secondary",onClick:()=>{o(t)}})]})},e.id)})),(0,l.jsx)(s.Button,{className:n.addLabelButton,icon:"plus-circle",type:"button",variant:"secondary",onClick:()=>{r({})},children:"Add label"})]})]})})}})]})}},"./public/app/features/alerting/unified/components/rule-editor/SelectWIthAdd.tsx":(e,t,n)=>{n.d(t,{P:()=>i});var r=n("./packages/grafana-ui/src/index.ts"),a=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),s=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/jsx-runtime.js");const i=e=>{let{value:t,onChange:n,options:i,className:o,placeholder:l,width:u,custom:d,onCustomChange:c,disabled:p=!1,addLabel:m="+ Add new","aria-label":g}=e;const[f,h]=(0,a.useState)(d);(0,a.useEffect)((()=>{d&&h(d)}),[d]);const v=(0,a.useMemo)((()=>[...i,{value:"__add__",label:m}]),[i,m]);return f?(0,s.jsx)(r.Input,{"aria-label":g,width:u,autoFocus:!d,value:t||"",placeholder:l,className:o,disabled:p,onChange:e=>n(e.target.value)}):(0,s.jsx)(r.Select,{menuShouldPortal:!0,"aria-label":g,width:u,options:v,value:t,className:o,placeholder:l,disabled:p,onChange:e=>{const t=null==e?void 0:e.value;"__add__"===t?(h(!0),c&&c(!0),n("")):n(t)}})}},"./public/app/features/alerting/unified/hooks/useFolder.ts":(e,t,n)=>{n.d(t,{W:()=>l});var r=n("./.yarn/__virtual__/react-redux-virtual-7ad20a440e/3/opt/drone/yarncache/react-redux-npm-7.2.6-134f5ed64d-0bf142ce0d.zip/node_modules/react-redux/es/index.js"),a=n("./public/app/features/alerting/unified/hooks/useUnifiedAlertingSelector.ts"),s=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),i=n("./public/app/features/alerting/unified/state/actions.ts"),o=n("./public/app/features/alerting/unified/utils/redux.ts");function l(e){const t=(0,r.useDispatch)(),n=(0,a._)((e=>e.folders));if((0,s.useEffect)((()=>{e&&t((0,i.sw)(e))}),[t,e]),e){const t=n[e]||o.oq;return{folder:t.result,loading:t.loading}}return{loading:!1}}},"./public/app/features/alerting/unified/hooks/useIsRuleEditable.ts":(e,t,n)=>{n.d(t,{M:()=>c});var r=n("./public/app/core/services/context_srv.ts"),a=n("./public/app/features/alerting/unified/utils/rules.ts"),s=n("./public/app/features/alerting/unified/hooks/useFolder.ts"),i=n("./public/app/features/alerting/unified/hooks/useUnifiedAlertingSelector.ts"),o=n("./.yarn/__virtual__/react-redux-virtual-7ad20a440e/3/opt/drone/yarncache/react-redux-npm-7.2.6-134f5ed64d-0bf142ce0d.zip/node_modules/react-redux/es/index.js"),l=n("../../opt/drone/yarncache/react-npm-17.0.2-99ba37d931-b254cc17ce.zip/node_modules/react/index.js"),u=n("./public/app/features/alerting/unified/state/actions.ts"),d=n("./public/app/features/alerting/unified/utils/datasource.ts");function c(e,t){var n,c;const p=(0,i._)((e=>e.lotexSupportsRuleEditing)),m=(0,o.useDispatch)(),g=t&&(0,a.Pc)(t)?t.grafana_alert.namespace_uid:void 0,{folder:f,loading:h}=(0,s.W)(g);if((0,l.useEffect)((()=>{void 0===p[e]&&e!==d.GC&&m((0,u.Yb)(e))}),[e,p,m]),!t)return{isEditable:!1,loading:!1};if((0,a.Pc)(t)){if(!g)throw new Error(`Rule ${t.grafana_alert.title} does not have a folder uid, cannot determine if it is editable.`);return{isEditable:null==f?void 0:f.canSave,loading:h}}return{isEditable:r.Vt.isEditor&&!(null===(n=p[e])||void 0===n||!n.result),loading:!(null===(c=p[e])||void 0===c||!c.loading)}}},"./public/app/features/alerting/unified/state/AlertingQueryRunner.ts":(e,t,n)=>{n.d(t,{v:()=>C});var r=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/ReplaySubject.js"),a=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/observable/of.js"),s=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/catchError.js"),i=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/share.js"),o=n("../../opt/drone/yarncache/rxjs-npm-7.5.1-ce59cbb6a3-78e3eecb16.zip/node_modules/rxjs/dist/esm5/internal/operators/map.js"),l=n("../../opt/drone/yarncache/uuid-npm-8.3.2-eca0baba53-5575a8a75c.zip/node_modules/uuid/dist/esm-browser/v4.js"),u=n("./packages/grafana-data/src/index.ts"),d=n("./packages/grafana-runtime/src/index.ts"),c=n("./public/app/core/services/backend_srv.ts"),p=n("./public/app/features/query/state/runRequest.ts"),m=n("./public/app/features/expressions/types.ts");const g={from:21600,to:0},f=(e,t)=>{switch(e.type){case m.Us.classic:return h(e);case m.Us.math:return x(e,t);case m.Us.resample:case m.Us.reduce:return b(e)}},h=e=>{var t;return null===(t=e.conditions)||void 0===t?void 0:t.map((e=>e.query.params[0]))},v=(e,t)=>{let n=[],r=[g.to];for(const a of e){const e=t.find((e=>e.refId===a));e&&e.relativeTimeRange&&(n.push(e.relativeTimeRange.from),r.push(e.relativeTimeRange.to))}return{from:n,to:r}},x=(e,t)=>t.filter((t=>{var n;return"query"===t.queryType&&(null===(n=e.expression)||void 0===n?void 0:n.includes(t.refId))})).map((e=>e.refId)),b=e=>e.expression?[e.expression]:void 0;var j=n("./public/app/features/expressions/guards.ts"),y=n("./public/app/features/query/state/processing/revision.ts"),w=n("./public/app/features/query/state/processing/canceler.ts");function S(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class C{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:(0,c.i)(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(0,d.getDataSourceSrv)();S(this,"subject",void 0),S(this,"subscription",void 0),S(this,"lastResult",void 0),this.backendSrv=e,this.dataSourceSrv=t,this.subject=new r.t(1),this.lastResult={}}get(){return this.subject.asObservable()}async run(e){if(0===e.length){const t=_(e,u.LoadingState.Done);return this.subject.next(t)}for(const t of e)if(!(0,j.j)(t.model)){const n=await this.dataSourceSrv.get(t.datasourceUid);if(n.filterQuery&&!n.filterQuery(t.model)){const t=_(e,u.LoadingState.Done);return this.subject.next(t)}}this.subscription=R(this.backendSrv,e).subscribe({next:e=>{const t=I(e,((e,t)=>{const n=this.lastResult[e],r=(0,p.zR)(t,n);return(0,y.C)(r,n)}));this.lastResult=t,this.subject.next(this.lastResult)},error:e=>{this.lastResult=N(this.lastResult,e),this.subject.next(this.lastResult)}})}cancel(){if(!this.subscription)return;this.subscription.unsubscribe();let e=!1;const t=I(this.lastResult,((t,n)=>(n.state===u.LoadingState.Loading&&(e=!0),Object.assign({},n,{state:u.LoadingState.Done}))));e&&this.subject.next(t)}destroy(){this.subject&&this.subject.complete(),this.cancel()}}const R=(e,t)=>{const n=_(t,u.LoadingState.Loading),r={data:{data:t},url:"/api/v1/eval",method:"POST",requestId:(0,l.Z)()};return(0,u.withLoadingIndicator)({whileLoading:n,source:e.fetch(r).pipe(O(n),(0,s.K)((e=>(0,a.of)(N(n,e)))),(0,w.V)(e,r.requestId),(0,i.B)())})},_=(e,t)=>e.reduce(((n,r)=>(n[r.refId]={state:t,series:[],timeRange:k(r,e)},n)),{}),k=(e,t)=>{if((0,j.j)(e.model)){const n=((e,t)=>{const n=f(e,t);if(!n)return g;const{from:r,to:a}=v(n,t);return r.length||a.length?{from:Math.max(...r),to:Math.min(...a)}:g})(e.model,t);return u.rangeUtil.relativeToTimeRange(n)}return e.relativeTimeRange?u.rangeUtil.relativeToTimeRange(e.relativeTimeRange):(console.warn(`Query with refId: ${e.refId} did not have any relative time range, using default.`),(0,u.getDefaultTimeRange)())},O=e=>(0,o.U)((t=>{const{data:n}=t,r={};for(const[t,a]of Object.entries(n.results))r[t]={timeRange:e[t].timeRange,state:u.LoadingState.Done,series:a.frames.map(u.dataFrameFromJSON)};return r})),N=(e,t)=>{const n=(0,d.toDataQueryError)(t);return I(e,((e,t)=>Object.assign({},t,{state:u.LoadingState.Error,error:n})))},I=(e,t)=>{const n={};for(const[r,a]of Object.entries(e))n[r]=t(r,a);return n}},"./public/app/features/expressions/guards.ts":(e,t,n)=>{n.d(t,{j:()=>s});var r=n("./packages/grafana-runtime/src/utils/DataSourceWithBackend.ts"),a=n("./public/app/features/expressions/types.ts");const s=e=>{if(!e)return!1;if((0,r.Pr)(e.datasource))return!0;const t=e;return"string"==typeof t.type&&Object.values(a.Us).includes(t.type)}}}]);
//# sourceMappingURL=AlertingRuleForm.cd4ada1146b53ad3284f.js.map