Skip to content

Commit

Permalink
Vislib replacement toggle (#56439)
Browse files Browse the repository at this point in the history
* Add new vislib replacement plugin shell
* Add config to toggle new vislib replacement
  • Loading branch information
nickofthyme committed Feb 4, 2020
1 parent 585fce8 commit ccae1a4
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions .sass-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
32 changes: 26 additions & 6 deletions src/legacy/core_plugins/vis_type_vislib/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
56 changes: 56 additions & 0 deletions src/legacy/core_plugins/vis_type_xy/index.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 { 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;
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/vis_type_xy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "visTypeXy",
"version": "kibana"
}
25 changes: 25 additions & 0 deletions src/legacy/core_plugins/vis_type_xy/public/index.ts
Original file line number Diff line number Diff line change
@@ -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);
}
44 changes: 44 additions & 0 deletions src/legacy/core_plugins/vis_type_xy/public/legacy.ts
Original file line number Diff line number Diff line change
@@ -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);
82 changes: 82 additions & 0 deletions src/legacy/core_plugins/vis_type_xy/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit ccae1a4

Please sign in to comment.