From c9ddbb8abe8719a7502b25533a0b7939e9335745 Mon Sep 17 00:00:00 2001 From: "Christiane (Tina) Heiligers" Date: Thu, 12 Dec 2024 17:28:20 -0700 Subject: [PATCH 1/2] Disables delete only when no items are selected or when all selected items are hidden --- .../__snapshots__/table.test.tsx.snap | 2 ++ .../objects_table/components/table.test.tsx | 30 +++++++++++++++++-- .../objects_table/components/table.tsx | 11 +++++-- 3 files changed, 37 insertions(+), 6 deletions(-) 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..c87e62dfc9f64 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 @@ -39,6 +39,7 @@ exports[`Table prevents hidden saved objects from being deleted 1`] = ` id="savedObjectsManagement.objectsTable.table.deleteDisabledTooltip" /> } + data-test-subj="deleteSOToolTip" delay="regular" display="inlineBlock" position="top" @@ -267,6 +268,7 @@ exports[`Table should render normally 1`] = ` toolsRight={ Array [ { 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 From 3b3a263d77e1b32f177d88560819580cc6e9e6be Mon Sep 17 00:00:00 2001 From: "Christiane (Tina) Heiligers" Date: Fri, 13 Dec 2024 09:09:23 -0700 Subject: [PATCH 2/2] updates snapshots --- .../__snapshots__/table.test.tsx.snap | 235 ------------------ 1 file changed, 235 deletions(-) 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 c87e62dfc9f64..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,240 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Table prevents hidden saved objects from being deleted 1`] = ` - - - } - data-test-subj="deleteSOToolTip" - 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`] = `