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] Add ML saved objects to Kibana saved objects management page #205177

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 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
@@ -0,0 +1,10 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export const ML_SAVED_OBJECT_TYPES = new Set(['ml-job', 'ml-trained-model']);
Copy link
Member

@jgowdyelastic jgowdyelastic Jan 10, 2025

Choose a reason for hiding this comment

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

I wonder if we should move the constants declared here to a package and also include this Set.

In this PR ml-job and ml-trained-model are used a few times and it would be safer if they all came from the same place.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage, FormattedRelative } from '@kbn/i18n-react';
import { SavedObjectsTaggingApi } from '@kbn/saved-objects-tagging-oss-plugin/public';
import { ML_SAVED_OBJECT_TYPES } from '../../../../common/constants/ml_saved_object_types';
import type { SavedObjectManagementTypeInfo } from '../../../../common/types';
import { getDefaultTitle, getSavedObjectLabel } from '../../../lib';
import { SavedObjectWithMetadata } from '../../../types';
Expand Down Expand Up @@ -328,6 +329,9 @@ export class Table extends PureComponent<TableProps, TableState> {
icon: 'kqlSelector',
onClick: (object) => onShowRelationships(object),
'data-test-subj': 'savedObjectsTableAction-relationships',
available: (object) => {
return object ? !object.type?.startsWith('ml') : true;
},
},
...actionRegistry.getAll().map((action) => {
action.setActionContext({ capabilities });
Expand Down Expand Up @@ -369,26 +373,64 @@ export class Table extends PureComponent<TableProps, TableState> {
);
}

const button = (
<EuiButton
iconType="arrowDown"
iconSide="right"
onClick={this.toggleExportPopoverVisibility}
isDisabled={selectedSavedObjects.length === 0}
>
<FormattedMessage
id="savedObjectsManagement.objectsTable.table.exportPopoverButtonLabel"
defaultMessage="Export"
/>
</EuiButton>
);

const activeActionContents = this.state.activeAction?.render() ?? null;
const exceededResultCount = totalItemCount > MAX_PAGINATED_ITEM;

const hasMlObjects = selectedSavedObjects.some(({ type }) => ML_SAVED_OBJECT_TYPES.has(type));

const anySelected = selectedSavedObjects.length > 0;
const allHidden =
anySelected && selectedSavedObjects.every(({ meta: { hiddenType } }) => hiddenType);

const deleteTooltip = () => {
Copy link
Member

Choose a reason for hiding this comment

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

There's a sneaky delete button at the top of the inspect saved object flyout.

image

if (hasMlObjects) {
return (
<FormattedMessage
id="savedObjectsManagement.objectsTable.table.hasMlObjects.deleteDisabledTooltip"
defaultMessage="Navigate to the Machine Learning management page to delete machine learning objects."
/>
);
}
if (allHidden) {
return (
<FormattedMessage
id="savedObjectsManagement.objectsTable.table.deleteDisabledTooltip"
defaultMessage="Selected objects can’t be deleted because they are hidden objects."
/>
);
}
};
const disabledExportTooltip = () => {
if (hasMlObjects) {
return (
<FormattedMessage
id="savedObjectsManagement.objectsTable.table.hasMlObjects.exportDisabledTooltip"
defaultMessage="Navigate to the Machine Learning management page to export machine learning objects."
peteharverson marked this conversation as resolved.
Show resolved Hide resolved
/>
);
}
};
const button = (
<EuiToolTip
data-test-subj="exportSOToolTip"
key="exportSOToolTip"
content={disabledExportTooltip()}
>
<EuiButton
iconType="arrowDown"
iconSide="right"
onClick={this.toggleExportPopoverVisibility}
isDisabled={selectedSavedObjects.length === 0}
disabled={hasMlObjects}
peteharverson marked this conversation as resolved.
Show resolved Hide resolved
>
<FormattedMessage
id="savedObjectsManagement.objectsTable.table.exportPopoverButtonLabel"
defaultMessage="Export"
/>
</EuiButton>
</EuiToolTip>
);

return (
<Fragment>
{activeActionContents}
Expand All @@ -406,22 +448,18 @@ export class Table extends PureComponent<TableProps, TableState> {
<EuiToolTip
data-test-subj="deleteSOToolTip"
key="deleteSOToolTip"
content={
allHidden ? (
<FormattedMessage
id="savedObjectsManagement.objectsTable.table.deleteDisabledTooltip"
defaultMessage="Selected objects can’t be deleted because they are hidden objects."
/>
) : undefined
}
content={deleteTooltip()}
>
<EuiButton
key="deleteSO"
iconType="trash"
color="danger"
onClick={onDelete}
isDisabled={
!anySelected || allHidden || !capabilities.savedObjectsManagement.delete
hasMlObjects ||
!anySelected ||
allHidden ||
!capabilities.savedObjectsManagement.delete
}
title={
capabilities.savedObjectsManagement.delete
Expand Down Expand Up @@ -468,7 +506,13 @@ export class Table extends PureComponent<TableProps, TableState> {
/>
</EuiFormRow>
<EuiFormRow>
<EuiButton key="exportSO" iconType="exportAction" onClick={this.onExportClick} fill>
<EuiButton
key="exportSO"
iconType="exportAction"
onClick={this.onExportClick}
fill
disabled={hasMlObjects}
>
<FormattedMessage
id="savedObjectsManagement.objectsTable.table.exportButtonLabel"
defaultMessage="Export"
Expand Down
Loading