[SecuritySolution] Hide create dashboard button from listing (#164476)

## Summary

original issue: https://github.com/elastic/kibana/issues/163459


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

![image](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="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
This commit is contained in:
Angela Chuang 2023-08-29 09:18:00 +01:00 committed by GitHub
parent aa27425663
commit d63dd9df2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 2 deletions

View file

@ -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(

View file

@ -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(() =>

View file

@ -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,

View file

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

View file

@ -146,6 +146,7 @@ export const DashboardsLandingPage = () => {
goToDashboard={goToDashboard}
initialFilter={initialFilter}
urlStateEnabled={false}
showCreateDashboardButton={false}
/>
</>
)}

View file

@ -30,7 +30,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
await testSubjects.click('solutionSideNavItemLink-dashboards');
await dashboard.clickNewDashboard();
await testSubjects.click('createDashboardButton');
await lens.createAndAddLensFromDashboard({});