Skip to content

Commit

Permalink
[SecuritySolution] Hide create dashboard button from listing (elastic…
Browse files Browse the repository at this point in the history
…#164476)

## Summary

original issue: elastic#163459

**Before** - Two Create Dashboard buttons on Security Dashboard

![image](https://github.com/elastic/kibana/assets/59917825/d82e7056-0df3-44b1-abeb-10da67510247)

**After** - Create dashboard button from listing is removed.
<img width="2542" alt="Screenshot 2023-08-22 at 16 45 56"
src="https://github.com/elastic/kibana/assets/6295984/ff9bc785-de2a-40b7-b414-829c8913d997">

### Checklist

Delete any items that are not applicable to this PR.

- [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

(cherry picked from commit d63dd9d)
  • Loading branch information
angorayc committed Aug 29, 2023
1 parent 7e257d0 commit 82f0874
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const DashboardListingTable = ({
getDashboardUrl,
useSessionStorageIntegration,
urlStateEnabled,
showCreateDashboardButton = true,
}: DashboardListingProps) => {
const {
application,
Expand Down Expand Up @@ -61,6 +62,7 @@ export const DashboardListingTable = ({
urlStateEnabled,
useSessionStorageIntegration,
initialFilter,
showCreateDashboardButton,
});

const savedObjectsTaggingFakePlugin = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const useDashboardListingTable = ({
initialFilter,
urlStateEnabled,
useSessionStorageIntegration,
showCreateDashboardButton = true,
}: {
dashboardListingId?: string;
disableCreateDashboardButton?: boolean;
Expand All @@ -79,6 +80,7 @@ export const useDashboardListingTable = ({
initialFilter?: string;
urlStateEnabled?: boolean;
useSessionStorageIntegration?: boolean;
showCreateDashboardButton?: boolean;
}): UseDashboardListingTableReturnType => {
const {
dashboardSessionStorage,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -308,6 +310,7 @@ export const useDashboardListingTable = ({
initialPageSize,
listingLimit,
onFetchSuccess,
showCreateDashboardButton,
showWriteControls,
title,
updateItemMeta,
Expand Down
1 change: 1 addition & 0 deletions src/plugins/dashboard/public/dashboard_listing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const DashboardsLandingPage = () => {
goToDashboard={goToDashboard}
initialFilter={initialFilter}
urlStateEnabled={false}
showCreateDashboardButton={false}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {

await testSubjects.click('solutionSideNavItemLink-dashboards');

await dashboard.clickNewDashboard();
await testSubjects.click('createDashboardButton');

await lens.createAndAddLensFromDashboard({});

Expand Down

0 comments on commit 82f0874

Please sign in to comment.