From a8c113a8c6ce2fedb6382de4972f6a6ad148efda Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 22 Aug 2023 16:55:27 +0100 Subject: [PATCH 1/5] Hide create dashboard button from listing --- .../dashboard_listing_table.tsx | 2 ++ .../hooks/use_dashboard_listing_table.test.tsx | 16 ++++++++++++++++ .../hooks/use_dashboard_listing_table.tsx | 5 ++++- .../dashboard/public/dashboard_listing/types.ts | 1 + .../dashboards/pages/landing_page/index.tsx | 1 + 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx b/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx index 196fd04cddf6c..2386b414c3209 100644 --- a/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx +++ b/src/plugins/dashboard/public/dashboard_listing/dashboard_listing_table.tsx @@ -34,6 +34,7 @@ export const DashboardListingTable = ({ getDashboardUrl, useSessionStorageIntegration, urlStateEnabled, + showCreateDashboardButton = true, }: DashboardListingProps) => { const { application, @@ -61,6 +62,7 @@ export const DashboardListingTable = ({ urlStateEnabled, useSessionStorageIntegration, initialFilter, + showCreateDashboardButton, }); const savedObjectsTaggingFakePlugin = useMemo( diff --git a/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.test.tsx b/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.test.tsx index 7716981e34942..602ac6a1f4a3c 100644 --- a/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.test.tsx +++ b/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.test.tsx @@ -105,6 +105,22 @@ describe('useDashboardListingTable', () => { expect(result.current.unsavedDashboardIds).toEqual([]); }); + test('should not render the create dashboard button when showCreateDashboardButton is false', () => { + const initialFilter = 'myFilter'; + const { result } = renderHook(() => + useDashboardListingTable({ + getDashboardUrl, + goToDashboard, + initialFilter, + urlStateEnabled: false, + showCreateDashboardButton: false, + }) + ); + + const tableListViewTableProps = result.current.tableListViewTableProps; + expect(tableListViewTableProps.createItem).toBeUndefined(); + }); + test('should return the correct tableListViewTableProps', () => { const initialFilter = 'myFilter'; const { result } = renderHook(() => diff --git a/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx b/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx index aefa45500b450..8f2fb7ac76cc9 100644 --- a/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx +++ b/src/plugins/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx @@ -70,6 +70,7 @@ export const useDashboardListingTable = ({ initialFilter, urlStateEnabled, useSessionStorageIntegration, + showCreateDashboardButton = true, }: { dashboardListingId?: string; disableCreateDashboardButton?: boolean; @@ -79,6 +80,7 @@ export const useDashboardListingTable = ({ initialFilter?: string; urlStateEnabled?: boolean; useSessionStorageIntegration?: boolean; + showCreateDashboardButton?: boolean; }): UseDashboardListingTableReturnType => { const { dashboardSessionStorage, @@ -274,7 +276,7 @@ export const useDashboardListingTable = ({ onSave: updateItemMeta, customValidators: contentEditorValidators, }, - createItem: !showWriteControls ? undefined : createItem, + createItem: !showWriteControls || !showCreateDashboardButton ? undefined : createItem, deleteItems: !showWriteControls ? undefined : deleteItems, editItem: !showWriteControls ? undefined : editItem, emptyPrompt, @@ -308,6 +310,7 @@ export const useDashboardListingTable = ({ initialPageSize, listingLimit, onFetchSuccess, + showCreateDashboardButton, showWriteControls, title, updateItemMeta, diff --git a/src/plugins/dashboard/public/dashboard_listing/types.ts b/src/plugins/dashboard/public/dashboard_listing/types.ts index c92344d4e778a..18767c1c75c32 100644 --- a/src/plugins/dashboard/public/dashboard_listing/types.ts +++ b/src/plugins/dashboard/public/dashboard_listing/types.ts @@ -17,6 +17,7 @@ export type DashboardListingProps = PropsWithChildren<{ goToDashboard: (dashboardId?: string, viewMode?: ViewMode) => void; getDashboardUrl: (dashboardId: string, usesTimeRestore: boolean) => string; urlStateEnabled?: boolean; + showCreateDashboardButton?: boolean; }>; // because the type of `application.capabilities.advancedSettings` is so generic, the provider diff --git a/x-pack/plugins/security_solution/public/dashboards/pages/landing_page/index.tsx b/x-pack/plugins/security_solution/public/dashboards/pages/landing_page/index.tsx index a843533400cf7..f2ac2520ecd8f 100644 --- a/x-pack/plugins/security_solution/public/dashboards/pages/landing_page/index.tsx +++ b/x-pack/plugins/security_solution/public/dashboards/pages/landing_page/index.tsx @@ -146,6 +146,7 @@ export const DashboardsLandingPage = () => { goToDashboard={goToDashboard} initialFilter={initialFilter} urlStateEnabled={false} + showCreateDashboardButton={false} /> ) : ( From 5569fbc179d8f6eb818a1fdae64bdb3352c34ad4 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 22 Aug 2023 20:53:57 +0100 Subject: [PATCH 2/5] tests --- test/functional/page_objects/dashboard_page.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/page_objects/dashboard_page.ts b/test/functional/page_objects/dashboard_page.ts index 897ceb5564d93..13de455aae95b 100644 --- a/test/functional/page_objects/dashboard_page.ts +++ b/test/functional/page_objects/dashboard_page.ts @@ -380,7 +380,7 @@ export class DashboardPageObject extends FtrService { } public async clickCreateDashboardPrompt() { - await this.testSubjects.click('newItemButton'); + await this.testSubjects.click('createDashboardButton'); } public async getCreateDashboardPromptExists() { From 2209d95f561de024f5c216b01e19ade9f9d21f20 Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Tue, 22 Aug 2023 21:53:54 +0100 Subject: [PATCH 3/5] tests --- test/functional/page_objects/dashboard_page.ts | 2 +- .../functional/test_suites/search/cases/attachment_framework.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/functional/page_objects/dashboard_page.ts b/test/functional/page_objects/dashboard_page.ts index 13de455aae95b..897ceb5564d93 100644 --- a/test/functional/page_objects/dashboard_page.ts +++ b/test/functional/page_objects/dashboard_page.ts @@ -380,7 +380,7 @@ export class DashboardPageObject extends FtrService { } public async clickCreateDashboardPrompt() { - await this.testSubjects.click('createDashboardButton'); + await this.testSubjects.click('newItemButton'); } public async getCreateDashboardPromptExists() { diff --git a/x-pack/test_serverless/functional/test_suites/search/cases/attachment_framework.ts b/x-pack/test_serverless/functional/test_suites/search/cases/attachment_framework.ts index 4f08611809886..2496dd4f07f34 100644 --- a/x-pack/test_serverless/functional/test_suites/search/cases/attachment_framework.ts +++ b/x-pack/test_serverless/functional/test_suites/search/cases/attachment_framework.ts @@ -28,6 +28,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { await svlCommonNavigation.sidenav.clickLink({ deepLinkId: 'dashboards' }); + await testSubjects.click('createDashboardButton'); await dashboard.clickNewDashboard(); await lens.createAndAddLensFromDashboard({}); From 1aa321a98442053c102abbd0991b2c7cdb99e46d Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 23 Aug 2023 11:25:30 +0100 Subject: [PATCH 4/5] tests --- .../functional/test_suites/search/cases/attachment_framework.ts | 1 - .../test_suites/security/ftr/cases/attachment_framework.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test_serverless/functional/test_suites/search/cases/attachment_framework.ts b/x-pack/test_serverless/functional/test_suites/search/cases/attachment_framework.ts index 2496dd4f07f34..4f08611809886 100644 --- a/x-pack/test_serverless/functional/test_suites/search/cases/attachment_framework.ts +++ b/x-pack/test_serverless/functional/test_suites/search/cases/attachment_framework.ts @@ -28,7 +28,6 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { await svlCommonNavigation.sidenav.clickLink({ deepLinkId: 'dashboards' }); - await testSubjects.click('createDashboardButton'); await dashboard.clickNewDashboard(); await lens.createAndAddLensFromDashboard({}); diff --git a/x-pack/test_serverless/functional/test_suites/security/ftr/cases/attachment_framework.ts b/x-pack/test_serverless/functional/test_suites/security/ftr/cases/attachment_framework.ts index a35787cff6aad..c5be8806a39f5 100644 --- a/x-pack/test_serverless/functional/test_suites/security/ftr/cases/attachment_framework.ts +++ b/x-pack/test_serverless/functional/test_suites/security/ftr/cases/attachment_framework.ts @@ -30,6 +30,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { await testSubjects.click('solutionSideNavItemLink-dashboards'); + await testSubjects.click('createDashboardButton'); await dashboard.clickNewDashboard(); await lens.createAndAddLensFromDashboard({}); From 666a85a3b901096b67196fba63a13c0ce843bf5e Mon Sep 17 00:00:00 2001 From: Angela Chuang Date: Wed, 23 Aug 2023 12:45:41 +0100 Subject: [PATCH 5/5] test --- .../test_suites/security/ftr/cases/attachment_framework.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/test_serverless/functional/test_suites/security/ftr/cases/attachment_framework.ts b/x-pack/test_serverless/functional/test_suites/security/ftr/cases/attachment_framework.ts index c5be8806a39f5..6b76503531d3c 100644 --- a/x-pack/test_serverless/functional/test_suites/security/ftr/cases/attachment_framework.ts +++ b/x-pack/test_serverless/functional/test_suites/security/ftr/cases/attachment_framework.ts @@ -31,7 +31,6 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { await testSubjects.click('solutionSideNavItemLink-dashboards'); await testSubjects.click('createDashboardButton'); - await dashboard.clickNewDashboard(); await lens.createAndAddLensFromDashboard({});