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

Fix delete disabled state #204154

Merged
Merged
Show file tree
Hide file tree
Changes from all 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

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();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Assert the button's disabled rather than relying on a snapshot, changes to which are easily overlooked (or "fixed" without inspection)

});
});

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={
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enables delete if some saved objects aren't hidden and delete is allowed

!anySelected || allHidden || !capabilities.savedObjectsManagement.delete
}
title={
capabilities.savedObjectsManagement.delete
? undefined
Expand Down
Loading