Skip to content

Commit

Permalink
Fix delete disabled state (elastic#204154)
Browse files Browse the repository at this point in the history
fix elastic#204095

Disables delete when no saved objects are selected or all objects
selected are hidden and delete is allowed.

![Screenshot 2024-12-12 at 18 02
10](https://github.com/user-attachments/assets/e894a087-7906-4905-bd2e-2325a90d37c0)


## Summary

Summarize your PR. If it involves visual changes include a screenshot or
gif.

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
TinaHeiligers authored Dec 13, 2024
1 parent f0d3a44 commit 4ee5222
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 240 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 4ee5222

Please sign in to comment.