From bb4099f086a69d3acce925a279ec30f636c9ec70 Mon Sep 17 00:00:00 2001 From: Maja Grubic Date: Tue, 7 Jan 2020 14:41:02 +0000 Subject: [PATCH] [Dashboard] Redesign empty screen in readonly mode (#54073) * [Dashboard] Make empty screen nicer in readonly mode * Adding contact-the-owner part * Updating text --- .../dashboard_empty_screen.test.tsx.snap | 362 ++++++++++++++++++ .../__tests__/dashboard_empty_screen.test.tsx | 16 +- .../np_ready/dashboard_app_controller.tsx | 24 +- .../np_ready/dashboard_empty_screen.tsx | 58 ++- .../dashboard_empty_screen_constants.tsx | 10 + 5 files changed, 443 insertions(+), 27 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/__snapshots__/dashboard_empty_screen.test.tsx.snap b/src/legacy/core_plugins/kibana/public/dashboard/__tests__/__snapshots__/dashboard_empty_screen.test.tsx.snap index f611ec978b6b36..f7fc3b0891feff 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/__tests__/__snapshots__/dashboard_empty_screen.test.tsx.snap +++ b/src/legacy/core_plugins/kibana/public/dashboard/__tests__/__snapshots__/dashboard_empty_screen.test.tsx.snap @@ -1,5 +1,367 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`DashboardEmptyScreen renders correctly with readonly mode 1`] = ` + + + + + +
+ +
+ + +
+ +
+ +
+
+ +
+

+ This dashboard is empty. +

+
+
+ +
+ +
+ You need additional privileges to edit this dashboard. +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+`; + exports[`DashboardEmptyScreen renders correctly with visualize paragraph 1`] = ` { function mountComponent(props?: DashboardEmptyScreenProps) { const compProps = props || defaultProps; - const comp = mountWithIntl(); - return comp; + return mountWithIntl(); } test('renders correctly with visualize paragraph', () => { @@ -52,8 +51,10 @@ describe('DashboardEmptyScreen', () => { test('renders correctly without visualize paragraph', () => { const component = mountComponent({ ...defaultProps, ...{ showLinkToVisualize: false } }); expect(component).toMatchSnapshot(); - const paragraph = findTestSubject(component, 'linkToVisualizeParagraph'); - expect(paragraph.length).toBe(0); + const linkToVisualizeParagraph = findTestSubject(component, 'linkToVisualizeParagraph'); + expect(linkToVisualizeParagraph.length).toBe(0); + const enterEditModeParagraph = component.find('.dshStartScreen__panelDesc'); + expect(enterEditModeParagraph.length).toBe(1); }); test('when specified, prop onVisualizeClick is called correctly', () => { @@ -66,4 +67,11 @@ describe('DashboardEmptyScreen', () => { button.simulate('click'); expect(onVisualizeClick).toHaveBeenCalled(); }); + + test('renders correctly with readonly mode', () => { + const component = mountComponent({ ...defaultProps, ...{ isReadonlyMode: true } }); + expect(component).toMatchSnapshot(); + const paragraph = component.find('.dshStartScreen__panelDesc'); + expect(paragraph.length).toBe(0); + }); }); diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx index 8fcc7e4c263210..2523d1e60a7412 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx @@ -161,6 +161,12 @@ export class DashboardAppController { dashboardStateManager.getIsViewMode() && !dashboardConfig.getHideWriteControls(); + const getIsEmptyInReadonlyMode = () => + !dashboardStateManager.getPanels().length && + !getShouldShowEditHelp() && + !getShouldShowViewHelp() && + dashboardConfig.getHideWriteControls(); + const addVisualization = () => { navActions[TopNavIds.VISUALIZE](); }; @@ -193,7 +199,10 @@ export class DashboardAppController { } }; - const getEmptyScreenProps = (shouldShowEditHelp: boolean): DashboardEmptyScreenProps => { + const getEmptyScreenProps = ( + shouldShowEditHelp: boolean, + isEmptyInReadOnlyMode: boolean + ): DashboardEmptyScreenProps => { const emptyScreenProps: DashboardEmptyScreenProps = { onLinkClick: shouldShowEditHelp ? $scope.showAddPanel : $scope.enterEditMode, showLinkToVisualize: shouldShowEditHelp, @@ -203,6 +212,9 @@ export class DashboardAppController { if (shouldShowEditHelp) { emptyScreenProps.onVisualizeClick = addVisualization; } + if (isEmptyInReadOnlyMode) { + emptyScreenProps.isReadonlyMode = true; + } return emptyScreenProps; }; @@ -219,6 +231,7 @@ export class DashboardAppController { } const shouldShowEditHelp = getShouldShowEditHelp(); const shouldShowViewHelp = getShouldShowViewHelp(); + const isEmptyInReadonlyMode = getIsEmptyInReadonlyMode(); return { id: dashboardStateManager.savedDashboard.id || '', filters: queryFilter.getFilters(), @@ -231,7 +244,7 @@ export class DashboardAppController { viewMode: dashboardStateManager.getViewMode(), panels: embeddablesMap, isFullScreenMode: dashboardStateManager.getFullScreenMode(), - isEmptyState: shouldShowEditHelp || shouldShowViewHelp, + isEmptyState: shouldShowEditHelp || shouldShowViewHelp || isEmptyInReadonlyMode, useMargins: dashboardStateManager.getUseMargins(), lastReloadRequestTime, title: dashboardStateManager.getTitle(), @@ -275,9 +288,12 @@ export class DashboardAppController { dashboardContainer.renderEmpty = () => { const shouldShowEditHelp = getShouldShowEditHelp(); const shouldShowViewHelp = getShouldShowViewHelp(); - const isEmptyState = shouldShowEditHelp || shouldShowViewHelp; + const isEmptyInReadOnlyMode = getIsEmptyInReadonlyMode(); + const isEmptyState = shouldShowEditHelp || shouldShowViewHelp || isEmptyInReadOnlyMode; return isEmptyState ? ( - + ) : null; }; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen.tsx index ae5319c560ab95..3ef87fda7236b7 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen.tsx @@ -37,6 +37,7 @@ export interface DashboardEmptyScreenProps { onVisualizeClick?: () => void; uiSettings: IUiSettingsClient; http: HttpStart; + isReadonlyMode?: boolean; } export function DashboardEmptyScreen({ @@ -45,6 +46,7 @@ export function DashboardEmptyScreen({ onVisualizeClick, uiSettings, http, + isReadonlyMode, }: DashboardEmptyScreenProps) { const IS_DARK_THEME = uiSettings.get('theme:darkMode'); const emptyStateGraphicURL = IS_DARK_THEME @@ -98,25 +100,42 @@ export function DashboardEmptyScreen({ constants.addExistingVisualizationLinkText, constants.addExistingVisualizationLinkAriaLabel ); - const viewMode = ( - - - - - -

{constants.fillDashboardTitle}

-
- -
{enterEditModeParagraph}
-
-
-
+ const page = (mainText: string, showAdditionalParagraph?: boolean, additionalText?: string) => { + return ( + + + + + +

{mainText}

+
+ {additionalText ? ( + + {additionalText} + + ) : null} + {showAdditionalParagraph ? ( + + +
{enterEditModeParagraph}
+
+ ) : null} +
+
+
+ ); + }; + const readonlyMode = page( + constants.emptyDashboardTitle, + false, + constants.emptyDashboardAdditionalPrivilege ); + const viewMode = page(constants.fillDashboardTitle, true); const editMode = (
{enterViewModeParagraph} @@ -124,5 +143,6 @@ export function DashboardEmptyScreen({ {linkToVisualizeParagraph}
); - return {showLinkToVisualize ? editMode : viewMode}; + const actionableMode = showLinkToVisualize ? editMode : viewMode; + return {isReadonlyMode ? readonlyMode : actionableMode}; } diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen_constants.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen_constants.tsx index 513e6cb685a7ac..51fe31913662a5 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen_constants.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_empty_screen_constants.tsx @@ -19,6 +19,16 @@ import { i18n } from '@kbn/i18n'; +/** READONLY VIEW CONSTANTS **/ +export const emptyDashboardTitle: string = i18n.translate('kbn.dashboard.emptyDashboardTitle', { + defaultMessage: 'This dashboard is empty.', +}); +export const emptyDashboardAdditionalPrivilege = i18n.translate( + 'kbn.dashboard.emptyDashboardAdditionalPrivilege', + { + defaultMessage: 'You need additional privileges to edit this dashboard.', + } +); /** VIEW MODE CONSTANTS **/ export const fillDashboardTitle: string = i18n.translate('kbn.dashboard.fillDashboardTitle', { defaultMessage: 'This dashboard is empty. Let\u2019s fill it up!',