Skip to content

Commit

Permalink
Migrate vega and graph configs to new platform (elastic#57011)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Feb 14, 2020
1 parent c23d770 commit 139f4de
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ us improve your user experience. Your data is never shared with anyone. Set to
`false` to disable telemetry capabilities entirely. You can alternatively opt
out through the *Advanced Settings* in {kib}.

`vega.enableExternalUrls:`:: *Default: false* Set this value to true to allow Vega to use any URL to access external data sources and images. If false, Vega can only get data from Elasticsearch.
`vis_type_vega.enableExternalUrls:`:: *Default: false* Set this value to true to allow Vega to use any URL to access external data sources and images. If false, Vega can only get data from Elasticsearch.

`xpack.license_management.enabled`:: *Default: true* Set this value to false to
disable the License Management user interface.
Expand Down
7 changes: 0 additions & 7 deletions src/legacy/core_plugins/vis_type_vega/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,10 @@ const vegaPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPlugin

return {
emsTileLayerId: mapConfig.emsTileLayerId,
enableExternalUrls: serverConfig.get('vega.enableExternalUrls'),
};
},
},
init: (server: Legacy.Server) => ({}),
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
enableExternalUrls: Joi.boolean().default(false),
}).default();
},
} as Legacy.PluginSpecOptions);

// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { createVegaTypeDefinition } from '../vega_type';
// 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';
import { setInjectedVars } from '../services';

const THRESHOLD = 0.1;
const PIXEL_DIFF = 30;
Expand All @@ -60,6 +61,12 @@ describe('VegaVisualizations', () => {
let vegaVisualizationDependencies;
let visRegComplete = false;

setInjectedVars({
emsTileLayerId: {},
enableExternalUrls: true,
esShardTimeout: 10000,
});

beforeEach(ngMock.module('kibana'));
beforeEach(
ngMock.inject((Private, $injector) => {
Expand Down
5 changes: 2 additions & 3 deletions src/legacy/core_plugins/vis_type_vega/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ import { LegacyDependenciesPlugin } from './shim';
import { plugin } from '.';

const setupPlugins: Readonly<VegaPluginSetupDependencies> = {
expressions: npSetup.plugins.expressions,
...npSetup.plugins,
visualizations: visualizationsSetup,
data: npSetup.plugins.data,

// Temporary solution
// It will be removed when all dependent services are migrated to the new platform.
__LEGACY: new LegacyDependenciesPlugin(),
};

const startPlugins: Readonly<VegaPluginStartDependencies> = {
data: npStart.plugins.data,
...npStart.plugins,
};

const pluginInstance = plugin({} as PluginInitializerContext);
Expand Down
6 changes: 4 additions & 2 deletions src/legacy/core_plugins/vis_type_vega/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {

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

/** @internal */
export interface VegaVisualizationDependencies extends LegacyDependenciesPluginSetup {
Expand All @@ -45,6 +46,7 @@ export interface VegaPluginSetupDependencies {
expressions: ReturnType<ExpressionsPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
data: ReturnType<DataPublicPlugin['setup']>;
visTypeVega: VisTypeVegaSetup;
__LEGACY: LegacyDependenciesPlugin;
}

Expand All @@ -63,11 +65,11 @@ export class VegaPlugin implements Plugin<Promise<void>, void> {

public async setup(
core: CoreSetup,
{ data, expressions, visualizations, __LEGACY }: VegaPluginSetupDependencies
{ data, expressions, visualizations, visTypeVega, __LEGACY }: VegaPluginSetupDependencies
) {
setInjectedVars({
enableExternalUrls: visTypeVega.config.enableExternalUrls,
esShardTimeout: core.injectedMetadata.getInjectedVar('esShardTimeout') as number,
enableExternalUrls: core.injectedMetadata.getInjectedVar('enableExternalUrls') as boolean,
emsTileLayerId: core.injectedMetadata.getInjectedVar('emsTileLayerId', true),
});
setUISettings(core.uiSettings);
Expand Down
2 changes: 2 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
NavigationPublicPluginSetup,
NavigationPublicPluginStart,
} from '../../../../plugins/navigation/public';
import { VisTypeVegaSetup } from '../../../../plugins/vis_type_vega/public';

export interface PluginsSetup {
bfetch: BfetchPublicSetup;
Expand All @@ -61,6 +62,7 @@ export interface PluginsSetup {
usageCollection: UsageCollectionSetup;
advancedSettings: AdvancedSettingsSetup;
management: ManagementSetup;
visTypeVega: VisTypeVegaSetup;
telemetry?: TelemetryPluginSetup;
}

Expand Down
27 changes: 27 additions & 0 deletions src/plugins/vis_type_vega/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
enableExternalUrls: schema.boolean({ defaultValue: false }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
6 changes: 6 additions & 0 deletions src/plugins/vis_type_vega/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "visTypeVega",
"version": "kibana",
"server": true,
"ui": true
}
38 changes: 38 additions & 0 deletions src/plugins/vis_type_vega/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 { ConfigSchema } from '../config';

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']>;
38 changes: 38 additions & 0 deletions src/plugins/vis_type_vega/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 { PluginConfigDescriptor } from 'kibana/server';

import { configSchema, ConfigSchema } from '../config';

export const config: PluginConfigDescriptor<ConfigSchema> = {
exposeToBrowser: {
enableExternalUrls: true,
},
schema: configSchema,
deprecations: ({ renameFromRoot }) => [
renameFromRoot('vega.enableExternalUrls', 'vis_type_vega.enableExternalUrls'),
renameFromRoot('vega.enabled', 'vis_type_vega.enabled'),
],
};

export const plugin = () => ({
setup() {},
start() {},
});
8 changes: 0 additions & 8 deletions x-pack/legacy/plugins/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ export const graph: LegacyPluginInitializer = kibana => {
},

init(server) {
server.injectUiAppVars('graph', () => {
const config = server.config();
return {
graphSavePolicy: config.get('xpack.graph.savePolicy'),
canEditDrillDownUrls: config.get('xpack.graph.canEditDrillDownUrls'),
};
});

server.plugins.xpack_main.registerFeature({
id: 'graph',
name: i18n.translate('xpack.graph.featureRegistry.graphFeatureName', {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/graph/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import { npSetup, npStart } from 'ui/new_platform';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';
import { GraphPlugin } from './plugin';
import { GraphSetup } from '../../../../plugins/graph/public';

type XpackNpSetupDeps = typeof npSetup.plugins & {
licensing: LicensingPluginSetup;
graph: GraphSetup;
};

(async () => {
Expand Down
10 changes: 5 additions & 5 deletions x-pack/legacy/plugins/graph/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../src/plugins/navigation/public';
import { initAngularBootstrap } from '../../../../../src/plugins/kibana_legacy/public';
import { GraphSetup } from '../../../../plugins/graph/public';

export interface GraphPluginStartDependencies {
npData: ReturnType<DataPlugin['start']>;
Expand All @@ -19,14 +20,15 @@ export interface GraphPluginStartDependencies {

export interface GraphPluginSetupDependencies {
licensing: LicensingPluginSetup;
graph: GraphSetup;
}

export class GraphPlugin implements Plugin {
private navigationStart: NavigationStart | null = null;
private npDataStart: ReturnType<DataPlugin['start']> | null = null;
private savedObjectsClient: SavedObjectsClientContract | null = null;

setup(core: CoreSetup, { licensing }: GraphPluginSetupDependencies) {
setup(core: CoreSetup, { licensing, graph }: GraphPluginSetupDependencies) {
initAngularBootstrap();
core.application.register({
id: 'graph',
Expand All @@ -41,10 +43,8 @@ export class GraphPlugin implements Plugin {
savedObjectsClient: this.savedObjectsClient!,
addBasePath: core.http.basePath.prepend,
getBasePath: core.http.basePath.get,
canEditDrillDownUrls: core.injectedMetadata.getInjectedVar(
'canEditDrillDownUrls'
) as boolean,
graphSavePolicy: core.injectedMetadata.getInjectedVar('graphSavePolicy') as string,
canEditDrillDownUrls: graph.config.canEditDrillDownUrls,
graphSavePolicy: graph.config.savePolicy,
storage: new Storage(window.localStorage),
capabilities: contextCore.application.capabilities.graph,
coreStart: contextCore,
Expand Down
23 changes: 23 additions & 0 deletions x-pack/plugins/graph/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
savePolicy: schema.oneOf(
[
schema.literal('none'),
schema.literal('config'),
schema.literal('configAndData'),
schema.literal('configAndDataWithConsent'),
],
{ defaultValue: 'configAndData' }
),
canEditDrillDownUrls: schema.boolean({ defaultValue: true }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
7 changes: 6 additions & 1 deletion x-pack/plugins/graph/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginInitializerContext } from 'kibana/public';
import { GraphPlugin } from './plugin';
import { ConfigSchema } from '../config';

export const plugin = () => new GraphPlugin();
export const plugin = (initializerContext: PluginInitializerContext<ConfigSchema>) =>
new GraphPlugin(initializerContext);

export { GraphSetup } from './plugin';
18 changes: 17 additions & 1 deletion x-pack/plugins/graph/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@
import { i18n } from '@kbn/i18n';
import { CoreSetup, CoreStart } from 'kibana/public';
import { Plugin } from 'src/core/public';
import { PluginInitializerContext } from 'kibana/public';
import { toggleNavLink } from './services/toggle_nav_link';
import { LicensingPluginSetup } from '../../licensing/public';
import { checkLicense } from '../common/check_license';
import {
FeatureCatalogueCategory,
HomePublicPluginSetup,
} from '../../../../src/plugins/home/public';
import { ConfigSchema } from '../config';

export interface GraphPluginSetupDependencies {
licensing: LicensingPluginSetup;
home?: HomePublicPluginSetup;
}

export class GraphPlugin implements Plugin {
export class GraphPlugin implements Plugin<{ config: Readonly<ConfigSchema> }, void> {
private licensing: LicensingPluginSetup | null = null;

constructor(private initializerContext: PluginInitializerContext<ConfigSchema>) {}

setup(core: CoreSetup, { licensing, home }: GraphPluginSetupDependencies) {
this.licensing = licensing;

Expand All @@ -39,6 +43,16 @@ export class GraphPlugin implements Plugin {
category: FeatureCatalogueCategory.DATA,
});
}

return {
/**
* The configuration is temporarily exposed to allow the legacy graph plugin to consume
* the setting. Once the graph plugin is migrated completely, this will become an implementation
* detail.
* @deprecated
*/
config: this.initializerContext.config.get(),
};
}

start(core: CoreStart) {
Expand All @@ -52,3 +66,5 @@ export class GraphPlugin implements Plugin {

stop() {}
}

export type GraphSetup = ReturnType<GraphPlugin['setup']>;
11 changes: 11 additions & 0 deletions x-pack/plugins/graph/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginConfigDescriptor } from 'kibana/server';

import { configSchema, ConfigSchema } from '../config';
import { GraphPlugin } from './plugin';

export const plugin = () => new GraphPlugin();

export const config: PluginConfigDescriptor<ConfigSchema> = {
exposeToBrowser: {
canEditDrillDownUrls: true,
savePolicy: true,
},
schema: configSchema,
};

0 comments on commit 139f4de

Please sign in to comment.