|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import { i18n } from '@kbn/i18n'; |
| 8 | +import { |
| 9 | + isRegressionAnalysis, |
| 10 | + isOutlierAnalysis, |
| 11 | + isClassificationAnalysis, |
| 12 | +} from '../../../../common/analytics'; |
| 13 | +import { |
| 14 | + DataFrameAnalyticsListRow, |
| 15 | + isDataFrameAnalyticsStopped, |
| 16 | + isDataFrameAnalyticsFailed, |
| 17 | + getDataFrameAnalyticsProgressPhase, |
| 18 | +} from '../analytics_list/common'; |
| 19 | + |
| 20 | +const unknownJobTypeMessage = i18n.translate( |
| 21 | + 'xpack.ml.dataframe.analyticsList.viewActionUnknownJobTypeToolTipContent', |
| 22 | + { |
| 23 | + defaultMessage: 'There is no results page available for this type of data frame analytics job.', |
| 24 | + } |
| 25 | +); |
| 26 | +const jobNotStartedMessage = i18n.translate( |
| 27 | + 'xpack.ml.dataframe.analyticsList.viewActionJobNotStartedToolTipContent', |
| 28 | + { |
| 29 | + defaultMessage: |
| 30 | + 'The data frame analytics job did not start. There is no results page available.', |
| 31 | + } |
| 32 | +); |
| 33 | +const jobNotFinishedMessage = i18n.translate( |
| 34 | + 'xpack.ml.dataframe.analyticsList.viewActionJobNotFinishedToolTipContent', |
| 35 | + { |
| 36 | + defaultMessage: |
| 37 | + 'The data frame analytics job is not finished. There is no results page available.', |
| 38 | + } |
| 39 | +); |
| 40 | +const jobFailedMessage = i18n.translate( |
| 41 | + 'xpack.ml.dataframe.analyticsList.viewActionJobFailedToolTipContent', |
| 42 | + { |
| 43 | + defaultMessage: 'The data frame analytics job failed. There is no results page available.', |
| 44 | + } |
| 45 | +); |
| 46 | + |
| 47 | +interface ViewLinkStatusReturn { |
| 48 | + disabled: boolean; |
| 49 | + tooltipContent?: string; |
| 50 | +} |
| 51 | + |
| 52 | +export function getViewLinkStatus(item: DataFrameAnalyticsListRow): ViewLinkStatusReturn { |
| 53 | + const viewLinkStatus: ViewLinkStatusReturn = { disabled: false }; |
| 54 | + |
| 55 | + const progressStats = getDataFrameAnalyticsProgressPhase(item.stats); |
| 56 | + const jobFailed = isDataFrameAnalyticsFailed(item.stats.state); |
| 57 | + const jobNotStarted = progressStats.currentPhase === 1 && progressStats.progress === 0; |
| 58 | + const jobFinished = |
| 59 | + isDataFrameAnalyticsStopped(item.stats.state) && |
| 60 | + progressStats.currentPhase === progressStats.totalPhases && |
| 61 | + progressStats.progress === 100; |
| 62 | + const isUnknownJobType = |
| 63 | + !isRegressionAnalysis(item.config.analysis) && |
| 64 | + !isOutlierAnalysis(item.config.analysis) && |
| 65 | + !isClassificationAnalysis(item.config.analysis); |
| 66 | + |
| 67 | + const disabled = !jobFinished || jobFailed || isUnknownJobType; |
| 68 | + |
| 69 | + if (disabled) { |
| 70 | + viewLinkStatus.disabled = true; |
| 71 | + if (isUnknownJobType) { |
| 72 | + viewLinkStatus.tooltipContent = unknownJobTypeMessage; |
| 73 | + } else if (jobFailed) { |
| 74 | + viewLinkStatus.tooltipContent = jobFailedMessage; |
| 75 | + } else if (jobNotStarted) { |
| 76 | + viewLinkStatus.tooltipContent = jobNotStartedMessage; |
| 77 | + } else if (!jobFinished) { |
| 78 | + viewLinkStatus.tooltipContent = jobNotFinishedMessage; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + return viewLinkStatus; |
| 83 | +} |
0 commit comments