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

# Backport

This will backport the following commits from `main` to `8.10`:
- [[SecuritySolution] Hide create dashboard button from listing
(#164476)](https://github.com/elastic/kibana/pull/164476)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Angela
Chuang","email":"6295984+angorayc@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-08-29T08:18:00Z","message":"[SecuritySolution]
Hide create dashboard button from listing (#164476)\n\n##
Summary\r\n\r\noriginal issue:
https://github.com/elastic/kibana/issues/163459\r\n\r\n\r\n**Before** -
Two Create Dashboard buttons on Security
Dashboard\r\n\r\n![image](d82e7056-0df3-44b1-abeb-10da67510247)\r\n\r\n\r\n**After**
- Create dashboard button from listing is removed.\r\n<img
width=\"2542\" alt=\"Screenshot 2023-08-22 at 16 45
56\"\r\nsrc=\"ff9bc785-de2a-40b7-b414-829c8913d997\">\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"d63dd9df2deebab9a4e425e8446ed3ffdc8eebb9","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Threat
Hunting","Team: SecuritySolution","Team:Threat
Hunting:Explore","Feature:Security
Dashboards","v8.10.0","v8.11.0"],"number":164476,"url":"https://github.com/elastic/kibana/pull/164476","mergeCommit":{"message":"[SecuritySolution]
Hide create dashboard button from listing (#164476)\n\n##
Summary\r\n\r\noriginal issue:
https://github.com/elastic/kibana/issues/163459\r\n\r\n\r\n**Before** -
Two Create Dashboard buttons on Security
Dashboard\r\n\r\n![image](d82e7056-0df3-44b1-abeb-10da67510247)\r\n\r\n\r\n**After**
- Create dashboard button from listing is removed.\r\n<img
width=\"2542\" alt=\"Screenshot 2023-08-22 at 16 45
56\"\r\nsrc=\"ff9bc785-de2a-40b7-b414-829c8913d997\">\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"d63dd9df2deebab9a4e425e8446ed3ffdc8eebb9"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164476","number":164476,"mergeCommit":{"message":"[SecuritySolution]
Hide create dashboard button from listing (#164476)\n\n##
Summary\r\n\r\noriginal issue:
https://github.com/elastic/kibana/issues/163459\r\n\r\n\r\n**Before** -
Two Create Dashboard buttons on Security
Dashboard\r\n\r\n![image](d82e7056-0df3-44b1-abeb-10da67510247)\r\n\r\n\r\n**After**
- Create dashboard button from listing is removed.\r\n<img
width=\"2542\" alt=\"Screenshot 2023-08-22 at 16 45
56\"\r\nsrc=\"ff9bc785-de2a-40b7-b414-829c8913d997\">\r\n\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"d63dd9df2deebab9a4e425e8446ed3ffdc8eebb9"}}]}]
BACKPORT-->

Co-authored-by: Angela Chuang <6295984+angorayc@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-08-29 05:43:35 -04:00 committed by GitHub
parent deff699e25
commit c76997894e
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({});