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

[Dashboard] Add visualization from dasbhoard empty screen #52670

Merged
merged 5 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,15 @@ describe('DashboardEmptyScreen', () => {
const paragraph = findTestSubject(component, 'linkToVisualizeParagraph');
expect(paragraph.length).toBe(0);
});

test('when specified, prop onVisualizeClick is called correctly', () => {
const onVisualizeClick = jest.fn();
const component = mountComponent({
...defaultProps,
...{ showLinkToVisualize: true, onVisualizeClick },
});
const button = findTestSubject(component, 'addVisualizationButton');
button.simulate('click');
expect(onVisualizeClick).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import React from 'react';
import angular from 'angular';
import { uniq, noop } from 'lodash';
import { uniq } from 'lodash';

import { Subscription } from 'rxjs';
import { DashboardEmptyScreen, DashboardEmptyScreenProps } from './dashboard_empty_screen';
Expand Down Expand Up @@ -54,6 +54,7 @@ import {
ErrorEmbeddable,
ViewMode,
openAddPanelFlyout,
EmbeddableFactoryNotFoundError,
} from '../../../embeddable_api/public/np_ready/public';
import { DashboardAppState, NavAction, ConfirmModalFn, SavedDashboardPanel } from './types';

Expand Down Expand Up @@ -142,16 +143,20 @@ export class DashboardAppController {
}
$scope.showSaveQuery = dashboardCapabilities.saveQuery as boolean;

$scope.getShouldShowEditHelp = () =>
const getShouldShowEditHelp = () =>
!dashboardStateManager.getPanels().length &&
dashboardStateManager.getIsEditMode() &&
!dashboardConfig.getHideWriteControls();

$scope.getShouldShowViewHelp = () =>
const getShouldShowViewHelp = () =>
!dashboardStateManager.getPanels().length &&
dashboardStateManager.getIsViewMode() &&
!dashboardConfig.getHideWriteControls();

const addVisualization = () => {
navActions[TopNavIds.VISUALIZE]();
};

const updateIndexPatterns = (container?: DashboardContainer) => {
if (!container || isErrorEmbeddable(container)) {
return;
Expand Down Expand Up @@ -186,7 +191,7 @@ export class DashboardAppController {
showLinkToVisualize: shouldShowEditHelp,
};
if (shouldShowEditHelp) {
emptyScreenProps.onVisualizeClick = noop;
emptyScreenProps.onVisualizeClick = addVisualization;
}
return emptyScreenProps;
};
Expand All @@ -202,8 +207,8 @@ export class DashboardAppController {
if (dashboardContainer && !isErrorEmbeddable(dashboardContainer)) {
expandedPanelId = dashboardContainer.getInput().expandedPanelId;
}
const shouldShowEditHelp = $scope.getShouldShowEditHelp();
const shouldShowViewHelp = $scope.getShouldShowViewHelp();
const shouldShowEditHelp = getShouldShowEditHelp();
const shouldShowViewHelp = getShouldShowViewHelp();
return {
id: dashboardStateManager.savedDashboard.id || '',
filters: queryFilter.getFilters(),
Expand Down Expand Up @@ -258,8 +263,8 @@ export class DashboardAppController {
dashboardContainer = container;

dashboardContainer.renderEmpty = () => {
const shouldShowEditHelp = $scope.getShouldShowEditHelp();
const shouldShowViewHelp = $scope.getShouldShowViewHelp();
const shouldShowEditHelp = getShouldShowEditHelp();
const shouldShowViewHelp = getShouldShowViewHelp();
const isEmptyState = shouldShowEditHelp || shouldShowViewHelp;
return isEmptyState ? (
<DashboardEmptyScreen {...getEmptyScreenProps(shouldShowEditHelp)} />
Expand Down Expand Up @@ -752,7 +757,17 @@ export class DashboardAppController {
}
};

navActions[TopNavIds.VISUALIZE] = async () => {};
navActions[TopNavIds.VISUALIZE] = async () => {
const type = 'visualization';
const factory = embeddables.getEmbeddableFactory(type);
if (!factory) {
throw new EmbeddableFactoryNotFoundError(type);
}
const explicitInput = await factory.getExplicitInput();
if (dashboardContainer) {
await dashboardContainer.addNewEmbeddable(type, explicitInput);
}
};

navActions[TopNavIds.OPTIONS] = anchorElement => {
showOptionsPopover({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
EuiPageBody,
EuiPage,
EuiText,
EuiButton,
} from '@elastic/eui';
import * as constants from './dashboard_empty_screen_constants';

Expand All @@ -38,23 +39,23 @@ export interface DashboardEmptyScreenProps {
export function DashboardEmptyScreen({
showLinkToVisualize,
onLinkClick,
onVisualizeClick,
}: DashboardEmptyScreenProps) {
const linkToVisualizeParagraph = (
<EuiText data-test-subj="linkToVisualizeParagraph">
<p>
<p data-test-subj="linkToVisualizeParagraph">
<EuiButton
iconSide="right"
fill
iconType="arrowDown"
onClick={onVisualizeClick}
data-test-subj="addVisualizationButton"
>
<FormattedMessage
id="kbn.dashboard.addVisualizationDescription3"
defaultMessage="If you haven't set up any visualizations yet, {visualizeAppLink} to create your first visualization"
values={{
visualizeAppLink: (
<a className="euiLink" href="#/visualize">
{constants.visualizeAppLinkTest}
</a>
),
}}
id="embeddableApi.addPanel.createNewDefaultOption"
defaultMessage="Create new"
/>
</p>
</EuiText>
</EuiButton>
</p>
);
const paragraph = (
description1: string,
Expand Down Expand Up @@ -96,7 +97,7 @@ export function DashboardEmptyScreen({
);
return (
<I18nProvider>
<EuiPage className="dshStartScreen" restrictWidth={'36em'}>
<EuiPage className="dshStartScreen" restrictWidth="36em">
<EuiPageBody>
<EuiPageContent verticalPosition="center" horizontalPosition="center">
<EuiIcon type="dashboardApp" size="xxl" color="subdued" />
Expand Down
Loading