Skip to content

Commit

Permalink
Update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Dec 30, 2024
1 parent 85b1e57 commit 349b842
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,30 @@ export class Table extends PureComponent<TableProps, TableState> {
const activeActionContents = this.state.activeAction?.render() ?? null;
const exceededResultCount = totalItemCount > MAX_PAGINATED_ITEM;

const hasMlObjects = selectedSavedObjects.some(({ type }) => type === 'ml-job');

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

const deleteTooltip = () => {
if (hasMlObjects) {
return (
<FormattedMessage
id="savedObjectsManagement.objectsTable.table.hasMlObjects.deleteDisabledTooltip"
defaultMessage="Machine learning objects can’t be deleted."
/>
);
}
if (allHidden) {
return (
<FormattedMessage
id="savedObjectsManagement.objectsTable.table.deleteDisabledTooltip"
defaultMessage="Selected objects can’t be deleted because they are hidden objects."
/>
);
}
};
return (
<Fragment>
{activeActionContents}
Expand All @@ -406,22 +427,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
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ import {
ExportModal,
} from './components';

// Saved objects for ML job are not importable/exportable because they are wrappers around ES objects
const DISABLED_TYPES_FOR_EXPORT = new Set(['ml-job']);

interface ExportAllOption {
id: string;
label: string;
disabled?: boolean;
}

export interface SavedObjectsTableProps {
Expand Down Expand Up @@ -168,6 +172,8 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb

const allowedTypes = this.props.allowedTypes.map((type) => type.name);

// @TODO: remove
console.log(`--@@allowedTypes`, allowedTypes);
const selectedTypes = allowedTypes.filter(
(type) => !visibleTypes || visibleTypes.includes(type)
);
Expand All @@ -186,18 +192,18 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
([id, count]) => ({
id,
label: `${id} (${count || 0})`,
disabled: DISABLED_TYPES_FOR_EXPORT.has(id),
})
);
const exportAllSelectedOptions: Record<string, boolean> = exportAllOptions.reduce(
(record, { id }) => {
return {
...record,
[id]: true,
[id]: DISABLED_TYPES_FOR_EXPORT.has(id) ? false : true,
};
},
{}
);

// Fetch all the saved objects that exist so we can accurately populate the counts within
// the table filter dropdown.
const savedObjectCounts = await getSavedObjectCounts({
Expand Down Expand Up @@ -420,7 +426,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
const { notifications, http, taggingApi, allowedTypes } = this.props;
const { queryText, selectedTags } = parseQuery(activeQuery, allowedTypes);
const exportTypes = Object.entries(exportAllSelectedOptions).reduce((accum, [id, selected]) => {
if (selected) {
if (selected && !DISABLED_TYPES_FOR_EXPORT.has(id)) {
accum.push(id);
}
return accum;
Expand Down

0 comments on commit 349b842

Please sign in to comment.