Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Display link to create data view from error cases in data frame analytics results pages #143596

Merged
merged 5 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { LoadingPanel } from '../loading_panel';
import { FeatureImportanceSummaryPanelProps } from '../total_feature_importance_summary/feature_importance_summary';
import { useExplorationUrlState } from '../../hooks/use_exploration_url_state';
import { ExplorationQueryBarProps } from '../exploration_query_bar/exploration_query_bar';
import { IndexPatternPrompt } from '../index_pattern_prompt';

function getFilters(resultsField: string) {
return {
Expand Down Expand Up @@ -114,6 +115,9 @@ export const ExplorationPageWrapper: FC<Props> = ({
};

const resultsField = jobConfig?.dest.results_field ?? '';
const destIndex =
(Array.isArray(jobConfig?.dest.index) ? jobConfig?.dest.index[0] : jobConfig?.dest.index) ?? '';

const scatterplotFieldOptions = useScatterplotFieldOptions(
indexPattern,
jobConfig?.analyzed_fields?.includes,
Expand All @@ -131,7 +135,12 @@ export const ExplorationPageWrapper: FC<Props> = ({
color="danger"
iconType="cross"
>
<p>{indexPatternErrorMessage}</p>
<p>
{indexPatternErrorMessage}
{needsDestIndexPattern ? (
<IndexPatternPrompt destIndex={destIndex} color="text" />
) : null}
</p>
</EuiCallOut>
</EuiPanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { EuiLink, EuiText } from '@elastic/eui';
import { useMlKibana } from '../../../../../contexts/kibana';

interface Props {
destIndex: string;
color?: string;
destIndex?: string;
}

export const IndexPatternPrompt: FC<Props> = ({ destIndex }) => {
export const IndexPatternPrompt: FC<Props> = ({ destIndex, color }) => {
const {
services: {
http: { basePath },
Expand All @@ -30,20 +31,20 @@ export const IndexPatternPrompt: FC<Props> = ({ destIndex }) => {

return (
<>
<EuiText size="xs" color="warning">
<EuiText size="xs" color={color ?? 'warning'}>
<FormattedMessage
id="xpack.ml.dataframe.analytics.dataViewPromptMessage"
defaultMessage="No data view exists for index {destIndex}. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will leave an extra space before the period if the destIndex is undefined. "No data view exists for index ."

values={{
destIndex,
destIndex: destIndex ?? '',
}}
/>
{canCreateDataView === true ? (
<FormattedMessage
id="xpack.ml.dataframe.analytics.dataViewPromptLink"
defaultMessage="{linkToDataViewManagement} for {destIndex}."
defaultMessage="{linkToDataViewManagement}{destIndex}."
values={{
destIndex,
destIndex: destIndex ? ` for ${destIndex}` : '',
linkToDataViewManagement: (
<EuiLink
href={`${basePath.get()}/app/management/kibana/dataViews/create`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { getFeatureCount } from './common';
import { useOutlierData } from './use_outlier_data';
import { useExplorationUrlState } from '../../hooks/use_exploration_url_state';
import { ExplorationQueryBarProps } from '../exploration_query_bar/exploration_query_bar';
import { IndexPatternPrompt } from '../index_pattern_prompt';

export type TableItem = Record<string, any>;

Expand Down Expand Up @@ -90,6 +91,8 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =
jobConfig?.analyzed_fields?.excludes,
resultsField
);
const destIndex =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is used in several places in DFA like useResultsViewConfig or deleteAnalyticsAndDestIndex... Might be out of scope of this PR but it's better to have a utility function (e.g. getDestinationIndex) so future updates to the logic can be more consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added util function in c849b80

(Array.isArray(jobConfig?.dest.index) ? jobConfig?.dest.index[0] : jobConfig?.dest.index) ?? '';

if (indexPatternErrorMessage !== undefined) {
return (
Expand All @@ -101,7 +104,12 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =
color="danger"
iconType="cross"
>
<p>{indexPatternErrorMessage}</p>
<p>
{indexPatternErrorMessage}
{needsDestIndexPattern ? (
<IndexPatternPrompt destIndex={destIndex} color="text" />
) : null}
</p>
</EuiCallOut>
</EuiPanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* 2.0.
*/

import { EuiToolTip } from '@elastic/eui';
import { EuiToolTip, EuiLink, EuiText } from '@elastic/eui';
import React, { FC } from 'react';
import { cloneDeep, isEqual } from 'lodash';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { toMountPoint, wrapWithTheme } from '@kbn/kibana-react-plugin/public';
import { DeepReadonly } from '../../../../../../../common/types/common';
import { DataFrameAnalyticsConfig, isOutlierAnalysis } from '../../../../common';
import { isClassificationAnalysis, isRegressionAnalysis } from '../../../../common/analytics';
Expand Down Expand Up @@ -401,9 +403,15 @@ export const useNavigateToWizardWithClonedJob = () => {
services: {
notifications: { toasts },
data: { dataViews },
http: { basePath },
application: { capabilities },
theme,
},
} = useMlKibana();
const theme$ = theme.theme$;
const navigateToPath = useNavigateToPath();
const canCreateDataView =
capabilities.savedObjectsManagement.edit === true || capabilities.indexPatterns.save === true;

return async (item: Pick<DataFrameAnalyticsListRow, 'config' | 'stats'>) => {
const sourceIndex = Array.isArray(item.config.source.index)
Expand All @@ -416,13 +424,42 @@ export const useNavigateToWizardWithClonedJob = () => {
if (dv !== undefined) {
sourceIndexId = dv.id;
} else {
toasts.addDanger(
i18n.translate('xpack.ml.dataframe.analyticsList.noSourceDataViewForClone', {
defaultMessage:
'Unable to clone the analytics job. No data view exists for index {dataView}.',
values: { dataView: sourceIndex },
})
);
toasts.addDanger({
title: toMountPoint(
wrapWithTheme(
<>
<FormattedMessage
id="xpack.ml.dataframe.analyticsList.noSourceDataViewForClone"
defaultMessage="Unable to clone the analytics job. No data view exists for index {sourceIndex}."
values={{ sourceIndex }}
/>
{canCreateDataView ? (
<EuiText size="xs" color="text">
<FormattedMessage
id="xpack.ml.dataframe.analytics.cloneAction.dataViewPromptLink"
defaultMessage="{linkToDataViewManagement}"
values={{
linkToDataViewManagement: (
<EuiLink
href={`${basePath.get()}/app/management/kibana/dataViews/create`}
target="_blank"
>
<FormattedMessage
id="xpack.ml.dataframe.analytics.cloneAction.dataViewPromptLinkText"
defaultMessage="Create a data view for {sourceIndex}"
values={{ sourceIndex }}
/>
</EuiLink>
),
}}
/>
</EuiText>
) : null}
</>,
theme$
)
),
});
}
} catch (e) {
const error = extractErrorMessage(e);
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -19210,7 +19210,6 @@
"xpack.ml.dataframe.analyticsList.errorWithCheckingIfUserCanDeleteIndexNotificationErrorMessage": "Une erreur s'est produite lors de la vérification de la possibilité pour un utilisateur de supprimer {destinationIndex} : {error}",
"xpack.ml.dataframe.analyticsList.fetchSourceDataViewForCloneErrorMessage": "Une erreur s’est produite lors de la vérification de l’existence de la vue de données {dataView} : {error}",
"xpack.ml.dataframe.analyticsList.forceStopModalBody": "{analyticsId} est en état d'échec. Vous devez arrêter la tâche et corriger la défaillance.",
"xpack.ml.dataframe.analyticsList.noSourceDataViewForClone": "Impossible de cloner la tâche d'analyse. Il n’existe aucune vue de données pour l’index {dataView}.",
"xpack.ml.dataframe.analyticsList.progressOfPhase": "Progression de la phase {currentPhase} : {progress}%",
"xpack.ml.dataframe.analyticsList.rowCollapse": "Masquer les détails pour {analyticsId}",
"xpack.ml.dataframe.analyticsList.rowExpand": "Afficher les détails pour {analyticsId}",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -19191,7 +19191,6 @@
"xpack.ml.dataframe.analyticsList.errorWithCheckingIfUserCanDeleteIndexNotificationErrorMessage": "ユーザーが{destinationIndex}を削除できるかどうかを確認するときにエラーが発生しました。{error}",
"xpack.ml.dataframe.analyticsList.fetchSourceDataViewForCloneErrorMessage": "データビュー{dataView}が存在するかどうかを確認しているときにエラーが発生しました:{error}",
"xpack.ml.dataframe.analyticsList.forceStopModalBody": "{analyticsId}は失敗状態です。ジョブを停止して、エラーを修正する必要があります。",
"xpack.ml.dataframe.analyticsList.noSourceDataViewForClone": "分析ジョブを複製できません。インデックス{dataView}のデータビューは存在しません。",
"xpack.ml.dataframe.analyticsList.progressOfPhase": "フェーズ{currentPhase}の進捗:{progress}%",
"xpack.ml.dataframe.analyticsList.rowCollapse": "{analyticsId}の詳細を非表示",
"xpack.ml.dataframe.analyticsList.rowExpand": "{analyticsId}の詳細を表示",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -19217,7 +19217,6 @@
"xpack.ml.dataframe.analyticsList.errorWithCheckingIfUserCanDeleteIndexNotificationErrorMessage": "检查用户是否能够删除 {destinationIndex} 时发生错误:{error}",
"xpack.ml.dataframe.analyticsList.fetchSourceDataViewForCloneErrorMessage": "检查数据视图 {dataView} 是否存在时发生错误:{error}",
"xpack.ml.dataframe.analyticsList.forceStopModalBody": "{analyticsId} 处于失败状态。您必须停止该作业并修复失败问题。",
"xpack.ml.dataframe.analyticsList.noSourceDataViewForClone": "无法克隆分析作业。对于索引 {dataView},不存在数据视图。",
"xpack.ml.dataframe.analyticsList.progressOfPhase": "阶段 {currentPhase} 的进度:{progress}%",
"xpack.ml.dataframe.analyticsList.rowCollapse": "隐藏 {analyticsId} 的详情",
"xpack.ml.dataframe.analyticsList.rowExpand": "显示 {analyticsId} 的详情",
Expand Down