Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown vis type np shim #38767

Merged
merged 15 commits into from
Jul 2, 2019
2 changes: 1 addition & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"kbnDocViews": "src/legacy/core_plugins/kbn_doc_views",
"embeddableApi": "src/legacy/core_plugins/embeddable_api",
"kbnVislibVisTypes": "src/legacy/core_plugins/kbn_vislib_vis_types",
"markdownVis": "src/legacy/core_plugins/markdown_vis",
"visTypeMarkdown": "src/legacy/core_plugins/vis_type_markdown",
"metricVis": "src/legacy/core_plugins/metric_vis",
"vega": "src/legacy/core_plugins/vega",
"tableVis": "src/legacy/core_plugins/table_vis",
Expand Down
4 changes: 0 additions & 4 deletions src/legacy/core_plugins/markdown_vis/package.json

This file was deleted.

65 changes: 0 additions & 65 deletions src/legacy/core_plugins/markdown_vis/public/markdown_vis.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
*/

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

export default function (kibana) {

return new kibana.Plugin({

// 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'],
uiExports: {
visTypes: [
'plugins/markdown_vis/markdown_vis'
],
interpreter: ['plugins/markdown_vis/markdown_fn'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
}

});
hacks: ['plugins/vis_type_markdown/index'],
},
};

return new kibana.Plugin(config);
}
4 changes: 4 additions & 0 deletions src/legacy/core_plugins/vis_type_markdown/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "vis_type_markdown",
"version": "kibana"
}
42 changes: 42 additions & 0 deletions src/legacy/core_plugins/vis_type_markdown/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.
*/

// @ts-ignore
import { markdownVis } from './markdown_vis';
// @ts-ignore
import { kibanaMarkdown } from './markdown_fn';

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

class VisTypeMarkdownPlugin {
constructor() {}

public setup(visualizationsSetup: VisualizationsSetup) {
visualizationsSetup.types.VisTypesRegistryProvider.register(() => markdownVis);
functionsRegistry.register(kibanaMarkdown);
}

public start() {}

public stop() {}
}

new VisTypeMarkdownPlugin().setup(visualizations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess visualizations should be just one of the plugin contracts, not the whole object, also you may want to inject the data plugin contract.

import { functionsRegistry } from '../../interpreter/public/registries';
import { visualizations, VisualizationsSetup } from '../../visualizations/public';

export interface SetupDeps {
  visualizations: VisualizationsSetup;
  data: any;
}

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,
  data: {
    expressions: {
      registerFunction: (fn: any) => functionsRegistry.register(fn),
    }
  }
});

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/

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

Expand All @@ -28,8 +29,8 @@ describe('interpreter/functions#markdown', () => {
markdown: '## hello _markdown_',
};

it('returns an object with the correct structure', () => {
const actual = fn(undefined, args);
it('returns an object with the correct structure', async () => {
const actual = await fn(undefined, args);
expect(actual).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,58 @@
* under the License.
*/

import { functionsRegistry } from 'plugins/interpreter/registries';
import { i18n } from '@kbn/i18n';
import { ExpressionFunction, KibanaDatatable, Render } from '../../interpreter/types';

export const kibanaMarkdown = () => ({
name: 'markdownVis',
const name = 'markdownVis';

export interface Arguments {
markdown: string;
fontSize: number;
openLinksInNewTab: boolean;
}

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

export const kibanaMarkdown = (): ExpressionFunction<
typeof name,
KibanaDatatable,
Arguments,
Return
> => ({
name,
type: 'render',
context: {
types: [],
},
help: i18n.translate('markdownVis.function.help', {
defaultMessage: 'Markdown visualization'
help: i18n.translate('visTypeMarkdown.function.help', {
defaultMessage: 'Markdown visualization',
}),
args: {
markdown: {
type: ['string'],
types: ['string'],
aliases: ['_'],
required: true,
help: i18n.translate('visTypeMarkdown.function.markdown.help', {
defaultMessage: 'Markdown to render',
}),
},
fontSize: {
types: ['number'],
default: 12,
help: i18n.translate('visTypeMarkdown.function.fontSize.help', {
defaultMessage: 'Sets the font size',
}),
},
openLinksInNewTab: {
types: ['boolean'],
default: false,
}
help: i18n.translate('visTypeMarkdown.function.openLinksInNewTab.help', {
defaultMessage: 'Opens links in new tab',
}),
},
},
fn(context, args) {
async fn(context, args) {
return {
type: 'render',
as: 'visualization',
Expand All @@ -53,9 +77,7 @@ export const kibanaMarkdown = () => ({
visConfig: {
...args,
},
}
},
};
}
},
});

functionsRegistry.register(kibanaMarkdown);
54 changes: 54 additions & 0 deletions src/legacy/core_plugins/vis_type_markdown/public/markdown_vis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 { i18n } from '@kbn/i18n';

import { visFactory, DefaultEditorSize } from '../../visualizations/public';

import { MarkdownVisWrapper } from './markdown_vis_controller';
import markdownVisParamsTemplate from './markdown_vis_params.html';

export const markdownVis = visFactory.createReactVisualization({
name: 'markdown',
title: 'Markdown',
isAccessible: true,
icon: 'visText',
description: i18n.translate('visTypeMarkdown.markdownDescription', {
defaultMessage: 'Create a document using markdown syntax',
}),
visConfig: {
component: MarkdownVisWrapper,
defaults: {
fontSize: 12,
openLinksInNewTab: false,
markdown: '',
},
},
editorConfig: {
optionsTemplate: markdownVisParamsTemplate,
enableAutoApply: true,
defaultSize: DefaultEditorSize.LARGE,
},
options: {
showTimePicker: false,
showFilterBar: false,
},
requestHandler: 'none',
responseHandler: 'none',
});
Loading