/*! 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.ml_bundle_jsonpfunction=window.ml_bundle_jsonpfunction||[]).push([[17],{656:function(e,t,a){var s,n=n||function(e){"use strict";if("undefined"==typeof navigator||!/MSIE [1-9]\./.test(navigator.userAgent)){var t=e.document,a=function(){return e.URL||e.webkitURL||e},s=t.createElementNS("http://www.w3.org/1999/xhtml","a"),n="download"in s,o=e.webkitRequestFileSystem,l=e.requestFileSystem||o||e.mozRequestFileSystem,i=function(t){(e.setImmediate||e.setTimeout)((function(){throw t}),0)},r="application/octet-stream",c=0,d=function(t){var s=function(){"string"==typeof t?a().revokeObjectURL(t):t.remove()};e.chrome?s():setTimeout(s,500)},u=function(e,t,a){for(var s=(t=[].concat(t)).length;s--;){var n=e["on"+t[s]];if("function"==typeof n)try{n.call(e,a||e)}catch(e){i(e)}}},b=function(e){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob(["\ufeff",e],{type:e.type}):e},m=function(t,i,m){m||(t=b(t));var j,p,x,g=this,f=t.type,O=!1,y=function(){u(g,"writestart progress write writeend".split(" "))},h=function(){!O&&j||(j=a().createObjectURL(t)),p?p.location.href=j:null==e.open(j,"_blank")&&"undefined"!=typeof safari&&(e.location.href=j),g.readyState=g.DONE,y(),d(j)},E=function(e){return function(){if(g.readyState!==g.DONE)return e.apply(this,arguments)}},M={create:!0,exclusive:!1};if(g.readyState=g.INIT,i||(i="download"),n)return j=a().createObjectURL(t),s.href=j,s.download=i,void setTimeout((function(){var e,t;e=s,t=new MouseEvent("click"),e.dispatchEvent(t),y(),d(j),g.readyState=g.DONE}));e.chrome&&f&&f!==r&&(x=t.slice||t.webkitSlice,t=x.call(t,0,t.size,r),O=!0),o&&"download"!==i&&(i+=".download"),(f===r||o)&&(p=e),l?(c+=t.size,l(e.TEMPORARY,c,E((function(e){e.root.getDirectory("saved",M,E((function(e){var a=function(){e.getFile(i,M,E((function(e){e.createWriter(E((function(a){a.onwriteend=function(t){p.location.href=e.toURL(),g.readyState=g.DONE,u(g,"writeend",t),d(e)},a.onerror=function(){var e=a.error;e.code!==e.ABORT_ERR&&h()},"writestart progress write abort".split(" ").forEach((function(e){a["on"+e]=g["on"+e]})),a.write(t),g.abort=function(){a.abort(),g.readyState=g.DONE},g.readyState=g.WRITING})),h)})),h)};e.getFile(i,{create:!1},E((function(e){e.remove(),a()})),E((function(e){e.code===e.NOT_FOUND_ERR?a():h()})))})),h)})),h)):h()},j=m.prototype;return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(e,t,a){return a||(e=b(e)),navigator.msSaveOrOpenBlob(e,t||"download")}:(j.abort=function(){var e=this;e.readyState=e.DONE,u(e,"abort")},j.readyState=j.INIT=0,j.WRITING=1,j.DONE=2,j.error=j.onwritestart=j.onprogress=j.onwrite=j.onabort=j.onerror=j.onwriteend=null,function(e,t,a){return new m(e,t,a)})}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content); /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */e.exports?e.exports.saveAs=n:null!==a(657)&&null!=a(658)&&(void 0===(s=function(){return n}.apply(t,[]))||(e.exports=s))},657:function(e,t,a){e.exports=a(56)(1802)},658:function(e,t){(function(t){e.exports=t}).call(this,{})},97:function(e,t,a){"use strict";a.r(t),a.d(t,"mountApp",(function(){return fe}));var s=a(71),n=a.n(s),o=a(2),l=a.n(o),i=a(269),r=a(6),c=a(15),d=a(28),u=a(21),b=a(0),m=a(102),j=a(4);const p=()=>Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiPageContent_Deprecated,{verticalPosition:"center",horizontalPosition:"center",color:"danger","data-test-subj":"mlPageAccessDenied"},Object(j.jsx)(d.EuiEmptyPrompt,{iconType:"warning",title:Object(j.jsx)("h2",null,Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.management.jobsList.noPermissionToAccessLabel",defaultMessage:"Access denied"})),body:Object(j.jsx)("p",null,Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.management.jobsList.noGrantedPrivilegesDescription",defaultMessage:"You don’t have permission to manage Machine Learning jobs. Access to the plugin requires the Machine Learning feature to be visible in this space."}))}))),x=({basePath:e})=>Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiPageTemplate.EmptyPrompt,{title:Object(j.jsx)("h2",null,Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.management.jobsList.insufficientLicenseLabel",defaultMessage:"Machine learning is a subscription feature"})),"data-test-subj":"mlPageInsufficientLicense",body:Object(j.jsx)(d.EuiFlexGroup,{direction:"column"},Object(j.jsx)(d.EuiFlexItem,null,Object(j.jsx)(d.EuiText,{color:"subdued"},Object(j.jsx)("p",null,Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.management.jobsList.insufficientLicenseDescription",defaultMessage:"Select an option to unlock it."})))),Object(j.jsx)(d.EuiFlexItem,null,Object(j.jsx)(d.EuiFlexGroup,{justifyContent:"center"},Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(d.EuiButtonEmpty,{"data-test-subj":"license-prompt-upgrade",key:"upgrade-subscription-button",target:"_blank",href:"https://www.elastic.co/subscriptions"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.management.jobsList.insufficientLicenseDescription.SubscriptionLink",defaultMessage:"Upgrade your subscription"}))),Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(d.EuiButton,{fill:!0,"data-test-subj":"license-prompt-trial",key:"start-trial-button",target:"_blank",href:`${e.get()}/app/management/stack/license_management/home`},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.management.jobsList.insufficientLicenseDescription.startTrialLink",defaultMessage:"Start trial"}))))))}));var g=a(357),f=a(190),O=a(160),y=a.n(O),h=a(107),E=a(9);const M=({jobs:e,autoExpand:t=!1})=>0===e.length?null:Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiCallOut,{title:r.i18n.translate("xpack.ml.importExport.importFlyout.cannotImportJobCallout.title",{defaultMessage:"{num, plural, one {# job} other {# jobs}} cannot be imported",values:{num:e.length}}),color:"warning","data-test-subj":"mlJobMgmtImportJobsCannotBeImportedCallout"},t?Object(j.jsx)(I,{jobs:e}):Object(j.jsx)(d.EuiAccordion,{id:"advancedOptions",paddingSize:"s","aria-label":r.i18n.translate("xpack.ml.importExport.importFlyout.cannotImportJobCallout.jobListAria",{defaultMessage:"view jobs"}),buttonContent:Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.cannotImportJobCallout.jobListButton",defaultMessage:"View jobs"})},Object(j.jsx)(I,{jobs:e}))),Object(j.jsx)(d.EuiSpacer,{size:"m"})),I=({jobs:e})=>Object(j.jsx)(l.a.Fragment,null,e.length>0&&Object(j.jsx)(l.a.Fragment,null,e.map((({jobId:e,missingIndices:t,missingFilters:a})=>Object(j.jsx)(d.EuiText,{size:"s"},Object(j.jsx)("h5",null,e),t.length>0&&Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.cannotImportJobCallout.missingIndex",defaultMessage:"Missing index {num, plural, one {pattern} other {patterns}}: {indices}",values:{num:t.length,indices:t.join(",")}}),a.length>0&&Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.cannotImportJobCallout.missingFilters",defaultMessage:"Missing filter {num, plural, one {list} other {lists}}: {filters}",values:{num:a.length,filters:a.join(",")}})))))),F=()=>Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiSpacer,{size:"l"}),Object(j.jsx)(d.EuiCallOut,{title:r.i18n.translate("xpack.ml.importExport.importFlyout.cannotReadFileCallout.title",{defaultMessage:"File cannot be read"}),color:"warning"},Object(j.jsx)("div",{"data-test-subj":"mlJobMgmtImportJobsFileReadErrorCallout"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.cannotReadFileCallout.body",defaultMessage:"Please select a file contained Machine Learning jobs which have been exported from Kibana using the Export Jobs option"}))));var S=a(101);class JobImportService{_readFile(e){return new Promise(((t,a)=>{if(e&&e.size){const s=new FileReader;s.readAsText(e),s.onload=()=>{const e=s.result;if("string"==typeof e)try{const a=JSON.parse(e);t(a)}catch(e){a()}else a()}}else a()}))}async readJobConfigs(e){try{const a=await this._readFile(e),s=Array.isArray(a)?a:[a];if(t=s,Array.isArray(t)&&t.some((e=>e.job&&e.datafeed))){const e=s.map((e=>e.job.job_id));return{jobs:s,jobIds:e,jobType:"anomaly-detector"}}if(function(e){return Array.isArray(e)&&e.some((e=>e.dest&&e.analysis))}(s)){const e=s.map((e=>e.id));return{jobs:s,jobIds:e,jobType:"data-frame-analytics"}}return{jobs:[],jobIds:[],jobType:null}}catch(e){return{jobs:[],jobIds:[],jobType:null}}var t}renameAdJobs(e,t){return t.length!=t.length?t:t.map(((t,a)=>{const{jobId:s}=e[a];return t.job.job_id=s,t.datafeed.job_id=s,t.datafeed.datafeed_id=`datafeed-${s}`,t}))}renameDfaJobs(e,t){return t.length!=t.length?t:t.map(((t,a)=>{const{jobId:s,destIndex:n}=e[a];return t.id=s,void 0!==n&&(t.dest.index=n),t}))}async validateJobs(e,t,a,s){const n=new Set(await a()),o=new Set((await s()).map((e=>e.filter_id))),l=[],i=[];return("anomaly-detector"===t?e.map((e=>({jobId:e.job.job_id,indices:e.datafeed.indices,filters:v(e.job)}))):e.map((e=>({jobId:e.id,destIndex:e.dest.index,indices:Array.isArray(e.source.index)?e.source.index:[e.source.index]})))).forEach((({jobId:e,indices:a,filters:s=[],destIndex:r})=>{const c=a.filter((e=>!1===n.has(e))),d=s.filter((e=>!1===o.has(e)));0===c.length&&0===d.length?l.push({jobId:e,..."data-frame-analytics"===t?{destIndex:r}:{}}):i.push({jobId:e,missingIndices:c,missingFilters:d})})),{jobs:l,skippedJobs:i}}}function v(e){const t=new Set;return e.analysis_config.detectors.forEach((e=>{void 0!==e.custom_rules&&e.custom_rules.forEach((e=>{void 0!==e.scope&&Object.values(e.scope).forEach((e=>{t.add(e.filter_id)}))}))})),[...t]}var k=a(296),C=a(106),T=a(42);const w=r.i18n.translate("xpack.ml.importExport.importFlyout.validateJobId.jobNameEmpty",{defaultMessage:"Enter a valid job ID"}),_=r.i18n.translate("xpack.ml.importExport.importFlyout.validateJobId.jobNameAllowedCharacters",{defaultMessage:"Job ID can contain lowercase alphanumeric (a-z and 0-9), hyphens or underscores; must start and end with an alphanumeric character"}),J=r.i18n.translate("xpack.ml.importExport.importFlyout.validateJobId.jobIdInvalidMaxLengthErrorMessage",{defaultMessage:"Job ID must be no more than {maxLength, plural, one {# character} other {# characters}} long.",values:{maxLength:T.b}}),D=r.i18n.translate("xpack.ml.importExport.importFlyout.validateJobId.jobNameAlreadyExists",{defaultMessage:"Job ID already exists. A job ID cannot be the same as an existing job or group."}),A=r.i18n.translate("xpack.ml.importExport.importFlyout.validateDestIndex.destIndexEmpty",{defaultMessage:"Enter a valid destination index"}),B=r.i18n.translate("xpack.ml.importExport.importFlyout.validateDestIndex.destIndexInvalid",{defaultMessage:"Invalid destination index name."}),L=r.i18n.translate("xpack.ml.importExport.importFlyout.validateDestIndex.destIndexExists",{defaultMessage:"An index with this name already exists. Be aware that running this analytics job will modify this destination index."}),z=({isDisabled:e})=>{const{jobs:{bulkCreateJobs:t},dataFrameAnalytics:{createDataFrameAnalytics:a},filters:{filters:s}}=Object(E.c)(),{services:{data:{dataViews:{getTitles:n}},notifications:{toasts:i},mlServices:{mlUsageCollection:u}}}=Object(E.d)(),b=Object(o.useMemo)((()=>new JobImportService),[]),[m,p]=Object(o.useState)(!1),[x,g]=Object(o.useState)([]),[f,O]=Object(o.useState)([]),[I,v]=Object(o.useState)([]),[z,R]=Object(o.useState)([]),[N,W]=Object(o.useState)(!1),[U,G]=Object(o.useState)(null),[$,H]=Object(o.useState)(0),[q,Y]=Object(o.useState)(!0),[K,Q]=Object(o.useState)(!0),[X,Z]=Object(o.useState)(""),[ee,te]=Object(o.useState)(!1),[ae,se]=Object(o.useState)(!1),{displayErrorToast:ne,displaySuccessToast:oe}=Object(o.useMemo)((()=>Object(S.b)(i)),[i]),[le]=((e,t,a,s,n)=>{const{jobs:{jobsExist:l},dataFrameAnalytics:{jobsExist:i},checkIndicesExists:r}=Object(E.c)();return[Object(o.useCallback)((async()=>{const a=[],o=[],c="anomaly-detector"===e;if(t.filter((({jobIdValidated:e})=>!1===e)).forEach((e=>{e.jobIdValid=!0,e.jobIdInvalidMessage="",""===e.jobId?(e.jobIdValid=!1,e.jobIdInvalidMessage=w,e.jobIdValidated=c):e.jobId.length>T.b?(e.jobIdValid=!1,e.jobIdInvalidMessage=J,e.jobIdValidated=c):!1===Object(C.l)(e.jobId)&&(e.jobIdValid=!1,e.jobIdInvalidMessage=_,e.jobIdValidated=c),!0===e.jobIdValid&&a.push(e.jobId)})),"data-frame-analytics"===e&&t.filter((({destIndexValidated:e})=>!1===e)).forEach((e=>{void 0!==e.destIndex&&(e.destIndexValid=!0,e.destIndexInvalidMessage="",""===e.destIndex?(e.destIndexValid=!1,e.destIndexInvalidMessage=A,e.destIndexValidated=!0):!1===Object(k.a)(e.destIndex)&&(e.destIndexValid=!1,e.destIndexInvalidMessage=B,e.destIndexValidated=!0),!0===e.destIndexValid&&o.push(e.destIndex))})),null!==e){const c="anomaly-detector"===e?l:i,d=await c(a,!0);if(t.forEach((e=>{const t=d[e.jobId];if(t){const{exists:a}=t;e.jobIdValid=!a,e.jobIdInvalidMessage=a?D:"",e.jobIdValidated=!0}})),"data-frame-analytics"===e){const e=await r({indices:o});t.forEach((t=>{if(void 0!==t.destIndex&&!1===t.destIndexValidated){var a;const s=!0===(null===(a=e[t.destIndex])||void 0===a?void 0:a.exists);t.destIndexInvalidMessage=s?L:"",t.destIndexValidated=!0}}))}s([...t]),n(!1)}}),[a,t])]})(U,I,X,v,te);y()(le,400,[X]);const ie=Object(o.useCallback)(((e=!1)=>{g([]),O([]),v([]),Z(""),W(!1),G(null),H(0),te(!1),se(e)}),[]);Object(o.useEffect)((function(){ie()}),[m]);const re=Object(o.useCallback)((async e=>{if(se(!1),0!==e.length)try{const t=await b.readJobConfigs(e[0]);if(null===t.jobType)return void ie(!0);H(t.jobs.length);const a=await b.validateJobs(t.jobs,t.jobType,n,s);if("anomaly-detector"===t.jobType){const e=t.jobs.filter((e=>a.jobs.map((({jobId:e})=>e)).includes(e.job.job_id)));g(e)}else if("data-frame-analytics"===t.jobType){const e=t.jobs.filter((e=>a.jobs.map((({jobId:e})=>e)).includes(e.id)));O(e)}G(t.jobType),v(a.jobs.map((({jobId:e,destIndex:t})=>({jobId:e,originalId:e,jobIdValid:!0,jobIdInvalidMessage:"",jobIdValidated:!1,destIndex:t,originalDestIndex:t,destIndexValid:!0,destIndexInvalidMessage:"",destIndexValidated:!1}))));const o=P(a.jobs,t.jobType);Z(o),te(!0),R(a.skippedJobs)}catch(e){ne(e)}else ie()}),[]),ce=Object(o.useCallback)((async()=>{if(W(!0),"anomaly-detector"===U){const e=b.renameAdJobs(I,x);try{await de(e),u.count("imported_anomaly_detector_jobs",e.length)}catch(e){ne(e)}}else if("data-frame-analytics"===U){const e=b.renameDfaJobs(I,f);await ue(e),u.count("imported_data_frame_analytics_jobs",e.length)}W(!1),p(!1)}),[U,I,x,f]),de=Object(o.useCallback)((async e=>{const a=await t(e);let s=0;const n=[],o=new Set;Object.entries(a).forEach((([e,{job:t,datafeed:a}])=>{t.error||a.error?(o.add(e),t.error&&n.push(t.error),a.error&&n.push(a.error)):s++})),s>0&&be(s),n.length>0&&(me(n,o.size),u.count("import_failed_anomaly_detector_jobs",o.size))}),[]),ue=Object(o.useCallback)((async e=>{const t=[],s=await Promise.all(e.map((async({id:e,...s})=>{try{return await a(e,s)}catch(e){t.push(e)}}))),n=Object.values(s).filter((e=>void 0!==e)).length;n>0&&be(n),t.length>0&&(me(t,t.length),u.count("import_failed_data_frame_analytics_jobs",t.length))}),[]),be=Object(o.useCallback)((e=>{const t=r.i18n.translate("xpack.ml.importExport.importFlyout.importJobSuccessToast",{defaultMessage:"{count, plural, one {# job} other {# jobs}} successfully imported",values:{count:e}});oe(t)}),[]),me=Object(o.useCallback)(((e,t)=>{const a=r.i18n.translate("xpack.ml.importExport.importFlyout.importJobErrorToast",{defaultMessage:"{count, plural, one {# job} other {# jobs}} failed to import correctly",values:{count:t}}),s=e.map(h.c);ne(s,a)}),[]),je=Object(o.useCallback)((e=>{if("anomaly-detector"===U){const t=[...x];t.splice(e,1),g(t)}else if("data-frame-analytics"===U){const t=[...f];t.splice(e,1),O(t)}const t=[...I];t.splice(e,1),v(t);const a=P(t,U);Z(a),te(!0)}),[I,x,f]);Object(o.useEffect)((()=>{const e=0===I.length||!0===N||!0===ee||I.some((({jobIdValid:e,destIndexValid:t})=>!1===e||!1===t));Y(e),Q(!0===N||!0===ee)}),[I,X,ee,N]);const pe=Object(o.useCallback)(((e,t)=>{I[t].jobId=e,I[t].jobIdValid=!1,I[t].jobIdValidated=!1,v([...I]);const a=P(I,U);Z(a),te(!0)}),[I]),xe=Object(o.useCallback)(((e,t)=>{I[t].destIndex=e,I[t].destIndexValid=!1,I[t].destIndexValidated=!1,I[t].destIndexInvalidMessage="",v([...I]);const a=P(I,U);Z(a),te(!0)}),[I]),ge=({index:e})=>Object(j.jsx)(d.EuiButtonIcon,{iconType:"trash","aria-label":r.i18n.translate("xpack.ml.importExport.importFlyout.deleteButtonAria",{defaultMessage:"Delete"}),color:K?"text":"danger",disabled:K,onClick:()=>je(e)});return Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(V,{onClick:function(){p(!m)},isDisabled:e}),!0===m&&!1===e&&Object(j.jsx)(d.EuiFlyout,{onClose:p.bind(null,!1),hideCloseButton:!0,size:"m","data-test-subj":"mlJobMgmtImportJobsFlyout"},Object(j.jsx)(d.EuiFlyoutHeader,{hasBorder:!0},Object(j.jsx)(d.EuiTitle,{size:"m"},Object(j.jsx)("h2",null,Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.flyoutHeader",defaultMessage:"Import jobs"})))),Object(j.jsx)(d.EuiFlyoutBody,null,Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiText,{textAlign:"center"},Object(j.jsx)(d.EuiFilePicker,{disabled:N,fullWidth:!0,id:"filePicker",initialPromptText:r.i18n.translate("xpack.ml.importExport.importFlyout.fileSelect",{defaultMessage:"Select or drag and drop a file"}),onChange:re,className:"file-datavisualizer-file-picker"})),ae?Object(j.jsx)(F,null):null,$>0&&null!==U&&Object(j.jsx)("div",{"data-test-subj":"mlJobMgmtImportJobsFileRead"},Object(j.jsx)(d.EuiSpacer,{size:"l"}),"anomaly-detector"===U&&Object(j.jsx)("div",{"data-test-subj":"mlJobMgmtImportJobsADTitle"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.selectedFiles.ad",defaultMessage:"{num} anomaly detection {num, plural, one {job} other {jobs}} read from file",values:{num:$}})),"data-frame-analytics"===U&&Object(j.jsx)("div",{"data-test-subj":"mlJobMgmtImportJobsDFATitle"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.selectedFiles.dfa",defaultMessage:"{num} data frame analytics {num, plural, one {job} other {jobs}} read from file",values:{num:$}})),Object(j.jsx)(d.EuiSpacer,{size:"m"}),Object(j.jsx)(M,{jobs:z,autoExpand:0===I.length||1===z.length}),Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.importableFiles",defaultMessage:"Import {num, plural, one {# job} other {# jobs}}",values:{num:I.length}}),Object(j.jsx)(d.EuiSpacer,{size:"m"}),I.map(((e,t)=>Object(j.jsx)("div",{key:e.originalId},Object(j.jsx)(d.EuiPanel,{hasBorder:!0},Object(j.jsx)(d.EuiFlexGroup,null,Object(j.jsx)(d.EuiFlexItem,null,Object(j.jsx)(d.EuiFormRow,{error:e.jobIdInvalidMessage,isInvalid:!1===e.jobIdValid},Object(j.jsx)(d.EuiFieldText,{prepend:r.i18n.translate("xpack.ml.importExport.importFlyout.jobId",{defaultMessage:"Job ID"}),disabled:N,compressed:!0,value:e.jobId,onChange:e=>pe(e.target.value,t),isInvalid:!1===e.jobIdValid,"data-test-subj":"mlJobMgmtImportJobIdInput"})),"data-frame-analytics"===U&&Object(j.jsx)(d.EuiFormRow,{helpText:!0===e.destIndexValid?e.destIndexInvalidMessage:"",error:!1===e.destIndexValid?e.destIndexInvalidMessage:"",isInvalid:!1===e.destIndexValid},Object(j.jsx)(d.EuiFieldText,{prepend:r.i18n.translate("xpack.ml.importExport.importFlyout.destIndex",{defaultMessage:"Destination index"}),disabled:N,compressed:!0,value:e.destIndex,onChange:e=>xe(e.target.value,t),isInvalid:!1===e.destIndexValid}))),Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(ge,{index:t})))),Object(j.jsx)(d.EuiSpacer,{size:"m"}))))))),Object(j.jsx)(d.EuiFlyoutFooter,null,Object(j.jsx)(d.EuiFlexGroup,{justifyContent:"spaceBetween"},Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(d.EuiButtonEmpty,{iconType:"cross",onClick:p.bind(null,!1),flush:"left"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.closeButton",defaultMessage:"Close"}))),Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(d.EuiButton,{disabled:q,onClick:ce,fill:!0,"data-test-subj":"mlJobMgmtImportImportButton"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importFlyout.closeButton.importButton",defaultMessage:"Import"})))))))},V=({isDisabled:e,onClick:t})=>Object(j.jsx)(d.EuiButtonEmpty,{iconType:"importAction",onClick:t,isDisabled:e,"data-test-subj":"mlJobsImportButton"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.importButton",defaultMessage:"Import jobs"}));function P(e,t){return e.map((({jobId:e})=>e)).join("")+("data-frame-analytics"===t?e.map((({destIndex:e})=>e)).join(""):"")}const R=({jobs:e})=>{const[t,a,s]=function(e){return e.reduce(((e,t)=>{const a=t.calendarIds.length>0,s=t.filterIds.length>0;return(a||s)&&(e[0].push(t),a&&e[1].push(t),s&&e[2].push(t)),e}),[[],[],[]])}(e),n=a.length>0,o=s.length>0;return!1===n&&!1===o?null:Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiCallOut,{title:U(t,a.length,s.length),color:"warning"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.calendarDependencies",defaultMessage:"When you export jobs, calendars and filter lists are not included. You must create the filter lists before you import jobs; otherwise, the import fails. If you want the new jobs to continue to ignore scheduled events, you must create the calendars."}),Object(j.jsx)(d.EuiSpacer,null),n&&Object(j.jsx)(d.EuiAccordion,{id:"advancedOptions",paddingSize:"s","aria-label":r.i18n.translate("xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.jobUsingCalendarsAria",{defaultMessage:"Jobs using calendars"}),buttonContent:Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.jobUsingCalendarsButton",defaultMessage:"Jobs using calendars"})},Object(j.jsx)(N,{jobs:a})),o&&Object(j.jsx)(d.EuiAccordion,{id:"advancedOptions",paddingSize:"s","aria-label":r.i18n.translate("xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.jobUsingFiltersAria",{defaultMessage:"Jobs using filter lists"}),buttonContent:Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.jobUsingFiltersButton",defaultMessage:"Jobs using filter lists"})},Object(j.jsx)(W,{jobs:s}))),Object(j.jsx)(d.EuiSpacer,{size:"m"}))},N=({jobs:e})=>Object(j.jsx)(l.a.Fragment,null,e.length>0&&Object(j.jsx)(l.a.Fragment,null,e.map((({jobId:e,calendarIds:t})=>Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiText,{size:"s"},Object(j.jsx)("h5",null,e),t.length>0&&Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.calendarList",defaultMessage:"{num, plural, one {calendar} other {calendars}}: {calendars}",values:{num:t.length,calendars:t.join(", ")}})),Object(j.jsx)(d.EuiSpacer,{size:"s"})))))),W=({jobs:e})=>Object(j.jsx)(l.a.Fragment,null,e.length>0&&Object(j.jsx)(l.a.Fragment,null,e.map((({jobId:e,filterIds:t})=>Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiText,{size:"s"},Object(j.jsx)("h5",null,e),t.length>0&&Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.filterList",defaultMessage:"Filter {num, plural, one {list} other {lists}}: {filters}",values:{num:t.length,filters:t.join(", ")}})),Object(j.jsx)(d.EuiSpacer,{size:"s"}))))));function U(e,t,a){return t>0&&0===a?r.i18n.translate("xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.calendarOnlyTitle",{defaultMessage:"{jobCount, plural, one {# job uses} other {# jobs use}} {calendarCount, plural, one {a calendar} other {calendars}}",values:{jobCount:e.length,calendarCount:t}}):0===t&&a>0?r.i18n.translate("xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.filterOnlyTitle",{defaultMessage:"{jobCount, plural, one {# job uses} other {# jobs use}} {filterCount, plural, one {a filter list} other {filter lists}}",values:{jobCount:e.length,filterCount:a}}):r.i18n.translate("xpack.ml.importExport.exportFlyout.exportJobDependenciesWarningCallout.filterAndCalendarTitle",{defaultMessage:"{jobCount, plural, one {# job uses} other {# jobs use}} filter lists and calendars",values:{jobCount:e.length}})}var G=a(656),$=a(201);class jobs_export_service_JobsExportService{constructor(e){this._mlApiServices=e}async exportAnomalyDetectionJobs(e){const t=await Promise.all(e.map(this._mlApiServices.jobs.jobForCloning));this._export(t,"anomaly-detector")}async exportDataframeAnalyticsJobs(e){const{data_frame_analytics:t}=await this._mlApiServices.dataFrameAnalytics.getDataFrameAnalytics(e.join(","),!0);this._export(t,"data-frame-analytics")}_export(e,t){const a=1===e.length?e[0]:e,s=new Blob([JSON.stringify(a,null,2)],{type:"application/json"}),n=this._createFileName(t);Object(G.saveAs)(s,n)}_createFileName(e){return("anomaly-detector"===e?"anomaly_detection":"data_frame_analytics")+"_jobs.json"}async getJobDependencies(e){const t=await this._mlApiServices.calendars(),a=e.reduce(((e,t)=>(Array.isArray(t.groups)&&t.groups.forEach((a=>{void 0===e[a]&&(e[a]=[]),e[a].push(t.job_id)})),e)),{}),s=t.reduce(((t,s)=>(s.job_ids.forEach((n=>{n===$.a?e.forEach((e=>{void 0===t[e.job_id]&&(t[e.job_id]=[]),t[e.job_id].push(s.calendar_id)})):void 0!==a[n]?a[n].forEach((e=>{void 0===t[e]&&(t[e]=[]),t[e].push(s.calendar_id)})):(void 0===t[n]&&(t[n]=[]),t[n].push(s.calendar_id))})),t)),{}),n=e.reduce(((e,t)=>(void 0===e[t.job_id]&&(e[t.job_id]=[]),t.analysis_config.detectors.forEach((a=>{void 0!==a.custom_rules&&a.custom_rules.forEach((a=>{void 0!==a.scope&&Object.values(a.scope).forEach((a=>{e[t.job_id].push(a.filter_id)}))}))})),e)),{});return e.map((e=>{var t,a;const o=e.job_id;return{jobId:o,calendarIds:null!==(t=[...new Set(s[o])])&&void 0!==t?t:[],filterIds:null!==(a=[...new Set(n[o])])&&void 0!==a?a:[]}}))}}const H=({isDisabled:e,currentTab:t})=>{const a=Object(E.c)(),{getJobs:s,dataFrameAnalytics:{getDataFrameAnalytics:n}}=a,{services:{notifications:{toasts:i},mlServices:{mlUsageCollection:u}}}=Object(E.d)(),b=Object(o.useMemo)((()=>new jobs_export_service_JobsExportService(a)),[]),[m,p]=Object(o.useState)(!0),[x,g]=Object(o.useState)(!0),[f,O]=Object(o.useState)(!1),[y,h]=Object(o.useState)([]),[M,I]=Object(o.useState)([]),[F,v]=Object(o.useState)([]),[k,C]=Object(o.useState)(!1),[T,w]=Object(o.useState)(t),[_,J]=Object(o.useState)(!1),[D,A]=Object(o.useState)(t),{displayErrorToast:B,displaySuccessToast:L}=Object(o.useMemo)((()=>Object(S.b)(i)),[i]),[z,V]=Object(o.useState)([]),[P,N]=Object(o.useState)([]);function W(e,t){v(e?[...F,t]:F.filter((e=>e!==t)))}Object(o.useEffect)((function(){p(!0),g(!0),h([]),v([]),C(!1),w(t),J(!1),f&&(s().then((({jobs:e})=>{p(!1),h(e.map((e=>e.job_id))),b.getJobDependencies(e).then((e=>{V(e),p(!1)})).catch((e=>{const t=r.i18n.translate("xpack.ml.importExport.exportFlyout.calendarsError",{defaultMessage:"Could not load calendars"});B(e,t)}))})).catch((e=>{const t=r.i18n.translate("xpack.ml.importExport.exportFlyout.adJobsError",{defaultMessage:"Could not load anomaly detection jobs"});B(e,t)})),n().then((({data_frame_analytics:e})=>{g(!1),I(e.map((e=>e.id)))})).catch((e=>{const t=r.i18n.translate("xpack.ml.importExport.exportFlyout.dfaJobsError",{defaultMessage:"Could not load data frame analytics jobs"});B(e,t)})))}),[f]);const U=Object(o.useCallback)((e=>{if(e!==T)return F.length>0?(A(e),void J(!0)):void G(e)}),[F]);function G(e){J(!1),v([]),w(e)}function $(){const e="anomaly-detector"===T?y:M;F.length===e.length?v([]):v([...e])}return Object(o.useEffect)((()=>{N(z.filter((({jobId:e})=>F.includes(e))))}),[F]),Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(q,{onClick:function(){O(!f)},isDisabled:e}),!0===f&&!1===e&&Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiFlyout,{onClose:()=>O(!1),hideCloseButton:!0,size:"s","data-test-subj":"mlJobMgmtExportJobsFlyout"},Object(j.jsx)(d.EuiFlyoutHeader,{hasBorder:!0},Object(j.jsx)(d.EuiTitle,{size:"m"},Object(j.jsx)("h2",null,Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.flyoutHeader",defaultMessage:"Export jobs"})))),Object(j.jsx)(d.EuiFlyoutBody,null,Object(j.jsx)(R,{jobs:P}),Object(j.jsx)(d.EuiTabs,{size:"s"},Object(j.jsx)(d.EuiTab,{isSelected:"anomaly-detector"===T,onClick:()=>U("anomaly-detector"),disabled:k,"data-test-subj":"mlJobMgmtExportJobsADTab"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.adTab",defaultMessage:"Anomaly detection"})),Object(j.jsx)(d.EuiTab,{isSelected:"data-frame-analytics"===T,onClick:()=>U("data-frame-analytics"),disabled:k,"data-test-subj":"mlJobMgmtExportJobsDFATab"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.dfaTab",defaultMessage:"Analytics"}))),Object(j.jsx)(d.EuiSpacer,{size:"s"}),Object(j.jsx)(l.a.Fragment,null,"anomaly-detector"===T&&Object(j.jsx)(l.a.Fragment,null,!0===m?Object(j.jsx)(Y,null):Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiButtonEmpty,{size:"xs",onClick:$,isDisabled:e,"data-test-subj":"mlJobMgmtExportJobsSelectAllButton"},F.length===y.length?Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.adDeselectAllButton",defaultMessage:"Deselect all"}):Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.adSelectAllButton",defaultMessage:"Select all"})),Object(j.jsx)(d.EuiSpacer,{size:"xs"}),Object(j.jsx)("div",{"data-test-subj":"mlJobMgmtExportJobsADJobList"},y.map((e=>Object(j.jsx)("div",{key:e},Object(j.jsx)(d.EuiCheckbox,{id:e,label:e,checked:F.includes(e),onChange:t=>W(t.target.checked,e)}),Object(j.jsx)(d.EuiSpacer,{size:"s"}))))))),"data-frame-analytics"===T&&Object(j.jsx)(l.a.Fragment,null,!0===x?Object(j.jsx)(Y,null):Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiButtonEmpty,{size:"xs",onClick:$,isDisabled:e,"data-test-subj":"mlJobMgmtExportJobsSelectAllButton"},F.length===M.length?Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.dfaDeselectAllButton",defaultMessage:"Deselect all"}):Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.dfaSelectAllButton",defaultMessage:"Select all"})),Object(j.jsx)(d.EuiSpacer,{size:"xs"}),Object(j.jsx)("div",{"data-test-subj":"mlJobMgmtExportJobsDFAJobList"},M.map((e=>Object(j.jsx)("div",{key:e},Object(j.jsx)(d.EuiCheckbox,{id:e,label:e,checked:F.includes(e),onChange:t=>W(t.target.checked,e)}),Object(j.jsx)(d.EuiSpacer,{size:"s"}))))))))),Object(j.jsx)(d.EuiFlyoutFooter,null,Object(j.jsx)(d.EuiFlexGroup,{justifyContent:"spaceBetween"},Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(d.EuiButtonEmpty,{iconType:"cross",onClick:O.bind(null,!1),flush:"left"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.closeButton",defaultMessage:"Close"}))),Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(d.EuiButton,{disabled:0===F.length||!0===k,onClick:async function(){C(!0);const e=r.i18n.translate("xpack.ml.importExport.exportFlyout.exportDownloading",{defaultMessage:"Your file is downloading in the background"});L(e);try{"anomaly-detector"===T?await b.exportAnomalyDetectionJobs(F):await b.exportDataframeAnalyticsJobs(F),u.count("anomaly-detector"===T?"exported_anomaly_detector_jobs":"exported_data_frame_analytics_jobs",F.length),C(!1),O(!1)}catch(e){const t=r.i18n.translate("xpack.ml.importExport.exportFlyout.exportError",{defaultMessage:"Could not export selected jobs"});B(e,t),C(!1)}},fill:!0,"data-test-subj":"mlJobMgmtExportExportButton"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.exportButton",defaultMessage:"Export"})))))),!0===_?Object(j.jsx)(K,{onCancel:J.bind(null,!1),onConfirm:()=>G(D)}):null))},q=({isDisabled:e,onClick:t})=>Object(j.jsx)(d.EuiButtonEmpty,{iconType:"exportAction",onClick:t,isDisabled:e,"data-test-subj":"mlJobsExportButton"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportButton",defaultMessage:"Export jobs"})),Y=()=>Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiSpacer,{size:"l"}),Object(j.jsx)(d.EuiFlexGroup,{justifyContent:"spaceAround"},Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(d.EuiLoadingSpinner,{size:"l"})))),K=({onCancel:e,onConfirm:t})=>Object(j.jsx)(d.EuiConfirmModal,{title:r.i18n.translate("xpack.ml.importExport.exportFlyout.switchTabsConfirm.title",{defaultMessage:"Change tabs?"}),onCancel:e,onConfirm:t,cancelButtonText:r.i18n.translate("xpack.ml.importExport.exportFlyout.switchTabsConfirm.cancelButton",{defaultMessage:"Cancel"}),confirmButtonText:r.i18n.translate("xpack.ml.importExport.exportFlyout.switchTabsConfirm.confirmButton",{defaultMessage:"Confirm"}),defaultFocusedButton:"confirm"},Object(j.jsx)("p",null,Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.importExport.exportFlyout.switchTabsConfirm.text",defaultMessage:"Changing tabs will clear currently selected jobs"})));var Q=a(12),X=a(25);var Z=a(266),ee=a(286),te=a(267);function ae(e){switch(e){case"anomaly-detector":return se;case"data-frame-analytics":return ne;case"trained-model":return oe;default:return[]}}const se=[{field:"id",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.trainedModels.ad.id",{defaultMessage:"ID"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnId",scope:"row",width:"250px",render:e=>Object(j.jsx)(ee.a,{id:e})},{field:"description",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.trainedModels.ad.description",{defaultMessage:"Description"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnDescription"},{field:"jobState",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.trainedModels.ad.jobState",{defaultMessage:"Job state"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnJobState",width:"100px"},{field:"datafeedState",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.ad.datafeedState",{defaultMessage:"Datafeed state"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnDatafeedState",width:"150px"}],ne=[{field:"id",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.dfa.id",{defaultMessage:"ID"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnId",scope:"row",width:"250px",render:e=>Object(j.jsx)(te.a,{jobId:e})},{field:"description",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.dfa.description",{defaultMessage:"Description"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnDescription"},{field:"source_index",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.dfa.source_index",{defaultMessage:"Source index"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnSourceIndex",width:"200px"},{field:"dest_index",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.dfa.dest_index",{defaultMessage:"Destination index"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnDestIndex",width:"200px"},{field:"job_type",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.dfa.job_type",{defaultMessage:"Type"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnJobType",width:"150px"},{field:"state",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.dfa.state",{defaultMessage:"Status"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnState",width:"100px"}],oe=[{field:"id",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.trainedModels.id",{defaultMessage:"ID"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnId",scope:"row",width:"250px",render:e=>Object(j.jsx)(Z.c,{id:e})},{field:"description",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.trainedModels.description",{defaultMessage:"Description"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnDescription"},{field:"type",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.trainedModels.type",{defaultMessage:"Type"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnType",width:"250px"},{field:"state",name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.trainedModels.state",{defaultMessage:"State"}),sortable:!0,truncateText:!0,"data-test-subj":"mlSpaceManagementTableColumnState",width:"100px"}];var le=a(27);const ie=r.i18n.translate("xpack.ml.management.jobsSpacesList.jobObjectNoun",{defaultMessage:"job"}),re=r.i18n.translate("xpack.ml.management.jobsSpacesList.modelObjectNoun",{defaultMessage:"trained model"}),ce=({spacesApi:e,spaceIds:t,id:a,mlSavedObjectType:s,refresh:n})=>{const{savedObjects:{updateJobsSpaces:i,updateModelsSpaces:c}}=Object(E.c)(),{displayErrorToast:u}=Object(S.c)(),[b,m]=Object(o.useState)(!1);function p(){m(!1),n()}function x(e){Object.entries(e).forEach((([e,{success:t,error:a}])=>{if(!1===t){const t=r.i18n.translate("xpack.ml.management.jobsSpacesList.updateSpaces.error",{defaultMessage:"Error updating {id}",values:{id:e}});u(a,t)}}))}const g=Object(o.useCallback)(e.ui.components.getSpaceList,[e]),f=Object(o.useCallback)(e.ui.components.getShareToSpaceFlyout,[e]),O={savedObjectTarget:{type:le.a,id:a,namespaces:t,title:a,noun:"trained-model"===s?re:ie},behaviorContext:"outside-space",changeSpacesHandler:async function(e,t,n){const o=t.includes("*")?[]:n;(t.length||o.length)&&x("trained-model"===s?await c([a],t,o):await i(s,[a],t,o)),p()},onClose:p};return Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiButtonEmpty,{onClick:()=>m(!0),style:{height:"auto"},"data-test-subj":"mlJobListRowManageSpacesButton"},Object(j.jsx)(g,{namespaces:t,displayLimit:0,behaviorContext:"outside-space"})),b&&Object(j.jsx)(f,O))};function de(e,t){return t.map((([t,a])=>{const s=[...new Set(e.map((e=>e[t])).flat())].sort(((e,t)=>e.localeCompare(t))).map((e=>({value:e,name:e})));return{type:"field_value_selection",multiSelect:"or",field:t,name:a,options:s}}))}const ue=({spacesApi:e,setCurrentTab:t})=>{const{getList:a}=function(){const{services:{mlServices:{httpService:e}}}=Object(E.d)();return Object(o.useMemo)((()=>function(e){return{getList:t=>e.http({path:`${b.c}/management/list/${t}`,method:"GET",version:"1"})}}(e)),[e])}(),[s,n]=Object(o.useState)("anomaly-detector"),[i,c]=Object(o.useState)(),[u,m]=Object(o.useState)([]),[p,x]=Object(o.useState)(),[g,f]=Object(o.useState)(!1),{onTableChange:O,pagination:y,sorting:h,setPageIndex:M}=function(e,t,a="asc"){const[s,n]=Object(o.useState)(0),[l,i]=Object(o.useState)(10),[r,c]=Object(o.useState)(t),[d,u]=Object(o.useState)(a);return{onTableChange:({page:e={index:0,size:10},sort:t={field:r,direction:d}})=>{const{index:a,size:s}=e;n(a),i(s);const{field:o,direction:l}=t;c(o),u(l)},pagination:{pageIndex:s,pageSize:l,totalItemCount:(null!=e?e:[]).length,pageSizeOptions:[10,20,50],showPerPageOptions:!0},sorting:{sort:{field:r,direction:d}},setPageIndex:n}}(null!=i?i:[],"id"),I=Object(o.useRef)(!0);Object(o.useEffect)((()=>()=>{I.current=!1}),[]);const F=Object(o.useRef)(null),S=Object(o.useCallback)((e=>{F.current=e,f(!0),a(e).then((t=>{I.current&&e===F.current&&(c(t),f(!1),x(function(e,t){switch(e){case"anomaly-detector":return de(t,[["jobState",r.i18n.translate("xpack.ml.management.spaceManagementFilters.ad.jobState",{defaultMessage:"Job state"})],["datafeedState",r.i18n.translate("xpack.ml.management.spaceManagementFilters.ad.datafeedState",{defaultMessage:"Datafeed state"})]]);case"data-frame-analytics":return de(t,[["job_type",r.i18n.translate("xpack.ml.management.spaceManagementFilters.dfa.job_type",{defaultMessage:"Type"})],["state",r.i18n.translate("xpack.ml.management.spaceManagementFilters.dfa.state",{defaultMessage:"Status"})]]);case"trained-model":return de(t,[["type",r.i18n.translate("xpack.ml.management.spaceManagementFilters.trainedModels.type",{defaultMessage:"Type"})]]);default:return}}(e,t)))})).catch((()=>{I.current&&(c([]),x(void 0),f(!1))}))}),[a,F]);Object(o.useEffect)((function(){c(void 0),m(v()),t(s),S(s),M(0)}),[s]);const v=Object(o.useCallback)((()=>[...ae(s),...void 0!==e?[{name:r.i18n.translate("xpack.ml.management.spaceManagementTableColumn.spaces",{defaultMessage:"spaces"}),"data-test-subj":"mlSpaceManagementTableColumnSpaces",sortable:!0,truncateText:!0,align:"right",width:"10%",render:t=>{var a;return Object(j.jsx)(ce,{spacesApi:e,spaceIds:null!==(a=t.spaces)&&void 0!==a?a:[],id:t.id,mlSavedObjectType:s,refresh:S.bind(null,s)})}}]:[]]),[s,e,S]),k=Object(o.useCallback)((()=>Object(j.jsx)(l.a.Fragment,null,g?Object(j.jsx)(d.EuiProgress,{size:"xs",color:"accent"}):null,Object(j.jsx)(d.EuiSpacer,{size:"m"}),void 0===i?null:Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiFlexGroup,{justifyContent:"flexEnd",gutterSize:"none"},Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(be,{onRefreshClick:S.bind(null,s),isRefreshing:g}))),Object(j.jsx)(d.EuiInMemoryTable,{"data-test-subj":`mlSpacesManagementTable-${s} ${g?"loading":"loaded"}`,items:i,columns:u,search:{box:{incremental:!0},filters:p},onTableChange:O,pagination:y,sorting:h,rowProps:e=>({"data-test-subj":`mlSpacesManagementTable-${s} row-${e.id}`})})))),[i,u,g,p,s,S,O]),C=Object(o.useMemo)((()=>[{"data-test-subj":"mlStackManagementAnomalyDetectionTab",id:"anomaly-detector",name:r.i18n.translate("xpack.ml.management.list.anomalyDetectionTab",{defaultMessage:"Anomaly detection"}),content:k()},{"data-test-subj":"mlStackManagementAnalyticsTab",id:"data-frame-analytics",name:r.i18n.translate("xpack.ml.management.list.analyticsTab",{defaultMessage:"Analytics"}),content:k()},{"data-test-subj":"mlStackManagementTrainedModelsTab",id:"trained-model",name:r.i18n.translate("xpack.ml.management.list.trainedModelsTab",{defaultMessage:"Trained models"}),content:k()}]),[k]);return Object(j.jsx)(d.EuiTabbedContent,{"data-test-subj":"mlSpacesManagementTable",onTabClick:({id:e})=>{n(e)},size:"s",tabs:C,initialSelectedTab:C[0]})},be=({onRefreshClick:e,isRefreshing:t})=>Object(j.jsx)(d.EuiButtonEmpty,{"data-test-subj":"mlRefreshJobListButton"+(t?" loading":" loaded"),onClick:e,isLoading:t,iconType:"refresh",iconSide:"left",iconSize:"m"},Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.management.list.refreshButtonLabel",defaultMessage:"Refresh"})),me=({currentTabId:e})=>{const{services:{docLinks:{links:{ml:t}}}}=Object(E.d)();let a=t.anomalyDetectionJobs,s=r.i18n.translate("xpack.ml.management.jobsList.anomalyDetectionDocsLabel",{defaultMessage:"Anomaly detection jobs docs"});return"data-frame-analytics"===e?(a=t.dataFrameAnalytics,s=r.i18n.translate("xpack.ml.management.jobsList.analyticsDocsLabel",{defaultMessage:"Analytics jobs docs"})):"trained-model"===e&&(a=t.trainedModels,s=r.i18n.translate("xpack.ml.management.jobsList.trainedModelsDocsLabel",{defaultMessage:"Trained models docs"})),Object(j.jsx)(d.EuiButtonEmpty,{href:a,target:"_blank",iconType:"help","data-test-subj":"mlDocumentationLink"},s)},je=({children:e})=>Object(j.jsx)(l.a.Fragment,null,e),pe=({coreStart:e,share:t,history:a,spacesApi:s,data:n,usageCollection:O,fieldFormats:y})=>{const h=Object(o.useMemo)((()=>Object(Q.mlApiServicesProvider)(new X.a(e.http))),[e.http]),[E,M]=Object(o.useState)(!1),[I,F]=Object(o.useState)(!1),[S,v]=Object(o.useState)(!0),[k,C]=Object(o.useState)(!1),[T,w]=Object(o.useState)("anomaly-detector"),_=e.i18n.Context,J=e.theme.theme$,D=Object(o.useMemo)((()=>Object(f.getMlGlobalServices)(e.http,O)),[e.http,O]);Object(o.useEffect)((()=>{(async()=>{try{await Object(m.c)(h)}catch(e){e.mlFeatureEnabledInSpace&&!1===e.isPlatinumOrTrialLicense?v(!1):F(!0)}M(!0)})()}),[]);const A=Object(o.useCallback)(s?s.ui.components.getSpacesContextProvider:je,[s]);return!1===E?null:I?Object(j.jsx)(p,null):!1===S?Object(j.jsx)(x,{basePath:e.http.basePath}):Object(j.jsx)(u.RedirectAppLinks,{application:e.application},Object(j.jsx)(_,null,Object(j.jsx)(u.KibanaThemeProvider,{theme$:J},Object(j.jsx)(u.KibanaContextProvider,{services:{...e,share:t,data:n,usageCollection:O,fieldFormats:y,spacesApi:s,mlServices:D}},Object(j.jsx)(A,{feature:b.f},Object(j.jsx)(i.b,{history:a},Object(j.jsx)(d.EuiPageHeader,{pageTitle:Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.management.jobsList.jobsListTitle",defaultMessage:"Machine Learning"}),description:Object(j.jsx)(c.FormattedMessage,{id:"xpack.ml.management.jobsList.jobsListTagline",defaultMessage:"View, export, and import machine learning analytics and anomaly detection items."}),rightSideItems:[Object(j.jsx)(me,{currentTabId:T})],bottomBorder:!0}),Object(j.jsx)(d.EuiSpacer,{size:"l"}),Object(j.jsx)(d.EuiPageContentBody_Deprecated,{id:"kibanaManagementMLSection","data-test-subj":"mlPageStackManagementJobsList"},Object(j.jsx)(d.EuiFlexGroup,null,Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(l.a.Fragment,null,Object(j.jsx)(d.EuiButtonEmpty,{onClick:()=>C(!0),"data-test-subj":"mlStackMgmtSyncButton"},r.i18n.translate("xpack.ml.management.jobsList.syncFlyoutButton",{defaultMessage:"Synchronize saved objects"})),k&&Object(j.jsx)(g.a,{onClose:function(){C(!1)}}),Object(j.jsx)(d.EuiSpacer,{size:"s"}))),Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(H,{isDisabled:!1,currentTab:"trained-model"===T?"anomaly-detector":T})),Object(j.jsx)(d.EuiFlexItem,{grow:!1},Object(j.jsx)(z,{isDisabled:!1}))),Object(j.jsx)(ue,{spacesApi:s,setCurrentTab:w}))))))))},xe="/management/ml/jobs_list",ge=(e,t,a,o,i,r,c,d)=>(n.a.render(l.a.createElement(pe,{coreStart:a,history:t,share:o,data:i,spacesApi:c,usageCollection:d,fieldFormats:r}),e),()=>{Object(s.unmountComponentAtNode)(e)});async function fe(e,t,a){const[s,n]=await e.getStartServices();return t.setBreadcrumbs([{text:r.i18n.translate("xpack.ml.management.breadcrumb",{defaultMessage:"Machine Learning"}),href:`#${xe}`}]),ge(t.element,t.history,s,n.share,n.data,n.fieldFormats,n.spaces,a.usageCollection)}}}]);