[NP] Vega migration (#63849) (#64426)

* 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 <elasticmachine@users.noreply.github.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
This commit is contained in:
Maryia Lapata 2020-04-24 18:27:17 +03:00 committed by GitHub
parent 8bad56c993
commit a960dae27f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 72 additions and 194 deletions

View file

@ -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",

View file

@ -136,9 +136,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: [

View file

@ -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';
@ -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;
@ -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(
@ -111,9 +126,6 @@ describe('VegaVisualizations', () => {
timefilter: {},
},
},
__LEGACY: {
esClient: npStart.plugins.data.search.__LEGACY.esClient,
},
},
},
};

View file

@ -1,55 +0,0 @@
/*
* 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 { resolve } from 'path';
import { Legacy } from 'kibana';
import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types';
const vegaPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) =>
new Plugin({
id: 'vis_type_vega',
deprecations: ({ rename }: { rename: any }) => [
rename('vega.enabled', 'vis_type_vega.enabled'),
],
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
enableExternalUrls: Joi.boolean().default(false),
}).default();
},
require: ['kibana', 'elasticsearch'],
publicDir: resolve(__dirname, 'public'),
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars: server => {
const serverConfig = server.config();
const mapConfig: Record<string, any> = serverConfig.get('map');
return {
emsTileLayerId: mapConfig.emsTileLayerId,
};
},
},
init: (server: Legacy.Server) => ({}),
} as Legacy.PluginSpecOptions);
// eslint-disable-next-line import/no-default-export
export default vegaPluginInitializer;

View file

@ -1,6 +0,0 @@
{
"author": "Yuri Astrakhan<yuri@elastic.co>",
"name": "vega",
"version": "kibana"
}

View file

@ -1,25 +0,0 @@
/*
* 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 '../../../../core/public';
import { VegaPlugin as Plugin } from './plugin';
export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin(initializerContext);
}

View file

@ -1,38 +0,0 @@
/*
* 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 } from 'ui/new_platform';
import { VegaPluginSetupDependencies, VegaPluginStartDependencies } from './plugin';
import { plugin } from '.';
const setupPlugins: Readonly<VegaPluginSetupDependencies> = {
...npSetup.plugins,
visualizations: npSetup.plugins.visualizations,
mapsLegacy: npSetup.plugins.mapsLegacy,
};
const startPlugins: Readonly<VegaPluginStartDependencies> = {
...npStart.plugins,
};
const pluginInstance = plugin({} as PluginInitializerContext);
export const setup = pluginInstance.setup(npSetup.core, setupPlugins);
export const start = pluginInstance.start(npStart.core, startPlugins);

View file

@ -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,
@ -88,7 +87,6 @@ export interface PluginsSetup {
usageCollection: UsageCollectionSetup;
advancedSettings: AdvancedSettingsSetup;
management: ManagementSetup;
visTypeVega: VisTypeVegaSetup;
discover: DiscoverSetup;
visualizations: VisualizationsSetup;
telemetry?: TelemetryPluginSetup;

View file

@ -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: {

View file

@ -2,5 +2,6 @@
"id": "visTypeVega",
"version": "kibana",
"server": true,
"ui": true
"ui": true,
"requiredPlugins": ["data", "visualizations", "mapsLegacy", "expressions"]
}

View file

@ -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());

View file

@ -1,5 +1,3 @@
@import 'src/legacy/ui/public/styles/styling_constants';
// Prefix all styles with "vga" to avoid conflicts.
// Examples
// vgaChart

View file

@ -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);
}

View file

@ -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,
@ -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 {
@ -47,7 +49,6 @@ export interface VegaPluginSetupDependencies {
expressions: ReturnType<ExpressionsPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
data: ReturnType<DataPublicPlugin['setup']>;
visTypeVega: VisTypeVegaSetup;
mapsLegacy: any;
}
@ -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),
});

View file

@ -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');

View file

@ -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';

View file

@ -17,9 +17,7 @@
* under the License.
*/
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getSearchService } from '../../../../plugins/data/public/services';
import { Filter, esQuery, TimeRange, Query } from '../../../../plugins/data/public';
import { Filter, esQuery, TimeRange, Query } from '../../data/public';
// @ts-ignore
import { VegaParser } from './data_model/vega_parser';
@ -30,6 +28,7 @@ import { TimeCache } from './data_model/time_cache';
import { VegaVisualizationDependencies } from './plugin';
import { VisParams } from './vega_fn';
import { getData } from './services';
interface VegaRequestHandlerParams {
query: Query;
@ -43,12 +42,18 @@ export function createVegaRequestHandler({
core: { uiSettings },
serviceSettings,
}: VegaVisualizationDependencies) {
const { esClient } = getSearchService().__LEGACY;
const searchCache = new SearchCache(esClient, { max: 10, maxAge: 4 * 1000 });
let searchCache: SearchCache | undefined;
const { timefilter } = data.query.timefilter;
const timeCache = new TimeCache(timefilter, 3 * 1000);
return ({ timeRange, filters, query, visParams }: VegaRequestHandlerParams) => {
if (!searchCache) {
searchCache = new SearchCache(getData().search.__LEGACY.esClient, {
max: 10,
maxAge: 4 * 1000,
});
}
timeCache.setTimeRange(timeRange);
const esQueryConfigs = esQuery.getEsQueryConfig(uiSettings);

View file

@ -18,10 +18,10 @@
*/
import { i18n } from '@kbn/i18n';
import { DefaultEditorSize } from '../../../../plugins/vis_default_editor/public';
import { DefaultEditorSize } from '../../vis_default_editor/public';
import { VegaVisualizationDependencies } from './plugin';
import { VegaVisEditor } from './components';
import { defaultFeedbackMessage } from '../../../../plugins/kibana_utils/public';
import { defaultFeedbackMessage } from '../../kibana_utils/public';
import { createVegaRequestHandler } from './vega_request_handler';
// @ts-ignore

View file

@ -26,7 +26,7 @@ import { Utils } from '../data_model/utils';
import { VISUALIZATION_COLORS } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { TooltipHandler } from './vega_tooltip';
import { esFilters } from '../../../../../plugins/data/public';
import { esFilters } from '../../../data/public';
import { getEnableExternalUrls } from '../services';

View file

@ -19,7 +19,7 @@
import L from 'leaflet';
import 'leaflet-vega';
import { KibanaMapLayer } from '../../../../../plugins/maps_legacy/public';
import { KibanaMapLayer } from '../../../maps_legacy/public';
export class VegaMapLayer extends KibanaMapLayer {
constructor(spec, options) {

View file

@ -21,7 +21,7 @@ import * as vega from 'vega-lib';
import { i18n } from '@kbn/i18n';
import { VegaBaseView } from './vega_base_view';
import { VegaMapLayer } from './vega_map_layer';
import { KibanaMap } from '../../../../../plugins/maps_legacy/public';
import { KibanaMap } from '../../../maps_legacy/public';
import { getEmsTileLayerId, getUISettings } from '../services';
export class VegaMapView extends VegaBaseView {