/*! 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.stackConnectors_bundle_jsonpfunction=window.stackConnectors_bundle_jsonpfunction||[]).push([[10,39],{121:function(e,t,s){"use strict";s.r(t),s.d(t,"default",(function(){return j}));var n=s(1),a=s.n(n),o=s(0),i=s(25),r=s(2),c=s(16),l=s(40),u=s(43);var d=s(31);var b=s(9);const p=({selectedValue:e,http:t,toastNotifications:s,actionConnector:a,onChange:o})=>{const[r,p]=Object(n.useState)(null),[m,j]=Object(n.useState)([]),[g,O]=Object(n.useState)([]),{isLoading:f,issues:A}=(({http:e,actionConnector:t,toastNotifications:s,query:a})=>{const[o,i]=Object(n.useState)(!1),[r,b]=Object(n.useState)([]),p=Object(n.useRef)(new AbortController);return Object(n.useEffect)((()=>{let n=!1;const o=Object(d.debounce)(500,(async()=>{if(t&&!Object(d.isEmpty)(a)){p.current=new AbortController,i(!0);try{const d=await async function({http:e,signal:t,connectorId:s,title:n}){const a=await e.post(`${c.BASE_ACTION_API_PATH}/connector/${encodeURIComponent(s)}/_execute`,{body:JSON.stringify({params:{subAction:"issues",subActionParams:{title:n}}}),signal:t});return Object(l.a)(a)}({http:e,signal:p.current.signal,connectorId:t.id,title:null!=a?a:""});var o,r;n||(i(!1),b(null!==(o=d.data)&&void 0!==o?o:[]),d.status&&"error"===d.status&&s.addDanger({title:u.ISSUES_API_ERROR,text:`${null!==(r=d.serviceMessage)&&void 0!==r?r:d.message}`}))}catch(e){n||(i(!1),s.addDanger({title:u.ISSUES_API_ERROR,text:e.message}))}}else i(!1)}));return p.current.abort(),o(),()=>{n=!0,i(!1),p.current.abort()}}),[e,t,s,a]),{issues:r,isLoading:o}})({http:t,toastNotifications:s,actionConnector:a,query:r}),{isLoading:E,issue:S}=(({http:e,toastNotifications:t,actionConnector:s,id:a})=>{const[o,i]=Object(n.useState)(!1),[r,d]=Object(n.useState)(null),b=Object(n.useRef)(new AbortController);return Object(n.useEffect)((()=>{let n=!1;return b.current.abort(),(async()=>{if(s&&a){b.current=new AbortController,i(!0);try{const p=await async function({http:e,signal:t,connectorId:s,id:n}){const a=await e.post(`${c.BASE_ACTION_API_PATH}/connector/${encodeURIComponent(s)}/_execute`,{body:JSON.stringify({params:{subAction:"issue",subActionParams:{id:n}}}),signal:t});return Object(l.a)(a)}({http:e,signal:b.current.signal,connectorId:s.id,id:a});var o,r;n||(i(!1),d(null!==(o=p.data)&&void 0!==o?o:null),p.status&&"error"===p.status&&t.addDanger({title:u.GET_ISSUE_API_ERROR(a),text:`${null!==(r=p.serviceMessage)&&void 0!==r?r:p.message}`}))}catch(e){n||(i(!1),t.addDanger({title:u.GET_ISSUE_API_ERROR(a),text:e.message}))}}else i(!1)})(),()=>{n=!0,i(!1),b.current.abort()}}),[e,s,a,t]),{isLoading:o,issue:r}})({http:t,toastNotifications:s,actionConnector:a,id:e});Object(n.useEffect)((()=>O(A.map((e=>({label:e.title,value:e.key}))))),[A]),Object(n.useEffect)((()=>{if(E||null==S)return;const e=[{label:S.title,value:S.key}];O(e),j(e)}),[S,E]);const y=Object(n.useCallback)((e=>{p(e)}),[]),x=Object(n.useCallback)((e=>{j(e),o(e[0].value)}),[o]),_=Object(n.useMemo)((()=>f||E?u.SEARCH_ISSUES_LOADING:u.SEARCH_ISSUES_PLACEHOLDER),[f,E]);return Object(b.jsx)(i.EuiComboBox,{singleSelection:!0,fullWidth:!0,placeholder:_,"data-test-subj":"search-parent-issues","aria-label":u.SEARCH_ISSUES_COMBO_BOX_ARIA_LABEL,options:g,isLoading:f||E,onSearchChange:y,selectedOptions:m,onChange:x})},m=Object(n.memo)(p),j=({actionConnector:e,actionParams:t,editAction:s,errors:d,index:p,messageVariables:j})=>{var g,O,f,A,E,S;const{http:y,notifications:{toasts:x}}=Object(r.useKibana)().services,{incident:_,comments:I}=Object(n.useMemo)((()=>{var e;return null!==(e=t.subActionParams)&&void 0!==e?e:{incident:{},comments:[]}}),[t.subActionParams]),C=Object(n.useRef)(null!==(g=null==e?void 0:e.id)&&void 0!==g?g:""),{isLoading:h,issueTypes:R}=(({http:e,actionConnector:t,toastNotifications:s})=>{const[a,o]=Object(n.useState)(!0),[i,r]=Object(n.useState)([]),d=Object(n.useRef)(new AbortController);return Object(n.useEffect)((()=>{let n=!1;return d.current.abort(),(async()=>{if(t){d.current=new AbortController,o(!0);try{const b=await async function({http:e,signal:t,connectorId:s}){const n=await e.post(`${c.BASE_ACTION_API_PATH}/connector/${encodeURIComponent(s)}/_execute`,{body:JSON.stringify({params:{subAction:"issueTypes",subActionParams:{}}}),signal:t});return Object(l.a)(n)}({http:e,signal:d.current.signal,connectorId:t.id});var a,i;n||(o(!1),r(null!==(a=b.data)&&void 0!==a?a:[]),b.status&&"error"===b.status&&s.addDanger({title:u.ISSUE_TYPES_API_ERROR,text:`${null!==(i=b.serviceMessage)&&void 0!==i?i:b.message}`}))}catch(e){n||(o(!1),s.addDanger({title:u.ISSUE_TYPES_API_ERROR,text:e.message}))}}else o(!1)})(),()=>{n=!0,o(!1),d.current.abort()}}),[e,t,s]),{issueTypes:i,isLoading:a}})({http:y,toastNotifications:x,actionConnector:e}),{isLoading:P,fields:v}=(({http:e,toastNotifications:t,actionConnector:s,issueType:a})=>{const[o,i]=Object(n.useState)(!0),[r,d]=Object(n.useState)({}),b=Object(n.useRef)(new AbortController);return Object(n.useEffect)((()=>{let n=!1;return b.current.abort(),(async()=>{if(s&&a){b.current=new AbortController,i(!0);try{const p=await async function({http:e,signal:t,connectorId:s,id:n}){const a=await e.post(`${c.BASE_ACTION_API_PATH}/connector/${encodeURIComponent(s)}/_execute`,{body:JSON.stringify({params:{subAction:"fieldsByIssueType",subActionParams:{id:n}}}),signal:t});return Object(l.a)(a)}({http:e,signal:b.current.signal,connectorId:s.id,id:a});var o,r;n||(d(null!==(o=p.data)&&void 0!==o?o:{}),i(!1),p.status&&"error"===p.status&&t.addDanger({title:u.FIELDS_API_ERROR,text:`${null!==(r=p.serviceMessage)&&void 0!==r?r:p.message}`}))}catch(e){n||(i(!1),t.addDanger({title:u.FIELDS_API_ERROR,text:e.message}))}}else i(!1)})(),()=>{n=!0,i(!1),b.current.abort()}}),[e,s,a,t]),{isLoading:o,fields:r}})({http:y,toastNotifications:x,actionConnector:e,issueType:null!==(O=_.issueType)&&void 0!==O?O:""}),L=Object(n.useCallback)(((e,t)=>s("subActionParams","issueType"===e?{incident:{issueType:t},comments:I}:"comments"===e?{incident:_,comments:t}:{incident:{..._,[e]:t},comments:I},p)),[I,s,_,p]),T=Object(n.useCallback)(((e,t)=>{L(e,[{commentId:"1",comment:t}])}),[L]),{hasLabels:k,hasDescription:M,hasPriority:w,hasParent:F}=Object(n.useMemo)((()=>null!=v?{hasLabels:Object.prototype.hasOwnProperty.call(v,"labels"),hasDescription:Object.prototype.hasOwnProperty.call(v,"description"),hasPriority:Object.prototype.hasOwnProperty.call(v,"priority"),hasParent:Object.prototype.hasOwnProperty.call(v,"parent")}:{hasLabels:!1,hasDescription:!1,hasPriority:!1,hasParent:!1}),[v]),U=Object(n.useMemo)((()=>{const e=null==_.issueType||!R.length||R.some((e=>e.id===_.issueType));var t;return _.issueType&&e||!(R.length>0)||L("issueType",null!==(t=R[0].id)&&void 0!==t?t:""),R.map((e=>{var t,s;return{value:null!==(t=e.id)&&void 0!==t?t:"",text:null!==(s=e.name)&&void 0!==s?s:""}}))}),[L,_,R]),B=Object(n.useMemo)((()=>{if(null!=_.issueType&&null!=v){const t=null!=v.priority?v.priority.allowedValues:[],s=t.some((e=>e.name===_.priority));var e;return _.priority&&s||!(t.length>0)||L("priority",null!==(e=t[0].name)&&void 0!==e?e:""),t.map((e=>({value:e.name,text:e.name})))}return[]}),[L,v,_.issueType,_.priority]);Object(n.useEffect)((()=>{P||w||null==_.priority||L("priority",null)}),[w,P]);const D=Object(n.useMemo)((()=>_.labels?_.labels.map((e=>({label:e}))):[]),[_.labels]);Object(n.useEffect)((()=>{null!=e&&C.current!==e.id&&(C.current=e.id,s("subActionParams",{incident:{},comments:[]},p))}),[e]),Object(n.useEffect)((()=>{t.subAction||s("subAction","pushToService",p),t.subActionParams||s("subActionParams",{incident:{},comments:[]},p)}),[t]);const N=null!=d["subActionParams.incident.labels"]&&void 0!==d["subActionParams.incident.labels"]&&d["subActionParams.incident.labels"].length>0&&void 0!==_.labels;return Object(b.jsx)(a.a.Fragment,null,Object(b.jsx)(i.EuiFormRow,{fullWidth:!0,label:o.i18n.translate("xpack.stackConnectors.components.jira.urgencySelectFieldLabel",{defaultMessage:"Issue type"})},Object(b.jsx)(i.EuiSelect,{fullWidth:!0,isLoading:h,disabled:h||P,"data-test-subj":"issueTypeSelect",options:U,value:null!==(f=_.issueType)&&void 0!==f?f:void 0,onChange:e=>L("issueType",e.target.value)})),Object(b.jsx)(i.EuiHorizontalRule,null),F&&Object(b.jsx)(a.a.Fragment,null,Object(b.jsx)(i.EuiFlexGroup,null,Object(b.jsx)(i.EuiFlexItem,null,Object(b.jsx)(i.EuiFormRow,{fullWidth:!0,label:o.i18n.translate("xpack.stackConnectors.components.jira.parentIssueSearchLabel",{defaultMessage:"Parent issue"})},Object(b.jsx)(m,{selectedValue:_.parent,http:y,toastNotifications:x,actionConnector:e,onChange:e=>{L("parent",e)}})))),Object(b.jsx)(i.EuiSpacer,{size:"m"})),Object(b.jsx)(a.a.Fragment,null,w&&Object(b.jsx)(a.a.Fragment,null,Object(b.jsx)(i.EuiFlexGroup,{"data-test-subj":"priority-wrapper"},Object(b.jsx)(i.EuiFlexItem,null,Object(b.jsx)(i.EuiFormRow,{fullWidth:!0,label:o.i18n.translate("xpack.stackConnectors.components.jira.severitySelectFieldLabel",{defaultMessage:"Priority"})},Object(b.jsx)(i.EuiSelect,{fullWidth:!0,isLoading:P,disabled:h||P,"data-test-subj":"prioritySelect",options:B,value:null!==(A=_.priority)&&void 0!==A?A:void 0,onChange:e=>{L("priority",e.target.value)}})))),Object(b.jsx)(i.EuiSpacer,{size:"m"})),Object(b.jsx)(i.EuiFormRow,{"data-test-subj":"summary-row",fullWidth:!0,error:d["subActionParams.incident.summary"],isInvalid:void 0!==d["subActionParams.incident.summary"]&&d["subActionParams.incident.summary"].length>0&&void 0!==_.summary,label:o.i18n.translate("xpack.stackConnectors.components.jira.summaryFieldLabel",{defaultMessage:"Summary (required)"})},Object(b.jsx)(r.TextFieldWithMessageVariables,{index:p,editAction:L,messageVariables:j,paramsProperty:"summary",inputTargetValue:null!==(E=_.summary)&&void 0!==E?E:void 0,errors:d["subActionParams.incident.summary"]})),Object(b.jsx)(i.EuiSpacer,{size:"m"}),k&&Object(b.jsx)(a.a.Fragment,null,Object(b.jsx)(i.EuiFlexGroup,{"data-test-subj":"labels-wrapper"},Object(b.jsx)(i.EuiFlexItem,null,Object(b.jsx)(i.EuiFormRow,{fullWidth:!0,label:o.i18n.translate("xpack.stackConnectors.components.jira.impactSelectFieldLabel",{defaultMessage:"Labels"}),error:d["subActionParams.incident.labels"],isInvalid:N},Object(b.jsx)(i.EuiComboBox,{noSuggestions:!0,fullWidth:!0,isLoading:P,isDisabled:h||P,selectedOptions:D,onCreateOption:e=>{const t=[...D,{label:e}];L("labels",t.map((e=>e.label)))},onChange:e=>{L("labels",e.map((e=>e.label)))},onBlur:()=>{_.labels||L("labels",[])},isClearable:!0,"data-test-subj":"labelsComboBox",isInvalid:N})))),Object(b.jsx)(i.EuiSpacer,{size:"m"})),M&&Object(b.jsx)(r.TextAreaWithMessageVariables,{index:p,editAction:L,messageVariables:j,paramsProperty:"description",inputTargetValue:null!==(S=_.description)&&void 0!==S?S:void 0,label:o.i18n.translate("xpack.stackConnectors.components.jira.descriptionTextAreaFieldLabel",{defaultMessage:"Description"})}),Object(b.jsx)(r.TextAreaWithMessageVariables,{index:p,editAction:T,messageVariables:j,paramsProperty:"comments",inputTargetValue:I&&I.length>0?I[0].comment:void 0,label:o.i18n.translate("xpack.stackConnectors.components.jira.commentsTextAreaFieldLabel",{defaultMessage:"Additional comments"})})))}},40:function(e,t,s){"use strict";s.d(t,"a",(function(){return n}));const n=({connector_id:e,service_message:t,...s})=>({...s,actionId:e,...t&&{serviceMessage:t}})},43:function(e,t,s){"use strict";s.r(t),s.d(t,"API_URL_LABEL",(function(){return a})),s.d(t,"JIRA_PROJECT_KEY_LABEL",(function(){return o})),s.d(t,"JIRA_EMAIL_LABEL",(function(){return i})),s.d(t,"JIRA_API_TOKEN_LABEL",(function(){return r})),s.d(t,"SUMMARY_REQUIRED",(function(){return c})),s.d(t,"ISSUE_TYPES_API_ERROR",(function(){return l})),s.d(t,"FIELDS_API_ERROR",(function(){return u})),s.d(t,"ISSUES_API_ERROR",(function(){return d})),s.d(t,"GET_ISSUE_API_ERROR",(function(){return b})),s.d(t,"SEARCH_ISSUES_COMBO_BOX_ARIA_LABEL",(function(){return p})),s.d(t,"SEARCH_ISSUES_PLACEHOLDER",(function(){return m})),s.d(t,"SEARCH_ISSUES_LOADING",(function(){return j})),s.d(t,"LABELS_WHITE_SPACES",(function(){return g}));var n=s(0);const a=n.i18n.translate("xpack.stackConnectors.components.jira.apiUrlTextFieldLabel",{defaultMessage:"URL"}),o=n.i18n.translate("xpack.stackConnectors.components.jira.projectKey",{defaultMessage:"Project key"}),i=n.i18n.translate("xpack.stackConnectors.components.jira.emailTextFieldLabel",{defaultMessage:"Email address"}),r=n.i18n.translate("xpack.stackConnectors.components.jira.apiTokenTextFieldLabel",{defaultMessage:"API token"}),c=n.i18n.translate("xpack.stackConnectors.components.jira.requiredSummaryTextField",{defaultMessage:"Summary is required."}),l=n.i18n.translate("xpack.stackConnectors.components.jira.unableToGetIssueTypesMessage",{defaultMessage:"Unable to get issue types"}),u=n.i18n.translate("xpack.stackConnectors.components.jira.unableToGetFieldsMessage",{defaultMessage:"Unable to get fields"}),d=n.i18n.translate("xpack.stackConnectors.components.jira.unableToGetIssuesMessage",{defaultMessage:"Unable to get issues"}),b=e=>n.i18n.translate("xpack.stackConnectors.components.jira.unableToGetIssueMessage",{defaultMessage:"Unable to get issue with id {id}",values:{id:e}}),p=n.i18n.translate("xpack.stackConnectors.components.jira.searchIssuesComboBoxAriaLabel",{defaultMessage:"Type to search"}),m=n.i18n.translate("xpack.stackConnectors.components.jira.searchIssuesComboBoxPlaceholder",{defaultMessage:"Type to search"}),j=n.i18n.translate("xpack.stackConnectors.components.jira.searchIssuesLoading",{defaultMessage:"Loading..."}),g=n.i18n.translate("xpack.stackConnectors.components.jira.labelsSpacesErrorMessage",{defaultMessage:"Labels cannot contain spaces."})}}]);