(window["observabilityDashboards_bundle_jsonpfunction"]=window["observabilityDashboards_bundle_jsonpfunction"]||[]).push([[13],{2314:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__);__webpack_require__.d(__webpack_exports__,"default",(function(){return IndexPatternSelect}));var lodash__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(3);var lodash__WEBPACK_IMPORTED_MODULE_0___default=__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);var react__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(0);var react__WEBPACK_IMPORTED_MODULE_1___default=__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);var _elastic_eui__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__(2);var _elastic_eui__WEBPACK_IMPORTED_MODULE_2___default=__webpack_require__.n(_elastic_eui__WEBPACK_IMPORTED_MODULE_2__);var _common_index_patterns_lib__WEBPACK_IMPORTED_MODULE_3__=__webpack_require__(62);function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};return _extends.apply(this,arguments)}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}const getIndexPatterns=async(client,search,fields)=>{const resp=await client.find({type:"index-pattern",fields:fields,search:"".concat(search,"*"),searchFields:["title"],perPage:100});return resp.savedObjects};class IndexPatternSelect extends react__WEBPACK_IMPORTED_MODULE_1__["Component"]{constructor(props){var _this;super(props);_this=this;_defineProperty(this,"isMounted",false);_defineProperty(this,"state",void 0);_defineProperty(this,"fetchSelectedIndexPattern",async indexPatternId=>{if(!indexPatternId){this.setState({selectedIndexPattern:undefined});return}let indexPatternTitle;try{indexPatternTitle=await Object(_common_index_patterns_lib__WEBPACK_IMPORTED_MODULE_3__["g"])(this.props.savedObjectsClient,indexPatternId)}catch(err){return}if(!this.isMounted){return}this.setState({selectedIndexPattern:{value:indexPatternId,label:indexPatternTitle}})});_defineProperty(this,"debouncedFetch",lodash__WEBPACK_IMPORTED_MODULE_0___default.a.debounce(async searchValue=>{const{fieldTypes:fieldTypes,onNoIndexPatterns:onNoIndexPatterns,savedObjectsClient:savedObjectsClient}=this.props;const savedObjectFields=["title"];if(fieldTypes){savedObjectFields.push("fields")}let savedObjects=await getIndexPatterns(savedObjectsClient,searchValue,savedObjectFields);if(fieldTypes){savedObjects=savedObjects.filter(savedObject=>{try{const indexPatternFields=JSON.parse(savedObject.attributes.fields);return indexPatternFields.some(field=>fieldTypes===null||fieldTypes===void 0?void 0:fieldTypes.includes(field.type))}catch(err){return false}})}if(!this.isMounted){return}if(searchValue===this.state.searchValue){const options=savedObjects.map(indexPatternSavedObject=>({label:indexPatternSavedObject.attributes.title,value:indexPatternSavedObject.id}));this.setState({isLoading:false,options:options});if(onNoIndexPatterns&&searchValue===""&&options.length===0){onNoIndexPatterns()}}},300));_defineProperty(this,"fetchOptions",(function(){let searchValue=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"";_this.setState({isLoading:true,searchValue:searchValue},_this.debouncedFetch.bind(null,searchValue))}));_defineProperty(this,"onChange",selectedOptions=>{this.props.onChange(lodash__WEBPACK_IMPORTED_MODULE_0___default.a.get(selectedOptions,"0.value"))});this.state={isLoading:false,options:[],selectedIndexPattern:undefined,searchValue:undefined}}componentWillUnmount(){this.isMounted=false;this.debouncedFetch.cancel()}componentDidMount(){this.isMounted=true;this.fetchOptions();this.fetchSelectedIndexPattern(this.props.indexPatternId)}UNSAFE_componentWillReceiveProps(nextProps){if(nextProps.indexPatternId!==this.props.indexPatternId){this.fetchSelectedIndexPattern(nextProps.indexPatternId)}}render(){const{fieldTypes:fieldTypes,onChange:onChange,indexPatternId:indexPatternId,placeholder:placeholder,onNoIndexPatterns:onNoIndexPatterns,savedObjectsClient:savedObjectsClient,...rest}=this.props;return react__WEBPACK_IMPORTED_MODULE_1___default.a.createElement(_elastic_eui__WEBPACK_IMPORTED_MODULE_2__["EuiComboBox"],_extends({},rest,{placeholder:placeholder,singleSelection:true,isLoading:this.state.isLoading,onSearchChange:this.fetchOptions,options:this.state.options,selectedOptions:this.state.selectedIndexPattern?[this.state.selectedIndexPattern]:[],onChange:this.onChange}))}}}}]);