Skip to content

Commit

Permalink
[Markdown] Shim new platform - cleanup plugin (#41760)
Browse files Browse the repository at this point in the history
* [Markdown] Shim new platform - cleanup plugin
  • Loading branch information
alexwizp authored Jul 31, 2019
1 parent c49ad02 commit 4d23d3c
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 53 deletions.
30 changes: 19 additions & 11 deletions src/legacy/core_plugins/vis_type_markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,27 @@
*/

import { resolve } from 'path';
import { Legacy } from '../../../../kibana';
import { LegacyPluginApi } from '../../plugin_discovery/types';
import { Legacy } from 'kibana';

// eslint-disable-next-line import/no-default-export
export default function MarkdownVisTypePlugin(kibana: LegacyPluginApi) {
const config: Legacy.PluginSpecOptions = {
id: 'vis_type_markdown',
require: ['data', 'visualizations'],
import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types';

const markdownPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) =>
new Plugin({
id: 'markdown_vis',
require: ['kibana', 'elasticsearch', 'visualizations', 'interpreter', 'data'],
publicDir: resolve(__dirname, 'public'),
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
hacks: ['plugins/vis_type_markdown/index'],
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars: server => ({}),
},
};
init: (server: Legacy.Server) => ({}),
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
} as Legacy.PluginSpecOptions);

return new kibana.Plugin(config);
}
// eslint-disable-next-line import/no-default-export
export default markdownPluginInitializer;
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/vis_type_markdown/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "vis_type_markdown",
"name": "markdown_vis",
"version": "kibana"
}
40 changes: 4 additions & 36 deletions src/legacy/core_plugins/vis_type_markdown/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,9 @@
* under the License.
*/

// @ts-ignore
import { markdownVis } from './markdown_vis';
// @ts-ignore
import { kibanaMarkdown } from './markdown_fn';
import { PluginInitializerContext } from '../../../../core/public';
import { MarkdownPlugin as Plugin } from './plugin';

// @ts-ignore
import { functionsRegistry } from '../../interpreter/public/registries';
import {
visualizations as visualizationsService,
VisualizationsSetup,
} from '../../visualizations/public';

export interface SetupDeps {
visualizations: VisualizationsSetup;
data: any;
export function plugin(initializerContext: PluginInitializerContext) {
return new Plugin(initializerContext);
}

class VisTypeMarkdownPlugin {
constructor() {}

public setup({ visualizations, data }: SetupDeps) {
visualizations.types.VisTypesRegistryProvider.register(() => markdownVis);
data.expressions.registerFunction(kibanaMarkdown);
}

public start() {}

public stop() {}
}

new VisTypeMarkdownPlugin().setup({
visualizations: visualizationsService,
data: {
expressions: {
registerFunction: (fn: any) => functionsRegistry.register(fn),
},
},
});
35 changes: 35 additions & 0 deletions src/legacy/core_plugins/vis_type_markdown/public/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { visualizations } from '../../visualizations/public';
import { MarkdownPluginSetupDependencies } from './plugin';
import { plugin } from '.';

const plugins: Readonly<MarkdownPluginSetupDependencies> = {
visualizations,
data: npSetup.plugins.data,
};

const pluginInstance = plugin({} as PluginInitializerContext);

export const setup = pluginInstance.setup(npSetup.core, plugins);
export const start = pluginInstance.start(npStart.core);
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

// @ts-ignore
import { functionWrapper } from '../../interpreter/test_helpers';
import { kibanaMarkdown } from './markdown_fn';

jest.mock('ui/new_platform');
import { createMarkdownVisFn } from './markdown_fn';

describe('interpreter/functions#markdown', () => {
const fn = functionWrapper(kibanaMarkdown);
const fn = functionWrapper(createMarkdownVisFn);
const args = {
font: { spec: { fontSize: 12 } },
openLinksInNewTab: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface MarkdownVisParams {

type Return = Promise<Render<{ visType: 'markdown'; visConfig: MarkdownVisParams }>>;

export const kibanaMarkdown = (): ExpressionFunction<
export const createMarkdownVisFn = (): ExpressionFunction<
typeof name,
KibanaDatatable,
Arguments,
Expand Down
49 changes: 49 additions & 0 deletions src/legacy/core_plugins/vis_type_markdown/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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, CoreSetup, CoreStart, Plugin } from '../../../../core/public';
import { Plugin as DataPublicPlugin } from '../../../../plugins/data/public';
import { VisualizationsSetup } from '../../visualizations/public';

import { markdownVis } from './markdown_vis';
import { createMarkdownVisFn } from './markdown_fn';

/** @internal */
export interface MarkdownPluginSetupDependencies {
data: ReturnType<DataPublicPlugin['setup']>;
visualizations: VisualizationsSetup;
}

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

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

public setup(core: CoreSetup, { data, visualizations }: MarkdownPluginSetupDependencies) {
visualizations.types.VisTypesRegistryProvider.register(() => markdownVis);
data.expressions.registerFunction(createMarkdownVisFn);
}

public start(core: CoreStart) {
// nothing to do here yet
}
}

0 comments on commit 4d23d3c

Please sign in to comment.