"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.AnomalyJobSelector = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireWildcard(require("react")); var _eui = require("@elastic/eui"); var _i18n = require("@kbn/i18n"); var _lodash = require("lodash"); var _anomaly_job_selector_empty_state = require("./anomaly_job_selector_empty_state"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /* * 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. */ class AnomalyJobSelector extends _react.Component { constructor(...args) { super(...args); (0, _defineProperty2.default)(this, "_isMounted", false); (0, _defineProperty2.default)(this, "state", {}); (0, _defineProperty2.default)(this, "onJobIdSelect", selectedOptions => { const jobId = selectedOptions[0].value; if (this._isMounted) { this.setState({ jobId }); this.props.onJobChange(jobId); } }); } async _loadJobs() { const jobIdList = await this.props.mlJobsService.jobIdsWithGeo(); const options = jobIdList.map(jobId => { return { label: jobId, value: jobId }; }); if (this._isMounted && !(0, _lodash.isEqual)(options, this.state.jobIdList)) { this.setState({ jobIdList: options }); } } componentDidUpdate(prevProps, prevState) { this._loadJobs(); } componentDidMount() { this._isMounted = true; this._loadJobs(); } componentWillUnmount() { this._isMounted = false; } render() { var _this$state$jobIdList, _this$state$jobIdList2; const supportedJobsExist = ((_this$state$jobIdList = this.state.jobIdList) === null || _this$state$jobIdList === void 0 ? void 0 : _this$state$jobIdList.length) && ((_this$state$jobIdList2 = this.state.jobIdList) === null || _this$state$jobIdList2 === void 0 ? void 0 : _this$state$jobIdList2.length) > 0; return supportedJobsExist || !this.props.jobsManagementPath ? /*#__PURE__*/_react.default.createElement(_eui.EuiFormRow, { label: _i18n.i18n.translate('xpack.ml.maps.jobIdLabel', { defaultMessage: 'Job ID' }), display: "columnCompressed" }, /*#__PURE__*/_react.default.createElement(_eui.EuiComboBox, { singleSelection: true, onChange: this.onJobIdSelect, options: this.state.jobIdList, selectedOptions: this.state.jobId ? [{ value: this.state.jobId, label: this.state.jobId }] : [] })) : /*#__PURE__*/_react.default.createElement(_anomaly_job_selector_empty_state.AnomalyJobSelectorEmptyState, { jobsManagementPath: this.props.jobsManagementPath, canCreateJobs: this.props.canCreateJobs }); } } exports.AnomalyJobSelector = AnomalyJobSelector;