/*! 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([[17,36],{63:function(e,t,n){"use strict";n.r(t),n.d(t,"INDEX_IS_NOT_VALID",(function(){return s})),n.d(t,"DOCUMENT_NOT_VALID",(function(){return o})),n.d(t,"HISTORY_NOT_VALID",(function(){return a})),n.d(t,"EXECUTION_TIME_LABEL",(function(){return c})),n.d(t,"SHOW_TIME_FIELD_TOGGLE_TOOLTIP",(function(){return d})),n.d(t,"INDEX_LABEL",(function(){return l}));var i=n(0);const s=i.i18n.translate("xpack.stackConnectors.components.index.error.notValidIndexText",{defaultMessage:"Index is not valid."}),o=i.i18n.translate("xpack.stackConnectors.components.index.error.requiredDocumentJson",{defaultMessage:"Document is required and should be a valid JSON object."}),a=i.i18n.translate("xpack.stackConnectors.components.index.error.badIndexOverrideSuffix",{defaultMessage:"Alert history index must contain valid suffix."}),c=i.i18n.translate("xpack.stackConnectors.components.index.executionTimeFieldLabel",{defaultMessage:"Time field"}),d=i.i18n.translate("xpack.stackConnectors.components.index.definedateFieldTooltip",{defaultMessage:"Set this time field to the time the document was indexed."}),l=i.i18n.translate("xpack.stackConnectors.components.index.indicesToQueryLabel",{defaultMessage:"Index"})},77:function(e,t,n){"use strict";n.r(t),n.d(t,"default",(function(){return f}));var i=n(1),s=n.n(i),o=n(10),a=n(25),c=n(26),d=n(28),l=n(27),r=n(29),u=n(0),x=n(2),b=n(63),j=n(9);const{indexPatternField:O,emptyField:g}=d.fieldValidators,p=e=>({label:b.INDEX_LABEL,helpText:Object(j.jsx)(s.a.Fragment,null,Object(j.jsx)(r.FormattedMessage,{id:"xpack.stackConnectors.components.index.howToBroadenSearchQueryDescription",defaultMessage:"Use * to broaden your query."}),Object(j.jsx)(a.EuiSpacer,{size:"s"}),Object(j.jsx)(a.EuiLink,{href:e.links.alerting.indexAction,target:"_blank"},Object(j.jsx)(r.FormattedMessage,{id:"xpack.stackConnectors.components.index.configureIndexHelpLabel",defaultMessage:"Configuring index connector."}))),validations:[{validator:g(b.INDEX_IS_NOT_VALID)},{validator:O(u.i18n),type:c.VALIDATION_TYPES.ARRAY_ITEM}]}),f=({readOnly:e})=>{const{http:t,docLinks:n}=Object(x.useKibana)().services,{getFieldDefaultValue:d}=Object(c.useFormContext)(),[{config:u,__internal__:O}]=Object(c.useFormData)({watch:["config.executionTimeField","config.index","__internal__.hasTimeFieldCheckbox"]}),{index:g=null}=null!=u?u:{},[f,m]=Object(i.useState)([]),[T,F]=Object(i.useState)([]),[_,h]=Object(i.useState)(!1),I=!!d("config.executionTimeField"),k=null!=g&&T.length>0,E=null!=O&&O.hasTimeFieldCheckbox,C=e=>{e.length>0?F([x.firstFieldOption,...e]):F([])},L=Object(o.debounce)((async e=>{h(!0),m(await Object(x.getIndexOptions)(t,e)),h(!1)}),250);return Object(i.useEffect)((()=>{(async()=>{if(g){const e=await Object(x.getFields)(t,[g]);Array.isArray(e)&&C(Object(x.getTimeFieldOptions)(e))}})()}),[t,g]),Object(j.jsx)(s.a.Fragment,null,Object(j.jsx)(a.EuiTitle,{size:"s"},Object(j.jsx)("h5",null,Object(j.jsx)(r.FormattedMessage,{defaultMessage:"Write to index",id:"xpack.stackConnectors.components.index.connectorSectionTitle"}))),Object(j.jsx)(c.UseField,{path:"config.refresh",component:l.HiddenField}),Object(j.jsx)(a.EuiSpacer,{size:"m"}),Object(j.jsx)(c.UseField,{path:"config.index",config:p(n)},(i=>{const{isInvalid:o,errorMessage:d}=Object(c.getFieldValidityAndErrorMessage)(i);return Object(j.jsx)(a.EuiFormRow,{id:"indexConnectorSelectSearchBox",fullWidth:!0,label:Object(j.jsx)(r.FormattedMessage,{id:"xpack.stackConnectors.components.index.indicesToQueryLabel",defaultMessage:"Index"}),isInvalid:o,error:d,helpText:Object(j.jsx)(s.a.Fragment,null,Object(j.jsx)(r.FormattedMessage,{id:"xpack.stackConnectors.components.index.howToBroadenSearchQueryDescription",defaultMessage:"Use * to broaden your query."}),Object(j.jsx)(a.EuiSpacer,{size:"s"}),Object(j.jsx)(a.EuiLink,{href:n.links.alerting.indexAction,target:"_blank"},Object(j.jsx)(r.FormattedMessage,{id:"xpack.stackConnectors.components.index.configureIndexHelpLabel",defaultMessage:"Configuring index connector."})))},Object(j.jsx)(a.EuiComboBox,{fullWidth:!0,singleSelection:{asPlainText:!0},async:!0,isLoading:_,isInvalid:o,noSuggestions:!f.length,options:f,"data-test-subj":"connectorIndexesComboBox","data-testid":"connectorIndexesComboBox",selectedOptions:g?[{value:g,label:g}]:[],isDisabled:e,onChange:async e=>{i.setValue(e.length>0?e[0].value:"");const n=e.map((e=>e.value));if(0===n.length)return void C([]);const s=await Object(x.getFields)(t,n);C(Object(x.getTimeFieldOptions)(s))},onSearchChange:e=>{void 0!==e&&i.clearErrors(c.VALIDATION_TYPES.ARRAY_ITEM),L(e)}}))})),Object(j.jsx)(a.EuiSpacer,{size:"m"}),k?Object(j.jsx)(c.UseField,{path:"__internal__.hasTimeFieldCheckbox",component:l.ToggleField,config:{defaultValue:I},componentProps:{euiFieldProps:{label:Object(j.jsx)(s.a.Fragment,null,Object(j.jsx)(r.FormattedMessage,{id:"xpack.stackConnectors.components.index.defineTimeFieldLabel",defaultMessage:"Define time field for each document"}),Object(j.jsx)(a.EuiIconTip,{position:"right",type:"questionInCircle",content:b.SHOW_TIME_FIELD_TOGGLE_TOOLTIP})),disabled:e,"data-test-subj":"hasTimeFieldCheckbox"}}}):null,E?Object(j.jsx)(s.a.Fragment,null,Object(j.jsx)(a.EuiSpacer,{size:"m"}),Object(j.jsx)(c.UseField,{path:"config.executionTimeField",component:l.SelectField,config:{label:b.EXECUTION_TIME_LABEL},componentProps:{euiFieldProps:{"data-test-subj":"executionTimeFieldSelect",options:T,fullWidth:!0,readOnly:e}}})):null)}}}]);