"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MLCallout = MLCallout; exports.shouldDisplayMlCallout = shouldDisplayMlCallout; var _eui = require("@elastic/eui"); var _i18n = require("@kbn/i18n"); var _react = _interopRequireWildcard(require("react")); var _get_anomaly_detection_setup_state = require("../../../../common/anomaly_detection/get_anomaly_detection_setup_state"); var _use_ml_manage_jobs_href = require("../../../hooks/use_ml_manage_jobs_href"); var _apm_link = require("../links/apm/apm_link"); 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. */ function shouldDisplayMlCallout(anomalyDetectionSetupState) { return anomalyDetectionSetupState === _get_anomaly_detection_setup_state.AnomalyDetectionSetupState.NoJobs || anomalyDetectionSetupState === _get_anomaly_detection_setup_state.AnomalyDetectionSetupState.UpgradeableJobs || anomalyDetectionSetupState === _get_anomaly_detection_setup_state.AnomalyDetectionSetupState.LegacyJobs; } function MLCallout({ onDismiss, onUpgradeClick, onCreateJobClick, anomalyDetectionSetupState, isOnSettingsPage }) { const [loading, setLoading] = (0, _react.useState)(false); const mlManageJobsHref = (0, _use_ml_manage_jobs_href.useMlManageJobsHref)(); let properties; const getLearnMoreLink = color => /*#__PURE__*/_react.default.createElement(_eui.EuiButton, { "data-test-subj": "apmGetLearnMoreLinkButton", color: color }, /*#__PURE__*/_react.default.createElement(_apm_link.LegacyAPMLink, { path: "/settings/anomaly-detection", style: { whiteSpace: 'nowrap' }, color: color }, _i18n.i18n.translate('xpack.apm.mlCallout.learnMoreButton', { defaultMessage: `Learn more` }))); switch (anomalyDetectionSetupState) { case _get_anomaly_detection_setup_state.AnomalyDetectionSetupState.NoJobs: properties = { title: _i18n.i18n.translate('xpack.apm.mlCallout.noJobsCalloutTitle', { defaultMessage: 'Enable anomaly detection to add health status indicators to your services' }), text: _i18n.i18n.translate('xpack.apm.mlCallout.noJobsCalloutText', { defaultMessage: `Pinpoint anomalous transactions and see the health of upstream and downstream services with APM's anomaly detection integration. Get started in just a few minutes.` }), icon: 'iInCircle', color: 'primary', primaryAction: isOnSettingsPage ? /*#__PURE__*/_react.default.createElement(_eui.EuiButton, { "data-test-subj": "apmMLCalloutCreateMlJobButton", color: "primary", onClick: () => { onCreateJobClick === null || onCreateJobClick === void 0 ? void 0 : onCreateJobClick(); } }, _i18n.i18n.translate('xpack.apm.mlCallout.noJobsCalloutButtonText', { defaultMessage: 'Create ML Job' })) : getLearnMoreLink('primary') }; break; case _get_anomaly_detection_setup_state.AnomalyDetectionSetupState.UpgradeableJobs: properties = { title: _i18n.i18n.translate('xpack.apm.mlCallout.updateAvailableCalloutTitle', { defaultMessage: 'Updates available' }), text: _i18n.i18n.translate('xpack.apm.mlCallout.updateAvailableCalloutText', { defaultMessage: 'We have updated the anomaly detection jobs that provide insights into degraded performance and added detectors for throughput and failed transaction rate. If you choose to upgrade, we will create the new jobs and close the existing legacy jobs. The data shown in the APM app will automatically switch to the new. Please note that the option to migrate all existing jobs will not be available if you choose to create a new job.' }), color: 'success', icon: 'wrench', primaryAction: isOnSettingsPage ? /*#__PURE__*/_react.default.createElement(_eui.EuiButton, { "data-test-subj": "apmMLCalloutUpdateJobsButton", color: "success", isLoading: loading, onClick: () => { setLoading(true); Promise.resolve(onUpgradeClick === null || onUpgradeClick === void 0 ? void 0 : onUpgradeClick()).finally(() => { setLoading(false); }); } }, _i18n.i18n.translate('xpack.apm.mlCallout.updateAvailableCalloutButtonText', { defaultMessage: 'Update jobs' })) : getLearnMoreLink('success') }; break; case _get_anomaly_detection_setup_state.AnomalyDetectionSetupState.LegacyJobs: properties = { title: _i18n.i18n.translate('xpack.apm.mlCallout.legacyJobsCalloutTitle', { defaultMessage: 'Legacy ML jobs are no longer used in APM app' }), text: _i18n.i18n.translate('xpack.apm.mlCallout.legacyJobsCalloutText', { defaultMessage: 'We have discovered legacy Machine Learning jobs from our previous integration which are no longer being used in the APM app' }), icon: 'iInCircle', color: 'primary', primaryAction: /*#__PURE__*/_react.default.createElement(_eui.EuiButton, { "data-test-subj": "apmMLCalloutReviewJobsButton", href: mlManageJobsHref }, _i18n.i18n.translate('xpack.apm.settings.anomaly_detection.legacy_jobs.button', { defaultMessage: 'Review jobs' })) }; break; } if (!properties) { return null; } const dismissable = !isOnSettingsPage; const hasAnyActions = properties.primaryAction || dismissable; const actions = hasAnyActions ? /*#__PURE__*/_react.default.createElement(_eui.EuiFlexGroup, { gutterSize: "s", justifyContent: "spaceBetween" }, properties.primaryAction && /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, { grow: false }, properties.primaryAction), dismissable && /*#__PURE__*/_react.default.createElement(_eui.EuiFlexItem, { grow: false }, /*#__PURE__*/_react.default.createElement(_eui.EuiButtonEmpty, { "data-test-subj": "apmMLCalloutButton", onClick: onDismiss, color: properties.color }, _i18n.i18n.translate('xpack.apm.mlCallout.dismissButton', { defaultMessage: `Dismiss` })))) : null; return /*#__PURE__*/_react.default.createElement(_eui.EuiCallOut, { title: properties.title, iconType: properties.icon, color: properties.color }, /*#__PURE__*/_react.default.createElement("p", null, properties.text), actions); }