/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.triggersActionsUi_bundle_jsonpfunction=window.triggersActionsUi_bundle_jsonpfunction||[]).push([[24,17],{104:function(e,t,n){"use strict";n.r(t),n.d(t,"default",(function(){return m}));var s=n(1),i=n.n(s),o=n(25),a=n(2),c=n(3),r=(n(213),n(121)),l=n(113),u=n(29),d=n(176),b=n(152),j=n(22),p=n(24),g=n(0);const m=({actionType:e,onClose:t,postSaveEventHandler:n,actionTypeRegistry:m})=>{var f,O;const{application:{capabilities:x},http:v,notifications:{toasts:h}}=Object(u.b)().services,[y,F]=Object(s.useState)(e),[C,S]=Object(s.useState)(!1),[M,E]=Object(s.useState)(void 0),{isLoading:T,createConnector:k}=Object(d.a)(),I=Object(s.useRef)(!1),[L,w]=Object(s.useState)({actionTypeId:null!==(f=null==y?void 0:y.id)&&void 0!==f?f:"",isDeprecated:!1,config:{},secrets:{},isMissingSecrets:!1}),A=Object(l.e)(x),U=m.get(y.id),z=U&&U.subtype?(null!==(O=null==U?void 0:U.subtype)&&void 0!==O?O:[]).map((e=>({...m.get(e.id),name:e.name}))):[],V=z.map((e=>({id:e.id,label:e.name,"data-test-subj":`${e.id}Button`}))),B=Object(s.useRef)(),[_,D]=Object(s.useState)(null),[N,P]=Object(s.useState)({isSubmitted:!1,isSubmitting:!1,isValid:void 0,submit:async()=>({isValid:!1,data:{}}),preSubmitValidator:null}),{preSubmitValidator:R,submit:H,isValid:G,isSubmitting:$}=N,W=!1===G,q=T||$,Y=Object(s.useCallback)((async()=>{D(null);const{isValid:e,data:t}=await H();if(I.current&&e){if(R){const e=await R();if(e)return void D(e.message)}const{actionTypeId:e,name:n,config:s,secrets:i}=t,o={actionTypeId:e,name:null!=n?n:"",config:s,secrets:i};return await k(o)}}),[H,R,k]),J=Object(s.useCallback)((()=>{t()}),[t]),K=Object(s.useCallback)((async()=>{const e=await Y();e&&(J(),n&&n(e))}),[Y,J,n]);return Object(s.useEffect)((()=>(I.current=!0,()=>{I.current=!1})),[]),Object(s.useEffect)((()=>{(async()=>{try{S(!0);const e=await Object(j.d)({http:v});S(!1);const t={};for(const n of e)t[n.id]=n;E(t)}catch(e){h&&h.addDanger({title:c.i18n.translate("xpack.triggersActionsUI.sections.actionsConnectorsList.unableToLoadConnectorTypesMessage",{defaultMessage:"Unable to load connector types"})})}})()}),[]),Object(g.jsx)(a.EuiModal,{className:"actConnectorModal","data-test-subj":"connectorAddModal",onClose:J,style:{width:m.get(y.id).modalWidth}},Object(g.jsx)(a.EuiModalHeader,null,Object(g.jsx)(a.EuiFlexGroup,{gutterSize:"m",alignItems:"center"},U&&U.iconClass?Object(g.jsx)(a.EuiFlexItem,{grow:!1},Object(g.jsx)(a.EuiIcon,{type:U.iconClass,size:"xl"})):null,Object(g.jsx)(a.EuiFlexItem,{grow:!1},Object(g.jsx)(a.EuiFlexGroup,{gutterSize:"s",justifyContent:"center",alignItems:"center"},Object(g.jsx)(a.EuiFlexItem,null,Object(g.jsx)(a.EuiModalHeaderTitle,{size:"s",component:"h3",id:"flyoutTitle"},Object(g.jsx)(o.FormattedMessage,{defaultMessage:"{actionTypeName} connector",id:"xpack.triggersActionsUI.sections.addModalConnectorForm.flyoutTitle",values:{actionTypeName:y.name}}))),U&&U.isExperimental&&Object(g.jsx)(a.EuiFlexItem,{className:"betaBadgeFlexItem",grow:!1},Object(g.jsx)(a.EuiBetaBadge,{label:r.a.label,tooltipContent:r.a.tooltipContent})))))),Object(g.jsx)(a.EuiModalBody,null,C?Object(g.jsx)(p.d,null,Object(g.jsx)(o.FormattedMessage,{id:"xpack.triggersActionsUI.sections.connectorAddModal.loadingConnectorTypesDescription",defaultMessage:"Loading connector types…"})):Object(g.jsx)(i.a.Fragment,null,z&&Object(g.jsx)(i.a.Fragment,null,Object(g.jsx)(a.EuiButtonGroup,{isFullWidth:!0,buttonSize:"m",color:"primary",legend:"",options:V,idSelected:y.id,onChange:e=>{M&&M[e]&&(F(M[e]),w({actionTypeId:e,isDeprecated:!1,config:{},secrets:{},isMissingSecrets:!1}),B.current&&B.current({resetValues:!0,defaultValue:{actionTypeId:e,isDeprecated:!1,config:{},secrets:{}}}))},"data-test-subj":"slackTypeChangeButton"}),Object(g.jsx)(a.EuiSpacer,{size:"xs"})),Object(g.jsx)(b.a,{actionTypeModel:U,connector:L,isEdit:!1,onChange:P,setResetForm:e=>{B.current=e}}),_)),Object(g.jsx)(a.EuiModalFooter,null,Object(g.jsx)(a.EuiButtonEmpty,{onClick:J,isLoading:q},c.i18n.translate("xpack.triggersActionsUI.sections.addModalConnectorForm.cancelButtonLabel",{defaultMessage:"Cancel"})),A?Object(g.jsx)(a.EuiButton,{fill:!0,color:"success","data-test-subj":"saveActionButtonModal",type:"submit",iconType:"check",isLoading:q,disabled:W,onClick:K},Object(g.jsx)(o.FormattedMessage,{id:"xpack.triggersActionsUI.sections.addModalConnectorForm.saveButtonLabel",defaultMessage:"Save"})):null))}},113:function(e,t,n){"use strict";n.d(t,"f",(function(){return s})),n.d(t,"e",(function(){return i})),n.d(t,"c",(function(){return o})),n.d(t,"b",(function(){return a})),n.d(t,"a",(function(){return c})),n.d(t,"d",(function(){return r}));const s=e=>{var t;return null==e||null===(t=e.actions)||void 0===t?void 0:t.show},i=e=>{var t;return null==e||null===(t=e.actions)||void 0===t?void 0:t.save},o=e=>{var t;return null==e||null===(t=e.actions)||void 0===t?void 0:t.execute},a=e=>{var t;return null==e||null===(t=e.actions)||void 0===t?void 0:t.delete};function c(e,t){var n,s;return null!==(n=null==t||null===(s=t.authorizedConsumers[e])||void 0===s?void 0:s.all)&&void 0!==n&&n}const r=e=>{var t,n;return null==e||null===(t=e.management)||void 0===t||null===(n=t.security)||void 0===n?void 0:n.api_keys}},121:function(e,t,n){"use strict";n.d(t,"a",(function(){return i}));var s=n(3);const i={label:s.i18n.translate("xpack.triggersActionsUI.technicalPreviewBadgeLabel",{defaultMessage:"Technical preview"}),tooltipContent:s.i18n.translate("xpack.triggersActionsUI.technicalPreviewBadgeDescription",{defaultMessage:"This functionality is in technical preview and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but features in technical preview are not subject to the support SLA of official GA features."})}},152:function(e,t,n){"use strict";n.d(t,"a",(function(){return k}));var s=n(1),i=n.n(s),o=n(9),a=n(15),c=n(2),r=n(25),l=n(52),u=n(113),d=n(29),b=n(62),j=n(37),p=n(3),g=n(0);const{emptyField:m}=b.fieldValidators,f={label:"Connector name",validations:[{validator:m(p.i18n.translate("xpack.triggersActionsUI.sections.actionConnectorForm.error.requiredNameText",{defaultMessage:"Name is required."}))}]},O=({canSave:e})=>Object(g.jsx)(i.a.Fragment,null,Object(g.jsx)(a.UseField,{path:"id",component:j.HiddenField}),Object(g.jsx)(a.UseField,{path:"actionTypeId",component:j.HiddenField}),Object(g.jsx)(a.UseField,{path:"isDeprecated",component:j.HiddenField}),Object(g.jsx)(a.UseField,{path:"name",config:f,component:j.Field,componentProps:{euiFieldProps:{readOnly:!e,"data-test-subj":"nameInput",fullWidth:!0}}})),x=Object(s.memo)(O),v=({actionTypeModel:e,isEdit:t,registerPreSubmitValidator:n})=>{var o;const{application:{capabilities:a}}=Object(d.b)().services,b=Object(u.e)(a),j=null!==(o=null==e?void 0:e.actionConnectorFields)&&void 0!==o?o:null;return Object(g.jsx)(i.a.Fragment,null,Object(g.jsx)(x,{canSave:b}),Object(g.jsx)(c.EuiSpacer,{size:"m"}),null!==j?Object(g.jsx)(i.a.Fragment,null,Object(g.jsx)(c.EuiTitle,{size:"xxs","data-test-subj":"connector-settings-label"},Object(g.jsx)("h4",null,Object(g.jsx)(r.FormattedMessage,{id:"xpack.triggersActionsUI.sections.actionConnectorForm.connectorSettingsLabel",defaultMessage:"Connector settings"}))),Object(g.jsx)(c.EuiSpacer,{size:"s"}),Object(g.jsx)(c.EuiErrorBoundary,null,Object(g.jsx)(s.Suspense,{fallback:Object(g.jsx)(l.a,null,Object(g.jsx)(r.FormattedMessage,{id:"xpack.triggersActionsUI.sections.actionConnectorForm.loadingConnectorSettingsDescription",defaultMessage:"Loading connector settings…"}))},Object(g.jsx)(j,{readOnly:!b,isEdit:t,registerPreSubmitValidator:n})))):null)},h=Object(s.memo)(v),y=({title:e,dataTestSubj:t})=>Object(g.jsx)(i.a.Fragment,null,Object(g.jsx)(c.EuiSpacer,{size:"s"}),Object(g.jsx)(c.EuiCallOut,{size:"s",iconType:"iInCircle","data-test-subj":t,title:e}),Object(g.jsx)(c.EuiSpacer,{size:"m"})),F=e=>null!=e||!F(e),C=({isEdit:e,isMissingSecrets:t})=>{const[n]=Object(a.useFormData)(),{getFields:s}=Object(a.useFormContext)(),i=s(),o=(c=i,Object.keys(c).filter((e=>e.includes("secrets"))).reduce(((e,t)=>({...e,[t]:c[t]})),{}));var c;const r=Object.keys(o).length,l=(e=>{if(0===e.length)return"";if(1===e.length)return`${e[0]}`;if(2===e.length)return e.join(" and ");const t=e[e.length-1];return`${e.slice(0,-1).join(", ")}, and ${t}`})((e=>Object.keys(e).map((t=>e[t].label)).filter(F))(o));return 0===Object.keys(o).length?null:t?Object(g.jsx)(y,{title:p.i18n.translate("xpack.triggersActionsUI.components.builtinActionTypes.missingSecretsValuesLabel",{values:{secretFieldsLabel:l,encryptedFieldsLength:r},defaultMessage:"Sensitive information is not imported. Please enter value{encryptedFieldsLength, plural, one {} other {s}} for the following field{encryptedFieldsLength, plural, one {} other {s}} {secretFieldsLabel}."}),dataTestSubj:"missing-secrets-callout"}):e?e?Object(g.jsx)(y,{title:p.i18n.translate("xpack.triggersActionsUI.components.simpleConnectorForm.secrets.reenterValuesMessage",{values:{secretFieldsLabel:l,encryptedFieldsLength:r},defaultMessage:"Value{encryptedFieldsLength, plural, one {} other {s}} {secretFieldsLabel} {encryptedFieldsLength, plural, one {is} other {are}} encrypted. Please reenter value{encryptedFieldsLength, plural, one {} other {s}} for {encryptedFieldsLength, plural, one {this} other {these}} field{encryptedFieldsLength, plural, one {} other {s}}."}),dataTestSubj:"edit-connector-secrets-callout"}):null:Object(g.jsx)(y,{title:p.i18n.translate("xpack.triggersActionsUI.components.simpleConnectorForm.secrets.reenterValuesLabel",{values:{secretFieldsLabel:l,encryptedFieldsLength:r},defaultMessage:"Remember your {secretFieldsLabel} {encryptedFieldsLength, plural, one {value} other {values}}. You must reenter {encryptedFieldsLength, plural, one {it} other {them}} each time you edit the connector."}),dataTestSubj:"create-connector-secrets-callout"})},S=Object(s.memo)(C),M=e=>{var t,n;if(".webhook"!==e.actionTypeId&&".cases-webhook"!==e.actionTypeId)return e;const s=e,i=Object.entries(null!==(t=null==s||null===(n=s.config)||void 0===n?void 0:n.headers)&&void 0!==t?t:{}).map((([e,t])=>({key:e,value:t})));return{...e,config:{...e.config,headers:Object(o.isEmpty)(i)?void 0:i}}},E=e=>{var t,n;if(".webhook"!==e.actionTypeId&&".cases-webhook"!==e.actionTypeId)return e;const s=(null!==(t=null==e||null===(n=e.config)||void 0===n?void 0:n.headers)&&void 0!==t?t:[]).reduce(((e,t)=>({...e,[t.key]:t.value})),{});return{...e,config:{...e.config,headers:Object(o.isEmpty)(s)?null:s}}},T=({actionTypeModel:e,connector:t,isEdit:n,onChange:i,onFormModifiedChange:o,setResetForm:r})=>{const{form:l}=Object(a.useForm)({defaultValue:t,serializer:E,deserializer:M}),{submit:u,isValid:d,isSubmitted:b,isSubmitting:j,reset:p}=l,[m,f]=Object(s.useState)(null),O=Object(s.useCallback)((e=>{f((()=>e))}),[]),x=Object(a.useFormIsModified)({form:l,discard:["__internal__"]});return Object(s.useEffect)((()=>{i&&i({isValid:d,isSubmitted:b,isSubmitting:j,submit:u,preSubmitValidator:m})}),[i,d,b,j,u,m]),Object(s.useEffect)((()=>{o&&o(x)}),[x,o]),Object(s.useEffect)((()=>{r&&r(p)}),[p]),Object(g.jsx)(a.Form,{form:l},Object(g.jsx)(h,{actionTypeModel:e,isEdit:n,registerPreSubmitValidator:O}),Object(g.jsx)(c.EuiSpacer,{size:"m"}),Object(g.jsx)(S,{isEdit:n,isMissingSecrets:t.isMissingSecrets}))},k=i.a.memo(T)},176:function(e,t,n){"use strict";n.d(t,"a",(function(){return c}));var s=n(1),i=n(3),o=n(22),a=n(29);const c=()=>{const{http:e,notifications:{toasts:t}}=Object(a.b)().services,[n,c]=Object(s.useState)(!1),r=Object(s.useRef)(new AbortController),l=Object(s.useRef)(!1);return Object(s.useEffect)((()=>(l.current=!0,()=>{l.current=!1,r.current.abort()})),[]),{isLoading:n,createConnector:async function(n){c(!0),l.current=!0,r.current.abort(),r.current=new AbortController;try{const s=await Object(o.a)({http:e,connector:n});return l.current&&(c(!1),t.addSuccess(i.i18n.translate("xpack.triggersActionsUI.sections.addConnectorForm.updateSuccessNotificationText",{defaultMessage:"Created '{connectorName}'",values:{connectorName:s.name}}))),s}catch(e){var s,a;l.current&&(c(!1),"AbortError"!==e.name&&t.addDanger(null!==(s=null===(a=e.body)||void 0===a?void 0:a.message)&&void 0!==s?s:i.i18n.translate("xpack.triggersActionsUI.sections.useCreateConnector.updateErrorNotificationText",{defaultMessage:"Cannot create a connector."})))}}}}},213:function(e,t,n){switch(window.__kbnThemeTag__){case"v8dark":return n(214);case"v8light":return n(216)}},214:function(e,t,n){var s=n(48),i=n(215);"string"==typeof(i=i.__esModule?i.default:i)&&(i=[[e.i,i,""]]);s(i,{insert:"head",singleton:!1}),e.exports=i.locals||{}},215:function(e,t,n){(t=n(49)(!1)).push([e.i,".actConnectorModal{z-index:9000}.euiComboBoxOptionsList{z-index:9001}",""]),e.exports=t},216:function(e,t,n){var s=n(48),i=n(217);"string"==typeof(i=i.__esModule?i.default:i)&&(i=[[e.i,i,""]]);s(i,{insert:"head",singleton:!1}),e.exports=i.locals||{}},217:function(e,t,n){(t=n(49)(!1)).push([e.i,".actConnectorModal{z-index:9000}.euiComboBoxOptionsList{z-index:9001}",""]),e.exports=t}}]);