EditNotificationChannel.8d541edf5aaa7f03dcc4.js 11 KB

1234567
  1. "use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7384],{39539:(e,t,n)=>{n.d(t,{$:()=>c});var i=n(24420),r=n.n(i),s=n(68404),a=n(18745),l=n(45193),o=n(45916);const c=(e,t,n)=>i=>{const c=(0,a.connect)(e,t)(i),d=e=>{const t=(0,a.useDispatch)();return(0,s.useEffect)((()=>function(){t((0,l.e)({stateSelector:n}))}),[t]),(0,o.jsx)(c,Object.assign({},e))};return d.displayName=`ConnectWithCleanUp(${c.displayName})`,r()(d,i),d}},13239:(e,t,n)=>{n.r(t),n.d(t,{EditNotificationChannelPage:()=>v,default:()=>j});var i,r,s=n(68404),a=n(90923),l=n(69783),o=n(33801),c=n(39539),d=n(8674),u=n(51114),p=n(9191),h=n(61988),g=n(97130),f=n(45916);function m(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class v extends s.PureComponent{constructor(){super(...arguments),m(this,"onSubmit",(e=>{const{notificationChannel:t}=this.props;this.props.updateNotificationChannel(Object.assign({},(0,g.YV)(Object.assign({},t,e,{settings:Object.assign({},t.settings,e.settings)})),{id:t.id}))})),m(this,"onTestChannel",(e=>{const{notificationChannel:t}=this.props;this.props.testNotificationChannel((0,g.dv)(Object.assign({},t,e,{settings:Object.assign({},t.settings,e.settings)})))}))}componentDidMount(){this.props.loadNotificationChannel(parseInt(this.props.match.params.id,10))}render(){const{navModel:e,notificationChannel:t,notificationChannelTypes:n}=this.props;return(0,f.jsx)(o.Z,{navModel:e,children:(0,f.jsxs)(o.Z.Contents,{children:[i||(i=(0,f.jsx)("h2",{className:"page-sub-heading",children:"Edit notification channel"})),t&&t.id>0?(0,f.jsx)(l.Form,{maxWidth:600,onSubmit:this.onSubmit,defaultValues:Object.assign({},t,{type:n.find((e=>e.value===t.type))}),children:e=>{let{control:i,errors:r,getValues:s,register:l,watch:o}=e;const c=n.find((e=>e.value===s().type.value));return(0,f.jsx)(u.w,{selectableChannels:(0,g.t7)(n,!0),selectedChannel:c,imageRendererAvailable:a.config.rendererAvailable,onTestChannel:this.onTestChannel,register:l,watch:o,errors:r,getValues:s,control:i,resetSecureField:this.props.resetSecureField,secureFields:t.secureFields})}}):r||(r=(0,f.jsxs)("div",{children:["Loading notification channel",(0,f.jsx)(l.Spinner,{})]}))]})})}}const b={loadNotificationChannel:p.tk,testNotificationChannel:p.c1,updateNotificationChannel:p.fg,resetSecureField:h.J0},j=(0,c.$)((e=>({navModel:(0,d.h)(e.navIndex,"channels"),notificationChannel:e.notificationChannel.notificationChannel,notificationChannelTypes:e.notificationChannel.notificationChannelTypes})),b,(e=>e.notificationChannel))(v)},51114:(e,t,n)=>{n.d(t,{w:()=>x});var i=n(36636),r=n(68404),s=n(69783),a=n(78837),l=n(45916);const o=["ref"];const c=e=>{let{control:t,option:n,register:i,invalid:r}=e;const a=n.secure?`secureSettings.${n.propertyName}`:`settings.${n.propertyName}`;switch(n.element){case"input":return(0,l.jsx)(s.Input,Object.assign({},i(`${a}`,{required:!!n.required&&"Required",validate:e=>""===n.validationRule||d(e,n.validationRule)}),{invalid:r,type:n.inputType,placeholder:n.placeholder}));case"select":return(0,l.jsx)(s.InputControl,{control:t,name:`${a}`,render:e=>{var t;let{}=e,i=function(e,t){if(null==e)return{};var n,i,r={},s=Object.keys(e);for(i=0;i<s.length;i++)n=s[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e.field,o);return(0,l.jsx)(s.Select,Object.assign({},i,{options:null!==(t=n.selectOptions)&&void 0!==t?t:void 0,invalid:r}))}});case"textarea":return(0,l.jsx)(s.TextArea,Object.assign({invalid:r},i(`${a}`,{required:!!n.required&&"Required",validate:e=>""===n.validationRule||d(e,n.validationRule)})));default:return console.error("Element not supported",n.element),null}},d=(e,t)=>!!RegExp(t).test(e)||"Invalid format",u=e=>{let{control:t,currentFormValues:n,errors:i,selectedChannelOptions:r,register:a,onResetSecureField:o,secureFields:d}=e;return(0,l.jsx)(l.Fragment,{children:r.map(((e,r)=>{var u;const p=`${e.label}-${r}`,h=n[`settings.${e.showWhen.field}`]&&n[`settings.${e.showWhen.field}`].value;return e.showWhen.field&&h!==e.showWhen.is?null:"checkbox"===e.element?(0,l.jsx)(s.Field,{children:(0,l.jsx)(s.Checkbox,Object.assign({},a(e.secure?`secureSettings.${e.propertyName}`:`settings.${e.propertyName}`),{label:e.label,description:e.description}))},p):(0,l.jsx)(s.Field,{label:e.label,description:e.description,invalid:i.settings&&!!i.settings[e.propertyName],error:i.settings&&(null===(u=i.settings[e.propertyName])||void 0===u?void 0:u.message),children:d&&d[e.propertyName]?(0,l.jsx)(s.Input,{readOnly:!0,value:"Configured",suffix:(0,l.jsx)(s.Button,{onClick:()=>o(e.propertyName),fill:"text",type:"button",size:"sm",children:"Clear"})}):(0,l.jsx)(c,{option:e,register:a,control:t})},p)}))})},p=["ref"];const h=e=>{let{control:t,currentFormValues:n,errors:i,secureFields:r,selectedChannel:a,channels:o,register:c,resetSecureField:d}=e;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(s.Field,{label:"Name",invalid:!!i.name,error:i.name&&i.name.message,children:(0,l.jsx)(s.Input,Object.assign({},c("name",{required:"Name is required"})))}),(0,l.jsx)(s.Field,{label:"Type",children:(0,l.jsx)(s.InputControl,{name:"type",render:e=>{let{}=e,t=function(e,t){if(null==e)return{};var n,i,r={},s=Object.keys(e);for(i=0;i<s.length;i++)n=s[i],t.indexOf(n)>=0||(r[n]=e[n]);return r}(e.field,p);return(0,l.jsx)(s.Select,Object.assign({},t,{options:o}))},control:t,rules:{required:!0}})}),(0,l.jsx)(u,{selectedChannelOptions:a.options.filter((e=>e.required)),currentFormValues:n,secureFields:r,onResetSecureField:d,register:c,errors:i,control:t})]})},g=e=>{var t;let{control:n,currentFormValues:i,errors:r,selectedChannel:a,secureFields:o,register:c,resetSecureField:d}=e;return(0,l.jsxs)(s.CollapsableSection,{label:`Optional ${a.heading}`,isOpen:!1,children:[""!==a.info&&(0,l.jsx)(s.Alert,{severity:"info",title:null!==(t=a.info)&&void 0!==t?t:""}),(0,l.jsx)(u,{selectedChannelOptions:a.options.filter((e=>!e.required)),currentFormValues:i,register:c,errors:r,control:n,onResetSecureField:d,secureFields:o})]})};var f;const m=e=>{let{currentFormValues:t,imageRendererAvailable:n,register:i}=e;return(0,l.jsxs)(s.CollapsableSection,{label:"Notification settings",isOpen:!1,children:[(0,l.jsx)(s.Field,{children:(0,l.jsx)(s.Checkbox,Object.assign({},i("isDefault"),{label:"Default",description:"Use this notification for all alerts"}))}),(0,l.jsx)(s.Field,{children:(0,l.jsx)(s.Checkbox,Object.assign({},i("settings.uploadImage"),{label:"Include image",description:"Captures an image and include it in the notification"}))}),t.uploadImage&&!n&&(f||(f=(0,l.jsx)(s.InfoBox,{title:"No image renderer available/installed",children:"Grafana cannot find an image renderer to capture an image for the notification. Please make sure the Grafana Image Renderer plugin is installed. Please contact your Grafana administrator to install the plugin."}))),(0,l.jsx)(s.Field,{children:(0,l.jsx)(s.Checkbox,Object.assign({},i("disableResolveMessage"),{label:"Disable Resolve Message",description:"Disable the resolve message [OK] that is sent when alerting state returns to false"}))}),(0,l.jsx)(s.Field,{children:(0,l.jsx)(s.Checkbox,Object.assign({},i("sendReminder"),{label:"Send reminders",description:"Send additional notifications for triggered alerts"}))}),t.sendReminder&&(0,l.jsx)(l.Fragment,{children:(0,l.jsx)(s.Field,{label:"Send reminder every",description:"Specify how often reminders should be sent, e.g. every 30s, 1m, 10m, 30m', or 1h etc. Alert reminders are sent after rules are evaluated. A reminder can never be sent more frequently than a configured alert rule evaluation interval.",children:(0,l.jsx)(s.Input,Object.assign({},i("frequency"),{width:8}))})})]})};var v,b,j;const x=e=>{let{control:t,errors:n,selectedChannel:i,selectableChannels:o,register:c,watch:d,getValues:u,imageRendererAvailable:p,onTestChannel:f,resetSecureField:x,secureFields:C}=e;const S=y((0,s.useTheme)());(0,r.useEffect)((()=>{const e=new Set(null==i?void 0:i.options.filter((e=>e.showWhen.field)).map((e=>`settings.${e.showWhen.field}`)))||[];d(["type","sendReminder","uploadImage",...e])}),[null==i?void 0:i.options,d]);const F=u();return i?(0,l.jsxs)("div",{className:S.formContainer,children:[(0,l.jsx)("div",{className:S.formItem,children:(0,l.jsx)(h,{selectedChannel:i,channels:o,secureFields:C,resetSecureField:x,currentFormValues:F,register:c,errors:n,control:t})}),i.options.filter((e=>!e.required)).length>0&&(0,l.jsx)("div",{className:S.formItem,children:(0,l.jsx)(g,{selectedChannel:i,secureFields:C,resetSecureField:x,currentFormValues:F,register:c,errors:n,control:t})}),(0,l.jsx)("div",{className:S.formItem,children:(0,l.jsx)(m,{imageRendererAvailable:p,currentFormValues:F,register:c,errors:n,control:t})}),(0,l.jsx)("div",{className:S.formButtons,children:(0,l.jsxs)(s.HorizontalGroup,{children:[b||(b=(0,l.jsx)(s.Button,{type:"submit",children:"Save"})),(0,l.jsx)(s.Button,{type:"button",variant:"secondary",onClick:()=>f(u()),children:"Test"}),(0,l.jsx)("a",{href:`${a.ZP.appSubUrl}/alerting/notifications`,children:j||(j=(0,l.jsx)(s.Button,{type:"button",variant:"secondary",children:"Back"}))})]})})]}):v||(v=(0,l.jsx)(s.Spinner,{}))},y=(0,s.stylesFactory)((e=>({formContainer:i.css``,formItem:i.css`
  2. flex-grow: 1;
  3. padding-top: ${e.spacing.md};
  4. `,formButtons:i.css`
  5. padding-top: ${e.spacing.xl};
  6. `})))},9191:(e,t,n)=>{n.d(t,{Au:()=>l,C2:()=>c,c1:()=>u,en:()=>o,fA:()=>p,fg:()=>d,tk:()=>h});var i=n(90923),r=n(36537),s=n(58257),a=n(61988);function l(e){return async t=>{t((0,a.gz)());const n=await(0,i.getBackendSrv)().get("/api/alerts",e);t((0,a.Oc)(n))}}function o(e,t){return async n=>{await(0,i.getBackendSrv)().post(`/api/alerts/${e}/pause`,t);n(l({state:(i.locationService.getSearchObject().state||"all").toString()}))}}function c(e){return async t=>{try{await(0,i.getBackendSrv)().post("/api/alert-notifications",e),t((0,r.$l)((0,s.AT)("Notification created"))),i.locationService.push("/alerting/notifications")}catch(e){t((0,r.$l)((0,s.t_)(e.data.error)))}}}function d(e){return async t=>{try{await(0,i.getBackendSrv)().put(`/api/alert-notifications/${e.id}`,e),t((0,r.$l)((0,s.AT)("Notification updated")))}catch(e){t((0,r.$l)((0,s.t_)(e.data.error)))}}}function u(e){return async(t,n)=>{const r=n().notificationChannel.notificationChannel;await(0,i.getBackendSrv)().post("/api/alert-notifications/test",Object.assign({id:r.id},e))}}function p(){return async e=>{const t=(await(0,i.getBackendSrv)().get("/api/alert-notifiers")).sort(((e,t)=>e.name>t.name?1:-1));e((0,a.T2)(t))}}function h(e){return async t=>{await t(p());const n=await(0,i.getBackendSrv)().get(`/api/alert-notifications/${e}`);t((0,a.K)(n))}}},97130:(e,t,n)=>{n.d(t,{Pg:()=>r,YV:()=>a,dv:()=>l,t7:()=>s});var i=n(58635);const r={id:-1,name:"",type:{value:"email",label:"Email"},sendReminder:!1,disableResolveMessage:!1,frequency:"15m",settings:{uploadImage:n(90923).config.rendererAvailable,autoResolve:!0,httpMethod:"POST",severity:"critical"},secureSettings:{},secureFields:{},isDefault:!1},s=(0,i.Z)(((e,t)=>e.map((e=>t?{value:e.value,label:e.label,description:e.description}:{value:e.value,label:e.label})))),a=e=>{const t=Object.fromEntries(Object.entries(e.settings).map((e=>{let[t,n]=e;return[t,n&&n.hasOwnProperty("value")?n.value:n]})));return Object.assign({},r,e,{frequency:""===e.frequency?r.frequency:e.frequency,type:e.type.value,settings:Object.assign({},r.settings,t),secureSettings:Object.assign({},e.secureSettings)})},l=e=>{var t;return{name:e.name,type:e.type.value,frequency:null!==(t=e.frequency)&&void 0!==t?t:r.frequency,settings:Object.assign({},Object.assign(r.settings,e.settings)),secureSettings:Object.assign({},e.secureSettings)}}}}]);
  7. //# sourceMappingURL=EditNotificationChannel.8d541edf5aaa7f03dcc4.js.map