Skip to content

Commit

Permalink
Shim home app (#48715) (#50088)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Nov 7, 2019
1 parent 19dfe26 commit b137b92
Show file tree
Hide file tree
Showing 11 changed files with 338 additions and 186 deletions.

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 @@ -136,7 +136,7 @@ export class Home extends Component {
const { apmUiEnabled, mlEnabled } = this.props;

return (
<EuiPage restrictWidth={1200}>
<EuiPage restrictWidth={1200} data-test-subj="homeApp">
<EuiPageBody className="eui-displayBlock">

<EuiScreenReaderOnly>
Expand Down
102 changes: 46 additions & 56 deletions src/legacy/core_plugins/kibana/public/home/components/home_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,16 @@
*/

import React from 'react';
import { I18nProvider } from '@kbn/i18n/react';
import PropTypes from 'prop-types';
import { Home } from './home';
import { FeatureDirectory } from './feature_directory';
import { TutorialDirectory } from './tutorial_directory';
import { Tutorial } from './tutorial/tutorial';
import {
HashRouter as Router,
Switch,
Route,
} from 'react-router-dom';
import { HashRouter as Router, Switch, Route, Redirect } from 'react-router-dom';
import { getTutorial } from '../load_tutorials';
import { replaceTemplateStrings } from './tutorial/replace_template_strings';
import {
getServices
} from '../kibana_services';
import { getServices } from '../kibana_services';

export function HomeApp({ directories }) {
const {
Expand All @@ -47,8 +42,9 @@ export function HomeApp({ directories }) {
const isCloudEnabled = getInjected('isCloudEnabled', false);
const apmUiEnabled = getInjected('apmUiEnabled', true);
const mlEnabled = getInjected('mlEnabled', false);
const defaultAppId = getInjected('kbnDefaultAppId', 'discover');

const renderTutorialDirectory = (props) => {
const renderTutorialDirectory = props => {
return (
<TutorialDirectory
addBasePath={addBasePath}
Expand All @@ -58,7 +54,7 @@ export function HomeApp({ directories }) {
);
};

const renderTutorial = (props) => {
const renderTutorial = props => {
return (
<Tutorial
addBasePath={addBasePath}
Expand All @@ -72,54 +68,48 @@ export function HomeApp({ directories }) {
};

return (
<Router>
<Switch>
<Route
path="/home/tutorial/:id"
render={renderTutorial}
/>
<Route
path="/home/tutorial_directory/:tab?"
render={renderTutorialDirectory}
/>
<Route
path="/home/feature_directory"
>
<FeatureDirectory
addBasePath={addBasePath}
directories={directories}
/>
</Route>
<Route
path="/home"
>
<Home
addBasePath={addBasePath}
directories={directories}
apmUiEnabled={apmUiEnabled}
mlEnabled={mlEnabled}
find={savedObjectsClient.find}
localStorage={localStorage}
urlBasePath={getBasePath()}
shouldShowTelemetryOptIn={shouldShowTelemetryOptIn}
setOptIn={telemetryOptInProvider.setOptIn}
fetchTelemetry={telemetryOptInProvider.fetchExample}
getTelemetryBannerId={telemetryOptInProvider.getBannerId}
/>
</Route>
</Switch>
</Router>
<I18nProvider>
<Router>
<Switch>
<Route path="/home/tutorial/:id" render={renderTutorial} />
<Route path="/home/tutorial_directory/:tab?" render={renderTutorialDirectory} />
<Route exact path="/home/feature_directory">
<FeatureDirectory addBasePath={addBasePath} directories={directories} />
</Route>
<Route exact path="/home">
<Home
addBasePath={addBasePath}
directories={directories}
apmUiEnabled={apmUiEnabled}
mlEnabled={mlEnabled}
find={savedObjectsClient.find}
localStorage={localStorage}
urlBasePath={getBasePath()}
shouldShowTelemetryOptIn={shouldShowTelemetryOptIn}
setOptIn={telemetryOptInProvider.setOptIn}
fetchTelemetry={telemetryOptInProvider.fetchExample}
getTelemetryBannerId={telemetryOptInProvider.getBannerId}
/>
</Route>
<Route path="/home">
<Redirect to={`/${defaultAppId}`} />
</Route>
</Switch>
</Router>
</I18nProvider>
);
}

HomeApp.propTypes = {
directories: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
path: PropTypes.string.isRequired,
showOnHomePage: PropTypes.bool.isRequired,
category: PropTypes.string.isRequired,
})),
directories: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
path: PropTypes.string.isRequired,
showOnHomePage: PropTypes.bool.isRequired,
category: PropTypes.string.isRequired,
})
),
};

This file was deleted.

61 changes: 0 additions & 61 deletions src/legacy/core_plugins/kibana/public/home/index.js

This file was deleted.

80 changes: 80 additions & 0 deletions src/legacy/core_plugins/kibana/public/home/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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 { FeatureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue';
import { npSetup, npStart } from 'ui/new_platform';
import chrome from 'ui/chrome';
import { IPrivate } from 'ui/private';
import { HomePlugin, LegacyAngularInjectedDependencies } from './plugin';
import { createUiStatsReporter, METRIC_TYPE } from '../../../ui_metric/public';
import { start as data } from '../../../data/public/legacy';
import { TelemetryOptInProvider } from '../../../telemetry/public/services';
import { localApplicationService } from '../local_application_service';

export const trackUiMetric = createUiStatsReporter('Kibana_home');

/**
* Get dependencies relying on the global angular context.
* They also have to get resolved together with the legacy imports above
*/
async function getAngularDependencies(): Promise<LegacyAngularInjectedDependencies> {
const injector = await chrome.dangerouslyGetActiveInjector();

const Private = injector.get<IPrivate>('Private');

const telemetryEnabled = npStart.core.injectedMetadata.getInjectedVar('telemetryEnabled');
const telemetryBanner = npStart.core.injectedMetadata.getInjectedVar('telemetryBanner');
const telemetryOptInProvider = Private(TelemetryOptInProvider);

return {
telemetryOptInProvider,
shouldShowTelemetryOptIn:
telemetryEnabled && telemetryBanner && !telemetryOptInProvider.getOptIn(),
};
}

let copiedLegacyCatalogue = false;

(async () => {
const instance = new HomePlugin();
instance.setup(npSetup.core, {
__LEGACY: {
trackUiMetric,
metadata: npStart.core.injectedMetadata.getLegacyMetadata(),
METRIC_TYPE,
getFeatureCatalogueEntries: async () => {
if (!copiedLegacyCatalogue) {
const injector = await chrome.dangerouslyGetActiveInjector();
const Private = injector.get<IPrivate>('Private');
// Merge legacy registry with new registry
(Private(FeatureCatalogueRegistryProvider as any) as any).inTitleOrder.map(
npSetup.plugins.feature_catalogue.register
);
copiedLegacyCatalogue = true;
}
return npStart.plugins.feature_catalogue.get();
},
getAngularDependencies,
localApplicationService,
},
});
instance.start(npStart.core, {
data,
});
})();
Loading

0 comments on commit b137b92

Please sign in to comment.