/*! 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.stackAlerts_bundle_jsonpfunction=window.stackAlerts_bundle_jsonpfunction||[]).push([[2],{27:function(e,t,n){"use strict";var i,a=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),o=[];function s(e){for(var t=-1,n=0;n{if(!e||0===e.length||!this.props.indexPatternService)return;let t;try{t=await this.props.indexPatternService.get(e)}catch(e){return}return this._isMounted&&t.id===e?(this.setState({doesIndexPatternHaveGeoField:t.fields.some((e=>this.props.includedGeoTypes.includes(e.type)))}),t):void 0})),f()(this,"_onIndexPatternSelect",(async e=>{const t=await this._loadIndexPattern(e);t&&this.props.onChange(t)})),f()(this,"_onNoIndexPatterns",(()=>{this.setState({noIndexPatternsExist:!0})}))}componentWillUnmount(){this._isMounted=!1}componentDidMount(){this._isMounted=!0,this.props.value&&this._loadIndexPattern(this.props.value)}_renderNoIndexPatternWarning(){return this.state.noIndexPatternsExist?Object(g.jsx)(a.a.Fragment,null,Object(g.jsx)(o.EuiCallOut,{title:r.i18n.translate("xpack.stackAlerts.geoContainment.noIndexPattern.messageTitle",{defaultMessage:"Couldn't find any data views"}),color:"warning"},Object(g.jsx)("p",null,Object(g.jsx)(s.FormattedMessage,{id:"xpack.stackAlerts.geoContainment.noIndexPattern.doThisPrefixDescription",defaultMessage:"You'll need to "}),Object(g.jsx)(o.EuiLink,{href:this.props.http.basePath.prepend("/app/management/kibana/dataViews")},Object(g.jsx)(s.FormattedMessage,{id:"xpack.stackAlerts.geoContainment.noIndexPattern.doThisLinkTextDescription",defaultMessage:"Create a data view."}))),Object(g.jsx)("p",null,Object(g.jsx)(s.FormattedMessage,{id:"xpack.stackAlerts.geoContainment.noIndexPattern.hintDescription",defaultMessage:"Don't have any data? "}),Object(g.jsx)(o.EuiLink,{href:this.props.http.basePath.prepend("/app/home#/tutorial_directory/sampleData")},Object(g.jsx)(s.FormattedMessage,{id:"xpack.stackAlerts.geoContainment.noIndexPattern.getStartedLinkText",defaultMessage:"Get started with some sample data sets."})))),Object(g.jsx)(o.EuiSpacer,{size:"s"})):null}render(){const e=this.props.IndexPatternSelectComponent,t=!!this.props.value&&!this.state.doesIndexPatternHaveGeoField,n=t?r.i18n.translate("xpack.stackAlerts.geoContainment.noGeoFieldInIndexPattern.message",{defaultMessage:"Data view does not contain any allowed geospatial fields. Must have one of type {geoFields}.",values:{geoFields:this.props.includedGeoTypes.join(", ")}}):"";return Object(g.jsx)(a.a.Fragment,null,this._renderNoIndexPatternWarning(),Object(g.jsx)(o.EuiFormRow,{label:r.i18n.translate("xpack.stackAlerts.geoContainment.indexPatternSelectLabel",{defaultMessage:"Data view"}),isInvalid:t,error:n},e?Object(g.jsx)(e,{isInvalid:t,isDisabled:this.state.noIndexPatternsExist,indexPatternId:this.props.value,onChange:this._onIndexPatternSelect,placeholder:r.i18n.translate("xpack.stackAlerts.geoContainment.indexPatternSelectPlaceholder",{defaultMessage:"Select data view"}),fieldTypes:this.props.includedGeoTypes,onNoIndexPatterns:this._onNoIndexPatterns,isClearable:!1}):Object(g.jsx)("div",null)))}}var h=n(5),m=n.n(h),j=n(30),y=n.n(j),k=n(20),F=n.n(k);const v={iconType:"questionInCircle",color:"gray"},O={binary:{iconType:"tokenBinary"},boolean:{iconType:"tokenBoolean"},conflict:{iconType:"warning",color:"euiColorVis9",shape:"square"},date:{iconType:"tokenDate"},date_range:{iconType:"tokenDate"},dense_vector:{iconType:"tokenDenseVector"},geo_point:{iconType:"tokenGeo"},geo_shape:{iconType:"tokenGeo"},ip:{iconType:"tokenIP"},ip_range:{iconType:"tokenIP"},flattened:{iconType:"tokenFlattened"},match_only_text:{iconType:"tokenString"},murmur3:{iconType:"tokenSearchType"},number:{iconType:"tokenNumber"},number_range:{iconType:"tokenNumber"},rank_feature:{iconType:"tokenRankFeature"},rank_features:{iconType:"tokenRankFeatures"},histogram:{iconType:"tokenHistogram"},_source:{iconType:"editorCodeBlock",color:"gray"},point:{iconType:"tokenShape"},shape:{iconType:"tokenShape"},string:{iconType:"tokenString"},text:{iconType:"tokenString"},keyword:{iconType:"tokenKeyword"},gauge:{iconType:"tokenMetricGauge"},counter:{iconType:"tokenMetricCounter"},nested:{iconType:"tokenNested"},version:{iconType:"tokenTag"}};function _({type:e,label:t,size:n="s",scripted:i,className:a,...s}){const r=O[e]||v;return Object(g.jsx)(o.EuiToken,y()({},r,{className:F()("kbnFieldIcon",a),"aria-label":t||e,title:t||e,size:n,fill:i?"dark":void 0},s))}n(34);function I(e){return e?e.map((e=>({value:e,label:e.name}))).sort(((e,t)=>e.label.toLowerCase().localeCompare(t.label.toLowerCase()))):[]}function S({placeholder:e,value:t,onChange:n,fields:i}){const a=[];if(t&&i){const e=i.find((e=>e.name===t));e&&a.push({value:e,label:t})}return Object(g.jsx)(o.EuiComboBox,{singleSelection:!0,options:I(i),selectedOptions:a,onChange:e=>{n(m.a.get(e,"0.value.name"))},isDisabled:!i,renderOption:function(e,t,n){return Object(g.jsx)(o.EuiFlexGroup,{className:n,gutterSize:"s",alignItems:"center"},Object(g.jsx)(o.EuiFlexItem,{grow:null},Object(g.jsx)(_,{type:e.value.type,fill:"none"})),Object(g.jsx)(o.EuiFlexItem,null,Object(g.jsx)(o.EuiHighlight,{search:t},e.label)))},isClearable:!1,placeholder:e,compressed:!0})}Object.keys({xs:"kbnFieldButton--xs",s:"kbnFieldButton--s"});const P=({popoverContent:e,expressionDescription:t,defaultValue:n,value:a,isInvalid:s})=>{const[l,d]=Object(i.useState)(!1);return Object(g.jsx)(o.EuiPopover,{id:"popoverForExpression",button:Object(g.jsx)(o.EuiExpression,{display:"columns","data-test-subj":"selectIndexExpression",description:t,value:a||n,isActive:l,onClick:()=>d(!0),isInvalid:s}),isOpen:l,closePopover:()=>d(!1),ownFocus:!0,anchorPosition:"downLeft",zIndex:8e3,display:"block"},Object(g.jsx)("div",{style:{width:"450px"}},Object(g.jsx)(o.EuiPopoverTitle,null,Object(g.jsx)(o.EuiFlexGroup,{alignItems:"center",gutterSize:"s"},Object(g.jsx)(o.EuiFlexItem,null,t),Object(g.jsx)(o.EuiFlexItem,{grow:!1},Object(g.jsx)(o.EuiButtonIcon,{"data-test-subj":"closePopover",iconType:"cross",color:"danger","aria-label":r.i18n.translate("xpack.stackAlerts.geoContainment.ui.expressionPopover.closePopoverLabel",{defaultMessage:"Close"}),onClick:()=>d(!1)})))),e))},C=({ruleParams:e,errors:t,boundaryIndexPattern:n,boundaryNameField:a,setBoundaryIndexPattern:s,setBoundaryGeoField:l,setBoundaryNameField:d,data:u,unifiedSearch:p})=>{const b=["string","number","ip"],{http:f}=Object(c.useKibana)().services,h=p.ui&&p.ui.IndexPatternSelect||null,{boundaryGeoField:m}=e,j={name:"",type:"string"},y=(e=>{const t=Object(i.useRef)();return Object(i.useEffect)((()=>{t.current=e})),t.current})(n),k=Object(i.useRef)({geoFields:[],boundaryNameFields:[]});Object(i.useEffect)((()=>{var e;y!==n&&(k.current.geoFields=n.fields&&n.fields.length&&n.fields.filter((e=>x.includes(e.type)))||[],k.current.geoFields.length&&l(k.current.geoFields[0].name),k.current.boundaryNameFields=[...(null!==(e=n.fields)&&void 0!==e?e:[]).filter((e=>b.includes(e.type)&&!e.name.startsWith("_")&&!e.name.endsWith("keyword"))),j],k.current.boundaryNameFields.length&&d(k.current.boundaryNameFields[0].name))}),[b,n,j,y,l,d]);const F=Object(g.jsx)(i.Fragment,null,Object(g.jsx)(o.EuiFormRow,{id:"geoIndexPatternSelect",fullWidth:!0,error:t.index},Object(g.jsx)(geo_index_pattern_select_GeoIndexPatternSelect,{onChange:e=>{e&&s(e)},value:n.id,IndexPatternSelectComponent:h,indexPatternService:u.indexPatterns,http:f,includedGeoTypes:x})),Object(g.jsx)(o.EuiFormRow,{id:"geoField",fullWidth:!0,label:r.i18n.translate("xpack.stackAlerts.geoContainment.geofieldLabel",{defaultMessage:"Geospatial field"})},Object(g.jsx)(S,{placeholder:r.i18n.translate("xpack.stackAlerts.geoContainment.selectLabel",{defaultMessage:"Select geo field"}),value:m,onChange:l,fields:k.current.geoFields})),Object(g.jsx)(o.EuiFormRow,{id:"boundaryNameFieldSelect",fullWidth:!0,label:r.i18n.translate("xpack.stackAlerts.geoContainment.boundaryNameSelectLabel",{defaultMessage:"Human-readable boundary name (optional)"})},Object(g.jsx)(S,{placeholder:r.i18n.translate("xpack.stackAlerts.geoContainment.boundaryNameSelect",{defaultMessage:"Select boundary name"}),value:a||null,onChange:e=>{d(e===j.name?void 0:e)},fields:k.current.boundaryNameFields})));return Object(g.jsx)(P,{defaultValue:"Select a data view and geo shape field",value:n.title,popoverContent:F,expressionDescription:r.i18n.translate("xpack.stackAlerts.geoContainment.indexLabel",{defaultMessage:"index"})})},w=["string","number","ip"],B=({errors:e,entity:t,setAlertParamsEntity:n,indexFields:a,isInvalid:s})=>{const l=(e=>{const t=Object(i.useRef)();return Object(i.useEffect)((()=>{t.current=e})),t.current})(a),d=Object(i.useRef)({indexFields:[]});Object(i.useEffect)((()=>{m.a.isEqual(l,a)||(d.current.indexFields=function(e){return e.filter((e=>{const t=w.includes(e.type),n=e.name.startsWith("_"),i=!!e.aggregatable;return t&&i&&!n}))}(a),!t&&d.current.indexFields.length&&n(d.current.indexFields[0].name))}),[a,l,n,t]);const c=Object(g.jsx)(o.EuiFormRow,{id:"entitySelect",fullWidth:!0,error:e.index},Object(g.jsx)(S,{placeholder:r.i18n.translate("xpack.stackAlerts.geoContainment.topHitsSplitFieldSelectPlaceholder",{defaultMessage:"Select entity field"}),value:t,onChange:e=>e&&n(e),fields:d.current.indexFields}));return Object(g.jsx)(P,{isInvalid:s,value:t,defaultValue:"Select entity field",popoverContent:c,expressionDescription:r.i18n.translate("xpack.stackAlerts.geoContainment.entityByLabel",{defaultMessage:"by"})})},E=({setAlertParamsDate:e,setAlertParamsGeoField:t,errors:n,setIndexPattern:a,indexPattern:l,isInvalid:d,dateField:u,geoField:x,data:b,unifiedSearch:f})=>{const{http:h}=Object(c.useKibana)().services,m=f.ui&&f.ui.IndexPatternSelect||null,j=(e=>{const t=Object(i.useRef)();return Object(i.useEffect)((()=>{t.current=e})),t.current})(l),y=Object(i.useRef)({dateFields:[],geoFields:[]});Object(i.useEffect)((()=>{j!==l&&(y.current.geoFields=l.fields&&l.fields.length&&l.fields.filter((e=>p.includes(e.type)))||[],y.current.geoFields.length&&t(y.current.geoFields[0].name),y.current.dateFields=l.fields&&l.fields.length&&l.fields.filter((e=>"date"===e.type))||[],y.current.dateFields.length&&e(y.current.dateFields[0].name))}),[l,j,e,t]);const k=Object(g.jsx)(i.Fragment,null,Object(g.jsx)(o.EuiFormRow,{id:"geoIndexPatternSelect",fullWidth:!0,error:n.index},Object(g.jsx)(geo_index_pattern_select_GeoIndexPatternSelect,{onChange:e=>{e&&a(e)},value:l.id,IndexPatternSelectComponent:m,indexPatternService:b.indexPatterns,http:h,includedGeoTypes:p})),Object(g.jsx)(o.EuiFormRow,{id:"containmentTimeField",fullWidth:!0,label:Object(g.jsx)(s.FormattedMessage,{id:"xpack.stackAlerts.geoContainment.timeFieldLabel",defaultMessage:"Time field"})},Object(g.jsx)(S,{placeholder:r.i18n.translate("xpack.stackAlerts.geoContainment.selectTimeLabel",{defaultMessage:"Select time field"}),value:u,onChange:t=>t&&e(t),fields:y.current.dateFields})),Object(g.jsx)(o.EuiFormRow,{id:"geoField",fullWidth:!0,label:r.i18n.translate("xpack.stackAlerts.geoContainment.geofieldLabel",{defaultMessage:"Geospatial field"})},Object(g.jsx)(S,{placeholder:r.i18n.translate("xpack.stackAlerts.geoContainment.selectGeoLabel",{defaultMessage:"Select geo field"}),value:x,onChange:e=>e&&t(e),fields:y.current.geoFields})));return Object(g.jsx)(P,{isInvalid:d,value:l.title,defaultValue:r.i18n.translate("xpack.stackAlerts.geoContainment.entityIndexSelect",{defaultMessage:"Select a data view and geo point field"}),popoverContent:k,expressionDescription:r.i18n.translate("xpack.stackAlerts.geoContainment.entityIndexLabel",{defaultMessage:"index"})})};function T(e){try{"kuery"===e.language?Object(l.fromKueryExpression)(e.query):Object(l.luceneStringToDsl)(e.query)}catch(e){return!1}return!0}const A=({ruleParams:e,ruleInterval:t,setRuleParams:n,setRuleProperty:a,errors:l,data:p,unifiedSearch:x})=>{const{index:b,indexId:f,indexQuery:h,geoField:m,entity:j,dateField:y,boundaryType:k,boundaryIndexTitle:F,boundaryIndexId:v,boundaryIndexQuery:O,boundaryGeoField:_,boundaryNameField:I}=e,{http:S,docLinks:P,uiSettings:w,notifications:A,storage:M,usageCollection:N,dataViews:G}=Object(c.useKibana)().services,[L,z]=Object(i.useState)({id:"",title:""}),R=e=>{e&&(z(e),e.title&&n("index",e.title),e.id&&n("indexId",e.id))},[D,H]=Object(i.useState)(h||{query:"",language:"kuery"}),[W,V]=Object(i.useState)({id:"",title:""}),q=e=>{e&&(V(e),e.title&&n("boundaryIndexTitle",e.title),e.id&&n("boundaryIndexId",e.id))},[Q,U]=Object(i.useState)(O||{query:"",language:"kuery"});return r.i18n.translate("xpack.stackAlerts.geoContainment.fixErrorInExpressionBelowValidationMessage",{defaultMessage:"Expression contains errors."}),Object(i.useEffect)((()=>{(async()=>{if(a("params",{...e,index:null!=b?b:"",indexId:null!=f?f:"",entity:null!=j?j:"",dateField:null!=y?y:"",boundaryType:null!=k?k:"entireIndex",geoField:null!=m?m:"",boundaryIndexTitle:null!=F?F:"",boundaryIndexId:null!=v?v:"",boundaryGeoField:null!=_?_:"",boundaryNameField:null!=I?I:""}),p.indexPatterns){if(f){const e=await p.indexPatterns.get(f);R(e)}if(v){const e=await p.indexPatterns.get(v);q(e)}}})()}),[]),Object(g.jsx)(i.Fragment,null,null,Object(g.jsx)(o.EuiSpacer,{size:"l"}),Object(g.jsx)(o.EuiTitle,{size:"xs"},Object(g.jsx)("h5",null,Object(g.jsx)(s.FormattedMessage,{id:"xpack.stackAlerts.geoContainment.selectEntity",defaultMessage:"Select entity"}))),Object(g.jsx)(o.EuiSpacer,{size:"s"}),Object(g.jsx)(E,{dateField:y,geoField:m,errors:l,setAlertParamsDate:e=>n("dateField",e),setAlertParamsGeoField:e=>n("geoField",e),setRuleProperty:a,setIndexPattern:R,indexPattern:L,isInvalid:!f||!y||!m,data:p,unifiedSearch:x}),Object(g.jsx)(B,{errors:l,entity:j,setAlertParamsEntity:e=>n("entity",e),indexFields:L.fields,isInvalid:!!(f&&y&&m)&&!j}),Object(g.jsx)(o.EuiSpacer,{size:"s"}),Object(g.jsx)(o.EuiFlexItem,null,Object(g.jsx)(d.QueryStringInput,{disableAutoFocus:!0,bubbleSubmitEvent:!0,indexPatterns:L?[L]:[],query:D,onChange:e=>{e.language&&(T(e)&&n("indexQuery",e),H(e))},appName:u.a,deps:{unifiedSearch:x,notifications:A,http:S,docLinks:P,uiSettings:w,data:p,dataViews:G,storage:M,usageCollection:N}})),Object(g.jsx)(o.EuiSpacer,{size:"l"}),Object(g.jsx)(o.EuiTitle,{size:"xs"},Object(g.jsx)("h5",null,Object(g.jsx)(s.FormattedMessage,{id:"xpack.stackAlerts.geoContainment.selectBoundaryIndex",defaultMessage:"Select boundary"}))),Object(g.jsx)(o.EuiSpacer,{size:"s"}),Object(g.jsx)(C,{ruleParams:e,errors:l,boundaryIndexPattern:W,setBoundaryIndexPattern:q,setBoundaryGeoField:e=>e&&n("boundaryGeoField",e),setBoundaryNameField:e=>n("boundaryNameField",e||""),boundaryNameField:I,data:p,unifiedSearch:x}),Object(g.jsx)(o.EuiSpacer,{size:"s"}),Object(g.jsx)(o.EuiFlexItem,null,Object(g.jsx)(d.QueryStringInput,{disableAutoFocus:!0,bubbleSubmitEvent:!0,indexPatterns:W?[W]:[],query:Q,onChange:e=>{e.language&&(T(e)&&n("boundaryIndexQuery",e),U(e))},appName:u.a,deps:{unifiedSearch:x,notifications:A,http:S,docLinks:P,uiSettings:w,data:p,dataViews:G,storage:M,usageCollection:N}})),Object(g.jsx)(o.EuiSpacer,{size:"l"}))}}}]);