Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SecuritySolution] Hide create dashboard button from listing #164476

Merged
merged 11 commits into from
Aug 29, 2023
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