Vislib replacement toggle (#56439) (#56719)

* Add new vislib replacement plugin shell
* Add config to toggle new vislib replacement
This commit is contained in:
Nick Partridge 2020-02-04 08:04:27 -06:00 committed by GitHub
parent af577cc79c
commit 68b9c7f3d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 243 additions and 7 deletions

View file

@ -22,7 +22,10 @@
"interpreter": "src/legacy/core_plugins/interpreter",
"kbn": "src/legacy/core_plugins/kibana",
"kbnDocViews": "src/legacy/core_plugins/kbn_doc_views",
"management": ["src/legacy/core_plugins/management", "src/plugins/management"],
"management": [
"src/legacy/core_plugins/management",
"src/plugins/management"
],
"kibana_react": "src/legacy/core_plugins/kibana_react",
"kibana-react": "src/plugins/kibana_react",
"kibana_utils": "src/plugins/kibana_utils",
@ -43,6 +46,7 @@
"visTypeTimeseries": ["src/legacy/core_plugins/vis_type_timeseries", "src/plugins/vis_type_timeseries"],
"visTypeVega": "src/legacy/core_plugins/vis_type_vega",
"visTypeVislib": "src/legacy/core_plugins/vis_type_vislib",
"visTypeXy": "src/legacy/core_plugins/vis_type_xy",
"visualizations": [
"src/plugins/visualizations",
"src/legacy/core_plugins/visualizations"

View file

@ -3,6 +3,7 @@ files:
- 'src/legacy/core_plugins/metrics/**/*.s+(a|c)ss'
- 'src/legacy/core_plugins/timelion/**/*.s+(a|c)ss'
- 'src/legacy/core_plugins/vis_type_vislib/**/*.s+(a|c)ss'
- 'src/legacy/core_plugins/vis_type_xy/**/*.s+(a|c)ss'
- 'x-pack/legacy/plugins/rollup/**/*.s+(a|c)ss'
- 'x-pack/legacy/plugins/security/**/*.s+(a|c)ss'
- 'x-pack/legacy/plugins/canvas/**/*.s+(a|c)ss'

View file

@ -39,6 +39,7 @@ import {
createGoalVisTypeDefinition,
} from './vis_type_vislib_vis_types';
import { ChartsPluginSetup } from '../../../../plugins/charts/public';
import { ConfigSchema as VisTypeXyConfigSchema } from '../../vis_type_xy';
export interface VisTypeVislibDependencies {
uiSettings: IUiSettingsClient;
@ -72,11 +73,7 @@ export class VisTypeVislibPlugin implements Plugin<Promise<void>, void> {
uiSettings: core.uiSettings,
charts,
};
expressions.registerFunction(createVisTypeVislibVisFn);
expressions.registerFunction(createPieVisFn);
[
const vislibTypes = [
createHistogramVisTypeDefinition,
createLineVisTypeDefinition,
createPieVisTypeDefinition,
@ -85,7 +82,30 @@ export class VisTypeVislibPlugin implements Plugin<Promise<void>, void> {
createHorizontalBarVisTypeDefinition,
createGaugeVisTypeDefinition,
createGoalVisTypeDefinition,
].forEach(vis => visualizations.types.createBaseVisualization(vis(visualizationDependencies)));
];
const vislibFns = [createVisTypeVislibVisFn, createPieVisFn];
const visTypeXy = core.injectedMetadata.getInjectedVar('visTypeXy') as
| VisTypeXyConfigSchema['visTypeXy']
| undefined;
// if visTypeXy plugin is disabled it's config will be undefined
if (!visTypeXy || !visTypeXy.enabled) {
const convertedTypes: any[] = [];
const convertedFns: any[] = [];
// Register legacy vislib types that have been converted
convertedFns.forEach(expressions.registerFunction);
convertedTypes.forEach(vis =>
visualizations.types.createBaseVisualization(vis(visualizationDependencies))
);
}
// Register non-converted types
vislibFns.forEach(expressions.registerFunction);
vislibTypes.forEach(vis =>
visualizations.types.createBaseVisualization(vis(visualizationDependencies))
);
}
public start(core: CoreStart, deps: VisTypeVislibPluginStartDependencies) {

View file

@ -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 { resolve } from 'path';
import { Legacy } from 'kibana';
import { LegacyPluginApi, LegacyPluginInitializer } from '../../types';
export interface ConfigSchema {
visTypeXy: {
enabled: boolean;
};
}
const visTypeXyPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) =>
new Plugin({
id: 'visTypeXy',
require: ['kibana', 'elasticsearch', 'visualizations', 'interpreter', 'data'],
publicDir: resolve(__dirname, 'public'),
uiExports: {
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars(server): ConfigSchema {
const config = server.config();
return {
visTypeXy: {
enabled: config.get('visTypeXy.enabled') as boolean,
},
};
},
},
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(false),
}).default();
},
} as Legacy.PluginSpecOptions);
// eslint-disable-next-line import/no-default-export
export default visTypeXyPluginInitializer;

View file

@ -0,0 +1,4 @@
{
"name": "visTypeXy",
"version": "kibana"
}

View file

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

View file

@ -0,0 +1,44 @@
/*
* 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 { npSetup, npStart } from 'ui/new_platform';
import { PluginInitializerContext } from 'kibana/public';
import { plugin } from '.';
import { VisTypeXyPluginSetupDependencies, VisTypeXyPluginStartDependencies } from './plugin';
import {
setup as visualizationsSetup,
start as visualizationsStart,
} from '../../visualizations/public/np_ready/public/legacy';
const setupPlugins: Readonly<VisTypeXyPluginSetupDependencies> = {
expressions: npSetup.plugins.expressions,
visualizations: visualizationsSetup,
charts: npSetup.plugins.charts,
};
const startPlugins: Readonly<VisTypeXyPluginStartDependencies> = {
expressions: npStart.plugins.expressions,
visualizations: visualizationsStart,
};
const pluginInstance = plugin({} as PluginInitializerContext);
export const setup = pluginInstance.setup(npSetup.core, setupPlugins);
export const start = pluginInstance.start(npStart.core, startPlugins);

View file

@ -0,0 +1,82 @@
/*
* 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 {
CoreSetup,
CoreStart,
Plugin,
IUiSettingsClient,
PluginInitializerContext,
} from 'kibana/public';
import { Plugin as ExpressionsPublicPlugin } from '../../../../plugins/expressions/public';
import { VisualizationsSetup, VisualizationsStart } from '../../visualizations/public';
import { ChartsPluginSetup } from '../../../../plugins/charts/public';
export interface VisTypeXyDependencies {
uiSettings: IUiSettingsClient;
charts: ChartsPluginSetup;
}
/** @internal */
export interface VisTypeXyPluginSetupDependencies {
expressions: ReturnType<ExpressionsPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
charts: ChartsPluginSetup;
}
/** @internal */
export interface VisTypeXyPluginStartDependencies {
expressions: ReturnType<ExpressionsPublicPlugin['start']>;
visualizations: VisualizationsStart;
}
type VisTypeXyCoreSetup = CoreSetup<VisTypeXyPluginStartDependencies>;
/** @internal */
export class VisTypeXyPlugin implements Plugin<Promise<void>, void> {
constructor(public initializerContext: PluginInitializerContext) {}
public async setup(
core: VisTypeXyCoreSetup,
{ expressions, visualizations, charts }: VisTypeXyPluginSetupDependencies
) {
// eslint-disable-next-line no-console
console.warn(
'The visTypeXy plugin is enabled\n\n',
'This may negatively alter existing vislib visualization configurations if saved.'
);
const visualizationDependencies: Readonly<VisTypeXyDependencies> = {
uiSettings: core.uiSettings,
charts,
};
const visTypeDefinitions: any[] = [];
const visFunctions: any = [];
visFunctions.forEach((fn: any) => expressions.registerFunction(fn));
visTypeDefinitions.forEach((vis: any) =>
visualizations.types.createBaseVisualization(vis(visualizationDependencies))
);
}
public start(core: CoreStart, deps: VisTypeXyPluginStartDependencies) {
// nothing to do here
}
}