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

[WIP] Adds 'upload data from file' to Kibana home page #24226

Merged
merged 11 commits into from
Oct 24, 2018

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`home directories should not render directory entry when showOnHomePage
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={false}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -145,6 +146,7 @@ exports[`home directories should render ADMIN directory entry in "Manage" panel
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={false}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -298,6 +300,7 @@ exports[`home directories should render DATA directory entry in "Explore Data" p
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={false}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -451,6 +454,7 @@ exports[`home isNewKibanaInstance should safely handle execeptions 1`] = `
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={false}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -585,6 +589,7 @@ exports[`home isNewKibanaInstance should set isNewKibanaInstance to false when t
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={false}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -719,6 +724,7 @@ exports[`home isNewKibanaInstance should set isNewKibanaInstance to true when th
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={true}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -853,6 +859,7 @@ exports[`home should not contain RecentlyAccessed panel when there is no recentl
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={false}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -1003,6 +1010,7 @@ exports[`home should render home component 1`] = `
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={false}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -1137,6 +1145,7 @@ exports[`home welcome should show the normal home page if loading fails 1`] = `
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={false}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -1271,6 +1280,7 @@ exports[`home welcome should show the normal home page if welcome screen is disa
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={false}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down Expand Up @@ -1412,6 +1422,7 @@ exports[`home welcome stores skip welcome setting if skipped 1`] = `
<InjectIntl(AddDataUi)
apmUiEnabled={true}
isNewKibanaInstance={true}
mlEnabled={true}
/>
<EuiSpacer
size="l"
Expand Down
45 changes: 35 additions & 10 deletions src/core_plugins/kibana/public/home/components/add_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { injectI18n, FormattedMessage } from '@kbn/i18n/react';
import chrome from 'ui/chrome';

import {
EuiButton,
Expand All @@ -34,9 +35,13 @@ import {
EuiCard,
EuiIcon,
EuiHorizontalRule,
EuiFlexGrid,
} from '@elastic/eui';

const AddDataUi = ({ apmUiEnabled, isNewKibanaInstance, intl }) => {
/* istanbul ignore next */
const basePath = chrome.getBasePath();

const AddDataUi = ({ apmUiEnabled, isNewKibanaInstance, intl, mlEnabled }) => {

const renderCards = () => {
const apmTitle = intl.formatMessage({
Expand Down Expand Up @@ -189,17 +194,17 @@ const AddDataUi = ({ apmUiEnabled, isNewKibanaInstance, intl }) => {

<EuiHorizontalRule />

<EuiFlexGroup justifyContent="spaceAround">
<EuiFlexGrid columns={mlEnabled !== false ? 3 : 2}>
<EuiFlexItem className={footerItemClasses}>
<EuiText>
<strong style={{ height: 38 }}>
<FormattedMessage
id="kbn.home.addData.sampleDataTitle"
defaultMessage="Sample Data"
defaultMessage="Add sample data"
/>
</strong>
<EuiLink
style={{ marginLeft: 8 }}
style={{ display: 'block', textAlign: 'center' }}
href="#/home/tutorial_directory/sampleData"
>
<FormattedMessage
Expand All @@ -209,16 +214,38 @@ const AddDataUi = ({ apmUiEnabled, isNewKibanaInstance, intl }) => {
</EuiLink>
</EuiText>
</EuiFlexItem>
{mlEnabled !== false ?
<EuiFlexItem className={footerItemClasses}>
<EuiText>
<strong style={{ height: 38 }}>
<FormattedMessage
id="kbn.home.addData.uploadFileTitle"
defaultMessage="Upload data from log file"
/>
</strong>
<EuiLink
style={{ display: 'block', textAlign: 'center' }}
href={`${basePath}/app/ml#/filedatavisualizer`}
>
<FormattedMessage
id="kbn.home.addData.uploadFileLink"
defaultMessage="Import a JSON, CSV, or log file"
/>
</EuiLink>
</EuiText>
</EuiFlexItem>
: null
}
<EuiFlexItem className={footerItemClasses}>
<EuiText>
<strong style={{ height: 38 }}>
<FormattedMessage
id="kbn.home.addData.yourDataTitle"
defaultMessage="Your Data"
defaultMessage="Use Elasticsearch data"
/>
</strong>
<EuiLink
style={{ marginLeft: 8 }}
style={{ display: 'block', textAlign: 'center' }}
href="#/management/kibana/index"
>
<FormattedMessage
Expand All @@ -228,16 +255,14 @@ const AddDataUi = ({ apmUiEnabled, isNewKibanaInstance, intl }) => {
</EuiLink>
</EuiText>
</EuiFlexItem>


</EuiFlexGroup>

</EuiFlexGrid>
</EuiPanel>
);
};

AddDataUi.propTypes = {
apmUiEnabled: PropTypes.bool.isRequired,
mlEnabled: PropTypes.bool.isRequired,
isNewKibanaInstance: PropTypes.bool.isRequired,
};

Expand Down
25 changes: 25 additions & 0 deletions src/core_plugins/kibana/public/home/components/add_data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,52 @@
import React from 'react';
import { AddData } from './add_data';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
import chrome from 'ui/chrome';

jest.mock(
'ui/chrome',
() => ({
getBasePath: jest.fn(() => 'path'),
}),
{ virtual: true }
);

test('render', () => {
const component = shallowWithIntl(<AddData.WrappedComponent
apmUiEnabled={false}
mlEnabled={false}
isNewKibanaInstance={false}
/>);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(chrome.getBasePath).toHaveBeenCalledTimes(1);
});

test('mlEnabled', () => {
const component = shallowWithIntl(<AddData.WrappedComponent
apmUiEnabled={true}
mlEnabled={true}
isNewKibanaInstance={false}
/>);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(chrome.getBasePath).toHaveBeenCalledTimes(1);
});

test('apmUiEnabled', () => {
const component = shallowWithIntl(<AddData.WrappedComponent
apmUiEnabled={true}
mlEnabled={false}
isNewKibanaInstance={false}
/>);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(chrome.getBasePath).toHaveBeenCalledTimes(1);
});

test('isNewKibanaInstance', () => {
const component = shallowWithIntl(<AddData.WrappedComponent
apmUiEnabled={false}
mlEnabled={false}
isNewKibanaInstance={true}
/>);
expect(component).toMatchSnapshot(); // eslint-disable-line
expect(chrome.getBasePath).toHaveBeenCalledTimes(1);
});
4 changes: 3 additions & 1 deletion src/core_plugins/kibana/public/home/components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class Home extends Component {
};

renderNormal() {
const { apmUiEnabled, recentlyAccessed } = this.props;
const { apmUiEnabled, recentlyAccessed, mlEnabled } = this.props;

let recentlyAccessedPanel;
if (recentlyAccessed.length > 0) {
Expand All @@ -148,6 +148,7 @@ export class Home extends Component {

<AddData
apmUiEnabled={apmUiEnabled}
mlEnabled={mlEnabled}
isNewKibanaInstance={this.state.isNewKibanaInstance}
/>

Expand Down Expand Up @@ -263,4 +264,5 @@ Home.propTypes = {
find: PropTypes.func.isRequired,
localStorage: PropTypes.object.isRequired,
urlBasePath: PropTypes.string.isRequired,
mlEnabled: PropTypes.bool.isRequired,
};
10 changes: 10 additions & 0 deletions src/core_plugins/kibana/public/home/components/home.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ import { shallow } from 'enzyme';
import { Home } from './home';
import { FeatureCatalogueCategory } from 'ui/registry/feature_catalogue';

jest.mock(
'ui/chrome',
() => ({
getBasePath: jest.fn(() => 'path'),
getInjected: jest.fn(() => ''),
}),
{ virtual: true }
);

describe('home', () => {
let defaultProps;

Expand All @@ -31,6 +40,7 @@ describe('home', () => {
recentlyAccessed: [],
directories: [],
apmUiEnabled: true,
mlEnabled: true,
kibanaVersion: '99.2.1',
addBasePath(url) {
return `base_path/${url}`;
Expand Down
2 changes: 2 additions & 0 deletions src/core_plugins/kibana/public/home/components/home_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function HomeApp({

const isCloudEnabled = chrome.getInjected('isCloudEnabled', false);
const apmUiEnabled = chrome.getInjected('apmUiEnabled', true);
const mlEnabled = chrome.getInjected('mlEnabled', false);
const savedObjectsClient = chrome.getSavedObjectsClient();

const renderTutorialDirectory = (props) => {
Expand Down Expand Up @@ -94,6 +95,7 @@ export function HomeApp({
addBasePath={addBasePath}
directories={directories}
apmUiEnabled={apmUiEnabled}
mlEnabled={mlEnabled}
recentlyAccessed={recentlyAccessed}
find={savedObjectsClient.find}
localStorage={localStorage}
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/apm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export function apm(kibana) {
injectDefaultVars(server) {
const config = server.config();
return {
mlEnabled: config.get('xpack.ml.enabled'),
apmUiEnabled: config.get('xpack.apm.ui.enabled'),
apmIndexPattern: config.get('apm_oss.indexPattern')
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TransactionOverview extends Component {
const { hasDynamicBaseline, license, location, urlParams } = this.props;

const { serviceName, transactionType } = urlParams;
const mlEnabled = chrome.getInjected('mlEnabled');
const mlEnabled = chrome.getInjected('mlEnabled', false);

const ChartHeaderContent =
hasDynamicBaseline && get(license.data, 'features.ml.isAvailable') ? (
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/ml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export const ml = (kibana) => {
styleSheetPaths: `${__dirname}/public/index.scss`,
hacks: ['plugins/ml/hacks/toggle_app_link_in_nav'],
home: ['plugins/ml/register_feature'],
injectDefaultVars(server) {
const config = server.config();
return {
mlEnabled: config.get('xpack.ml.enabled'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just looking for the xpack.ml.enabled setting in kibana.yml? If so, using this as the check as to whether to add the 'Upload data from log file' link to the Home page LGTM.

I believe APM have been using this mlEnabled flag to check whether to add a link to creating ML jobs from APM dashboards, but that is being edited in #24486 as they now need to check the type of license, and not just whether the ML feature is enabled.

};
},
},


Expand Down