Skip to content

Commit

Permalink
[NP] Vega migration (#63849)
Browse files Browse the repository at this point in the history
* Vega migartion

* Move mocha tests to legacy

* Fix TS

* Update .i18nrc.json

* Move mocks to vis_type_vega

* Fix issue with babel and vega deps

* Update mocha test

* Mock services

* Update vega_request_handler.ts

* don't parse vega-lib/build/vega.js

Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: spalger <[email protected]>
  • Loading branch information
3 people authored Apr 24, 2020
1 parent 9bda6bd commit 2ace269
Show file tree
Hide file tree
Showing 50 changed files with 72 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"visTypeTable": "src/plugins/vis_type_table",
"visTypeTagCloud": "src/plugins/vis_type_tagcloud",
"visTypeTimeseries": ["src/legacy/core_plugins/vis_type_timeseries", "src/plugins/vis_type_timeseries"],
"visTypeVega": "src/legacy/core_plugins/vis_type_vega",
"visTypeVega": "src/plugins/vis_type_vega",
"visTypeVislib": "src/legacy/core_plugins/vis_type_vislib",
"visTypeXy": "src/legacy/core_plugins/vis_type_xy",
"visualizations": "src/plugins/visualizations",
Expand Down
5 changes: 4 additions & 1 deletion packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ export function getWebpackConfig(bundle: Bundle, worker: WorkerConfig) {

module: {
// no parse rules for a few known large packages which have no require() statements
// or which have require() statements that should be ignored because the file is
// already bundled with all its necessary depedencies
noParse: [
/[\///]node_modules[\///]elasticsearch-browser[\///]/,
/[\///]node_modules[\///]lodash[\///]index\.js/,
/[\///]node_modules[\///]lodash[\///]index\.js$/,
/[\///]node_modules[\///]vega-lib[\///]build[\///]vega\.js$/,
],

rules: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import Bluebird from 'bluebird';
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import $ from 'jquery';
import { createVegaVisualization } from '../vega_visualization';
// Will be replaced with new path when tests are moved
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { createVegaVisualization } from '../../../../../../plugins/vis_type_vega/public/vega_visualization';
import { ImageComparator } from 'test_utils/image_comparator';

import vegaliteGraph from '!!raw-loader!./vegalite_graph.hjson';
Expand All @@ -35,24 +37,34 @@ import vegaTooltipGraph from '!!raw-loader!./vega_tooltip_test.hjson';

import vegaMapGraph from '!!raw-loader!./vega_map_test.hjson';
import vegaMapImage256 from './vega_map_image_256.png';
// Will be replaced with new path when tests are moved
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { VegaParser } from '../../../../../../plugins/vis_type_vega/public/data_model/vega_parser';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { SearchCache } from '../../../../../../plugins/vis_type_vega/public/data_model/search_cache';

import { VegaParser } from '../data_model/vega_parser';
import { SearchCache } from '../data_model/search_cache';

import { createVegaTypeDefinition } from '../vega_type';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { createVegaTypeDefinition } from '../../../../../../plugins/vis_type_vega/public/vega_type';
// TODO This is an integration test and thus requires a running platform. When moving to the new platform,
// this test has to be migrated to the newly created integration test environment.
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { npStart } from 'ui/new_platform';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { BaseVisType } from '../../../../../plugins/visualizations/public/vis_types/base_vis_type';
import { BaseVisType } from '../../../../../../plugins/visualizations/public/vis_types/base_vis_type';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ExprVis } from '../../../../../plugins/visualizations/public/expressions/vis';
import { setInjectedVars } from '../services';
import { ExprVis } from '../../../../../../plugins/visualizations/public/expressions/vis';

import {
setInjectedVars,
setData,
setSavedObjects,
setNotifications,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../../plugins/vis_type_vega/public/services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { setInjectedVarFunc } from '../../../../../plugins/maps_legacy/public/kibana_services';
import { setInjectedVarFunc } from '../../../../../../plugins/maps_legacy/public/kibana_services';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { ServiceSettings } from '../../../../../plugins/maps_legacy/public/map/service_settings';
import { ServiceSettings } from '../../../../../../plugins/maps_legacy/public/map/service_settings';

const THRESHOLD = 0.1;
const PIXEL_DIFF = 30;
Expand All @@ -70,6 +82,9 @@ describe('VegaVisualizations', () => {
enableExternalUrls: true,
esShardTimeout: 10000,
});
setData(npStart.plugins.data);
setSavedObjects(npStart.core.savedObjects);
setNotifications(npStart.core.notifications);

beforeEach(ngMock.module('kibana'));
beforeEach(
Expand Down Expand Up @@ -111,9 +126,6 @@ describe('VegaVisualizations', () => {
timefilter: {},
},
},
__LEGACY: {
esClient: npStart.plugins.data.search.__LEGACY.esClient,
},
},
},
};
Expand Down
55 changes: 0 additions & 55 deletions src/legacy/core_plugins/vis_type_vega/index.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/legacy/core_plugins/vis_type_vega/package.json

This file was deleted.

25 changes: 0 additions & 25 deletions src/legacy/core_plugins/vis_type_vega/public/index.ts

This file was deleted.

38 changes: 0 additions & 38 deletions src/legacy/core_plugins/vis_type_vega/public/legacy.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ import {
NavigationPublicPluginSetup,
NavigationPublicPluginStart,
} from '../../../../plugins/navigation/public';
import { VisTypeVegaSetup } from '../../../../plugins/vis_type_vega/public';
import { DiscoverSetup, DiscoverStart } from '../../../../plugins/discover/public';
import {
SavedObjectsManagementPluginSetup,
Expand Down Expand Up @@ -88,7 +87,6 @@ export interface PluginsSetup {
usageCollection: UsageCollectionSetup;
advancedSettings: AdvancedSettingsSetup;
management: ManagementSetup;
visTypeVega: VisTypeVegaSetup;
discover: DiscoverSetup;
visualizations: VisualizationsSetup;
telemetry?: TelemetryPluginSetup;
Expand Down
1 change: 1 addition & 0 deletions src/legacy/ui/ui_exports/ui_export_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const UI_EXPORT_DEFAULTS = {
webpackNoParseRules: [
/node_modules[\/\\](angular|elasticsearch-browser)[\/\\]/,
/node_modules[\/\\](mocha|moment)[\/\\]/,
/node_modules[\/\\]vega-lib[\/\\]build[\/\\]vega\.js$/,
],

webpackAliases: {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/vis_type_vega/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"id": "visTypeVega",
"version": "kibana",
"server": true,
"ui": true
"ui": true,
"requiredPlugins": ["data", "visualizations", "mapsLegacy", "expressions"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* under the License.
*/

import { createGetterSetter } from '../../../../../plugins/kibana_utils/public';
import { DataPublicPluginStart } from '../../../../../plugins/data/public';
import { createGetterSetter } from '../../../kibana_utils/public';
import { DataPublicPluginStart } from '../../../data/public';
import { IUiSettingsClient, NotificationsStart, SavedObjectsStart } from 'kibana/public';
import { dataPluginMock } from '../../../../../plugins/data/public/mocks';
import { coreMock } from '../../../../../core/public/mocks';
import { dataPluginMock } from '../../../data/public/mocks';
import { coreMock } from '../../../../core/public/mocks';

export const [getData, setData] = createGetterSetter<DataPublicPluginStart>('Data');
setData(dataPluginMock.createStartContract());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@import 'src/legacy/ui/public/styles/styling_constants';

// Prefix all styles with "vga" to avoid conflicts.
// Examples
// vgaChart
Expand Down
20 changes: 4 additions & 16 deletions src/plugins/vis_type_vega/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,8 @@

import { PluginInitializerContext } from 'kibana/public';
import { ConfigSchema } from '../config';
import { VegaPlugin as Plugin } from './plugin';

export const plugin = (initializerContext: PluginInitializerContext<ConfigSchema>) => ({
setup() {
return {
/**
* The configuration is temporarily exposed to allow the legacy vega plugin to consume
* the setting. Once the vega plugin is migrated completely, this will become an implementation
* detail.
* @deprecated
*/
config: initializerContext.config.get(),
};
},
start() {},
});

export type VisTypeVegaSetup = ReturnType<ReturnType<typeof plugin>['setup']>;
export function plugin(initializerContext: PluginInitializerContext<ConfigSchema>) {
return new Plugin(initializerContext);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../../core/public';
import { Plugin as ExpressionsPublicPlugin } from '../../../../plugins/expressions/public';
import { Plugin as DataPublicPlugin } from '../../../../plugins/data/public';
import { VisualizationsSetup } from '../../../../plugins/visualizations/public';
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { Plugin as ExpressionsPublicPlugin } from '../../expressions/public';
import { Plugin as DataPublicPlugin } from '../../data/public';
import { VisualizationsSetup } from '../../visualizations/public';
import {
setNotifications,
setData,
Expand All @@ -30,8 +30,10 @@ import {

import { createVegaFn } from './vega_fn';
import { createVegaTypeDefinition } from './vega_type';
import { VisTypeVegaSetup } from '../../../../plugins/vis_type_vega/public';
import { IServiceSettings } from '../../../../plugins/maps_legacy/public';
import { IServiceSettings } from '../../maps_legacy/public';
import { ConfigSchema } from '../config';

import './index.scss';

/** @internal */
export interface VegaVisualizationDependencies {
Expand All @@ -47,7 +49,6 @@ export interface VegaPluginSetupDependencies {
expressions: ReturnType<ExpressionsPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
data: ReturnType<DataPublicPlugin['setup']>;
visTypeVega: VisTypeVegaSetup;
mapsLegacy: any;
}

Expand All @@ -58,18 +59,18 @@ export interface VegaPluginStartDependencies {

/** @internal */
export class VegaPlugin implements Plugin<Promise<void>, void> {
initializerContext: PluginInitializerContext;
initializerContext: PluginInitializerContext<ConfigSchema>;

constructor(initializerContext: PluginInitializerContext) {
constructor(initializerContext: PluginInitializerContext<ConfigSchema>) {
this.initializerContext = initializerContext;
}

public async setup(
core: CoreSetup,
{ data, expressions, visualizations, visTypeVega, mapsLegacy }: VegaPluginSetupDependencies
{ data, expressions, visualizations, mapsLegacy }: VegaPluginSetupDependencies
) {
setInjectedVars({
enableExternalUrls: visTypeVega.config.enableExternalUrls,
enableExternalUrls: this.initializerContext.config.get().enableExternalUrls,
esShardTimeout: core.injectedMetadata.getInjectedVar('esShardTimeout') as number,
emsTileLayerId: core.injectedMetadata.getInjectedVar('emsTileLayerId', true),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*/

import { SavedObjectsStart } from 'kibana/public';
import { NotificationsStart } from 'src/core/public';
import { DataPublicPluginStart } from '../../../../plugins/data/public';
import { createGetterSetter } from '../../../../plugins/kibana_utils/public';
import { IUiSettingsClient } from '../../../../core/public';
import { NotificationsStart, IUiSettingsClient } from 'src/core/public';
import { DataPublicPluginStart } from '../../data/public';
import { createGetterSetter } from '../../kibana_utils/public';

export const [getData, setData] = createGetterSetter<DataPublicPluginStart>('Data');

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

import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import {
ExpressionFunctionDefinition,
KibanaContext,
Render,
} from '../../../../plugins/expressions/public';
import { ExpressionFunctionDefinition, KibanaContext, Render } from '../../expressions/public';
import { VegaVisualizationDependencies } from './plugin';
import { createVegaRequestHandler } from './vega_request_handler';

Expand Down
Loading

0 comments on commit 2ace269

Please sign in to comment.