Skip to content

Commit

Permalink
Migration: Separate legacy and index entrypoint (#54124)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Jan 21, 2020
1 parent c196058 commit c88aa5a
Show file tree
Hide file tree
Showing 28 changed files with 202 additions and 123 deletions.
7 changes: 6 additions & 1 deletion src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ export default function(kibana) {
},

uiExports: {
hacks: ['plugins/kibana/discover', 'plugins/kibana/dev_tools', 'plugins/kibana/visualize'],
hacks: [
'plugins/kibana/discover/legacy',
'plugins/kibana/dev_tools',
'plugins/kibana/visualize/legacy',
'plugins/kibana/dashboard/legacy',
],
savedObjectTypes: ['plugins/kibana/dashboard/saved_dashboard/saved_dashboard_register'],
app: {
id: 'kibana',
Expand Down
1 change: 1 addition & 0 deletions src/legacy/core_plugins/kibana/public/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function buildRestrictedPaths(shimmedPlugins) {
from: [
`src/legacy/core_plugins/kibana/public/${shimmedPlugin}/**/*`,
`!src/legacy/core_plugins/kibana/public/${shimmedPlugin}/index.ts`,
`!src/legacy/core_plugins/kibana/public/${shimmedPlugin}/legacy.ts`,
],
allowSameFolder: false,
errorMessage: `kibana/public/${shimmedPlugin} is behaving like a NP plugin and does not allow deep imports. If you need something from within ${shimmedPlugin} in another plugin, consider re-exporting it from the top level index module`,
Expand Down
40 changes: 6 additions & 34 deletions src/legacy/core_plugins/kibana/public/dashboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,12 @@
* under the License.
*/

import { npSetup, npStart, legacyChrome } from './legacy_imports';
import { DashboardPlugin, LegacyAngularInjectedDependencies } from './plugin';
import { start as data } from '../../../data/public/legacy';
import { start as embeddables } from '../../../embeddable_api/public/np_ready/public/legacy';
import './saved_dashboard/saved_dashboard_register';
import './dashboard_config';
import { PluginInitializerContext } from 'kibana/public';
import { DashboardPlugin } from './plugin';

export * from './np_ready/dashboard_constants';

/**
* 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 legacyChrome.dangerouslyGetActiveInjector();

return {
dashboardConfig: injector.get('dashboardConfig'),
};
}

(async () => {
const instance = new DashboardPlugin();
instance.setup(npSetup.core, {
...npSetup.plugins,
__LEGACY: {
getAngularDependencies,
},
});
instance.start(npStart.core, {
...npStart.plugins,
data,
npData: npStart.plugins.data,
embeddables,
navigation: npStart.plugins.navigation,
});
})();
// Core will be looking for this when loading our plugin in the new platform
export const plugin = (context: PluginInitializerContext) => {
return new DashboardPlugin();
};
56 changes: 56 additions & 0 deletions src/legacy/core_plugins/kibana/public/dashboard/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart, legacyChrome } from './legacy_imports';
import { LegacyAngularInjectedDependencies } from './plugin';
import { start as data } from '../../../data/public/legacy';
import { start as embeddables } from '../../../embeddable_api/public/np_ready/public/legacy';
import './saved_dashboard/saved_dashboard_register';
import './dashboard_config';
import { plugin } from './index';

/**
* 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 legacyChrome.dangerouslyGetActiveInjector();

return {
dashboardConfig: injector.get('dashboardConfig'),
};
}

(async () => {
const instance = plugin({} as PluginInitializerContext);
instance.setup(npSetup.core, {
...npSetup.plugins,
__LEGACY: {
getAngularDependencies,
},
});
instance.start(npStart.core, {
...npStart.plugins,
data,
npData: npStart.plugins.data,
embeddables,
navigation: npStart.plugins.navigation,
});
})();
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import _ from 'lodash';
import sinon from 'sinon';
import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

// Load the kibana app dependencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';
import ngMock from 'ng_mock';
import { fieldCalculator } from '../../np_ready/components/field_chooser/lib/field_calculator';
import expect from '@kbn/expect';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import _ from 'lodash';
import sinon from 'sinon';
import expect from '@kbn/expect';
import $ from 'jquery';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';
import FixturesHitsProvider from 'fixtures/hits';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { SimpleSavedObject } from '../../../../../../../core/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import expect from '@kbn/expect';
import _ from 'lodash';
import ngMock from 'ng_mock';
import 'ui/private';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import hits from 'fixtures/real_hits';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { getFakeRow, getFakeRowVals } from 'fixtures/fake_row';
import $ from 'jquery';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

describe('Doc Table', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ngMock from 'ng_mock';
import { createStateStub } from './_utils';
import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions';
import { createIndexPatternsStub } from '../../np_ready/angular/context/api/__tests__/_stubs';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';
import { npStart } from 'ui/new_platform';

describe('context app', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';
import { createStateStub } from './_utils';
import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';

import { createStateStub } from './_utils';
import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';

import { createStateStub } from './_utils';
import { getQueryParameterActions } from '../../np_ready/angular/context/query_parameters/actions';
Expand Down
17 changes: 3 additions & 14 deletions src/legacy/core_plugins/kibana/public/discover/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
import chrome from 'ui/chrome';

import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';
import { DiscoverPlugin } from './plugin';

export { createSavedSearchesService } from './saved_searches/saved_searches';

// Core will be looking for this when loading our plugin in the new platform
export const plugin = (context: PluginInitializerContext) => {
return new DiscoverPlugin();
};

// Legacy compatiblity part - to be removed at cutover, replaced by a kibana.json file
export const pluginInstance = plugin({} as PluginInitializerContext);
export const setup = pluginInstance.setup(npSetup.core, {
...npSetup.plugins,
__LEGACY: {
chrome,
},
});
export const start = pluginInstance.start(npStart.core, npStart.plugins);

export { createSavedSearchesService } from './saved_searches/saved_searches';
32 changes: 32 additions & 0 deletions src/legacy/core_plugins/kibana/public/discover/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 chrome from 'ui/chrome';
import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';
import { plugin } from './index';

// Legacy compatiblity part - to be removed at cutover, replaced by a kibana.json file
export const pluginInstance = plugin({} as PluginInitializerContext);
export const setup = pluginInstance.setup(npSetup.core, {
...npSetup.plugins,
__LEGACY: {
chrome,
},
});
export const start = pluginInstance.start(npStart.core, npStart.plugins);
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';

import { createIndexPatternsStub, createSearchSourceStub } from './_stubs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import moment from 'moment';
import * as _ from 'lodash';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';

import { createIndexPatternsStub, createContextSearchSourceStub } from './_stubs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import moment from 'moment';
import * as _ from 'lodash';
import { pluginInstance } from 'plugins/kibana/discover/index';
import { pluginInstance } from 'plugins/kibana/discover/legacy';

import { createIndexPatternsStub, createContextSearchSourceStub } from './_stubs';

Expand Down
5 changes: 0 additions & 5 deletions src/legacy/core_plugins/kibana/public/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ 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 { TelemetryOptInProvider } from '../../../telemetry/public/services';

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
Expand Down Expand Up @@ -54,9 +51,7 @@ let copiedLegacyCatalogue = false;
instance.setup(npSetup.core, {
...npSetup.plugins,
__LEGACY: {
trackUiMetric,
metadata: npStart.core.injectedMetadata.getLegacyMetadata(),
METRIC_TYPE,
getFeatureCatalogueEntries: async () => {
if (!copiedLegacyCatalogue) {
const injector = await chrome.dangerouslyGetActiveInjector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export interface HomeKibanaServices {
savedObjectsClient: SavedObjectsClientContract;
toastNotifications: NotificationsSetup['toasts'];
banners: OverlayStart['banners'];
METRIC_TYPE: any;
trackUiMetric: (type: UiStatsMetricType, eventNames: string | string[], count?: number) => void;
getBasePath: () => string;
shouldShowTelemetryOptIn: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ jest.mock('../../kibana_services', () => ({
getServices: () => ({
addBasePath: (path: string) => `root${path}`,
trackUiMetric: () => {},
METRIC_TYPE: {
LOADED: 'loaded',
CLICK: 'click',
},
}),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
EuiIcon,
EuiPortal,
} from '@elastic/eui';
import { METRIC_TYPE } from '@kbn/analytics';
import { FormattedMessage } from '@kbn/i18n/react';
import { getServices } from '../../kibana_services';

Expand Down Expand Up @@ -64,17 +65,17 @@ export class Welcome extends React.Component<Props> {
}

private onSampleDataDecline = () => {
this.services.trackUiMetric(this.services.METRIC_TYPE.CLICK, 'sampleDataDecline');
this.services.trackUiMetric(METRIC_TYPE.CLICK, 'sampleDataDecline');
this.props.onSkip();
};

private onSampleDataConfirm = () => {
this.services.trackUiMetric(this.services.METRIC_TYPE.CLICK, 'sampleDataConfirm');
this.services.trackUiMetric(METRIC_TYPE.CLICK, 'sampleDataConfirm');
this.redirecToSampleData();
};

componentDidMount() {
this.services.trackUiMetric(this.services.METRIC_TYPE.LOADED, 'welcomeScreenMount');
this.services.trackUiMetric(METRIC_TYPE.LOADED, 'welcomeScreenMount');
this.props.onOptInSeen();
document.addEventListener('keydown', this.hideOnEsc);
}
Expand Down
Loading

0 comments on commit c88aa5a

Please sign in to comment.