AlertingRuleForm.5af23c57cbc0948c33bd.js 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*! For license information please see AlertingRuleForm.5af23c57cbc0948c33bd.js.LICENSE.txt */
  2. "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[5372],{29507:(e,t,n)=>{n.d(t,{x:()=>o});var r=n(68404),i=n(18745),a=n(45193);function o(e){const t=(0,i.useDispatch)(),n=(0,r.useRef)(e);n.current=e,(0,r.useEffect)((()=>()=>{t((0,a.e)({stateSelector:n.current}))}),[t])}},84083:(e,t,n)=>{n.r(t),n.d(t,{default:()=>wi});var r=n(36636),i=n(68404),a=n(18745),o=n(94087),s=n(69783),l=n(33801),u=n(29507),c=n(80916),d=n(43397),p=n(58257),f=n(26011),h=n(33899),g=n(83809),m=n(88414),v=n(8455),x=n(50475),b=n(59940),y=n(66322),j=n(29990),w=n(13673),C=n(43215),S=n(2937),A=n(10010),k=n(76913),I=n(7392),O=n(90923);function N(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=m.$.grafana;return(0,C.withLoadingIndicator)({whileLoading:R(t),source:(0,O.getBackendSrv)().fetch({method:"POST",url:"/api/v1/rule/test/grafana",data:e}).pipe((0,A.U)((e=>{let{data:n}=e;return R(t,{state:C.LoadingState.Done,series:n.instances.map(C.dataFrameFromJSON)})})),(0,k.K)((e=>(0,S.of)(R(t,{state:C.LoadingState.Error,error:(0,O.toDataQueryError)(e)})))),(0,I.B)())})}(e);throw new Error("unsupported preview rule request")}function R(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return{ruleType:e,data:Object.assign({state:C.LoadingState.Loading,series:[],timeRange:(0,C.getDefaultTimeRange)()},t)}}var T,$,F=n(17569),q=n(87723),E=n(45916);function L(e){const{preview:t}=e,n=(0,s.useStyles2)(D),r={defaults:{},overrides:[{matcher:{id:C.FieldMatcherID.byName,options:"Info"},properties:[{id:"custom.displayMode",value:s.TableCellDisplayMode.JSONView}]}]};if(!t)return null;const{data:i,ruleType:a}=t;return i.state===C.LoadingState.Loading?(0,E.jsx)("div",{className:n.container,children:T||(T=(0,E.jsx)("span",{children:"Loading preview..."}))}):i.state===C.LoadingState.Error?(0,E.jsx)("div",{className:n.container,children:i.error?(0,v.kk)(i.error):"Failed to preview alert rule"}):(0,E.jsxs)("div",{className:n.container,children:[(0,E.jsxs)("span",{children:["Preview based on the result of running the query, for this moment."," ",a===m.$.grafana?"Configuration for `no data` and `error handling` is not applied.":null]}),(0,E.jsx)("div",{className:n.table,children:(0,E.jsx)(q.Z,{children:e=>{let{width:t,height:n}=e;return(0,E.jsx)("div",{style:{width:`${t}px`,height:`${n}px`},children:(0,E.jsx)(O.PanelRenderer,{title:"",width:t,height:n,pluginId:"table",data:i,fieldConfig:r})})}})})]})}function D(e){return{container:r.css`
  3. margin: ${e.spacing(2)} 0;
  4. `,table:r.css`
  5. flex: 1 1 auto;
  6. height: 135px;
  7. margin-top: ${e.spacing(2)};
  8. border: 1px solid ${e.colors.border.medium};
  9. border-radius: ${e.shape.borderRadius(1)};
  10. `}}const M=["type","dataSourceName","condition","queries","expression"];function Q(){const e=(0,s.useStyles2)(B),[t,n]=function(){const[e,t]=(0,i.useState)(),{getValues:n}=(0,c.Gc)(),r=(0,j.Z)(),a=(0,i.useCallback)((()=>{const e=function(e){const[t,n,r,i,a]=e;switch(t){case m.$.cloudAlerting:return{dataSourceName:n,expr:a};case m.$.grafana:return{grafana_condition:{condition:r,data:i,now:(0,C.dateTimeFormatISO)(Date.now())}};default:throw new Error(`Alert type ${t} not supported by preview.`)}}(n(M));N(e).pipe((0,w.o)((e=>!function(e){switch(e.data.state){case C.LoadingState.Done:case C.LoadingState.Error:return!0;default:return!1}}(e)),!0)).subscribe((e=>{r()&&t(e)}))}),[n,r]);return[e,a]}(),{watch:r}=(0,c.Gc)(),[a,o,l]=r(["type","condition","queries"]),{allDataSourcesAvailable:u}=(0,F.S)(l);if(a===m.$.cloudRecording||a===m.$.cloudAlerting)return null;const d=Boolean(o)&&u;return(0,E.jsxs)("div",{className:e.container,children:[(0,E.jsxs)(s.HorizontalGroup,{children:[u&&(0,E.jsx)(s.Button,{disabled:!d,type:"button",variant:"primary",onClick:n,children:"Preview alerts"}),!u&&($||($=(0,E.jsx)(s.Alert,{title:"Preview is not available",severity:"warning",children:"Cannot display the query preview. Some of the data sources used in the queries are not available."})))]}),(0,E.jsx)(L,{preview:t})]})}function B(e){return{container:r.css`
  11. margin-top: ${e.spacing(2)};
  12. max-width: ${e.breakpoints.values.xxl}px;
  13. `}}const _=e=>{let{title:t,stepNo:n,children:r,description:i}=e;const a=(0,s.useStyles2)(P);return(0,E.jsxs)("div",{className:a.parent,children:[(0,E.jsx)("div",{children:(0,E.jsx)("span",{className:a.stepNo,children:n})}),(0,E.jsx)("div",{className:a.content,children:(0,E.jsxs)(s.FieldSet,{label:t,className:a.fieldset,children:[i&&(0,E.jsx)("p",{className:a.description,children:i}),r]})})]})},P=e=>({fieldset:r.css`
  14. legend {
  15. font-size: 16px;
  16. padding-top: ${e.spacing(.5)};
  17. }
  18. `,parent:r.css`
  19. display: flex;
  20. flex-direction: row;
  21. max-width: ${e.breakpoints.values.xl};
  22. & + & {
  23. margin-top: ${e.spacing(4)};
  24. }
  25. `,description:r.css`
  26. margin-top: -${e.spacing(2)};
  27. color: ${e.colors.text.secondary};
  28. `,stepNo:r.css`
  29. display: inline-block;
  30. width: ${e.spacing(4)};
  31. height: ${e.spacing(4)};
  32. line-height: ${e.spacing(4)};
  33. border-radius: ${e.spacing(4)};
  34. text-align: center;
  35. color: ${e.colors.text.maxContrast};
  36. background-color: ${e.colors.background.canvas};
  37. font-size: ${e.typography.size.lg};
  38. margin-right: ${e.spacing(2)};
  39. `,content:r.css`
  40. flex: 1;
  41. `});var U;const V=["onChange","ref"];const G=()=>{var e,t;const n=(0,s.useStyles)(Y),{register:r,control:i,watch:a,formState:{errors:o}}=(0,c.Gc)();return a("type")===m.$.cloudRecording?null:(0,E.jsxs)(_,{stepNo:2,title:"Alert evaluation behavior",children:[(0,E.jsx)(s.Field,{label:"For",description:"Expression has to be true for this long for the alert to be fired.",children:(0,E.jsxs)("div",{className:n.flexRow,children:[(0,E.jsx)(s.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,E.jsx)(s.Input,Object.assign({},r("forTime",{pattern:{value:/^\d+$/,message:"Must be a positive integer."}}),{width:8}))}),(0,E.jsx)(s.InputControl,{name:"forTimeUnit",render:e=>{let{field:{onChange:t}}=e,r=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e.field,V);return(0,E.jsx)(s.Select,Object.assign({},r,{options:y.qr,onChange:e=>t(null==e?void 0:e.value),width:15,className:n.timeUnit}))},control:i})]})}),U||(U=(0,E.jsx)(Q,{}))]})},Y=e=>({inlineField:r.css`
  42. margin-bottom: 0;
  43. `,flexRow:r.css`
  44. display: flex;
  45. flex-direction: row;
  46. justify-content: flex-start;
  47. align-items: flex-start;
  48. `,timeUnit:r.css`
  49. margin-left: ${e.spacing.xs};
  50. `});var W=n(23019),Z=n.n(W),z=n(90747),K=n(61959),H=n(58170),J=n(93783),X=n(19854),ee=n(92691);function te(e,t,n){const r=new RegExp("(\\$"+t+"\\b)|(\\${"+t+"})","gm"),i="${"+n+"}";return e.replace(r,i)}function ne(e){return!(e.includes("/")||e.includes("\\"))||'Cannot contain "/" or "\\" characters'}const re=["onChange","ref"],ie=["ref"];function ae(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}const oe=e=>{var t,n,r,o,l;let{rulesSourceName:u}=e;const{control:d,watch:p,formState:{errors:f},setValue:m}=(0,c.Gc)(),v=(0,s.useStyles2)(se),[x,b]=(0,i.useState)(!1),y=(0,h._)((e=>e.rulerRules)),j=(0,a.useDispatch)();(0,i.useEffect)((()=>{j((0,g.UR)({rulesSourceName:u}))}),[u,j]);const w=null===(t=y[u])||void 0===t?void 0:t.result,C=p("namespace"),S=(0,i.useMemo)((()=>w?Object.keys(w).map((e=>({label:e,value:e}))):[]),[w]),A=(0,i.useMemo)((()=>{var e;return C&&(null==w||null===(e=w[C])||void 0===e?void 0:e.map((e=>({label:e.name,value:e.name}))))||[]}),[C,w]);return(0,E.jsxs)("div",{className:v.flexRow,children:[(0,E.jsx)(s.Field,{"data-testid":"namespace-picker",label:"Namespace",error:null===(n=f.namespace)||void 0===n?void 0:n.message,invalid:!(null===(r=f.namespace)||void 0===r||!r.message),children:(0,E.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=ae(e.field,re);return(0,E.jsx)(X.P,Object.assign({},n,{className:v.input,onChange:e=>{m("group",""),t(e)},onCustomChange:e=>{e&&b(!0)},options:S,width:42}))},name:"namespace",control:d,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:ne}}})}),(0,E.jsx)(s.Field,{"data-testid":"group-picker",label:"Group",error:null===(o=f.group)||void 0===o?void 0:o.message,invalid:!(null===(l=f.group)||void 0===l||!l.message),children:(0,E.jsx)(s.InputControl,{render:e=>{let{}=e,t=ae(e.field,ie);return(0,E.jsx)(X.P,Object.assign({},t,{options:A,width:42,custom:x,className:v.input}))},name:"group",control:d,rules:{required:{value:!0,message:"Required."},validate:{pathSeparator:ne}}})})]})},se=e=>({flexRow:r.css`
  51. display: flex;
  52. flex-direction: row;
  53. justify-content: flex-start;
  54. & > * + * {
  55. margin-left: ${e.spacing(3)};
  56. }
  57. `,input:r.css`
  58. width: 330px !important;
  59. `});var le=n(95513);const ue=["value","folderPermissions"];const ce=e=>{let{value:t,folderPermissions:n=[]}=e,r=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,ue);return(0,E.jsx)(le.E,Object.assign({showRoot:!1,allowEmpty:!0,initialTitle:null==t?void 0:t.title,initialFolderId:null==t?void 0:t.id,accessControlMetadata:!0},r,{permissionLevel:H.bf.View}))},de=["ref"];var pe,fe;const he={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_:]*$/},ge=e=>{var t,n,r,i,a,o;let{initialFolder:l}=e;const{register:u,watch:d,formState:{errors:p}}=(0,c.Gc)(),f=(0,s.useStyles2)(ve),h=d("type"),g=d("dataSourceName"),v=d("type"),x=me(l);return(0,E.jsxs)(_,{stepNo:v===m.$.cloudRecording?2:3,title:v===m.$.cloudRecording?"Add details for your recording rule":"Add details for your alert",description:v===m.$.cloudRecording?"Add labels to help you better manage your rules":"Write a summary and add labels to help you better manage your alerts",children:[(0,E.jsx)(s.Field,{className:f.formInput,label:"Rule name",error:null==p||null===(t=p.name)||void 0===t?void 0:t.message,invalid:!(null===(n=p.name)||void 0===n||!n.message),children:(0,E.jsx)(s.Input,Object.assign({id:"name"},u("name",{required:{value:!0,message:"Must enter an alert name"},pattern:h===m.$.cloudRecording?he:void 0,validate:{pathSeparator:e=>h!==m.$.grafana||ne(e)}})))}),(h===m.$.cloudRecording||h===m.$.cloudAlerting)&&g&&(0,E.jsx)(oe,{rulesSourceName:g}),h===m.$.grafana&&(0,E.jsxs)("div",{className:Z()([f.flexRow,f.alignBaseline]),children:[(0,E.jsx)(s.Field,{label:pe||(pe=(0,E.jsx)(s.Label,{htmlFor:"folder",description:"Select a folder to store your rule.",children:(0,E.jsxs)(z.Stack,{gap:.5,children:["Folder",(0,E.jsx)(s.Tooltip,{placement:"top",content:(0,E.jsx)("div",{children:"Each folder has unique folder permission. When you store multiple rules in a folder, the folder access permissions get assigned to the rules."}),children:(0,E.jsx)(s.Icon,{name:"info-circle",size:"xs"})})]})})),className:f.formInput,error:null===(r=p.folder)||void 0===r?void 0:r.message,invalid:!(null===(i=p.folder)||void 0===i||!i.message),"data-testid":"folder-picker",children:(0,E.jsx)(s.InputControl,{render:e=>{let{}=e,t=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e.field,de);return(0,E.jsx)(ce,Object.assign({inputId:"folder"},t,{enableCreateNew:K.Vt.hasPermission(H.bW.FoldersCreate),enableReset:!0,filter:x}))},name:"folder",rules:{required:{value:!0,message:"Please select a folder"},validate:{pathSeparator:e=>ne(e.title)}}})}),(0,E.jsx)(s.Field,{label:"Group","data-testid":"group-picker",description:"Rules within the same group are evaluated after the same time interval.",className:f.formInput,error:null===(a=p.group)||void 0===a?void 0:a.message,invalid:!(null===(o=p.group)||void 0===o||!o.message),children:(0,E.jsx)(s.Input,Object.assign({id:"group"},u("group",{required:{value:!0,message:"Must enter a group name"}})))})]}),v!==m.$.cloudRecording&&(fe||(fe=(0,E.jsx)(J.Z,{})))]})},me=e=>{const t=(0,i.useCallback)((t=>{const n=K.Vt.hasEditPermissionInFolders,r=K.Vt.hasAccessInMetadata(H.bW.AlertingRuleCreate,t,n),i=e&&t.folderId===e.id&&K.Vt.hasAccessInMetadata(H.bW.AlertingRuleUpdate,t,n);return r||i}),[e]);return(0,i.useCallback)((e=>e.filter(t)),[t])},ve=e=>({alignBaseline:r.css`
  60. align-items: baseline;
  61. margin-bottom: ${e.spacing(3)};
  62. `,formInput:r.css`
  63. width: 275px;
  64. & + & {
  65. margin-left: ${e.spacing(3)};
  66. }
  67. `,flexRow:r.css`
  68. display: flex;
  69. flex-direction: row;
  70. justify-content: flex-start;
  71. align-items: flex-end;
  72. `});var xe=n(91045),be=n(51542);const ye=["includeNoData","includeError"];const je=[{value:be.g0.Alerting,label:"Alerting"},{value:be.g0.NoData,label:"No Data"},{value:be.g0.OK,label:"OK"},{value:be.g0.Error,label:"Error"}],we=e=>{let{includeNoData:t,includeError:n}=e,r=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,ye);const a=(0,i.useMemo)((()=>t?n?je:je.filter((e=>e.value!==be.g0.Error)):je.filter((e=>e.value!==be.g0.NoData))),[t,n]);return(0,E.jsx)(s.Select,Object.assign({options:a},r))};var Ce,Se=n(82897);const Ae=()=>{const{watch:e}=(0,c.Gc)(),t=e("evaluateFor"),n=e("evaluateEvery");if("0"===t)return null;const r=(0,C.parseDuration)(t),i=(0,C.parseDuration)(n);if((0,Se.isEmpty)(r)||(0,Se.isEmpty)(i))return null;const a=(0,C.durationToMilliseconds)(r),o=(0,C.durationToMilliseconds)(i);return a&&o&&a<=o?Ce||(Ce=(0,E.jsx)(s.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},ke=["onChange","ref"],Ie=["onChange","ref"];var Oe,Ne;function Re(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}const Te={required:{value:!0,message:"Required."},pattern:y.lR},$e={required:{value:!0,message:"Required."},pattern:y.O8,validate:e=>{const t=(0,C.parseDuration)(e);if(Object.keys(t).length){const e=(0,C.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}},Fe=()=>{var e,t;const n=(0,s.useStyles2)(qe),[r,a]=(0,i.useState)(!1),{register:o,formState:{errors:l}}=(0,c.Gc)(),u="eval-every-input",d="eval-for-input";return(0,E.jsxs)(_,{stepNo:2,title:"Alert evaluation behavior",children:[(0,E.jsx)(s.Field,{label:"Evaluate",description:"Evaluation interval applies to every rule within a group. It can overwrite the interval of an existing alert rule.",children:(0,E.jsxs)("div",{className:n.flexRow,children:[(0,E.jsx)(s.InlineLabel,{htmlFor:u,width:16,tooltip:"How often the alert will be evaluated to see if it fires",children:"Evaluate every"}),(0,E.jsx)(s.Input,Object.assign({id:u,width:8},o("evaluateEvery",$e))),(0,E.jsx)(s.InlineLabel,{htmlFor:d,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,E.jsx)(s.Field,{className:n.inlineField,error:null===(e=l.evaluateFor)||void 0===e?void 0:e.message,invalid:!(null===(t=l.evaluateFor)||void 0===t||!t.message),validationMessageHorizontalOverflow:!0,children:(0,E.jsx)(s.Input,Object.assign({id:d,width:8},o("evaluateFor",Te)))})]})}),Oe||(Oe=(0,E.jsx)(Ae,{})),(0,E.jsx)(xe.U,{isCollapsed:!r,onToggle:e=>a(!e),text:"Configure no data and error handling",className:n.collapseToggle}),r&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(s.Field,{htmlFor:"no-data-state-input",label:"Alert state if no data or all values are null",children:(0,E.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=Re(e.field,ke);return(0,E.jsx)(we,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,E.jsx)(s.Field,{htmlFor:"exec-err-state-input",label:"Alert state if execution error or timeout",children:(0,E.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=Re(e.field,Ie);return(0,E.jsx)(we,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"})})]}),Ne||(Ne=(0,E.jsx)(Q,{}))]})},qe=e=>({inlineField:r.css`
  73. margin-bottom: 0;
  74. `,flexRow:r.css`
  75. display: flex;
  76. flex-direction: row;
  77. justify-content: flex-start;
  78. align-items: flex-start;
  79. `,collapseToggle:r.css`
  80. margin: ${e.spacing(2,0,2,-1)};
  81. `});var Ee,Le,De,Me=n(2394);const Qe=()=>{const[e,t]=(0,i.useState)(!1),n=(0,s.useStyles2)(Be),r=(0,s.useTheme2)();return(0,E.jsxs)(_,{stepNo:4,title:"Notifications",description:"Grafana handles the notifications for alerts by assigning labels to alerts. These labels connect alerts to contact points and silence alert instances that have matching labels.",children:[(0,E.jsx)("div",{children:(0,E.jsx)("div",{className:n.hideButton,onClick:()=>t(!e),children:(e?"Show":"Hide")+" flow chart"})}),(0,E.jsxs)("div",{className:n.contentWrapper,children:[!e&&(0,E.jsx)("img",{className:n.flowChart,src:`public/img/alerting/notification_policy_${r.name.toLowerCase()}.svg`,alt:"notification policy flow chart"}),(0,E.jsxs)("div",{style:{display:"flex",flexDirection:"column"},children:[Ee||(Ee=(0,E.jsx)(Me.Z,{})),(0,E.jsxs)(s.Card,{className:n.card,children:[Le||(Le=(0,E.jsx)(s.Card.Heading,{children:"Root route – default for all alerts"})),De||(De=(0,E.jsxs)(s.Card.Description,{children:["Without custom labels, your alert will be routed through the root route. To view and edit the root route, go to ",(0,E.jsx)(s.Link,{href:"/alerting/routes",children:"notification policies"})," or contact your admin in case you are using non-Grafana alert management."]}))]})]})]})]})},Be=e=>({contentWrapper:r.css`
  82. display: flex;
  83. align-items: center;
  84. `,hideButton:r.css`
  85. color: ${e.colors.text.secondary};
  86. cursor: pointer;
  87. margin-bottom: ${e.spacing(1)};
  88. `,card:r.css`
  89. max-width: 500px;
  90. `,flowChart:r.css`
  91. margin-right: ${e.spacing(3)};
  92. `});function _e(e){return null==e}var Pe={isNothing:_e,isObject:function(e){return"object"==typeof e&&null!==e},toArray:function(e){return Array.isArray(e)?e:_e(e)?[]:[e]},repeat:function(e,t){var n,r="";for(n=0;n<t;n+=1)r+=e;return r},isNegativeZero:function(e){return 0===e&&Number.NEGATIVE_INFINITY===1/e},extend:function(e,t){var n,r,i,a;if(t)for(n=0,r=(a=Object.keys(t)).length;n<r;n+=1)e[i=a[n]]=t[i];return e}};function Ue(e,t){var n="",r=e.reason||"(unknown reason)";return e.mark?(e.mark.name&&(n+='in "'+e.mark.name+'" '),n+="("+(e.mark.line+1)+":"+(e.mark.column+1)+")",!t&&e.mark.snippet&&(n+="\n\n"+e.mark.snippet),r+" "+n):r}function Ve(e,t){Error.call(this),this.name="YAMLException",this.reason=e,this.mark=t,this.message=Ue(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=(new Error).stack||""}Ve.prototype=Object.create(Error.prototype),Ve.prototype.constructor=Ve,Ve.prototype.toString=function(e){return this.name+": "+Ue(this,e)};var Ge=Ve;function Ye(e,t,n,r,i){var a="",o="",s=Math.floor(i/2)-1;return r-t>s&&(t=r-s+(a=" ... ").length),n-r>s&&(n=r+s-(o=" ...").length),{str:a+e.slice(t,n).replace(/\t/g,"→")+o,pos:r-t+a.length}}function We(e,t){return Pe.repeat(" ",t-e.length)+e}var Ze=function(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),"number"!=typeof t.indent&&(t.indent=1),"number"!=typeof t.linesBefore&&(t.linesBefore=3),"number"!=typeof t.linesAfter&&(t.linesAfter=2);for(var n,r=/\r?\n|\r|\0/g,i=[0],a=[],o=-1;n=r.exec(e.buffer);)a.push(n.index),i.push(n.index+n[0].length),e.position<=n.index&&o<0&&(o=i.length-2);o<0&&(o=i.length-1);var s,l,u="",c=Math.min(e.line+t.linesAfter,a.length).toString().length,d=t.maxLength-(t.indent+c+3);for(s=1;s<=t.linesBefore&&!(o-s<0);s++)l=Ye(e.buffer,i[o-s],a[o-s],e.position-(i[o]-i[o-s]),d),u=Pe.repeat(" ",t.indent)+We((e.line-s+1).toString(),c)+" | "+l.str+"\n"+u;for(l=Ye(e.buffer,i[o],a[o],e.position,d),u+=Pe.repeat(" ",t.indent)+We((e.line+1).toString(),c)+" | "+l.str+"\n",u+=Pe.repeat("-",t.indent+c+3+l.pos)+"^\n",s=1;s<=t.linesAfter&&!(o+s>=a.length);s++)l=Ye(e.buffer,i[o+s],a[o+s],e.position-(i[o]-i[o+s]),d),u+=Pe.repeat(" ",t.indent)+We((e.line+s+1).toString(),c)+" | "+l.str+"\n";return u.replace(/\n$/,"")},ze=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],Ke=["scalar","sequence","mapping"];var He=function(e,t){if(t=t||{},Object.keys(t).forEach((function(t){if(-1===ze.indexOf(t))throw new Ge('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')})),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=function(e){var t={};return null!==e&&Object.keys(e).forEach((function(n){e[n].forEach((function(e){t[String(e)]=n}))})),t}(t.styleAliases||null),-1===Ke.indexOf(this.kind))throw new Ge('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function Je(e,t){var n=[];return e[t].forEach((function(e){var t=n.length;n.forEach((function(n,r){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=r)})),n[t]=e})),n}function Xe(e){return this.extend(e)}Xe.prototype.extend=function(e){var t=[],n=[];if(e instanceof He)n.push(e);else if(Array.isArray(e))n=n.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new Ge("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit))}t.forEach((function(e){if(!(e instanceof He))throw new Ge("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new Ge("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new Ge("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")})),n.forEach((function(e){if(!(e instanceof He))throw new Ge("Specified list of YAML types (or a single Type object) contains a non-Type object.")}));var r=Object.create(Xe.prototype);return r.implicit=(this.implicit||[]).concat(t),r.explicit=(this.explicit||[]).concat(n),r.compiledImplicit=Je(r,"implicit"),r.compiledExplicit=Je(r,"explicit"),r.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function r(e){e.multi?(n.multi[e.kind].push(e),n.multi.fallback.push(e)):n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e<t;e+=1)arguments[e].forEach(r);return n}(r.compiledImplicit,r.compiledExplicit),r};var et=Xe,tt=new He("tag:yaml.org,2002:str",{kind:"scalar",construct:function(e){return null!==e?e:""}}),nt=new He("tag:yaml.org,2002:seq",{kind:"sequence",construct:function(e){return null!==e?e:[]}}),rt=new He("tag:yaml.org,2002:map",{kind:"mapping",construct:function(e){return null!==e?e:{}}}),it=new et({explicit:[tt,nt,rt]});var at=new He("tag:yaml.org,2002:null",{kind:"scalar",resolve:function(e){if(null===e)return!0;var t=e.length;return 1===t&&"~"===e||4===t&&("null"===e||"Null"===e||"NULL"===e)},construct:function(){return null},predicate:function(e){return null===e},represent:{canonical:function(){return"~"},lowercase:function(){return"null"},uppercase:function(){return"NULL"},camelcase:function(){return"Null"},empty:function(){return""}},defaultStyle:"lowercase"});var ot=new He("tag:yaml.org,2002:bool",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t=e.length;return 4===t&&("true"===e||"True"===e||"TRUE"===e)||5===t&&("false"===e||"False"===e||"FALSE"===e)},construct:function(e){return"true"===e||"True"===e||"TRUE"===e},predicate:function(e){return"[object Boolean]"===Object.prototype.toString.call(e)},represent:{lowercase:function(e){return e?"true":"false"},uppercase:function(e){return e?"TRUE":"FALSE"},camelcase:function(e){return e?"True":"False"}},defaultStyle:"lowercase"});function st(e){return 48<=e&&e<=55}function lt(e){return 48<=e&&e<=57}var ut=new He("tag:yaml.org,2002:int",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,r=e.length,i=0,a=!1;if(!r)return!1;if("-"!==(t=e[i])&&"+"!==t||(t=e[++i]),"0"===t){if(i+1===r)return!0;if("b"===(t=e[++i])){for(i++;i<r;i++)if("_"!==(t=e[i])){if("0"!==t&&"1"!==t)return!1;a=!0}return a&&"_"!==t}if("x"===t){for(i++;i<r;i++)if("_"!==(t=e[i])){if(!(48<=(n=e.charCodeAt(i))&&n<=57||65<=n&&n<=70||97<=n&&n<=102))return!1;a=!0}return a&&"_"!==t}if("o"===t){for(i++;i<r;i++)if("_"!==(t=e[i])){if(!st(e.charCodeAt(i)))return!1;a=!0}return a&&"_"!==t}}if("_"===t)return!1;for(;i<r;i++)if("_"!==(t=e[i])){if(!lt(e.charCodeAt(i)))return!1;a=!0}return!(!a||"_"===t)},construct:function(e){var t,n=e,r=1;if(-1!==n.indexOf("_")&&(n=n.replace(/_/g,"")),"-"!==(t=n[0])&&"+"!==t||("-"===t&&(r=-1),t=(n=n.slice(1))[0]),"0"===n)return 0;if("0"===t){if("b"===n[1])return r*parseInt(n.slice(2),2);if("x"===n[1])return r*parseInt(n.slice(2),16);if("o"===n[1])return r*parseInt(n.slice(2),8)}return r*parseInt(n,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&e%1==0&&!Pe.isNegativeZero(e)},represent:{binary:function(e){return e>=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),ct=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var dt=/^[-+]?[0-9]+e/;var pt=new He("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!ct.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n;return n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:n*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||Pe.isNegativeZero(e))},represent:function(e,t){var n;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(Pe.isNegativeZero(e))return"-0.0";return n=e.toString(10),dt.test(n)?n.replace("e",".e"):n},defaultStyle:"lowercase"}),ft=it.extend({implicit:[at,ot,ut,pt]}),ht=ft,gt=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),mt=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var vt=new He("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==gt.exec(e)||null!==mt.exec(e))},construct:function(e){var t,n,r,i,a,o,s,l,u=0,c=null;if(null===(t=gt.exec(e))&&(t=mt.exec(e)),null===t)throw new Error("Date resolve error");if(n=+t[1],r=+t[2]-1,i=+t[3],!t[4])return new Date(Date.UTC(n,r,i));if(a=+t[4],o=+t[5],s=+t[6],t[7]){for(u=t[7].slice(0,3);u.length<3;)u+="0";u=+u}return t[9]&&(c=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(c=-c)),l=new Date(Date.UTC(n,r,i,a,o,s,u)),c&&l.setTime(l.getTime()-c),l},instanceOf:Date,represent:function(e){return e.toISOString()}});var xt=new He("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),bt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var yt=new He("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,r=0,i=e.length,a=bt;for(n=0;n<i;n++)if(!((t=a.indexOf(e.charAt(n)))>64)){if(t<0)return!1;r+=6}return r%8==0},construct:function(e){var t,n,r=e.replace(/[\r\n=]/g,""),i=r.length,a=bt,o=0,s=[];for(t=0;t<i;t++)t%4==0&&t&&(s.push(o>>16&255),s.push(o>>8&255),s.push(255&o)),o=o<<6|a.indexOf(r.charAt(t));return 0===(n=i%4*6)?(s.push(o>>16&255),s.push(o>>8&255),s.push(255&o)):18===n?(s.push(o>>10&255),s.push(o>>2&255)):12===n&&s.push(o>>4&255),new Uint8Array(s)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,n,r="",i=0,a=e.length,o=bt;for(t=0;t<a;t++)t%3==0&&t&&(r+=o[i>>18&63],r+=o[i>>12&63],r+=o[i>>6&63],r+=o[63&i]),i=(i<<8)+e[t];return 0===(n=a%3)?(r+=o[i>>18&63],r+=o[i>>12&63],r+=o[i>>6&63],r+=o[63&i]):2===n?(r+=o[i>>10&63],r+=o[i>>4&63],r+=o[i<<2&63],r+=o[64]):1===n&&(r+=o[i>>2&63],r+=o[i<<4&63],r+=o[64],r+=o[64]),r}}),jt=Object.prototype.hasOwnProperty,wt=Object.prototype.toString;var Ct=new He("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,r,i,a,o=[],s=e;for(t=0,n=s.length;t<n;t+=1){if(r=s[t],a=!1,"[object Object]"!==wt.call(r))return!1;for(i in r)if(jt.call(r,i)){if(a)return!1;a=!0}if(!a)return!1;if(-1!==o.indexOf(i))return!1;o.push(i)}return!0},construct:function(e){return null!==e?e:[]}}),St=Object.prototype.toString;var At=new He("tag:yaml.org,2002:pairs",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,r,i,a,o=e;for(a=new Array(o.length),t=0,n=o.length;t<n;t+=1){if(r=o[t],"[object Object]"!==St.call(r))return!1;if(1!==(i=Object.keys(r)).length)return!1;a[t]=[i[0],r[i[0]]]}return!0},construct:function(e){if(null===e)return[];var t,n,r,i,a,o=e;for(a=new Array(o.length),t=0,n=o.length;t<n;t+=1)r=o[t],i=Object.keys(r),a[t]=[i[0],r[i[0]]];return a}}),kt=Object.prototype.hasOwnProperty;var It=new He("tag:yaml.org,2002:set",{kind:"mapping",resolve:function(e){if(null===e)return!0;var t,n=e;for(t in n)if(kt.call(n,t)&&null!==n[t])return!1;return!0},construct:function(e){return null!==e?e:{}}}),Ot=ht.extend({implicit:[vt,xt],explicit:[yt,Ct,At,It]}),Nt=Object.prototype.hasOwnProperty,Rt=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/,Tt=/[\x85\u2028\u2029]/,$t=/[,\[\]\{\}]/,Ft=/^(?:!|!!|![a-z\-]+!)$/i,qt=/^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;function Et(e){return Object.prototype.toString.call(e)}function Lt(e){return 10===e||13===e}function Dt(e){return 9===e||32===e}function Mt(e){return 9===e||32===e||10===e||13===e}function Qt(e){return 44===e||91===e||93===e||123===e||125===e}function Bt(e){var t;return 48<=e&&e<=57?e-48:97<=(t=32|e)&&t<=102?t-97+10:-1}function _t(e){return 48===e?"\0":97===e?"":98===e?"\b":116===e||9===e?"\t":110===e?"\n":118===e?"\v":102===e?"\f":114===e?"\r":101===e?"":32===e?" ":34===e?'"':47===e?"/":92===e?"\\":78===e?"…":95===e?" ":76===e?"\u2028":80===e?"\u2029":""}function Pt(e){return e<=65535?String.fromCharCode(e):String.fromCharCode(55296+(e-65536>>10),56320+(e-65536&1023))}for(var Ut=new Array(256),Vt=new Array(256),Gt=0;Gt<256;Gt++)Ut[Gt]=_t(Gt)?1:0,Vt[Gt]=_t(Gt);function Yt(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||Ot,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function Wt(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=Ze(n),new Ge(t,n)}function Zt(e,t){throw Wt(e,t)}function zt(e,t){e.onWarning&&e.onWarning.call(null,Wt(e,t))}var Kt={YAML:function(e,t,n){var r,i,a;null!==e.version&&Zt(e,"duplication of %YAML directive"),1!==n.length&&Zt(e,"YAML directive accepts exactly one argument"),null===(r=/^([0-9]+)\.([0-9]+)$/.exec(n[0]))&&Zt(e,"ill-formed argument of the YAML directive"),i=parseInt(r[1],10),a=parseInt(r[2],10),1!==i&&Zt(e,"unacceptable YAML version of the document"),e.version=n[0],e.checkLineBreaks=a<2,1!==a&&2!==a&&zt(e,"unsupported YAML version of the document")},TAG:function(e,t,n){var r,i;2!==n.length&&Zt(e,"TAG directive accepts exactly two arguments"),r=n[0],i=n[1],Ft.test(r)||Zt(e,"ill-formed tag handle (first argument) of the TAG directive"),Nt.call(e.tagMap,r)&&Zt(e,'there is a previously declared suffix for "'+r+'" tag handle'),qt.test(i)||Zt(e,"ill-formed tag prefix (second argument) of the TAG directive");try{i=decodeURIComponent(i)}catch(t){Zt(e,"tag prefix is malformed: "+i)}e.tagMap[r]=i}};function Ht(e,t,n,r){var i,a,o,s;if(t<n){if(s=e.input.slice(t,n),r)for(i=0,a=s.length;i<a;i+=1)9===(o=s.charCodeAt(i))||32<=o&&o<=1114111||Zt(e,"expected valid JSON character");else Rt.test(s)&&Zt(e,"the stream contains non-printable characters");e.result+=s}}function Jt(e,t,n,r){var i,a,o,s;for(Pe.isObject(n)||Zt(e,"cannot merge mappings; the provided source object is unacceptable"),o=0,s=(i=Object.keys(n)).length;o<s;o+=1)a=i[o],Nt.call(t,a)||(t[a]=n[a],r[a]=!0)}function Xt(e,t,n,r,i,a,o,s,l){var u,c;if(Array.isArray(i))for(u=0,c=(i=Array.prototype.slice.call(i)).length;u<c;u+=1)Array.isArray(i[u])&&Zt(e,"nested arrays are not supported inside keys"),"object"==typeof i&&"[object Object]"===Et(i[u])&&(i[u]="[object Object]");if("object"==typeof i&&"[object Object]"===Et(i)&&(i="[object Object]"),i=String(i),null===t&&(t={}),"tag:yaml.org,2002:merge"===r)if(Array.isArray(a))for(u=0,c=a.length;u<c;u+=1)Jt(e,t,a[u],n);else Jt(e,t,a,n);else e.json||Nt.call(n,i)||!Nt.call(t,i)||(e.line=o||e.line,e.lineStart=s||e.lineStart,e.position=l||e.position,Zt(e,"duplicated mapping key")),"__proto__"===i?Object.defineProperty(t,i,{configurable:!0,enumerable:!0,writable:!0,value:a}):t[i]=a,delete n[i];return t}function en(e){var t;10===(t=e.input.charCodeAt(e.position))?e.position++:13===t?(e.position++,10===e.input.charCodeAt(e.position)&&e.position++):Zt(e,"a line break is expected"),e.line+=1,e.lineStart=e.position,e.firstTabInLine=-1}function tn(e,t,n){for(var r=0,i=e.input.charCodeAt(e.position);0!==i;){for(;Dt(i);)9===i&&-1===e.firstTabInLine&&(e.firstTabInLine=e.position),i=e.input.charCodeAt(++e.position);if(t&&35===i)do{i=e.input.charCodeAt(++e.position)}while(10!==i&&13!==i&&0!==i);if(!Lt(i))break;for(en(e),i=e.input.charCodeAt(e.position),r++,e.lineIndent=0;32===i;)e.lineIndent++,i=e.input.charCodeAt(++e.position)}return-1!==n&&0!==r&&e.lineIndent<n&&zt(e,"deficient indentation"),r}function nn(e){var t,n=e.position;return!(45!==(t=e.input.charCodeAt(n))&&46!==t||t!==e.input.charCodeAt(n+1)||t!==e.input.charCodeAt(n+2)||(n+=3,0!==(t=e.input.charCodeAt(n))&&!Mt(t)))}function rn(e,t){1===t?e.result+=" ":t>1&&(e.result+=Pe.repeat("\n",t-1))}function an(e,t){var n,r,i=e.tag,a=e.anchor,o=[],s=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=o),r=e.input.charCodeAt(e.position);0!==r&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,Zt(e,"tab characters must not be used in indentation")),45===r)&&Mt(e.input.charCodeAt(e.position+1));)if(s=!0,e.position++,tn(e,!0,-1)&&e.lineIndent<=t)o.push(null),r=e.input.charCodeAt(e.position);else if(n=e.line,ln(e,t,3,!1,!0),o.push(e.result),tn(e,!0,-1),r=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==r)Zt(e,"bad indentation of a sequence entry");else if(e.lineIndent<t)break;return!!s&&(e.tag=i,e.anchor=a,e.kind="sequence",e.result=o,!0)}function on(e){var t,n,r,i,a=!1,o=!1;if(33!==(i=e.input.charCodeAt(e.position)))return!1;if(null!==e.tag&&Zt(e,"duplication of a tag property"),60===(i=e.input.charCodeAt(++e.position))?(a=!0,i=e.input.charCodeAt(++e.position)):33===i?(o=!0,n="!!",i=e.input.charCodeAt(++e.position)):n="!",t=e.position,a){do{i=e.input.charCodeAt(++e.position)}while(0!==i&&62!==i);e.position<e.length?(r=e.input.slice(t,e.position),i=e.input.charCodeAt(++e.position)):Zt(e,"unexpected end of the stream within a verbatim tag")}else{for(;0!==i&&!Mt(i);)33===i&&(o?Zt(e,"tag suffix cannot contain exclamation marks"):(n=e.input.slice(t-1,e.position+1),Ft.test(n)||Zt(e,"named tag handle cannot contain such characters"),o=!0,t=e.position+1)),i=e.input.charCodeAt(++e.position);r=e.input.slice(t,e.position),$t.test(r)&&Zt(e,"tag suffix cannot contain flow indicator characters")}r&&!qt.test(r)&&Zt(e,"tag name cannot contain such characters: "+r);try{r=decodeURIComponent(r)}catch(t){Zt(e,"tag name is malformed: "+r)}return a?e.tag=r:Nt.call(e.tagMap,n)?e.tag=e.tagMap[n]+r:"!"===n?e.tag="!"+r:"!!"===n?e.tag="tag:yaml.org,2002:"+r:Zt(e,'undeclared tag handle "'+n+'"'),!0}function sn(e){var t,n;if(38!==(n=e.input.charCodeAt(e.position)))return!1;for(null!==e.anchor&&Zt(e,"duplication of an anchor property"),n=e.input.charCodeAt(++e.position),t=e.position;0!==n&&!Mt(n)&&!Qt(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&Zt(e,"name of an anchor node must contain at least one character"),e.anchor=e.input.slice(t,e.position),!0}function ln(e,t,n,r,i){var a,o,s,l,u,c,d,p,f,h=1,g=!1,m=!1;if(null!==e.listener&&e.listener("open",e),e.tag=null,e.anchor=null,e.kind=null,e.result=null,a=o=s=4===n||3===n,r&&tn(e,!0,-1)&&(g=!0,e.lineIndent>t?h=1:e.lineIndent===t?h=0:e.lineIndent<t&&(h=-1)),1===h)for(;on(e)||sn(e);)tn(e,!0,-1)?(g=!0,s=a,e.lineIndent>t?h=1:e.lineIndent===t?h=0:e.lineIndent<t&&(h=-1)):s=!1;if(s&&(s=g||i),1!==h&&4!==n||(p=1===n||2===n?t:t+1,f=e.position-e.lineStart,1===h?s&&(an(e,f)||function(e,t,n){var r,i,a,o,s,l,u,c=e.tag,d=e.anchor,p={},f=Object.create(null),h=null,g=null,m=null,v=!1,x=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=p),u=e.input.charCodeAt(e.position);0!==u;){if(v||-1===e.firstTabInLine||(e.position=e.firstTabInLine,Zt(e,"tab characters must not be used in indentation")),r=e.input.charCodeAt(e.position+1),a=e.line,63!==u&&58!==u||!Mt(r)){if(o=e.line,s=e.lineStart,l=e.position,!ln(e,n,2,!1,!0))break;if(e.line===a){for(u=e.input.charCodeAt(e.position);Dt(u);)u=e.input.charCodeAt(++e.position);if(58===u)Mt(u=e.input.charCodeAt(++e.position))||Zt(e,"a whitespace character is expected after the key-value separator within a block mapping"),v&&(Xt(e,p,f,h,g,null,o,s,l),h=g=m=null),x=!0,v=!1,i=!1,h=e.tag,g=e.result;else{if(!x)return e.tag=c,e.anchor=d,!0;Zt(e,"can not read an implicit mapping pair; a colon is missed")}}else{if(!x)return e.tag=c,e.anchor=d,!0;Zt(e,"can not read a block mapping entry; a multiline key may not be an implicit key")}}else 63===u?(v&&(Xt(e,p,f,h,g,null,o,s,l),h=g=m=null),x=!0,v=!0,i=!0):v?(v=!1,i=!0):Zt(e,"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line"),e.position+=1,u=r;if((e.line===a||e.lineIndent>t)&&(v&&(o=e.line,s=e.lineStart,l=e.position),ln(e,t,4,!0,i)&&(v?g=e.result:m=e.result),v||(Xt(e,p,f,h,g,m,o,s,l),h=g=m=null),tn(e,!0,-1),u=e.input.charCodeAt(e.position)),(e.line===a||e.lineIndent>t)&&0!==u)Zt(e,"bad indentation of a mapping entry");else if(e.lineIndent<t)break}return v&&Xt(e,p,f,h,g,null,o,s,l),x&&(e.tag=c,e.anchor=d,e.kind="mapping",e.result=p),x}(e,f,p))||function(e,t){var n,r,i,a,o,s,l,u,c,d,p,f,h=!0,g=e.tag,m=e.anchor,v=Object.create(null);if(91===(f=e.input.charCodeAt(e.position)))o=93,u=!1,a=[];else{if(123!==f)return!1;o=125,u=!0,a={}}for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),f=e.input.charCodeAt(++e.position);0!==f;){if(tn(e,!0,t),(f=e.input.charCodeAt(e.position))===o)return e.position++,e.tag=g,e.anchor=m,e.kind=u?"mapping":"sequence",e.result=a,!0;h?44===f&&Zt(e,"expected the node content, but found ','"):Zt(e,"missed comma between flow collection entries"),p=null,s=l=!1,63===f&&Mt(e.input.charCodeAt(e.position+1))&&(s=l=!0,e.position++,tn(e,!0,t)),n=e.line,r=e.lineStart,i=e.position,ln(e,t,1,!1,!0),d=e.tag,c=e.result,tn(e,!0,t),f=e.input.charCodeAt(e.position),!l&&e.line!==n||58!==f||(s=!0,f=e.input.charCodeAt(++e.position),tn(e,!0,t),ln(e,t,1,!1,!0),p=e.result),u?Xt(e,a,v,d,c,p,n,r,i):s?a.push(Xt(e,null,v,d,c,p,n,r,i)):a.push(c),tn(e,!0,t),44===(f=e.input.charCodeAt(e.position))?(h=!0,f=e.input.charCodeAt(++e.position)):h=!1}Zt(e,"unexpected end of the stream within a flow collection")}(e,p)?m=!0:(o&&function(e,t){var n,r,i,a,o,s=1,l=!1,u=!1,c=t,d=0,p=!1;if(124===(a=e.input.charCodeAt(e.position)))r=!1;else{if(62!==a)return!1;r=!0}for(e.kind="scalar",e.result="";0!==a;)if(43===(a=e.input.charCodeAt(++e.position))||45===a)1===s?s=43===a?3:2:Zt(e,"repeat of a chomping mode identifier");else{if(!((i=48<=(o=a)&&o<=57?o-48:-1)>=0))break;0===i?Zt(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):u?Zt(e,"repeat of an indentation width identifier"):(c=t+i-1,u=!0)}if(Dt(a)){do{a=e.input.charCodeAt(++e.position)}while(Dt(a));if(35===a)do{a=e.input.charCodeAt(++e.position)}while(!Lt(a)&&0!==a)}for(;0!==a;){for(en(e),e.lineIndent=0,a=e.input.charCodeAt(e.position);(!u||e.lineIndent<c)&&32===a;)e.lineIndent++,a=e.input.charCodeAt(++e.position);if(!u&&e.lineIndent>c&&(c=e.lineIndent),Lt(a))d++;else{if(e.lineIndent<c){3===s?e.result+=Pe.repeat("\n",l?1+d:d):1===s&&l&&(e.result+="\n");break}for(r?Dt(a)?(p=!0,e.result+=Pe.repeat("\n",l?1+d:d)):p?(p=!1,e.result+=Pe.repeat("\n",d+1)):0===d?l&&(e.result+=" "):e.result+=Pe.repeat("\n",d):e.result+=Pe.repeat("\n",l?1+d:d),l=!0,u=!0,d=0,n=e.position;!Lt(a)&&0!==a;)a=e.input.charCodeAt(++e.position);Ht(e,n,e.position,!1)}}return!0}(e,p)||function(e,t){var n,r,i;if(39!==(n=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,r=i=e.position;0!==(n=e.input.charCodeAt(e.position));)if(39===n){if(Ht(e,r,e.position,!0),39!==(n=e.input.charCodeAt(++e.position)))return!0;r=e.position,e.position++,i=e.position}else Lt(n)?(Ht(e,r,i,!0),rn(e,tn(e,!1,t)),r=i=e.position):e.position===e.lineStart&&nn(e)?Zt(e,"unexpected end of the document within a single quoted scalar"):(e.position++,i=e.position);Zt(e,"unexpected end of the stream within a single quoted scalar")}(e,p)||function(e,t){var n,r,i,a,o,s,l;if(34!==(s=e.input.charCodeAt(e.position)))return!1;for(e.kind="scalar",e.result="",e.position++,n=r=e.position;0!==(s=e.input.charCodeAt(e.position));){if(34===s)return Ht(e,n,e.position,!0),e.position++,!0;if(92===s){if(Ht(e,n,e.position,!0),Lt(s=e.input.charCodeAt(++e.position)))tn(e,!1,t);else if(s<256&&Ut[s])e.result+=Vt[s],e.position++;else if((o=120===(l=s)?2:117===l?4:85===l?8:0)>0){for(i=o,a=0;i>0;i--)(o=Bt(s=e.input.charCodeAt(++e.position)))>=0?a=(a<<4)+o:Zt(e,"expected hexadecimal character");e.result+=Pt(a),e.position++}else Zt(e,"unknown escape sequence");n=r=e.position}else Lt(s)?(Ht(e,n,r,!0),rn(e,tn(e,!1,t)),n=r=e.position):e.position===e.lineStart&&nn(e)?Zt(e,"unexpected end of the document within a double quoted scalar"):(e.position++,r=e.position)}Zt(e,"unexpected end of the stream within a double quoted scalar")}(e,p)?m=!0:!function(e){var t,n,r;if(42!==(r=e.input.charCodeAt(e.position)))return!1;for(r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!Mt(r)&&!Qt(r);)r=e.input.charCodeAt(++e.position);return e.position===t&&Zt(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),Nt.call(e.anchorMap,n)||Zt(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],tn(e,!0,-1),!0}(e)?function(e,t,n){var r,i,a,o,s,l,u,c,d=e.kind,p=e.result;if(Mt(c=e.input.charCodeAt(e.position))||Qt(c)||35===c||38===c||42===c||33===c||124===c||62===c||39===c||34===c||37===c||64===c||96===c)return!1;if((63===c||45===c)&&(Mt(r=e.input.charCodeAt(e.position+1))||n&&Qt(r)))return!1;for(e.kind="scalar",e.result="",i=a=e.position,o=!1;0!==c;){if(58===c){if(Mt(r=e.input.charCodeAt(e.position+1))||n&&Qt(r))break}else if(35===c){if(Mt(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&nn(e)||n&&Qt(c))break;if(Lt(c)){if(s=e.line,l=e.lineStart,u=e.lineIndent,tn(e,!1,-1),e.lineIndent>=t){o=!0,c=e.input.charCodeAt(e.position);continue}e.position=a,e.line=s,e.lineStart=l,e.lineIndent=u;break}}o&&(Ht(e,i,a,!1),rn(e,e.line-s),i=a=e.position,o=!1),Dt(c)||(a=e.position+1),c=e.input.charCodeAt(++e.position)}return Ht(e,i,a,!1),!!e.result||(e.kind=d,e.result=p,!1)}(e,p,1===n)&&(m=!0,null===e.tag&&(e.tag="?")):(m=!0,null===e.tag&&null===e.anchor||Zt(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===h&&(m=s&&an(e,f))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&Zt(e,'unacceptable node kind for !<?> tag; it should be "scalar", not "'+e.kind+'"'),l=0,u=e.implicitTypes.length;l<u;l+=1)if((d=e.implicitTypes[l]).resolve(e.result)){e.result=d.construct(e.result),e.tag=d.tag,null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);break}}else if("!"!==e.tag){if(Nt.call(e.typeMap[e.kind||"fallback"],e.tag))d=e.typeMap[e.kind||"fallback"][e.tag];else for(d=null,l=0,u=(c=e.typeMap.multi[e.kind||"fallback"]).length;l<u;l+=1)if(e.tag.slice(0,c[l].tag.length)===c[l].tag){d=c[l];break}d||Zt(e,"unknown tag !<"+e.tag+">"),null!==e.result&&d.kind!==e.kind&&Zt(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+d.kind+'", not "'+e.kind+'"'),d.resolve(e.result,e.tag)?(e.result=d.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):Zt(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||m}function un(e){var t,n,r,i,a=e.position,o=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(i=e.input.charCodeAt(e.position))&&(tn(e,!0,-1),i=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==i));){for(o=!0,i=e.input.charCodeAt(++e.position),t=e.position;0!==i&&!Mt(i);)i=e.input.charCodeAt(++e.position);for(r=[],(n=e.input.slice(t,e.position)).length<1&&Zt(e,"directive name must not be less than one character in length");0!==i;){for(;Dt(i);)i=e.input.charCodeAt(++e.position);if(35===i){do{i=e.input.charCodeAt(++e.position)}while(0!==i&&!Lt(i));break}if(Lt(i))break;for(t=e.position;0!==i&&!Mt(i);)i=e.input.charCodeAt(++e.position);r.push(e.input.slice(t,e.position))}0!==i&&en(e),Nt.call(Kt,n)?Kt[n](e,n,r):zt(e,'unknown document directive "'+n+'"')}tn(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,tn(e,!0,-1)):o&&Zt(e,"directives end mark is expected"),ln(e,e.lineIndent-1,4,!1,!0),tn(e,!0,-1),e.checkLineBreaks&&Tt.test(e.input.slice(a,e.position))&&zt(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&nn(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,tn(e,!0,-1)):e.position<e.length-1&&Zt(e,"end of the stream or a document separator is expected")}function cn(e,t){t=t||{},0!==(e=String(e)).length&&(10!==e.charCodeAt(e.length-1)&&13!==e.charCodeAt(e.length-1)&&(e+="\n"),65279===e.charCodeAt(0)&&(e=e.slice(1)));var n=new Yt(e,t),r=e.indexOf("\0");for(-1!==r&&(n.position=r,Zt(n,"null byte is not allowed in input")),n.input+="\0";32===n.input.charCodeAt(n.position);)n.lineIndent+=1,n.position+=1;for(;n.position<n.length-1;)un(n);return n.documents}var dn=function(e,t,n){null!==t&&"object"==typeof t&&void 0===n&&(n=t,t=null);var r=cn(e,n);if("function"!=typeof t)return r;for(var i=0,a=r.length;i<a;i+=1)t(r[i])},pn=function(e,t){var n=cn(e,t);if(0!==n.length){if(1===n.length)return n[0];throw new Ge("expected a single document in the stream, but found more")}},fn={loadAll:dn,load:pn},hn=Object.prototype.toString,gn=Object.prototype.hasOwnProperty,mn=65279,vn={0:"\\0",7:"\\a",8:"\\b",9:"\\t",10:"\\n",11:"\\v",12:"\\f",13:"\\r",27:"\\e",34:'\\"',92:"\\\\",133:"\\N",160:"\\_",8232:"\\L",8233:"\\P"},xn=["y","Y","yes","Yes","YES","on","On","ON","n","N","no","No","NO","off","Off","OFF"],bn=/^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;function yn(e){var t,n,r;if(t=e.toString(16).toUpperCase(),e<=255)n="x",r=2;else if(e<=65535)n="u",r=4;else{if(!(e<=4294967295))throw new Ge("code point within a string may not be greater than 0xFFFFFFFF");n="U",r=8}return"\\"+n+Pe.repeat("0",r-t.length)+t}function jn(e){this.schema=e.schema||Ot,this.indent=Math.max(1,e.indent||2),this.noArrayIndent=e.noArrayIndent||!1,this.skipInvalid=e.skipInvalid||!1,this.flowLevel=Pe.isNothing(e.flowLevel)?-1:e.flowLevel,this.styleMap=function(e,t){var n,r,i,a,o,s,l;if(null===t)return{};for(n={},i=0,a=(r=Object.keys(t)).length;i<a;i+=1)o=r[i],s=String(t[o]),"!!"===o.slice(0,2)&&(o="tag:yaml.org,2002:"+o.slice(2)),(l=e.compiledTypeMap.fallback[o])&&gn.call(l.styleAliases,s)&&(s=l.styleAliases[s]),n[o]=s;return n}(this.schema,e.styles||null),this.sortKeys=e.sortKeys||!1,this.lineWidth=e.lineWidth||80,this.noRefs=e.noRefs||!1,this.noCompatMode=e.noCompatMode||!1,this.condenseFlow=e.condenseFlow||!1,this.quotingType='"'===e.quotingType?2:1,this.forceQuotes=e.forceQuotes||!1,this.replacer="function"==typeof e.replacer?e.replacer:null,this.implicitTypes=this.schema.compiledImplicit,this.explicitTypes=this.schema.compiledExplicit,this.tag=null,this.result="",this.duplicates=[],this.usedDuplicates=null}function wn(e,t){for(var n,r=Pe.repeat(" ",t),i=0,a=-1,o="",s=e.length;i<s;)-1===(a=e.indexOf("\n",i))?(n=e.slice(i),i=s):(n=e.slice(i,a+1),i=a+1),n.length&&"\n"!==n&&(o+=r),o+=n;return o}function Cn(e,t){return"\n"+Pe.repeat(" ",e.indent*t)}function Sn(e){return 32===e||9===e}function An(e){return 32<=e&&e<=126||161<=e&&e<=55295&&8232!==e&&8233!==e||57344<=e&&e<=65533&&e!==mn||65536<=e&&e<=1114111}function kn(e){return An(e)&&e!==mn&&13!==e&&10!==e}function In(e,t,n){var r=kn(e),i=r&&!Sn(e);return(n?r:r&&44!==e&&91!==e&&93!==e&&123!==e&&125!==e)&&35!==e&&!(58===t&&!i)||kn(t)&&!Sn(t)&&35===e||58===t&&i}function On(e,t){var n,r=e.charCodeAt(t);return r>=55296&&r<=56319&&t+1<e.length&&(n=e.charCodeAt(t+1))>=56320&&n<=57343?1024*(r-55296)+n-56320+65536:r}function Nn(e){return/^\n* /.test(e)}function Rn(e,t,n,r,i,a,o,s){var l,u,c=0,d=null,p=!1,f=!1,h=-1!==r,g=-1,m=An(u=On(e,0))&&u!==mn&&!Sn(u)&&45!==u&&63!==u&&58!==u&&44!==u&&91!==u&&93!==u&&123!==u&&125!==u&&35!==u&&38!==u&&42!==u&&33!==u&&124!==u&&61!==u&&62!==u&&39!==u&&34!==u&&37!==u&&64!==u&&96!==u&&function(e){return!Sn(e)&&58!==e}(On(e,e.length-1));if(t||o)for(l=0;l<e.length;c>=65536?l+=2:l++){if(!An(c=On(e,l)))return 5;m=m&&In(c,d,s),d=c}else{for(l=0;l<e.length;c>=65536?l+=2:l++){if(10===(c=On(e,l)))p=!0,h&&(f=f||l-g-1>r&&" "!==e[g+1],g=l);else if(!An(c))return 5;m=m&&In(c,d,s),d=c}f=f||h&&l-g-1>r&&" "!==e[g+1]}return p||f?n>9&&Nn(e)?5:o?2===a?5:2:f?4:3:!m||o||i(e)?2===a?5:2:1}function Tn(e,t,n,r,i){e.dump=function(){if(0===t.length)return 2===e.quotingType?'""':"''";if(!e.noCompatMode&&(-1!==xn.indexOf(t)||bn.test(t)))return 2===e.quotingType?'"'+t+'"':"'"+t+"'";var a=e.indent*Math.max(1,n),o=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-a),s=r||e.flowLevel>-1&&n>=e.flowLevel;switch(Rn(t,s,e.indent,o,(function(t){return function(e,t){var n,r;for(n=0,r=e.implicitTypes.length;n<r;n+=1)if(e.implicitTypes[n].resolve(t))return!0;return!1}(e,t)}),e.quotingType,e.forceQuotes&&!r,i)){case 1:return t;case 2:return"'"+t.replace(/'/g,"''")+"'";case 3:return"|"+$n(t,e.indent)+Fn(wn(t,a));case 4:return">"+$n(t,e.indent)+Fn(wn(function(e,t){var n,r,i=/(\n+)([^\n]*)/g,a=(s=e.indexOf("\n"),s=-1!==s?s:e.length,i.lastIndex=s,qn(e.slice(0,s),t)),o="\n"===e[0]||" "===e[0];var s;for(;r=i.exec(e);){var l=r[1],u=r[2];n=" "===u[0],a+=l+(o||n||""===u?"":"\n")+qn(u,t),o=n}return a}(t,o),a));case 5:return'"'+function(e){for(var t,n="",r=0,i=0;i<e.length;r>=65536?i+=2:i++)r=On(e,i),!(t=vn[r])&&An(r)?(n+=e[i],r>=65536&&(n+=e[i+1])):n+=t||yn(r);return n}(t)+'"';default:throw new Ge("impossible error: invalid scalar style")}}()}function $n(e,t){var n=Nn(e)?String(t):"",r="\n"===e[e.length-1];return n+(r&&("\n"===e[e.length-2]||"\n"===e)?"+":r?"":"-")+"\n"}function Fn(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function qn(e,t){if(""===e||" "===e[0])return e;for(var n,r,i=/ [^ ]/g,a=0,o=0,s=0,l="";n=i.exec(e);)(s=n.index)-a>t&&(r=o>a?o:s,l+="\n"+e.slice(a,r),a=r+1),o=s;return l+="\n",e.length-a>t&&o>a?l+=e.slice(a,o)+"\n"+e.slice(o+1):l+=e.slice(a),l.slice(1)}function En(e,t,n,r){var i,a,o,s="",l=e.tag;for(i=0,a=n.length;i<a;i+=1)o=n[i],e.replacer&&(o=e.replacer.call(n,String(i),o)),(Dn(e,t+1,o,!0,!0,!1,!0)||void 0===o&&Dn(e,t+1,null,!0,!0,!1,!0))&&(r&&""===s||(s+=Cn(e,t)),e.dump&&10===e.dump.charCodeAt(0)?s+="-":s+="- ",s+=e.dump);e.tag=l,e.dump=s||"[]"}function Ln(e,t,n){var r,i,a,o,s,l;for(a=0,o=(i=n?e.explicitTypes:e.implicitTypes).length;a<o;a+=1)if(((s=i[a]).instanceOf||s.predicate)&&(!s.instanceOf||"object"==typeof t&&t instanceof s.instanceOf)&&(!s.predicate||s.predicate(t))){if(n?s.multi&&s.representName?e.tag=s.representName(t):e.tag=s.tag:e.tag="?",s.represent){if(l=e.styleMap[s.tag]||s.defaultStyle,"[object Function]"===hn.call(s.represent))r=s.represent(t,l);else{if(!gn.call(s.represent,l))throw new Ge("!<"+s.tag+'> tag resolver accepts not "'+l+'" style');r=s.represent[l](t,l)}e.dump=r}return!0}return!1}function Dn(e,t,n,r,i,a,o){e.tag=null,e.dump=n,Ln(e,n,!1)||Ln(e,n,!0);var s,l=hn.call(e.dump),u=r;r&&(r=e.flowLevel<0||e.flowLevel>t);var c,d,p="[object Object]"===l||"[object Array]"===l;if(p&&(d=-1!==(c=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||d||2!==e.indent&&t>0)&&(i=!1),d&&e.usedDuplicates[c])e.dump="*ref_"+c;else{if(p&&d&&!e.usedDuplicates[c]&&(e.usedDuplicates[c]=!0),"[object Object]"===l)r&&0!==Object.keys(e.dump).length?(!function(e,t,n,r){var i,a,o,s,l,u,c="",d=e.tag,p=Object.keys(n);if(!0===e.sortKeys)p.sort();else if("function"==typeof e.sortKeys)p.sort(e.sortKeys);else if(e.sortKeys)throw new Ge("sortKeys must be a boolean or a function");for(i=0,a=p.length;i<a;i+=1)u="",r&&""===c||(u+=Cn(e,t)),s=n[o=p[i]],e.replacer&&(s=e.replacer.call(n,o,s)),Dn(e,t+1,o,!0,!0,!0)&&((l=null!==e.tag&&"?"!==e.tag||e.dump&&e.dump.length>1024)&&(e.dump&&10===e.dump.charCodeAt(0)?u+="?":u+="? "),u+=e.dump,l&&(u+=Cn(e,t)),Dn(e,t+1,s,!0,l)&&(e.dump&&10===e.dump.charCodeAt(0)?u+=":":u+=": ",c+=u+=e.dump));e.tag=d,e.dump=c||"{}"}(e,t,e.dump,i),d&&(e.dump="&ref_"+c+e.dump)):(!function(e,t,n){var r,i,a,o,s,l="",u=e.tag,c=Object.keys(n);for(r=0,i=c.length;r<i;r+=1)s="",""!==l&&(s+=", "),e.condenseFlow&&(s+='"'),o=n[a=c[r]],e.replacer&&(o=e.replacer.call(n,a,o)),Dn(e,t,a,!1,!1)&&(e.dump.length>1024&&(s+="? "),s+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),Dn(e,t,o,!1,!1)&&(l+=s+=e.dump));e.tag=u,e.dump="{"+l+"}"}(e,t,e.dump),d&&(e.dump="&ref_"+c+" "+e.dump));else if("[object Array]"===l)r&&0!==e.dump.length?(e.noArrayIndent&&!o&&t>0?En(e,t-1,e.dump,i):En(e,t,e.dump,i),d&&(e.dump="&ref_"+c+e.dump)):(!function(e,t,n){var r,i,a,o="",s=e.tag;for(r=0,i=n.length;r<i;r+=1)a=n[r],e.replacer&&(a=e.replacer.call(n,String(r),a)),(Dn(e,t,a,!1,!1)||void 0===a&&Dn(e,t,null,!1,!1))&&(""!==o&&(o+=","+(e.condenseFlow?"":" ")),o+=e.dump);e.tag=s,e.dump="["+o+"]"}(e,t,e.dump),d&&(e.dump="&ref_"+c+" "+e.dump));else{if("[object String]"!==l){if("[object Undefined]"===l)return!1;if(e.skipInvalid)return!1;throw new Ge("unacceptable kind of an object to dump "+l)}"?"!==e.tag&&Tn(e,e.dump,t,a,u)}null!==e.tag&&"?"!==e.tag&&(s=encodeURI("!"===e.tag[0]?e.tag.slice(1):e.tag).replace(/!/g,"%21"),s="!"===e.tag[0]?"!"+s:"tag:yaml.org,2002:"===s.slice(0,18)?"!!"+s.slice(18):"!<"+s+">",e.dump=s+" "+e.dump)}return!0}function Mn(e,t){var n,r,i=[],a=[];for(Qn(e,i,a),n=0,r=a.length;n<r;n+=1)t.duplicates.push(i[a[n]]);t.usedDuplicates=new Array(r)}function Qn(e,t,n){var r,i,a;if(null!==e&&"object"==typeof e)if(-1!==(i=t.indexOf(e)))-1===n.indexOf(i)&&n.push(i);else if(t.push(e),Array.isArray(e))for(i=0,a=e.length;i<a;i+=1)Qn(e[i],t,n);else for(i=0,a=(r=Object.keys(e)).length;i<a;i+=1)Qn(e[r[i]],t,n)}var Bn=function(e,t){var n=new jn(t=t||{});n.noRefs||Mn(e,n);var r=e;return n.replacer&&(r=n.replacer.call({"":r},"",r)),Dn(n,0,r,!0,!0)?n.dump+"\n":""};function _n(e,t){return function(){throw new Error("Function yaml."+e+" is removed in js-yaml 4. Use yaml."+t+" instead, which is now safe by default.")}}var Pn=fn.load,Un={dump:Bn}.dump;_n("safeLoad","load"),_n("safeLoadAll","loadAll"),_n("safeDump","dump");const Vn=[{label:"Yaml",value:"yaml"}],Gn=e=>{let{onClose:t}=e;const[n,r]=(0,i.useState)("yaml"),{setValue:a}=(0,c.Gc)(),o=(0,s.useStyles2)(zn);return(0,E.jsx)(s.Drawer,{title:"Inspect Alert rule",subtitle:(0,E.jsx)("div",{className:o.subtitle,children:(0,E.jsx)(Yn,{setActiveTab:r,activeTab:n})}),onClose:t,children:"yaml"===n&&(0,E.jsx)(Wn,{onSubmit:e=>{for(const t in e)a(t,e[t]);t()}})})},Yn=e=>{let{activeTab:t,setActiveTab:n}=e;return(0,E.jsx)(s.TabsBar,{children:Vn.map(((e,r)=>(0,E.jsx)(s.Tab,{label:e.label,value:e.value,onChangeTab:()=>n(e.value),active:t===e.value},`${e.value}-${r}`)))})},Wn=e=>{let{onSubmit:t}=e;const n=(0,s.useStyles2)(Zn),{getValues:r}=(0,c.Gc)(),[a,o]=(0,i.useState)(Un(r()));return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)("div",{className:n.applyButton,children:(0,E.jsx)(s.Button,{type:"button",onClick:()=>{t(Pn(a))},children:"Apply"})}),(0,E.jsx)("div",{className:n.content,children:(0,E.jsx)(q.Z,{disableWidth:!0,children:e=>{let{height:t}=e;return(0,E.jsx)(s.CodeEditor,{width:"100%",height:t,language:"yaml",value:a,onBlur:o,monacoOptions:{minimap:{enabled:!1}}})}})})]})},Zn=e=>({content:r.css`
  93. flex-grow: 1;
  94. height: 100%;
  95. padding-bottom: 16px;
  96. margin-bottom: ${e.spacing(2)};
  97. `,applyButton:r.css`
  98. display: flex;
  99. flex-grow: 0;
  100. `}),zn=()=>({subtitle:r.css`
  101. display: flex;
  102. align-items: center;
  103. justify-content: space-between;
  104. `});var Kn=n(24036);const Hn=["onChange","ref"];var Jn,Xn;const er=e=>{var t,n;let{existing:r=!1}=e;const{watch:a,setValue:o,formState:{errors:l}}=(0,c.Gc)(),u=a("queries"),d=a("condition"),p=(0,i.useMemo)((()=>u.filter((e=>e.datasourceUid===Kn.Yq))),[u]),f=(0,i.useMemo)((()=>u.filter((e=>!!e.refId)).map((e=>({value:e.refId,label:`${e.refId} - ${p.includes(e)?"expression":"query"}`})))),[u,p]);(0,i.useEffect)((()=>{const e=(0,Se.last)(p);e&&!r&&o("condition",e.refId,{shouldValidate:!0})}),[p,o,r]),(0,i.useEffect)((()=>{const e=(0,Se.last)(p),t=f.find((e=>{let{value:t}=e;return t===d}));var n;d&&!t?o("condition",null!==(n=null==e?void 0:e.refId)&&void 0!==n?n:null):!d&&e&&o("condition",e.refId,{shouldValidate:!0})}),[d,p,f,o]);const h=(0,s.useStyles2)(tr);return f.length?(0,E.jsxs)(s.Card,{className:h.container,children:[Jn||(Jn=(0,E.jsx)(s.Card.Heading,{children:"Set alert condition"})),Xn||(Xn=(0,E.jsx)(s.Card.Meta,{children:"Select one of your queries or expressions set above that contains your alert condition."})),(0,E.jsx)(s.Card.Actions,{children:(0,E.jsx)(s.Field,{error:null===(t=l.condition)||void 0===t?void 0:t.message,invalid:!(null===(n=l.condition)||void 0===n||!n.message),children:(0,E.jsx)(s.InputControl,{name:"condition",render:e=>{let{field:{onChange:t}}=e,n=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e.field,Hn);return(0,E.jsx)(s.RadioButtonList,Object.assign({options:f,onChange:t},n))},rules:{required:{value:!0,message:"Please select the condition to alert on"}}})})})]}):(0,E.jsx)(s.Alert,{title:"No queries or expressions have been configured",severity:"warning",className:h.container,children:"Create at least one query or expression to be alerted on"})},tr=e=>({container:r.css`
  105. max-width: ${e.breakpoints.values.sm}px;
  106. `});var nr=n(19462);function rr(){const e=(0,h._)((e=>e.dataSources));return Object.values(e).map((e=>e.result)).filter((e=>Boolean(null==e?void 0:e.rulerConfig))).map((e=>(0,nr.c$)(e.name))).filter((e=>Boolean(e)))}const ir=["value"];function ar(e){let{value:t}=e,n=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,ir);const r=rr(),a=(0,i.useCallback)((e=>!!r.find((t=>{let{id:n}=t;return n===e.id}))),[r]);return(0,E.jsx)(O.DataSourcePicker,Object.assign({noDefault:!0,alerting:!0,filter:a,current:t},n))}const or=e=>{const{name:t,description:n,image:i,selected:a=!1,value:o,onClick:l,disabled:u=!1}=e,c=(0,s.useStyles2)(sr),d=(0,r.cx)({[c.wrapper]:!0,[c.disabled]:u});return(0,E.jsxs)(s.Card,{className:d,isSelected:a,onClick:()=>l(o),disabled:u,children:[(0,E.jsx)(s.Card.Figure,{children:(0,E.jsx)("img",{src:i})}),(0,E.jsx)(s.Card.Heading,{children:t}),(0,E.jsx)(s.Card.Description,{children:n})]})},sr=e=>({wrapper:r.css`
  107. width: 380px;
  108. cursor: pointer;
  109. user-select: none;
  110. `,disabled:r.css`
  111. opacity: 0.5;
  112. `});var lr;const ur=e=>{let{selected:t=!1,disabled:n,onClick:r}=e;return(0,E.jsx)(or,{name:"Grafana managed alert",description:lr||(lr=(0,E.jsxs)("span",{children:["Supports multiple data sources of any kind.",(0,E.jsx)("br",{}),"Transform data with expressions."]})),image:"public/img/grafana_icon.svg",selected:t,disabled:n,value:m.$.grafana,onClick:r})},cr=e=>{let{children:t,visible:n=!1}=e;return n?(0,E.jsx)(s.Tooltip,{content:"You do not appear to have any compatible datasources.",placement:"top",children:(0,E.jsx)("div",{children:t})}):(0,E.jsx)(E.Fragment,{children:t})};var dr;const pr=e=>{let{selected:t=!1,disabled:n=!1,onClick:r}=e;return(0,E.jsx)(cr,{visible:n,children:(0,E.jsx)(or,{name:"Mimir or Loki alert",description:dr||(dr=(0,E.jsxs)("span",{children:["Use a Mimir, Loki or Cortex datasource.",(0,E.jsx)("br",{}),"Expressions are not supported."]})),image:"public/img/alerting/mimir_logo.svg",selected:t,disabled:n,value:m.$.cloudAlerting,onClick:r})})};var fr;const hr=e=>{let{selected:t=!1,disabled:n=!1,onClick:r}=e;return(0,E.jsx)(cr,{visible:n,children:(0,E.jsx)(or,{name:"Mimir or Loki recording rule",description:fr||(fr=(0,E.jsxs)("span",{children:["Precompute expressions.",(0,E.jsx)("br",{}),"Should be combined with an alert rule."]})),image:"public/img/alerting/mimir_logo_recording.svg",selected:t,disabled:n,value:m.$.cloudRecording,onClick:r})})},gr=e=>{let{selected:t,onChange:n,enabledTypes:r}=e;const i=rr(),a=!(0,Se.isEmpty)(i),o=(0,s.useStyles2)(mr);return(0,E.jsxs)(E.Fragment,{children:[(0,E.jsxs)(z.Stack,{direction:"row",gap:2,children:[r.includes(m.$.grafana)&&(0,E.jsx)(ur,{selected:t===m.$.grafana,onClick:n}),r.includes(m.$.cloudAlerting)&&(0,E.jsx)(pr,{selected:t===m.$.cloudAlerting,onClick:n,disabled:!a}),r.includes(m.$.cloudRecording)&&(0,E.jsx)(hr,{selected:t===m.$.cloudRecording,onClick:n,disabled:!a})]}),r.includes(m.$.grafana)&&(0,E.jsx)("small",{className:o.meta,children:"Select “Grafana managed” unless you have a Mimir, Loki or Cortex data source with the Ruler API enabled."})]})},mr=e=>({meta:r.css`
  113. color: ${e.colors.text.disabled};
  114. `}),vr=["onChange","ref"];const xr=e=>{var t,n,r,i;let{editingExistingRule:a}=e;const{enabledRuleTypes:o,defaultRuleType:l}=function(){const e=K.Vt.hasAccess(H.bW.AlertingRuleCreate,K.Vt.hasEditPermissionInFolders),t=K.Vt.hasAccess(H.bW.AlertingRuleExternalWrite,K.Vt.isEditor),n=e?m.$.grafana:m.$.cloudAlerting,r=[];e&&r.push(m.$.grafana);t&&r.push(m.$.cloudAlerting,m.$.cloudRecording);return{enabledRuleTypes:r,defaultRuleType:n}}(),{control:u,formState:{errors:d},getValues:p,setValue:f,watch:h}=(0,c.Gc)(),g=(0,s.useStyles2)(br),v=h("type");return(0,E.jsxs)(E.Fragment,{children:[!a&&(0,E.jsx)(s.Field,{error:null===(t=d.type)||void 0===t?void 0:t.message,invalid:!(null===(n=d.type)||void 0===n||!n.message),"data-testid":"alert-type-picker",children:(0,E.jsx)(s.InputControl,{render:e=>{var t;let{field:{onChange:n}}=e;return(0,E.jsx)(gr,{"aria-label":"Rule type",selected:null!==(t=p("type"))&&void 0!==t?t:l,onChange:n,enabledTypes:o})},name:"type",control:u,rules:{required:{value:!0,message:"Please select alert type"}}})}),(0,E.jsx)("div",{className:g.flexRow,children:(v===m.$.cloudRecording||v===m.$.cloudAlerting)&&(0,E.jsx)(s.Field,{className:g.formInput,label:"Select data source",error:null===(r=d.dataSourceName)||void 0===r?void 0:r.message,invalid:!(null===(i=d.dataSourceName)||void 0===i||!i.message),"data-testid":"datasource-picker",children:(0,E.jsx)(s.InputControl,{render:e=>{let{field:{onChange:t}}=e,n=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e.field,vr);return(0,E.jsx)(ar,Object.assign({},n,{onChange:e=>{var n;f("location",void 0),t(null!==(n=null==e?void 0:e.name)&&void 0!==n?n:null)}}))},name:"dataSourceName",control:u,rules:{required:{value:!0,message:"Please select a data source"}}})})})]})};const br=e=>({formInput:r.css`
  115. width: 330px;
  116. & + & {
  117. margin-left: ${e.spacing(3)};
  118. }
  119. `,flexRow:r.css`
  120. display: flex;
  121. flex-direction: row;
  122. justify-content: flex-start;
  123. align-items: flex-end;
  124. `}),yr=e=>{var t,n;let{value:r,onChange:a,dataSourceName:s}=e;const{mapToValue:l,mapToQuery:u}=function(e){return(0,i.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),[c,d]=(0,i.useState)(u({refId:"A",hide:!1},r)),{error:p,loading:f,value:h}=(0,o.Z)((()=>(0,O.getDataSourceSrv)().get(s)),[s]),g=(0,i.useCallback)((e=>{d(e),a(l(e))}),[a,l]);if(f||(null==h?void 0:h.name)!==s)return null;if(p||!h||null==h||null===(t=h.components)||void 0===t||!t.QueryEditor){const e=(null==p?void 0:p.message)||"Data source plugin does not export any Query Editor component";return(0,E.jsxs)("div",{children:["Could not load query editor due to: ",e]})}const m=null==h||null===(n=h.components)||void 0===n?void 0:n.QueryEditor;return(0,E.jsx)(m,{query:c,queries:[c],app:C.CoreApp.CloudAlerting,onChange:g,onRunQuery:Se.noop,datasource:h})};var jr=n(16695),wr=n(65184),Cr=n(22912),Sr=n(95450),Ar=n(20910),kr=n(48435),Ir=n(71623),Or=n(67436),Nr=n(359),Rr=n(85464),Tr=n(91312),$r=n(5831);var Fr=n(95910);const qr=e=>{let{data:t,currentPanel:n,changePanel:r,onThresholdsChange:a,thresholds:o}=e;const[l,u]=(0,i.useState)({frameIndex:0,showHeader:!0}),c=function(e,t,n){const r=(0,s.useTheme2)();if(t===Rr.GC||t===Rr.Kd||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,a=5*r.spacing.gridSize,o=i*a+a;return o>=200?200:o}(t,n,l.frameIndex),d=(0,s.useStyles2)(Er(c)),[p,f]=(0,i.useState)(function(e,t){if(!e)return{defaults:{},overrides:[]};return{defaults:{thresholds:e,unit:Lr(t),custom:{thresholdsStyle:{mode:Tr.i3.Line}}},overrides:[]}}(o,t));(0,i.useEffect)((()=>{f((e=>Object.assign({},e,{defaults:Object.assign({},e.defaults,{thresholds:o,unit:Lr(t),custom:Object.assign({},e.defaults.custom,{thresholdsStyle:{mode:Tr.i3.Line}})})})))}),[o,f,t]);const h=(0,i.useMemo)((()=>({eventBus:$r.Z,canEditThresholds:!0,onThresholdsChange:a})),[a]);return l&&t?(0,E.jsxs)("div",{className:d.wrapper,children:[(0,E.jsx)("div",{className:d.buttonGroup,children:(0,E.jsx)(Fr.j,{onChange:r,value:n})}),(0,E.jsx)(q.Z,{children:e=>{let{width:r}=e;return 0===r?null:(0,E.jsx)("div",{style:{height:`${c}px`,width:`${r}px`},children:(0,E.jsx)(s.PanelContextProvider,{value:h,children:(0,E.jsx)(O.PanelRenderer,{height:c,width:r,data:t,pluginId:n,title:"title",onOptionsChange:u,options:l,fieldConfig:p})})})}})]}):null},Er=e=>t=>({wrapper:r.css`
  125. padding: 0 ${t.spacing(2)};
  126. height: ${e+4*t.spacing.gridSize}px;
  127. `,buttonGroup:r.css`
  128. display: flex;
  129. justify-content: flex-end;
  130. `});function Lr(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 Dr=e=>{let{data:t,dsSettings:n,index:r,onChangeDataSource:a,onChangeQuery:o,onChangeTimeRange:l,onRunQueries:u,onRemoveQuery:c,onDuplicateQuery:d,query:p,queries:f,thresholds:h,onChangeThreshold:g}=e;const m=(0,s.useStyles2)(Qr),v=(0,ee.j)(p.model),[x,b]=(0,i.useState)(v?Rr.Fe:Rr.GC);return(0,E.jsx)("div",{className:m.wrapper,children:(0,E.jsx)(Nr.x,{alerting:!0,dataSource:n,onChangeDataSource:v?void 0:e=>a(e,r),id:p.refId,index:r,data:t,query:(0,Se.cloneDeep)(p.model),onChange:e=>o(e,r),onRemoveQuery:c,onAddQuery:()=>d((0,Se.cloneDeep)(p)),onRunQuery:u,queries:f,renderHeaderExtras:()=>((e,t)=>{var n;return(0,ee.j)(e.model)||!l?null:(0,E.jsx)(s.RelativeTimeRangePicker,{timeRange:null!==(n=e.relativeTimeRange)&&void 0!==n?n:(0,C.getDefaultRelativeTimeRange)(),onChange:e=>l(e,t)})})(p,r),app:C.CoreApp.UnifiedAlerting,visualization:t.state!==C.LoadingState.NotStarted?(0,E.jsx)(qr,{data:t,changePanel:b,currentPanel:x,thresholds:h,onThresholdsChange:e=>g(e,r)}):null,hideDisableQuery:!0},p.refId)})},Mr=e=>{let{children:t}=e;const n=(0,s.useStyles2)(Qr);return(0,E.jsx)("div",{className:n.wrapper,children:t})},Qr=e=>({wrapper:r.css`
  131. label: AlertingQueryWrapper;
  132. margin-bottom: ${e.spacing(1)};
  133. border: 1px solid ${e.colors.border.medium};
  134. border-radius: ${e.shape.borderRadius(1)};
  135. `});var Br,_r,Pr;function Ur(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class Vr extends i.PureComponent{constructor(e){super(e),Ur(this,"onRemoveQuery",(e=>{this.props.onQueriesChange(this.props.queries.filter((t=>t.model.refId!==e.refId)))})),Ur(this,"onChangeTimeRange",((e,t)=>{const{queries:n,onQueriesChange:r}=this.props;r(n.map(((n,r)=>r!==t?n:Object.assign({},n,{relativeTimeRange:e}))))})),Ur(this,"onChangeThreshold",((e,t)=>{const{queries:n,onQueriesChange:r}=this.props,i=n[t].refId;r(n.map((t=>(0,ee.j)(t.model)&&t.model.conditions&&t.model.conditions[0].query.params[0]===i?Object.assign({},t,{model:Object.assign({},t.model,{conditions:t.model.conditions.map(((t,n)=>t.query.params[0]===i&&0===n?Object.assign({},t,{evaluator:Object.assign({},t.evaluator,{params:[parseFloat(e.steps[1].value.toPrecision(3))]})}):t))})}):t)))})),Ur(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,Se.omit)(e.model,"datasource"),datasourceUid:t})}(n,e.uid))))})),Ur(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,ee.j)(e.model))return e;const r="math"===e.model.type,i="reduce"===e.model.type,a="resample"===e.model.type,o="classic_conditions"===e.model.type;var s;if(r)return Object.assign({},e,{model:Object.assign({},e.model,{expression:te(null!==(s=e.model.expression)&&void 0!==s?s:"",t,n)})});if(a||i){const r=e.model.expression===t;return Object.assign({},e,{model:Object.assign({},e.model,{expression:r?n:e.model.expression})})}if(o){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 i;return r!==t?n:Object.assign({},n,{refId:e.refId,queryType:null!==(i=n.model.queryType)&&void 0!==i?i:"",model:Object.assign({},n.model,e,{datasource:e.datasource})})})))})),Ur(this,"onDragEnd",(e=>{const{queries:t,onQueriesChange:n}=this.props;if(!e||!e.destination)return;const r=e.source.index,i=e.destination.index;if(r===i)return;const a=Array.from(t),[o]=a.splice(r,1);a.splice(i,0,o),n(a)})),Ur(this,"onDuplicateQuery",((e,t)=>{this.props.onDuplicateQuery(Object.assign({},t,{model:e}))})),Ur(this,"getDataSourceSettings",(e=>(0,O.getDataSourceSrv)().getInstanceSettings(e.datasourceUid))),Ur(this,"getThresholdsForQueries",(e=>{const t={};for(const n of e)(0,ee.j)(n.model)&&Array.isArray(n.model.conditions)&&n.model.conditions.forEach(((e,n)=>{if(n>0)return;const r=e.evaluator.params[0],i=e.query.params[0];"outside_range"!==e.evaluator.type&&"within_range"!==e.evaluator.type&&(t[i]||(t[i]={mode:C.ThresholdsMode.Absolute,steps:[{value:-1/0,color:O.config.theme2.colors.success.main}]}),t[i].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,E.jsx)(kr.Z5,{onDragEnd:this.onDragEnd,children:(0,E.jsx)(kr.bK,{droppableId:"alerting-queries",direction:"vertical",children:i=>(0,E.jsxs)("div",Object.assign({ref:i.innerRef},i.droppableProps,{children:[n.map(((i,a)=>{var o,s;const l=null!==(o=null===(s=this.props.data)||void 0===s?void 0:s[i.refId])&&void 0!==o?o:{series:[],state:C.LoadingState.NotStarted},u=this.getDataSourceSettings(i);return u?(0,E.jsx)(Dr,{index:a,dsSettings:u,data:l,query:i,onChangeQuery:this.onChangeQuery,onRemoveQuery:this.onRemoveQuery,queries:n,onChangeDataSource:this.onChangeDataSource,onDuplicateQuery:e,onRunQueries:t,onChangeTimeRange:this.onChangeTimeRange,thresholds:r[i.refId],onChangeThreshold:this.onChangeThreshold},i.refId):(0,E.jsx)(Gr,{index:a,model:i.model,onUpdateDatasource:()=>{const e=(0,Or.ak)().getInstanceSettings(null);e&&this.onChangeDataSource(e,a)},onRemoveQuery:()=>{this.onRemoveQuery(i)}},`${i.refId}-${a}`)})),i.placeholder]}))})})}}const Gr=e=>{let{index:t,onUpdateDatasource:n,onRemoveQuery:r,model:a}=e;const o=a.refId,[l,u]=(0,i.useState)(!1);return(0,E.jsx)(Mr,{children:(0,E.jsxs)(Ir.t,{title:o,draggable:!0,index:t,id:o,isOpen:!0,children:[(0,E.jsxs)(s.Card,{children:[Br||(Br=(0,E.jsx)(s.Card.Heading,{children:"This datasource has been removed"})),_r||(_r=(0,E.jsx)(s.Card.Description,{children:"The datasource for this query was not found, it was either removed or is not installed correctly."})),Pr||(Pr=(0,E.jsx)(s.Card.Figure,{children:(0,E.jsx)(s.Icon,{name:"question-circle"})})),(0,E.jsxs)(s.Card.Actions,{children:[(0,E.jsx)(s.Button,{variant:"secondary",onClick:()=>{n()},children:"Update datasource"},"update"),(0,E.jsx)(s.Button,{variant:"destructive",onClick:r,children:"Remove query"},"remove")]}),(0,E.jsx)(s.Card.SecondaryActions,{children:(0,E.jsx)(s.Button,{onClick:()=>{u((e=>!e))},icon:l?"angle-up":"angle-down",fill:"text",size:"sm",children:"Show details"},"details")})]}),l&&(0,E.jsx)("div",{children:(0,E.jsx)("pre",{children:(0,E.jsx)("code",{children:JSON.stringify(a,null,2)})})})]})})};function Yr(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class Wr extends i.PureComponent{constructor(e){var t;super(e),Yr(this,"runner",void 0),Yr(this,"queries",void 0),Yr(this,"onRunQueries",(()=>{const{queries:e}=this;this.runner.run(e)})),Yr(this,"onCancelQueries",(()=>{this.runner.cancel()})),Yr(this,"onChangeQueries",(e=>{this.queries=e,this.props.onChange(e)})),Yr(this,"onDuplicateQuery",(e=>{const{queries:t}=this;this.onChangeQueries(Zr(t,e))})),Yr(this,"onNewAlertingQuery",(()=>{const{queries:e}=this,t=(0,nr.P)();t&&this.onChangeQueries(Zr(e,{datasourceUid:t.uid,model:{refId:"",datasource:{type:t.type,uid:t.uid}}}))})),Yr(this,"onNewExpressionQuery",(()=>{const{queries:e}=this;this.onChangeQueries(Zr(e,{datasourceUid:Kn.Yq,model:Kn.mV.newQuery({type:Cr.Us.classic,conditions:[Sr.R]})}))})),this.state={panelDataByRefId:{}},this.runner=new Ar.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()}isRunning(){const e=Object.values(this.state.panelDataByRefId).find((e=>Boolean(e)));return(null==e?void 0:e.state)===C.LoadingState.Loading}renderRunQueryButton(){return this.isRunning()?(0,E.jsx)(s.Button,{icon:"fa fa-spinner",type:"button",variant:"destructive",onClick:this.onCancelQueries,children:"Cancel"}):(0,E.jsx)(s.Button,{icon:"sync",type:"button",onClick:this.onRunQueries,children:"Run queries"})}render(){const{value:e=[]}=this.props,{panelDataByRefId:t}=this.state,n=Kr(O.config.theme2),r=void 0===(0,nr.P)();return(0,E.jsxs)("div",{className:n.container,children:[(0,E.jsx)(Vr,{data:t,queries:e,onQueriesChange:this.onChangeQueries,onDuplicateQuery:this.onDuplicateQuery,onRunQueries:this.onRunQueries}),(0,E.jsxs)(s.HorizontalGroup,{spacing:"sm",align:"flex-start",children:[(0,E.jsx)(s.Tooltip,{content:"You appear to have no compatible data sources",show:r,children:(0,E.jsx)(s.Button,{type:"button",icon:"plus",onClick:this.onNewAlertingQuery,variant:"secondary","aria-label":jr.wl.components.QueryTab.addQuery,disabled:r,children:"Add query"})}),O.config.expressionsEnabled&&(0,E.jsx)(s.Button,{type:"button",icon:"plus",onClick:this.onNewExpressionQuery,variant:"secondary",children:"Add expression"}),this.renderRunQueryButton()]})]})}}const Zr=(e,t)=>{const n=(0,wr.Hs)(e),r=Object.assign({},t,{refId:n,queryType:"",model:Object.assign({},t.model,{hide:!1,refId:n}),relativeTimeRange:zr(t.model)});return[...e,r]},zr=e=>{if(!(0,ee.j)(e))return(0,C.getDefaultRelativeTimeRange)()},Kr=(0,s.stylesFactory)((e=>({container:r.css`
  136. background-color: ${e.colors.background.primary};
  137. height: 100%;
  138. max-width: ${e.breakpoints.values.xxl}px;
  139. `,runWrapper:r.css`
  140. margin-top: ${e.spacing(1)};
  141. `,editorWrapper:r.css`
  142. border: 1px solid ${e.colors.border.medium};
  143. border-radius: ${e.shape.borderRadius()};
  144. `}))),Hr=["ref"],Jr=["ref"];function Xr(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}const ei=()=>{var e,t;const{control:n,watch:r,formState:{errors:i}}=(0,c.Gc)(),a=r("type"),o=r("dataSourceName"),l=a===m.$.grafana,u=a===m.$.cloudAlerting,d=(a===m.$.cloudRecording||u)&&o;return(0,E.jsxs)("div",{children:[d&&(0,E.jsx)(s.Field,{error:null===(e=i.expression)||void 0===e?void 0:e.message,invalid:!(null===(t=i.expression)||void 0===t||!t.message),children:(0,E.jsx)(s.InputControl,{name:"expression",render:e=>{let{}=e,t=Xr(e.field,Hr);return(0,E.jsx)(yr,Object.assign({},t,{dataSourceName:o}))},control:n,rules:{required:{value:!0,message:"A valid expression is required"}}})}),l&&(0,E.jsx)(s.Field,{invalid:!!i.queries,error:!i.queries?void 0:"Must provide at least one valid query.",children:(0,E.jsx)(s.InputControl,{name:"queries",render:e=>{let{}=e,t=Xr(e.field,Jr);return(0,E.jsx)(Wr,Object.assign({},t))},control:n,rules:{validate:e=>Array.isArray(e)&&!!e.length}})})]})};var ti;const ni=e=>{let{editingExistingRule:t}=e;const{watch:n}=(0,c.Gc)(),r=n("type"),i=r===m.$.grafana;return(0,E.jsxs)(_,{stepNo:1,title:"Set a query and alert condition",children:[(0,E.jsx)(xr,{editingExistingRule:t}),r&&(ti||(ti=(0,E.jsx)(ei,{}))),i&&(0,E.jsx)(er,{existing:t})]})};var ri,ii,ai;const oi=e=>{var t;let{existing:n}=e;const r=(0,s.useStyles2)(li),o=(0,a.useDispatch)(),l=(0,p.iG)(),[y]=(0,f.K)(),[j,w]=(0,i.useState)(!1),C=null!==(t=y.returnTo)&&void 0!==t?t:"/alerting/list",[S,A]=(0,i.useState)(!1),k=(0,i.useMemo)((()=>n?(0,x.DQ)(n):Object.assign({},(0,x.uZ)(),{queries:(0,x.s0)()},y.defaults?JSON.parse(y.defaults):{},{type:m.$.grafana})),[n,y]),I=(0,c.cI)({mode:"onSubmit",defaultValues:k,shouldFocusError:!0}),{handleSubmit:O,watch:N}=I,R=N("type"),T=N("dataSourceName"),$=Boolean(R&&(R===m.$.grafana||!!T)),F=(0,h._)((e=>e.ruleForm.saveRule))||v.oq;(0,u.x)((e=>e.unifiedAlerting.ruleForm.saveRule));const q=(e,t)=>{var r,i,a,s;o((0,g.wy)({values:Object.assign({},k,e,{annotations:null!==(r=null===(i=e.annotations)||void 0===i?void 0:i.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!==(a=null===(s=e.labels)||void 0===s?void 0:s.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!==a?a:[]}),existing:n,redirectOnSave:t?C:void 0}))},L=()=>{l.error("There are errors in the form. Please correct them and try again!")};return(0,E.jsxs)(c.RV,Object.assign({},I,{children:[(0,E.jsxs)("form",{onSubmit:e=>e.preventDefault(),className:r.form,children:[(0,E.jsxs)(s.PageToolbar,{title:(n?"Edit":"Create")+" alert rule",pageIcon:"bell",children:[(0,E.jsx)(d.Link,{to:C,children:(0,E.jsx)(s.Button,{variant:"secondary",disabled:F.loading,type:"button",fill:"outline",children:"Cancel"})}),n?(0,E.jsx)(s.Button,{variant:"destructive",type:"button",onClick:()=>A(!0),children:"Delete"}):null,si(N)&&(0,E.jsx)(s.Button,{variant:"secondary",type:"button",onClick:()=>w(!0),disabled:F.loading,children:"Edit yaml"}),(0,E.jsxs)(s.Button,{variant:"primary",type:"button",onClick:O((e=>q(e,!1)),L),disabled:F.loading,children:[F.loading&&(0,E.jsx)(s.Spinner,{className:r.buttonSpinner,inline:!0}),"Save"]}),(0,E.jsxs)(s.Button,{variant:"primary",type:"button",onClick:O((e=>q(e,!0)),L),disabled:F.loading,children:[F.loading&&(0,E.jsx)(s.Spinner,{className:r.buttonSpinner,inline:!0}),"Save and exit"]})]}),(0,E.jsx)("div",{className:r.contentOuter,children:(0,E.jsx)(s.CustomScrollbar,{autoHeightMin:"100%",hideHorizontalTrack:!0,children:(0,E.jsxs)("div",{className:r.contentInner,children:[(0,E.jsx)(ni,{editingExistingRule:!!n}),$&&(0,E.jsxs)(E.Fragment,{children:[R===m.$.grafana?ri||(ri=(0,E.jsx)(Fe,{})):ii||(ii=(0,E.jsx)(G,{})),(0,E.jsx)(ge,{initialFolder:k.folder}),ai||(ai=(0,E.jsx)(Qe,{}))]})]})})})]}),S?(0,E.jsx)(s.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=b.Zk(n.ruleSourceName,n.namespace,n.group.name,n.rule);o((0,g.hS)(e,{navigateTo:"/alerting/list"}))}},onDismiss:()=>A(!1)}):null,j?(0,E.jsx)(Gn,{onClose:()=>w(!1)}):null]}))},si=e=>{const[t,n]=e(["type","dataSourceName"]);return(t===m.$.cloudAlerting||t===m.$.cloudRecording)&&""!==n},li=e=>({buttonSpinner:r.css`
  145. margin-right: ${e.spacing(1)};
  146. `,form:r.css`
  147. width: 100%;
  148. height: 100%;
  149. display: flex;
  150. flex-direction: column;
  151. `,contentInner:r.css`
  152. flex: 1;
  153. padding: ${e.spacing(2)};
  154. `,contentOuter:r.css`
  155. background: ${e.colors.background.primary};
  156. border: 1px solid ${e.colors.border.weak};
  157. border-radius: ${e.shape.borderRadius()};
  158. margin: ${e.spacing(0,2,2)};
  159. overflow: hidden;
  160. flex: 1;
  161. `,flexRow:r.css`
  162. display: flex;
  163. flex-direction: row;
  164. justify-content: flex-start;
  165. `});var ui,ci,di,pi,fi,hi,gi,mi,vi=n(78567),xi=n(69450);const bi=e=>{let{identifier:t}=e;(0,u.x)((e=>e.unifiedAlerting.ruleForm.existingRule));const{loading:n,result:r,error:o,dispatched:c}=(0,h._)((e=>e.ruleForm.existingRule)),d=(0,a.useDispatch)(),{isEditable:p}=(0,vi.M)(b.s0(t),null==r?void 0:r.rule);return(0,i.useEffect)((()=>{c||d((0,g.on)(t))}),[c,d,t]),n||void 0===p?ui||(ui=(0,E.jsx)(l.Z.Contents,{children:(0,E.jsx)(s.LoadingPlaceholder,{text:"Loading rule..."})})):o?(0,E.jsx)(l.Z.Contents,{children:(0,E.jsx)(s.Alert,{severity:"error",title:"Failed to load rule",children:o.message})}):r?!1===p?di||(di=(0,E.jsx)(yi,{title:"Cannot edit rule",children:"Sorry! You do not have permission to edit this rule."})):(0,E.jsx)(oi,{existing:r}):ci||(ci=(0,E.jsx)(yi,{title:"Rule not found",children:"Sorry! This rule does not exist."}))},yi=e=>{let{title:t,children:n}=e;return(0,E.jsxs)(s.Alert,{className:(0,s.useStyles2)(ji).warning,severity:"warning",title:t,children:[(0,E.jsx)("p",{children:n}),mi||(mi=(0,E.jsx)(s.LinkButton,{href:"alerting/list",children:"To rule list"}))]})},ji=e=>({warning:r.css`
  166. margin: ${e.spacing(4)};
  167. `}),wi=(0,s.withErrorBoundary)((e=>{let{match:t}=e;const n=(0,a.useDispatch)(),{id:r}=t.params,i=b.OA(r,!0),{loading:u}=(0,o.Z)((async()=>{await n((0,g.dV)())}),[n]),{canCreateGrafanaRules:c,canCreateCloudRules:d,canEditRules:p}=(0,xi.B)();return i||c||d?i&&!p(i.ruleSourceName)?fi||(fi=(0,E.jsx)(yi,{title:"Cannot edit rules",children:"Sorry! You are not allowed to edit rules."})):u?hi||(hi=(0,E.jsx)(l.Z.Contents,{children:(0,E.jsx)(s.LoadingPlaceholder,{text:"Loading..."})})):i?(0,E.jsx)(bi,{identifier:i},r):gi||(gi=(0,E.jsx)(oi,{})):pi||(pi=(0,E.jsx)(yi,{title:"Cannot create rules",children:"Sorry! You are not allowed to create rules."}))}),{style:"page"})},95910:(e,t,n)=>{n.d(t,{j:()=>l});var r=n(68404),i=n(90923),a=n(69783),o=n(85464),s=n(45916);function l(e){const{value:t,onChange:n,size:l="md"}=e,u=(0,r.useMemo)((()=>Object.values(i.config.panels).reduce(((e,t)=>(function(e){switch(e){case o.GC:case o.Fe:case o.Kd:return!0;default:return!1}}(t.id)&&e.push({value:t.id,label:t.name,imgUrl:t.info.logos.small}),e)),[])),[]);return(0,s.jsx)(a.RadioButtonGroup,{options:u,value:t,onChange:n,size:l})}},93783:(e,t,n)=>{n.d(t,{Z:()=>g});var r=n(36636),i=n(68404),a=n(80916),o=n(69783),s=n(85464),l=n(19854),u=n(45916);const c=["value","existingKeys","aria-label"];const d=e=>{let{value:t,existingKeys:n,"aria-label":r}=e,a=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e,c);const o=(0,i.useMemo)((()=>Object.values(s.q6).filter((e=>!n.includes(e))).map((e=>({value:e,label:s.vY[e]})))),[n]);return(0,u.jsx)(l.P,Object.assign({"aria-label":r,value:t,options:o,custom:!!t&&!Object.values(s.q6).includes(t)},a))},p=["ref"];var f;const h=e=>({annotationValueInput:r.css`
  168. width: 426px;
  169. `,textarea:r.css`
  170. height: 76px;
  171. `,addAnnotationsButton:r.css`
  172. flex-grow: 0;
  173. align-self: flex-start;
  174. margin-left: 148px;
  175. `,flexColumn:r.css`
  176. display: flex;
  177. flex-direction: column;
  178. `,field:r.css`
  179. margin-bottom: ${e.spacing.xs};
  180. `,flexRow:r.css`
  181. display: flex;
  182. flex-direction: row;
  183. justify-content: flex-start;
  184. `,flexRowItemMargin:r.css`
  185. margin-left: ${e.spacing.xs};
  186. `}),g=()=>{const e=(0,o.useStyles)(h),{control:t,register:n,watch:s,formState:{errors:l}}=(0,a.Gc)(),c=s("annotations"),g=(0,i.useCallback)((e=>c.filter(((t,n)=>n!==e)).map((e=>{let{key:t}=e;return t}))),[c]);return(0,u.jsxs)(u.Fragment,{children:[f||(f=(0,u.jsx)(o.Label,{children:"Summary and annotations"})),(0,u.jsx)(o.FieldArray,{name:"annotations",control:t,children:i=>{let{fields:a,append:s,remove:f}=i;return(0,u.jsxs)("div",{className:e.flexColumn,children:[a.map(((i,a)=>{var s,h,m,v,x,b,y,j,w,C,S,A,k,I,O;const N=null===(s=c[a])||void 0===s||null===(h=s.key)||void 0===h?void 0:h.toLocaleLowerCase().endsWith("url"),R=N?o.Input:o.TextArea;return(0,u.jsxs)("div",{className:e.flexRow,children:[(0,u.jsx)(o.Field,{className:e.field,invalid:!(null===(m=l.annotations)||void 0===m||null===(v=m[a])||void 0===v||null===(x=v.key)||void 0===x||!x.message),error:null===(b=l.annotations)||void 0===b||null===(y=b[a])||void 0===y||null===(j=y.key)||void 0===j?void 0:j.message,"data-testid":`annotation-key-${a}`,children:(0,u.jsx)(o.InputControl,{name:`annotations[${a}].key`,render:e=>{let{}=e,t=function(e,t){if(null==e)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(i[n]=e[n]);return i}(e.field,p);return(0,u.jsx)(d,Object.assign({},t,{"aria-label":`Annotation detail ${a+1}`,existingKeys:g(a),width:18}))},control:t,rules:{required:{value:!(null===(w=c[a])||void 0===w||!w.value),message:"Required."}}})}),(0,u.jsx)(o.Field,{className:(0,r.cx)(e.flexRowItemMargin,e.field),invalid:!(null===(C=l.annotations)||void 0===C||null===(S=C[a])||void 0===S||null===(A=S.value)||void 0===A||!A.message),error:null===(k=l.annotations)||void 0===k||null===(I=k[a])||void 0===I||null===(O=I.value)||void 0===O?void 0:O.message,children:(0,u.jsx)(R,Object.assign({"data-testid":`annotation-value-${a}`,className:(0,r.cx)(e.annotationValueInput,{[e.textarea]:!N})},n(`annotations[${a}].value`),{placeholder:N?"https://":"Text",defaultValue:i.value}))}),(0,u.jsx)(o.Button,{type:"button",className:e.flexRowItemMargin,"aria-label":"delete annotation",icon:"trash-alt",variant:"secondary",onClick:()=>f(a)})]},i.id)})),(0,u.jsx)(o.Button,{className:e.addAnnotationsButton,icon:"plus-circle",type:"button",variant:"secondary",onClick:()=>{s({key:"",value:""})},children:"Add info"})]})}})]})}},2394:(e,t,n)=>{n.d(t,{Z:()=>c});var r,i,a=n(36636),o=(n(68404),n(80916)),s=n(69783),l=n(45916);const u=e=>({wrapper:a.css`
  187. margin-bottom: ${e.spacing.xl};
  188. `,flexColumn:a.css`
  189. display: flex;
  190. flex-direction: column;
  191. `,flexRow:a.css`
  192. display: flex;
  193. flex-direction: row;
  194. justify-content: flex-start;
  195. & + button {
  196. margin-left: ${e.spacing.xs};
  197. }
  198. `,deleteLabelButton:a.css`
  199. margin-left: ${e.spacing.xs};
  200. align-self: flex-start;
  201. `,addLabelButton:a.css`
  202. flex-grow: 0;
  203. align-self: flex-start;
  204. `,centerAlignRow:a.css`
  205. align-items: baseline;
  206. `,equalSign:a.css`
  207. align-self: flex-start;
  208. width: 28px;
  209. justify-content: center;
  210. margin-left: ${e.spacing.xs};
  211. `,labelInput:a.css`
  212. width: 175px;
  213. margin-bottom: ${e.spacing.sm};
  214. & + & {
  215. margin-left: ${e.spacing.sm};
  216. }
  217. `}),c=e=>{let{className:t}=e;const n=(0,s.useStyles)(u),{register:c,control:d,watch:p,formState:{errors:f}}=(0,o.Gc)(),h=p("labels");return(0,l.jsxs)("div",{className:(0,a.cx)(t,n.wrapper),children:[r||(r=(0,l.jsx)(s.Label,{children:"Custom Labels"})),(0,l.jsx)(s.FieldArray,{control:d,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:[i||(i=(0,l.jsx)(s.InlineLabel,{width:18,children:"Labels"})),(0,l.jsxs)("div",{className:n.flexColumn,children:[t.map(((e,t)=>{var r,i,u,d,p,g,m,v,x,b,y,j,w,C;return(0,l.jsx)("div",{children:(0,l.jsxs)("div",{className:(0,a.cx)(n.flexRow,n.centerAlignRow),children:[(0,l.jsx)(s.Field,{className:n.labelInput,invalid:!(null===(r=f.labels)||void 0===r||null===(i=r[t])||void 0===i||null===(u=i.key)||void 0===u||!u.message),error:null===(d=f.labels)||void 0===d||null===(p=d[t])||void 0===p||null===(g=p.key)||void 0===g?void 0:g.message,children:(0,l.jsx)(s.Input,Object.assign({},c(`labels[${t}].key`,{required:{value:!(null===(m=h[t])||void 0===m||!m.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=f.labels)||void 0===v||null===(x=v[t])||void 0===x||null===(b=x.value)||void 0===b||!b.message),error:null===(y=f.labels)||void 0===y||null===(j=y[t])||void 0===j||null===(w=j.value)||void 0===w?void 0:w.message,children:(0,l.jsx)(s.Input,Object.assign({},c(`labels[${t}].value`,{required:{value:!(null===(C=h[t])||void 0===C||!C.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"})]})]})})}})]})}},19854:(e,t,n)=>{n.d(t,{P:()=>o});var r=n(68404),i=n(69783),a=n(45916);const o=e=>{let{value:t,onChange:n,options:o,className:s,placeholder:l,width:u,custom:c,onCustomChange:d,disabled:p=!1,addLabel:f="+ Add new","aria-label":h}=e;const[g,m]=(0,r.useState)(c);(0,r.useEffect)((()=>{c&&m(c)}),[c]);const v=(0,r.useMemo)((()=>[...o,{value:"__add__",label:f}]),[o,f]);return g?(0,a.jsx)(i.Input,{"aria-label":h,width:u,autoFocus:!c,value:t||"",placeholder:l,className:s,disabled:p,onChange:e=>n(e.target.value)}):(0,a.jsx)(i.Select,{"aria-label":h,width:u,options:v,value:t,className:s,placeholder:l,disabled:p,onChange:e=>{const t=null==e?void 0:e.value;"__add__"===t?(m(!0),d&&d(!0),n("")):n(t)}})}},17569:(e,t,n)=>{n.d(t,{S:()=>a});var r=n(68404),i=n(90923);function a(e){return{allDataSourcesAvailable:(0,r.useMemo)((()=>e.every((e=>Boolean((0,i.getDataSourceSrv)().getInstanceSettings(e.datasourceUid))))),[e])}}},13309:(e,t,n)=>{n.d(t,{W:()=>l});var r=n(68404),i=n(18745),a=n(83809),o=n(8455),s=n(33899);function l(e){const t=(0,i.useDispatch)(),n=(0,s._)((e=>e.folders));if((0,r.useEffect)((()=>{e&&t((0,a.sw)(e))}),[t,e]),e){const t=n[e]||o.oq;return{folder:t.result,loading:t.loading}}return{loading:!1}}},78567:(e,t,n)=>{n.d(t,{M:()=>l});var r=n(61959),i=n(82969),a=n(86647),o=n(13309),s=n(33899);function l(e,t){var n,l,u;const c=(0,s._)((e=>e.dataSources)),d=t&&(0,a.Pc)(t)?t.grafana_alert.namespace_uid:void 0,p=(0,i.Bz)(e),{folder:f,loading:h}=(0,o.W)(d);if(!t)return{isEditable:!1,isRemovable:!1,loading:!1};if((0,a.Pc)(t)){var g,m;if(!d)throw new Error(`Rule ${t.grafana_alert.title} does not have a folder uid, cannot determine if it is editable.`);return{isEditable:r.Vt.hasAccess(p.update,null!==(g=null==f?void 0:f.canSave)&&void 0!==g&&g),isRemovable:r.Vt.hasAccess(p.delete,null!==(m=null==f?void 0:f.canSave)&&void 0!==m&&m),loading:h}}const v=Boolean(null===(n=c[e])||void 0===n||null===(l=n.result)||void 0===l?void 0:l.rulerConfig);return{isEditable:r.Vt.hasAccess(p.update,r.Vt.isEditor)&&v,isRemovable:r.Vt.hasAccess(p.delete,r.Vt.isEditor)&&v,loading:null===(u=c[e])||void 0===u?void 0:u.loading}}},20910:(e,t,n)=>{n.d(t,{v:()=>S});var r=n(61928),i=n(2937),a=n(76913),o=n(7392),s=n(10010),l=n(34110),u=n(43215),c=n(90923),d=n(28659),p=n(92691),f=n(45418),h=n(86452),g=n(392),m=n(22912);const v={from:21600,to:0},x=(e,t)=>{switch(e.type){case m.Us.classic:return b(e);case m.Us.math:return j(e,t);case m.Us.resample:case m.Us.reduce:return w(e)}},b=e=>{var t;return null===(t=e.conditions)||void 0===t?void 0:t.map((e=>e.query.params[0]))},y=(e,t)=>{let n=[],r=[v.to];for(const i of e){const e=t.find((e=>e.refId===i));e&&e.relativeTimeRange&&(n.push(e.relativeTimeRange.from),r.push(e.relativeTimeRange.to))}return{from:n,to:r}},j=(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)),w=e=>e.expression?[e.expression]:void 0;function C(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class S{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:(0,d.i)(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:(0,c.getDataSourceSrv)();C(this,"subject",void 0),C(this,"subscription",void 0),C(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=k(e,u.LoadingState.Done);return this.subject.next(t)}for(const t of e)if(!(0,p.j)(t.model)){const n=await this.dataSourceSrv.get(t.datasourceUid);if(n.filterQuery&&!n.filterQuery(t.model)){const t=k(e,u.LoadingState.Done);return this.subject.next(t)}}this.subscription=A(this.backendSrv,e).subscribe({next:e=>{const t=R(e,((e,t)=>{const n=this.lastResult[e],r=(0,g.zR)(t,n);return(0,h.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=R(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 A=(e,t)=>{const n=k(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,a.K)((e=>(0,i.of)(N(n,e)))),(0,f.V)(e,r.requestId),(0,o.B)())})},k=(e,t)=>e.reduce(((n,r)=>(n[r.refId]={state:t,series:[],timeRange:I(r,e)},n)),{}),I=(e,t)=>{if((0,p.j)(e.model)){const n=((e,t)=>{const n=x(e,t);if(!n)return v;const{from:r,to:i}=y(n,t);return r.length||i.length?{from:Math.max(...r),to:Math.min(...i)}:v})(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,s.U)((t=>{const{data:n}=t,r={};for(const[t,i]of Object.entries(n.results))r[t]={timeRange:e[t].timeRange,state:u.LoadingState.Done,series:i.frames.map(u.dataFrameFromJSON)};return r})),N=(e,t)=>{const n=(0,c.toDataQueryError)(t);return R(e,((e,t)=>Object.assign({},t,{state:u.LoadingState.Error,error:n})))},R=(e,t)=>{const n={};for(const[r,i]of Object.entries(e))n[r]=t(r,i);return n}},69450:(e,t,n)=>{n.d(t,{B:()=>a});var r=n(68404),i=n(82969);function a(){return(0,r.useMemo)((()=>(0,i.Rv)()),[])}},92691:(e,t,n)=>{n.d(t,{j:()=>a});var r=n(20467),i=n(22912);const a=e=>{if(!e)return!1;if((0,r.Pr)(e.datasource))return!0;const t=e;return"string"==typeof t.type&&Object.values(i.Us).includes(t.type)}}}]);
  218. //# sourceMappingURL=AlertingRuleForm.5af23c57cbc0948c33bd.js.map