diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap index bc0eda7e6d5a5..a3bcf4da52544 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap @@ -1,239 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Table prevents hidden saved objects from being deleted 1`] = ` - - - } - delay="regular" - display="inlineBlock" - position="top" - > - - - - , - - - - } - closePopover={[Function]} - display="inline-block" - hasArrow={true} - isOpen={false} - ownFocus={true} - panelPaddingSize="m" - repositionToCrossAxis={true} - > - - } - > - - } - name="includeReferencesDeep" - onChange={[Function]} - /> - - - - - - - , - ] - } - /> - -
- - } - onChange={[Function]} - pagination={ - Object { - "pageIndex": 1, - "pageSize": 2, - "pageSizeOptions": Array [ - 5, - 10, - 20, - 50, - ], - "totalItemCount": 3, - } - } - rowProps={[Function]} - selection={ - Object { - "onSelectionChange": [Function], - } - } - sorting={ - Object { - "sort": Object { - "direction": "desc", - "field": "updated_at", - }, - } - } - tableLayout="fixed" - /> -
-
-`; - exports[`Table should render normally 1`] = ` { 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 } }, @@ -124,9 +124,33 @@ describe('Table', () => { selectedSavedObjects, capabilities: { savedObjectsManagement: { delete: false } } as any, }; - const component = shallowWithI18nProvider(); + render( + +
+ + ); - 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( + +
+ + ); + + await waitFor(() => { + expect(screen.getByTestId('savedObjectsManagementDelete')).toBeDisabled(); + }); }); it(`allows for automatic refreshing after an action`, () => { diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx index a32a1e9e958e1..73e6e2978429b 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx @@ -386,8 +386,9 @@ export class Table extends PureComponent { 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 ( {activeActionContents} @@ -403,6 +404,8 @@ export class Table extends PureComponent { defaultQuery={this.props.initialQuery} toolsRight={[ { iconType="trash" color="danger" onClick={onDelete} - isDisabled={allHidden || !capabilities.savedObjectsManagement.delete} + isDisabled={ + !anySelected || allHidden || !capabilities.savedObjectsManagement.delete + } title={ capabilities.savedObjectsManagement.delete ? undefined