(window.savedObjectsFinder_bundle_jsonpfunction=window.savedObjectsFinder_bundle_jsonpfunction||[]).push([[1],{11:function(e,t,s){e.exports=s(4)(1465)},12:function(e,t,s){"use strict";s.r(t),s.d(t,"SavedObjectFinderUi",(function(){return saved_object_finder_SavedObjectFinderUi}));var i=s(11),n=s.n(i),a=s(8),o=s(2),d=s.n(o),r=s(9),l=s(1),c=s(10),p=s(0);class saved_object_finder_SavedObjectFinderUi extends d.a.Component{constructor(e){super(e),n()(this,"isComponentMounted",!1),n()(this,"debouncedFetch",Object(a.debounce)((async e=>{var t;const s=this.getSavedObjectMetaDataMap(),{contentClient:i,uiSettings:n}=this.props.services,{queryText:a,visibleTypes:o,selectedTags:d}=Object(r.parseQuery)(e,Object.values(s).map((e=>({name:e.type,namespaceType:"single",hidden:!1,displayName:e.name})))),l=null===(t=Object(r.getTagFindReferences)({selectedTags:d,taggingApi:this.props.services.savedObjectsTagging}))||void 0===t?void 0:t.map((({id:e,type:t})=>e)),c=null!=o?o:Object.keys(s),p=(await i.mSearch({contentTypes:c.map((e=>({contentTypeId:e}))),query:{text:a?`${a}*`:void 0,...null!=l&&l.length?{tags:{included:l}}:{},limit:n.get("savedObjects:listingLimit")}})).hits.map((e=>{const{attributes:{name:t,title:s}}=e,i="string"==typeof s?s:"",n=t||i;return{...e,version:e.version,title:i,name:n,simple:e}})).filter((e=>{const t=s[e.type];return!t.showSavedObject||t.showSavedObject(e.simple)}));this.isComponentMounted&&e.text===this.state.query.text&&this.setState({isFetchingItems:!1,items:p})}),300)),n()(this,"fetchItems",(()=>{this.setState({isFetchingItems:!0},this.debouncedFetch.bind(null,this.state.query))})),this.state={items:[],isFetchingItems:!1,query:l.Query.parse("")}}componentWillUnmount(){this.isComponentMounted=!1,this.debouncedFetch.cancel()}componentDidMount(){this.isComponentMounted=!0,this.fetchItems()}getSavedObjectMetaDataMap(){return this.props.savedObjectMetaData.reduce(((e,t)=>({...e,[t.type]:t})),{})}render(){var e,t;const{onChoose:s,savedObjectMetaData:i}=this.props,n=this.props.services.savedObjectsTagging,a=null==n?void 0:n.ui.getTableColumnDefinition(),o=a?{...a,sortable:e=>{var t;return"function"==typeof a.sortable&&null!==(t=a.sortable(e))&&void 0!==t?t:""},"data-test-subj":"savedObjectFinderTags"}:void 0,r=i.length>1?{field:"type",name:c.i18n.translate("savedObjectsFinder.typeName",{defaultMessage:"Type"}),width:"50px",align:"center",description:c.i18n.translate("savedObjectsFinder.typeDescription",{defaultMessage:"Type of the saved object"}),sortable:({type:e})=>{var t;const s=i.find((t=>t.type===e));return null!==(t=null==s?void 0:s.name)&&void 0!==t?t:""},"data-test-subj":"savedObjectFinderType",render:(e,t)=>{const s=i.find((e=>e.type===t.type)),n=(s||{getIconForSavedObject:()=>"document"}).getIconForSavedObject(t.simple);return Object(p.jsx)(l.EuiToolTip,{position:"top",content:s.name},Object(p.jsx)(l.EuiIcon,{"aria-label":s.name,type:n,size:"s","data-test-subj":"objectType"}))}}:void 0,u=[...r?[r]:[],{field:"title",name:c.i18n.translate("savedObjectsFinder.titleName",{defaultMessage:"Title"}),width:o?"55%":"100%",description:c.i18n.translate("savedObjectsFinder.titleDescription",{defaultMessage:"Title of the saved object"}),dataType:"string",sortable:({name:e})=>null==e?void 0:e.toLowerCase(),"data-test-subj":"savedObjectFinderTitle",render:(e,t)=>{const n=i.find((e=>e.type===t.type)),a=n.getTooltipForSavedObject?n.getTooltipForSavedObject(t.simple):`${t.name} (${n.name})`;return Object(p.jsx)(l.EuiLink,{onClick:s?()=>{s(t.id,t.type,a,t.simple)}:void 0,title:a,"data-test-subj":`savedObjectTitle${(t.title||"").split(" ").join("-")}`},t.name)}},...o?[o]:[]],b={initialPageSize:this.props.initialPageSize||this.props.fixedPageSize||10,pageSizeOptions:[5,10,15,25],showPerPageOptions:!this.props.fixedPageSize},h={sort:null!==(e=this.state.sort)&&void 0!==e?e:{field:null!==(t=this.state.query)&&void 0!==t&&t.text?"":"title",direction:"asc"}},j={type:"field_value_selection",field:"type",name:c.i18n.translate("savedObjectsFinder.filterButtonLabel",{defaultMessage:"Types"}),multiSelect:"or",options:this.props.savedObjectMetaData.map((e=>({value:e.type,name:e.name})))},m={onChange:({query:e})=>{this.setState({query:null!=e?e:l.Query.parse("")},this.fetchItems)},box:{incremental:!0,"data-test-subj":"savedObjectFinderSearchInput"},filters:this.props.showFilter?[...i.length>1?[j]:[],...n?[n.ui.getSearchBarFilter({useName:!0})]:[]]:void 0,toolsRight:this.props.children?Object(p.jsx)(d.a.Fragment,null,this.props.children):void 0,toolsLeft:this.props.leftChildren?Object(p.jsx)(d.a.Fragment,null,this.props.leftChildren):void 0};return Object(p.jsx)(l.EuiFlexGroup,{direction:"column"},this.props.helpText?Object(p.jsx)(l.EuiFlexItem,null,Object(p.jsx)(l.EuiText,{size:"s",color:"subdued"},this.props.helpText)):void 0,Object(p.jsx)(l.EuiFlexItem,null,Object(p.jsx)(l.EuiInMemoryTable,{loading:this.state.isFetchingItems,itemId:"id",items:this.state.items,columns:u,"data-test-subj":"savedObjectsFinderTable",message:this.props.noItemsMessage,search:m,pagination:b,sorting:h,onTableChange:({sort:e})=>{this.setState({sort:e})}})))}}t.default=saved_object_finder_SavedObjectFinderUi}}]);