(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{"3S08":function(e,t,n){"use strict";n.r(t);var r=n("vF1F"),a=n("kDLi"),i=n("ZGyg"),s=n("umNM"),o=n("SGmB"),l=n("q1tI"),c=n("/MKj"),u=n("Obii"),d=n("nKUr");const b=({title:e,stepNo:t,children:n,description:r})=>{const i=Object(a.useStyles2)(p);return Object(d.jsxs)("div",{className:i.parent,children:[Object(d.jsx)("div",{children:Object(d.jsx)("span",{className:i.stepNo,children:t})}),Object(d.jsx)("div",{className:i.content,children:Object(d.jsxs)(a.FieldSet,{label:e,className:i.fieldset,children:[r&&Object(d.jsx)("p",{className:i.description,children:r}),n]})})]})},p=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 j=n("NKCw"),f=n("jN8I"),h=n("71ie"),g=n("w+lj"),v=n("4Yfp");const m=({value:e,onChange:t,options:n,className:r,placeholder:i,width:s,custom:o,onCustomChange:c,disabled:u=!1,addLabel:b="+ Add new"})=>{const[p,j]=Object(l.useState)(o);Object(l.useEffect)(()=>{o&&j(o)},[o]);const f=Object(l.useMemo)(()=>[...n,{value:"__add__",label:b}],[n,b]);return p?Object(d.jsx)(a.Input,{width:s,autoFocus:!o,value:e||"",placeholder:i,className:r,disabled:u,onChange:e=>t(e.target.value)}):Object(d.jsx)(a.Select,{menuShouldPortal:!0,width:s,options:f,value:e,className:r,placeholder:i,disabled:u,onChange:e=>{const n=null==e?void 0:e.value;"__add__"===n?(j(!0),c&&c(!0),t("")):t(n)}})},O=["onChange","ref"],x=["ref"];function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function w(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}const S=({dataSourceName:e})=>{var t,n,r,i,s;const{control:o,watch:u,formState:{errors:b},setValue:p}=Object(j.h)(),f=Object(a.useStyles2)(C),[h,S]=Object(l.useState)(!1),I=Object(g.a)(e=>e.rulerRules),R=Object(c.useDispatch)();Object(l.useEffect)(()=>{R(Object(v.r)(e))},[e,R]);const N=null===(t=I[e])||void 0===t?void 0:t.result,k=u("namespace"),T=Object(l.useMemo)(()=>N?Object.keys(N).map(e=>({label:e,value:e})):[],[N]),q=Object(l.useMemo)(()=>{var e;return k&&(null==N||null===(e=N[k])||void 0===e?void 0:e.map(e=>({label:e.name,value:e.name})))||[]},[k,N]);return Object(d.jsxs)("div",{className:f.flexRow,children:[Object(d.jsx)(a.Field,{"data-testid":"namespace-picker",label:"Namespace",error:null===(n=b.namespace)||void 0===n?void 0:n.message,invalid:!(null===(r=b.namespace)||void 0===r||!r.message),children:Object(d.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=w(e.field,O);return Object(d.jsx)(m,y({},n,{className:f.input,onChange:e=>{p("group",""),t(e)},onCustomChange:e=>{e&&S(!0)},options:T,width:42}))},name:"namespace",control:o,rules:{required:{value:!0,message:"Required."}}})}),Object(d.jsx)(a.Field,{"data-testid":"group-picker",label:"Group",error:null===(i=b.group)||void 0===i?void 0:i.message,invalid:!(null===(s=b.group)||void 0===s||!s.message),children:Object(d.jsx)(a.InputControl,{render:e=>{let{}=e,t=w(e.field,x);return Object(d.jsx)(m,y({},t,{options:q,width:42,custom:h,className:f.input}))},name:"group",control:o,rules:{required:{value:!0,message:"Required."}}})})]})},C=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 I=n("t8hP"),R=n("Jzaf");const N=["value"];function k(){return(k=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function T(e){let{value:t}=e,n=function(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,N);const r=function(){const e=Object(g.a)(e=>e.lotexSupportsRuleEditing),t=Object(c.useDispatch)();return Object(l.useEffect)(()=>{Object(R.g)().filter(t=>void 0===e[t.name]).forEach(e=>t(Object(v.a)(e.name)))},[t,e]),Object(l.useMemo)(()=>Object(R.g)().filter(t=>{var n;return null===(n=e[t.name])||void 0===n?void 0:n.result}),[e])}(),a=Object(l.useCallback)(e=>!!r.find(({id:t})=>t===e.id),[r]);return Object(d.jsx)(I.DataSourcePicker,k({noDefault:!0,alerting:!0,filter:a,current:t},n))}const q=["onChange","ref"],D=["onChange","ref"],F=["ref"];function Q(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}function P(){return(P=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const E=({editingExistingRule:e})=>{var t,n,r,i,o,c,u,p;const g=Object(a.useStyles2)($),{register:v,control:m,watch:O,formState:{errors:x},setValue:y}=Object(j.h)(),w=O("type"),C=O("dataSourceName"),I=Object(l.useMemo)(()=>{const e=[{label:"Grafana managed alert",value:f.a.grafana,description:"Classic Grafana alerts based on thresholds."}];return s.a.isEditor&&e.push({label:"Cortex/Loki managed alert",value:f.a.cloud,description:"Alert based on a system or application behavior. Based on Prometheus."}),e},[]);return Object(d.jsxs)(b,{stepNo:1,title:"Alert type",children:[Object(d.jsx)(a.Field,{className:g.formInput,label:"Alert name",error:null==x||null===(t=x.name)||void 0===t?void 0:t.message,invalid:!(null===(n=x.name)||void 0===n||!n.message),children:Object(d.jsx)(a.Input,P({id:"name"},v("name",{required:{value:!0,message:"Must enter an alert name"}}),{autoFocus:!0}))}),Object(d.jsxs)("div",{className:g.flexRow,children:[Object(d.jsx)(a.Field,{disabled:e,label:"Alert type",className:g.formInput,error:null===(r=x.type)||void 0===r?void 0:r.message,invalid:!(null===(i=x.type)||void 0===i||!i.message),"data-testid":"alert-type-picker",children:Object(d.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=Q(e.field,q);return Object(d.jsx)(a.Select,P({menuShouldPortal:!0},n,{options:I,onChange:e=>t(null==e?void 0:e.value)}))},name:"type",control:m,rules:{required:{value:!0,message:"Please select alert type"}}})}),w===f.a.cloud&&Object(d.jsx)(a.Field,{className:g.formInput,label:"Select data source",error:null===(o=x.dataSourceName)||void 0===o?void 0:o.message,invalid:!(null===(c=x.dataSourceName)||void 0===c||!c.message),"data-testid":"datasource-picker",children:Object(d.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=Q(e.field,D);return Object(d.jsx)(T,P({},n,{onChange:e=>{var n;y("location",void 0),t(null!==(n=null==e?void 0:e.name)&&void 0!==n?n:null)}}))},name:"dataSourceName",control:m,rules:{required:{value:!0,message:"Please select a data source"}}})})]}),w===f.a.cloud&&C&&Object(d.jsx)(S,{dataSourceName:C}),w===f.a.grafana&&Object(d.jsx)(a.Field,{label:"Folder",className:g.formInput,error:null===(u=x.folder)||void 0===u?void 0:u.message,invalid:!(null===(p=x.folder)||void 0===p||!p.message),"data-testid":"folder-picker",children:Object(d.jsx)(a.InputControl,{render:e=>{let{}=e,t=Q(e.field,F);return Object(d.jsx)(h.a,P({},t,{enableCreateNew:!0,enableReset:!0}))},name:"folder",rules:{required:{value:!0,message:"Please select a folder"}}})})]})},$=e=>({formInput:r.css`
    width: 330px;
    & + & {
      margin-left: ${e.spacing(3)};
    }
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
  `});var L,B;function M(){return(M=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const A=e=>({wrapper:r.css`
      margin-top: ${e.spacing.md};
    `,flexColumn:r.css`
      display: flex;
      flex-direction: column;
    `,flexRow:r.css`
      display: flex;
      flex-direction: row;
      justify-content: flex-start;

      & + button {
        margin-left: ${e.spacing.xs};
      }
    `,deleteLabelButton:r.css`
      margin-left: ${e.spacing.xs};
      align-self: flex-start;
    `,addLabelButton:r.css`
      flex-grow: 0;
      align-self: flex-start;
    `,centerAlignRow:r.css`
      align-items: baseline;
    `,equalSign:r.css`
      align-self: flex-start;
      width: 28px;
      justify-content: center;
      margin-left: ${e.spacing.xs};
    `,labelInput:r.css`
      width: 183px;
      margin-bottom: ${e.spacing.sm};
      & + & {
        margin-left: ${e.spacing.sm};
      }
    `});var _=({className:e})=>{const t=Object(a.useStyles)(A),{register:n,control:i,watch:s,formState:{errors:o}}=Object(j.h)(),l=s("labels");return Object(d.jsxs)("div",{className:Object(r.cx)(e,t.wrapper),children:[L||(L=Object(d.jsx)(a.Label,{children:"Custom Labels"})),Object(d.jsx)(a.FieldArray,{control:i,name:"labels",children:({fields:e,append:i,remove:s})=>Object(d.jsx)(d.Fragment,{children:Object(d.jsxs)("div",{className:t.flexRow,children:[B||(B=Object(d.jsx)(a.InlineLabel,{width:18,children:"Labels"})),Object(d.jsxs)("div",{className:t.flexColumn,children:[e.map((e,i)=>{var c,u,b,p,j,f,h,g,v,m,O,x,y,w;return Object(d.jsx)("div",{children:Object(d.jsxs)("div",{className:Object(r.cx)(t.flexRow,t.centerAlignRow),children:[Object(d.jsx)(a.Field,{className:t.labelInput,invalid:!(null===(c=o.labels)||void 0===c||null===(u=c[i])||void 0===u||null===(b=u.key)||void 0===b||!b.message),error:null===(p=o.labels)||void 0===p||null===(j=p[i])||void 0===j||null===(f=j.key)||void 0===f?void 0:f.message,children:Object(d.jsx)(a.Input,M({},n(`labels[${i}].key`,{required:{value:!(null===(h=l[i])||void 0===h||!h.value),message:"Required."}}),{placeholder:"key","data-testid":"label-key-"+i,defaultValue:e.key}))}),Object(d.jsx)(a.InlineLabel,{className:t.equalSign,children:"="}),Object(d.jsx)(a.Field,{className:t.labelInput,invalid:!(null===(g=o.labels)||void 0===g||null===(v=g[i])||void 0===v||null===(m=v.value)||void 0===m||!m.message),error:null===(O=o.labels)||void 0===O||null===(x=O[i])||void 0===x||null===(y=x.value)||void 0===y?void 0:y.message,children:Object(d.jsx)(a.Input,M({},n(`labels[${i}].value`,{required:{value:!(null===(w=l[i])||void 0===w||!w.key),message:"Required."}}),{placeholder:"value","data-testid":"label-value-"+i,defaultValue:e.value}))}),Object(d.jsx)(a.Button,{className:t.deleteLabelButton,"aria-label":"delete label",icon:"trash-alt",variant:"secondary",onClick:()=>{s(i)}})]})},e.id)}),Object(d.jsx)(a.Button,{className:t.addLabelButton,icon:"plus-circle",type:"button",variant:"secondary",onClick:()=>{i({})},children:"Add label"})]})]})})})]})},z=n("d6cI");const U=["value","existingKeys"];function V(){return(V=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const K=e=>{let{value:t,existingKeys:n}=e,r=function(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,U);const a=Object(l.useMemo)(()=>Object.values(z.c).filter(e=>!n.includes(e)).map(e=>({value:e,label:z.k[e]})),[n]);return Object(d.jsx)(m,V({value:t,options:a,custom:!!t&&!Object.values(z.c).includes(t)},r))},G=["ref"];var Y;function H(){return(H=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const W=e=>({annotationValueInput:r.css`
    width: 426px;
  `,textarea:r.css`
    height: 76px;
  `,addAnnotationsButton:r.css`
    flex-grow: 0;
    align-self: flex-start;
    margin-left: 148px;
  `,flexColumn:r.css`
    display: flex;
    flex-direction: column;
  `,field:r.css`
    margin-bottom: ${e.spacing.xs};
  `,flexRow:r.css`
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
  `,flexRowItemMargin:r.css`
    margin-left: ${e.spacing.xs};
  `});var X,Z=()=>{const e=Object(a.useStyles)(W),{control:t,register:n,watch:i,formState:{errors:s}}=Object(j.h)(),o=i("annotations"),c=Object(l.useCallback)(e=>o.filter((t,n)=>n!==e).map(({key:e})=>e),[o]);return Object(d.jsxs)(d.Fragment,{children:[Y||(Y=Object(d.jsx)(a.Label,{children:"Summary and annotations"})),Object(d.jsx)(a.FieldArray,{name:"annotations",control:t,children:({fields:i,append:l,remove:u})=>Object(d.jsxs)("div",{className:e.flexColumn,children:[i.map((i,l)=>{var b,p,j,f,h,g,v,m,O,x,y,w,S,C,I;const R=null===(b=o[l])||void 0===b||null===(p=b.key)||void 0===p?void 0:p.toLocaleLowerCase().endsWith("url"),N=R?a.Input:a.TextArea;return Object(d.jsxs)("div",{className:e.flexRow,children:[Object(d.jsx)(a.Field,{className:e.field,invalid:!(null===(j=s.annotations)||void 0===j||null===(f=j[l])||void 0===f||null===(h=f.key)||void 0===h||!h.message),error:null===(g=s.annotations)||void 0===g||null===(v=g[l])||void 0===v||null===(m=v.key)||void 0===m?void 0:m.message,"data-testid":"annotation-key-"+l,children:Object(d.jsx)(a.InputControl,{name:`annotations[${l}].key`,render:e=>{let{}=e,t=function(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e.field,G);return Object(d.jsx)(K,H({},t,{existingKeys:c(l),width:18}))},control:t,rules:{required:{value:!(null===(O=o[l])||void 0===O||!O.value),message:"Required."}}})}),Object(d.jsx)(a.Field,{className:Object(r.cx)(e.flexRowItemMargin,e.field),invalid:!(null===(x=s.annotations)||void 0===x||null===(y=x[l])||void 0===y||null===(w=y.value)||void 0===w||!w.message),error:null===(S=s.annotations)||void 0===S||null===(C=S[l])||void 0===C||null===(I=C.value)||void 0===I?void 0:I.message,children:Object(d.jsx)(N,H({"data-testid":"annotation-value-"+l,className:Object(r.cx)(e.annotationValueInput,{[e.textarea]:!R})},n(`annotations[${l}].value`),{placeholder:R?"https://":"Text",defaultValue:i.value}))}),Object(d.jsx)(a.Button,{type:"button",className:e.flexRowItemMargin,"aria-label":"delete annotation",icon:"trash-alt",variant:"secondary",onClick:()=>u(l)})]},i.id)}),Object(d.jsx)(a.Button,{className:e.addAnnotationsButton,icon:"plus-circle",type:"button",variant:"secondary",onClick:()=>{l({key:"",value:""})},children:"Add info"})]})})]})};const J=()=>X||(X=Object(d.jsxs)(b,{stepNo:4,title:"Add details for your alert",description:"Write a summary and add labels to help you better manage your alerts",children:[Object(d.jsx)(Z,{}),Object(d.jsx)(_,{})]}));var ee=n("LvDl"),te=n("Y8YH");function ne(){return(ne=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const re=({value:e,onChange:t,dataSourceName:n})=>{var r,a;const{mapToValue:i,mapToQuery:s}=function(e){return Object(l.useMemo)(()=>{const t=Object(I.getDataSourceSrv)().getInstanceSettings(e);switch(null==t?void 0:t.type){case"loki":case"prometheus":return{mapToValue:e=>e.expr,mapToQuery:(e,t)=>ne({},e,{expr:t})};default:throw new Error(e+" is not supported as an expression editor")}},[e])}(n),[o,c]=Object(l.useState)(s({refId:"A",hide:!1},e)),{error:b,loading:p,value:j}=Object(te.a)(()=>Object(I.getDataSourceSrv)().get(n),[n]),f=Object(l.useCallback)(e=>{c(e),t(i(e))},[t,i]);if(p||(null==j?void 0:j.name)!==n)return null;if(b||!j||null==j||null===(r=j.components)||void 0===r||!r.QueryEditor){const e=(null==b?void 0:b.message)||"Data source plugin does not export any Query Editor component";return Object(d.jsxs)("div",{children:["Could not load query editor due to: ",e]})}const h=null==j||null===(a=j.components)||void 0===a?void 0:a.QueryEditor;return Object(d.jsx)(h,{query:o,queries:[o],app:u.CoreApp.CloudAlerting,onChange:f,onRunQuery:ee.noop,datasource:j})};var ae=n("Csm0"),ie=n("ngQI"),se=n("DcPX"),oe=n("jYz7");var le=n("mfno");const ce=({data:e,currentPanel:t,changePanel:n})=>{const[r,i]=Object(l.useState)({frameIndex:0,showHeader:!0}),s=function(e,t,n){const r=Object(a.useTheme2)();if(t===z.j||t===z.h||function(e){return!(e&&e.series[0]&&e.series[0].fields[0]&&e.series[0].fields[0].values)}(e))return 200;const i=e.series[n].fields[0].values.length,s=5*r.spacing.gridSize,o=i*s+s;return o>=200?200:o}(e,t,r.frameIndex),o=Object(a.useStyles2)(ue(s));return r&&e?Object(d.jsxs)("div",{className:o.wrapper,children:[Object(d.jsx)("div",{className:o.buttonGroup,children:Object(d.jsx)(le.a,{onChange:n,value:t})}),Object(d.jsx)(oe.a,{children:({width:n})=>0===n?null:Object(d.jsx)("div",{style:{height:s+"px",width:n+"px"},children:Object(d.jsx)(I.PanelRenderer,{height:s,width:n,data:e,pluginId:t,title:"title",onOptionsChange:i,options:r})})})]}):null},ue=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;
  `});var de=n("p8f7");const be=({data:e,dsSettings:t,index:n,onChangeDataSource:r,onChangeQuery:i,onChangeTimeRange:s,onRunQueries:o,onRemoveQuery:c,onDuplicateQuery:b,query:p,queries:j})=>{const f=Object(a.useStyles2)(pe),h=Object(de.a)(p.model),[g,v]=Object(l.useState)(h?z.i:z.j);return Object(d.jsx)("div",{className:f.wrapper,children:Object(d.jsx)(se.a,{dataSource:t,onChangeDataSource:h?void 0:e=>r(e,n),id:p.refId,index:n,data:e,query:Object(ee.cloneDeep)(p.model),onChange:e=>i(e,n),onRemoveQuery:c,onAddQuery:b,onRunQuery:o,queries:j,renderHeaderExtras:()=>((e,t)=>{var n;return Object(de.a)(e.model)||!s?null:Object(d.jsx)(a.RelativeTimeRangePicker,{timeRange:null!==(n=e.relativeTimeRange)&&void 0!==n?n:Object(u.getDefaultRelativeTimeRange)(),onChange:e=>s(e,t)})})(p,n),visualization:e?Object(d.jsx)(ce,{data:e,changePanel:v,currentPanel:g}):null,hideDisableQuery:!0},p.refId)})},pe=e=>({wrapper:r.css`
    label: AlertingQueryWrapper;
    margin-bottom: ${e.spacing(1)};
    border: 1px solid ${e.colors.border.medium};
    border-radius: ${e.shape.borderRadius(1)};
    padding-bottom: ${e.spacing(1)};
  `});function je(){return(je=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function fe(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class he extends l.PureComponent{constructor(e){super(e),fe(this,"onRemoveQuery",e=>{this.props.onQueriesChange(this.props.queries.filter(t=>t.model.refId!==e.refId))}),fe(this,"onChangeTimeRange",(e,t)=>{const{queries:n,onQueriesChange:r}=this.props;r(n.map((n,r)=>r!==t?n:je({},n,{relativeTimeRange:e})))}),fe(this,"onChangeDataSource",(e,t)=>{const{queries:n,onQueriesChange:r}=this.props;r(n.map((n,r)=>{if(r!==t)return n;const a=Object(I.getDataSourceSrv)().getInstanceSettings(n.datasourceUid);if((null==a?void 0:a.type)===e.uid)return je({},n,{datasourceUid:e.uid});const{refId:i,hide:s}=n.model;return je({},n,{datasourceUid:e.uid,model:{refId:i,hide:s}})}))}),fe(this,"onChangeQuery",(e,t)=>{const{queries:n,onQueriesChange:r}=this.props;r(n.map((n,r)=>r!==t?n:je({},n,{refId:e.refId,model:je({},n.model,e,{datasource:e.datasource})})))}),fe(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 i=Array.from(t),[s]=i.splice(r,1);i.splice(a,0,s),n(i)}),fe(this,"onDuplicateQuery",(e,t)=>{this.props.onDuplicateQuery(je({},t,{model:e}))}),fe(this,"getDataSourceSettings",e=>Object(I.getDataSourceSrv)().getInstanceSettings(e.datasourceUid)),this.state={dataPerQuery:{}}}render(){const{onDuplicateQuery:e,onRunQueries:t,queries:n}=this.props;return Object(d.jsx)(ie.a,{onDragEnd:this.onDragEnd,children:Object(d.jsx)(ie.c,{droppableId:"alerting-queries",direction:"vertical",children:r=>Object(d.jsxs)("div",je({ref:r.innerRef},r.droppableProps,{children:[n.map((r,a)=>{const i=this.props.data?this.props.data[r.refId]:{},s=this.getDataSourceSettings(r);return s?Object(d.jsx)(be,{index:a,dsSettings:s,data:i,query:r,onChangeQuery:this.onChangeQuery,onRemoveQuery:this.onRemoveQuery,queries:n,onChangeDataSource:this.onChangeDataSource,onDuplicateQuery:e,onRunQueries:t,onChangeTimeRange:this.onChangeTimeRange},`${r.refId}-${a}`):null}),r.placeholder]}))})})}}var ge,ve,me=n("exx3"),Oe=n("bMS5"),xe=n("9qRS"),ye=n("yhyZ"),we=n("P0IT"),Se=n("WnbS");function Ce(){return(Ce=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function Ie(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class Re extends l.PureComponent{constructor(e){var t;super(e),Ie(this,"runner",void 0),Ie(this,"queries",void 0),Ie(this,"onRunQueries",()=>{const{queries:e}=this;this.runner.run(e)}),Ie(this,"onCancelQueries",()=>{this.runner.cancel()}),Ie(this,"onChangeQueries",e=>{this.queries=e,this.props.onChange(e)}),Ie(this,"onDuplicateQuery",e=>{const{queries:t}=this;this.onChangeQueries(Ne(t,e))}),Ie(this,"onNewAlertingQuery",()=>{const{queries:e}=this,t=Object(Se.a)().getInstanceSettings("default");t&&this.onChangeQueries(Ne(e,{datasourceUid:t.uid,model:{refId:"",datasource:t.name}}))}),Ie(this,"onNewExpressionQuery",()=>{const{queries:e}=this;this.onChangeQueries(Ne(e,{datasourceUid:me.b,model:me.c.newQuery({type:ye.a.classic,conditions:[xe.a]})}))}),this.state={panelDataByRefId:{}},this.runner=new we.a,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 Object(d.jsxs)(a.HorizontalGroup,{spacing:"md",align:"flex-start",children:[Object(d.jsx)(a.Button,{type:"button",icon:"plus",onClick:this.onNewAlertingQuery,variant:"secondary","aria-label":ae.a.components.QueryTab.addQuery,children:"Query"}),I.config.expressionsEnabled&&Object(d.jsx)(a.Tooltip,{content:"Beta feature: queries could stop working in next version",placement:"right",children:Object(d.jsxs)(a.Button,{type:"button",icon:"plus",onClick:this.onNewExpressionQuery,variant:"secondary",className:e.expressionButton,children:[ge||(ge=Object(d.jsx)("span",{children:"Expression "})),ve||(ve=Object(d.jsx)(a.Icon,{name:"exclamation-triangle",className:"muted",size:"sm"}))]})})]})}isRunning(){const e=Object.values(this.state.panelDataByRefId).find(e=>Boolean(e));return(null==e?void 0:e.state)===u.LoadingState.Loading}renderRunQueryButton(){const e=this.isRunning(),t=Te(I.config.theme2);return e?Object(d.jsx)("div",{className:t.runWrapper,children:Object(d.jsx)(a.Button,{icon:"fa fa-spinner",type:"button",variant:"destructive",onClick:this.onCancelQueries,children:"Cancel"})}):Object(d.jsx)("div",{className:t.runWrapper,children:Object(d.jsx)(a.Button,{icon:"sync",type:"button",onClick:this.onRunQueries,children:"Run queries"})})}render(){const{value:e=[]}=this.props,{panelDataByRefId:t}=this.state,n=Te(I.config.theme2);return Object(d.jsxs)("div",{className:n.container,children:[Object(d.jsx)(he,{data:t,queries:e,onQueriesChange:this.onChangeQueries,onDuplicateQuery:this.onDuplicateQuery,onRunQueries:this.onRunQueries}),this.renderAddQueryRow(n),this.renderRunQueryButton()]})}}const Ne=(e,t)=>{const n=Object(Oe.b)(e),r=Ce({},t,{refId:n,queryType:"",model:Ce({},t.model,{hide:!1,refId:n}),relativeTimeRange:ke(t.model)});return[...e,r]},ke=e=>{if(!Object(de.a)(e))return Object(u.getDefaultRelativeTimeRange)()},Te=Object(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)};
    `})),qe=["ref"],De=["ref"];function Fe(){return(Fe=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function Qe(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}const Pe=()=>{var e,t;const{control:n,watch:r,formState:{errors:i}}=Object(j.h)(),s=r("type"),o=r("dataSourceName");return Object(d.jsxs)(b,{stepNo:2,title:"Create a query to be alerted on",children:[s===f.a.cloud&&o&&Object(d.jsx)(a.Field,{error:null===(e=i.expression)||void 0===e?void 0:e.message,invalid:!(null===(t=i.expression)||void 0===t||!t.message),children:Object(d.jsx)(a.InputControl,{name:"expression",render:e=>{let{}=e,t=Qe(e.field,qe);return Object(d.jsx)(re,Fe({},t,{dataSourceName:o}))},control:n,rules:{required:{value:!0,message:"A valid expression is required"}}})}),s===f.a.grafana&&Object(d.jsx)(a.Field,{invalid:!!i.queries,error:!i.queries?void 0:"Must provide at least one valid query.",children:Object(d.jsx)(a.InputControl,{name:"queries",render:e=>{let{}=e,t=Qe(e.field,De);return Object(d.jsx)(Re,Fe({},t))},control:n,rules:{validate:e=>Array.isArray(e)&&!!e.length}})})]})};var Ee,$e=n("fXZ9"),Le=n("R6rR"),Be=n("55Ip"),Me=n("9f6O"),Ae=n("HJRA"),_e=n("G1gI"),ze=n("jvbL"),Ue=n("VQUf"),Ve=n("F/XL"),Ke=n("67Y/"),Ge=n("9Z1F"),Ye=n("S1nX");function He(){return(He=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function We(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.a.grafana;return Object(u.withLoadingIndicator)({whileLoading:Xe(t),source:Object(I.getBackendSrv)().fetch({method:"POST",url:"/api/v1/rule/test/grafana",data:e}).pipe(Object(Ke.a)(({data:e})=>Xe(t,{state:u.LoadingState.Done,series:e.instances.map(u.dataFrameFromJSON)})),Object(Ge.a)(e=>Object(Ve.a)(Xe(t,{state:u.LoadingState.Error,error:Object(I.toDataQueryError)(e)}))),Object(Ye.a)())})}(e);throw new Error("unsupported preview rule request")}function Xe(e,t={}){return{ruleType:e,data:He({state:u.LoadingState.Loading,series:[],timeRange:Object(u.getDefaultTimeRange)()},t)}}function Ze(e){const{preview:t}=e,n=Object(a.useStyles2)(Je);if(!t)return null;const{data:r,ruleType:i}=t;return r.state===u.LoadingState.Loading?Object(d.jsx)("div",{className:n.container,children:Ee||(Ee=Object(d.jsx)("span",{children:"Loading preview..."}))}):r.state===u.LoadingState.Error?Object(d.jsx)("div",{className:n.container,children:null!==(s=r.error)&&void 0!==s?s:"Failed to preview alert rule"}):Object(d.jsxs)("div",{className:n.container,children:[Object(d.jsxs)("span",{children:["Preview based on the result of running the query, for this moment."," ",i===f.a.grafana?"Configuration for `no data` and `error handling` is not applied.":null]}),Object(d.jsx)("div",{className:n.table,children:Object(d.jsx)(oe.a,{children:({width:e,height:t})=>Object(d.jsx)("div",{style:{width:e+"px",height:t+"px"},children:Object(d.jsx)(I.PanelRenderer,{title:"",width:e,height:t,pluginId:"table",data:r})})})})]});var s}function Je(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 et=["type","dataSourceName","condition","queries","expression"];function tt(){const e=Object(a.useStyles2)(nt),[t,n]=function(){const[e,t]=Object(l.useState)(),{getValues:n}=Object(j.h)(),r=Object(Ue.a)(),a=Object(l.useCallback)(()=>{We(function(e){const[t,n,r,a,i]=e;switch(t){case f.a.cloud:return{dataSourceName:n,expr:i};case f.a.grafana:return{grafana_condition:{condition:r,data:a,now:Object(u.dateTimeFormatISO)(Date.now())}};default:throw new Error(`Alert type ${t} not supported by preview.`)}}(n(et))).pipe(Object(ze.a)(e=>!function(e){switch(e.data.state){case u.LoadingState.Done:case u.LoadingState.Error:return!0;default:return!1}}(e),!0)).subscribe(e=>{r()&&t(e)})},[n,r]);return[e,a]}(),{getValues:r}=Object(j.h)(),[i]=r(et);return i===f.a.cloud?null:Object(d.jsxs)("div",{className:e.container,children:[Object(d.jsx)(a.HorizontalGroup,{children:Object(d.jsx)(a.Button,{type:"button",variant:"primary",onClick:n,children:"Preview alerts"})}),Object(d.jsx)(Ze,{preview:t})]})}function nt(e){return{container:r.css`
      margin-top: ${e.spacing(2)};
    `}}var rt;const at=["onChange","ref"];function it(){return(it=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const st=()=>{var e,t;const n=Object(a.useStyles)(ot),{register:r,control:i,formState:{errors:s}}=Object(j.h)();return Object(d.jsxs)(b,{stepNo:3,title:"Define alert conditions",children:[Object(d.jsx)(a.Field,{label:"For",description:"Expression has to be true for this long for the alert to be fired.",children:Object(d.jsxs)("div",{className:n.flexRow,children:[Object(d.jsx)(a.Field,{invalid:!(null===(e=s.forTime)||void 0===e||!e.message),error:null===(t=s.forTime)||void 0===t?void 0:t.message,className:n.inlineField,children:Object(d.jsx)(a.Input,it({},r("forTime",{pattern:{value:/^\d+$/,message:"Must be a positive integer."}}),{width:8}))}),Object(d.jsx)(a.InputControl,{name:"forTimeUnit",render:e=>{let{field:{onChange:t}}=e,r=function(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e.field,at);return Object(d.jsx)(a.Select,it({menuShouldPortal:!0},r,{options:_e.d,onChange:e=>t(null==e?void 0:e.value),width:15,className:n.timeUnit}))},control:i})]})}),rt||(rt=Object(d.jsx)(tt,{}))]})},ot=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};
  `}),lt=["onChange","ref"];function ct(){return(ct=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const ut=()=>{var e,t;const{watch:n,setValue:r,formState:{errors:i}}=Object(j.h)(),s=n("queries"),o=n("condition"),c=Object(l.useMemo)(()=>s.filter(e=>!!e.refId).map(e=>({value:e.refId,label:e.refId})),[s]);return Object(l.useEffect)(()=>{const e=s.filter(e=>e.model.datasource===me.a);o&&!c.find(({value:e})=>e===o)?r("condition",e.length?e[e.length-1].refId:null):!o&&e.length&&r("condition",e[e.length-1].refId)},[o,c,s,r]),Object(d.jsx)(a.Field,{label:"Condition",description:"The query or expression that will be alerted on",error:null===(e=i.condition)||void 0===e?void 0:e.message,invalid:!(null===(t=i.condition)||void 0===t||!t.message),children:Object(d.jsx)(a.InputControl,{name:"condition",render:e=>{let{field:{onChange:t}}=e,n=function(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e.field,lt);return Object(d.jsx)(a.Select,ct({menuShouldPortal:!0},n,{width:42,options:c,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 dt=n("rhRp");const bt=["includeNoData"];function pt(){return(pt=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const jt=[{value:dt.b.Alerting,label:"Alerting"},{value:dt.b.NoData,label:"No Data"},{value:dt.b.OK,label:"OK"}],ft=e=>{let{includeNoData:t}=e,n=function(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,bt);const r=Object(l.useMemo)(()=>t?jt:jt.filter(e=>e.value!==dt.b.NoData),[t]);return Object(d.jsx)(a.Select,pt({menuShouldPortal:!0,options:r},n))};var ht;const gt=()=>{const{watch:e}=Object(j.h)(),t=e("evaluateFor"),n=e("evaluateEvery");if("0"===t)return null;const r=Object(u.parseDuration)(t),i=Object(u.parseDuration)(n);if(Object(ee.isEmpty)(r)||Object(ee.isEmpty)(i))return null;const s=Object(u.durationToMilliseconds)(r),o=Object(u.durationToMilliseconds)(i);return s&&o&&s<=o?ht||(ht=Object(d.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 vt=n("te+q");const mt=["onChange","ref"],Ot=["onChange","ref"];var xt,yt,wt,St,Ct;function It(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}function Rt(){return(Rt=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const Nt={required:{value:!0,message:"Required."},pattern:_e.a},kt={required:{value:!0,message:"Required."},pattern:_e.c,validate:e=>{const t=Object(u.parseDuration)(e);if(Object.keys(t).length){const e=Object(u.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}},Tt=()=>{var e,t,n,r;const i=Object(a.useStyles2)(qt),[s,o]=Object(l.useState)(!1),{register:c,formState:{errors:u}}=Object(j.h)();return Object(d.jsxs)(b,{stepNo:3,title:"Define alert conditions",children:[xt||(xt=Object(d.jsx)(ut,{})),Object(d.jsx)(a.Field,{label:"Evaluate",children:Object(d.jsxs)("div",{className:i.flexRow,children:[yt||(yt=Object(d.jsx)(a.InlineLabel,{width:16,tooltip:"How often the alert will be evaluated to see if it fires",children:"Evaluate every"})),Object(d.jsx)(a.Field,{className:i.inlineField,error:null===(e=u.evaluateEvery)||void 0===e?void 0:e.message,invalid:!(null===(t=u.evaluateEvery)||void 0===t||!t.message),validationMessageHorizontalOverflow:!0,children:Object(d.jsx)(a.Input,Rt({width:8},c("evaluateEvery",kt)))}),wt||(wt=Object(d.jsx)(a.InlineLabel,{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"})),Object(d.jsx)(a.Field,{className:i.inlineField,error:null===(n=u.evaluateFor)||void 0===n?void 0:n.message,invalid:!(null===(r=u.evaluateFor)||void 0===r||!r.message),validationMessageHorizontalOverflow:!0,children:Object(d.jsx)(a.Input,Rt({width:8},c("evaluateFor",Nt)))})]})}),St||(St=Object(d.jsx)(gt,{})),Object(d.jsx)(vt.a,{isCollapsed:!s,onToggle:e=>o(!e),text:"Configure no data and error handling",className:i.collapseToggle}),s&&Object(d.jsxs)(d.Fragment,{children:[Object(d.jsx)(a.Field,{label:"Alert state if no data or all values are null",children:Object(d.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=It(e.field,mt);return Object(d.jsx)(ft,Rt({},n,{width:42,includeNoData:!0,onChange:e=>t(null==e?void 0:e.value)}))},name:"noDataState"})}),Object(d.jsx)(a.Field,{label:"Alert state if execution error or timeout",children:Object(d.jsx)(a.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=It(e.field,Ot);return Object(d.jsx)(ft,Rt({},n,{width:42,includeNoData:!1,onChange:e=>t(null==e?void 0:e.value)}))},name:"execErrState"})})]}),Ct||(Ct=Object(d.jsx)(tt,{}))]})},qt=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 Dt,Ft,Qt,Pt;function Et(){return(Et=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const $t=({existing:e})=>{var t;const n=Object(a.useStyles2)(Lt),r=Object(c.useDispatch)(),[i]=Object(Me.a)(),s=null!==(t=i.returnTo)&&void 0!==t?t:"/alerting/list",b=Object(l.useMemo)(()=>e?Object(Le.f)(e):Et({},Object(Le.c)(),{queries:Object(Le.d)()},i.defaults?JSON.parse(i.defaults):{}),[e,i]),p=Object(j.g)({mode:"onSubmit",defaultValues:b,shouldFocusError:!0}),{handleSubmit:h,watch:m}=p,O=m("type"),x=m("dataSourceName"),y=Boolean(O&&(O===f.a.grafana||!!x)),w=Object(g.a)(e=>e.ruleForm.saveRule)||$e.c;Object(o.a)(e=>e.unifiedAlerting.ruleForm.saveRule);const S=(t,n)=>{var a,i,o,l;r(Object(v.t)({values:Et({},b,t,{annotations:null!==(a=null===(i=t.annotations)||void 0===i?void 0:i.map(({key:e,value:t})=>({key:e.trim(),value:t.trim()})).filter(({key:e,value:t})=>!!e&&!!t))&&void 0!==a?a:[],labels:null!==(o=null===(l=t.labels)||void 0===l?void 0:l.map(({key:e,value:t})=>({key:e.trim(),value:t.trim()})).filter(({key:e})=>!!e))&&void 0!==o?o:[]}),existing:e,redirectOnSave:n?s:void 0}))},C=()=>{Ae.a.emit(u.AppEvents.alertError,["There are errors in the form. Please correct them and try again!"])};return Object(d.jsx)(j.c,Et({},p,{children:Object(d.jsxs)("form",{onSubmit:e=>e.preventDefault(),className:n.form,children:[Object(d.jsxs)(a.PageToolbar,{title:"Create alert rule",pageIcon:"bell",children:[Object(d.jsx)(Be.Link,{to:s,children:Object(d.jsx)(a.Button,{variant:"secondary",disabled:w.loading,type:"button",fill:"outline",children:"Cancel"})}),Object(d.jsxs)(a.Button,{variant:"secondary",type:"button",onClick:h(e=>S(e,!1),C),disabled:w.loading,children:[w.loading&&Object(d.jsx)(a.Spinner,{className:n.buttonSpinner,inline:!0}),"Save"]}),Object(d.jsxs)(a.Button,{variant:"primary",type:"button",onClick:h(e=>S(e,!0),C),disabled:w.loading,children:[w.loading&&Object(d.jsx)(a.Spinner,{className:n.buttonSpinner,inline:!0}),"Save and exit"]})]}),Object(d.jsx)("div",{className:n.contentOuter,children:Object(d.jsx)(a.CustomScrollbar,{autoHeightMin:"100%",hideHorizontalTrack:!0,children:Object(d.jsxs)("div",{className:n.contentInner,children:[Object(d.jsx)(E,{editingExistingRule:!!e}),y&&Object(d.jsxs)(d.Fragment,{children:[Dt||(Dt=Object(d.jsx)(Pe,{})),O===f.a.cloud?Ft||(Ft=Object(d.jsx)(st,{})):Qt||(Qt=Object(d.jsx)(Tt,{})),Pt||(Pt=Object(d.jsx)(J,{}))]})]})})})]})}))},Lt=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 Bt,Mt,At,_t,zt,Ut,Vt=n("PynR"),Kt=n("K3Xr");const Gt=({identifier:e})=>{Object(o.a)(e=>e.unifiedAlerting.ruleForm.existingRule);const{loading:t,result:n,error:r,dispatched:s}=Object(g.a)(e=>e.ruleForm.existingRule),u=Object(c.useDispatch)(),{isEditable:b}=Object(Vt.a)(Kt.e(e),null==n?void 0:n.rule);return Object(l.useEffect)(()=>{s||u(Object(v.m)(e))},[s,u,e]),t||void 0===b?Bt||(Bt=Object(d.jsx)(i.b.Contents,{children:Object(d.jsx)(a.LoadingPlaceholder,{text:"Loading rule..."})})):r?Object(d.jsx)(i.b.Contents,{children:Object(d.jsx)(a.Alert,{severity:"error",title:"Failed to load rule",children:r.message})}):n?!1===b?At||(At=Object(d.jsx)(Yt,{title:"Cannot edit rule",children:"Sorry! You do not have permission to edit this rule."})):Object(d.jsx)($t,{existing:n}):Mt||(Mt=Object(d.jsx)(Yt,{title:"Rule not found",children:"Sorry! This rule does not exist."}))},Yt=({title:e,children:t})=>Object(d.jsxs)(a.Alert,{className:Object(a.useStyles2)(Ht).warning,severity:"warning",title:e,children:[Object(d.jsx)("p",{children:t}),Ut||(Ut=Object(d.jsx)(a.LinkButton,{href:"alerting/list",children:"To rule list"}))]}),Ht=e=>({warning:r.css`
    margin: ${e.spacing(4)};
  `});t.default=Object(a.withErrorBoundary)(({match:e})=>{const{id:t}=e.params,n=Kt.g(t,!0);return n?Object(d.jsx)(Gt,{identifier:n},t):s.a.hasEditPermissionInFolders||s.a.isEditor?zt||(zt=Object(d.jsx)($t,{})):_t||(_t=Object(d.jsx)(Yt,{title:"Cannot create rules",children:"Sorry! You are not allowed to create rules."}))},{style:"page"})},"9f6O":function(e,t,n){"use strict";(function(e){n.d(t,"a",(function(){return s}));var r=n("t8hP"),a=n("q1tI"),i=n("Ty5D");function s(){const{search:t}=Object(i.l)();return[Object(a.useMemo)(()=>Object(r.locationSearchToObject)(t||""),[t]),Object(a.useCallback)((t,n)=>e(()=>r.locationService.partial(t,n)),[])]}}).call(this,n("URgk").setImmediate)},P0IT:function(e,t,n){"use strict";var r=n("S5bw"),a=n("F/XL"),i=n("9Z1F"),s=n("S1nX"),o=n("67Y/"),l=n("7Cbv"),c=n("Obii"),u=n("t8hP"),d=n("NXk7"),b=n("tCoL"),p=n("yhyZ");const j={from:21600,to:0},f=(e,t)=>{switch(e.type){case p.a.classic:return h(e);case p.a.math:return v(e,t);case p.a.resample:case p.a.reduce:return m(e)}},h=e=>{var t;return null===(t=e.conditions)||void 0===t?void 0:t.map(e=>e.query.params[0])},g=(e,t)=>{let n=[],r=[j.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}},v=(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),m=e=>e.expression?[e.expression]:void 0;var O=n("p8f7"),x=n("65gb"),y=n("w/qm");function w(){return(w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}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}n.d(t,"a",(function(){return C}));class C{constructor(e=Object(d.c)()){S(this,"subject",void 0),S(this,"subscription",void 0),S(this,"lastResult",void 0),this.backendSrv=e,this.subject=new r.a(1),this.lastResult={}}get(){return this.subject.asObservable()}run(e){if(0===e.length){const t=R(e,c.LoadingState.Done);return this.subject.next(t)}this.subscription=I(this.backendSrv,e).subscribe({next:e=>{const t=q(e,(e,t)=>{const n=this.lastResult[e],r=Object(b.b)(t,n);return Object(x.a)(r,n)});this.lastResult=t,this.subject.next(this.lastResult)},error:e=>{this.lastResult=T(this.lastResult,e),this.subject.next(this.lastResult)}})}cancel(){if(!this.subscription)return;this.subscription.unsubscribe();let e=!1;const t=q(this.lastResult,(t,n)=>(n.state===c.LoadingState.Loading&&(e=!0),w({},n,{state:c.LoadingState.Done})));e&&this.subject.next(t)}destroy(){this.subject&&this.subject.complete(),this.cancel()}}const I=(e,t)=>{const n=R(t,c.LoadingState.Loading),r={data:{data:t},url:"/api/v1/eval",method:"POST",requestId:Object(l.a)()};return Object(c.withLoadingIndicator)({whileLoading:n,source:e.fetch(r).pipe(k(n),Object(i.a)(e=>Object(a.a)(T(n,e))),Object(y.a)(e,r.requestId),Object(s.a)())})},R=(e,t)=>e.reduce((n,r)=>(n[r.refId]={state:t,series:[],timeRange:N(r,e)},n),{}),N=(e,t)=>{if(Object(O.a)(e.model)){const n=((e,t)=>{const n=f(e,t);if(!n)return j;const{from:r,to:a}=g(n,t);return r.length||a.length?{from:Math.max(...r),to:Math.min(...a)}:j})(e.model,t);return c.rangeUtil.relativeToTimeRange(n)}return e.relativeTimeRange?c.rangeUtil.relativeToTimeRange(e.relativeTimeRange):(console.warn(`Query with refId: ${e.refId} did not have any relative time range, using default.`),Object(c.getDefaultTimeRange)())},k=e=>Object(o.a)(t=>{const{data:n}=t,r={};for(const[t,a]of Object.entries(n.results))r[t]={timeRange:e[t].timeRange,state:c.LoadingState.Done,series:a.frames.map(c.dataFrameFromJSON)};return r}),T=(e,t)=>{const n=Object(u.toDataQueryError)(t);return q(e,(e,t)=>w({},t,{state:c.LoadingState.Error,error:n}))},q=(e,t)=>{const n={};for(const[r,a]of Object.entries(e))n[r]=t(r,a);return n}},P8sI:function(e,t,n){"use strict";n.d(t,"a",(function(){return l}));var r=n("/MKj"),a=n("w+lj"),i=n("q1tI"),s=n("4Yfp"),o=n("fXZ9");function l(e){const t=Object(r.useDispatch)(),n=Object(a.a)(e=>e.folders);if(Object(i.useEffect)(()=>{e&&t(Object(s.o)(e))},[t,e]),e){const t=n[e]||o.c;return{folder:t.result,loading:t.loading}}return{loading:!1}}},PynR:function(e,t,n){"use strict";n.d(t,"a",(function(){return u}));var r=n("umNM"),a=n("IpGs"),i=n("P8sI"),s=n("w+lj"),o=n("/MKj"),l=n("q1tI"),c=n("4Yfp");function u(e,t){var n,u;const d=Object(s.a)(e=>e.lotexSupportsRuleEditing),b=Object(o.useDispatch)(),p=t&&Object(a.j)(t)?t.grafana_alert.namespace_uid:void 0,{folder:j,loading:f}=Object(i.a)(p);if(Object(l.useEffect)(()=>{void 0===d[e]&&b(Object(c.a)(e))},[e,d,b]),!t)return{isEditable:!1,loading:!1};if(Object(a.j)(t)){if(!p)throw new Error(`Rule ${t.grafana_alert.title} does not have a folder uid, cannot determine if it is editable.`);return{isEditable:null==j?void 0:j.canSave,loading:f}}return{isEditable:r.a.isEditor&&!(null===(n=d[e])||void 0===n||!n.result),loading:!(null===(u=d[e])||void 0===u||!u.loading)}}},SGmB:function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var r=n("q1tI"),a=n("/MKj"),i=n("zVNn");function s(e){const t=Object(a.useDispatch)(),n=Object(r.useRef)(e);n.current=e,Object(r.useEffect)(()=>()=>{t(Object(i.a)({stateSelector:n.current}))},[t])}},URgk:function(e,t,n){(function(e){var r=void 0!==e&&e||"undefined"!=typeof self&&self||window,a=Function.prototype.apply;function i(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new i(a.call(setTimeout,r,arguments),clearTimeout)},t.setInterval=function(){return new i(a.call(setInterval,r,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(r,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout((function(){e._onTimeout&&e._onTimeout()}),t))},n("YBdB"),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,n("yLpj"))},YBdB:function(e,t,n){(function(e,t){!function(e,n){"use strict";if(!e.setImmediate){var r,a,i,s,o,l=1,c={},u=!1,d=e.document,b=Object.getPrototypeOf&&Object.getPrototypeOf(e);b=b&&b.setTimeout?b:e,"[object process]"==={}.toString.call(e.process)?r=function(e){t.nextTick((function(){j(e)}))}:!function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?e.MessageChannel?((i=new MessageChannel).port1.onmessage=function(e){j(e.data)},r=function(e){i.port2.postMessage(e)}):d&&"onreadystatechange"in d.createElement("script")?(a=d.documentElement,r=function(e){var t=d.createElement("script");t.onreadystatechange=function(){j(e),t.onreadystatechange=null,a.removeChild(t),t=null},a.appendChild(t)}):r=function(e){setTimeout(j,0,e)}:(s="setImmediate$"+Math.random()+"$",o=function(t){t.source===e&&"string"==typeof t.data&&0===t.data.indexOf(s)&&j(+t.data.slice(s.length))},e.addEventListener?e.addEventListener("message",o,!1):e.attachEvent("onmessage",o),r=function(t){e.postMessage(s+t,"*")}),b.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n<t.length;n++)t[n]=arguments[n+1];var a={callback:e,args:t};return c[l]=a,r(l),l++},b.clearImmediate=p}function p(e){delete c[e]}function j(e){if(u)setTimeout(j,0,e);else{var t=c[e];if(t){u=!0;try{!function(e){var t=e.callback,n=e.args;switch(n.length){case 0:t();break;case 1:t(n[0]);break;case 2:t(n[0],n[1]);break;case 3:t(n[0],n[1],n[2]);break;default:t.apply(void 0,n)}}(t)}finally{p(e),u=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(this,n("yLpj"),n("8oxB"))},mfno:function(e,t,n){"use strict";n.d(t,"a",(function(){return l}));var r=n("t8hP"),a=n("kDLi"),i=n("q1tI"),s=n("d6cI"),o=n("nKUr");function l(e){const{value:t,onChange:n,size:l="md"}=e,c=Object(i.useMemo)(()=>Object.values(r.config.panels).reduce((e,t)=>(function(e){switch(e){case s.j:case s.i:case s.h:return!0;default:return!1}}(t.id)&&e.push({value:t.id,label:t.name,imgUrl:t.info.logos.small}),e),[]),[]);return Object(o.jsx)(a.RadioButtonGroup,{options:c,value:t,onChange:n,size:l})}},p8f7:function(e,t,n){"use strict";n.d(t,"a",(function(){return i}));var r=n("exx3"),a=n("yhyZ");const i=e=>{if(!e)return!1;if(e.datasource===r.a)return!0;const t=e;return"string"==typeof t.type&&Object.values(a.a).includes(t.type)}},"te+q":function(e,t,n){"use strict";n.d(t,"a",(function(){return l}));n("q1tI");var r=n("vF1F"),a=n("kDLi"),i=n("nKUr");const s=["isCollapsed","onToggle","className","text","size"];function o(){return(o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}const l=e=>{let{isCollapsed:t,onToggle:n,className:l,text:u,size:d="xl"}=e,b=function(e,t){if(null==e)return{};var n,r,a={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,s);const p=Object(a.useStyles)(c);return Object(i.jsxs)("button",o({className:Object(r.cx)(p.expandButton,l),onClick:()=>n(!t)},b,{children:[Object(i.jsx)(a.Icon,{size:d,name:t?"angle-right":"angle-down"}),u]}))},c=()=>({expandButton:r.css`
    background: none;
    border: none;

    outline: none !important;

    display: inline-flex;
    align-items: center;

    svg {
      margin-bottom: 0;
    }
  `})}}]);
//# sourceMappingURL=AlertingRuleForm.d7cfb4e56c8be9229275.js.map