Skip to content

Commit

Permalink
Disables delete only when no items are selected or when all selected …
Browse files Browse the repository at this point in the history
…items are hidden
  • Loading branch information
TinaHeiligers committed Dec 13, 2024
1 parent 08da946 commit c9ddbb8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.

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 @@ -113,7 +113,7 @@ describe('Table', () => {
expect(component.state().isSearchTextValid).toBe(true);
});

it(`prevents hidden saved objects from being deleted`, () => {
it(`prevents hidden saved objects from being deleted`, async () => {
const selectedSavedObjects = [
{ type: 'visualization', meta: { hiddenType: true } },
{ type: 'search', meta: { hiddenType: true } },
Expand All @@ -124,9 +124,33 @@ describe('Table', () => {
selectedSavedObjects,
capabilities: { savedObjectsManagement: { delete: false } } as any,
};
const component = shallowWithI18nProvider(<Table {...customizedProps} />);
render(
<I18nProvider>
<Table {...customizedProps} />
</I18nProvider>
);

expect(component).toMatchSnapshot();
await waitFor(() => {
expect(screen.getByTestId('savedObjectsManagementDelete')).toBeDisabled();
});
});

it(`disables delete when no objects are selected `, async () => {
const selectedSavedObjects = [] as any;
const customizedProps = {
...defaultProps,
selectedSavedObjects,
capabilities: { savedObjectsManagement: { delete: true } } as any,
};
render(
<I18nProvider>
<Table {...customizedProps} />
</I18nProvider>
);

await waitFor(() => {
expect(screen.getByTestId('savedObjectsManagementDelete')).toBeDisabled();
});
});

it(`allows for automatic refreshing after an action`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ export class Table extends PureComponent<TableProps, TableState> {
const activeActionContents = this.state.activeAction?.render() ?? null;
const exceededResultCount = totalItemCount > MAX_PAGINATED_ITEM;

const allHidden = selectedSavedObjects.every(({ meta: { hiddenType } }) => hiddenType);

const anySelected = selectedSavedObjects.length > 0;
const allHidden =
anySelected && selectedSavedObjects.every(({ meta: { hiddenType } }) => hiddenType);
return (
<Fragment>
{activeActionContents}
Expand All @@ -403,6 +404,8 @@ export class Table extends PureComponent<TableProps, TableState> {
defaultQuery={this.props.initialQuery}
toolsRight={[
<EuiToolTip
data-test-subj="deleteSOToolTip"
key="deleteSOToolTip"
content={
allHidden ? (
<FormattedMessage
Expand All @@ -417,7 +420,9 @@ export class Table extends PureComponent<TableProps, TableState> {
iconType="trash"
color="danger"
onClick={onDelete}
isDisabled={allHidden || !capabilities.savedObjectsManagement.delete}
isDisabled={
!anySelected || allHidden || !capabilities.savedObjectsManagement.delete
}
title={
capabilities.savedObjectsManagement.delete
? undefined
Expand Down

0 comments on commit c9ddbb8

Please sign in to comment.