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

Remove Lens-specific code from visualize #16

Closed
Closed
Show file tree
Hide file tree
Changes from all 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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import { NewVisHelp } from './new_vis_help';
import chrome from 'ui/chrome';

jest.doMock('ui/chrome');

describe('NewVisHelp', () => {
it('should render as expected', () => {
(chrome.addBasePath as unknown) = (url: string) => `testbasepath${url}`;

expect(
shallowWithIntl(
<NewVisHelp
promotedTypes={[
{
aliasUrl: '/my/fancy/new/thing',
description: 'Some desc',
highlighted: false,
icon: 'wahtever',
name: 'whatever',
promotion: {
calloutText: 'Do it now!',
description: 'Look at this fancy new thing!!!',
},
title: 'Test title',
},
]}
/>
)
).toMatchInlineSnapshot(`
<EuiText>
<p>
<FormattedMessage
defaultMessage="Start creating your visualization by selecting a type for that visualization."
id="kbn.visualize.newVisWizard.helpText"
values={Object {}}
/>
</p>
<p>
<strong>
Look at this fancy new thing!!!
</strong>
</p>
<EuiButton
fill={true}
href="testbasepath/my/fancy/new/thing"
iconSide="right"
iconType="popout"
size="s"
>
Do it now!
</EuiButton>
</EuiText>
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,39 @@

import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';

import { EuiText, EuiButton } from '@elastic/eui';
import chrome from 'ui/chrome';
import { VisTypeAliasListEntry } from './type_selection';

interface Props {
promotedTypes: VisTypeAliasListEntry[];
}

export const NewVisHelp = () => (
<EuiText>
<p>
<FormattedMessage
id="kbn.visualize.newVisWizard.helpText"
defaultMessage="Start creating your visualization by selecting a type for that visualization."
/>
</p>
<p>
<strong>
export function NewVisHelp(props: Props) {
return (
<EuiText>
<p>
<FormattedMessage
id="kbn.visualize.newVisWizard.tryLensText"
defaultMessage="Try Lens, our new, intuitive way to create visualizations."
id="kbn.visualize.newVisWizard.helpText"
defaultMessage="Start creating your visualization by selecting a type for that visualization."
/>
</strong>
</p>
<EuiButton fill size="s" iconType="popout" iconSide="right">
Go to Lens
</EuiButton>
</EuiText>
);
</p>
{props.promotedTypes.map(t => (
<>
<p>
<strong>{t.promotion!.description}</strong>
</p>
<EuiButton
href={chrome.addBasePath(t.aliasUrl)}
fill
size="s"
iconType="popout"
iconSide="right"
>
{t.promotion!.calloutText}
</EuiButton>
</>
))}
</EuiText>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ import { VisHelpText } from './vis_help_text';
import { VisTypeIcon } from './vis_type_icon';
import { TypesStart } from '../../../../../visualizations/public/np_ready/types';

interface VisTypeListEntry extends VisType {
export interface VisTypeListEntry extends VisType {
highlighted: boolean;
}

interface VisTypeAliasListEntry extends VisTypeAlias {
export interface VisTypeAliasListEntry extends VisTypeAlias {
highlighted: boolean;
}

Expand Down Expand Up @@ -152,7 +152,9 @@ class TypeSelection extends React.Component<TypeSelectionProps, TypeSelectionSta
</h2>
</EuiTitle>
<EuiSpacer size="m" />
<NewVisHelp />
<NewVisHelp
promotedTypes={(visTypes as VisTypeAliasListEntry[]).filter(t => t.promotion)}
/>
</React.Fragment>
)}
</EuiFlexItem>
Expand Down Expand Up @@ -196,7 +198,7 @@ class TypeSelection extends React.Component<TypeSelectionProps, TypeSelectionSta
});
}

return sortByOrder(entries, ['highlighted', 'isPromoted', 'title'], ['desc', 'asc', 'asc']);
return sortByOrder(entries, ['highlighted', 'promotion', 'title'], ['desc', 'asc', 'asc']);
}

private renderVisType = (visType: VisTypeListEntry | VisTypeAliasListEntry) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ interface VisualizationsAppExtension {
}) => VisualizationListItem;
}

export interface VisTypeAliasPromotion {
description: string;
calloutText: string;
}

export interface VisTypeAlias {
aliasUrl: string;
name: string;
title: string;
icon: string;
isPromoted?: boolean;
promotion?: VisTypeAliasPromotion;
description: string;

appExtensions?: {
Expand Down
48 changes: 0 additions & 48 deletions x-pack/legacy/plugins/lens/public/help_menu.js

This file was deleted.

17 changes: 0 additions & 17 deletions x-pack/legacy/plugins/lens/public/help_menu_util.js

This file was deleted.

48 changes: 48 additions & 0 deletions x-pack/legacy/plugins/lens/public/help_menu_util.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { EuiHorizontalRule, EuiSpacer, EuiLink, EuiText, EuiIcon, EuiButton } from '@elastic/eui';
import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { render, unmountComponentAtNode } from 'react-dom';
import { Chrome } from 'ui/chrome';

export function addHelpMenuToAppChrome(chrome: Chrome) {
chrome.helpExtension.set(domElement => {
render(<HelpMenu />, domElement);
return () => {
unmountComponentAtNode(domElement);
};
});
}

function HelpMenu() {
return (
<>
<EuiHorizontalRule margin="none" />
<EuiSpacer />
<EuiButton
fill
iconType="popout"
href={`${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/lens.html`}
target="_blank"
>
<FormattedMessage id="xpack.lens.helpMenu.docLabel" defaultMessage="Lens documentation" />
</EuiButton>
<EuiSpacer />
<EuiText size="s">
<EuiIcon type="logoGithub" color="primary" /> &nbsp;
<EuiLink href="https://github.com/elastic/kibana/issues/new" target="_blank">
{i18n.translate('xpack.lens.helpMenu.feedbackLinkText', {
defaultMessage: 'Provide feedback for the Lens application',
})}
</EuiLink>
</EuiText>
</>
);
}
3 changes: 3 additions & 0 deletions x-pack/legacy/plugins/lens/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { IScope } from 'angular';
import chrome from 'ui/chrome';
import { appStart, appSetup, appStop } from './app_plugin';
import { PLUGIN_ID } from '../common';
import { addHelpMenuToAppChrome } from './help_menu_util';

// TODO: Convert this to the "new platform" way of doing UI
function Root($scope: IScope, $element: JQLite) {
Expand All @@ -30,6 +31,8 @@ function Root($scope: IScope, $element: JQLite) {
});

appSetup();
addHelpMenuToAppChrome(chrome);

return render(appStart(), el);
}

Expand Down
9 changes: 8 additions & 1 deletion x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import { BASE_APP_URL, getEditPath } from '../common';
visualizations.types.registerAlias({
aliasUrl: BASE_APP_URL,
name: 'lens',
isPromoted: true,
promotion: {
description: i18n.translate('xpack.lens.visTypeAlias.promotion.description', {
defaultMessage: 'Try Lens, our new, intuitive way to create visualizations.',
}),
calloutText: i18n.translate('xpack.lens.visTypeAlias.promotion.calloutText', {
defaultMessage: 'Go to Lens',
}),
},
title: i18n.translate('xpack.lens.visTypeAlias.title', {
defaultMessage: 'Lens Visualizations',
}),
Expand Down