From 63ad0f81a50a041b2b516a256eaa35d19745f2f8 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 10 Jun 2021 11:01:32 +0300 Subject: [PATCH 01/77] expression_reveal_image skeleton. --- .../expression_reveal_image/.i18nrc.json | 7 ++++ src/plugins/expression_reveal_image/README.md | 9 ++++++ .../common/i18n/index.ts | 16 ++++++++++ .../expression_reveal_image/common/index.ts | 10 ++++++ .../expression_reveal_image/kibana.json | 10 ++++++ .../public/components/index.ts | 7 ++++ .../public/expression_functions/index.ts | 8 +++++ .../reveal_image_function.ts | 7 ++++ .../public/expression_renderers/index.ts | 9 ++++++ .../reveal_image_renderer.ts | 7 ++++ .../expression_reveal_image/public/index.ts | 17 ++++++++++ .../expression_reveal_image/public/plugin.ts | 32 +++++++++++++++++++ 12 files changed, 139 insertions(+) create mode 100755 src/plugins/expression_reveal_image/.i18nrc.json create mode 100755 src/plugins/expression_reveal_image/README.md create mode 100644 src/plugins/expression_reveal_image/common/i18n/index.ts create mode 100755 src/plugins/expression_reveal_image/common/index.ts create mode 100755 src/plugins/expression_reveal_image/kibana.json create mode 100644 src/plugins/expression_reveal_image/public/components/index.ts create mode 100644 src/plugins/expression_reveal_image/public/expression_functions/index.ts create mode 100644 src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers/index.ts create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts create mode 100755 src/plugins/expression_reveal_image/public/index.ts create mode 100755 src/plugins/expression_reveal_image/public/plugin.ts diff --git a/src/plugins/expression_reveal_image/.i18nrc.json b/src/plugins/expression_reveal_image/.i18nrc.json new file mode 100755 index 0000000000000..5b073e4374519 --- /dev/null +++ b/src/plugins/expression_reveal_image/.i18nrc.json @@ -0,0 +1,7 @@ +{ + "prefix": "expressionRevealImage", + "paths": { + "expressionRevealImage": "." + }, + "translations": ["translations/ja-JP.json"] +} diff --git a/src/plugins/expression_reveal_image/README.md b/src/plugins/expression_reveal_image/README.md new file mode 100755 index 0000000000000..9ab6e6fd5d4e6 --- /dev/null +++ b/src/plugins/expression_reveal_image/README.md @@ -0,0 +1,9 @@ +# expressionRevealImage + +A Kibana plugin + +--- + +## Development + +See the [kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) for instructions setting up your development environment. diff --git a/src/plugins/expression_reveal_image/common/i18n/index.ts b/src/plugins/expression_reveal_image/common/i18n/index.ts new file mode 100644 index 0000000000000..b94845dce939f --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { i18n } from '@kbn/i18n'; + +export const RendererStrings = { + getLabelText: () => + i18n.translate('expressionRevealImage.labelMessage', { + defaultMessage: 'Here is the input text', + }), +}; diff --git a/src/plugins/expression_reveal_image/common/index.ts b/src/plugins/expression_reveal_image/common/index.ts new file mode 100755 index 0000000000000..4133f27f96ab9 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/index.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export const PLUGIN_ID = 'expressionRevealImage'; +export const PLUGIN_NAME = 'expressionRevealImage'; diff --git a/src/plugins/expression_reveal_image/kibana.json b/src/plugins/expression_reveal_image/kibana.json new file mode 100755 index 0000000000000..b2579bd061e5d --- /dev/null +++ b/src/plugins/expression_reveal_image/kibana.json @@ -0,0 +1,10 @@ +{ + "id": "expressionRevealImage", + "version": "1.0.0", + "kibanaVersion": "kibana", + "server": false, + "ui": true, + "requiredPlugins": ["expressions"], + "optionalPlugins": [], + "requiredBundles": [] +} diff --git a/src/plugins/expression_reveal_image/public/components/index.ts b/src/plugins/expression_reveal_image/public/components/index.ts new file mode 100644 index 0000000000000..5c2d5b68ae2e0 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/components/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ diff --git a/src/plugins/expression_reveal_image/public/expression_functions/index.ts b/src/plugins/expression_reveal_image/public/expression_functions/index.ts new file mode 100644 index 0000000000000..23b46542472f0 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_functions/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +export * from './reveal_image_function'; diff --git a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts new file mode 100644 index 0000000000000..5c2d5b68ae2e0 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/index.ts b/src/plugins/expression_reveal_image/public/expression_renderers/index.ts new file mode 100644 index 0000000000000..f34e2c400cec0 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export * from './reveal_image_renderer'; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts new file mode 100644 index 0000000000000..5c2d5b68ae2e0 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ diff --git a/src/plugins/expression_reveal_image/public/index.ts b/src/plugins/expression_reveal_image/public/index.ts new file mode 100755 index 0000000000000..d7a3ec25309f1 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import './index.scss'; + +import { ExpressionRevealImagePlugin } from './plugin'; + +// This exports static code and TypeScript types, +// as well as, Kibana Platform `plugin()` initializer. +export function plugin() { + return new ExpressionRevealImagePlugin(); +} diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts new file mode 100755 index 0000000000000..45a51074dbfc7 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { i18n } from '@kbn/i18n'; +import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../core/public'; +import { ExpressionsStart, ExpressionsSetup } from '../../../src/plugins/expressions/public'; +import { PLUGIN_NAME } from '../common'; + +interface StartDeps { + expression: ExpressionsStart; +} + +interface SetupDeps { + expressions: ExpressionsSetup; +} + +export class ExpressionRevealImagePlugin implements Plugin { + public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup { + expressions.registerFunction(null); + expressions.registerRenderer(null); + } + + public start(core: CoreStart): ExpressionRevealImagePluginStart { + return {}; + } + + public stop() {} +} From 1240bb2e38b225bd2199da2651d825c364a473ff Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 10 Jun 2021 13:57:14 +0300 Subject: [PATCH 02/77] expression_functions added. --- .../common/i18n/constants.ts | 10 ++ .../expression_functions/dict/reveal_image.ts | 59 +++++++++++ .../expression_functions/function_errors.ts | 13 +++ .../expression_functions/function_help.ts | 24 +++++ .../common/i18n/expression_functions/index.ts | 10 ++ .../common/i18n/index.ts | 9 +- .../common/lib/dataurl.test.ts | 98 +++++++++++++++++++ .../common/lib/dataurl.ts | 68 +++++++++++++ .../common/lib/elastic_logo.ts | 10 ++ .../common/lib/elastic_outline.ts | 10 ++ .../common/lib/httpurl.test.ts | 32 ++++++ .../common/lib/httpurl.ts | 14 +++ .../common/lib/missing_asset.ts | 11 +++ .../common/lib/resolve_dataurl.test.ts | 43 ++++++++ .../common/lib/resolve_dataurl.ts | 34 +++++++ .../common/lib/url.test.ts | 23 +++++ .../expression_reveal_image/common/lib/url.ts | 14 +++ .../common/test_helpers/function_wrapper.ts | 21 ++++ .../common/types/index.ts | 95 ++++++++++++++++++ .../expression_functions/reveal_image.test.ts | 89 +++++++++++++++++ .../reveal_image_function.ts | 72 ++++++++++++++ .../expression_reveal_image/public/index.ts | 2 - .../expression_reveal_image/public/plugin.ts | 11 ++- 23 files changed, 757 insertions(+), 15 deletions(-) create mode 100644 src/plugins/expression_reveal_image/common/i18n/constants.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/expression_functions/function_errors.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/expression_functions/function_help.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/expression_functions/index.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/dataurl.test.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/dataurl.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/elastic_logo.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/elastic_outline.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/httpurl.test.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/httpurl.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/missing_asset.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/resolve_dataurl.test.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/resolve_dataurl.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/url.test.ts create mode 100644 src/plugins/expression_reveal_image/common/lib/url.ts create mode 100644 src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts create mode 100644 src/plugins/expression_reveal_image/common/types/index.ts create mode 100644 src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts diff --git a/src/plugins/expression_reveal_image/common/i18n/constants.ts b/src/plugins/expression_reveal_image/common/i18n/constants.ts new file mode 100644 index 0000000000000..413f376515a33 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/constants.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export const BASE64 = '`base64`'; +export const URL = 'URL'; diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts new file mode 100644 index 0000000000000..34ee66febe516 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts @@ -0,0 +1,59 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { i18n } from '@kbn/i18n'; +import { FunctionHelp } from '../function_help'; +import { ExpressionRevealImageFunction, FunctionFactory, Position } from '../../../types'; +import { BASE64, URL } from '../../constants'; + +export const help: FunctionHelp> = { + help: i18n.translate('xpack.canvas.functions.revealImageHelpText', { + defaultMessage: 'Configures an image reveal element.', + }), + args: { + image: i18n.translate('xpack.canvas.functions.revealImage.args.imageHelpText', { + defaultMessage: + 'The image to reveal. Provide an image asset as a {BASE64} data {URL}, ' + + 'or pass in a sub-expression.', + values: { + BASE64, + URL, + }, + }), + emptyImage: i18n.translate('xpack.canvas.functions.revealImage.args.emptyImageHelpText', { + defaultMessage: + 'An optional background image to reveal over. ' + + 'Provide an image asset as a `{BASE64}` data {URL}, or pass in a sub-expression.', + values: { + BASE64, + URL, + }, + }), + origin: i18n.translate('xpack.canvas.functions.revealImage.args.originHelpText', { + defaultMessage: 'The position to start the image fill. For example, {list}, or {end}.', + values: { + list: Object.values(Position) + .slice(0, -1) + .map((position) => `\`"${position}"\``) + .join(', '), + end: Object.values(Position).slice(-1)[0], + }, + }), + }, +}; +export const errors = { + invalidPercent: (percent: number) => + new Error( + i18n.translate('xpack.canvas.functions.revealImage.invalidPercentErrorMessage', { + defaultMessage: "Invalid value: '{percent}'. Percentage must be between 0 and 1", + values: { + percent, + }, + }) + ), +}; diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_errors.ts b/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_errors.ts new file mode 100644 index 0000000000000..09cd26c9e620b --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_errors.ts @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { errors as revealImage } from './dict/reveal_image'; + +export const getFunctionErrors = () => ({ + revealImage, +}); diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_help.ts b/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_help.ts new file mode 100644 index 0000000000000..6f49cf8471da5 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_help.ts @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ExpressionFunctionDefinition } from 'src/plugins/expressions'; +import { UnionToIntersection } from '@kbn/utility-types'; + +import { help as revealImage } from './dict/reveal_image'; + +/** + * Help text for Canvas Functions should be properly localized. This function will + * return a dictionary of help strings, organized by `ExpressionFunctionDefinition` + * specification and then by available arguments within each `ExpressionFunctionDefinition`. + * + * This a function, rather than an object, to future-proof string initialization, + * if ever necessary. + */ +export const getFunctionHelp = (): FunctionHelpDict => ({ + revealImage, +}); diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_functions/index.ts b/src/plugins/expression_reveal_image/common/i18n/expression_functions/index.ts new file mode 100644 index 0000000000000..3d36b123421f4 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/expression_functions/index.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export * from './function_help'; +export * from './function_errors'; diff --git a/src/plugins/expression_reveal_image/common/i18n/index.ts b/src/plugins/expression_reveal_image/common/i18n/index.ts index b94845dce939f..05c8096d77431 100644 --- a/src/plugins/expression_reveal_image/common/i18n/index.ts +++ b/src/plugins/expression_reveal_image/common/i18n/index.ts @@ -6,11 +6,4 @@ * Side Public License, v 1. */ -import { i18n } from '@kbn/i18n'; - -export const RendererStrings = { - getLabelText: () => - i18n.translate('expressionRevealImage.labelMessage', { - defaultMessage: 'Here is the input text', - }), -}; +export * from './expression_functions'; diff --git a/src/plugins/expression_reveal_image/common/lib/dataurl.test.ts b/src/plugins/expression_reveal_image/common/lib/dataurl.test.ts new file mode 100644 index 0000000000000..5820b10f589fe --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/dataurl.test.ts @@ -0,0 +1,98 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { isValidDataUrl, parseDataUrl } from './dataurl'; + +const BASE64_TEXT = 'data:text/plain;charset=utf-8;base64,VGhpcyBpcyBhIHRlc3Q='; +const BASE64_SVG = + 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='; +const BASE64_PIXEL = + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk8PxfDwADYgHJvQ16TAAAAABJRU5ErkJggg=='; +const INVALID_BASE64_PIXEL = + 'data:image/png;%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%01%00%00%00%01%08%06%00%00%00%1F%15%C4%89%0'; + +const RAW_TEXT = 'data:text/plain;charset=utf-8,This%20is%20a%20test'; +const RAW_SVG = + 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%2F%3E'; +const RAW_PIXEL = + 'data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%01%00%00%00%01%08%06%00%00%00%1F%15%C4%89%00%00%00%0DIDATx%DAcd%F0%FC_%0F%00%03b%01%C9%BD%0DzL%00%00%00%00IEND%AEB%60%82'; + +describe('dataurl', () => { + describe('isValidDataUrl', () => { + it('returns false for an invalid data url', () => { + expect(isValidDataUrl('somestring')).toBe(false); + }); + it('returns false for an empty string', () => { + expect(isValidDataUrl('')).toBe(false); + }); + it('returns true for valid data urls', () => { + expect(isValidDataUrl(BASE64_TEXT)).toBe(true); + expect(isValidDataUrl(BASE64_SVG)).toBe(true); + expect(isValidDataUrl(BASE64_PIXEL)).toBe(true); + expect(isValidDataUrl(RAW_TEXT)).toBe(true); + expect(isValidDataUrl(RAW_SVG)).toBe(true); + expect(isValidDataUrl(RAW_PIXEL)).toBe(true); + }); + }); + + describe('dataurl.parseDataUrl', () => { + it('returns null for an invalid data url', () => { + expect(parseDataUrl('somestring')).toBeNull(); + }); + it('returns null for an invalid base64 image', () => { + expect(parseDataUrl(INVALID_BASE64_PIXEL)).toBeNull(); + }); + it('returns correct values for text data urls', () => { + expect(parseDataUrl(BASE64_TEXT)).toEqual({ + charset: 'utf-8', + data: null, + encoding: 'base64', + extension: 'txt', + isImage: false, + mimetype: 'text/plain', + }); + expect(parseDataUrl(RAW_TEXT)).toEqual({ + charset: 'utf-8', + data: null, + encoding: undefined, + extension: 'txt', + isImage: false, + mimetype: 'text/plain', + }); + }); + it('returns correct values for png data urls', () => { + expect(parseDataUrl(RAW_PIXEL)).toBeNull(); + expect(parseDataUrl(BASE64_PIXEL)).toEqual({ + charset: undefined, + data: null, + encoding: 'base64', + extension: 'png', + isImage: true, + mimetype: 'image/png', + }); + }); + it('returns correct values for svg data urls', () => { + expect(parseDataUrl(RAW_SVG)).toEqual({ + charset: undefined, + data: null, + encoding: undefined, + extension: 'svg', + isImage: true, + mimetype: 'image/svg+xml', + }); + expect(parseDataUrl(BASE64_SVG)).toEqual({ + charset: undefined, + data: null, + encoding: 'base64', + extension: 'svg', + isImage: true, + mimetype: 'image/svg+xml', + }); + }); + }); +}); diff --git a/src/plugins/expression_reveal_image/common/lib/dataurl.ts b/src/plugins/expression_reveal_image/common/lib/dataurl.ts new file mode 100644 index 0000000000000..9ac232369cdc1 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/dataurl.ts @@ -0,0 +1,68 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { fromByteArray } from 'base64-js'; + +// @ts-expect-error @types/mime doesn't resolve mime/lite for some reason. +import mime from 'mime/lite'; + +const dataurlRegex = /^data:([a-z]+\/[a-z0-9-+.]+)(;[a-z-]+=[a-z0-9-]+)?(;([a-z0-9]+))?,/; + +export const imageTypes = ['image/svg+xml', 'image/jpeg', 'image/png', 'image/gif']; + +export function parseDataUrl(str: string, withData = false) { + if (typeof str !== 'string') { + return null; + } + + const matches = str.match(dataurlRegex); + + if (!matches) { + return null; + } + + const [, mimetype, charset, , encoding] = matches; + + // all types except for svg need to be base64 encoded + const imageTypeIndex = imageTypes.indexOf(matches[1]); + if (imageTypeIndex > 0 && encoding !== 'base64') { + return null; + } + + return { + mimetype, + encoding, + charset: charset && charset.split('=')[1], + data: !withData ? null : str.split(',')[1], + isImage: imageTypeIndex >= 0, + extension: mime.getExtension(mimetype), + }; +} + +export function isValidDataUrl(str?: string) { + if (!str) { + return false; + } + return dataurlRegex.test(str); +} + +export function encode(data: any | null, type = 'text/plain') { + // use FileReader if it's available, like in the browser + if (FileReader) { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onloadend = () => resolve(reader.result as string); + reader.onerror = (err) => reject(err); + reader.readAsDataURL(data); + }); + } + + // otherwise fall back to fromByteArray + // note: Buffer doesn't seem to correctly base64 encode binary data + return Promise.resolve(`data:${type};base64,${fromByteArray(data)}`); +} diff --git a/src/plugins/expression_reveal_image/common/lib/elastic_logo.ts b/src/plugins/expression_reveal_image/common/lib/elastic_logo.ts new file mode 100644 index 0000000000000..9a789d1a5fb03 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/elastic_logo.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export const elasticLogo = + 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgdmlld0JveD0iMCAwIDI3MC42MDAwMSAyNjkuNTQ2NjYiCiAgIGhlaWdodD0iMjY5LjU0NjY2IgogICB3aWR0aD0iMjcwLjYwMDAxIgogICB4bWw6c3BhY2U9InByZXNlcnZlIgogICBpZD0ic3ZnMiIKICAgdmVyc2lvbj0iMS4xIj48bWV0YWRhdGEKICAgICBpZD0ibWV0YWRhdGE4Ij48cmRmOlJERj48Y2M6V29yawogICAgICAgICByZGY6YWJvdXQ9IiI+PGRjOmZvcm1hdD5pbWFnZS9zdmcreG1sPC9kYzpmb3JtYXQ+PGRjOnR5cGUKICAgICAgICAgICByZGY6cmVzb3VyY2U9Imh0dHA6Ly9wdXJsLm9yZy9kYy9kY21pdHlwZS9TdGlsbEltYWdlIiAvPjwvY2M6V29yaz48L3JkZjpSREY+PC9tZXRhZGF0YT48ZGVmcwogICAgIGlkPSJkZWZzNiIgLz48ZwogICAgIHRyYW5zZm9ybT0ibWF0cml4KDEuMzMzMzMzMywwLDAsLTEuMzMzMzMzMywwLDI2OS41NDY2NykiCiAgICAgaWQ9ImcxMCI+PGcKICAgICAgIHRyYW5zZm9ybT0ic2NhbGUoMC4xKSIKICAgICAgIGlkPSJnMTIiPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMTQiCiAgICAgICAgIHN0eWxlPSJmaWxsOiNmZmZmZmY7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gMjAyOS40OCw5NjIuNDQxIGMgMCwxNzAuMDk5IC0xMDUuNDYsMzE4Ljc5OSAtMjY0LjE3LDM3Ni42NTkgNi45OCwzNS44NiAxMC42Miw3MS43MSAxMC42MiwxMDkuMDUgMCwzMTYuMTkgLTI1Ny4yNCw1NzMuNDMgLTU3My40Nyw1NzMuNDMgLTE4NC43MiwwIC0zNTYuNTU4LC04OC41OSAtNDY0LjUzLC0yMzcuODUgLTUzLjA5LDQxLjE4IC0xMTguMjg1LDYzLjc1IC0xODYuMzA1LDYzLjc1IC0xNjcuODM2LDAgLTMwNC4zODMsLTEzNi41NCAtMzA0LjM4MywtMzA0LjM4IDAsLTM3LjA4IDYuNjE3LC03Mi41OCAxOS4wMzEsLTEwNi4wOCBDIDEwOC40ODgsMTM4MC4wOSAwLDEyMjcuODkgMCwxMDU4Ljg4IDAsODg3LjkxIDEwNS45NzcsNzM4LjUzOSAyNjUuMzk4LDY4MS4wOSBjIC02Ljc2OSwtMzUuNDQyIC0xMC40NiwtNzIuMDIgLTEwLjQ2LC0xMDkgQyAyNTQuOTM4LDI1Ni42MjEgNTExLjU2NiwwIDgyNy4wMjcsMCAxMDEyLjIsMCAxMTgzLjk0LDg4Ljk0MTQgMTI5MS4zLDIzOC44MzIgYyA1My40NSwtNDEuOTYxIDExOC44LC02NC45OTIgMTg2LjU2LC02NC45OTIgMTY3LjgzLDAgMzA0LjM4LDEzNi40OTIgMzA0LjM4LDMwNC4zMzIgMCwzNy4wNzggLTYuNjIsNzIuNjI5IC0xOS4wMywxMDYuMTI5IDE1Ny43OCw1Ni44NzkgMjY2LjI3LDIwOS4xMjkgMjY2LjI3LDM3OC4xNCIgLz48cGF0aAogICAgICAgICBpZD0icGF0aDE2IgogICAgICAgICBzdHlsZT0iZmlsbDojZmFjZjA5O2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIgogICAgICAgICBkPSJtIDc5Ny44OTgsMTE1MC45MyA0NDQuMDcyLC0yMDIuNDUgNDQ4LjA1LDM5Mi41OCBjIDYuNDksMzIuMzkgOS42Niw2NC42NyA5LjY2LDk4LjQ2IDAsMjc2LjIzIC0yMjQuNjgsNTAwLjk1IC01MDAuOSw1MDAuOTUgLTE2NS4yNCwwIC0zMTkuMzcsLTgxLjM2IC00MTMuMDUzLC0yMTcuNzkgbCAtNzQuNTI0LC0zODYuNjQgODYuNjk1LC0xODUuMTEiIC8+PHBhdGgKICAgICAgICAgaWQ9InBhdGgxOCIKICAgICAgICAgc3R5bGU9ImZpbGw6IzQ5YzFhZTtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6bm9uZSIKICAgICAgICAgZD0ibSAzMzguMjIzLDY4MC42NzIgYyAtNi40ODksLTMyLjM4MyAtOS44MDksLTY1Ljk4MSAtOS44MDksLTk5Ljk3MyAwLC0yNzYuOTI5IDIyNS4zMzYsLTUwMi4yNTc2IDUwMi4zMTMsLTUwMi4yNTc2IDE2Ni41OTMsMCAzMjEuNDczLDgyLjExNzYgNDE1LjAxMywyMTkuOTQ5NiBsIDczLjk3LDM4NS4zNDcgLTk4LjcyLDE4OC42MjEgTCA3NzUuMTU2LDEwNzUuNTcgMzM4LjIyMyw2ODAuNjcyIiAvPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMjAiCiAgICAgICAgIHN0eWxlPSJmaWxsOiNlZjI5OWI7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gMzM1LjQxLDE0NDkuMTggMzA0LjMzMiwtNzEuODYgNjYuNjgsMzQ2LjAyIGMgLTQxLjU4NiwzMS43OCAtOTIuOTMsNDkuMTggLTE0NS43MzEsNDkuMTggLTEzMi4yNSwwIC0yMzkuODEyLC0xMDcuNjEgLTIzOS44MTIsLTIzOS44NyAwLC0yOS4yMSA0Ljg3OSwtNTcuMjIgMTQuNTMxLC04My40NyIgLz48cGF0aAogICAgICAgICBpZD0icGF0aDIyIgogICAgICAgICBzdHlsZT0iZmlsbDojNGNhYmU0O2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIgogICAgICAgICBkPSJNIDMwOC45OTIsMTM3Ni43IEMgMTczLjAyLDEzMzEuNjQgNzguNDgwNSwxMjAxLjMgNzguNDgwNSwxMDU3LjkzIDc4LjQ4MDUsOTE4LjM0IDE2NC44Miw3OTMuNjggMjk0LjQwNiw3NDQuMzUyIGwgNDI2Ljk4MSwzODUuOTM4IC03OC4zOTUsMTY3LjUxIC0zMzQsNzguOSIgLz48cGF0aAogICAgICAgICBpZD0icGF0aDI0IgogICAgICAgICBzdHlsZT0iZmlsbDojODVjZTI2O2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIgogICAgICAgICBkPSJtIDEzMjMuOCwyOTguNDEgYyA0MS43NCwtMzIuMDkgOTIuODMsLTQ5LjU5IDE0NC45OCwtNDkuNTkgMTMyLjI1LDAgMjM5LjgxLDEwNy41NTkgMjM5LjgxLDIzOS44MjEgMCwyOS4xNiAtNC44OCw1Ny4xNjggLTE0LjUzLDgzLjQxOCBsIC0zMDQuMDgsNzEuMTYgLTY2LjE4LC0zNDQuODA5IiAvPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMjYiCiAgICAgICAgIHN0eWxlPSJmaWxsOiMzMTc3YTc7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gMTM4NS42Nyw3MjIuOTMgMzM0Ljc2LC03OC4zMDEgYyAxMzYuMDIsNDQuOTYxIDIzMC41NiwxNzUuMzUxIDIzMC41NiwzMTguNzYyIDAsMTM5LjMzOSAtODYuNTQsMjYzLjg1OSAtMjE2LjM4LDMxMy4wMzkgbCAtNDM3Ljg0LC0zODMuNTkgODguOSwtMTY5LjkxIiAvPjwvZz48L2c+PC9zdmc+'; diff --git a/src/plugins/expression_reveal_image/common/lib/elastic_outline.ts b/src/plugins/expression_reveal_image/common/lib/elastic_outline.ts new file mode 100644 index 0000000000000..4747be58127f7 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/elastic_outline.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export const elasticOutline = + 'data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3Csvg%20viewBox%3D%22-3.948730230331421%20-1.7549896240234375%20245.25946044921875%20241.40370178222656%22%20width%3D%22245.25946044921875%22%20height%3D%22241.40370178222656%22%20style%3D%22enable-background%3Anew%200%200%20686.2%20235.7%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%20%20%3Cdefs%3E%0A%20%20%20%20%3Cstyle%20type%3D%22text%2Fcss%22%3E%0A%09.st0%7Bfill%3A%232D2D2D%3B%7D%0A%3C%2Fstyle%3E%0A%20%20%3C%2Fdefs%3E%0A%20%20%3Cg%20transform%3D%22matrix%281%2C%200%2C%200%2C%201%2C%200%2C%200%29%22%3E%0A%20%20%20%20%3Cg%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M329.4%2C160.3l4.7-0.5l0.3%2C9.6c-12.4%2C1.7-23%2C2.6-31.8%2C2.6c-11.7%2C0-20-3.4-24.9-10.2%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-4.9-6.8-7.3-17.4-7.3-31.7c0-28.6%2C11.4-42.9%2C34.1-42.9c11%2C0%2C19.2%2C3.1%2C24.6%2C9.2c5.4%2C6.1%2C8.1%2C15.8%2C8.1%2C28.9l-0.7%2C9.3h-53.8%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc0%2C9%2C1.6%2C15.7%2C4.9%2C20c3.3%2C4.3%2C8.9%2C6.5%2C17%2C6.5C312.8%2C161.2%2C321.1%2C160.9%2C329.4%2C160.3z%20M325%2C124.9c0-10-1.6-17.1-4.8-21.2%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-3.2-4.1-8.4-6.2-15.6-6.2c-7.2%2C0-12.7%2C2.2-16.3%2C6.5c-3.6%2C4.3-5.5%2C11.3-5.6%2C20.9H325z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M354.3%2C171.4V64h12.2v107.4H354.3z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M443.5%2C113.5v41.1c0%2C4.1%2C10.1%2C3.9%2C10.1%2C3.9l-0.6%2C10.8c-8.6%2C0-15.7%2C0.7-20-3.4c-9.8%2C4.3-19.5%2C6.1-29.3%2C6.1%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-7.5%2C0-13.2-2.1-17.1-6.4c-3.9-4.2-5.9-10.3-5.9-18.3c0-7.9%2C2-13.8%2C6-17.5c4-3.7%2C10.3-6.1%2C18.9-6.9l25.6-2.4v-7%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc0-5.5-1.2-9.5-3.6-11.9c-2.4-2.4-5.7-3.6-9.8-3.6l-32.1%2C0V87.2h31.3c9.2%2C0%2C15.9%2C2.1%2C20.1%2C6.4C441.4%2C97.8%2C443.5%2C104.5%2C443.5%2C113.5%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bz%20M393.3%2C146.7c0%2C10%2C4.1%2C15%2C12.4%2C15c7.4%2C0%2C14.7-1.2%2C21.8-3.7l3.7-1.3v-26.9l-24.1%2C2.3c-4.9%2C0.4-8.4%2C1.8-10.6%2C4.2%26%2310%3B%26%239%3B%26%239%3B%26%239%3BC394.4%2C138.7%2C393.3%2C142.2%2C393.3%2C146.7z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M491.2%2C98.2c-11.8%2C0-17.8%2C4.1-17.8%2C12.4c0%2C3.8%2C1.4%2C6.5%2C4.1%2C8.1c2.7%2C1.6%2C8.9%2C3.2%2C18.6%2C4.9%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc9.7%2C1.7%2C16.5%2C4%2C20.5%2C7.1c4%2C3%2C6%2C8.7%2C6%2C17.1c0%2C8.4-2.7%2C14.5-8.1%2C18.4c-5.4%2C3.9-13.2%2C5.9-23.6%2C5.9c-6.7%2C0-29.2-2.5-29.2-2.5%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bl0.7-10.6c12.9%2C1.2%2C22.3%2C2.2%2C28.6%2C2.2c6.3%2C0%2C11.1-1%2C14.4-3c3.3-2%2C5-5.4%2C5-10.1c0-4.7-1.4-7.9-4.2-9.6c-2.8-1.7-9-3.3-18.6-4.8%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-9.6-1.5-16.4-3.7-20.4-6.7c-4-2.9-6-8.4-6-16.3c0-7.9%2C2.8-13.8%2C8.4-17.6c5.6-3.8%2C12.6-5.7%2C20.9-5.7c6.6%2C0%2C29.6%2C1.7%2C29.6%2C1.7%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bv10.7C508.1%2C99%2C498.2%2C98.2%2C491.2%2C98.2z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M581.7%2C99.5h-25.9v39c0%2C9.3%2C0.7%2C15.5%2C2%2C18.4c1.4%2C2.9%2C4.6%2C4.4%2C9.7%2C4.4l14.5-1l0.8%2C10.1%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-7.3%2C1.2-12.8%2C1.8-16.6%2C1.8c-8.5%2C0-14.3-2.1-17.6-6.2c-3.3-4.1-4.9-12-4.9-23.6V99.5h-11.6V88.9h11.6V63.9h12.1v24.9h25.9V99.5z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M598.7%2C78.4V64.3h12.2v14.2H598.7z%20M598.7%2C171.4V88.9h12.2v82.5H598.7z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M663.8%2C87.2c3.6%2C0%2C9.7%2C0.7%2C18.3%2C2l3.9%2C0.5l-0.5%2C9.9c-8.7-1-15.1-1.5-19.2-1.5c-9.2%2C0-15.5%2C2.2-18.8%2C6.6%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-3.3%2C4.4-5%2C12.6-5%2C24.5c0%2C11.9%2C1.5%2C20.2%2C4.6%2C24.9c3.1%2C4.7%2C9.5%2C7%2C19.3%2C7l19.2-1.5l0.5%2C10.1c-10.1%2C1.5-17.7%2C2.3-22.7%2C2.3%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-12.7%2C0-21.5-3.3-26.3-9.8c-4.8-6.5-7.3-17.5-7.3-33c0-15.5%2C2.6-26.4%2C7.8-32.6C643%2C90.4%2C651.7%2C87.2%2C663.8%2C87.2z%22%2F%3E%0A%20%20%20%20%3C%2Fg%3E%0A%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M236.6%2C123.5c0-19.8-12.3-37.2-30.8-43.9c0.8-4.2%2C1.2-8.4%2C1.2-12.7C207%2C30%2C177%2C0%2C140.2%2C0%26%2310%3B%26%239%3B%26%239%3BC118.6%2C0%2C98.6%2C10.3%2C86%2C27.7c-6.2-4.8-13.8-7.4-21.7-7.4c-19.6%2C0-35.5%2C15.9-35.5%2C35.5c0%2C4.3%2C0.8%2C8.5%2C2.2%2C12.4%26%2310%3B%26%239%3B%26%239%3BC12.6%2C74.8%2C0%2C92.5%2C0%2C112.2c0%2C19.9%2C12.4%2C37.3%2C30.9%2C44c-0.8%2C4.1-1.2%2C8.4-1.2%2C12.7c0%2C36.8%2C29.9%2C66.7%2C66.7%2C66.7%26%2310%3B%26%239%3B%26%239%3Bc21.6%2C0%2C41.6-10.4%2C54.1-27.8c6.2%2C4.9%2C13.8%2C7.6%2C21.7%2C7.6c19.6%2C0%2C35.5-15.9%2C35.5-35.5c0-4.3-0.8-8.5-2.2-12.4%26%2310%3B%26%239%3B%26%239%3BC223.9%2C160.9%2C236.6%2C143.2%2C236.6%2C123.5z%20M91.6%2C34.8c10.9-15.9%2C28.9-25.4%2C48.1-25.4c32.2%2C0%2C58.4%2C26.2%2C58.4%2C58.4%26%2310%3B%26%239%3B%26%239%3Bc0%2C3.9-0.4%2C7.7-1.1%2C11.5l-52.2%2C45.8L93%2C101.5L82.9%2C79.9L91.6%2C34.8z%20M65.4%2C29c6.2%2C0%2C12.1%2C2%2C17%2C5.7l-7.8%2C40.3l-35.5-8.4%26%2310%3B%26%239%3B%26%239%3Bc-1.1-3.1-1.7-6.3-1.7-9.7C37.4%2C41.6%2C49.9%2C29%2C65.4%2C29z%20M9.1%2C112.3c0-16.7%2C11-31.9%2C26.9-37.2L75%2C84.4l9.1%2C19.5l-49.8%2C45%26%2310%3B%26%239%3B%26%239%3BC19.2%2C143.1%2C9.1%2C128.6%2C9.1%2C112.3z%20M145.2%2C200.9c-10.9%2C16.1-29%2C25.6-48.4%2C25.6c-32.3%2C0-58.6-26.3-58.6-58.5c0-4%2C0.4-7.9%2C1.1-11.7%26%2310%3B%26%239%3B%26%239%3Bl50.9-46l52%2C23.7l11.5%2C22L145.2%2C200.9z%20M171.2%2C206.6c-6.1%2C0-12-2-16.9-5.8l7.7-40.2l35.4%2C8.3c1.1%2C3.1%2C1.7%2C6.3%2C1.7%2C9.7%26%2310%3B%26%239%3B%26%239%3BC199.2%2C194.1%2C186.6%2C206.6%2C171.2%2C206.6z%20M200.5%2C160.5l-39-9.1l-10.4-19.8l51-44.7c15.1%2C5.7%2C25.2%2C20.2%2C25.2%2C36.5%26%2310%3B%26%239%3B%26%239%3BC227.4%2C140.1%2C216.4%2C155.3%2C200.5%2C160.5z%22%2F%3E%0A%20%20%3C%2Fg%3E%0A%3C%2Fsvg%3E'; diff --git a/src/plugins/expression_reveal_image/common/lib/httpurl.test.ts b/src/plugins/expression_reveal_image/common/lib/httpurl.test.ts new file mode 100644 index 0000000000000..20cd40480691d --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/httpurl.test.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { isValidHttpUrl } from './httpurl'; + +describe('httpurl.isValidHttpUrl', () => { + it('matches HTTP URLs', () => { + expect(isValidHttpUrl('http://server.com/veggie/hamburger.jpg')).toBe(true); + expect(isValidHttpUrl('https://server.com:4443/veggie/hamburger.jpg')).toBe(true); + expect(isValidHttpUrl('http://user:password@server.com:4443/veggie/hamburger.jpg')).toBe(true); + expect(isValidHttpUrl('http://virtual-machine/veggiehamburger.jpg')).toBe(true); + expect(isValidHttpUrl('https://virtual-machine:44330/veggie.jpg?hamburger')).toBe(true); + expect(isValidHttpUrl('http://192.168.1.50/veggie/hamburger.jpg')).toBe(true); + expect(isValidHttpUrl('https://2600::/veggie/hamburger.jpg')).toBe(true); // ipv6 + expect(isValidHttpUrl('http://2001:4860:4860::8844/veggie/hamburger.jpg')).toBe(true); // ipv6 + }); + it('rejects non-HTTP URLs', () => { + expect(isValidHttpUrl('')).toBe(false); + expect(isValidHttpUrl('http://server.com')).toBe(false); + expect(isValidHttpUrl('file:///Users/programmer/Pictures/hamburger.jpeg')).toBe(false); + expect(isValidHttpUrl('ftp://hostz.com:1111/path/to/image.png')).toBe(false); + expect(isValidHttpUrl('ftp://user:password@host:1111/path/to/image.png')).toBe(false); + expect( + isValidHttpUrl('data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+...') + ).toBe(false); + }); +}); diff --git a/src/plugins/expression_reveal_image/common/lib/httpurl.ts b/src/plugins/expression_reveal_image/common/lib/httpurl.ts new file mode 100644 index 0000000000000..4777eb4c8128d --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/httpurl.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +// A cheap regex to distinguish an HTTP URL string from a data URL string +const httpurlRegex = /^https?:\/\/\S+(?:[0-9]+)?\/\S{1,}/; + +export function isValidHttpUrl(str: string): boolean { + return httpurlRegex.test(str); +} diff --git a/src/plugins/expression_reveal_image/common/lib/missing_asset.ts b/src/plugins/expression_reveal_image/common/lib/missing_asset.ts new file mode 100644 index 0000000000000..10d429870c88c --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/missing_asset.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +// CC0, source: https://pixabay.com/en/question-mark-confirmation-question-838656/ +export const missingImage = + 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCAzMSAzMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZGVmcz48ZmlsdGVyIGlkPSJiIiB4PSItLjM2IiB5PSItLjM2IiB3aWR0aD0iMS43MiIgaGVpZ2h0PSIxLjcyIiBjb2xvci1pbnRlcnBvbGF0aW9uLWZpbHRlcnM9InNSR0IiPjxmZUdhdXNzaWFuQmx1ciBzdGREZXZpYXRpb249IjIuNDY0Ii8+PC9maWx0ZXI+PGxpbmVhckdyYWRpZW50IGlkPSJhIiB4MT0iMTU5LjM0IiB4Mj0iMTg0LjQ4IiB5MT0iNzI3LjM2IiB5Mj0iNzQ5Ljg5IiBncmFkaWVudFRyYW5zZm9ybT0idHJhbnNsYXRlKC0xMTEuNTMgLTU0OS42OCkgc2NhbGUoLjc3MDAyKSIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPjxzdG9wIHN0b3AtY29sb3I9IiNlYmYwZWQiIG9mZnNldD0iMCIvPjxzdG9wIHN0b3AtY29sb3I9IiNmYWZhZmEiIG9mZnNldD0iMSIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxwYXRoIGQ9Ik0xNS40MzcgMi42OTVsMTQuNTA2IDI0LjQ3NkgxLjI4N2wxNC4xNS0yNC40NzZ6IiBmaWxsPSJ1cmwoI2EpIiBzdHJva2U9InJlZCIgc3Ryb2tlLWxpbmVjYXA9InNxdWFyZSIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIyIi8+PHBhdGggdHJhbnNmb3JtPSJtYXRyaXgoLjgzMTk3IDAgMCAuNTU0NjYgLTc4LjU4MyAtMzgzLjUxKSIgZD0iTTExMS4zMSA3MzEuMmMtMy4yODMtMy45MjUtMy41OTUtNi4xNDgtMi4wMjQtMTAuNDM4IDMuMzM2LTYuMTQ1IDQuNDk2LTguMDY4IDUuNDEtOS40MDUgMS45MDEgNS4xNjIgMi4xMjYgMTkuMTQtMy4zODYgMTkuODQzeiIgZmlsbD0iI2ZmZiIgZmlsbC1vcGFjaXR5PSIuODc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGZpbHRlcj0idXJsKCNiKSIvPjxnIGZpbGwtb3BhY2l0eT0iLjgyIj48cGF0aCBkPSJNMTUuMDQ2IDIwLjIyN2gtLjQxNWMtLjAxMy0uNzQ4LjAyLTEuMzA4LjEwMS0xLjY3OC4wODgtLjM3MS4zMDctLjg4LjY1OC0xLjUyOC4zNTctLjY1NC41OS0xLjE3Ni42OTctMS41NjcuMTE1LS4zOTguMTcyLS44ODcuMTcyLTEuNDY3IDAtLjg5Ni0uMTc1LTEuNTU3LS41MjYtMS45ODItLjM1LS40MjUtLjc2NS0uNjM3LTEuMjQ0LS42MzctLjM2NCAwLS42Ny4wOTgtLjkyLjI5My0uMTg5LjE0OS0uMjgzLjMwNC0uMjgzLjQ2NiAwIC4xMDcuMDY0LjI3Ni4xOTIuNTA1LjI5LjUyLjQzNS45NjEuNDM1IDEuMzI1IDAgLjMzLS4xMTUuNjA3LS4zNDQuODNhMS4xMzggMS4xMzggMCAwIDEtLjg0LjMzM2MtLjM3NyAwLS42OTQtLjEzMS0uOTUtLjM5NC0uMjU2LS4yNy0uMzg0LS42MjQtLjM4NC0xLjA2MiAwLS43OTYuMzQ0LTEuNDk0IDEuMDMxLTIuMDk0LjY4OC0uNiAxLjY0OS0uOSAyLjg4My0uOSAxLjMwOCAwIDIuMzAyLjMxNCAyLjk4My45NC42ODguNjIxIDEuMDMyIDEuMzczIDEuMDMyIDIuMjU2IDAgLjY0LS4xNzYgMS4yMzQtLjUyNiAxLjc4LS4zNTEuNTQtMS4wMjkgMS4xNC0yLjAzMyAxLjgtLjY3NC40NDUtMS4xMi44NDMtMS4zMzUgMS4xOTQtLjIxLjM0My0uMzM3Ljg3My0uMzg0IDEuNTg3bS0uMTEyIDEuNDc3Yy40NTIgMCAuODM2LjE1OCAxLjE1My40NzUuMzE3LjMxNy40NzYuNzAxLjQ3NiAxLjE1MyAwIC40NTItLjE1OS44NC0uNDc2IDEuMTYzYTEuNTcgMS41NyAwIDAgMS0xLjE1My40NzUgMS41NyAxLjU3IDAgMCAxLTEuMTUzLS40NzUgMS42MDQgMS42MDQgMCAwIDEtLjQ3NS0xLjE2M2MwLS40NTIuMTU5LS44MzYuNDc1LTEuMTUzYTEuNTcgMS41NyAwIDAgMSAxLjE1My0uNDc1IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9Ii40ODYiLz48cGF0aCBkPSJNMTUuMzI3IDIwLjUwOGgtLjQxNWMtLjAxMy0uNzQ4LjAyLTEuMzA4LjEwMS0xLjY3OC4wODgtLjM3MS4zMDctLjg4LjY1OC0xLjUyOC4zNTctLjY1NC41OS0xLjE3Ni42OTctMS41NjcuMTE1LS4zOTguMTcyLS44ODcuMTcyLTEuNDY2IDAtLjg5Ny0uMTc1LTEuNTU4LS41MjYtMS45ODMtLjM1LS40MjQtLjc2NS0uNjM3LTEuMjQzLS42MzctLjM2NSAwLS42NzEuMDk4LS45Mi4yOTMtLjE5LjE0OS0uMjg0LjMwNC0uMjg0LjQ2NiAwIC4xMDguMDY0LjI3Ni4xOTIuNTA1LjI5LjUyLjQzNS45NjEuNDM1IDEuMzI1IDAgLjMzLS4xMTUuNjA3LS4zNDQuODNhMS4xMzggMS4xMzggMCAwIDEtLjg0LjMzM2MtLjM3NyAwLS42OTQtLjEzMS0uOTUtLjM5NC0uMjU2LS4yNy0uMzg0LS42MjQtLjM4NC0xLjA2MiAwLS43OTYuMzQ0LTEuNDkzIDEuMDMxLTIuMDk0LjY4OC0uNiAxLjY0OS0uOSAyLjg4My0uOSAxLjMwOCAwIDIuMzAyLjMxNCAyLjk4My45NC42ODguNjIxIDEuMDMyIDEuMzczIDEuMDMyIDIuMjU2IDAgLjY0LS4xNzYgMS4yMzQtLjUyNiAxLjc4LS4zNS41NC0xLjAyOCAxLjE0LTIuMDMzIDEuOC0uNjc0LjQ0NS0uODUzLjg0My0xLjA2OCAxLjE5NC0uMjEuMzQzLS4zMzcuODczLS4zODUgMS41ODdtLS4zNzggMS40NzdjLjQ1MiAwIC44MzYuMTU4IDEuMTUzLjQ3NS4zMTcuMzE3LjQ3Ni43MDEuNDc2IDEuMTUzIDAgLjQ1Mi0uMTU5Ljg0LS40NzYgMS4xNjNhMS41NyAxLjU3IDAgMCAxLTEuMTUzLjQ3NiAxLjU3IDEuNTcgMCAwIDEtMS4xNTMtLjQ3NiAxLjYwNCAxLjYwNCAwIDAgMS0uNDc1LTEuMTYzYzAtLjQ1Mi4xNTktLjgzNi40NzUtMS4xNTNhMS41NyAxLjU3IDAgMCAxIDEuMTUzLS40NzUiIGZpbGwtb3BhY2l0eT0iLjgyIi8+PC9nPjwvc3ZnPg=='; diff --git a/src/plugins/expression_reveal_image/common/lib/resolve_dataurl.test.ts b/src/plugins/expression_reveal_image/common/lib/resolve_dataurl.test.ts new file mode 100644 index 0000000000000..c2b9a444d20ef --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/resolve_dataurl.test.ts @@ -0,0 +1,43 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { missingImage } from './missing_asset'; +import { resolveFromArgs, resolveWithMissingImage } from './resolve_dataurl'; + +describe('resolve_dataurl', () => { + describe('resolveFromArgs', () => { + it('finds and returns the dataurl from args successfully', () => { + const args = { + name: 'dataurl', + argType: 'imageUpload', + dataurl: [missingImage, 'test2'], + }; + expect(resolveFromArgs(args)).toBe(missingImage); + }); + it('finds and returns null for invalid dataurl', () => { + const args = { + name: 'dataurl', + argType: 'imageUpload', + dataurl: ['invalid url', 'test2'], + }; + expect(resolveFromArgs(args)).toBe(null); + }); + }); + + describe('resolveWithMissingImage', () => { + it('returns valid dataurl', () => { + expect(resolveWithMissingImage(missingImage)).toBe(missingImage); + }); + it('returns missingImage for invalid dataurl', () => { + expect(resolveWithMissingImage('invalid dataurl')).toBe(missingImage); + }); + it('returns null for null dataurl', () => { + expect(resolveWithMissingImage(null)).toBe(null); + }); + }); +}); diff --git a/src/plugins/expression_reveal_image/common/lib/resolve_dataurl.ts b/src/plugins/expression_reveal_image/common/lib/resolve_dataurl.ts new file mode 100644 index 0000000000000..db94bdf04c32b --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/resolve_dataurl.ts @@ -0,0 +1,34 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { get } from 'lodash'; +import { isValidUrl } from './url'; +import { missingImage } from './missing_asset'; + +/* + * NOTE: args.dataurl can come as an expression here. + * For example: + * [{"type":"expression","chain":[{"type":"function","function":"asset","arguments":{"_":["..."]}}]}] + */ +export const resolveFromArgs = (args: any, defaultDataurl: string | null = null): string => { + const dataurl = get(args, 'dataurl.0', null); + return isValidUrl(dataurl) ? dataurl : defaultDataurl; +}; + +export const resolveWithMissingImage = ( + img: string | null, + alt: string | null = null +): string | null => { + if (img !== null && isValidUrl(img)) { + return img; + } + if (img === null) { + return alt; + } + return missingImage; +}; diff --git a/src/plugins/expression_reveal_image/common/lib/url.test.ts b/src/plugins/expression_reveal_image/common/lib/url.test.ts new file mode 100644 index 0000000000000..4599e776a6266 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/url.test.ts @@ -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 + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { missingImage } from './missing_asset'; +import { isValidUrl } from './url'; + +describe('resolve_dataurl', () => { + it('returns valid dataurl', () => { + expect(isValidUrl(missingImage)).toBe(true); + }); + it('returns valid http url', () => { + const httpurl = 'https://test.com/s/'; + expect(isValidUrl(httpurl)).toBe(true); + }); + it('returns false for invalid url', () => { + expect(isValidUrl('test')).toBe(false); + }); +}); diff --git a/src/plugins/expression_reveal_image/common/lib/url.ts b/src/plugins/expression_reveal_image/common/lib/url.ts new file mode 100644 index 0000000000000..e6a1064200cc1 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/url.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { isValidDataUrl } from './dataurl'; +import { isValidHttpUrl } from './httpurl'; + +export function isValidUrl(url: string) { + return isValidDataUrl(url) || isValidHttpUrl(url); +} diff --git a/src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts b/src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts new file mode 100644 index 0000000000000..4dc8c93f9ba7b --- /dev/null +++ b/src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { mapValues } from 'lodash'; +import { ExpressionRevealImageFunction } from '../types'; + +// It takes a function spec and passes in default args into the spec fn +export const functionWrapper = (fnSpec: () => ExpressionRevealImageFunction, mockReduxStore) => { + const spec = fnSpec(); + const defaultArgs = mapValues(spec.args, (argSpec) => { + return argSpec.default; + }); + + return (context, args, handlers) => + spec.fn(context, { ...defaultArgs, ...args }, handlers, mockReduxStore); +}; diff --git a/src/plugins/expression_reveal_image/common/types/index.ts b/src/plugins/expression_reveal_image/common/types/index.ts new file mode 100644 index 0000000000000..9ed220758760f --- /dev/null +++ b/src/plugins/expression_reveal_image/common/types/index.ts @@ -0,0 +1,95 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { ExpressionFunctionDefinition, ExpressionValueRender } from 'src/plugins/expressions'; + +export type ExpressionRevealImageFunction = () => ExpressionFunctionDefinition< + 'revealImageExpr', + number, + Arguments, + ExpressionValueRender +>; + +/** + * This type defines an entry in the `FunctionHelpMap`. It uses + * an `ExpressionFunction` to infer its `Arguments` in order to strongly-type that + * entry. + * + * For example: + * +``` + interface Arguments { + bar: string; + baz: number; + } + + function foo(): ExpressionFunction<'foo', Context, Arguments, Return> { + // ... + } + + const help: FunctionHelp = { + help: 'Some help for foo', + args: { + bar: 'Help for bar.', // pass; error if missing + baz: 'Help for baz.', // pass; error if missing + zap: 'Help for zap.`, // error: zap doesn't exist + } + }; +``` + * This allows one to ensure each argument is present, and no extraneous arguments + * remain. + */ +export type FunctionHelp = T extends ExpressionFunctionDefinition< + infer Name, + infer Input, + infer Arguments, + infer Output +> + ? { + help: string; + args: { [key in keyof Arguments]: string }; + } + : never; + +// This internal type infers a Function name and uses `FunctionHelp` above to build +// a dictionary entry. This can be used to ensure every Function is defined and all +// Arguments have help strings. +// +// For example: +// +// function foo(): ExpressionFunction<'foo', Context, Arguments, Return> { +// // ... +// } +// +// const map: FunctionHelpMap = { +// foo: FunctionHelp, +// } +// +// Given a collection of functions, the map would contain each entry. +// +export type FunctionHelpMap = T extends ExpressionFunctionDefinition< + infer Name, + infer Input, + infer Arguments, + infer Output +> + ? { [key in Name]: FunctionHelp } + : never; + +// This internal type represents an exhaustive dictionary of `FunctionHelp` types, +// organized by Function Name and then Function Argument. +// +// This type indexes the existing function factories, reverses the union to an +// intersection, and produces the dictionary of strings. +export type FunctionHelpDict = UnionToIntersection>; + +export enum Position { + TOP = 'top', + BOTTOM = 'bottom', + LEFT = 'left', + RIGHT = 'right', +} diff --git a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts new file mode 100644 index 0000000000000..1d58a62112265 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts @@ -0,0 +1,89 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { functionWrapper } from '../../common/test_helpers/function_wrapper'; +import { elasticOutline } from '../../common/lib/elastic_outline'; +import { elasticLogo } from '../../common/lib/elastic_logo'; +import { getFunctionErrors } from '../../common/i18n'; +import { revealImageFunction } from './reveal_image_function'; + +const errors = getFunctionErrors().revealImage; + +describe('revealImageFunction', () => { + const fn = functionWrapper(revealImageFunction); + + it('returns a render as revealImage', () => { + const result = fn(0.5); + expect(result).toHaveProperty('type', 'render'); + expect(result).toHaveProperty('as', 'revealImageExpr'); + }); + + describe('context', () => { + it('throws when context is not a number between 0 and 1', () => { + expect(() => { + fn(10, { + image: elasticLogo, + emptyImage: elasticOutline, + origin: 'top', + }); + }).toThrow(new RegExp(errors.invalidPercent(10).message)); + + expect(() => { + fn(-0.1, { + image: elasticLogo, + emptyImage: elasticOutline, + origin: 'top', + }); + }).toThrow(new RegExp(errors.invalidPercent(-0.1).message)); + }); + }); + + describe('args', () => { + describe('image', () => { + it('sets the image', () => { + const result = fn(0.89, { image: elasticLogo }).value; + expect(result).toHaveProperty('image', elasticLogo); + }); + + it('defaults to the Elastic outline logo', () => { + const result = fn(0.89).value; + expect(result).toHaveProperty('image', elasticOutline); + }); + }); + + describe('emptyImage', () => { + it('sets the background image', () => { + const result = fn(0, { emptyImage: elasticLogo }).value; + expect(result).toHaveProperty('emptyImage', elasticLogo); + }); + + it('sets emptyImage to null', () => { + const result = fn(0).value; + expect(result).toHaveProperty('emptyImage', null); + }); + }); + + describe('origin', () => { + it('sets which side to start the reveal from', () => { + let result = fn(1, { origin: 'top' }).value; + expect(result).toHaveProperty('origin', 'top'); + result = fn(1, { origin: 'left' }).value; + expect(result).toHaveProperty('origin', 'left'); + result = fn(1, { origin: 'bottom' }).value; + expect(result).toHaveProperty('origin', 'bottom'); + result = fn(1, { origin: 'right' }).value; + expect(result).toHaveProperty('origin', 'right'); + }); + + it('defaults to bottom', () => { + const result = fn(1).value; + expect(result).toHaveProperty('origin', 'bottom'); + }); + }); + }); +}); diff --git a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts index 5c2d5b68ae2e0..80998f207dad5 100644 --- a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts +++ b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts @@ -5,3 +5,75 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ + +import { resolveWithMissingImage } from '../../common/lib/resolve_dataurl'; +import { elasticOutline } from '../../common/lib/elastic_outline'; +import { getFunctionHelp, getFunctionErrors } from '../../common/i18n'; +import { ExpressionRevealImageFunction } from '../../common/types'; + +export enum Origin { + TOP = 'top', + LEFT = 'left', + BOTTOM = 'bottom', + RIGHT = 'right', +} + +interface Arguments { + image: string | null; + emptyImage: string | null; + origin: Origin; +} + +export interface Output { + image: string; + emptyImage: string; + origin: Origin; + percent: number; +} + +export function revealImageFunction(): ExpressionRevealImageFunction { + const { help, args: argHelp } = getFunctionHelp().revealImage; + const errors = getFunctionErrors().revealImage; + + return { + name: 'revealImageExpr', + aliases: [], + type: 'render', + inputTypes: ['number'], + help, + args: { + image: { + types: ['string', 'null'], + help: argHelp.image, + default: elasticOutline, + }, + emptyImage: { + types: ['string', 'null'], + help: argHelp.emptyImage, + default: null, + }, + origin: { + types: ['string'], + help: argHelp.origin, + default: 'bottom', + options: Object.values(Origin), + }, + }, + fn: (percent, args) => { + if (percent > 1 || percent < 0) { + throw errors.invalidPercent(percent); + } + + return { + type: 'render', + as: 'revealImageExpr', + value: { + percent, + ...args, + image: resolveWithMissingImage(args.image, elasticOutline) as string, + emptyImage: resolveWithMissingImage(args.emptyImage) as string, + }, + }; + }, + }; +} diff --git a/src/plugins/expression_reveal_image/public/index.ts b/src/plugins/expression_reveal_image/public/index.ts index d7a3ec25309f1..8eb4ca7026421 100755 --- a/src/plugins/expression_reveal_image/public/index.ts +++ b/src/plugins/expression_reveal_image/public/index.ts @@ -6,8 +6,6 @@ * Side Public License, v 1. */ -import './index.scss'; - import { ExpressionRevealImagePlugin } from './plugin'; // This exports static code and TypeScript types, diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts index 45a51074dbfc7..462618191c39b 100755 --- a/src/plugins/expression_reveal_image/public/plugin.ts +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -9,18 +9,19 @@ import { i18n } from '@kbn/i18n'; import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../core/public'; import { ExpressionsStart, ExpressionsSetup } from '../../../src/plugins/expressions/public'; import { PLUGIN_NAME } from '../common'; - -interface StartDeps { - expression: ExpressionsStart; -} +import { revealImageFunction } from './expression_functions'; interface SetupDeps { expressions: ExpressionsSetup; } +interface StartDeps { + expression: ExpressionsStart; +} + export class ExpressionRevealImagePlugin implements Plugin { public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup { - expressions.registerFunction(null); + expressions.registerFunction(revealImageFunction); expressions.registerRenderer(null); } From 72eac6362486bc47a6cc36fb80b839e0035407a6 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 10 Jun 2021 14:42:49 +0300 Subject: [PATCH 03/77] expression_renderers added. --- .../i18n/expression_renderers/dict/index.ts | 9 ++ .../expression_renderers/dict/reveal_image.ts | 19 ++++ .../common/i18n/expression_renderers/index.ts | 9 ++ .../expression_renderers/renderer_strings.ts | 24 +++++ .../common/i18n/index.ts | 1 + .../common/types/expression_functions.ts | 95 +++++++++++++++++++ .../common/types/expression_renderers.ts | 54 +++++++++++ .../common/types/index.ts | 90 +----------------- .../reveal_image_renderer.ts | 82 ++++++++++++++++ .../expression_reveal_image/public/plugin.ts | 3 +- 10 files changed, 297 insertions(+), 89 deletions(-) create mode 100644 src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/index.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/reveal_image.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/expression_renderers/index.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/expression_renderers/renderer_strings.ts create mode 100644 src/plugins/expression_reveal_image/common/types/expression_functions.ts create mode 100644 src/plugins/expression_reveal_image/common/types/expression_renderers.ts diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/index.ts b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/index.ts new file mode 100644 index 0000000000000..4f70f9d30b74b --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export { strings as revealImage } from './reveal_image'; diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/reveal_image.ts new file mode 100644 index 0000000000000..7e637b1f7438d --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/reveal_image.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { i18n } from '@kbn/i18n'; + +export const strings = { + getDisplayName: () => + i18n.translate('xpack.canvas.renderer.revealImage.displayName', { + defaultMessage: 'Image reveal', + }), + getHelpDescription: () => + i18n.translate('xpack.canvas.renderer.revealImage.helpDescription', { + defaultMessage: 'Reveal a percentage of an image to make a custom gauge-style chart', + }), +}; diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_renderers/index.ts b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/index.ts new file mode 100644 index 0000000000000..7e637f240d15c --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export * from './renderer_strings'; diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_renderers/renderer_strings.ts b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/renderer_strings.ts new file mode 100644 index 0000000000000..ff9b84ac2f9c5 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/renderer_strings.ts @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ExpressionFunctionDefinition } from 'src/plugins/expressions'; +import { UnionToIntersection } from '@kbn/utility-types'; + +import { revealImage } from './dict'; + +/** + * Help text for Canvas Functions should be properly localized. This function will + * return a dictionary of help strings, organized by `ExpressionFunctionDefinition` + * specification and then by available arguments within each `ExpressionFunctionDefinition`. + * + * This a function, rather than an object, to future-proof string initialization, + * if ever necessary. + */ +export const getRendererStrings = () => ({ + revealImage, +}); diff --git a/src/plugins/expression_reveal_image/common/i18n/index.ts b/src/plugins/expression_reveal_image/common/i18n/index.ts index 05c8096d77431..9c50bfab1305d 100644 --- a/src/plugins/expression_reveal_image/common/i18n/index.ts +++ b/src/plugins/expression_reveal_image/common/i18n/index.ts @@ -7,3 +7,4 @@ */ export * from './expression_functions'; +export * from './expression_renderers'; diff --git a/src/plugins/expression_reveal_image/common/types/expression_functions.ts b/src/plugins/expression_reveal_image/common/types/expression_functions.ts new file mode 100644 index 0000000000000..9ed220758760f --- /dev/null +++ b/src/plugins/expression_reveal_image/common/types/expression_functions.ts @@ -0,0 +1,95 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { ExpressionFunctionDefinition, ExpressionValueRender } from 'src/plugins/expressions'; + +export type ExpressionRevealImageFunction = () => ExpressionFunctionDefinition< + 'revealImageExpr', + number, + Arguments, + ExpressionValueRender +>; + +/** + * This type defines an entry in the `FunctionHelpMap`. It uses + * an `ExpressionFunction` to infer its `Arguments` in order to strongly-type that + * entry. + * + * For example: + * +``` + interface Arguments { + bar: string; + baz: number; + } + + function foo(): ExpressionFunction<'foo', Context, Arguments, Return> { + // ... + } + + const help: FunctionHelp = { + help: 'Some help for foo', + args: { + bar: 'Help for bar.', // pass; error if missing + baz: 'Help for baz.', // pass; error if missing + zap: 'Help for zap.`, // error: zap doesn't exist + } + }; +``` + * This allows one to ensure each argument is present, and no extraneous arguments + * remain. + */ +export type FunctionHelp = T extends ExpressionFunctionDefinition< + infer Name, + infer Input, + infer Arguments, + infer Output +> + ? { + help: string; + args: { [key in keyof Arguments]: string }; + } + : never; + +// This internal type infers a Function name and uses `FunctionHelp` above to build +// a dictionary entry. This can be used to ensure every Function is defined and all +// Arguments have help strings. +// +// For example: +// +// function foo(): ExpressionFunction<'foo', Context, Arguments, Return> { +// // ... +// } +// +// const map: FunctionHelpMap = { +// foo: FunctionHelp, +// } +// +// Given a collection of functions, the map would contain each entry. +// +export type FunctionHelpMap = T extends ExpressionFunctionDefinition< + infer Name, + infer Input, + infer Arguments, + infer Output +> + ? { [key in Name]: FunctionHelp } + : never; + +// This internal type represents an exhaustive dictionary of `FunctionHelp` types, +// organized by Function Name and then Function Argument. +// +// This type indexes the existing function factories, reverses the union to an +// intersection, and produces the dictionary of strings. +export type FunctionHelpDict = UnionToIntersection>; + +export enum Position { + TOP = 'top', + BOTTOM = 'bottom', + LEFT = 'left', + RIGHT = 'right', +} diff --git a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts new file mode 100644 index 0000000000000..74fabfdd39b8a --- /dev/null +++ b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts @@ -0,0 +1,54 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { IInterpreterRenderHandlers } from 'src/plugins/expressions'; + +type GenericRendererCallback = (callback: () => void) => void; + +export interface RendererHandlers extends IInterpreterRenderHandlers { + /** Handler to invoke when an element should be destroyed. */ + destroy: () => void; + /** Get the id of the element being rendered. Can be used as a unique ID in a render function */ + getElementId: () => string; + /** Retrieves the value of the filter property on the element object persisted on the workpad */ + getFilter: () => string; + /** Handler to invoke when a renderer is considered complete */ + onComplete: (fn: () => void) => void; + /** Handler to invoke when a rendered embeddable is destroyed */ + onEmbeddableDestroyed: () => void; + /** Handler to invoke when the input to a function has changed internally */ + onEmbeddableInputChange: (expression: string) => void; + /** Handler to invoke when an element's dimensions have changed*/ + onResize: GenericRendererCallback; + /** Handler to invoke when an element should be resized. */ + resize: (size: { height: number; width: number }) => void; + /** Sets the value of the filter property on the element object persisted on the workpad */ + setFilter: (filter: string) => void; +} + +export interface RendererSpec { + /** The render type */ + name: string; + /** The name to display */ + displayName: string; + /** A description of what is rendered */ + help: string; + /** Indicate whether the element should reuse the existing DOM element when re-rendering */ + reuseDomNode: boolean; + /** The default width of the element in pixels */ + width?: number; + /** The default height of the element in pixels */ + height?: number; + /** A function that renders an element into the specified DOM element */ + render: (domNode: HTMLElement, config: RendererConfig, handlers: RendererHandlers) => void; +} + +export type RendererFactory = () => RendererSpec; + +export type AnyRendererFactory = RendererFactory; +export type AnyRendererSpec = RendererSpec; diff --git a/src/plugins/expression_reveal_image/common/types/index.ts b/src/plugins/expression_reveal_image/common/types/index.ts index 9ed220758760f..ec934e7affe88 100644 --- a/src/plugins/expression_reveal_image/common/types/index.ts +++ b/src/plugins/expression_reveal_image/common/types/index.ts @@ -5,91 +5,5 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { ExpressionFunctionDefinition, ExpressionValueRender } from 'src/plugins/expressions'; - -export type ExpressionRevealImageFunction = () => ExpressionFunctionDefinition< - 'revealImageExpr', - number, - Arguments, - ExpressionValueRender ->; - -/** - * This type defines an entry in the `FunctionHelpMap`. It uses - * an `ExpressionFunction` to infer its `Arguments` in order to strongly-type that - * entry. - * - * For example: - * -``` - interface Arguments { - bar: string; - baz: number; - } - - function foo(): ExpressionFunction<'foo', Context, Arguments, Return> { - // ... - } - - const help: FunctionHelp = { - help: 'Some help for foo', - args: { - bar: 'Help for bar.', // pass; error if missing - baz: 'Help for baz.', // pass; error if missing - zap: 'Help for zap.`, // error: zap doesn't exist - } - }; -``` - * This allows one to ensure each argument is present, and no extraneous arguments - * remain. - */ -export type FunctionHelp = T extends ExpressionFunctionDefinition< - infer Name, - infer Input, - infer Arguments, - infer Output -> - ? { - help: string; - args: { [key in keyof Arguments]: string }; - } - : never; - -// This internal type infers a Function name and uses `FunctionHelp` above to build -// a dictionary entry. This can be used to ensure every Function is defined and all -// Arguments have help strings. -// -// For example: -// -// function foo(): ExpressionFunction<'foo', Context, Arguments, Return> { -// // ... -// } -// -// const map: FunctionHelpMap = { -// foo: FunctionHelp, -// } -// -// Given a collection of functions, the map would contain each entry. -// -export type FunctionHelpMap = T extends ExpressionFunctionDefinition< - infer Name, - infer Input, - infer Arguments, - infer Output -> - ? { [key in Name]: FunctionHelp } - : never; - -// This internal type represents an exhaustive dictionary of `FunctionHelp` types, -// organized by Function Name and then Function Argument. -// -// This type indexes the existing function factories, reverses the union to an -// intersection, and produces the dictionary of strings. -export type FunctionHelpDict = UnionToIntersection>; - -export enum Position { - TOP = 'top', - BOTTOM = 'bottom', - LEFT = 'left', - RIGHT = 'right', -} +export * from './expression_functions'; +export * from './expression_renderers'; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts index 5c2d5b68ae2e0..685498b67b5b3 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts @@ -5,3 +5,85 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ + +import { elasticOutline } from '../../common/lib/elastic_outline'; +import { isValidUrl } from '../../common/lib/url'; +import { getRendererStrings } from '../../common/i18n'; +import { RendererFactory } from '../../common/types'; +import { Output as Arguments } from '../expression_functions'; + +const { revealImage: revealImageStrings } = getRendererStrings(); + +export const revealImageRenderer: RendererFactory = () => ({ + name: 'revealImageExpr', + displayName: revealImageStrings.getDisplayName(), + help: revealImageStrings.getHelpDescription(), + reuseDomNode: true, + render(domNode, config, handlers) { + const aligner = document.createElement('div'); + const img = new Image(); + + // modify the top-level container class + domNode.className = 'revealImage'; + + // set up the overlay image + function onLoad() { + setSize(); + finish(); + } + img.onload = onLoad; + + img.className = 'revealImage__image'; + img.style.clipPath = getClipPath(config.percent, config.origin); + img.style.setProperty('-webkit-clip-path', getClipPath(config.percent, config.origin)); + img.src = isValidUrl(config.image) ? config.image : elasticOutline; + handlers.onResize(onLoad); + + // set up the underlay, "empty" image + aligner.className = 'revealImageAligner'; + aligner.appendChild(img); + if (isValidUrl(config.emptyImage)) { + // only use empty image if one is provided + aligner.style.backgroundImage = `url(${config.emptyImage})`; + } + + function finish() { + const firstChild = domNode.firstChild; + if (firstChild) { + domNode.replaceChild(aligner, firstChild); + } else { + domNode.appendChild(aligner); + } + handlers.done(); + } + + function getClipPath(percent: number, origin = 'bottom') { + const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; + const values: Array = [0, 0, 0, 0]; + values[directions[origin]] = `${100 - percent * 100}%`; + return `inset(${values.join(' ')})`; + } + + function setSize() { + const imgDimensions = { + height: img.naturalHeight, + width: img.naturalWidth, + ratio: img.naturalHeight / img.naturalWidth, + }; + + const domNodeDimensions = { + height: domNode.clientHeight, + width: domNode.clientWidth, + ratio: domNode.clientHeight / domNode.clientWidth, + }; + + if (imgDimensions.ratio > domNodeDimensions.ratio) { + img.style.height = `${domNodeDimensions.height}px`; + img.style.width = 'initial'; + } else { + img.style.width = `${domNodeDimensions.width}px`; + img.style.height = 'initial'; + } + } + }, +}); diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts index 462618191c39b..3ea0f12c2a614 100755 --- a/src/plugins/expression_reveal_image/public/plugin.ts +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -10,6 +10,7 @@ import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../core/ import { ExpressionsStart, ExpressionsSetup } from '../../../src/plugins/expressions/public'; import { PLUGIN_NAME } from '../common'; import { revealImageFunction } from './expression_functions'; +import { revealImageRenderer } from './expression_renderers'; interface SetupDeps { expressions: ExpressionsSetup; @@ -22,7 +23,7 @@ interface StartDeps { export class ExpressionRevealImagePlugin implements Plugin { public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup { expressions.registerFunction(revealImageFunction); - expressions.registerRenderer(null); + expressions.registerRenderer(revealImageRenderer); } public start(core: CoreStart): ExpressionRevealImagePluginStart { From 9e1e8177fe07de24fee4a38f5cf6bcedc6e2750e Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 10 Jun 2021 18:05:37 +0300 Subject: [PATCH 04/77] Backup of daily work. --- .../public/components/index.ts | 2 + .../components/reveal_image_component.tsx | 121 ++++++++++++++++++ .../public/expression_renderers/index.ts | 2 +- .../reveal_image_renderer.ts | 89 ------------- .../reveal_image_renderer.tsx | 51 ++++++++ .../public/expression_renderers/types.ts | 19 +++ 6 files changed, 194 insertions(+), 90 deletions(-) create mode 100644 src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx delete mode 100644 src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers/types.ts diff --git a/src/plugins/expression_reveal_image/public/components/index.ts b/src/plugins/expression_reveal_image/public/components/index.ts index 5c2d5b68ae2e0..23cb4d7a20cb8 100644 --- a/src/plugins/expression_reveal_image/public/components/index.ts +++ b/src/plugins/expression_reveal_image/public/components/index.ts @@ -5,3 +5,5 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ + +export * from './reveal_image_component'; diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx new file mode 100644 index 0000000000000..05e6aa3aec8c8 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -0,0 +1,121 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import React, { useRef, useLoaded, useCallback } from 'react'; +import { RevealImageRendererConfig, NodeDimensions } from '../expression_renderers/types'; +import { RendererHandlers } from '../../common/types'; + +interface RevealImageComponentProps { + handlers: RendererHandlers; + [property in RevealImageRendererConfig]: RevealImageRendererConfig[property]; + parentNodeDimensions: NodeDimensions; +} + +function RevealImageComponent({ + handlers, + parentNodeParameters, + percent, + origin, + image, + emptyImage, +}: RevealImageComponentProps) { + const [loaded, setLoaded] = useState(false); + const [dimensions, setDimensions] = useState({ + width: 0, + height: 0, + }); + + const imgRef = useRef(null); + + // set up the overlay image + const onLoad = useCallback(() => { + setLoaded(true); + if (imgRef.current) { + setDimensions( + { + height: imgRef.current.naturalHeight, + width: imgRef.current.naturalWidth, + }, + // () => handlers.done() + ); + console.log('here'); + } + }, [imgRef, handlers]); + + useEffect(() => { + // handlers.onResize(onLoad); + return handlers.destroy(); + }, [handlers, onLoad]); + + function getClipPath(percentParam: number, originParam = 'bottom') { + const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; + const values: Array = [0, 0, 0, 0]; + values[directions[originParam]] = `${100 - percentParam * 100}%`; + return `inset(${values.join(' ')})`; + } + + function getImageSizeStyle() { + const imgStyles = {}; + + const imgDimensions = { + height: dimensions.height, + width: dimensions.width, + ratio: dimensions.width > 0 ? dimensions.height / dimensions.width : 0, + }; + + const domNodeDimensions = { + height: parentNodeParameters.height, + width: parentNodeParameters.width, + ratio: parentNodeParameters.height / parentNodeParameters.width, + }; + + if (imgDimensions.ratio > domNodeDimensions.ratio) { + imgStyles.height = `${domNodeDimensions.height}px`; + imgStyles.width = 'initial'; + } else { + imgStyles.width = `${domNodeDimensions.width}px`; + imgStyles.height = 'initial'; + } + + return imgStyles; + } + + const imgSrc = isValidUrl(image) ? image : elasticOutline; + + const alignerStyles = {}; + if (isValidUrl(emptyImage)) { + // only use empty image if one is provided + alignerStyles.backgroundImage = `url(${emptyImage})`; + } + + const imgStyles = {}; + if (imgRef.current && loaded) imgStyles = getImageSizeStyle(); + + imgStyles.clipPath = getClipPath(percent, origin); + if (imgRef.current && loaded) { + imgRef.current.style.setProperty('-webkit-clip-path', getClipPath(percent, origin)); + } + + return ( +
+ +
+ ); +} + +// default export required for React.Lazy +// eslint-disable-next-line import/no-default-export +export { RevealImageComponent as default }; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/index.ts b/src/plugins/expression_reveal_image/public/expression_renderers/index.ts index f34e2c400cec0..4ad58398e2c49 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/index.ts +++ b/src/plugins/expression_reveal_image/public/expression_renderers/index.ts @@ -6,4 +6,4 @@ * Side Public License, v 1. */ -export * from './reveal_image_renderer'; +export * from './reveal_image_renderer.tsx'; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts deleted file mode 100644 index 685498b67b5b3..0000000000000 --- a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.ts +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { elasticOutline } from '../../common/lib/elastic_outline'; -import { isValidUrl } from '../../common/lib/url'; -import { getRendererStrings } from '../../common/i18n'; -import { RendererFactory } from '../../common/types'; -import { Output as Arguments } from '../expression_functions'; - -const { revealImage: revealImageStrings } = getRendererStrings(); - -export const revealImageRenderer: RendererFactory = () => ({ - name: 'revealImageExpr', - displayName: revealImageStrings.getDisplayName(), - help: revealImageStrings.getHelpDescription(), - reuseDomNode: true, - render(domNode, config, handlers) { - const aligner = document.createElement('div'); - const img = new Image(); - - // modify the top-level container class - domNode.className = 'revealImage'; - - // set up the overlay image - function onLoad() { - setSize(); - finish(); - } - img.onload = onLoad; - - img.className = 'revealImage__image'; - img.style.clipPath = getClipPath(config.percent, config.origin); - img.style.setProperty('-webkit-clip-path', getClipPath(config.percent, config.origin)); - img.src = isValidUrl(config.image) ? config.image : elasticOutline; - handlers.onResize(onLoad); - - // set up the underlay, "empty" image - aligner.className = 'revealImageAligner'; - aligner.appendChild(img); - if (isValidUrl(config.emptyImage)) { - // only use empty image if one is provided - aligner.style.backgroundImage = `url(${config.emptyImage})`; - } - - function finish() { - const firstChild = domNode.firstChild; - if (firstChild) { - domNode.replaceChild(aligner, firstChild); - } else { - domNode.appendChild(aligner); - } - handlers.done(); - } - - function getClipPath(percent: number, origin = 'bottom') { - const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; - const values: Array = [0, 0, 0, 0]; - values[directions[origin]] = `${100 - percent * 100}%`; - return `inset(${values.join(' ')})`; - } - - function setSize() { - const imgDimensions = { - height: img.naturalHeight, - width: img.naturalWidth, - ratio: img.naturalHeight / img.naturalWidth, - }; - - const domNodeDimensions = { - height: domNode.clientHeight, - width: domNode.clientWidth, - ratio: domNode.clientHeight / domNode.clientWidth, - }; - - if (imgDimensions.ratio > domNodeDimensions.ratio) { - img.style.height = `${domNodeDimensions.height}px`; - img.style.width = 'initial'; - } else { - img.style.width = `${domNodeDimensions.width}px`; - img.style.height = 'initial'; - } - } - }, -}); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx new file mode 100644 index 0000000000000..8a6531a28360f --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx @@ -0,0 +1,51 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import React, { lazy } from 'react'; +import { render, unmountComponentAtNode } from 'react-dom'; +import { I18nProvider } from '@kbn/i18n/react'; +import { elasticOutline } from '../../common/lib/elastic_outline'; +import { isValidUrl } from '../../common/lib/url'; +import { getRendererStrings } from '../../common/i18n'; +import { RendererFactory } from '../../common/types'; +import { Output as Arguments } from '../expression_functions'; +import { RevealImageRendererConfig, NodeDimensions } from './types'; + +const { revealImage: revealImageStrings } = getRendererStrings(); + +const RevealImageComponent = lazy(() => import('../components/reveal_image_component')); + +export const revealImageRenderer: RendererFactory = () => ({ + name: 'revealImageExpr', + displayName: revealImageStrings.getDisplayName(), + help: revealImageStrings.getHelpDescription(), + reuseDomNode: true, + render: async (domNode: HTMLElement, config: RevealImageRendererConfig, handlers) => { + handlers.onDestroy(() => { + unmountComponentAtNode(domNode); + }); + + // modify the top-level container class + domNode.className = 'revealImage'; + + const parentNodeDimensions: NodeDimensions = { + width: domNode.clientWidth, + height: domNode.clientHeight, + }; + + render( + + + , + domNode + ); + }, +}); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/types.ts b/src/plugins/expression_reveal_image/public/expression_renderers/types.ts new file mode 100644 index 0000000000000..cf40a07f4fd5b --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers/types.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export interface RevealImageRendererConfig { + percent: number; + origin?: 'bottom' | 'left' | 'top' | 'right'; + image?: string; + emptyImage?: string; +} + +export interface NodeDimensions { + width: number; + height: number; +} From befec5d6efa80c8f6e8d225f748c58f83d13994c Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 10:44:54 +0300 Subject: [PATCH 05/77] Fixed errors. --- .../public/components/renderer_wrapper.tsx | 20 +++++++ .../components/reveal_image_component.tsx | 52 +++++++++++-------- .../reveal_image_renderer.tsx | 19 ++----- 3 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx diff --git a/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx b/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx new file mode 100644 index 0000000000000..92be473919fd6 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import React from 'react'; +import { EuiDelayRender, EuiLoadingContent } from '@elastic/eui'; + +const Fallback = () => ( + + + +); + +export function RendererWrapper({ children }) { + return }>{children}; +} diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx index 05e6aa3aec8c8..c8558bcdc0d4f 100644 --- a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -6,19 +6,22 @@ * Side Public License, v 1. */ -import React, { useRef, useLoaded, useCallback } from 'react'; +import React, { useRef, useState, useEffect, useCallback } from 'react'; +import { EuiDelayRender, EuiLoadingContent } from '@elastic/eui'; +import { debounce } from 'lodash'; import { RevealImageRendererConfig, NodeDimensions } from '../expression_renderers/types'; import { RendererHandlers } from '../../common/types'; +import { isValidUrl } from '../../common/lib/url'; interface RevealImageComponentProps { handlers: RendererHandlers; [property in RevealImageRendererConfig]: RevealImageRendererConfig[property]; - parentNodeDimensions: NodeDimensions; + parentNode: HTMLElement; } function RevealImageComponent({ handlers, - parentNodeParameters, + parentNode, percent, origin, image, @@ -26,31 +29,34 @@ function RevealImageComponent({ }: RevealImageComponentProps) { const [loaded, setLoaded] = useState(false); const [dimensions, setDimensions] = useState({ - width: 0, - height: 0, + width: 1, + height: 1, }); const imgRef = useRef(null); + // modify the top-level container class + parentNode.className = 'revealImage'; + // set up the overlay image const onLoad = useCallback(() => { setLoaded(true); if (imgRef.current) { - setDimensions( - { - height: imgRef.current.naturalHeight, - width: imgRef.current.naturalWidth, - }, - // () => handlers.done() - ); - console.log('here'); + setDimensions({ + height: imgRef.current.naturalHeight, + width: imgRef.current.naturalWidth, + }); + return handlers.done(); } }, [imgRef, handlers]); useEffect(() => { - // handlers.onResize(onLoad); - return handlers.destroy(); - }, [handlers, onLoad]); + const cleanupResizeHandler = handlers.onResize(onLoad); + return () => { + cleanupResizeHandler(); + handlers.destroy(); + }; + }, [onLoad, handlers]); function getClipPath(percentParam: number, originParam = 'bottom') { const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; @@ -65,13 +71,13 @@ function RevealImageComponent({ const imgDimensions = { height: dimensions.height, width: dimensions.width, - ratio: dimensions.width > 0 ? dimensions.height / dimensions.width : 0, + ratio: dimensions.height / dimensions.width, }; const domNodeDimensions = { - height: parentNodeParameters.height, - width: parentNodeParameters.width, - ratio: parentNodeParameters.height / parentNodeParameters.width, + width: parentNode.clientWidth, + height: parentNode.clientHeight, + ratio: parentNode.clientHeight / parentNode.clientWidth, }; if (imgDimensions.ratio > domNodeDimensions.ratio) { @@ -93,7 +99,7 @@ function RevealImageComponent({ alignerStyles.backgroundImage = `url(${emptyImage})`; } - const imgStyles = {}; + let imgStyles = {}; if (imgRef.current && loaded) imgStyles = getImageSizeStyle(); imgStyles.clipPath = getClipPath(percent, origin); @@ -102,7 +108,7 @@ function RevealImageComponent({ } return ( -
+
); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx index 8a6531a28360f..0cb51c890bd70 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx @@ -13,7 +13,8 @@ import { isValidUrl } from '../../common/lib/url'; import { getRendererStrings } from '../../common/i18n'; import { RendererFactory } from '../../common/types'; import { Output as Arguments } from '../expression_functions'; -import { RevealImageRendererConfig, NodeDimensions } from './types'; +import { RevealImageRendererConfig } from './types'; +import { RendererWrapper } from '../components/renderer_wrapper'; const { revealImage: revealImageStrings } = getRendererStrings(); @@ -29,21 +30,11 @@ export const revealImageRenderer: RendererFactory = () => ({ unmountComponentAtNode(domNode); }); - // modify the top-level container class - domNode.className = 'revealImage'; - - const parentNodeDimensions: NodeDimensions = { - width: domNode.clientWidth, - height: domNode.clientHeight, - }; - render( - + + + , domNode ); From 03b214fb6a7e868283934173a61ecdb9898b5200 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 15:49:23 +0300 Subject: [PATCH 06/77] Added legacy support. Added button for legacy. --- .../common/constants.ts | 10 +++ .../expression_reveal_image/common/index.ts | 3 +- .../expression_reveal_image/kibana.json | 4 +- .../components/reveal_image_component.tsx | 3 +- .../reveal_image.stories.storyshot | 14 +++ .../__stories__/render.tsx | 70 +++++++++++++++ .../__stories__/reveal_image.stories.tsx | 26 ++++++ .../expression_renderers_legacy/index.ts | 89 +++++++++++++++++++ .../expression_reveal_image/public/plugin.ts | 10 ++- .../expression_reveal_image/server/index.ts | 11 +++ .../expression_reveal_image/server/plugin.ts | 20 +++++ .../server/ui_settings.ts | 33 +++++++ 12 files changed, 285 insertions(+), 8 deletions(-) create mode 100644 src/plugins/expression_reveal_image/common/constants.ts create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/render.tsx create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts create mode 100644 src/plugins/expression_reveal_image/server/index.ts create mode 100644 src/plugins/expression_reveal_image/server/plugin.ts create mode 100644 src/plugins/expression_reveal_image/server/ui_settings.ts diff --git a/src/plugins/expression_reveal_image/common/constants.ts b/src/plugins/expression_reveal_image/common/constants.ts new file mode 100644 index 0000000000000..c01ef82e1b00c --- /dev/null +++ b/src/plugins/expression_reveal_image/common/constants.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +export const PLUGIN_ID = 'expressionRevealImage'; +export const PLUGIN_NAME = 'expressionRevealImage'; +export const LEGACY_RENDERER_LIBRARY = `labs:expressions:${PLUGIN_NAME}:legacyRendererLibrary`; diff --git a/src/plugins/expression_reveal_image/common/index.ts b/src/plugins/expression_reveal_image/common/index.ts index 4133f27f96ab9..d8989abcc3d6f 100755 --- a/src/plugins/expression_reveal_image/common/index.ts +++ b/src/plugins/expression_reveal_image/common/index.ts @@ -6,5 +6,4 @@ * Side Public License, v 1. */ -export const PLUGIN_ID = 'expressionRevealImage'; -export const PLUGIN_NAME = 'expressionRevealImage'; +export * from './constants'; diff --git a/src/plugins/expression_reveal_image/kibana.json b/src/plugins/expression_reveal_image/kibana.json index b2579bd061e5d..9af9a5857dcfb 100755 --- a/src/plugins/expression_reveal_image/kibana.json +++ b/src/plugins/expression_reveal_image/kibana.json @@ -2,9 +2,9 @@ "id": "expressionRevealImage", "version": "1.0.0", "kibanaVersion": "kibana", - "server": false, + "server": true, "ui": true, - "requiredPlugins": ["expressions"], + "requiredPlugins": ["expressions", "presentationUtil"], "optionalPlugins": [], "requiredBundles": [] } diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx index c8558bcdc0d4f..d58a05cc0b887 100644 --- a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -51,9 +51,8 @@ function RevealImageComponent({ }, [imgRef, handlers]); useEffect(() => { - const cleanupResizeHandler = handlers.onResize(onLoad); + handlers.onResize(onLoad); return () => { - cleanupResizeHandler(); handlers.destroy(); }; }, [onLoad, handlers]); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot new file mode 100644 index 0000000000000..b9963565a09f5 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots renderers/revealImage default 1`] = ` +
+ +
+`; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/render.tsx b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/render.tsx new file mode 100644 index 0000000000000..b35a5233f5028 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/render.tsx @@ -0,0 +1,70 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { action } from '@storybook/addon-actions'; +import React, { useRef, useEffect } from 'react'; +import { RendererFactory, RendererHandlers } from '../../common/types'; + +export const defaultHandlers: RendererHandlers = { + destroy: () => action('destroy'), + getElementId: () => 'element-id', + getFilter: () => 'filter', + getRenderMode: () => 'display', + isSyncColorsEnabled: () => false, + onComplete: (fn) => undefined, + onEmbeddableDestroyed: action('onEmbeddableDestroyed'), + onEmbeddableInputChange: action('onEmbeddableInputChange'), + onResize: action('onResize'), + resize: action('resize'), + setFilter: action('setFilter'), + done: action('done'), + onDestroy: action('onDestroy'), + reload: action('reload'), + update: action('update'), + event: action('event'), +}; + +/* + Uses a RenderDefinitionFactory and Config to render into an element. + + Intended to be used for stories for RenderDefinitionFactory +*/ +interface RenderAdditionalProps { + height?: string; + width?: string; + handlers?: RendererHandlers; +} + +export const Render = ({ + renderer, + config, + ...rest +}: Renderer extends RendererFactory + ? { renderer: Renderer; config: Config } & RenderAdditionalProps + : { renderer: undefined; config: undefined } & RenderAdditionalProps) => { + const { height, width, handlers } = { + height: '200px', + width: '200px', + handlers: defaultHandlers, + ...rest, + }; + + const containerRef = useRef(null); + + useEffect(() => { + if (renderer && containerRef.current !== null) { + renderer().render(containerRef.current, config, handlers); + } + }, [renderer, config, handlers]); + + return ( +
+ {' '} +
+ ); +}; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx new file mode 100644 index 0000000000000..7d4d1ea392deb --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx @@ -0,0 +1,26 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import React from 'react'; +import { storiesOf } from '@storybook/react'; +import { revealImage } from '../'; +import { Render } from './render'; +import { elasticOutline } from '../../../common/lib/elastic_outline'; +import { elasticOutline } from '../../../common/lib/elastic_logo'; +import { Origin } from '../../expression_functions'; + +storiesOf('renderers/revealImage_legacy', module).add('default', () => { + const config = { + image: elasticLogo, + emptyImage: elasticOutline, + origin: Origin.LEFT, + percent: 0.45, + }; + + return ; +}); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts new file mode 100644 index 0000000000000..eccc17e928b1e --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts @@ -0,0 +1,89 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { elasticOutline } from '../../common/lib/elastic_outline'; +import { isValidUrl } from '../../common/lib/url'; +import { getRendererStrings } from '../../common/i18n'; +import { RendererFactory } from '../../common/types'; +import { Output as Arguments } from '../expression_functions'; + +const { revealImage: strings } = getRendererStrings(); + +export const revealImage: RendererFactory = () => ({ + name: 'revealImageExpr', + displayName: strings.getDisplayName(), + help: strings.getHelpDescription(), + reuseDomNode: true, + render(domNode, config, handlers) { + const aligner = document.createElement('div'); + const img = new Image(); + + // modify the top-level container class + domNode.className = 'revealImage'; + + // set up the overlay image + function onLoad() { + setSize(); + finish(); + } + img.onload = onLoad; + + img.className = 'revealImage__image'; + img.style.clipPath = getClipPath(config.percent, config.origin); + img.style.setProperty('-webkit-clip-path', getClipPath(config.percent, config.origin)); + img.src = isValidUrl(config.image) ? config.image : elasticOutline; + handlers.onResize(onLoad); + + // set up the underlay, "empty" image + aligner.className = 'revealImageAligner'; + aligner.appendChild(img); + if (isValidUrl(config.emptyImage)) { + // only use empty image if one is provided + aligner.style.backgroundImage = `url(${config.emptyImage})`; + } + + function finish() { + const firstChild = domNode.firstChild; + if (firstChild) { + domNode.replaceChild(aligner, firstChild); + } else { + domNode.appendChild(aligner); + } + handlers.done(); + } + + function getClipPath(percent: number, origin = 'bottom') { + const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; + const values: Array = [0, 0, 0, 0]; + values[directions[origin]] = `${100 - percent * 100}%`; + return `inset(${values.join(' ')})`; + } + + function setSize() { + const imgDimensions = { + height: img.naturalHeight, + width: img.naturalWidth, + ratio: img.naturalHeight / img.naturalWidth, + }; + + const domNodeDimensions = { + height: domNode.clientHeight, + width: domNode.clientWidth, + ratio: domNode.clientHeight / domNode.clientWidth, + }; + + if (imgDimensions.ratio > domNodeDimensions.ratio) { + img.style.height = `${domNodeDimensions.height}px`; + img.style.width = 'initial'; + } else { + img.style.width = `${domNodeDimensions.width}px`; + img.style.height = 'initial'; + } + } + }, +}); diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts index 3ea0f12c2a614..2395a4cdf2e7d 100755 --- a/src/plugins/expression_reveal_image/public/plugin.ts +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -8,9 +8,10 @@ import { i18n } from '@kbn/i18n'; import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../core/public'; import { ExpressionsStart, ExpressionsSetup } from '../../../src/plugins/expressions/public'; -import { PLUGIN_NAME } from '../common'; +import { LEGACY_RENDERER_LIBRARY, PLUGIN_NAME } from '../common'; import { revealImageFunction } from './expression_functions'; import { revealImageRenderer } from './expression_renderers'; +import { revealImage as revealImageRendererLegacy } from './expression_renderers_legacy'; interface SetupDeps { expressions: ExpressionsSetup; @@ -23,7 +24,12 @@ interface StartDeps { export class ExpressionRevealImagePlugin implements Plugin { public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup { expressions.registerFunction(revealImageFunction); - expressions.registerRenderer(revealImageRenderer); + + if (!core.uiSettings.get(LEGACY_RENDERER_LIBRARY, false)) { + expressions.registerRenderer(revealImageRenderer); + } else { + expressions.registerRenderer(revealImageRendererLegacy); + } } public start(core: CoreStart): ExpressionRevealImagePluginStart { diff --git a/src/plugins/expression_reveal_image/server/index.ts b/src/plugins/expression_reveal_image/server/index.ts new file mode 100644 index 0000000000000..26c352b0bb333 --- /dev/null +++ b/src/plugins/expression_reveal_image/server/index.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ExpressionRevealImageServerPlugin } from './plugin'; + +export const plugin = () => new ExpressionRevealImageServerPlugin(); diff --git a/src/plugins/expression_reveal_image/server/plugin.ts b/src/plugins/expression_reveal_image/server/plugin.ts new file mode 100644 index 0000000000000..b1449033701d4 --- /dev/null +++ b/src/plugins/expression_reveal_image/server/plugin.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { CoreSetup, Plugin, UiSettingsParams } from 'kibana/server'; +import { getUiSettingsConfig } from './ui_settings'; + +export class ExpressionRevealImageServerPlugin implements Plugin { + public setup(core: CoreSetup) { + core.uiSettings.register(getUiSettingsConfig()); + return {}; + } + + public start() { + return {}; + } +} diff --git a/src/plugins/expression_reveal_image/server/ui_settings.ts b/src/plugins/expression_reveal_image/server/ui_settings.ts new file mode 100644 index 0000000000000..f4d0afff3ab9a --- /dev/null +++ b/src/plugins/expression_reveal_image/server/ui_settings.ts @@ -0,0 +1,33 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { i18n } from '@kbn/i18n'; +import { schema } from '@kbn/config-schema'; + +import { UiSettingsParams } from 'kibana/server'; + +import { SETTING_CATEGORY } from '../../presentation_util/server'; +import { LEGACY_RENDERER_LIBRARY } from '../common'; + +export const getUiSettingsConfig: () => Record> = () => ({ + [LEGACY_RENDERER_LIBRARY]: { + name: i18n.translate('expressionRevealImage.advancedSettings.legacyRendererLibrary.name', { + defaultMessage: 'Legacy expression reveal image renderer library', + }), + requiresPageReload: true, + value: false, + description: i18n.translate( + 'expressionRevealImage.advancedSettings.legacyRendererLibrary.description', + { + defaultMessage: 'Enables legacy renderer library for revealImage expression in canvas.', + } + ), + category: [SETTING_CATEGORY], + schema: schema.boolean(), + }, +}); From 010b7b9212df34ea1a4e45649aaca410109f2962 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 16:45:37 +0300 Subject: [PATCH 07/77] Added storybook. --- src/dev/storybook/aliases.ts | 1 + .../.storybook/main.js | 10 +++++++ .../public/__stories__/index.tsx | 9 +++++++ .../__stories__/render.tsx | 0 .../reveal_image.stories.storyshot | 14 ++++++++++ .../__stories__/reveal_image.scss | 18 +++++++++++++ .../reveal_image_renderer.stories.tsx | 27 +++++++++++++++++++ .../reveal_image.stories.storyshot | 2 +- .../__stories__/reveal_image.scss | 18 +++++++++++++ .../__stories__/reveal_image.stories.tsx | 5 ++-- 10 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/plugins/expression_reveal_image/.storybook/main.js create mode 100644 src/plugins/expression_reveal_image/public/__stories__/index.tsx rename src/plugins/expression_reveal_image/public/{expression_renderers_legacy => }/__stories__/render.tsx (100%) create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers/__stories__/__snapshots__/reveal_image.stories.storyshot create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image.scss create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx create mode 100644 src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.scss diff --git a/src/dev/storybook/aliases.ts b/src/dev/storybook/aliases.ts index e0f0432c61463..6fc0841551fad 100644 --- a/src/dev/storybook/aliases.ts +++ b/src/dev/storybook/aliases.ts @@ -17,6 +17,7 @@ export const storybookAliases = { dashboard_enhanced: 'x-pack/plugins/dashboard_enhanced/.storybook', data_enhanced: 'x-pack/plugins/data_enhanced/.storybook', embeddable: 'src/plugins/embeddable/.storybook', + expression_reveal_image: 'src/plugins/expression_reveal_image/.storybook', infra: 'x-pack/plugins/infra/.storybook', security_solution: 'x-pack/plugins/security_solution/.storybook', ui_actions_enhanced: 'x-pack/plugins/ui_actions_enhanced/.storybook', diff --git a/src/plugins/expression_reveal_image/.storybook/main.js b/src/plugins/expression_reveal_image/.storybook/main.js new file mode 100644 index 0000000000000..742239e638b8a --- /dev/null +++ b/src/plugins/expression_reveal_image/.storybook/main.js @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +// eslint-disable-next-line import/no-commonjs +module.exports = require('@kbn/storybook').defaultConfig; diff --git a/src/plugins/expression_reveal_image/public/__stories__/index.tsx b/src/plugins/expression_reveal_image/public/__stories__/index.tsx new file mode 100644 index 0000000000000..078a16cb8cab2 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/__stories__/index.tsx @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export * from './render'; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/render.tsx b/src/plugins/expression_reveal_image/public/__stories__/render.tsx similarity index 100% rename from src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/render.tsx rename to src/plugins/expression_reveal_image/public/__stories__/render.tsx diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/__snapshots__/reveal_image.stories.storyshot b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/__snapshots__/reveal_image.stories.storyshot new file mode 100644 index 0000000000000..b9963565a09f5 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/__snapshots__/reveal_image.stories.storyshot @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots renderers/revealImage default 1`] = ` +
+ +
+`; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image.scss b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image.scss new file mode 100644 index 0000000000000..f94668b7cdfa2 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image.scss @@ -0,0 +1,18 @@ +.revealImage { + height: 100%; + width: 100%; + display: flex; + align-items: center; + justify-content: center; + pointer-events: none; + + .revealImageAligner { + background-size: contain; + background-repeat: no-repeat; + } + + // disables selection and dragging + .revealImage__image { + user-select: none; + } +} diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx new file mode 100644 index 0000000000000..7f164fa9f2448 --- /dev/null +++ b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx @@ -0,0 +1,27 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import React from 'react'; +import { storiesOf } from '@storybook/react'; +import { revealImageRenderer } from '../'; +import { Render } from '../../__stories__'; +import { elasticOutline } from '../../../common/lib/elastic_outline'; +import { elasticLogo } from '../../../common/lib/elastic_logo'; +import { Origin } from '../../expression_functions'; +import './reveal_image.scss'; + +storiesOf('renderers/revealImage', module).add('default', () => { + const config = { + image: elasticLogo, + emptyImage: elasticOutline, + origin: Origin.LEFT, + percent: 0.45, + }; + + return ; +}); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot index b9963565a09f5..d8a4ea0e11a5c 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot +++ b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Storyshots renderers/revealImage default 1`] = ` +exports[`Storyshots renderers/revealImage_legacy default 1`] = `
{ const config = { From 13789f101e9098df46caf1644e8d6587e4413bef Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 17:39:33 +0300 Subject: [PATCH 08/77] Removed revealImage from canvas. --- .../expression_functions/reveal_image.test.ts | 2 +- .../reveal_image_function.ts | 4 +- .../{__stories__ => }/reveal_image.scss | 0 .../reveal_image_renderer.tsx | 3 +- .../expression_renderers_legacy/index.ts | 3 +- .../{__stories__ => }/reveal_image.scss | 0 .../expression_reveal_image/public/index.ts | 2 + .../functions/common/index.ts | 2 - .../functions/common/render.ts | 1 - .../functions/common/revealImage.ts | 83 ----------------- .../functions/common/reveal_image.test.js | 88 ------------------- .../canvas_plugin_src/renderers/core.ts | 2 - .../reveal_image.stories.storyshot | 14 --- .../__stories__/reveal_image.stories.tsx | 25 ------ .../renderers/reveal_image/index.ts | 88 ------------------- .../renderers/reveal_image/reveal_image.scss | 18 ---- .../canvas_plugin_src/uis/views/index.ts | 3 - .../uis/views/revealImage.js | 44 ---------- .../i18n/functions/dict/reveal_image.ts | 60 ------------- .../canvas/i18n/functions/function_errors.ts | 2 - .../canvas/i18n/functions/function_help.ts | 2 - x-pack/plugins/canvas/i18n/renderers.ts | 10 --- x-pack/plugins/canvas/kibana.json | 3 +- x-pack/plugins/canvas/public/style/index.scss | 2 - .../shareable_runtime/supported_renderers.js | 2 +- 25 files changed, 12 insertions(+), 451 deletions(-) rename src/plugins/expression_reveal_image/public/expression_renderers/{__stories__ => }/reveal_image.scss (100%) rename src/plugins/expression_reveal_image/public/expression_renderers_legacy/{__stories__ => }/reveal_image.scss (100%) delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/functions/common/revealImage.ts delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/functions/common/reveal_image.test.js delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/__stories__/__snapshots__/reveal_image.stories.storyshot delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/__stories__/reveal_image.stories.tsx delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/index.ts delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/reveal_image.scss delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/uis/views/revealImage.js delete mode 100644 x-pack/plugins/canvas/i18n/functions/dict/reveal_image.ts diff --git a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts index 1d58a62112265..2a961a5a3ab06 100644 --- a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts +++ b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts @@ -20,7 +20,7 @@ describe('revealImageFunction', () => { it('returns a render as revealImage', () => { const result = fn(0.5); expect(result).toHaveProperty('type', 'render'); - expect(result).toHaveProperty('as', 'revealImageExpr'); + expect(result).toHaveProperty('as', 'revealImage'); }); describe('context', () => { diff --git a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts index 80998f207dad5..0393509b3f99a 100644 --- a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts +++ b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts @@ -36,7 +36,7 @@ export function revealImageFunction(): ExpressionRevealImageFunction { const errors = getFunctionErrors().revealImage; return { - name: 'revealImageExpr', + name: 'revealImage', aliases: [], type: 'render', inputTypes: ['number'], @@ -66,7 +66,7 @@ export function revealImageFunction(): ExpressionRevealImageFunction { return { type: 'render', - as: 'revealImageExpr', + as: 'revealImage', value: { percent, ...args, diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image.scss b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image.scss similarity index 100% rename from src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image.scss rename to src/plugins/expression_reveal_image/public/expression_renderers/reveal_image.scss diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx index 0cb51c890bd70..cbda5b1c1f164 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx @@ -15,13 +15,14 @@ import { RendererFactory } from '../../common/types'; import { Output as Arguments } from '../expression_functions'; import { RevealImageRendererConfig } from './types'; import { RendererWrapper } from '../components/renderer_wrapper'; +import './reveal_image.scss'; const { revealImage: revealImageStrings } = getRendererStrings(); const RevealImageComponent = lazy(() => import('../components/reveal_image_component')); export const revealImageRenderer: RendererFactory = () => ({ - name: 'revealImageExpr', + name: 'revealImage', displayName: revealImageStrings.getDisplayName(), help: revealImageStrings.getHelpDescription(), reuseDomNode: true, diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts index eccc17e928b1e..8d281277c3240 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts +++ b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts @@ -11,11 +11,12 @@ import { isValidUrl } from '../../common/lib/url'; import { getRendererStrings } from '../../common/i18n'; import { RendererFactory } from '../../common/types'; import { Output as Arguments } from '../expression_functions'; +import './reveal_image.scss'; const { revealImage: strings } = getRendererStrings(); export const revealImage: RendererFactory = () => ({ - name: 'revealImageExpr', + name: 'revealImage', displayName: strings.getDisplayName(), help: strings.getHelpDescription(), reuseDomNode: true, diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.scss b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/reveal_image.scss similarity index 100% rename from src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.scss rename to src/plugins/expression_reveal_image/public/expression_renderers_legacy/reveal_image.scss diff --git a/src/plugins/expression_reveal_image/public/index.ts b/src/plugins/expression_reveal_image/public/index.ts index 8eb4ca7026421..e9fa799d15bc0 100755 --- a/src/plugins/expression_reveal_image/public/index.ts +++ b/src/plugins/expression_reveal_image/public/index.ts @@ -8,6 +8,8 @@ import { ExpressionRevealImagePlugin } from './plugin'; +export * from './expression_renderers'; + // This exports static code and TypeScript types, // as well as, Kibana Platform `plugin()` initializer. export function plugin() { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/index.ts index 5c4d1d55cff04..9da646e695861 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/index.ts @@ -43,7 +43,6 @@ import { replace } from './replace'; import { rounddate } from './rounddate'; import { rowCount } from './rowCount'; import { repeatImage } from './repeat_image'; -import { revealImage } from './revealImage'; import { seriesStyle } from './seriesStyle'; import { shape } from './shape'; import { sort } from './sort'; @@ -94,7 +93,6 @@ export const functions = [ render, repeatImage, replace, - revealImage, rounddate, rowCount, seriesStyle, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.ts index cc7fc00a5df1f..7a52833693cc6 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.ts @@ -49,7 +49,6 @@ export function render(): ExpressionFunctionDefinition< 'plot', 'progress', 'repeatImage', - 'revealImage', 'shape', 'table', 'time_filter', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/revealImage.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/revealImage.ts deleted file mode 100644 index 91d70609ab708..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/revealImage.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ExpressionFunctionDefinition, ExpressionValueRender } from 'src/plugins/expressions'; -import { resolveWithMissingImage } from '../../../common/lib/resolve_dataurl'; -import { elasticOutline } from '../../lib/elastic_outline'; -import { getFunctionHelp, getFunctionErrors } from '../../../i18n'; - -export enum Origin { - TOP = 'top', - LEFT = 'left', - BOTTOM = 'bottom', - RIGHT = 'right', -} - -interface Arguments { - image: string | null; - emptyImage: string | null; - origin: Origin; -} - -export interface Output { - image: string; - emptyImage: string; - origin: Origin; - percent: number; -} - -export function revealImage(): ExpressionFunctionDefinition< - 'revealImage', - number, - Arguments, - ExpressionValueRender -> { - const { help, args: argHelp } = getFunctionHelp().revealImage; - const errors = getFunctionErrors().revealImage; - - return { - name: 'revealImage', - aliases: [], - type: 'render', - inputTypes: ['number'], - help, - args: { - image: { - types: ['string', 'null'], - help: argHelp.image, - default: elasticOutline, - }, - emptyImage: { - types: ['string', 'null'], - help: argHelp.emptyImage, - default: null, - }, - origin: { - types: ['string'], - help: argHelp.origin, - default: 'bottom', - options: Object.values(Origin), - }, - }, - fn: (percent, args) => { - if (percent > 1 || percent < 0) { - throw errors.invalidPercent(percent); - } - - return { - type: 'render', - as: 'revealImage', - value: { - percent, - ...args, - image: resolveWithMissingImage(args.image, elasticOutline) as string, - emptyImage: resolveWithMissingImage(args.emptyImage) as string, - }, - }; - }, - }; -} diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/reveal_image.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/reveal_image.test.js deleted file mode 100644 index d97168c3aacc1..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/reveal_image.test.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { functionWrapper } from '../../../test_helpers/function_wrapper'; -import { elasticOutline } from '../../lib/elastic_outline'; -import { elasticLogo } from '../../lib/elastic_logo'; -import { getFunctionErrors } from '../../../i18n'; -import { revealImage } from './revealImage'; - -const errors = getFunctionErrors().revealImage; - -describe('revealImage', () => { - const fn = functionWrapper(revealImage); - - it('returns a render as revealImage', () => { - const result = fn(0.5); - expect(result).toHaveProperty('type', 'render'); - expect(result).toHaveProperty('as', 'revealImage'); - }); - - describe('context', () => { - it('throws when context is not a number between 0 and 1', () => { - expect(() => { - fn(10, { - image: elasticLogo, - emptyImage: elasticOutline, - origin: 'top', - }); - }).toThrow(new RegExp(errors.invalidPercent(10).message)); - - expect(() => { - fn(-0.1, { - image: elasticLogo, - emptyImage: elasticOutline, - origin: 'top', - }); - }).toThrow(new RegExp(errors.invalidPercent(-0.1).message)); - }); - }); - - describe('args', () => { - describe('image', () => { - it('sets the image', () => { - const result = fn(0.89, { image: elasticLogo }).value; - expect(result).toHaveProperty('image', elasticLogo); - }); - - it('defaults to the Elastic outline logo', () => { - const result = fn(0.89).value; - expect(result).toHaveProperty('image', elasticOutline); - }); - }); - - describe('emptyImage', () => { - it('sets the background image', () => { - const result = fn(0, { emptyImage: elasticLogo }).value; - expect(result).toHaveProperty('emptyImage', elasticLogo); - }); - - it('sets emptyImage to null', () => { - const result = fn(0).value; - expect(result).toHaveProperty('emptyImage', null); - }); - }); - - describe('origin', () => { - it('sets which side to start the reveal from', () => { - let result = fn(1, { origin: 'top' }).value; - expect(result).toHaveProperty('origin', 'top'); - result = fn(1, { origin: 'left' }).value; - expect(result).toHaveProperty('origin', 'left'); - result = fn(1, { origin: 'bottom' }).value; - expect(result).toHaveProperty('origin', 'bottom'); - result = fn(1, { origin: 'right' }).value; - expect(result).toHaveProperty('origin', 'right'); - }); - - it('defaults to bottom', () => { - const result = fn(1).value; - expect(result).toHaveProperty('origin', 'bottom'); - }); - }); - }); -}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/core.ts b/x-pack/plugins/canvas/canvas_plugin_src/renderers/core.ts index c6b40936c288a..3295332bb6316 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/core.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/core.ts @@ -14,7 +14,6 @@ import { pie } from './pie'; import { plot } from './plot'; import { progress } from './progress'; import { repeatImage } from './repeat_image'; -import { revealImage } from './reveal_image'; import { shape } from './shape'; import { table } from './table'; import { text } from './text'; @@ -29,7 +28,6 @@ export const renderFunctions = [ plot, progress, repeatImage, - revealImage, shape, table, text, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/__stories__/__snapshots__/reveal_image.stories.storyshot b/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/__stories__/__snapshots__/reveal_image.stories.storyshot deleted file mode 100644 index b9963565a09f5..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/__stories__/__snapshots__/reveal_image.stories.storyshot +++ /dev/null @@ -1,14 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Storyshots renderers/revealImage default 1`] = ` -
- -
-`; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/__stories__/reveal_image.stories.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/__stories__/reveal_image.stories.tsx deleted file mode 100644 index 672cecca1bead..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/__stories__/reveal_image.stories.tsx +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import React from 'react'; -import { storiesOf } from '@storybook/react'; -import { revealImage } from '../'; -import { Render } from '../../__stories__/render'; -import { elasticOutline } from '../../../lib/elastic_outline'; -import { elasticLogo } from '../../../lib/elastic_logo'; -import { Origin } from '../../../functions/common/revealImage'; - -storiesOf('renderers/revealImage', module).add('default', () => { - const config = { - image: elasticLogo, - emptyImage: elasticOutline, - origin: Origin.LEFT, - percent: 0.45, - }; - - return ; -}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/index.ts deleted file mode 100644 index 8d9ceb70f17a6..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/index.ts +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { elasticOutline } from '../../lib/elastic_outline'; -import { isValidUrl } from '../../../common/lib/url'; -import { RendererStrings } from '../../../i18n'; -import { RendererFactory } from '../../../types'; -import { Output as Arguments } from '../../functions/common/revealImage'; - -const { revealImage: strings } = RendererStrings; - -export const revealImage: RendererFactory = () => ({ - name: 'revealImage', - displayName: strings.getDisplayName(), - help: strings.getHelpDescription(), - reuseDomNode: true, - render(domNode, config, handlers) { - const aligner = document.createElement('div'); - const img = new Image(); - - // modify the top-level container class - domNode.className = 'revealImage'; - - // set up the overlay image - function onLoad() { - setSize(); - finish(); - } - img.onload = onLoad; - - img.className = 'revealImage__image'; - img.style.clipPath = getClipPath(config.percent, config.origin); - img.style.setProperty('-webkit-clip-path', getClipPath(config.percent, config.origin)); - img.src = isValidUrl(config.image) ? config.image : elasticOutline; - handlers.onResize(onLoad); - - // set up the underlay, "empty" image - aligner.className = 'revealImageAligner'; - aligner.appendChild(img); - if (isValidUrl(config.emptyImage)) { - // only use empty image if one is provided - aligner.style.backgroundImage = `url(${config.emptyImage})`; - } - - function finish() { - const firstChild = domNode.firstChild; - if (firstChild) { - domNode.replaceChild(aligner, firstChild); - } else { - domNode.appendChild(aligner); - } - handlers.done(); - } - - function getClipPath(percent: number, origin = 'bottom') { - const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; - const values: Array = [0, 0, 0, 0]; - values[directions[origin]] = `${100 - percent * 100}%`; - return `inset(${values.join(' ')})`; - } - - function setSize() { - const imgDimensions = { - height: img.naturalHeight, - width: img.naturalWidth, - ratio: img.naturalHeight / img.naturalWidth, - }; - - const domNodeDimensions = { - height: domNode.clientHeight, - width: domNode.clientWidth, - ratio: domNode.clientHeight / domNode.clientWidth, - }; - - if (imgDimensions.ratio > domNodeDimensions.ratio) { - img.style.height = `${domNodeDimensions.height}px`; - img.style.width = 'initial'; - } else { - img.style.width = `${domNodeDimensions.width}px`; - img.style.height = 'initial'; - } - } - }, -}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/reveal_image.scss b/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/reveal_image.scss deleted file mode 100644 index f94668b7cdfa2..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/reveal_image/reveal_image.scss +++ /dev/null @@ -1,18 +0,0 @@ -.revealImage { - height: 100%; - width: 100%; - display: flex; - align-items: center; - justify-content: center; - pointer-events: none; - - .revealImageAligner { - background-size: contain; - background-repeat: no-repeat; - } - - // disables selection and dragging - .revealImage__image { - user-select: none; - } -} diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/index.ts index ed8428f0203ca..045bb15e17ece 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/index.ts @@ -23,8 +23,6 @@ import { progress } from './progress'; // @ts-expect-error untyped local import { repeatImage } from './repeatImage'; // @ts-expect-error untyped local -import { revealImage } from './revealImage'; -// @ts-expect-error untyped local import { render } from './render'; // @ts-expect-error untyped local import { shape } from './shape'; @@ -44,7 +42,6 @@ export const viewSpecs = [ plot, progress, repeatImage, - revealImage, render, shape, table, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/revealImage.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/revealImage.js deleted file mode 100644 index 30e0b9a640f92..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/revealImage.js +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ViewStrings } from '../../../i18n'; - -const { RevealImage: strings } = ViewStrings; - -export const revealImage = () => ({ - name: 'revealImage', - displayName: strings.getDisplayName(), - modelArgs: [['_', { label: 'Value' }]], - args: [ - { - name: 'image', - displayName: strings.getImageDisplayName(), - help: strings.getImageHelp(), - argType: 'imageUpload', - }, - { - name: 'emptyImage', - displayName: strings.getEmptyImageDisplayName(), - help: strings.getEmptyImageHelp(), - argType: 'imageUpload', - }, - { - name: 'origin', - displayName: strings.getOriginDisplayName(), - help: strings.getOriginHelp(), - argType: 'select', - options: { - choices: [ - { value: 'top', name: strings.getOriginTop() }, - { value: 'left', name: strings.getOriginLeft() }, - { value: 'bottom', name: strings.getOriginBottom() }, - { value: 'right', name: strings.getOriginRight() }, - ], - }, - }, - ], -}); diff --git a/x-pack/plugins/canvas/i18n/functions/dict/reveal_image.ts b/x-pack/plugins/canvas/i18n/functions/dict/reveal_image.ts deleted file mode 100644 index 374334824d61a..0000000000000 --- a/x-pack/plugins/canvas/i18n/functions/dict/reveal_image.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { i18n } from '@kbn/i18n'; -import { revealImage } from '../../../canvas_plugin_src/functions/common/revealImage'; -import { FunctionHelp } from '../function_help'; -import { FunctionFactory } from '../../../types'; -import { Position } from '../../../types'; -import { BASE64, URL } from '../../constants'; - -export const help: FunctionHelp> = { - help: i18n.translate('xpack.canvas.functions.revealImageHelpText', { - defaultMessage: 'Configures an image reveal element.', - }), - args: { - image: i18n.translate('xpack.canvas.functions.revealImage.args.imageHelpText', { - defaultMessage: - 'The image to reveal. Provide an image asset as a {BASE64} data {URL}, ' + - 'or pass in a sub-expression.', - values: { - BASE64, - URL, - }, - }), - emptyImage: i18n.translate('xpack.canvas.functions.revealImage.args.emptyImageHelpText', { - defaultMessage: - 'An optional background image to reveal over. ' + - 'Provide an image asset as a `{BASE64}` data {URL}, or pass in a sub-expression.', - values: { - BASE64, - URL, - }, - }), - origin: i18n.translate('xpack.canvas.functions.revealImage.args.originHelpText', { - defaultMessage: 'The position to start the image fill. For example, {list}, or {end}.', - values: { - list: Object.values(Position) - .slice(0, -1) - .map((position) => `\`"${position}"\``) - .join(', '), - end: Object.values(Position).slice(-1)[0], - }, - }), - }, -}; -export const errors = { - invalidPercent: (percent: number) => - new Error( - i18n.translate('xpack.canvas.functions.revealImage.invalidPercentErrorMessage', { - defaultMessage: "Invalid value: '{percent}'. Percentage must be between 0 and 1", - values: { - percent, - }, - }) - ), -}; diff --git a/x-pack/plugins/canvas/i18n/functions/function_errors.ts b/x-pack/plugins/canvas/i18n/functions/function_errors.ts index 4a85018c1b4ac..a01cb09a38347 100644 --- a/x-pack/plugins/canvas/i18n/functions/function_errors.ts +++ b/x-pack/plugins/canvas/i18n/functions/function_errors.ts @@ -19,7 +19,6 @@ import { errors as joinRows } from './dict/join_rows'; import { errors as ply } from './dict/ply'; import { errors as pointseries } from './dict/pointseries'; import { errors as progress } from './dict/progress'; -import { errors as revealImage } from './dict/reveal_image'; import { errors as timefilter } from './dict/timefilter'; import { errors as to } from './dict/to'; @@ -38,7 +37,6 @@ export const getFunctionErrors = () => ({ ply, pointseries, progress, - revealImage, timefilter, to, }); diff --git a/x-pack/plugins/canvas/i18n/functions/function_help.ts b/x-pack/plugins/canvas/i18n/functions/function_help.ts index 512ebc4ff8c93..b72d410ddd63f 100644 --- a/x-pack/plugins/canvas/i18n/functions/function_help.ts +++ b/x-pack/plugins/canvas/i18n/functions/function_help.ts @@ -57,7 +57,6 @@ import { help as progress } from './dict/progress'; import { help as render } from './dict/render'; import { help as repeatImage } from './dict/repeat_image'; import { help as replace } from './dict/replace'; -import { help as revealImage } from './dict/reveal_image'; import { help as rounddate } from './dict/rounddate'; import { help as rowCount } from './dict/row_count'; import { help as savedLens } from './dict/saved_lens'; @@ -218,7 +217,6 @@ export const getFunctionHelp = (): FunctionHelpDict => ({ render, repeatImage, replace, - revealImage, rounddate, rowCount, savedLens, diff --git a/x-pack/plugins/canvas/i18n/renderers.ts b/x-pack/plugins/canvas/i18n/renderers.ts index f74516433f924..29687155818e7 100644 --- a/x-pack/plugins/canvas/i18n/renderers.ts +++ b/x-pack/plugins/canvas/i18n/renderers.ts @@ -139,16 +139,6 @@ export const RendererStrings = { defaultMessage: 'Repeat an image a given number of times', }), }, - revealImage: { - getDisplayName: () => - i18n.translate('xpack.canvas.renderer.revealImage.displayName', { - defaultMessage: 'Image reveal', - }), - getHelpDescription: () => - i18n.translate('xpack.canvas.renderer.revealImage.helpDescription', { - defaultMessage: 'Reveal a percentage of an image to make a custom gauge-style chart', - }), - }, shape: { getDisplayName: () => i18n.translate('xpack.canvas.renderer.shape.displayName', { diff --git a/x-pack/plugins/canvas/kibana.json b/x-pack/plugins/canvas/kibana.json index 5faeaefc9e392..22c8d4e0d2ab4 100644 --- a/x-pack/plugins/canvas/kibana.json +++ b/x-pack/plugins/canvas/kibana.json @@ -14,7 +14,8 @@ "features", "inspector", "presentationUtil", - "uiActions" + "uiActions", + "expressionRevealImage" ], "optionalPlugins": [ "home", diff --git a/x-pack/plugins/canvas/public/style/index.scss b/x-pack/plugins/canvas/public/style/index.scss index a79e07a7d0016..07c24b038238f 100644 --- a/x-pack/plugins/canvas/public/style/index.scss +++ b/x-pack/plugins/canvas/public/style/index.scss @@ -45,11 +45,9 @@ @import '../components/workpad_page/workpad_page'; @import '../components/workpad_page/workpad_interactive_page/workpad_interactive_page'; @import '../components/workpad_page/workpad_static_page/workpad_static_page'; - @import '../../canvas_plugin_src/renderers/filters/advanced_filter/component/advanced_filter.scss'; @import '../../canvas_plugin_src/renderers/filters/dropdown_filter/component/dropdown_filter.scss'; @import '../../canvas_plugin_src/renderers/embeddable/embeddable.scss'; @import '../../canvas_plugin_src/renderers/plot/plot.scss'; -@import '../../canvas_plugin_src/renderers/reveal_image/reveal_image.scss'; @import '../../canvas_plugin_src/renderers/filters/time_filter/time_filter.scss'; @import '../../canvas_plugin_src/uis/arguments/image_upload/image_upload.scss'; diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js index 8ee96aeec2951..99d83f35ea992 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js @@ -9,7 +9,7 @@ import { debug } from '../canvas_plugin_src/renderers/debug'; import { error } from '../canvas_plugin_src/renderers/error'; import { image } from '../canvas_plugin_src/renderers/image'; import { repeatImage } from '../canvas_plugin_src/renderers/repeat_image'; -import { revealImage } from '../canvas_plugin_src/renderers/reveal_image'; +import { revealImageRenderer as revealImage } from '../../../../src/plugins/expression_reveal_image/public'; import { markdown } from '../canvas_plugin_src/renderers/markdown'; import { metric } from '../canvas_plugin_src/renderers/metric'; import { pie } from '../canvas_plugin_src/renderers/pie'; From 96ec59bc513a57f486920563527bdbbf50f0a3df Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 17:42:23 +0300 Subject: [PATCH 09/77] setState while rendering error fixed. --- .../public/components/reveal_image_component.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx index d58a05cc0b887..350f102814b29 100644 --- a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -40,8 +40,8 @@ function RevealImageComponent({ // set up the overlay image const onLoad = useCallback(() => { - setLoaded(true); if (imgRef.current) { + setLoaded(true); setDimensions({ height: imgRef.current.naturalHeight, width: imgRef.current.naturalWidth, From fc13023fe3291cf7109a574b5de062c7195eb828 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 17:46:19 +0300 Subject: [PATCH 10/77] tsconfig.json added. --- .../expression_reveal_image/tsconfig.json | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/plugins/expression_reveal_image/tsconfig.json diff --git a/src/plugins/expression_reveal_image/tsconfig.json b/src/plugins/expression_reveal_image/tsconfig.json new file mode 100644 index 0000000000000..09a6d24dd7839 --- /dev/null +++ b/src/plugins/expression_reveal_image/tsconfig.json @@ -0,0 +1,20 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outDir": "./target/types", + "emitDeclarationOnly": true, + "declaration": true, + "declarationMap": true, + "isolatedModules": true + }, + "include": [ + "common/**/*", + "public/**/*", + "server/**/*", + ], + "references": [ + { "path": "../../core/tsconfig.json" }, + { "path": "../expressions/tsconfig.json" }, + ] +} From 4196c5df32b9239ad76893ed8e2699a314855cf9 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 17:47:49 +0300 Subject: [PATCH 11/77] jest.config.js added. --- src/plugins/expression_reveal_image/jest.config.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/plugins/expression_reveal_image/jest.config.js diff --git a/src/plugins/expression_reveal_image/jest.config.js b/src/plugins/expression_reveal_image/jest.config.js new file mode 100644 index 0000000000000..aac5fad293846 --- /dev/null +++ b/src/plugins/expression_reveal_image/jest.config.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test', + rootDir: '../../..', + roots: ['/src/plugins/expression_reveal_image'], +}; From 6be3ccfad3b452656300d0f01ef9d7db234f529c Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 17:51:51 +0300 Subject: [PATCH 12/77] Demo doc added. --- docs/developer/plugin-list.asciidoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/developer/plugin-list.asciidoc b/docs/developer/plugin-list.asciidoc index 6675a8dd283c9..2c75eaf169edf 100644 --- a/docs/developer/plugin-list.asciidoc +++ b/docs/developer/plugin-list.asciidoc @@ -72,6 +72,10 @@ This API doesn't support angular, for registering angular dev tools, bootstrap a |This plugin contains reusable code in the form of self-contained modules (or libraries). Each of these modules exports a set of functionality relevant to the domain of the module. +|{kib-repo}blob/{branch}/src/plugins/expression_reveal_image/README.md[expressionRevealImage] +| This plugin addes expression to the canvas to be rendered + + |<> |Expression pipeline is a chain of functions that *pipe* its output to the input of the next function. Functions can be configured using arguments provided From b317f8bba687893ff8a93922bde090d386aea0fd Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 20:09:31 +0300 Subject: [PATCH 13/77] Types fixed. --- .i18nrc.json | 1 + .../expression_functions/dict/reveal_image.ts | 5 +- .../expression_functions/function_help.ts | 5 +- .../common/test_helpers/function_wrapper.ts | 7 +- .../common/types/expression_functions.ts | 95 +++---------- .../common/types/expression_renderers.ts | 21 ++- .../public/components/renderer_wrapper.tsx | 6 +- .../components/reveal_image_component.tsx | 44 +++--- .../public/expression_functions/index.ts | 1 + .../expression_functions/reveal_image.test.ts | 125 +++++++++++++---- .../reveal_image_function.ts | 26 +--- .../reveal_image_renderer.stories.tsx | 2 +- .../public/expression_renderers/index.ts | 2 +- .../reveal_image_renderer.tsx | 13 +- .../public/expression_renderers/types.ts | 3 +- .../__stories__/reveal_image.stories.tsx | 2 +- .../expression_renderers_legacy/index.ts | 130 +++++++++--------- .../expression_reveal_image/public/plugin.ts | 12 +- .../expression_reveal_image/server/plugin.ts | 2 +- .../expression_reveal_image/tsconfig.json | 1 + 20 files changed, 261 insertions(+), 242 deletions(-) diff --git a/.i18nrc.json b/.i18nrc.json index ad91042a2172d..0e2598bd46339 100644 --- a/.i18nrc.json +++ b/.i18nrc.json @@ -16,6 +16,7 @@ "esUi": "src/plugins/es_ui_shared", "devTools": "src/plugins/dev_tools", "expressions": "src/plugins/expressions", + "expressionRevealImage": "src/plugins/expression_reveal_image", "inputControl": "src/plugins/input_control_vis", "inspector": "src/plugins/inspector", "inspectorViews": "src/legacy/core_plugins/inspector_views", diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts index 34ee66febe516..9d2e00ab8c9bc 100644 --- a/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts +++ b/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts @@ -7,11 +7,10 @@ */ import { i18n } from '@kbn/i18n'; -import { FunctionHelp } from '../function_help'; -import { ExpressionRevealImageFunction, FunctionFactory, Position } from '../../../types'; +import { Position } from '../../../types'; import { BASE64, URL } from '../../constants'; -export const help: FunctionHelp> = { +export const help = { help: i18n.translate('xpack.canvas.functions.revealImageHelpText', { defaultMessage: 'Configures an image reveal element.', }), diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_help.ts b/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_help.ts index 6f49cf8471da5..30e79b120771b 100644 --- a/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_help.ts +++ b/src/plugins/expression_reveal_image/common/i18n/expression_functions/function_help.ts @@ -6,9 +6,6 @@ * Side Public License, v 1. */ -import { ExpressionFunctionDefinition } from 'src/plugins/expressions'; -import { UnionToIntersection } from '@kbn/utility-types'; - import { help as revealImage } from './dict/reveal_image'; /** @@ -19,6 +16,6 @@ import { help as revealImage } from './dict/reveal_image'; * This a function, rather than an object, to future-proof string initialization, * if ever necessary. */ -export const getFunctionHelp = (): FunctionHelpDict => ({ +export const getFunctionHelp = () => ({ revealImage, }); diff --git a/src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts b/src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts index 4dc8c93f9ba7b..4b0ef266f974d 100644 --- a/src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts +++ b/src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts @@ -10,12 +10,13 @@ import { mapValues } from 'lodash'; import { ExpressionRevealImageFunction } from '../types'; // It takes a function spec and passes in default args into the spec fn -export const functionWrapper = (fnSpec: () => ExpressionRevealImageFunction, mockReduxStore) => { +export const functionWrapper = ( + fnSpec: ExpressionRevealImageFunction +): ReturnType['fn'] => { const spec = fnSpec(); const defaultArgs = mapValues(spec.args, (argSpec) => { return argSpec.default; }); - return (context, args, handlers) => - spec.fn(context, { ...defaultArgs, ...args }, handlers, mockReduxStore); + return (context, args, handlers) => spec.fn(context, { ...defaultArgs, ...args }, handlers); }; diff --git a/src/plugins/expression_reveal_image/common/types/expression_functions.ts b/src/plugins/expression_reveal_image/common/types/expression_functions.ts index 9ed220758760f..ee291e204acfb 100644 --- a/src/plugins/expression_reveal_image/common/types/expression_functions.ts +++ b/src/plugins/expression_reveal_image/common/types/expression_functions.ts @@ -7,86 +7,33 @@ */ import { ExpressionFunctionDefinition, ExpressionValueRender } from 'src/plugins/expressions'; +export enum Origin { + TOP = 'top', + LEFT = 'left', + BOTTOM = 'bottom', + RIGHT = 'right', +} + +interface Arguments { + image: string | null; + emptyImage: string | null; + origin: Origin; +} + +export interface Output { + image: string; + emptyImage: string; + origin: Origin; + percent: number; +} + export type ExpressionRevealImageFunction = () => ExpressionFunctionDefinition< - 'revealImageExpr', + 'revealImage', number, Arguments, ExpressionValueRender >; -/** - * This type defines an entry in the `FunctionHelpMap`. It uses - * an `ExpressionFunction` to infer its `Arguments` in order to strongly-type that - * entry. - * - * For example: - * -``` - interface Arguments { - bar: string; - baz: number; - } - - function foo(): ExpressionFunction<'foo', Context, Arguments, Return> { - // ... - } - - const help: FunctionHelp = { - help: 'Some help for foo', - args: { - bar: 'Help for bar.', // pass; error if missing - baz: 'Help for baz.', // pass; error if missing - zap: 'Help for zap.`, // error: zap doesn't exist - } - }; -``` - * This allows one to ensure each argument is present, and no extraneous arguments - * remain. - */ -export type FunctionHelp = T extends ExpressionFunctionDefinition< - infer Name, - infer Input, - infer Arguments, - infer Output -> - ? { - help: string; - args: { [key in keyof Arguments]: string }; - } - : never; - -// This internal type infers a Function name and uses `FunctionHelp` above to build -// a dictionary entry. This can be used to ensure every Function is defined and all -// Arguments have help strings. -// -// For example: -// -// function foo(): ExpressionFunction<'foo', Context, Arguments, Return> { -// // ... -// } -// -// const map: FunctionHelpMap = { -// foo: FunctionHelp, -// } -// -// Given a collection of functions, the map would contain each entry. -// -export type FunctionHelpMap = T extends ExpressionFunctionDefinition< - infer Name, - infer Input, - infer Arguments, - infer Output -> - ? { [key in Name]: FunctionHelp } - : never; - -// This internal type represents an exhaustive dictionary of `FunctionHelp` types, -// organized by Function Name and then Function Argument. -// -// This type indexes the existing function factories, reverses the union to an -// intersection, and produces the dictionary of strings. -export type FunctionHelpDict = UnionToIntersection>; - export enum Position { TOP = 'top', BOTTOM = 'bottom', diff --git a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts index 74fabfdd39b8a..3d6a399cfc4ec 100644 --- a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts +++ b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts @@ -12,23 +12,23 @@ type GenericRendererCallback = (callback: () => void) => void; export interface RendererHandlers extends IInterpreterRenderHandlers { /** Handler to invoke when an element should be destroyed. */ - destroy: () => void; + destroy?: () => void; /** Get the id of the element being rendered. Can be used as a unique ID in a render function */ - getElementId: () => string; + getElementId?: () => string; /** Retrieves the value of the filter property on the element object persisted on the workpad */ - getFilter: () => string; + getFilter?: () => string; /** Handler to invoke when a renderer is considered complete */ - onComplete: (fn: () => void) => void; + onComplete?: (fn: () => void) => void; /** Handler to invoke when a rendered embeddable is destroyed */ - onEmbeddableDestroyed: () => void; + onEmbeddableDestroyed?: () => void; /** Handler to invoke when the input to a function has changed internally */ - onEmbeddableInputChange: (expression: string) => void; + onEmbeddableInputChange?: (expression: string) => void; /** Handler to invoke when an element's dimensions have changed*/ - onResize: GenericRendererCallback; + onResize?: GenericRendererCallback; /** Handler to invoke when an element should be resized. */ - resize: (size: { height: number; width: number }) => void; + resize?: (size: { height: number; width: number }) => void; /** Sets the value of the filter property on the element object persisted on the workpad */ - setFilter: (filter: string) => void; + setFilter?: (filter: string) => void; } export interface RendererSpec { @@ -49,6 +49,3 @@ export interface RendererSpec { } export type RendererFactory = () => RendererSpec; - -export type AnyRendererFactory = RendererFactory; -export type AnyRendererSpec = RendererSpec; diff --git a/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx b/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx index 92be473919fd6..003d7643460d9 100644 --- a/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx +++ b/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx @@ -15,6 +15,10 @@ const Fallback = () => ( ); -export function RendererWrapper({ children }) { +interface RendererWrapperProps { + children: React.ReactNode; +} + +export function RendererWrapper({ children }: RendererWrapperProps) { return }>{children}; } diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx index 350f102814b29..55dcc2cad256f 100644 --- a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -7,18 +7,26 @@ */ import React, { useRef, useState, useEffect, useCallback } from 'react'; -import { EuiDelayRender, EuiLoadingContent } from '@elastic/eui'; -import { debounce } from 'lodash'; -import { RevealImageRendererConfig, NodeDimensions } from '../expression_renderers/types'; +import { NodeDimensions, RevealImageRendererConfig, Origin } from '../expression_renderers/types'; import { RendererHandlers } from '../../common/types'; import { isValidUrl } from '../../common/lib/url'; +import { elasticOutline } from '../../common/lib/elastic_outline'; -interface RevealImageComponentProps { +interface RevealImageComponentProps extends RevealImageRendererConfig { handlers: RendererHandlers; - [property in RevealImageRendererConfig]: RevealImageRendererConfig[property]; parentNode: HTMLElement; } +interface ImageStyles { + width?: string; + height?: string; + clipPath?: string; +} + +interface AlignerStyles { + backgroundImage?: string; +} + function RevealImageComponent({ handlers, parentNode, @@ -33,7 +41,7 @@ function RevealImageComponent({ height: 1, }); - const imgRef = useRef(null); + const imgRef = useRef(null); // modify the top-level container class parentNode.className = 'revealImage'; @@ -41,31 +49,32 @@ function RevealImageComponent({ // set up the overlay image const onLoad = useCallback(() => { if (imgRef.current) { - setLoaded(true); setDimensions({ height: imgRef.current.naturalHeight, width: imgRef.current.naturalWidth, }); + + setLoaded(true); return handlers.done(); } }, [imgRef, handlers]); useEffect(() => { - handlers.onResize(onLoad); + handlers.onResize?.(onLoad); return () => { - handlers.destroy(); + handlers.destroy?.(); }; }, [onLoad, handlers]); - function getClipPath(percentParam: number, originParam = 'bottom') { - const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; + function getClipPath(percentParam: number, originParam: Origin = 'bottom') { + const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; const values: Array = [0, 0, 0, 0]; values[directions[originParam]] = `${100 - percentParam * 100}%`; return `inset(${values.join(' ')})`; } function getImageSizeStyle() { - const imgStyles = {}; + const imgStyles: ImageStyles = {}; const imgDimensions = { height: dimensions.height, @@ -90,15 +99,16 @@ function RevealImageComponent({ return imgStyles; } - const imgSrc = isValidUrl(image) ? image : elasticOutline; + const imgSrc = isValidUrl(image ?? '') ? image : elasticOutline; + + const alignerStyles: AlignerStyles = {}; - const alignerStyles = {}; - if (isValidUrl(emptyImage)) { + if (isValidUrl(emptyImage ?? '')) { // only use empty image if one is provided alignerStyles.backgroundImage = `url(${emptyImage})`; } - let imgStyles = {}; + let imgStyles: ImageStyles = {}; if (imgRef.current && loaded) imgStyles = getImageSizeStyle(); imgStyles.clipPath = getClipPath(percent, origin); @@ -112,7 +122,7 @@ function RevealImageComponent({ ref={imgRef} onLoad={onLoad} className="revealImage__image" - src={imgSrc} + src={imgSrc ?? ''} alt="" role="presentation" style={imgStyles} diff --git a/src/plugins/expression_reveal_image/public/expression_functions/index.ts b/src/plugins/expression_reveal_image/public/expression_functions/index.ts index 23b46542472f0..ed5f173465e57 100644 --- a/src/plugins/expression_reveal_image/public/expression_functions/index.ts +++ b/src/plugins/expression_reveal_image/public/expression_functions/index.ts @@ -5,4 +5,5 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ + export * from './reveal_image_function'; diff --git a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts index 2a961a5a3ab06..83277d4a485f8 100644 --- a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts +++ b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts @@ -11,6 +11,8 @@ import { elasticOutline } from '../../common/lib/elastic_outline'; import { elasticLogo } from '../../common/lib/elastic_logo'; import { getFunctionErrors } from '../../common/i18n'; import { revealImageFunction } from './reveal_image_function'; +import { Origin } from '../../common/types/expression_functions'; +import { ExecutionContext } from 'src/plugins/expressions'; const errors = getFunctionErrors().revealImage; @@ -18,7 +20,15 @@ describe('revealImageFunction', () => { const fn = functionWrapper(revealImageFunction); it('returns a render as revealImage', () => { - const result = fn(0.5); + const result = fn( + 0.5, + { + image: null, + emptyImage: null, + origin: Origin.BOTTOM, + }, + {} as ExecutionContext + ); expect(result).toHaveProperty('type', 'render'); expect(result).toHaveProperty('as', 'revealImage'); }); @@ -26,19 +36,27 @@ describe('revealImageFunction', () => { describe('context', () => { it('throws when context is not a number between 0 and 1', () => { expect(() => { - fn(10, { - image: elasticLogo, - emptyImage: elasticOutline, - origin: 'top', - }); + fn( + 10, + { + image: elasticLogo, + emptyImage: elasticOutline, + origin: Origin.TOP, + }, + {} as ExecutionContext + ); }).toThrow(new RegExp(errors.invalidPercent(10).message)); expect(() => { - fn(-0.1, { - image: elasticLogo, - emptyImage: elasticOutline, - origin: 'top', - }); + fn( + -0.1, + { + image: elasticLogo, + emptyImage: elasticOutline, + origin: Origin.TOP, + }, + {} as ExecutionContext + ); }).toThrow(new RegExp(errors.invalidPercent(-0.1).message)); }); }); @@ -46,44 +64,103 @@ describe('revealImageFunction', () => { describe('args', () => { describe('image', () => { it('sets the image', () => { - const result = fn(0.89, { image: elasticLogo }).value; + const result = fn( + 0.89, + { + emptyImage: null, + origin: Origin.TOP, + image: elasticLogo, + }, + {} as ExecutionContext + ).value; expect(result).toHaveProperty('image', elasticLogo); }); it('defaults to the Elastic outline logo', () => { - const result = fn(0.89).value; + const result = fn( + 0.89, + { + emptyImage: null, + origin: Origin.TOP, + image: null, + }, + {} as ExecutionContext + ).value; expect(result).toHaveProperty('image', elasticOutline); }); }); describe('emptyImage', () => { it('sets the background image', () => { - const result = fn(0, { emptyImage: elasticLogo }).value; + const result = fn( + 0, + { + emptyImage: elasticLogo, + origin: Origin.TOP, + image: null, + }, + {} as ExecutionContext + ).value; expect(result).toHaveProperty('emptyImage', elasticLogo); }); it('sets emptyImage to null', () => { - const result = fn(0).value; + const result = fn( + 0, + { + emptyImage: null, + origin: Origin.TOP, + image: null, + }, + {} as ExecutionContext + ).value; expect(result).toHaveProperty('emptyImage', null); }); }); describe('origin', () => { it('sets which side to start the reveal from', () => { - let result = fn(1, { origin: 'top' }).value; + let result = fn( + 1, + { + emptyImage: null, + origin: Origin.TOP, + image: null, + }, + {} as ExecutionContext + ).value; expect(result).toHaveProperty('origin', 'top'); - result = fn(1, { origin: 'left' }).value; + result = fn( + 1, + { + emptyImage: null, + origin: Origin.LEFT, + image: null, + }, + {} as ExecutionContext + ).value; expect(result).toHaveProperty('origin', 'left'); - result = fn(1, { origin: 'bottom' }).value; + result = fn( + 1, + { + emptyImage: null, + origin: Origin.BOTTOM, + image: null, + }, + {} as ExecutionContext + ).value; expect(result).toHaveProperty('origin', 'bottom'); - result = fn(1, { origin: 'right' }).value; + result = fn( + 1, + { + emptyImage: null, + origin: Origin.RIGHT, + image: null, + }, + {} as ExecutionContext + ).value; expect(result).toHaveProperty('origin', 'right'); }); - - it('defaults to bottom', () => { - const result = fn(1).value; - expect(result).toHaveProperty('origin', 'bottom'); - }); }); }); }); diff --git a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts index 0393509b3f99a..8aea1318c8764 100644 --- a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts +++ b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts @@ -9,29 +9,9 @@ import { resolveWithMissingImage } from '../../common/lib/resolve_dataurl'; import { elasticOutline } from '../../common/lib/elastic_outline'; import { getFunctionHelp, getFunctionErrors } from '../../common/i18n'; -import { ExpressionRevealImageFunction } from '../../common/types'; +import { ExpressionRevealImageFunction, Origin } from '../../common/types'; -export enum Origin { - TOP = 'top', - LEFT = 'left', - BOTTOM = 'bottom', - RIGHT = 'right', -} - -interface Arguments { - image: string | null; - emptyImage: string | null; - origin: Origin; -} - -export interface Output { - image: string; - emptyImage: string; - origin: Origin; - percent: number; -} - -export function revealImageFunction(): ExpressionRevealImageFunction { +export const revealImageFunction: ExpressionRevealImageFunction = () => { const { help, args: argHelp } = getFunctionHelp().revealImage; const errors = getFunctionErrors().revealImage; @@ -76,4 +56,4 @@ export function revealImageFunction(): ExpressionRevealImageFunction { }; }, }; -} +}; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx index 7f164fa9f2448..550c7b1fb9ac2 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx @@ -12,7 +12,7 @@ import { revealImageRenderer } from '../'; import { Render } from '../../__stories__'; import { elasticOutline } from '../../../common/lib/elastic_outline'; import { elasticLogo } from '../../../common/lib/elastic_logo'; -import { Origin } from '../../expression_functions'; +import { Origin } from '../../../common/types/expression_functions'; import './reveal_image.scss'; storiesOf('renderers/revealImage', module).add('default', () => { diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/index.ts b/src/plugins/expression_reveal_image/public/expression_renderers/index.ts index 4ad58398e2c49..f34e2c400cec0 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/index.ts +++ b/src/plugins/expression_reveal_image/public/expression_renderers/index.ts @@ -6,4 +6,4 @@ * Side Public License, v 1. */ -export * from './reveal_image_renderer.tsx'; +export * from './reveal_image_renderer'; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx index cbda5b1c1f164..cf0ba9384008f 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx @@ -8,11 +8,8 @@ import React, { lazy } from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; -import { elasticOutline } from '../../common/lib/elastic_outline'; -import { isValidUrl } from '../../common/lib/url'; import { getRendererStrings } from '../../common/i18n'; -import { RendererFactory } from '../../common/types'; -import { Output as Arguments } from '../expression_functions'; +import { RendererHandlers, RendererSpec } from '../../common/types'; import { RevealImageRendererConfig } from './types'; import { RendererWrapper } from '../components/renderer_wrapper'; import './reveal_image.scss'; @@ -21,12 +18,16 @@ const { revealImage: revealImageStrings } = getRendererStrings(); const RevealImageComponent = lazy(() => import('../components/reveal_image_component')); -export const revealImageRenderer: RendererFactory = () => ({ +export const revealImageRenderer = (): RendererSpec => ({ name: 'revealImage', displayName: revealImageStrings.getDisplayName(), help: revealImageStrings.getHelpDescription(), reuseDomNode: true, - render: async (domNode: HTMLElement, config: RevealImageRendererConfig, handlers) => { + render: async ( + domNode: HTMLElement, + config: RevealImageRendererConfig, + handlers: RendererHandlers + ) => { handlers.onDestroy(() => { unmountComponentAtNode(domNode); }); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/types.ts b/src/plugins/expression_reveal_image/public/expression_renderers/types.ts index cf40a07f4fd5b..a1c4aaff038e8 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/types.ts +++ b/src/plugins/expression_reveal_image/public/expression_renderers/types.ts @@ -6,9 +6,10 @@ * Side Public License, v 1. */ +export type Origin = 'bottom' | 'left' | 'top' | 'right'; export interface RevealImageRendererConfig { percent: number; - origin?: 'bottom' | 'left' | 'top' | 'right'; + origin?: Origin; image?: string; emptyImage?: string; } diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx index ef0dd67019336..c6cbf91c28122 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx @@ -12,7 +12,7 @@ import { revealImage } from '../'; import { Render } from '../../__stories__'; import { elasticOutline } from '../../../common/lib/elastic_outline'; import { elasticLogo } from '../../../common/lib/elastic_logo'; -import { Origin } from '../../expression_functions'; +import { Origin } from '../../../common/types/expression_functions'; import './reveal_image.scss'; storiesOf('renderers/revealImage_legacy', module).add('default', () => { diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts index 8d281277c3240..ac34b3ec04ecd 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts +++ b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts @@ -9,82 +9,84 @@ import { elasticOutline } from '../../common/lib/elastic_outline'; import { isValidUrl } from '../../common/lib/url'; import { getRendererStrings } from '../../common/i18n'; -import { RendererFactory } from '../../common/types'; -import { Output as Arguments } from '../expression_functions'; +import { Output as Arguments, RendererSpec, RendererHandlers } from '../../common/types'; + import './reveal_image.scss'; const { revealImage: strings } = getRendererStrings(); -export const revealImage: RendererFactory = () => ({ - name: 'revealImage', - displayName: strings.getDisplayName(), - help: strings.getHelpDescription(), - reuseDomNode: true, - render(domNode, config, handlers) { - const aligner = document.createElement('div'); - const img = new Image(); +export const revealImage = (): RendererSpec => { + return { + name: 'revealImage', + displayName: strings.getDisplayName(), + help: strings.getHelpDescription(), + reuseDomNode: true, + render(domNode: HTMLElement, config: Arguments, handlers: RendererHandlers) { + const aligner = document.createElement('div'); + const img = new Image(); - // modify the top-level container class - domNode.className = 'revealImage'; + // modify the top-level container class + domNode.className = 'revealImage'; - // set up the overlay image - function onLoad() { - setSize(); - finish(); - } - img.onload = onLoad; + // set up the overlay image + function onLoad() { + setSize(); + finish(); + } + img.onload = onLoad; - img.className = 'revealImage__image'; - img.style.clipPath = getClipPath(config.percent, config.origin); - img.style.setProperty('-webkit-clip-path', getClipPath(config.percent, config.origin)); - img.src = isValidUrl(config.image) ? config.image : elasticOutline; - handlers.onResize(onLoad); + img.className = 'revealImage__image'; + img.style.clipPath = getClipPath(config.percent, config.origin); + img.style.setProperty('-webkit-clip-path', getClipPath(config.percent, config.origin)); + img.src = isValidUrl(config.image) ? config.image : elasticOutline; + handlers.onResize?.(onLoad); - // set up the underlay, "empty" image - aligner.className = 'revealImageAligner'; - aligner.appendChild(img); - if (isValidUrl(config.emptyImage)) { - // only use empty image if one is provided - aligner.style.backgroundImage = `url(${config.emptyImage})`; - } + // set up the underlay, "empty" image + aligner.className = 'revealImageAligner'; + aligner.appendChild(img); + if (isValidUrl(config.emptyImage)) { + // only use empty image if one is provided + aligner.style.backgroundImage = `url(${config.emptyImage})`; + } - function finish() { - const firstChild = domNode.firstChild; - if (firstChild) { - domNode.replaceChild(aligner, firstChild); - } else { - domNode.appendChild(aligner); + function finish() { + const firstChild = domNode.firstChild; + if (firstChild) { + domNode.replaceChild(aligner, firstChild); + } else { + domNode.appendChild(aligner); + } + handlers.done(); } - handlers.done(); - } - function getClipPath(percent: number, origin = 'bottom') { - const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; - const values: Array = [0, 0, 0, 0]; - values[directions[origin]] = `${100 - percent * 100}%`; - return `inset(${values.join(' ')})`; - } + function getClipPath(percent: number, origin = 'bottom') { + const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; + const values: Array = [0, 0, 0, 0]; + values[directions[origin]] = `${100 - percent * 100}%`; + return `inset(${values.join(' ')})`; + } - function setSize() { - const imgDimensions = { - height: img.naturalHeight, - width: img.naturalWidth, - ratio: img.naturalHeight / img.naturalWidth, - }; + function setSize() { + const imgDimensions = { + height: img.naturalHeight, + width: img.naturalWidth, + ratio: img.naturalHeight / img.naturalWidth, + }; - const domNodeDimensions = { - height: domNode.clientHeight, - width: domNode.clientWidth, - ratio: domNode.clientHeight / domNode.clientWidth, - }; + const domNodeDimensions = { + height: domNode.clientHeight, + width: domNode.clientWidth, + ratio: domNode.clientHeight / domNode.clientWidth, + }; - if (imgDimensions.ratio > domNodeDimensions.ratio) { - img.style.height = `${domNodeDimensions.height}px`; - img.style.width = 'initial'; - } else { - img.style.width = `${domNodeDimensions.width}px`; - img.style.height = 'initial'; + if (imgDimensions.ratio > domNodeDimensions.ratio) { + img.style.height = `${domNodeDimensions.height}px`; + img.style.width = 'initial'; + } else { + img.style.width = `${domNodeDimensions.width}px`; + img.style.height = 'initial'; + } } - } - }, -}); + }, + }; +}; diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts index 2395a4cdf2e7d..8047b4a351d32 100755 --- a/src/plugins/expression_reveal_image/public/plugin.ts +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -5,10 +5,10 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { i18n } from '@kbn/i18n'; -import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../core/public'; -import { ExpressionsStart, ExpressionsSetup } from '../../../src/plugins/expressions/public'; -import { LEGACY_RENDERER_LIBRARY, PLUGIN_NAME } from '../common'; + +import { CoreSetup, CoreStart, Plugin } from '../../../core/public'; +import { ExpressionsStart, ExpressionsSetup } from '../../expressions/public'; +import { LEGACY_RENDERER_LIBRARY } from '../common'; import { revealImageFunction } from './expression_functions'; import { revealImageRenderer } from './expression_renderers'; import { revealImage as revealImageRendererLegacy } from './expression_renderers_legacy'; @@ -22,7 +22,7 @@ interface StartDeps { } export class ExpressionRevealImagePlugin implements Plugin { - public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup { + public setup(core: CoreSetup, { expressions }: SetupDeps) { expressions.registerFunction(revealImageFunction); if (!core.uiSettings.get(LEGACY_RENDERER_LIBRARY, false)) { @@ -32,7 +32,7 @@ export class ExpressionRevealImagePlugin implements Plugin { diff --git a/src/plugins/expression_reveal_image/tsconfig.json b/src/plugins/expression_reveal_image/tsconfig.json index 09a6d24dd7839..93cf163110ac0 100644 --- a/src/plugins/expression_reveal_image/tsconfig.json +++ b/src/plugins/expression_reveal_image/tsconfig.json @@ -16,5 +16,6 @@ "references": [ { "path": "../../core/tsconfig.json" }, { "path": "../expressions/tsconfig.json" }, + { "path": "../presentation_util/tsconfig.json" }, ] } From 784450d521b471b8b8a0689582fd86d8cdbc3db8 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 11 Jun 2021 20:21:44 +0300 Subject: [PATCH 14/77] added limits. --- packages/kbn-optimizer/limits.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 9b4199c812864..226875516cb76 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -111,3 +111,4 @@ pageLoadAssetSize: cases: 162385 screenshotMode: 17856 visTypePie: 35583 + expressionRevealImage: 62826 From 5de41e64ec59c4ab4bd78864de8f1f56ee3fbc81 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 09:06:55 +0300 Subject: [PATCH 15/77] Removed not used imports. --- .../common/i18n/expression_renderers/renderer_strings.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_renderers/renderer_strings.ts b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/renderer_strings.ts index ff9b84ac2f9c5..b74230a2a5d76 100644 --- a/src/plugins/expression_reveal_image/common/i18n/expression_renderers/renderer_strings.ts +++ b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/renderer_strings.ts @@ -6,9 +6,6 @@ * Side Public License, v 1. */ -import { ExpressionFunctionDefinition } from 'src/plugins/expressions'; -import { UnionToIntersection } from '@kbn/utility-types'; - import { revealImage } from './dict'; /** From 788c5f6535f4d49e75d735b610b85d427869fd10 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 09:14:26 +0300 Subject: [PATCH 16/77] i18n namespaces fixed. --- .../expression_functions/dict/reveal_image.ts | 29 ++++++++++--------- .../expression_renderers/dict/reveal_image.ts | 4 +-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts index 9d2e00ab8c9bc..ccf9967bd6a65 100644 --- a/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts +++ b/src/plugins/expression_reveal_image/common/i18n/expression_functions/dict/reveal_image.ts @@ -11,11 +11,11 @@ import { Position } from '../../../types'; import { BASE64, URL } from '../../constants'; export const help = { - help: i18n.translate('xpack.canvas.functions.revealImageHelpText', { + help: i18n.translate('expressionRevealImage.functions.revealImageHelpText', { defaultMessage: 'Configures an image reveal element.', }), args: { - image: i18n.translate('xpack.canvas.functions.revealImage.args.imageHelpText', { + image: i18n.translate('expressionRevealImage.functions.revealImage.args.imageHelpText', { defaultMessage: 'The image to reveal. Provide an image asset as a {BASE64} data {URL}, ' + 'or pass in a sub-expression.', @@ -24,16 +24,19 @@ export const help = { URL, }, }), - emptyImage: i18n.translate('xpack.canvas.functions.revealImage.args.emptyImageHelpText', { - defaultMessage: - 'An optional background image to reveal over. ' + - 'Provide an image asset as a `{BASE64}` data {URL}, or pass in a sub-expression.', - values: { - BASE64, - URL, - }, - }), - origin: i18n.translate('xpack.canvas.functions.revealImage.args.originHelpText', { + emptyImage: i18n.translate( + 'expressionRevealImage.functions.revealImage.args.emptyImageHelpText', + { + defaultMessage: + 'An optional background image to reveal over. ' + + 'Provide an image asset as a `{BASE64}` data {URL}, or pass in a sub-expression.', + values: { + BASE64, + URL, + }, + } + ), + origin: i18n.translate('expressionRevealImage.functions.revealImage.args.originHelpText', { defaultMessage: 'The position to start the image fill. For example, {list}, or {end}.', values: { list: Object.values(Position) @@ -48,7 +51,7 @@ export const help = { export const errors = { invalidPercent: (percent: number) => new Error( - i18n.translate('xpack.canvas.functions.revealImage.invalidPercentErrorMessage', { + i18n.translate('expressionRevealImage.functions.revealImage.invalidPercentErrorMessage', { defaultMessage: "Invalid value: '{percent}'. Percentage must be between 0 and 1", values: { percent, diff --git a/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/reveal_image.ts index 7e637b1f7438d..a32fdbd4c0b50 100644 --- a/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/reveal_image.ts +++ b/src/plugins/expression_reveal_image/common/i18n/expression_renderers/dict/reveal_image.ts @@ -9,11 +9,11 @@ import { i18n } from '@kbn/i18n'; export const strings = { getDisplayName: () => - i18n.translate('xpack.canvas.renderer.revealImage.displayName', { + i18n.translate('expressionRevealImage.renderer.revealImage.displayName', { defaultMessage: 'Image reveal', }), getHelpDescription: () => - i18n.translate('xpack.canvas.renderer.revealImage.helpDescription', { + i18n.translate('expressionRevealImage.renderer.revealImage.helpDescription', { defaultMessage: 'Reveal a percentage of an image to make a custom gauge-style chart', }), }; From 3d6d5f38bdaaf8a9a4cb936be29591d868a7c717 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 09:29:55 +0300 Subject: [PATCH 17/77] Fixed test suite error. --- .../server/collectors/management/schema.ts | 4 ++++ .../server/collectors/management/types.ts | 1 + 2 files changed, 5 insertions(+) diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts index 5f70deccba93c..3de5f6936a92f 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts @@ -456,4 +456,8 @@ export const stackManagementSchema: MakeSchemaFrom = { type: 'boolean', _meta: { description: 'Non-default value of setting.' }, }, + 'labs:expressions:expressionRevealImage:legacyRendererLibrary' : { + type: 'boolean', + _meta: { description: 'Non-default value of setting.' }, + }, }; diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts index bf28bb6cc01f5..f0bade6a339c3 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts @@ -124,4 +124,5 @@ export interface UsageStats { 'labs:presentation:timeToPresent': boolean; 'labs:dashboard:enable_ui': boolean; 'labs:dashboard:deferBelowFold': boolean; + 'labs:expressions:expressionRevealImage:legacyRendererLibrary': boolean; } From 4911e14f6863539f823f3d053fc17a60e1708d24 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 09:54:40 +0300 Subject: [PATCH 18/77] Some errors fixed. --- src/plugins/telemetry/schema/oss_plugins.json | 6 ++++++ x-pack/plugins/translations/translations/ja-JP.json | 5 ----- x-pack/plugins/translations/translations/zh-CN.json | 6 ------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/plugins/telemetry/schema/oss_plugins.json b/src/plugins/telemetry/schema/oss_plugins.json index 51df1d3162b7c..afabf95072717 100644 --- a/src/plugins/telemetry/schema/oss_plugins.json +++ b/src/plugins/telemetry/schema/oss_plugins.json @@ -8596,6 +8596,12 @@ "_meta": { "description": "Non-default value of setting." } + }, + "labs:expressions:expressionRevealImage:legacyRendererLibrary": { + "type": "boolean", + "_meta": { + "description": "Non-default value of setting." + } } } }, diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index e47dfdf986eee..ce3369a2d969c 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -6366,11 +6366,6 @@ "xpack.canvas.functions.replace.args.patternHelpText": "{JS} 正規表現のテキストまたはパターンです。例:{example}。ここではキャプチャグループを使用できます。", "xpack.canvas.functions.replace.args.replacementHelpText": "文字列の一致する部分の代わりです。キャプチャグループはノードによってアクセス可能です。例:{example}。", "xpack.canvas.functions.replaceImageHelpText": "正規表現で文字列の一部を置き換えます。", - "xpack.canvas.functions.revealImage.args.emptyImageHelpText": "表示される背景画像です。画像アセットは「{BASE64}」データ {URL} として提供するか、部分式で渡します。", - "xpack.canvas.functions.revealImage.args.imageHelpText": "表示する画像です。画像アセットは{BASE64}データ{URL}として提供するか、部分式で渡します。", - "xpack.canvas.functions.revealImage.args.originHelpText": "画像で埋め始める位置です。たとえば、{list}、または {end}です。", - "xpack.canvas.functions.revealImage.invalidPercentErrorMessage": "無効な値:「{percent}」。パーセンテージは 0 と 1 の間でなければなりません ", - "xpack.canvas.functions.revealImageHelpText": "画像表示エレメントを構成します。", "xpack.canvas.functions.rounddate.args.formatHelpText": "バケットに使用する{MOMENTJS}フォーマットです。たとえば、{example}は月単位に端数処理されます。{url}を参照してください。", "xpack.canvas.functions.rounddateHelpText": "新世紀からのミリ秒の繰り上げ・繰り下げに {MOMENTJS} を使用し、新世紀からのミリ秒を戻します。", "xpack.canvas.functions.rowCountHelpText": "行数を返します。{plyFn}と組み合わせて、固有の列値の数、または固有の列値の組み合わせを求めます。", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 3ab6203b48942..e8e437ce3a57a 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -6405,12 +6405,6 @@ "xpack.canvas.functions.replace.args.flagsHelpText": "指定标志。请参见 {url}。", "xpack.canvas.functions.replace.args.patternHelpText": "{JS} 正则表达式的文本或模式。例如,{example}。您可以在此处使用捕获组。", "xpack.canvas.functions.replace.args.replacementHelpText": "字符串匹配部分的替代。捕获组可以通过其索引进行访问。例如,{example}。", - "xpack.canvas.functions.replaceImageHelpText": "使用正则表达式替换字符串的各部分。", - "xpack.canvas.functions.revealImage.args.emptyImageHelpText": "要显示的可选背景图像。以 `{BASE64}` 数据 {URL} 的形式提供图像资产或传入子表达式。", - "xpack.canvas.functions.revealImage.args.imageHelpText": "要显示的图像。以 {BASE64} 数据 {URL} 的形式提供图像资产或传入子表达式。", - "xpack.canvas.functions.revealImage.args.originHelpText": "要开始图像填充的位置。例如 {list} 或 {end}。", - "xpack.canvas.functions.revealImage.invalidPercentErrorMessage": "无效值:“{percent}”。百分比必须介于 0 和 1 之间", - "xpack.canvas.functions.revealImageHelpText": "配置图像显示元素。", "xpack.canvas.functions.rounddate.args.formatHelpText": "用于存储桶存储的 {MOMENTJS} 格式。例如,{example} 四舍五入到月份。请参见 {url}。", "xpack.canvas.functions.rounddateHelpText": "使用 {MOMENTJS} 格式字符串舍入自 Epoch 起毫秒数,并返回自 Epoch 起毫秒数。", "xpack.canvas.functions.rowCountHelpText": "返回行数。与 {plyFn} 搭配使用,可获取唯一列值的计数或唯一列值的组合。", From 3fb130aa8a5d3ad2a1084707c6f9d0e3c791bc30 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 09:57:54 +0300 Subject: [PATCH 19/77] Fixed eslint error. --- .../server/collectors/management/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts index 3de5f6936a92f..33a26ec0f4211 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts @@ -456,7 +456,7 @@ export const stackManagementSchema: MakeSchemaFrom = { type: 'boolean', _meta: { description: 'Non-default value of setting.' }, }, - 'labs:expressions:expressionRevealImage:legacyRendererLibrary' : { + 'labs:expressions:expressionRevealImage:legacyRendererLibrary': { type: 'boolean', _meta: { description: 'Non-default value of setting.' }, }, From 273a2a27247bb96884524fe7efa30de1701142fb Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 10:11:04 +0300 Subject: [PATCH 20/77] Removed more unused translations. --- x-pack/plugins/translations/translations/ja-JP.json | 2 -- x-pack/plugins/translations/translations/zh-CN.json | 2 -- 2 files changed, 4 deletions(-) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index ce3369a2d969c..df3d30bef98da 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -6558,8 +6558,6 @@ "xpack.canvas.renderer.progress.helpDescription": "エレメントのパーセンテージを示す進捗インジケーターをレンダリングします", "xpack.canvas.renderer.repeatImage.displayName": "画像の繰り返し", "xpack.canvas.renderer.repeatImage.helpDescription": "画像を指定回数繰り返し表示します", - "xpack.canvas.renderer.revealImage.displayName": "画像の部分表示", - "xpack.canvas.renderer.revealImage.helpDescription": "カスタムゲージスタイルチャートを作成するため、画像のパーセンテージを表示します", "xpack.canvas.renderer.shape.displayName": "形状", "xpack.canvas.renderer.shape.helpDescription": "基本的な図形をレンダリングします", "xpack.canvas.renderer.table.displayName": "データテーブル", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index e8e437ce3a57a..e491ac665253b 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -6597,8 +6597,6 @@ "xpack.canvas.renderer.progress.helpDescription": "呈现显示元素百分比的进度指示", "xpack.canvas.renderer.repeatImage.displayName": "图像重复", "xpack.canvas.renderer.repeatImage.helpDescription": "重复图像给定次数", - "xpack.canvas.renderer.revealImage.displayName": "图像显示", - "xpack.canvas.renderer.revealImage.helpDescription": "显示一定百分比的图像,以制作定制的仪表样式图表", "xpack.canvas.renderer.shape.displayName": "形状", "xpack.canvas.renderer.shape.helpDescription": "呈现基本形状", "xpack.canvas.renderer.table.displayName": "数据表", From 02ed217c74cdf53fddc46ed90aac72dacee8076b Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 15:43:29 +0300 Subject: [PATCH 21/77] Moved UI and elements, related to expressionRevealImage from canvas. --- .../common/i18n/elements/dict/index.ts | 9 +++ .../common/i18n/elements/dict/reveal_image.ts | 19 +++++++ .../common/i18n/elements/index.ts | 21 +++++++ .../common/i18n/index.ts | 2 + .../common/i18n/ui/dict/index.ts | 9 +++ .../common/i18n/ui/dict/reveal_image.ts | 55 +++++++++++++++++++ .../common/i18n/ui/index.ts | 21 +++++++ .../public/elements}/index.ts | 18 +++++- .../public/ui_views/index.ts | 44 +++++++++++++++ .../canvas_plugin_src/elements/index.ts | 2 - .../canvas/i18n/elements/element_strings.ts | 8 --- x-pack/plugins/canvas/kibana.json | 3 +- .../__stories__/element_menu.stories.tsx | 11 ---- .../__mocks__/supported_renderers.js | 1 - .../shareable_runtime/supported_renderers.js | 2 - 15 files changed, 196 insertions(+), 29 deletions(-) create mode 100644 src/plugins/expression_reveal_image/common/i18n/elements/dict/index.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/elements/index.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/ui/dict/index.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/ui/dict/reveal_image.ts create mode 100644 src/plugins/expression_reveal_image/common/i18n/ui/index.ts rename {x-pack/plugins/canvas/canvas_plugin_src/elements/reveal_image => src/plugins/expression_reveal_image/public/elements}/index.ts (50%) create mode 100644 src/plugins/expression_reveal_image/public/ui_views/index.ts diff --git a/src/plugins/expression_reveal_image/common/i18n/elements/dict/index.ts b/src/plugins/expression_reveal_image/common/i18n/elements/dict/index.ts new file mode 100644 index 0000000000000..4f70f9d30b74b --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/elements/dict/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export { strings as revealImage } from './reveal_image'; diff --git a/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts new file mode 100644 index 0000000000000..7b5d0bf66ac10 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { i18n } from '@kbn/i18n'; + +export const strings = { + revealImage: { + displayName: i18n.translate('expressionRevealImage.elements.revealImageDisplayName', { + defaultMessage: 'Image reveal', + }), + help: i18n.translate('expressionRevealImage.elements.revealImageHelpText', { + defaultMessage: 'Reveals a percentage of an image', + }), + }, +}; diff --git a/src/plugins/expression_reveal_image/common/i18n/elements/index.ts b/src/plugins/expression_reveal_image/common/i18n/elements/index.ts new file mode 100644 index 0000000000000..c0beeaaca58f2 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/elements/index.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { revealImage } from './dict'; + +/** + * Help text for Canvas Functions should be properly localized. This function will + * return a dictionary of help strings, organized by `ExpressionFunctionDefinition` + * specification and then by available arguments within each `ExpressionFunctionDefinition`. + * + * This a function, rather than an object, to future-proof string initialization, + * if ever necessary. + */ +export const getElementsStrings = () => ({ + revealImage, +}); diff --git a/src/plugins/expression_reveal_image/common/i18n/index.ts b/src/plugins/expression_reveal_image/common/i18n/index.ts index 9c50bfab1305d..4ff6b6bed9cbc 100644 --- a/src/plugins/expression_reveal_image/common/i18n/index.ts +++ b/src/plugins/expression_reveal_image/common/i18n/index.ts @@ -8,3 +8,5 @@ export * from './expression_functions'; export * from './expression_renderers'; +export * from './elements'; +export * from './ui'; diff --git a/src/plugins/expression_reveal_image/common/i18n/ui/dict/index.ts b/src/plugins/expression_reveal_image/common/i18n/ui/dict/index.ts new file mode 100644 index 0000000000000..4f70f9d30b74b --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/ui/dict/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export { strings as revealImage } from './reveal_image'; diff --git a/src/plugins/expression_reveal_image/common/i18n/ui/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/ui/dict/reveal_image.ts new file mode 100644 index 0000000000000..4a4d65533cbae --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/ui/dict/reveal_image.ts @@ -0,0 +1,55 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { i18n } from '@kbn/i18n'; + +export const strings = { + getDisplayName: () => + i18n.translate('expressionRevealImage.uis.views.revealImageTitle', { + defaultMessage: 'Reveal image', + }), + getEmptyImageDisplayName: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.emptyImageTitle', { + defaultMessage: 'Background image', + }), + getEmptyImageHelp: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.emptyImageLabel', { + defaultMessage: 'A background image. Eg, an empty glass', + }), + getImageDisplayName: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.imageTitle', { + defaultMessage: 'Image', + }), + getImageHelp: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.imageLabel', { + defaultMessage: 'An image to reveal given the function input. Eg, a full glass', + }), + getOriginBottom: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.origin.bottomDropDown', { + defaultMessage: 'Bottom', + }), + getOriginDisplayName: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.originTitle', { + defaultMessage: 'Reveal from', + }), + getOriginHelp: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.originLabel', { + defaultMessage: 'The direction from which to start the reveal', + }), + getOriginLeft: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.origin.leftDropDown', { + defaultMessage: 'Left', + }), + getOriginRight: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.origin.rightDropDown', { + defaultMessage: 'Right', + }), + getOriginTop: () => + i18n.translate('expressionRevealImage.uis.views.revealImage.args.origin.topDropDown', { + defaultMessage: 'Top', + }), +}; diff --git a/src/plugins/expression_reveal_image/common/i18n/ui/index.ts b/src/plugins/expression_reveal_image/common/i18n/ui/index.ts new file mode 100644 index 0000000000000..31f2231d1f64d --- /dev/null +++ b/src/plugins/expression_reveal_image/common/i18n/ui/index.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { revealImage } from './dict'; + +/** + * Help text for Canvas Functions should be properly localized. This function will + * return a dictionary of help strings, organized by `ExpressionFunctionDefinition` + * specification and then by available arguments within each `ExpressionFunctionDefinition`. + * + * This a function, rather than an object, to future-proof string initialization, + * if ever necessary. + */ +export const getUIStrings = () => ({ + revealImage, +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/elements/reveal_image/index.ts b/src/plugins/expression_reveal_image/public/elements/index.ts similarity index 50% rename from x-pack/plugins/canvas/canvas_plugin_src/elements/reveal_image/index.ts rename to src/plugins/expression_reveal_image/public/elements/index.ts index b2b4ea4a942a3..60eb3c32eab61 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/elements/reveal_image/index.ts +++ b/src/plugins/expression_reveal_image/public/elements/index.ts @@ -1,11 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ +export interface ElementSpec { + name: string; + icon?: string; + expression: string; + displayName?: string; + type?: string; + help?: string; + filter?: string; + width?: number; + height?: number; +} -import { ElementFactory } from '../../../types'; +export type ElementFactory = () => ElementSpec; export const revealImage: ElementFactory = () => ({ name: 'revealImage', diff --git a/src/plugins/expression_reveal_image/public/ui_views/index.ts b/src/plugins/expression_reveal_image/public/ui_views/index.ts new file mode 100644 index 0000000000000..24442523ec91d --- /dev/null +++ b/src/plugins/expression_reveal_image/public/ui_views/index.ts @@ -0,0 +1,44 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { getUIStrings } from '../../common/i18n'; + +const { revealImage: strings } = getUIStrings(); + +export const revealImage = () => ({ + name: 'revealImage', + displayName: strings.getDisplayName(), + modelArgs: [['_', { label: 'Value' }]], + args: [ + { + name: 'image', + displayName: strings.getImageDisplayName(), + help: strings.getImageHelp(), + argType: 'imageUpload', + }, + { + name: 'emptyImage', + displayName: strings.getEmptyImageDisplayName(), + help: strings.getEmptyImageHelp(), + argType: 'imageUpload', + }, + { + name: 'origin', + displayName: strings.getOriginDisplayName(), + help: strings.getOriginHelp(), + argType: 'select', + options: { + choices: [ + { value: 'top', name: strings.getOriginTop() }, + { value: 'left', name: strings.getOriginLeft() }, + { value: 'bottom', name: strings.getOriginBottom() }, + { value: 'right', name: strings.getOriginRight() }, + ], + }, + }, + ], +}); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/elements/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/elements/index.ts index 4925849045216..6c684cfb92157 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/elements/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/elements/index.ts @@ -24,7 +24,6 @@ import { progressGauge } from './progress_gauge'; import { progressSemicircle } from './progress_semicircle'; import { progressWheel } from './progress_wheel'; import { repeatImage } from './repeat_image'; -import { revealImage } from './reveal_image'; import { shape } from './shape'; import { table } from './table'; import { timeFilter } from './time_filter'; @@ -53,7 +52,6 @@ const elementSpecs = [ progressSemicircle, progressWheel, repeatImage, - revealImage, shape, table, timeFilter, diff --git a/x-pack/plugins/canvas/i18n/elements/element_strings.ts b/x-pack/plugins/canvas/i18n/elements/element_strings.ts index 87879c4c753c9..e5128721d643b 100644 --- a/x-pack/plugins/canvas/i18n/elements/element_strings.ts +++ b/x-pack/plugins/canvas/i18n/elements/element_strings.ts @@ -166,14 +166,6 @@ export const getElementStrings = (): ElementStringDict => ({ defaultMessage: 'Repeats an image N times', }), }, - revealImage: { - displayName: i18n.translate('xpack.canvas.elements.revealImageDisplayName', { - defaultMessage: 'Image reveal', - }), - help: i18n.translate('xpack.canvas.elements.revealImageHelpText', { - defaultMessage: 'Reveals a percentage of an image', - }), - }, shape: { displayName: i18n.translate('xpack.canvas.elements.shapeDisplayName', { defaultMessage: 'Shape', diff --git a/x-pack/plugins/canvas/kibana.json b/x-pack/plugins/canvas/kibana.json index 22c8d4e0d2ab4..5faeaefc9e392 100644 --- a/x-pack/plugins/canvas/kibana.json +++ b/x-pack/plugins/canvas/kibana.json @@ -14,8 +14,7 @@ "features", "inspector", "presentationUtil", - "uiActions", - "expressionRevealImage" + "uiActions" ], "optionalPlugins": [ "home", diff --git a/x-pack/plugins/canvas/public/components/workpad_header/element_menu/__stories__/element_menu.stories.tsx b/x-pack/plugins/canvas/public/components/workpad_header/element_menu/__stories__/element_menu.stories.tsx index 6f4b6661ded53..80280d55a4e1c 100644 --- a/x-pack/plugins/canvas/public/components/workpad_header/element_menu/__stories__/element_menu.stories.tsx +++ b/x-pack/plugins/canvas/public/components/workpad_header/element_menu/__stories__/element_menu.stories.tsx @@ -95,17 +95,6 @@ You can use standard Markdown in here, but you can also access your piped-in dat | progress shape="gauge" label={formatnumber 0%} font={font size=24 family="Helvetica" color="#000000" align=center} | render`, }, - revealImage: { - name: 'revealImage', - displayName: 'Image reveal', - type: 'image', - help: 'Reveals a percentage of an image', - expression: `filters - | demodata - | math "mean(percent_uptime)" - | revealImage origin=bottom image=null - | render`, - }, shape: { name: 'shape', displayName: 'Shape', diff --git a/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js index c01b1b3f23543..ab602ad3be631 100644 --- a/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js @@ -13,7 +13,6 @@ const renderers = [ 'error', 'image', 'repeatImage', - 'revealImage', 'markdown', 'metric', 'pie', diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js index 99d83f35ea992..b4309117edbc4 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js @@ -9,7 +9,6 @@ import { debug } from '../canvas_plugin_src/renderers/debug'; import { error } from '../canvas_plugin_src/renderers/error'; import { image } from '../canvas_plugin_src/renderers/image'; import { repeatImage } from '../canvas_plugin_src/renderers/repeat_image'; -import { revealImageRenderer as revealImage } from '../../../../src/plugins/expression_reveal_image/public'; import { markdown } from '../canvas_plugin_src/renderers/markdown'; import { metric } from '../canvas_plugin_src/renderers/metric'; import { pie } from '../canvas_plugin_src/renderers/pie'; @@ -29,7 +28,6 @@ export const renderFunctions = [ error, image, repeatImage, - revealImage, markdown, metric, pie, From 2e1e9bf178cacdc4b163407212f98fdefe959d0a Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 15:57:40 +0300 Subject: [PATCH 22/77] Fixed unused translations errors. --- x-pack/plugins/translations/translations/ja-JP.json | 2 -- x-pack/plugins/translations/translations/zh-CN.json | 2 -- 2 files changed, 4 deletions(-) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index df3d30bef98da..6afd0873885c8 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -6083,8 +6083,6 @@ "xpack.canvas.elements.progressWheelHelpText": "進捗状況をホイールで表示します", "xpack.canvas.elements.repeatImageDisplayName": "画像の繰り返し", "xpack.canvas.elements.repeatImageHelpText": "画像を N 回繰り返します", - "xpack.canvas.elements.revealImageDisplayName": "画像の部分表示", - "xpack.canvas.elements.revealImageHelpText": "画像のパーセンテージを表示します", "xpack.canvas.elements.shapeDisplayName": "形状", "xpack.canvas.elements.shapeHelpText": "カスタマイズ可能な図形です", "xpack.canvas.elements.tableDisplayName": "データテーブル", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index e491ac665253b..d790ec971555b 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -6122,8 +6122,6 @@ "xpack.canvas.elements.progressWheelHelpText": "将进度显示为轮盘的一部分", "xpack.canvas.elements.repeatImageDisplayName": "图像重复", "xpack.canvas.elements.repeatImageHelpText": "使图像重复 N 次", - "xpack.canvas.elements.revealImageDisplayName": "图像显示", - "xpack.canvas.elements.revealImageHelpText": "显示图像特定百分比", "xpack.canvas.elements.shapeDisplayName": "形状", "xpack.canvas.elements.shapeHelpText": "可定制的形状", "xpack.canvas.elements.tableDisplayName": "数据表", From 2e727cdd5f8d3c112ebc92c2099118f670d64a3b Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 16:53:11 +0300 Subject: [PATCH 23/77] Moved type of element to types. --- .../common/types/elements.ts | 20 +++++++++++++++++++ .../common/types/index.ts | 1 + .../public/elements/index.ts | 13 +----------- 3 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 src/plugins/expression_reveal_image/common/types/elements.ts diff --git a/src/plugins/expression_reveal_image/common/types/elements.ts b/src/plugins/expression_reveal_image/common/types/elements.ts new file mode 100644 index 0000000000000..7c7aaf98ed199 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/types/elements.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +export interface ElementSpec { + name: string; + icon?: string; + expression: string; + displayName?: string; + type?: string; + help?: string; + filter?: string; + width?: number; + height?: number; +} + +export type ElementFactory = () => ElementSpec; diff --git a/src/plugins/expression_reveal_image/common/types/index.ts b/src/plugins/expression_reveal_image/common/types/index.ts index ec934e7affe88..8df939a11b30d 100644 --- a/src/plugins/expression_reveal_image/common/types/index.ts +++ b/src/plugins/expression_reveal_image/common/types/index.ts @@ -7,3 +7,4 @@ */ export * from './expression_functions'; export * from './expression_renderers'; +export * from './elements'; diff --git a/src/plugins/expression_reveal_image/public/elements/index.ts b/src/plugins/expression_reveal_image/public/elements/index.ts index 60eb3c32eab61..f8ce2ba0f4576 100644 --- a/src/plugins/expression_reveal_image/public/elements/index.ts +++ b/src/plugins/expression_reveal_image/public/elements/index.ts @@ -5,19 +5,8 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -export interface ElementSpec { - name: string; - icon?: string; - expression: string; - displayName?: string; - type?: string; - help?: string; - filter?: string; - width?: number; - height?: number; -} -export type ElementFactory = () => ElementSpec; +import { ElementFactory } from '../../common/types'; export const revealImage: ElementFactory = () => ({ name: 'revealImage', From 96807332c90e31019280b57567272b483942198f Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 14 Jun 2021 19:03:11 +0300 Subject: [PATCH 24/77] Fixed types and added service for representing elements, ui and supported renderers to canvas. --- .../common/types/expression_renderers.ts | 19 -------- .../common/types/index.ts | 1 + .../common/types/ui_views.ts | 10 +++++ .../public/__stories__/render.tsx | 5 ++- .../public/elements/index.ts | 10 ++--- .../reveal_image_renderer.tsx | 5 ++- .../expression_renderers_legacy/index.ts | 7 +-- .../expression_reveal_image/public/index.ts | 8 +++- .../expression_reveal_image/public/plugin.ts | 17 ++++++-- .../public/services/expression_service.ts | 43 +++++++++++++++++++ .../public/services/index.ts | 9 ++++ .../public/ui_views/index.ts | 3 +- 12 files changed, 101 insertions(+), 36 deletions(-) create mode 100644 src/plugins/expression_reveal_image/common/types/ui_views.ts create mode 100644 src/plugins/expression_reveal_image/public/services/expression_service.ts create mode 100644 src/plugins/expression_reveal_image/public/services/index.ts diff --git a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts index 3d6a399cfc4ec..d17cc5a55d722 100644 --- a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts +++ b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts @@ -30,22 +30,3 @@ export interface RendererHandlers extends IInterpreterRenderHandlers { /** Sets the value of the filter property on the element object persisted on the workpad */ setFilter?: (filter: string) => void; } - -export interface RendererSpec { - /** The render type */ - name: string; - /** The name to display */ - displayName: string; - /** A description of what is rendered */ - help: string; - /** Indicate whether the element should reuse the existing DOM element when re-rendering */ - reuseDomNode: boolean; - /** The default width of the element in pixels */ - width?: number; - /** The default height of the element in pixels */ - height?: number; - /** A function that renders an element into the specified DOM element */ - render: (domNode: HTMLElement, config: RendererConfig, handlers: RendererHandlers) => void; -} - -export type RendererFactory = () => RendererSpec; diff --git a/src/plugins/expression_reveal_image/common/types/index.ts b/src/plugins/expression_reveal_image/common/types/index.ts index 8df939a11b30d..356df1ff8dd13 100644 --- a/src/plugins/expression_reveal_image/common/types/index.ts +++ b/src/plugins/expression_reveal_image/common/types/index.ts @@ -8,3 +8,4 @@ export * from './expression_functions'; export * from './expression_renderers'; export * from './elements'; +export * from './ui_views'; diff --git a/src/plugins/expression_reveal_image/common/types/ui_views.ts b/src/plugins/expression_reveal_image/common/types/ui_views.ts new file mode 100644 index 0000000000000..d4c48d2afb262 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/types/ui_views.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { CoreStart } from 'src/core/public'; + +export type StartInitializer = (core: CoreStart, plugins: unknown) => T; diff --git a/src/plugins/expression_reveal_image/public/__stories__/render.tsx b/src/plugins/expression_reveal_image/public/__stories__/render.tsx index b35a5233f5028..f7576ea9422ee 100644 --- a/src/plugins/expression_reveal_image/public/__stories__/render.tsx +++ b/src/plugins/expression_reveal_image/public/__stories__/render.tsx @@ -8,7 +8,8 @@ import { action } from '@storybook/addon-actions'; import React, { useRef, useEffect } from 'react'; -import { RendererFactory, RendererHandlers } from '../../common/types'; +import { ExpressionRenderDefinition } from 'src/plugins/expressions'; +import { RendererHandlers } from '../../common/types'; export const defaultHandlers: RendererHandlers = { destroy: () => action('destroy'), @@ -44,7 +45,7 @@ export const Render = ({ renderer, config, ...rest -}: Renderer extends RendererFactory +}: Renderer extends () => ExpressionRenderDefinition ? { renderer: Renderer; config: Config } & RenderAdditionalProps : { renderer: undefined; config: undefined } & RenderAdditionalProps) => { const { height, width, handlers } = { diff --git a/src/plugins/expression_reveal_image/public/elements/index.ts b/src/plugins/expression_reveal_image/public/elements/index.ts index f8ce2ba0f4576..5d18105ea87fc 100644 --- a/src/plugins/expression_reveal_image/public/elements/index.ts +++ b/src/plugins/expression_reveal_image/public/elements/index.ts @@ -8,14 +8,14 @@ import { ElementFactory } from '../../common/types'; -export const revealImage: ElementFactory = () => ({ +export const revealImageElement: ElementFactory = () => ({ name: 'revealImage', displayName: 'Image reveal', type: 'image', help: 'Reveals a percentage of an image', expression: `filters -| demodata -| math "mean(percent_uptime)" -| revealImage origin=bottom image=null -| render`, + | demodata + | math "mean(percent_uptime)" + | revealImage origin=bottom image=null + | render`, }); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx index cf0ba9384008f..484f0dea9d5d1 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx @@ -8,8 +8,9 @@ import React, { lazy } from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; +import { ExpressionRenderDefinition } from 'src/plugins/expressions'; import { getRendererStrings } from '../../common/i18n'; -import { RendererHandlers, RendererSpec } from '../../common/types'; +import { RendererHandlers } from '../../common/types'; import { RevealImageRendererConfig } from './types'; import { RendererWrapper } from '../components/renderer_wrapper'; import './reveal_image.scss'; @@ -18,7 +19,7 @@ const { revealImage: revealImageStrings } = getRendererStrings(); const RevealImageComponent = lazy(() => import('../components/reveal_image_component')); -export const revealImageRenderer = (): RendererSpec => ({ +export const revealImageRenderer = (): ExpressionRenderDefinition => ({ name: 'revealImage', displayName: revealImageStrings.getDisplayName(), help: revealImageStrings.getHelpDescription(), diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts index ac34b3ec04ecd..5d9933ebcc2c8 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts +++ b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts @@ -5,17 +5,17 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ - +import { ExpressionRenderDefinition } from 'src/plugins/expressions'; import { elasticOutline } from '../../common/lib/elastic_outline'; import { isValidUrl } from '../../common/lib/url'; import { getRendererStrings } from '../../common/i18n'; -import { Output as Arguments, RendererSpec, RendererHandlers } from '../../common/types'; +import { Output as Arguments, RendererHandlers } from '../../common/types'; import './reveal_image.scss'; const { revealImage: strings } = getRendererStrings(); -export const revealImage = (): RendererSpec => { +export const revealImage = (): ExpressionRenderDefinition => { return { name: 'revealImage', displayName: strings.getDisplayName(), @@ -33,6 +33,7 @@ export const revealImage = (): RendererSpec => { setSize(); finish(); } + img.onload = onLoad; img.className = 'revealImage__image'; diff --git a/src/plugins/expression_reveal_image/public/index.ts b/src/plugins/expression_reveal_image/public/index.ts index e9fa799d15bc0..92063cbfaf2e7 100755 --- a/src/plugins/expression_reveal_image/public/index.ts +++ b/src/plugins/expression_reveal_image/public/index.ts @@ -8,7 +8,13 @@ import { ExpressionRevealImagePlugin } from './plugin'; -export * from './expression_renderers'; +import { revealImageRenderer } from './expression_renderers'; +import { revealImageElement } from './elements'; +import { revealImageUIView } from './ui_views'; + +export const elements = [revealImageElement]; +export const renderers = [revealImageRenderer]; +export const uiViews = [revealImageUIView]; // This exports static code and TypeScript types, // as well as, Kibana Platform `plugin()` initializer. diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts index 8047b4a351d32..bd7ff05743416 100755 --- a/src/plugins/expression_reveal_image/public/plugin.ts +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -12,6 +12,7 @@ import { LEGACY_RENDERER_LIBRARY } from '../common'; import { revealImageFunction } from './expression_functions'; import { revealImageRenderer } from './expression_renderers'; import { revealImage as revealImageRendererLegacy } from './expression_renderers_legacy'; +import { ExpressionService, ExpressionsServiceSetup } from './services'; interface SetupDeps { expressions: ExpressionsSetup; @@ -22,7 +23,9 @@ interface StartDeps { } export class ExpressionRevealImagePlugin implements Plugin { - public setup(core: CoreSetup, { expressions }: SetupDeps) { + private readonly expressionService: ExpressionService = new ExpressionService(); + + public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionsServiceSetup { expressions.registerFunction(revealImageFunction); if (!core.uiSettings.get(LEGACY_RENDERER_LIBRARY, false)) { @@ -30,11 +33,19 @@ export class ExpressionRevealImagePlugin implements Plugin; + +export interface ExpressionsServiceSetup { + getViews: () => Array>; + getRenderers: () => Array<() => ExpressionRenderDefinition>; + getElements: () => ElementFactory[]; +} + +export type ExpressionsServiceStart = ExpressionsServiceSetup; + +export class ExpressionService { + public readonly getElements = (): ElementFactory[] => elements; + public readonly getRenderers = (): Array< + () => ExpressionRenderDefinition + > => renderers; + public readonly getViews = (): Array> => uiViews; + + public setup(...args: unknown[]): ExpressionsServiceSetup { + return this; + } + + public start(...args: unknown[]): ExpressionsServiceStart { + return this; + } + + public stop() {} +} diff --git a/src/plugins/expression_reveal_image/public/services/index.ts b/src/plugins/expression_reveal_image/public/services/index.ts new file mode 100644 index 0000000000000..b0480efcc975f --- /dev/null +++ b/src/plugins/expression_reveal_image/public/services/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export * from './expression_service'; diff --git a/src/plugins/expression_reveal_image/public/ui_views/index.ts b/src/plugins/expression_reveal_image/public/ui_views/index.ts index 24442523ec91d..82ffab2ef4f4e 100644 --- a/src/plugins/expression_reveal_image/public/ui_views/index.ts +++ b/src/plugins/expression_reveal_image/public/ui_views/index.ts @@ -6,10 +6,11 @@ * Side Public License, v 1. */ import { getUIStrings } from '../../common/i18n'; +import { StartInitializer } from '../../common/types'; const { revealImage: strings } = getUIStrings(); -export const revealImage = () => ({ +export const revealImageUIView: StartInitializer = () => ({ name: 'revealImage', displayName: strings.getDisplayName(), modelArgs: [['_', { label: 'Value' }]], From 3aebdf6a950ec6072cf120ad8d96f1df2248330c Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 15 Jun 2021 10:24:30 +0300 Subject: [PATCH 25/77] Added expression registration to canvas. --- .../common/i18n/elements/dict/reveal_image.ts | 17 +++++++------- .../common/i18n/elements/index.ts | 3 ++- .../common/lib/translate_elements.ts | 22 +++++++++++++++++++ .../common/types/dict.ts | 16 ++++++++++++++ .../common/types/index.ts | 1 + .../expression_reveal_image/public/index.ts | 6 ++--- .../expression_reveal_image/public/plugin.ts | 18 +++++++++++---- .../public/services/expression_service.ts | 13 ++++------- x-pack/plugins/canvas/kibana.json | 3 ++- x-pack/plugins/canvas/public/plugin.tsx | 14 ++++++++++++ x-pack/plugins/canvas/tsconfig.json | 1 + x-pack/plugins/canvas/types/renderers.ts | 10 +++++---- 12 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 src/plugins/expression_reveal_image/common/lib/translate_elements.ts create mode 100644 src/plugins/expression_reveal_image/common/types/dict.ts diff --git a/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts index 7b5d0bf66ac10..c1ead2dfd75d8 100644 --- a/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts +++ b/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts @@ -6,14 +6,13 @@ * Side Public License, v 1. */ import { i18n } from '@kbn/i18n'; +import { ElementStrings } from '../../../types'; -export const strings = { - revealImage: { - displayName: i18n.translate('expressionRevealImage.elements.revealImageDisplayName', { - defaultMessage: 'Image reveal', - }), - help: i18n.translate('expressionRevealImage.elements.revealImageHelpText', { - defaultMessage: 'Reveals a percentage of an image', - }), - }, +export const strings: ElementStrings = { + displayName: i18n.translate('expressionRevealImage.elements.revealImageDisplayName', { + defaultMessage: 'Image reveal', + }), + help: i18n.translate('expressionRevealImage.elements.revealImageHelpText', { + defaultMessage: 'Reveals a percentage of an image', + }), }; diff --git a/src/plugins/expression_reveal_image/common/i18n/elements/index.ts b/src/plugins/expression_reveal_image/common/i18n/elements/index.ts index c0beeaaca58f2..17cc64753b912 100644 --- a/src/plugins/expression_reveal_image/common/i18n/elements/index.ts +++ b/src/plugins/expression_reveal_image/common/i18n/elements/index.ts @@ -6,6 +6,7 @@ * Side Public License, v 1. */ +import { ElementStringDict } from '../../types'; import { revealImage } from './dict'; /** @@ -16,6 +17,6 @@ import { revealImage } from './dict'; * This a function, rather than an object, to future-proof string initialization, * if ever necessary. */ -export const getElementsStrings = () => ({ +export const getElementsStrings = (): ElementStringDict => ({ revealImage, }); diff --git a/src/plugins/expression_reveal_image/common/lib/translate_elements.ts b/src/plugins/expression_reveal_image/common/lib/translate_elements.ts new file mode 100644 index 0000000000000..e2b7037faf034 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/lib/translate_elements.ts @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { ElementFactory } from '../types'; +import { getElementsStrings } from '../i18n'; + +export function translateElements(elements: ElementFactory[] = []) { + return elements.map((elFactory) => { + const element = elFactory(); + const { name } = element; + const strings = getElementsStrings(); + const elementStrings = strings[name] ?? {}; + element.displayName = elementStrings['displayName'] ?? element.displayName; + element.help = elementStrings.help ?? element.help; + + return () => element; + }); +} diff --git a/src/plugins/expression_reveal_image/common/types/dict.ts b/src/plugins/expression_reveal_image/common/types/dict.ts new file mode 100644 index 0000000000000..66303caabb827 --- /dev/null +++ b/src/plugins/expression_reveal_image/common/types/dict.ts @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export interface ElementStrings { + displayName: string; + help: string; +} + +export interface ElementStringDict { + [elementName: string]: ElementStrings; +} diff --git a/src/plugins/expression_reveal_image/common/types/index.ts b/src/plugins/expression_reveal_image/common/types/index.ts index 356df1ff8dd13..6cc5706b453c0 100644 --- a/src/plugins/expression_reveal_image/common/types/index.ts +++ b/src/plugins/expression_reveal_image/common/types/index.ts @@ -9,3 +9,4 @@ export * from './expression_functions'; export * from './expression_renderers'; export * from './elements'; export * from './ui_views'; +export * from './dict'; diff --git a/src/plugins/expression_reveal_image/public/index.ts b/src/plugins/expression_reveal_image/public/index.ts index 92063cbfaf2e7..bdbc0b47306ef 100755 --- a/src/plugins/expression_reveal_image/public/index.ts +++ b/src/plugins/expression_reveal_image/public/index.ts @@ -11,13 +11,13 @@ import { ExpressionRevealImagePlugin } from './plugin'; import { revealImageRenderer } from './expression_renderers'; import { revealImageElement } from './elements'; import { revealImageUIView } from './ui_views'; +import { translateElements } from '../common/lib/translate_elements'; -export const elements = [revealImageElement]; +export type { ExpressionRevealImagePluginSetup, ExpressionRevealImagePluginStart } from './plugin'; +export const elements = translateElements([revealImageElement]); export const renderers = [revealImageRenderer]; export const uiViews = [revealImageUIView]; -// This exports static code and TypeScript types, -// as well as, Kibana Platform `plugin()` initializer. export function plugin() { return new ExpressionRevealImagePlugin(); } diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts index bd7ff05743416..b49933f75a9b0 100755 --- a/src/plugins/expression_reveal_image/public/plugin.ts +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -12,7 +12,7 @@ import { LEGACY_RENDERER_LIBRARY } from '../common'; import { revealImageFunction } from './expression_functions'; import { revealImageRenderer } from './expression_renderers'; import { revealImage as revealImageRendererLegacy } from './expression_renderers_legacy'; -import { ExpressionService, ExpressionsServiceSetup } from './services'; +import { ExpressionService, ExpressionServiceSetup, ExpressionServiceStart } from './services'; interface SetupDeps { expressions: ExpressionsSetup; @@ -22,10 +22,20 @@ interface StartDeps { expression: ExpressionsStart; } -export class ExpressionRevealImagePlugin implements Plugin { +export type ExpressionRevealImagePluginSetup = ExpressionServiceSetup; +export type ExpressionRevealImagePluginStart = ExpressionServiceStart; + +export class ExpressionRevealImagePlugin + implements + Plugin< + ExpressionRevealImagePluginSetup, + ExpressionRevealImagePluginStart, + SetupDeps, + StartDeps + > { private readonly expressionService: ExpressionService = new ExpressionService(); - public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionsServiceSetup { + public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup { expressions.registerFunction(revealImageFunction); if (!core.uiSettings.get(LEGACY_RENDERER_LIBRARY, false)) { @@ -39,7 +49,7 @@ export class ExpressionRevealImagePlugin implements Plugin; - -export interface ExpressionsServiceSetup { +export interface ExpressionServiceSetup { getViews: () => Array>; getRenderers: () => Array<() => ExpressionRenderDefinition>; getElements: () => ElementFactory[]; } -export type ExpressionsServiceStart = ExpressionsServiceSetup; +export type ExpressionServiceStart = ExpressionServiceSetup; export class ExpressionService { public readonly getElements = (): ElementFactory[] => elements; @@ -31,11 +26,11 @@ export class ExpressionService { > => renderers; public readonly getViews = (): Array> => uiViews; - public setup(...args: unknown[]): ExpressionsServiceSetup { + public setup(...args: unknown[]): ExpressionServiceSetup { return this; } - public start(...args: unknown[]): ExpressionsServiceStart { + public start(...args: unknown[]): ExpressionServiceStart { return this; } diff --git a/x-pack/plugins/canvas/kibana.json b/x-pack/plugins/canvas/kibana.json index 5faeaefc9e392..b332740151297 100644 --- a/x-pack/plugins/canvas/kibana.json +++ b/x-pack/plugins/canvas/kibana.json @@ -19,7 +19,8 @@ "optionalPlugins": [ "home", "reporting", - "usageCollection" + "usageCollection", + "expressionRevealImage" ], "requiredBundles": [ "discover", diff --git a/x-pack/plugins/canvas/public/plugin.tsx b/x-pack/plugins/canvas/public/plugin.tsx index d31a5a18cecc1..1d5d9b74a6155 100644 --- a/x-pack/plugins/canvas/public/plugin.tsx +++ b/x-pack/plugins/canvas/public/plugin.tsx @@ -22,6 +22,10 @@ import { getSessionStorage } from './lib/storage'; import { SESSIONSTORAGE_LASTPATH } from '../common/lib/constants'; import { featureCatalogueEntry } from './feature_catalogue_entry'; import { ExpressionsSetup, ExpressionsStart } from '../../../../src/plugins/expressions/public'; +import { + ExpressionRevealImagePluginSetup, + ExpressionRevealImagePluginStart, +} from '../../../../src/plugins/expression_reveal_image/public'; import { DataPublicPluginSetup, DataPublicPluginStart } from '../../../../src/plugins/data/public'; import { UiActionsStart } from '../../../../src/plugins/ui_actions/public'; import { EmbeddableStart } from '../../../../src/plugins/embeddable/public'; @@ -45,6 +49,8 @@ export interface CanvasSetupDeps { usageCollection?: UsageCollectionSetup; bfetch: BfetchPublicSetup; charts: ChartsPluginSetup; + + expressionRevealImage?: ExpressionRevealImagePluginSetup; } export interface CanvasStartDeps { @@ -56,6 +62,8 @@ export interface CanvasStartDeps { charts: ChartsPluginStart; data: DataPublicPluginStart; presentationUtil: PresentationUtilPluginStart; + + expressionRevealImage?: ExpressionRevealImagePluginStart; } /** @@ -126,6 +134,12 @@ export class CanvasPlugin plugins.home.featureCatalogue.register(featureCatalogueEntry); } + if (plugins.expressionRevealImage) { + canvasApi.addElements(plugins.expressionRevealImage.getElements()); + canvasApi.addViewUIs(plugins.expressionRevealImage.getViews()); + canvasApi.addRenderers(plugins.expressionRevealImage.getRenderers()); + } + canvasApi.addArgumentUIs(async () => { // @ts-expect-error const { argTypeSpecs } = await import('./expression_types/arg_types'); diff --git a/x-pack/plugins/canvas/tsconfig.json b/x-pack/plugins/canvas/tsconfig.json index 487b68ba3542b..84581d7be85a3 100644 --- a/x-pack/plugins/canvas/tsconfig.json +++ b/x-pack/plugins/canvas/tsconfig.json @@ -31,6 +31,7 @@ { "path": "../../../src/plugins/discover/tsconfig.json" }, { "path": "../../../src/plugins/embeddable/tsconfig.json" }, { "path": "../../../src/plugins/expressions/tsconfig.json" }, + { "path": "../../../src/plugins/expression_reveal_image/tsconfig.json" }, { "path": "../../../src/plugins/home/tsconfig.json" }, { "path": "../../../src/plugins/inspector/tsconfig.json" }, { "path": "../../../src/plugins/kibana_legacy/tsconfig.json" }, diff --git a/x-pack/plugins/canvas/types/renderers.ts b/x-pack/plugins/canvas/types/renderers.ts index e840ebee43ed3..2c3931485757d 100644 --- a/x-pack/plugins/canvas/types/renderers.ts +++ b/x-pack/plugins/canvas/types/renderers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { IInterpreterRenderHandlers } from 'src/plugins/expressions'; +import { ExpressionRenderDefinition, IInterpreterRenderHandlers } from 'src/plugins/expressions'; type GenericRendererCallback = (callback: () => void) => void; @@ -35,9 +35,9 @@ export interface RendererSpec { /** The render type */ name: string; /** The name to display */ - displayName: string; + displayName?: string; /** A description of what is rendered */ - help: string; + help?: string; /** Indicate whether the element should reuse the existing DOM element when re-rendering */ reuseDomNode: boolean; /** The default width of the element in pixels */ @@ -50,5 +50,7 @@ export interface RendererSpec { export type RendererFactory = () => RendererSpec; -export type AnyRendererFactory = RendererFactory; +export type AnyRendererFactory = + | RendererFactory + | Array<() => ExpressionRenderDefinition>; export type AnyRendererSpec = RendererSpec; From 49e52b075e90ca47228d8e4c4b7fa849b4e66901 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 15 Jun 2021 10:24:48 +0300 Subject: [PATCH 26/77] Fixed --- .../expression_reveal_image/common/lib/translate_elements.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/expression_reveal_image/common/lib/translate_elements.ts b/src/plugins/expression_reveal_image/common/lib/translate_elements.ts index e2b7037faf034..0e9f27eaf6771 100644 --- a/src/plugins/expression_reveal_image/common/lib/translate_elements.ts +++ b/src/plugins/expression_reveal_image/common/lib/translate_elements.ts @@ -14,7 +14,7 @@ export function translateElements(elements: ElementFactory[] = []) { const { name } = element; const strings = getElementsStrings(); const elementStrings = strings[name] ?? {}; - element.displayName = elementStrings['displayName'] ?? element.displayName; + element.displayName = elementStrings.displayName ?? element.displayName; element.help = elementStrings.help ?? element.help; return () => element; From 5f9ab82c80cb3800968b6bc48947476a397860fb Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 15 Jun 2021 10:26:16 +0300 Subject: [PATCH 27/77] Fixed mutiple call of the function. --- .../expression_reveal_image/common/lib/translate_elements.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/expression_reveal_image/common/lib/translate_elements.ts b/src/plugins/expression_reveal_image/common/lib/translate_elements.ts index 0e9f27eaf6771..3e86180f9d6e1 100644 --- a/src/plugins/expression_reveal_image/common/lib/translate_elements.ts +++ b/src/plugins/expression_reveal_image/common/lib/translate_elements.ts @@ -9,10 +9,10 @@ import { ElementFactory } from '../types'; import { getElementsStrings } from '../i18n'; export function translateElements(elements: ElementFactory[] = []) { + const strings = getElementsStrings(); return elements.map((elFactory) => { const element = elFactory(); const { name } = element; - const strings = getElementsStrings(); const elementStrings = strings[name] ?? {}; element.displayName = elementStrings.displayName ?? element.displayName; element.help = elementStrings.help ?? element.help; From 0c11bcd42920f2ee0313b3cdbc06f757c992d4f4 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 15 Jun 2021 10:30:50 +0300 Subject: [PATCH 28/77] Removed support of a legacy lib for revealImage chart. --- .../common/constants.ts | 1 - .../expression_reveal_image/kibana.json | 2 +- .../reveal_image.stories.storyshot | 14 --- .../__stories__/reveal_image.stories.tsx | 27 ------ .../expression_renderers_legacy/index.ts | 93 ------------------- .../reveal_image.scss | 18 ---- .../expression_reveal_image/public/plugin.ts | 9 +- .../expression_reveal_image/server/index.ts | 11 --- .../expression_reveal_image/server/plugin.ts | 20 ---- .../server/ui_settings.ts | 33 ------- 10 files changed, 2 insertions(+), 226 deletions(-) delete mode 100644 src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot delete mode 100644 src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx delete mode 100644 src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts delete mode 100644 src/plugins/expression_reveal_image/public/expression_renderers_legacy/reveal_image.scss delete mode 100644 src/plugins/expression_reveal_image/server/index.ts delete mode 100644 src/plugins/expression_reveal_image/server/plugin.ts delete mode 100644 src/plugins/expression_reveal_image/server/ui_settings.ts diff --git a/src/plugins/expression_reveal_image/common/constants.ts b/src/plugins/expression_reveal_image/common/constants.ts index c01ef82e1b00c..68ac53171ee7f 100644 --- a/src/plugins/expression_reveal_image/common/constants.ts +++ b/src/plugins/expression_reveal_image/common/constants.ts @@ -7,4 +7,3 @@ */ export const PLUGIN_ID = 'expressionRevealImage'; export const PLUGIN_NAME = 'expressionRevealImage'; -export const LEGACY_RENDERER_LIBRARY = `labs:expressions:${PLUGIN_NAME}:legacyRendererLibrary`; diff --git a/src/plugins/expression_reveal_image/kibana.json b/src/plugins/expression_reveal_image/kibana.json index 9af9a5857dcfb..5593ceb06a85c 100755 --- a/src/plugins/expression_reveal_image/kibana.json +++ b/src/plugins/expression_reveal_image/kibana.json @@ -2,7 +2,7 @@ "id": "expressionRevealImage", "version": "1.0.0", "kibanaVersion": "kibana", - "server": true, + "server": false, "ui": true, "requiredPlugins": ["expressions", "presentationUtil"], "optionalPlugins": [], diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot deleted file mode 100644 index d8a4ea0e11a5c..0000000000000 --- a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/__snapshots__/reveal_image.stories.storyshot +++ /dev/null @@ -1,14 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Storyshots renderers/revealImage_legacy default 1`] = ` -
- -
-`; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx deleted file mode 100644 index c6cbf91c28122..0000000000000 --- a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/__stories__/reveal_image.stories.tsx +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; -import { storiesOf } from '@storybook/react'; -import { revealImage } from '../'; -import { Render } from '../../__stories__'; -import { elasticOutline } from '../../../common/lib/elastic_outline'; -import { elasticLogo } from '../../../common/lib/elastic_logo'; -import { Origin } from '../../../common/types/expression_functions'; -import './reveal_image.scss'; - -storiesOf('renderers/revealImage_legacy', module).add('default', () => { - const config = { - image: elasticLogo, - emptyImage: elasticOutline, - origin: Origin.LEFT, - percent: 0.45, - }; - - return ; -}); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts deleted file mode 100644 index 5d9933ebcc2c8..0000000000000 --- a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/index.ts +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { ExpressionRenderDefinition } from 'src/plugins/expressions'; -import { elasticOutline } from '../../common/lib/elastic_outline'; -import { isValidUrl } from '../../common/lib/url'; -import { getRendererStrings } from '../../common/i18n'; -import { Output as Arguments, RendererHandlers } from '../../common/types'; - -import './reveal_image.scss'; - -const { revealImage: strings } = getRendererStrings(); - -export const revealImage = (): ExpressionRenderDefinition => { - return { - name: 'revealImage', - displayName: strings.getDisplayName(), - help: strings.getHelpDescription(), - reuseDomNode: true, - render(domNode: HTMLElement, config: Arguments, handlers: RendererHandlers) { - const aligner = document.createElement('div'); - const img = new Image(); - - // modify the top-level container class - domNode.className = 'revealImage'; - - // set up the overlay image - function onLoad() { - setSize(); - finish(); - } - - img.onload = onLoad; - - img.className = 'revealImage__image'; - img.style.clipPath = getClipPath(config.percent, config.origin); - img.style.setProperty('-webkit-clip-path', getClipPath(config.percent, config.origin)); - img.src = isValidUrl(config.image) ? config.image : elasticOutline; - handlers.onResize?.(onLoad); - - // set up the underlay, "empty" image - aligner.className = 'revealImageAligner'; - aligner.appendChild(img); - if (isValidUrl(config.emptyImage)) { - // only use empty image if one is provided - aligner.style.backgroundImage = `url(${config.emptyImage})`; - } - - function finish() { - const firstChild = domNode.firstChild; - if (firstChild) { - domNode.replaceChild(aligner, firstChild); - } else { - domNode.appendChild(aligner); - } - handlers.done(); - } - - function getClipPath(percent: number, origin = 'bottom') { - const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; - const values: Array = [0, 0, 0, 0]; - values[directions[origin]] = `${100 - percent * 100}%`; - return `inset(${values.join(' ')})`; - } - - function setSize() { - const imgDimensions = { - height: img.naturalHeight, - width: img.naturalWidth, - ratio: img.naturalHeight / img.naturalWidth, - }; - - const domNodeDimensions = { - height: domNode.clientHeight, - width: domNode.clientWidth, - ratio: domNode.clientHeight / domNode.clientWidth, - }; - - if (imgDimensions.ratio > domNodeDimensions.ratio) { - img.style.height = `${domNodeDimensions.height}px`; - img.style.width = 'initial'; - } else { - img.style.width = `${domNodeDimensions.width}px`; - img.style.height = 'initial'; - } - } - }, - }; -}; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/reveal_image.scss b/src/plugins/expression_reveal_image/public/expression_renderers_legacy/reveal_image.scss deleted file mode 100644 index f94668b7cdfa2..0000000000000 --- a/src/plugins/expression_reveal_image/public/expression_renderers_legacy/reveal_image.scss +++ /dev/null @@ -1,18 +0,0 @@ -.revealImage { - height: 100%; - width: 100%; - display: flex; - align-items: center; - justify-content: center; - pointer-events: none; - - .revealImageAligner { - background-size: contain; - background-repeat: no-repeat; - } - - // disables selection and dragging - .revealImage__image { - user-select: none; - } -} diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts index b49933f75a9b0..ee76221857e81 100755 --- a/src/plugins/expression_reveal_image/public/plugin.ts +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -8,10 +8,8 @@ import { CoreSetup, CoreStart, Plugin } from '../../../core/public'; import { ExpressionsStart, ExpressionsSetup } from '../../expressions/public'; -import { LEGACY_RENDERER_LIBRARY } from '../common'; import { revealImageFunction } from './expression_functions'; import { revealImageRenderer } from './expression_renderers'; -import { revealImage as revealImageRendererLegacy } from './expression_renderers_legacy'; import { ExpressionService, ExpressionServiceSetup, ExpressionServiceStart } from './services'; interface SetupDeps { @@ -37,12 +35,7 @@ export class ExpressionRevealImagePlugin public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup { expressions.registerFunction(revealImageFunction); - - if (!core.uiSettings.get(LEGACY_RENDERER_LIBRARY, false)) { - expressions.registerRenderer(revealImageRenderer); - } else { - expressions.registerRenderer(revealImageRendererLegacy); - } + expressions.registerRenderer(revealImageRenderer); const setup = { ...this.expressionService.setup() }; diff --git a/src/plugins/expression_reveal_image/server/index.ts b/src/plugins/expression_reveal_image/server/index.ts deleted file mode 100644 index 26c352b0bb333..0000000000000 --- a/src/plugins/expression_reveal_image/server/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { ExpressionRevealImageServerPlugin } from './plugin'; - -export const plugin = () => new ExpressionRevealImageServerPlugin(); diff --git a/src/plugins/expression_reveal_image/server/plugin.ts b/src/plugins/expression_reveal_image/server/plugin.ts deleted file mode 100644 index 467a1ca662106..0000000000000 --- a/src/plugins/expression_reveal_image/server/plugin.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { CoreSetup, Plugin } from 'kibana/server'; -import { getUiSettingsConfig } from './ui_settings'; - -export class ExpressionRevealImageServerPlugin implements Plugin { - public setup(core: CoreSetup) { - core.uiSettings.register(getUiSettingsConfig()); - return {}; - } - - public start() { - return {}; - } -} diff --git a/src/plugins/expression_reveal_image/server/ui_settings.ts b/src/plugins/expression_reveal_image/server/ui_settings.ts deleted file mode 100644 index f4d0afff3ab9a..0000000000000 --- a/src/plugins/expression_reveal_image/server/ui_settings.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { i18n } from '@kbn/i18n'; -import { schema } from '@kbn/config-schema'; - -import { UiSettingsParams } from 'kibana/server'; - -import { SETTING_CATEGORY } from '../../presentation_util/server'; -import { LEGACY_RENDERER_LIBRARY } from '../common'; - -export const getUiSettingsConfig: () => Record> = () => ({ - [LEGACY_RENDERER_LIBRARY]: { - name: i18n.translate('expressionRevealImage.advancedSettings.legacyRendererLibrary.name', { - defaultMessage: 'Legacy expression reveal image renderer library', - }), - requiresPageReload: true, - value: false, - description: i18n.translate( - 'expressionRevealImage.advancedSettings.legacyRendererLibrary.description', - { - defaultMessage: 'Enables legacy renderer library for revealImage expression in canvas.', - } - ), - category: [SETTING_CATEGORY], - schema: schema.boolean(), - }, -}); From 2b36c9496eb8c6aa9c77e6ee5c5f695ca29db342 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 15 Jun 2021 11:16:12 +0300 Subject: [PATCH 29/77] Removed legacy presentation_utils plugin import. --- src/plugins/expression_reveal_image/kibana.json | 2 +- src/plugins/expression_reveal_image/tsconfig.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/plugins/expression_reveal_image/kibana.json b/src/plugins/expression_reveal_image/kibana.json index 5593ceb06a85c..b2579bd061e5d 100755 --- a/src/plugins/expression_reveal_image/kibana.json +++ b/src/plugins/expression_reveal_image/kibana.json @@ -4,7 +4,7 @@ "kibanaVersion": "kibana", "server": false, "ui": true, - "requiredPlugins": ["expressions", "presentationUtil"], + "requiredPlugins": ["expressions"], "optionalPlugins": [], "requiredBundles": [] } diff --git a/src/plugins/expression_reveal_image/tsconfig.json b/src/plugins/expression_reveal_image/tsconfig.json index 93cf163110ac0..09a6d24dd7839 100644 --- a/src/plugins/expression_reveal_image/tsconfig.json +++ b/src/plugins/expression_reveal_image/tsconfig.json @@ -16,6 +16,5 @@ "references": [ { "path": "../../core/tsconfig.json" }, { "path": "../expressions/tsconfig.json" }, - { "path": "../presentation_util/tsconfig.json" }, ] } From 33b3ec764e56f8feda9fa07b3bad9da804a0e29e Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 15 Jun 2021 11:23:21 +0300 Subject: [PATCH 30/77] Doc error fixed. --- docs/developer/plugin-list.asciidoc | 2 +- src/plugins/expression_reveal_image/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/developer/plugin-list.asciidoc b/docs/developer/plugin-list.asciidoc index 2c75eaf169edf..91abd0d39ad28 100644 --- a/docs/developer/plugin-list.asciidoc +++ b/docs/developer/plugin-list.asciidoc @@ -73,7 +73,7 @@ This API doesn't support angular, for registering angular dev tools, bootstrap a |{kib-repo}blob/{branch}/src/plugins/expression_reveal_image/README.md[expressionRevealImage] -| This plugin addes expression to the canvas to be rendered +|Expression Reveal Image plugin is an extracted Canvas chart. It is registrating the revealImage chart, expression elements, functions and views to canvas and expression plugins. |<> diff --git a/src/plugins/expression_reveal_image/README.md b/src/plugins/expression_reveal_image/README.md index 9ab6e6fd5d4e6..5335580636a3e 100755 --- a/src/plugins/expression_reveal_image/README.md +++ b/src/plugins/expression_reveal_image/README.md @@ -1,6 +1,6 @@ # expressionRevealImage -A Kibana plugin +Expression Reveal Image plugin is an extracted Canvas chart. It is registrating the `revealImage` chart, expression elements, functions and views to canvas and expression plugins. --- From aa1f474532279207ddea3598a63e305827d909da Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 15 Jun 2021 15:44:35 +0300 Subject: [PATCH 31/77] Removed useless translations and tried to fix error. --- .../server/collectors/management/schema.ts | 4 ---- .../server/collectors/management/types.ts | 1 - src/plugins/telemetry/schema/oss_plugins.json | 6 ------ x-pack/plugins/canvas/public/plugin.tsx | 3 +++ .../shareable_runtime/__mocks__/supported_renderers.js | 1 + .../canvas/shareable_runtime/supported_renderers.d.ts | 5 +++++ .../plugins/canvas/shareable_runtime/supported_renderers.js | 2 ++ 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts index 33a26ec0f4211..5f70deccba93c 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/schema.ts @@ -456,8 +456,4 @@ export const stackManagementSchema: MakeSchemaFrom = { type: 'boolean', _meta: { description: 'Non-default value of setting.' }, }, - 'labs:expressions:expressionRevealImage:legacyRendererLibrary': { - type: 'boolean', - _meta: { description: 'Non-default value of setting.' }, - }, }; diff --git a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts index f0bade6a339c3..bf28bb6cc01f5 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/management/types.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/management/types.ts @@ -124,5 +124,4 @@ export interface UsageStats { 'labs:presentation:timeToPresent': boolean; 'labs:dashboard:enable_ui': boolean; 'labs:dashboard:deferBelowFold': boolean; - 'labs:expressions:expressionRevealImage:legacyRendererLibrary': boolean; } diff --git a/src/plugins/telemetry/schema/oss_plugins.json b/src/plugins/telemetry/schema/oss_plugins.json index afabf95072717..51df1d3162b7c 100644 --- a/src/plugins/telemetry/schema/oss_plugins.json +++ b/src/plugins/telemetry/schema/oss_plugins.json @@ -8596,12 +8596,6 @@ "_meta": { "description": "Non-default value of setting." } - }, - "labs:expressions:expressionRevealImage:legacyRendererLibrary": { - "type": "boolean", - "_meta": { - "description": "Non-default value of setting." - } } } }, diff --git a/x-pack/plugins/canvas/public/plugin.tsx b/x-pack/plugins/canvas/public/plugin.tsx index 1d5d9b74a6155..77f7ed613d9fb 100644 --- a/x-pack/plugins/canvas/public/plugin.tsx +++ b/x-pack/plugins/canvas/public/plugin.tsx @@ -35,6 +35,8 @@ import { BfetchPublicSetup } from '../../../../src/plugins/bfetch/public'; import { PresentationUtilPluginStart } from '../../../../src/plugins/presentation_util/public'; import { getPluginApi, CanvasApi } from './plugin_api'; import { CanvasSrcPlugin } from '../canvas_plugin_src/plugin'; +import { addSupportedRenderFunctions } from '../shareable_runtime/supported_renderers'; + export { CoreStart, CoreSetup }; /** @@ -138,6 +140,7 @@ export class CanvasPlugin canvasApi.addElements(plugins.expressionRevealImage.getElements()); canvasApi.addViewUIs(plugins.expressionRevealImage.getViews()); canvasApi.addRenderers(plugins.expressionRevealImage.getRenderers()); + addSupportedRenderFunctions(plugins.expressionRevealImage.getRenderers()); } canvasApi.addArgumentUIs(async () => { diff --git a/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js index ab602ad3be631..c01b1b3f23543 100644 --- a/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js @@ -13,6 +13,7 @@ const renderers = [ 'error', 'image', 'repeatImage', + 'revealImage', 'markdown', 'metric', 'pie', diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts index 0ad36b1b7166a..4e5e878e435d4 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts @@ -5,7 +5,12 @@ * 2.0. */ +import { ExpressionRenderDefinition } from '../../../../src/plugins/expressions/public'; + import { RendererFactory } from '../types'; export const renderFunctions: RendererFactory[]; export const renderFunctionNames: string[]; +export const addSupportedRenderFunctions: ( + renderers: RendererFactory[] | Array<() => ExpressionRenderDefinition> +) => void; diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js index b4309117edbc4..13c5b222b6cd4 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js @@ -38,4 +38,6 @@ export const renderFunctions = [ text, ]; +export const addSupportedRenderFunctions = (renderers = []) => renderFunctions.concat(renderers); + export const renderFunctionNames = renderFunctions.map((fn) => fn.name); From 7bad36625260b2d27dae7676e2f544183ab3940c Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 15 Jun 2021 15:49:46 +0300 Subject: [PATCH 32/77] One more fix. --- .../plugins/canvas/shareable_runtime/supported_renderers.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js index 13c5b222b6cd4..1cd5524608f75 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js @@ -23,7 +23,7 @@ import { text } from '../canvas_plugin_src/renderers/text'; * a renderer is not listed here, but is used by the Shared Workpad, it will * not render. This includes any plugins. */ -export const renderFunctions = [ +export let renderFunctions = [ debug, error, image, @@ -38,6 +38,7 @@ export const renderFunctions = [ text, ]; -export const addSupportedRenderFunctions = (renderers = []) => renderFunctions.concat(renderers); +export const addSupportedRenderFunctions = (renderers = []) => + (renderFunctions = [...renderFunctions, ...renderers]); export const renderFunctionNames = renderFunctions.map((fn) => fn.name); From 29830970ca034ea1dce2623fa12dd80044a408e7 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Wed, 16 Jun 2021 12:56:01 +0300 Subject: [PATCH 33/77] Small imports fix. --- .../public/elements/index.ts | 16 ++----- .../public/elements/reveal_image_element.ts | 21 +++++++++ .../public/expression_renderers/index.ts | 6 ++- .../expression_reveal_image/public/index.ts | 8 ---- .../public/services/expression_service.ts | 4 +- .../public/ui_views/index.ts | 40 ++--------------- .../public/ui_views/reveal_image_ui_view.ts | 45 +++++++++++++++++++ 7 files changed, 82 insertions(+), 58 deletions(-) create mode 100644 src/plugins/expression_reveal_image/public/elements/reveal_image_element.ts create mode 100644 src/plugins/expression_reveal_image/public/ui_views/reveal_image_ui_view.ts diff --git a/src/plugins/expression_reveal_image/public/elements/index.ts b/src/plugins/expression_reveal_image/public/elements/index.ts index 5d18105ea87fc..a0d988c2f1afe 100644 --- a/src/plugins/expression_reveal_image/public/elements/index.ts +++ b/src/plugins/expression_reveal_image/public/elements/index.ts @@ -5,17 +5,9 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ +import { translateElements } from '../../common/lib/translate_elements'; +import { revealImageElement } from './reveal_image_element'; -import { ElementFactory } from '../../common/types'; +export const elements = translateElements([revealImageElement]); -export const revealImageElement: ElementFactory = () => ({ - name: 'revealImage', - displayName: 'Image reveal', - type: 'image', - help: 'Reveals a percentage of an image', - expression: `filters - | demodata - | math "mean(percent_uptime)" - | revealImage origin=bottom image=null - | render`, -}); +export { revealImageElement }; diff --git a/src/plugins/expression_reveal_image/public/elements/reveal_image_element.ts b/src/plugins/expression_reveal_image/public/elements/reveal_image_element.ts new file mode 100644 index 0000000000000..5d18105ea87fc --- /dev/null +++ b/src/plugins/expression_reveal_image/public/elements/reveal_image_element.ts @@ -0,0 +1,21 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { ElementFactory } from '../../common/types'; + +export const revealImageElement: ElementFactory = () => ({ + name: 'revealImage', + displayName: 'Image reveal', + type: 'image', + help: 'Reveals a percentage of an image', + expression: `filters + | demodata + | math "mean(percent_uptime)" + | revealImage origin=bottom image=null + | render`, +}); diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/index.ts b/src/plugins/expression_reveal_image/public/expression_renderers/index.ts index f34e2c400cec0..433a81884f157 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/index.ts +++ b/src/plugins/expression_reveal_image/public/expression_renderers/index.ts @@ -6,4 +6,8 @@ * Side Public License, v 1. */ -export * from './reveal_image_renderer'; +import { revealImageRenderer } from './reveal_image_renderer'; + +export const renderers = [revealImageRenderer]; + +export { revealImageRenderer }; diff --git a/src/plugins/expression_reveal_image/public/index.ts b/src/plugins/expression_reveal_image/public/index.ts index bdbc0b47306ef..b86c356974321 100755 --- a/src/plugins/expression_reveal_image/public/index.ts +++ b/src/plugins/expression_reveal_image/public/index.ts @@ -8,15 +8,7 @@ import { ExpressionRevealImagePlugin } from './plugin'; -import { revealImageRenderer } from './expression_renderers'; -import { revealImageElement } from './elements'; -import { revealImageUIView } from './ui_views'; -import { translateElements } from '../common/lib/translate_elements'; - export type { ExpressionRevealImagePluginSetup, ExpressionRevealImagePluginStart } from './plugin'; -export const elements = translateElements([revealImageElement]); -export const renderers = [revealImageRenderer]; -export const uiViews = [revealImageUIView]; export function plugin() { return new ExpressionRevealImagePlugin(); diff --git a/src/plugins/expression_reveal_image/public/services/expression_service.ts b/src/plugins/expression_reveal_image/public/services/expression_service.ts index ffbdab7616a50..c175620586bdf 100644 --- a/src/plugins/expression_reveal_image/public/services/expression_service.ts +++ b/src/plugins/expression_reveal_image/public/services/expression_service.ts @@ -8,7 +8,9 @@ import { ExpressionRenderDefinition } from 'src/plugins/expressions'; import { ElementFactory, StartInitializer } from '../../common/types'; -import { elements, renderers, uiViews } from '../'; +import { elements } from '../elements'; +import { renderers } from '../expression_renderers'; +import { uiViews } from '../ui_views'; import { RevealImageRendererConfig } from '../expression_renderers/types'; export interface ExpressionServiceSetup { diff --git a/src/plugins/expression_reveal_image/public/ui_views/index.ts b/src/plugins/expression_reveal_image/public/ui_views/index.ts index 82ffab2ef4f4e..ba2d19308b797 100644 --- a/src/plugins/expression_reveal_image/public/ui_views/index.ts +++ b/src/plugins/expression_reveal_image/public/ui_views/index.ts @@ -5,41 +5,9 @@ * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ -import { getUIStrings } from '../../common/i18n'; -import { StartInitializer } from '../../common/types'; -const { revealImage: strings } = getUIStrings(); +import { revealImageUIView } from './reveal_image_ui_view'; -export const revealImageUIView: StartInitializer = () => ({ - name: 'revealImage', - displayName: strings.getDisplayName(), - modelArgs: [['_', { label: 'Value' }]], - args: [ - { - name: 'image', - displayName: strings.getImageDisplayName(), - help: strings.getImageHelp(), - argType: 'imageUpload', - }, - { - name: 'emptyImage', - displayName: strings.getEmptyImageDisplayName(), - help: strings.getEmptyImageHelp(), - argType: 'imageUpload', - }, - { - name: 'origin', - displayName: strings.getOriginDisplayName(), - help: strings.getOriginHelp(), - argType: 'select', - options: { - choices: [ - { value: 'top', name: strings.getOriginTop() }, - { value: 'left', name: strings.getOriginLeft() }, - { value: 'bottom', name: strings.getOriginBottom() }, - { value: 'right', name: strings.getOriginRight() }, - ], - }, - }, - ], -}); +export const uiViews = [revealImageUIView]; + +export { revealImageUIView }; diff --git a/src/plugins/expression_reveal_image/public/ui_views/reveal_image_ui_view.ts b/src/plugins/expression_reveal_image/public/ui_views/reveal_image_ui_view.ts new file mode 100644 index 0000000000000..82ffab2ef4f4e --- /dev/null +++ b/src/plugins/expression_reveal_image/public/ui_views/reveal_image_ui_view.ts @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ +import { getUIStrings } from '../../common/i18n'; +import { StartInitializer } from '../../common/types'; + +const { revealImage: strings } = getUIStrings(); + +export const revealImageUIView: StartInitializer = () => ({ + name: 'revealImage', + displayName: strings.getDisplayName(), + modelArgs: [['_', { label: 'Value' }]], + args: [ + { + name: 'image', + displayName: strings.getImageDisplayName(), + help: strings.getImageHelp(), + argType: 'imageUpload', + }, + { + name: 'emptyImage', + displayName: strings.getEmptyImageDisplayName(), + help: strings.getEmptyImageHelp(), + argType: 'imageUpload', + }, + { + name: 'origin', + displayName: strings.getOriginDisplayName(), + help: strings.getOriginHelp(), + argType: 'select', + options: { + choices: [ + { value: 'top', name: strings.getOriginTop() }, + { value: 'left', name: strings.getOriginLeft() }, + { value: 'bottom', name: strings.getOriginBottom() }, + { value: 'right', name: strings.getOriginRight() }, + ], + }, + }, + ], +}); From 226fc89ba82c26c4f3f27ef0189b5a6526c4a74f Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Wed, 16 Jun 2021 14:39:16 +0300 Subject: [PATCH 34/77] Fixed translations. --- x-pack/plugins/translations/translations/ja-JP.json | 9 +++++++++ x-pack/plugins/translations/translations/zh-CN.json | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 5e351e3a4f4a9..27ac5128663b2 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -6081,6 +6081,8 @@ "xpack.canvas.elements.progressWheelHelpText": "進捗状況をホイールで表示します", "xpack.canvas.elements.repeatImageDisplayName": "画像の繰り返し", "xpack.canvas.elements.repeatImageHelpText": "画像を N 回繰り返します", + "expressionRevealImage.elements.revealImageDisplayName": "画像の部分表示", + "expressionRevealImage.elements.revealImageHelpText": "画像のパーセンテージを表示します", "xpack.canvas.elements.shapeDisplayName": "形状", "xpack.canvas.elements.shapeHelpText": "カスタマイズ可能な図形です", "xpack.canvas.elements.tableDisplayName": "データテーブル", @@ -6358,6 +6360,11 @@ "xpack.canvas.functions.repeatImage.args.maxHelpText": "画像が繰り返される最高回数です。", "xpack.canvas.functions.repeatImage.args.sizeHelpText": "画像の高さまたは幅のピクセル単位での最高値です。画像が縦長の場合、この関数は高さを制限します。", "xpack.canvas.functions.repeatImageHelpText": "繰り返し画像エレメントを構成します。", + "expressionRevealImage.functions.revealImage.args.emptyImageHelpText": "表示される背景画像です。画像アセットは「{BASE64}」データ {URL} として提供するか、部分式で渡します。", + "expressionRevealImage.functions.revealImage.args.imageHelpText": "表示する画像です。画像アセットは{BASE64}データ{URL}として提供するか、部分式で渡します。", + "expressionRevealImage.functions.revealImage.args.originHelpText": "画像で埋め始める位置です。たとえば、{list}、または {end}です。", + "expressionRevealImage.functions.revealImage.invalidPercentErrorMessage": "無効な値:「{percent}」。パーセンテージは 0 と 1 の間でなければなりません ", + "expressionRevealImage.functions.revealImageHelpText": "画像表示エレメントを構成します。", "xpack.canvas.functions.replace.args.flagsHelpText": "フラグを指定します。{url}を参照してください。", "xpack.canvas.functions.replace.args.patternHelpText": "{JS} 正規表現のテキストまたはパターンです。例:{example}。ここではキャプチャグループを使用できます。", "xpack.canvas.functions.replace.args.replacementHelpText": "文字列の一致する部分の代わりです。キャプチャグループはノードによってアクセス可能です。例:{example}。", @@ -6554,6 +6561,8 @@ "xpack.canvas.renderer.progress.helpDescription": "エレメントのパーセンテージを示す進捗インジケーターをレンダリングします", "xpack.canvas.renderer.repeatImage.displayName": "画像の繰り返し", "xpack.canvas.renderer.repeatImage.helpDescription": "画像を指定回数繰り返し表示します", + "expressionRevealImage.renderer.revealImage.displayName": "画像の部分表示", + "expressionRevealImage.renderer.revealImage.helpDescription": "カスタムゲージスタイルチャートを作成するため、画像のパーセンテージを表示します", "xpack.canvas.renderer.shape.displayName": "形状", "xpack.canvas.renderer.shape.helpDescription": "基本的な図形をレンダリングします", "xpack.canvas.renderer.table.displayName": "データテーブル", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index cd1853ef27106..a2c761c6b2eac 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -6120,6 +6120,8 @@ "xpack.canvas.elements.progressWheelHelpText": "将进度显示为轮盘的一部分", "xpack.canvas.elements.repeatImageDisplayName": "图像重复", "xpack.canvas.elements.repeatImageHelpText": "使图像重复 N 次", + "expressionRevealImage.elements.revealImageDisplayName": "图像显示", + "expressionRevealImage.elements.revealImageHelpText": "显示图像特定百分比", "xpack.canvas.elements.shapeDisplayName": "形状", "xpack.canvas.elements.shapeHelpText": "可定制的形状", "xpack.canvas.elements.tableDisplayName": "数据表", @@ -6402,6 +6404,12 @@ "xpack.canvas.functions.replace.args.patternHelpText": "{JS} 正则表达式的文本或模式。例如,{example}。您可以在此处使用捕获组。", "xpack.canvas.functions.replace.args.replacementHelpText": "字符串匹配部分的替代。捕获组可以通过其索引进行访问。例如,{example}。", "xpack.canvas.functions.rounddate.args.formatHelpText": "用于存储桶存储的 {MOMENTJS} 格式。例如,{example} 四舍五入到月份。请参见 {url}。", + "xpack.canvas.functions.replaceImageHelpText": "使用正则表达式替换字符串的各部分。", + "expressionRevealImage.functions.revealImage.args.emptyImageHelpText": "要显示的可选背景图像。以 `{BASE64}` 数据 {URL} 的形式提供图像资产或传入子表达式。", + "expressionRevealImage.functions.revealImage.args.imageHelpText": "要显示的图像。以 {BASE64} 数据 {URL} 的形式提供图像资产或传入子表达式。", + "expressionRevealImage.functions.revealImage.args.originHelpText": "要开始图像填充的位置。例如 {list} 或 {end}。", + "expressionRevealImage.functions.revealImage.invalidPercentErrorMessage": "无效值:“{percent}”。百分比必须介于 0 和 1 之间", + "expressionRevealImage.functions.revealImageHelpText": "配置图像显示元素。", "xpack.canvas.functions.rounddateHelpText": "使用 {MOMENTJS} 格式字符串舍入自 Epoch 起毫秒数,并返回自 Epoch 起毫秒数。", "xpack.canvas.functions.rowCountHelpText": "返回行数。与 {plyFn} 搭配使用,可获取唯一列值的计数或唯一列值的组合。", "xpack.canvas.functions.savedLens.args.idHelpText": "已保存 Lens 可视化对象的 ID", @@ -6593,6 +6601,8 @@ "xpack.canvas.renderer.progress.helpDescription": "呈现显示元素百分比的进度指示", "xpack.canvas.renderer.repeatImage.displayName": "图像重复", "xpack.canvas.renderer.repeatImage.helpDescription": "重复图像给定次数", + "expressionRevealImage.renderer.revealImage.displayName": "图像显示", + "expressionRevealImage.renderer.revealImage.helpDescription": "显示一定百分比的图像,以制作定制的仪表样式图表", "xpack.canvas.renderer.shape.displayName": "形状", "xpack.canvas.renderer.shape.helpDescription": "呈现基本形状", "xpack.canvas.renderer.table.displayName": "数据表", From ccd44506d4864a36f687fad06bec52ce0d96aafd Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Wed, 16 Jun 2021 16:52:43 +0300 Subject: [PATCH 35/77] Made fixes based on nits. --- .../public/expression_functions/index.ts | 6 ++- .../expression_reveal_image/public/plugin.ts | 6 +-- .../public/services/expression_service.ts | 41 ++++++++++++------- x-pack/plugins/canvas/public/plugin.tsx | 14 +++---- .../shareable_runtime/components/app.tsx | 4 +- .../supported_renderers.d.ts | 2 +- .../shareable_runtime/supported_renderers.js | 5 ++- .../canvas/shareable_runtime/test/context.tsx | 4 +- 8 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/plugins/expression_reveal_image/public/expression_functions/index.ts b/src/plugins/expression_reveal_image/public/expression_functions/index.ts index ed5f173465e57..dba24e8a0cb0a 100644 --- a/src/plugins/expression_reveal_image/public/expression_functions/index.ts +++ b/src/plugins/expression_reveal_image/public/expression_functions/index.ts @@ -6,4 +6,8 @@ * Side Public License, v 1. */ -export * from './reveal_image_function'; +import { revealImageFunction } from './reveal_image_function'; + +export const functions = [revealImageFunction]; + +export { revealImageFunction }; diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts index ee76221857e81..1ec63d92b25b3 100755 --- a/src/plugins/expression_reveal_image/public/plugin.ts +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -42,11 +42,7 @@ export class ExpressionRevealImagePlugin return Object.freeze(setup); } - public start(core: CoreStart): ExpressionRevealImagePluginStart { - const start = { ...this.expressionService.start() }; - - return Object.freeze(start); - } + public start(core: CoreStart): ExpressionRevealImagePluginStart {} public stop() { this.expressionService.stop(); diff --git a/src/plugins/expression_reveal_image/public/services/expression_service.ts b/src/plugins/expression_reveal_image/public/services/expression_service.ts index c175620586bdf..4865d3be20618 100644 --- a/src/plugins/expression_reveal_image/public/services/expression_service.ts +++ b/src/plugins/expression_reveal_image/public/services/expression_service.ts @@ -7,34 +7,45 @@ */ import { ExpressionRenderDefinition } from 'src/plugins/expressions'; -import { ElementFactory, StartInitializer } from '../../common/types'; +import { + ElementFactory, + StartInitializer, + ExpressionRevealImageFunction, +} from '../../common/types'; import { elements } from '../elements'; import { renderers } from '../expression_renderers'; +import { functions } from '../expression_functions'; import { uiViews } from '../ui_views'; import { RevealImageRendererConfig } from '../expression_renderers/types'; -export interface ExpressionServiceSetup { - getViews: () => Array>; - getRenderers: () => Array<() => ExpressionRenderDefinition>; - getElements: () => ElementFactory[]; +export type ExpressionServiceSetup = Pick; + +export interface ExpressionSetup { + elements: ElementFactory[]; + renderers: Array<() => ExpressionRenderDefinition>; + uiViews: Array>; + functions: ExpressionRevealImageFunction[]; } -export type ExpressionServiceStart = ExpressionServiceSetup; +export type ExpressionServiceStart = void; export class ExpressionService { - public readonly getElements = (): ElementFactory[] => elements; - public readonly getRenderers = (): Array< - () => ExpressionRenderDefinition - > => renderers; - public readonly getViews = (): Array> => uiViews; + public readonly registerExpression: (fn?: (expressions: ExpressionSetup) => void) => void = ( + fn + ) => { + if (fn && typeof fn === 'function') { + fn({ elements, renderers, uiViews, functions }); + } + }; public setup(...args: unknown[]): ExpressionServiceSetup { - return this; + const { registerExpression } = this; + return Object.freeze({ + registerExpression, + }); } - public start(...args: unknown[]): ExpressionServiceStart { - return this; - } + public start(...args: unknown[]): ExpressionServiceStart {} public stop() {} } diff --git a/x-pack/plugins/canvas/public/plugin.tsx b/x-pack/plugins/canvas/public/plugin.tsx index 77f7ed613d9fb..12f4a3f6e1096 100644 --- a/x-pack/plugins/canvas/public/plugin.tsx +++ b/x-pack/plugins/canvas/public/plugin.tsx @@ -65,7 +65,7 @@ export interface CanvasStartDeps { data: DataPublicPluginStart; presentationUtil: PresentationUtilPluginStart; - expressionRevealImage?: ExpressionRevealImagePluginStart; + freee?: ExpressionRevealImagePluginStart; } /** @@ -136,12 +136,12 @@ export class CanvasPlugin plugins.home.featureCatalogue.register(featureCatalogueEntry); } - if (plugins.expressionRevealImage) { - canvasApi.addElements(plugins.expressionRevealImage.getElements()); - canvasApi.addViewUIs(plugins.expressionRevealImage.getViews()); - canvasApi.addRenderers(plugins.expressionRevealImage.getRenderers()); - addSupportedRenderFunctions(plugins.expressionRevealImage.getRenderers()); - } + plugins.expressionRevealImage?.registerExpression(({ elements, renderers, uiViews }) => { + canvasApi.addElements(elements); + canvasApi.addRenderers(renderers); + canvasApi.addViewUIs(uiViews); + addSupportedRenderFunctions(renderers); + }); canvasApi.addArgumentUIs(async () => { // @ts-expect-error diff --git a/x-pack/plugins/canvas/shareable_runtime/components/app.tsx b/x-pack/plugins/canvas/shareable_runtime/components/app.tsx index 35c40168cbea4..5784310e8e488 100644 --- a/x-pack/plugins/canvas/shareable_runtime/components/app.tsx +++ b/x-pack/plugins/canvas/shareable_runtime/components/app.tsx @@ -10,7 +10,7 @@ import { CanvasRenderedWorkpad, CanvasShareableState, Stage } from '../types'; import { RendererSpec } from '../../types'; import { initialCanvasShareableState, CanvasShareableStateProvider } from '../context'; import { Canvas } from './canvas'; -import { renderFunctions } from '../supported_renderers'; +import { getSupportedRenderFunctions } from '../supported_renderers'; interface Props { /** @@ -30,7 +30,7 @@ interface Props { export const App: FC = ({ workpad, stage }) => { const renderers: { [key: string]: RendererSpec } = {}; - renderFunctions.forEach((fn) => { + getSupportedRenderFunctions().forEach((fn) => { const func = fn(); renderers[func.name] = func; }); diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts index 4e5e878e435d4..4db016c1a37ab 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts @@ -9,8 +9,8 @@ import { ExpressionRenderDefinition } from '../../../../src/plugins/expressions/ import { RendererFactory } from '../types'; -export const renderFunctions: RendererFactory[]; export const renderFunctionNames: string[]; export const addSupportedRenderFunctions: ( renderers: RendererFactory[] | Array<() => ExpressionRenderDefinition> ) => void; +export const getSupportedRenderFunctions: () => RendererFactory[]; diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js index 1cd5524608f75..45858e3ab3d70 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js @@ -23,7 +23,7 @@ import { text } from '../canvas_plugin_src/renderers/text'; * a renderer is not listed here, but is used by the Shared Workpad, it will * not render. This includes any plugins. */ -export let renderFunctions = [ +let renderFunctions = [ debug, error, image, @@ -38,7 +38,10 @@ export let renderFunctions = [ text, ]; +// this method is for usage on setup step of plugin only export const addSupportedRenderFunctions = (renderers = []) => (renderFunctions = [...renderFunctions, ...renderers]); +export const getSupportedRenderFunctions = () => renderFunctions; + export const renderFunctionNames = renderFunctions.map((fn) => fn.name); diff --git a/x-pack/plugins/canvas/shareable_runtime/test/context.tsx b/x-pack/plugins/canvas/shareable_runtime/test/context.tsx index 394a666599bc6..a9543a889bdf8 100644 --- a/x-pack/plugins/canvas/shareable_runtime/test/context.tsx +++ b/x-pack/plugins/canvas/shareable_runtime/test/context.tsx @@ -11,7 +11,7 @@ import { CanvasShareableStateProvider, useCanvasShareableState, } from '../context/index'; -import { renderFunctions } from '../supported_renderers'; +import { getSupportedRenderFunctions } from '../supported_renderers'; import { CanvasShareableState } from '../types'; import { RendererSpec } from '../../types'; import { sharedWorkpads, WorkpadNames } from '.'; @@ -60,7 +60,7 @@ export const Context = ({ }: Props) => { const renderers: { [key: string]: RendererSpec } = {}; - renderFunctions.forEach((rendererFn) => { + getSupportedRenderFunctions().forEach((rendererFn) => { const renderer = rendererFn(); renderers[renderer.name] = renderer; }); From 390a54788c36028b94a252450aec2847df592ef6 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Wed, 16 Jun 2021 16:54:23 +0300 Subject: [PATCH 36/77] Removed useless params. --- .../public/services/expression_service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/expression_reveal_image/public/services/expression_service.ts b/src/plugins/expression_reveal_image/public/services/expression_service.ts index 4865d3be20618..83941dbfe5b12 100644 --- a/src/plugins/expression_reveal_image/public/services/expression_service.ts +++ b/src/plugins/expression_reveal_image/public/services/expression_service.ts @@ -38,14 +38,14 @@ export class ExpressionService { } }; - public setup(...args: unknown[]): ExpressionServiceSetup { + public setup(): ExpressionServiceSetup { const { registerExpression } = this; return Object.freeze({ registerExpression, }); } - public start(...args: unknown[]): ExpressionServiceStart {} + public start(): ExpressionServiceStart {} public stop() {} } From ec78576a8ed1ed8c30ef07dc635bac0be85787a2 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Wed, 16 Jun 2021 18:11:43 +0300 Subject: [PATCH 37/77] fix. --- .../plugins/canvas/shareable_runtime/supported_renderers.d.ts | 2 +- .../plugins/canvas/shareable_runtime/supported_renderers.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts index 4db016c1a37ab..c9934c3feef23 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts @@ -13,4 +13,4 @@ export const renderFunctionNames: string[]; export const addSupportedRenderFunctions: ( renderers: RendererFactory[] | Array<() => ExpressionRenderDefinition> ) => void; -export const getSupportedRenderFunctions: () => RendererFactory[]; +export function getSupportedRenderFunctions(): RendererFactory[]; diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js index 45858e3ab3d70..305aecc40e0f3 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js @@ -42,6 +42,8 @@ let renderFunctions = [ export const addSupportedRenderFunctions = (renderers = []) => (renderFunctions = [...renderFunctions, ...renderers]); -export const getSupportedRenderFunctions = () => renderFunctions; +export function getSupportedRenderFunctions() { + return renderFunctions; +} export const renderFunctionNames = renderFunctions.map((fn) => fn.name); From 55b21d0caa3f60e45dc761fb7bd96c4e2628c7d1 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Wed, 16 Jun 2021 20:17:38 +0300 Subject: [PATCH 38/77] Fixed errors, related to jest and __mocks__. --- .../canvas/shareable_runtime/__mocks__/supported_renderers.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js index c01b1b3f23543..b47e3b2b84304 100644 --- a/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js @@ -37,3 +37,7 @@ export const renderFunctions = renderers.map((fn) => () => ({ ReactDOM.render(
{fn} mock
, domNode); }, })); + +export const getSupportedRenderFunctions = () => { + return renderFunctions; +}; From 19e90245eae794ac31ea8d4858f6b8ccbd3bbbf7 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Wed, 16 Jun 2021 20:21:47 +0300 Subject: [PATCH 39/77] Removed useless type definition. --- x-pack/plugins/canvas/public/plugin.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/x-pack/plugins/canvas/public/plugin.tsx b/x-pack/plugins/canvas/public/plugin.tsx index 12f4a3f6e1096..99aed6dfe57de 100644 --- a/x-pack/plugins/canvas/public/plugin.tsx +++ b/x-pack/plugins/canvas/public/plugin.tsx @@ -22,10 +22,7 @@ import { getSessionStorage } from './lib/storage'; import { SESSIONSTORAGE_LASTPATH } from '../common/lib/constants'; import { featureCatalogueEntry } from './feature_catalogue_entry'; import { ExpressionsSetup, ExpressionsStart } from '../../../../src/plugins/expressions/public'; -import { - ExpressionRevealImagePluginSetup, - ExpressionRevealImagePluginStart, -} from '../../../../src/plugins/expression_reveal_image/public'; +import { ExpressionRevealImagePluginSetup } from '../../../../src/plugins/expression_reveal_image/public'; import { DataPublicPluginSetup, DataPublicPluginStart } from '../../../../src/plugins/data/public'; import { UiActionsStart } from '../../../../src/plugins/ui_actions/public'; import { EmbeddableStart } from '../../../../src/plugins/embeddable/public'; @@ -64,8 +61,6 @@ export interface CanvasStartDeps { charts: ChartsPluginStart; data: DataPublicPluginStart; presentationUtil: PresentationUtilPluginStart; - - freee?: ExpressionRevealImagePluginStart; } /** From bdea22accee944921b5b31612c80e4fd040c06ec Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 12:29:04 +0300 Subject: [PATCH 40/77] Replaced RendererHandlers with IInterpreterRendererHandlers. --- .../common/types/expression_renderers.ts | 32 ------------------- .../common/types/index.ts | 1 - .../public/__stories__/render.tsx | 16 ++-------- .../components/reveal_image_component.tsx | 14 ++++---- .../reveal_image_renderer.tsx | 5 ++- 5 files changed, 12 insertions(+), 56 deletions(-) delete mode 100644 src/plugins/expression_reveal_image/common/types/expression_renderers.ts diff --git a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts deleted file mode 100644 index d17cc5a55d722..0000000000000 --- a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { IInterpreterRenderHandlers } from 'src/plugins/expressions'; - -type GenericRendererCallback = (callback: () => void) => void; - -export interface RendererHandlers extends IInterpreterRenderHandlers { - /** Handler to invoke when an element should be destroyed. */ - destroy?: () => void; - /** Get the id of the element being rendered. Can be used as a unique ID in a render function */ - getElementId?: () => string; - /** Retrieves the value of the filter property on the element object persisted on the workpad */ - getFilter?: () => string; - /** Handler to invoke when a renderer is considered complete */ - onComplete?: (fn: () => void) => void; - /** Handler to invoke when a rendered embeddable is destroyed */ - onEmbeddableDestroyed?: () => void; - /** Handler to invoke when the input to a function has changed internally */ - onEmbeddableInputChange?: (expression: string) => void; - /** Handler to invoke when an element's dimensions have changed*/ - onResize?: GenericRendererCallback; - /** Handler to invoke when an element should be resized. */ - resize?: (size: { height: number; width: number }) => void; - /** Sets the value of the filter property on the element object persisted on the workpad */ - setFilter?: (filter: string) => void; -} diff --git a/src/plugins/expression_reveal_image/common/types/index.ts b/src/plugins/expression_reveal_image/common/types/index.ts index 6cc5706b453c0..e21c6e33b6a91 100644 --- a/src/plugins/expression_reveal_image/common/types/index.ts +++ b/src/plugins/expression_reveal_image/common/types/index.ts @@ -6,7 +6,6 @@ * Side Public License, v 1. */ export * from './expression_functions'; -export * from './expression_renderers'; export * from './elements'; export * from './ui_views'; export * from './dict'; diff --git a/src/plugins/expression_reveal_image/public/__stories__/render.tsx b/src/plugins/expression_reveal_image/public/__stories__/render.tsx index f7576ea9422ee..29d95e6bf2819 100644 --- a/src/plugins/expression_reveal_image/public/__stories__/render.tsx +++ b/src/plugins/expression_reveal_image/public/__stories__/render.tsx @@ -8,21 +8,11 @@ import { action } from '@storybook/addon-actions'; import React, { useRef, useEffect } from 'react'; -import { ExpressionRenderDefinition } from 'src/plugins/expressions'; -import { RendererHandlers } from '../../common/types'; +import { ExpressionRenderDefinition, IInterpreterRenderHandlers } from 'src/plugins/expressions'; -export const defaultHandlers: RendererHandlers = { - destroy: () => action('destroy'), - getElementId: () => 'element-id', - getFilter: () => 'filter', +export const defaultHandlers: IInterpreterRenderHandlers = { getRenderMode: () => 'display', isSyncColorsEnabled: () => false, - onComplete: (fn) => undefined, - onEmbeddableDestroyed: action('onEmbeddableDestroyed'), - onEmbeddableInputChange: action('onEmbeddableInputChange'), - onResize: action('onResize'), - resize: action('resize'), - setFilter: action('setFilter'), done: action('done'), onDestroy: action('onDestroy'), reload: action('reload'), @@ -38,7 +28,7 @@ export const defaultHandlers: RendererHandlers = { interface RenderAdditionalProps { height?: string; width?: string; - handlers?: RendererHandlers; + handlers?: IInterpreterRenderHandlers; } export const Render = ({ diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx index 55dcc2cad256f..0fdc0c0691f23 100644 --- a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -7,13 +7,13 @@ */ import React, { useRef, useState, useEffect, useCallback } from 'react'; +import { IInterpreterRenderHandlers } from 'src/plugins/expressions'; import { NodeDimensions, RevealImageRendererConfig, Origin } from '../expression_renderers/types'; -import { RendererHandlers } from '../../common/types'; import { isValidUrl } from '../../common/lib/url'; import { elasticOutline } from '../../common/lib/elastic_outline'; interface RevealImageComponentProps extends RevealImageRendererConfig { - handlers: RendererHandlers; + handlers: IInterpreterRenderHandlers; parentNode: HTMLElement; } @@ -47,7 +47,7 @@ function RevealImageComponent({ parentNode.className = 'revealImage'; // set up the overlay image - const onLoad = useCallback(() => { + const updateImageView = useCallback(() => { if (imgRef.current) { setDimensions({ height: imgRef.current.naturalHeight, @@ -60,11 +60,11 @@ function RevealImageComponent({ }, [imgRef, handlers]); useEffect(() => { - handlers.onResize?.(onLoad); + handlers.event({ name: 'onResize', data: updateImageView }); return () => { - handlers.destroy?.(); + handlers.event({ name: 'destroy' }); }; - }, [onLoad, handlers]); + }, [handlers, updateImageView]); function getClipPath(percentParam: number, originParam: Origin = 'bottom') { const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; @@ -120,7 +120,7 @@ function RevealImageComponent({
{ handlers.onDestroy(() => { unmountComponentAtNode(domNode); From b4eaa1bee9b267699400ca33affb5854e7134cde Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 14:37:57 +0300 Subject: [PATCH 41/77] fixed supported_shareable. --- src/plugins/expression_reveal_image/public/index.ts | 3 +++ x-pack/plugins/canvas/kibana.json | 6 +++--- x-pack/plugins/canvas/public/plugin.tsx | 2 -- .../__mocks__/supported_renderers.js | 4 ---- .../canvas/shareable_runtime/components/app.tsx | 4 ++-- .../shareable_runtime/supported_renderers.d.ts | 7 +------ .../canvas/shareable_runtime/supported_renderers.js | 12 +++--------- .../canvas/shareable_runtime/test/context.tsx | 4 ++-- 8 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/plugins/expression_reveal_image/public/index.ts b/src/plugins/expression_reveal_image/public/index.ts index b86c356974321..3c3c4e8804012 100755 --- a/src/plugins/expression_reveal_image/public/index.ts +++ b/src/plugins/expression_reveal_image/public/index.ts @@ -13,3 +13,6 @@ export type { ExpressionRevealImagePluginSetup, ExpressionRevealImagePluginStart export function plugin() { return new ExpressionRevealImagePlugin(); } + +export * from './expression_functions'; +export * from './expression_renderers'; diff --git a/x-pack/plugins/canvas/kibana.json b/x-pack/plugins/canvas/kibana.json index b332740151297..22c8d4e0d2ab4 100644 --- a/x-pack/plugins/canvas/kibana.json +++ b/x-pack/plugins/canvas/kibana.json @@ -14,13 +14,13 @@ "features", "inspector", "presentationUtil", - "uiActions" + "uiActions", + "expressionRevealImage" ], "optionalPlugins": [ "home", "reporting", - "usageCollection", - "expressionRevealImage" + "usageCollection" ], "requiredBundles": [ "discover", diff --git a/x-pack/plugins/canvas/public/plugin.tsx b/x-pack/plugins/canvas/public/plugin.tsx index 99aed6dfe57de..081e6c9fc9880 100644 --- a/x-pack/plugins/canvas/public/plugin.tsx +++ b/x-pack/plugins/canvas/public/plugin.tsx @@ -32,7 +32,6 @@ import { BfetchPublicSetup } from '../../../../src/plugins/bfetch/public'; import { PresentationUtilPluginStart } from '../../../../src/plugins/presentation_util/public'; import { getPluginApi, CanvasApi } from './plugin_api'; import { CanvasSrcPlugin } from '../canvas_plugin_src/plugin'; -import { addSupportedRenderFunctions } from '../shareable_runtime/supported_renderers'; export { CoreStart, CoreSetup }; @@ -135,7 +134,6 @@ export class CanvasPlugin canvasApi.addElements(elements); canvasApi.addRenderers(renderers); canvasApi.addViewUIs(uiViews); - addSupportedRenderFunctions(renderers); }); canvasApi.addArgumentUIs(async () => { diff --git a/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js index b47e3b2b84304..c01b1b3f23543 100644 --- a/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/__mocks__/supported_renderers.js @@ -37,7 +37,3 @@ export const renderFunctions = renderers.map((fn) => () => ({ ReactDOM.render(
{fn} mock
, domNode); }, })); - -export const getSupportedRenderFunctions = () => { - return renderFunctions; -}; diff --git a/x-pack/plugins/canvas/shareable_runtime/components/app.tsx b/x-pack/plugins/canvas/shareable_runtime/components/app.tsx index 5784310e8e488..35c40168cbea4 100644 --- a/x-pack/plugins/canvas/shareable_runtime/components/app.tsx +++ b/x-pack/plugins/canvas/shareable_runtime/components/app.tsx @@ -10,7 +10,7 @@ import { CanvasRenderedWorkpad, CanvasShareableState, Stage } from '../types'; import { RendererSpec } from '../../types'; import { initialCanvasShareableState, CanvasShareableStateProvider } from '../context'; import { Canvas } from './canvas'; -import { getSupportedRenderFunctions } from '../supported_renderers'; +import { renderFunctions } from '../supported_renderers'; interface Props { /** @@ -30,7 +30,7 @@ interface Props { export const App: FC = ({ workpad, stage }) => { const renderers: { [key: string]: RendererSpec } = {}; - getSupportedRenderFunctions().forEach((fn) => { + renderFunctions.forEach((fn) => { const func = fn(); renderers[func.name] = func; }); diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts index c9934c3feef23..0ad36b1b7166a 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.d.ts @@ -5,12 +5,7 @@ * 2.0. */ -import { ExpressionRenderDefinition } from '../../../../src/plugins/expressions/public'; - import { RendererFactory } from '../types'; +export const renderFunctions: RendererFactory[]; export const renderFunctionNames: string[]; -export const addSupportedRenderFunctions: ( - renderers: RendererFactory[] | Array<() => ExpressionRenderDefinition> -) => void; -export function getSupportedRenderFunctions(): RendererFactory[]; diff --git a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js index 305aecc40e0f3..60987e987f63a 100644 --- a/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js +++ b/x-pack/plugins/canvas/shareable_runtime/supported_renderers.js @@ -17,17 +17,19 @@ import { progress } from '../canvas_plugin_src/renderers/progress'; import { shape } from '../canvas_plugin_src/renderers/shape'; import { table } from '../canvas_plugin_src/renderers/table'; import { text } from '../canvas_plugin_src/renderers/text'; +import { revealImageRenderer as revealImage } from '../../../../src/plugins/expression_reveal_image/public'; /** * This is a collection of renderers which are bundled with the runtime. If * a renderer is not listed here, but is used by the Shared Workpad, it will * not render. This includes any plugins. */ -let renderFunctions = [ +export const renderFunctions = [ debug, error, image, repeatImage, + revealImage, markdown, metric, pie, @@ -38,12 +40,4 @@ let renderFunctions = [ text, ]; -// this method is for usage on setup step of plugin only -export const addSupportedRenderFunctions = (renderers = []) => - (renderFunctions = [...renderFunctions, ...renderers]); - -export function getSupportedRenderFunctions() { - return renderFunctions; -} - export const renderFunctionNames = renderFunctions.map((fn) => fn.name); diff --git a/x-pack/plugins/canvas/shareable_runtime/test/context.tsx b/x-pack/plugins/canvas/shareable_runtime/test/context.tsx index a9543a889bdf8..394a666599bc6 100644 --- a/x-pack/plugins/canvas/shareable_runtime/test/context.tsx +++ b/x-pack/plugins/canvas/shareable_runtime/test/context.tsx @@ -11,7 +11,7 @@ import { CanvasShareableStateProvider, useCanvasShareableState, } from '../context/index'; -import { getSupportedRenderFunctions } from '../supported_renderers'; +import { renderFunctions } from '../supported_renderers'; import { CanvasShareableState } from '../types'; import { RendererSpec } from '../../types'; import { sharedWorkpads, WorkpadNames } from '.'; @@ -60,7 +60,7 @@ export const Context = ({ }: Props) => { const renderers: { [key: string]: RendererSpec } = {}; - getSupportedRenderFunctions().forEach((rendererFn) => { + renderFunctions.forEach((rendererFn) => { const renderer = rendererFn(); renderers[renderer.name] = renderer; }); From d552813058b0314f75f8dc66138e622f3960288e Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 14:49:03 +0300 Subject: [PATCH 42/77] Moved elements back to canvas. --- .../common/i18n/elements/dict/index.ts | 9 -------- .../common/i18n/elements/dict/reveal_image.ts | 18 --------------- .../common/i18n/elements/index.ts | 22 ------------------- .../common/i18n/index.ts | 1 - .../common/lib/translate_elements.ts | 22 ------------------- .../public/elements/index.ts | 13 ----------- .../public/services/expression_service.ts | 4 +--- .../canvas_plugin_src/elements/index.ts | 2 ++ .../elements/reveal_image/index.ts | 9 ++++---- .../canvas/i18n/elements/element_strings.ts | 8 +++++++ x-pack/plugins/canvas/public/plugin.tsx | 3 +-- 11 files changed, 16 insertions(+), 95 deletions(-) delete mode 100644 src/plugins/expression_reveal_image/common/i18n/elements/dict/index.ts delete mode 100644 src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts delete mode 100644 src/plugins/expression_reveal_image/common/i18n/elements/index.ts delete mode 100644 src/plugins/expression_reveal_image/common/lib/translate_elements.ts delete mode 100644 src/plugins/expression_reveal_image/public/elements/index.ts rename src/plugins/expression_reveal_image/public/elements/reveal_image_element.ts => x-pack/plugins/canvas/canvas_plugin_src/elements/reveal_image/index.ts (58%) diff --git a/src/plugins/expression_reveal_image/common/i18n/elements/dict/index.ts b/src/plugins/expression_reveal_image/common/i18n/elements/dict/index.ts deleted file mode 100644 index 4f70f9d30b74b..0000000000000 --- a/src/plugins/expression_reveal_image/common/i18n/elements/dict/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export { strings as revealImage } from './reveal_image'; diff --git a/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts deleted file mode 100644 index c1ead2dfd75d8..0000000000000 --- a/src/plugins/expression_reveal_image/common/i18n/elements/dict/reveal_image.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { i18n } from '@kbn/i18n'; -import { ElementStrings } from '../../../types'; - -export const strings: ElementStrings = { - displayName: i18n.translate('expressionRevealImage.elements.revealImageDisplayName', { - defaultMessage: 'Image reveal', - }), - help: i18n.translate('expressionRevealImage.elements.revealImageHelpText', { - defaultMessage: 'Reveals a percentage of an image', - }), -}; diff --git a/src/plugins/expression_reveal_image/common/i18n/elements/index.ts b/src/plugins/expression_reveal_image/common/i18n/elements/index.ts deleted file mode 100644 index 17cc64753b912..0000000000000 --- a/src/plugins/expression_reveal_image/common/i18n/elements/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { ElementStringDict } from '../../types'; -import { revealImage } from './dict'; - -/** - * Help text for Canvas Functions should be properly localized. This function will - * return a dictionary of help strings, organized by `ExpressionFunctionDefinition` - * specification and then by available arguments within each `ExpressionFunctionDefinition`. - * - * This a function, rather than an object, to future-proof string initialization, - * if ever necessary. - */ -export const getElementsStrings = (): ElementStringDict => ({ - revealImage, -}); diff --git a/src/plugins/expression_reveal_image/common/i18n/index.ts b/src/plugins/expression_reveal_image/common/i18n/index.ts index 4ff6b6bed9cbc..c93d89054b5b2 100644 --- a/src/plugins/expression_reveal_image/common/i18n/index.ts +++ b/src/plugins/expression_reveal_image/common/i18n/index.ts @@ -8,5 +8,4 @@ export * from './expression_functions'; export * from './expression_renderers'; -export * from './elements'; export * from './ui'; diff --git a/src/plugins/expression_reveal_image/common/lib/translate_elements.ts b/src/plugins/expression_reveal_image/common/lib/translate_elements.ts deleted file mode 100644 index 3e86180f9d6e1..0000000000000 --- a/src/plugins/expression_reveal_image/common/lib/translate_elements.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { ElementFactory } from '../types'; -import { getElementsStrings } from '../i18n'; - -export function translateElements(elements: ElementFactory[] = []) { - const strings = getElementsStrings(); - return elements.map((elFactory) => { - const element = elFactory(); - const { name } = element; - const elementStrings = strings[name] ?? {}; - element.displayName = elementStrings.displayName ?? element.displayName; - element.help = elementStrings.help ?? element.help; - - return () => element; - }); -} diff --git a/src/plugins/expression_reveal_image/public/elements/index.ts b/src/plugins/expression_reveal_image/public/elements/index.ts deleted file mode 100644 index a0d988c2f1afe..0000000000000 --- a/src/plugins/expression_reveal_image/public/elements/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { translateElements } from '../../common/lib/translate_elements'; -import { revealImageElement } from './reveal_image_element'; - -export const elements = translateElements([revealImageElement]); - -export { revealImageElement }; diff --git a/src/plugins/expression_reveal_image/public/services/expression_service.ts b/src/plugins/expression_reveal_image/public/services/expression_service.ts index 83941dbfe5b12..bd4c977a7adf5 100644 --- a/src/plugins/expression_reveal_image/public/services/expression_service.ts +++ b/src/plugins/expression_reveal_image/public/services/expression_service.ts @@ -12,7 +12,6 @@ import { StartInitializer, ExpressionRevealImageFunction, } from '../../common/types'; -import { elements } from '../elements'; import { renderers } from '../expression_renderers'; import { functions } from '../expression_functions'; import { uiViews } from '../ui_views'; @@ -21,7 +20,6 @@ import { RevealImageRendererConfig } from '../expression_renderers/types'; export type ExpressionServiceSetup = Pick; export interface ExpressionSetup { - elements: ElementFactory[]; renderers: Array<() => ExpressionRenderDefinition>; uiViews: Array>; functions: ExpressionRevealImageFunction[]; @@ -34,7 +32,7 @@ export class ExpressionService { fn ) => { if (fn && typeof fn === 'function') { - fn({ elements, renderers, uiViews, functions }); + fn({ renderers, uiViews, functions }); } }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/elements/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/elements/index.ts index 6c684cfb92157..4925849045216 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/elements/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/elements/index.ts @@ -24,6 +24,7 @@ import { progressGauge } from './progress_gauge'; import { progressSemicircle } from './progress_semicircle'; import { progressWheel } from './progress_wheel'; import { repeatImage } from './repeat_image'; +import { revealImage } from './reveal_image'; import { shape } from './shape'; import { table } from './table'; import { timeFilter } from './time_filter'; @@ -52,6 +53,7 @@ const elementSpecs = [ progressSemicircle, progressWheel, repeatImage, + revealImage, shape, table, timeFilter, diff --git a/src/plugins/expression_reveal_image/public/elements/reveal_image_element.ts b/x-pack/plugins/canvas/canvas_plugin_src/elements/reveal_image/index.ts similarity index 58% rename from src/plugins/expression_reveal_image/public/elements/reveal_image_element.ts rename to x-pack/plugins/canvas/canvas_plugin_src/elements/reveal_image/index.ts index 5d18105ea87fc..91e35867f76d5 100644 --- a/src/plugins/expression_reveal_image/public/elements/reveal_image_element.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/elements/reveal_image/index.ts @@ -1,14 +1,13 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. */ -import { ElementFactory } from '../../common/types'; +import { ElementFactory } from '../../../types'; -export const revealImageElement: ElementFactory = () => ({ +export const revealImage: ElementFactory = () => ({ name: 'revealImage', displayName: 'Image reveal', type: 'image', diff --git a/x-pack/plugins/canvas/i18n/elements/element_strings.ts b/x-pack/plugins/canvas/i18n/elements/element_strings.ts index e5128721d643b..87879c4c753c9 100644 --- a/x-pack/plugins/canvas/i18n/elements/element_strings.ts +++ b/x-pack/plugins/canvas/i18n/elements/element_strings.ts @@ -166,6 +166,14 @@ export const getElementStrings = (): ElementStringDict => ({ defaultMessage: 'Repeats an image N times', }), }, + revealImage: { + displayName: i18n.translate('xpack.canvas.elements.revealImageDisplayName', { + defaultMessage: 'Image reveal', + }), + help: i18n.translate('xpack.canvas.elements.revealImageHelpText', { + defaultMessage: 'Reveals a percentage of an image', + }), + }, shape: { displayName: i18n.translate('xpack.canvas.elements.shapeDisplayName', { defaultMessage: 'Shape', diff --git a/x-pack/plugins/canvas/public/plugin.tsx b/x-pack/plugins/canvas/public/plugin.tsx index 081e6c9fc9880..2e34d28074a1f 100644 --- a/x-pack/plugins/canvas/public/plugin.tsx +++ b/x-pack/plugins/canvas/public/plugin.tsx @@ -130,8 +130,7 @@ export class CanvasPlugin plugins.home.featureCatalogue.register(featureCatalogueEntry); } - plugins.expressionRevealImage?.registerExpression(({ elements, renderers, uiViews }) => { - canvasApi.addElements(elements); + plugins.expressionRevealImage?.registerExpression(({ renderers, uiViews }) => { canvasApi.addRenderers(renderers); canvasApi.addViewUIs(uiViews); }); From 596a027c56472929337fc5469a8e699aee8c00b0 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 15:13:50 +0300 Subject: [PATCH 43/77] Moved views to canvas, removed expression service and imported renderer to canvas. --- .../common/i18n/index.ts | 1 - .../common/i18n/ui/dict/index.ts | 9 --- .../common/i18n/ui/dict/reveal_image.ts | 55 ------------------- .../common/i18n/ui/index.ts | 21 ------- .../common/types/dict.ts | 16 ------ .../common/types/elements.ts | 20 ------- .../types/expression_renderers.ts} | 0 .../common/types/index.ts | 4 +- .../common/types/ui_views.ts | 10 ---- .../reveal_image_renderer.tsx | 2 +- .../expression_reveal_image/public/plugin.ts | 15 +---- .../public/services/expression_service.ts | 49 ----------------- .../public/services/index.ts | 9 --- .../public/ui_views/index.ts | 13 ----- .../canvas_plugin_src/renderers/external.ts | 11 ++++ .../canvas_plugin_src/renderers/index.ts | 14 ++++- .../canvas_plugin_src/uis/views/index.ts | 3 + .../uis/views/revealImage.js | 12 ++-- x-pack/plugins/canvas/public/plugin.tsx | 5 -- 19 files changed, 37 insertions(+), 232 deletions(-) delete mode 100644 src/plugins/expression_reveal_image/common/i18n/ui/dict/index.ts delete mode 100644 src/plugins/expression_reveal_image/common/i18n/ui/dict/reveal_image.ts delete mode 100644 src/plugins/expression_reveal_image/common/i18n/ui/index.ts delete mode 100644 src/plugins/expression_reveal_image/common/types/dict.ts delete mode 100644 src/plugins/expression_reveal_image/common/types/elements.ts rename src/plugins/expression_reveal_image/{public/expression_renderers/types.ts => common/types/expression_renderers.ts} (100%) delete mode 100644 src/plugins/expression_reveal_image/common/types/ui_views.ts delete mode 100644 src/plugins/expression_reveal_image/public/services/expression_service.ts delete mode 100644 src/plugins/expression_reveal_image/public/services/index.ts delete mode 100644 src/plugins/expression_reveal_image/public/ui_views/index.ts create mode 100644 x-pack/plugins/canvas/canvas_plugin_src/renderers/external.ts rename src/plugins/expression_reveal_image/public/ui_views/reveal_image_ui_view.ts => x-pack/plugins/canvas/canvas_plugin_src/uis/views/revealImage.js (71%) diff --git a/src/plugins/expression_reveal_image/common/i18n/index.ts b/src/plugins/expression_reveal_image/common/i18n/index.ts index c93d89054b5b2..9c50bfab1305d 100644 --- a/src/plugins/expression_reveal_image/common/i18n/index.ts +++ b/src/plugins/expression_reveal_image/common/i18n/index.ts @@ -8,4 +8,3 @@ export * from './expression_functions'; export * from './expression_renderers'; -export * from './ui'; diff --git a/src/plugins/expression_reveal_image/common/i18n/ui/dict/index.ts b/src/plugins/expression_reveal_image/common/i18n/ui/dict/index.ts deleted file mode 100644 index 4f70f9d30b74b..0000000000000 --- a/src/plugins/expression_reveal_image/common/i18n/ui/dict/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export { strings as revealImage } from './reveal_image'; diff --git a/src/plugins/expression_reveal_image/common/i18n/ui/dict/reveal_image.ts b/src/plugins/expression_reveal_image/common/i18n/ui/dict/reveal_image.ts deleted file mode 100644 index 4a4d65533cbae..0000000000000 --- a/src/plugins/expression_reveal_image/common/i18n/ui/dict/reveal_image.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { i18n } from '@kbn/i18n'; - -export const strings = { - getDisplayName: () => - i18n.translate('expressionRevealImage.uis.views.revealImageTitle', { - defaultMessage: 'Reveal image', - }), - getEmptyImageDisplayName: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.emptyImageTitle', { - defaultMessage: 'Background image', - }), - getEmptyImageHelp: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.emptyImageLabel', { - defaultMessage: 'A background image. Eg, an empty glass', - }), - getImageDisplayName: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.imageTitle', { - defaultMessage: 'Image', - }), - getImageHelp: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.imageLabel', { - defaultMessage: 'An image to reveal given the function input. Eg, a full glass', - }), - getOriginBottom: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.origin.bottomDropDown', { - defaultMessage: 'Bottom', - }), - getOriginDisplayName: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.originTitle', { - defaultMessage: 'Reveal from', - }), - getOriginHelp: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.originLabel', { - defaultMessage: 'The direction from which to start the reveal', - }), - getOriginLeft: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.origin.leftDropDown', { - defaultMessage: 'Left', - }), - getOriginRight: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.origin.rightDropDown', { - defaultMessage: 'Right', - }), - getOriginTop: () => - i18n.translate('expressionRevealImage.uis.views.revealImage.args.origin.topDropDown', { - defaultMessage: 'Top', - }), -}; diff --git a/src/plugins/expression_reveal_image/common/i18n/ui/index.ts b/src/plugins/expression_reveal_image/common/i18n/ui/index.ts deleted file mode 100644 index 31f2231d1f64d..0000000000000 --- a/src/plugins/expression_reveal_image/common/i18n/ui/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { revealImage } from './dict'; - -/** - * Help text for Canvas Functions should be properly localized. This function will - * return a dictionary of help strings, organized by `ExpressionFunctionDefinition` - * specification and then by available arguments within each `ExpressionFunctionDefinition`. - * - * This a function, rather than an object, to future-proof string initialization, - * if ever necessary. - */ -export const getUIStrings = () => ({ - revealImage, -}); diff --git a/src/plugins/expression_reveal_image/common/types/dict.ts b/src/plugins/expression_reveal_image/common/types/dict.ts deleted file mode 100644 index 66303caabb827..0000000000000 --- a/src/plugins/expression_reveal_image/common/types/dict.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export interface ElementStrings { - displayName: string; - help: string; -} - -export interface ElementStringDict { - [elementName: string]: ElementStrings; -} diff --git a/src/plugins/expression_reveal_image/common/types/elements.ts b/src/plugins/expression_reveal_image/common/types/elements.ts deleted file mode 100644 index 7c7aaf98ed199..0000000000000 --- a/src/plugins/expression_reveal_image/common/types/elements.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -export interface ElementSpec { - name: string; - icon?: string; - expression: string; - displayName?: string; - type?: string; - help?: string; - filter?: string; - width?: number; - height?: number; -} - -export type ElementFactory = () => ElementSpec; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/types.ts b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts similarity index 100% rename from src/plugins/expression_reveal_image/public/expression_renderers/types.ts rename to src/plugins/expression_reveal_image/common/types/expression_renderers.ts diff --git a/src/plugins/expression_reveal_image/common/types/index.ts b/src/plugins/expression_reveal_image/common/types/index.ts index e21c6e33b6a91..ec934e7affe88 100644 --- a/src/plugins/expression_reveal_image/common/types/index.ts +++ b/src/plugins/expression_reveal_image/common/types/index.ts @@ -6,6 +6,4 @@ * Side Public License, v 1. */ export * from './expression_functions'; -export * from './elements'; -export * from './ui_views'; -export * from './dict'; +export * from './expression_renderers'; diff --git a/src/plugins/expression_reveal_image/common/types/ui_views.ts b/src/plugins/expression_reveal_image/common/types/ui_views.ts deleted file mode 100644 index d4c48d2afb262..0000000000000 --- a/src/plugins/expression_reveal_image/common/types/ui_views.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -import { CoreStart } from 'src/core/public'; - -export type StartInitializer = (core: CoreStart, plugins: unknown) => T; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx index 6f27e29842547..0ca4337e43deb 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx @@ -10,7 +10,7 @@ import { render, unmountComponentAtNode } from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; import { ExpressionRenderDefinition, IInterpreterRenderHandlers } from 'src/plugins/expressions'; import { getRendererStrings } from '../../common/i18n'; -import { RevealImageRendererConfig } from './types'; +import { RevealImageRendererConfig } from '../../common/types'; import { RendererWrapper } from '../components/renderer_wrapper'; import './reveal_image.scss'; diff --git a/src/plugins/expression_reveal_image/public/plugin.ts b/src/plugins/expression_reveal_image/public/plugin.ts index 1ec63d92b25b3..5424faa3aacdb 100755 --- a/src/plugins/expression_reveal_image/public/plugin.ts +++ b/src/plugins/expression_reveal_image/public/plugin.ts @@ -10,7 +10,6 @@ import { CoreSetup, CoreStart, Plugin } from '../../../core/public'; import { ExpressionsStart, ExpressionsSetup } from '../../expressions/public'; import { revealImageFunction } from './expression_functions'; import { revealImageRenderer } from './expression_renderers'; -import { ExpressionService, ExpressionServiceSetup, ExpressionServiceStart } from './services'; interface SetupDeps { expressions: ExpressionsSetup; @@ -20,8 +19,8 @@ interface StartDeps { expression: ExpressionsStart; } -export type ExpressionRevealImagePluginSetup = ExpressionServiceSetup; -export type ExpressionRevealImagePluginStart = ExpressionServiceStart; +export type ExpressionRevealImagePluginSetup = void; +export type ExpressionRevealImagePluginStart = void; export class ExpressionRevealImagePlugin implements @@ -31,20 +30,12 @@ export class ExpressionRevealImagePlugin SetupDeps, StartDeps > { - private readonly expressionService: ExpressionService = new ExpressionService(); - public setup(core: CoreSetup, { expressions }: SetupDeps): ExpressionRevealImagePluginSetup { expressions.registerFunction(revealImageFunction); expressions.registerRenderer(revealImageRenderer); - - const setup = { ...this.expressionService.setup() }; - - return Object.freeze(setup); } public start(core: CoreStart): ExpressionRevealImagePluginStart {} - public stop() { - this.expressionService.stop(); - } + public stop() {} } diff --git a/src/plugins/expression_reveal_image/public/services/expression_service.ts b/src/plugins/expression_reveal_image/public/services/expression_service.ts deleted file mode 100644 index bd4c977a7adf5..0000000000000 --- a/src/plugins/expression_reveal_image/public/services/expression_service.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { ExpressionRenderDefinition } from 'src/plugins/expressions'; -import { - ElementFactory, - StartInitializer, - ExpressionRevealImageFunction, -} from '../../common/types'; -import { renderers } from '../expression_renderers'; -import { functions } from '../expression_functions'; -import { uiViews } from '../ui_views'; -import { RevealImageRendererConfig } from '../expression_renderers/types'; - -export type ExpressionServiceSetup = Pick; - -export interface ExpressionSetup { - renderers: Array<() => ExpressionRenderDefinition>; - uiViews: Array>; - functions: ExpressionRevealImageFunction[]; -} - -export type ExpressionServiceStart = void; - -export class ExpressionService { - public readonly registerExpression: (fn?: (expressions: ExpressionSetup) => void) => void = ( - fn - ) => { - if (fn && typeof fn === 'function') { - fn({ renderers, uiViews, functions }); - } - }; - - public setup(): ExpressionServiceSetup { - const { registerExpression } = this; - return Object.freeze({ - registerExpression, - }); - } - - public start(): ExpressionServiceStart {} - - public stop() {} -} diff --git a/src/plugins/expression_reveal_image/public/services/index.ts b/src/plugins/expression_reveal_image/public/services/index.ts deleted file mode 100644 index b0480efcc975f..0000000000000 --- a/src/plugins/expression_reveal_image/public/services/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export * from './expression_service'; diff --git a/src/plugins/expression_reveal_image/public/ui_views/index.ts b/src/plugins/expression_reveal_image/public/ui_views/index.ts deleted file mode 100644 index ba2d19308b797..0000000000000 --- a/src/plugins/expression_reveal_image/public/ui_views/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { revealImageUIView } from './reveal_image_ui_view'; - -export const uiViews = [revealImageUIView]; - -export { revealImageUIView }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/external.ts b/x-pack/plugins/canvas/canvas_plugin_src/renderers/external.ts new file mode 100644 index 0000000000000..bf9b6a744e686 --- /dev/null +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/external.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { revealImageRenderer } from '../../../../../src/plugins/expression_reveal_image/public'; + +export const renderFunctions = [revealImageRenderer]; +export const renderFunctionFactories = []; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/renderers/index.ts index 3c2d90f81eedc..16a052edbbe82 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/index.ts @@ -15,11 +15,23 @@ import { renderFunctionFactories as filterFactories, } from './filters'; +import { + renderFunctions as externalFunctions, + renderFunctionFactories as externalFactories, +} from './external'; + import { renderFunctions as coreFunctions, renderFunctionFactories as coreFactories } from './core'; -export const renderFunctions = [...coreFunctions, ...filterFunctions, ...embeddableFunctions]; +export const renderFunctions = [ + ...coreFunctions, + ...filterFunctions, + ...embeddableFunctions, + ...externalFunctions, +]; + export const renderFunctionFactories = [ ...coreFactories, ...embeddableFactories, ...filterFactories, + ...externalFactories, ]; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/index.ts index 045bb15e17ece..ed8428f0203ca 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/index.ts @@ -23,6 +23,8 @@ import { progress } from './progress'; // @ts-expect-error untyped local import { repeatImage } from './repeatImage'; // @ts-expect-error untyped local +import { revealImage } from './revealImage'; +// @ts-expect-error untyped local import { render } from './render'; // @ts-expect-error untyped local import { shape } from './shape'; @@ -42,6 +44,7 @@ export const viewSpecs = [ plot, progress, repeatImage, + revealImage, render, shape, table, diff --git a/src/plugins/expression_reveal_image/public/ui_views/reveal_image_ui_view.ts b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/revealImage.js similarity index 71% rename from src/plugins/expression_reveal_image/public/ui_views/reveal_image_ui_view.ts rename to x-pack/plugins/canvas/canvas_plugin_src/uis/views/revealImage.js index 82ffab2ef4f4e..f9bba68c56949 100644 --- a/src/plugins/expression_reveal_image/public/ui_views/reveal_image_ui_view.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/revealImage.js @@ -1,16 +1,14 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. */ -import { getUIStrings } from '../../common/i18n'; -import { StartInitializer } from '../../common/types'; -const { revealImage: strings } = getUIStrings(); +import { ViewStrings } from '../../../i18n'; +const { RevealImage: strings } = ViewStrings; -export const revealImageUIView: StartInitializer = () => ({ +export const revealImage = () => ({ name: 'revealImage', displayName: strings.getDisplayName(), modelArgs: [['_', { label: 'Value' }]], diff --git a/x-pack/plugins/canvas/public/plugin.tsx b/x-pack/plugins/canvas/public/plugin.tsx index 2e34d28074a1f..c12a436e12beb 100644 --- a/x-pack/plugins/canvas/public/plugin.tsx +++ b/x-pack/plugins/canvas/public/plugin.tsx @@ -130,11 +130,6 @@ export class CanvasPlugin plugins.home.featureCatalogue.register(featureCatalogueEntry); } - plugins.expressionRevealImage?.registerExpression(({ renderers, uiViews }) => { - canvasApi.addRenderers(renderers); - canvasApi.addViewUIs(uiViews); - }); - canvasApi.addArgumentUIs(async () => { // @ts-expect-error const { argTypeSpecs } = await import('./expression_types/arg_types'); From 40af51254b77154bbc41eb5a40e396513f7d1bad Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 15:16:44 +0300 Subject: [PATCH 44/77] Fixed translations. --- x-pack/plugins/translations/translations/ja-JP.json | 4 ++-- x-pack/plugins/translations/translations/zh-CN.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 27ac5128663b2..1ae150300f3fd 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -6081,8 +6081,8 @@ "xpack.canvas.elements.progressWheelHelpText": "進捗状況をホイールで表示します", "xpack.canvas.elements.repeatImageDisplayName": "画像の繰り返し", "xpack.canvas.elements.repeatImageHelpText": "画像を N 回繰り返します", - "expressionRevealImage.elements.revealImageDisplayName": "画像の部分表示", - "expressionRevealImage.elements.revealImageHelpText": "画像のパーセンテージを表示します", + "xpack.canvas.elements.revealImageDisplayName": "画像の部分表示", + "xpack.canvas.elements.revealImageHelpText": "画像のパーセンテージを表示します", "xpack.canvas.elements.shapeDisplayName": "形状", "xpack.canvas.elements.shapeHelpText": "カスタマイズ可能な図形です", "xpack.canvas.elements.tableDisplayName": "データテーブル", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index a2c761c6b2eac..63a8f071cb156 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -6120,8 +6120,8 @@ "xpack.canvas.elements.progressWheelHelpText": "将进度显示为轮盘的一部分", "xpack.canvas.elements.repeatImageDisplayName": "图像重复", "xpack.canvas.elements.repeatImageHelpText": "使图像重复 N 次", - "expressionRevealImage.elements.revealImageDisplayName": "图像显示", - "expressionRevealImage.elements.revealImageHelpText": "显示图像特定百分比", + "xpack.canvas.elements.revealImageDisplayName": "图像显示", + "xpack.canvas.elements.revealImageHelpText": "显示图像特定百分比", "xpack.canvas.elements.shapeDisplayName": "形状", "xpack.canvas.elements.shapeHelpText": "可定制的形状", "xpack.canvas.elements.tableDisplayName": "数据表", From 6ba2baac78a0cf2eeb27db421464484929a42212 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 15:45:50 +0300 Subject: [PATCH 45/77] Types fix. --- .../common/types/expression_renderers.ts | 4 ++-- .../public/components/reveal_image_component.tsx | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts index a1c4aaff038e8..2162b025d7596 100644 --- a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts +++ b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts @@ -6,10 +6,10 @@ * Side Public License, v 1. */ -export type Origin = 'bottom' | 'left' | 'top' | 'right'; +export type OriginString = 'bottom' | 'left' | 'top' | 'right'; export interface RevealImageRendererConfig { percent: number; - origin?: Origin; + origin?: OriginString; image?: string; emptyImage?: string; } diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx index 0fdc0c0691f23..b292b54b42541 100644 --- a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -8,7 +8,7 @@ import React, { useRef, useState, useEffect, useCallback } from 'react'; import { IInterpreterRenderHandlers } from 'src/plugins/expressions'; -import { NodeDimensions, RevealImageRendererConfig, Origin } from '../expression_renderers/types'; +import { NodeDimensions, RevealImageRendererConfig, OriginString } from '../../common/types'; import { isValidUrl } from '../../common/lib/url'; import { elasticOutline } from '../../common/lib/elastic_outline'; @@ -66,8 +66,8 @@ function RevealImageComponent({ }; }, [handlers, updateImageView]); - function getClipPath(percentParam: number, originParam: Origin = 'bottom') { - const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; + function getClipPath(percentParam: number, originParam: OriginString = 'bottom') { + const directions: Record = { bottom: 0, left: 1, top: 2, right: 3 }; const values: Array = [0, 0, 0, 0]; values[directions[originParam]] = `${100 - percentParam * 100}%`; return `inset(${values.join(' ')})`; From 899482832259514f5d4a212355485833143e54df Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 16:46:17 +0300 Subject: [PATCH 46/77] Moved libs to presentation utils. --- .../expression_reveal_image/kibana.json | 2 +- .../public/components/renderer_wrapper.tsx | 24 ------------------- .../components/reveal_image_component.tsx | 3 +-- .../expression_functions/reveal_image.test.ts | 4 +--- .../reveal_image_function.ts | 3 +-- .../reveal_image_renderer.stories.tsx | 4 +--- .../reveal_image_renderer.tsx | 9 ++++--- .../expression_reveal_image/tsconfig.json | 1 + src/plugins/presentation_util/common/index.ts | 2 ++ .../common/lib/dataurl.test.ts | 0 .../common/lib/dataurl.ts | 0 .../common/lib/elastic_logo.ts | 0 .../common/lib/elastic_outline.ts | 0 .../common/lib/httpurl.test.ts | 0 .../common/lib/httpurl.ts | 0 .../presentation_util/common/lib/index.ts | 15 ++++++++++++ .../common/lib/missing_asset.ts | 0 .../common/lib/resolve_dataurl.test.ts | 0 .../common/lib/resolve_dataurl.ts | 0 .../common/lib/url.test.ts | 0 .../common/lib/url.ts | 0 .../common/test_helpers/function_wrapper.ts | 13 ++++++---- .../common/test_helpers/index.ts | 9 +++++++ .../public/__stories__/index.tsx | 0 .../public/__stories__/render.tsx | 0 src/plugins/presentation_util/public/index.ts | 4 ++++ 26 files changed, 49 insertions(+), 44 deletions(-) delete mode 100644 src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/dataurl.test.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/dataurl.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/elastic_logo.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/elastic_outline.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/httpurl.test.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/httpurl.ts (100%) create mode 100644 src/plugins/presentation_util/common/lib/index.ts rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/missing_asset.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/resolve_dataurl.test.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/resolve_dataurl.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/url.test.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/lib/url.ts (100%) rename src/plugins/{expression_reveal_image => presentation_util}/common/test_helpers/function_wrapper.ts (69%) create mode 100644 src/plugins/presentation_util/common/test_helpers/index.ts rename src/plugins/{expression_reveal_image => presentation_util}/public/__stories__/index.tsx (100%) rename src/plugins/{expression_reveal_image => presentation_util}/public/__stories__/render.tsx (100%) diff --git a/src/plugins/expression_reveal_image/kibana.json b/src/plugins/expression_reveal_image/kibana.json index b2579bd061e5d..5593ceb06a85c 100755 --- a/src/plugins/expression_reveal_image/kibana.json +++ b/src/plugins/expression_reveal_image/kibana.json @@ -4,7 +4,7 @@ "kibanaVersion": "kibana", "server": false, "ui": true, - "requiredPlugins": ["expressions"], + "requiredPlugins": ["expressions", "presentationUtil"], "optionalPlugins": [], "requiredBundles": [] } diff --git a/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx b/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx deleted file mode 100644 index 003d7643460d9..0000000000000 --- a/src/plugins/expression_reveal_image/public/components/renderer_wrapper.tsx +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import React from 'react'; -import { EuiDelayRender, EuiLoadingContent } from '@elastic/eui'; - -const Fallback = () => ( - - - -); - -interface RendererWrapperProps { - children: React.ReactNode; -} - -export function RendererWrapper({ children }: RendererWrapperProps) { - return }>{children}; -} diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx index b292b54b42541..14fb6cc73f6a0 100644 --- a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -9,8 +9,7 @@ import React, { useRef, useState, useEffect, useCallback } from 'react'; import { IInterpreterRenderHandlers } from 'src/plugins/expressions'; import { NodeDimensions, RevealImageRendererConfig, OriginString } from '../../common/types'; -import { isValidUrl } from '../../common/lib/url'; -import { elasticOutline } from '../../common/lib/elastic_outline'; +import { isValidUrl, elasticOutline } from '../../../presentation_util/public'; interface RevealImageComponentProps extends RevealImageRendererConfig { handlers: IInterpreterRenderHandlers; diff --git a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts index 83277d4a485f8..e34a1464104f0 100644 --- a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts +++ b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image.test.ts @@ -6,9 +6,7 @@ * Side Public License, v 1. */ -import { functionWrapper } from '../../common/test_helpers/function_wrapper'; -import { elasticOutline } from '../../common/lib/elastic_outline'; -import { elasticLogo } from '../../common/lib/elastic_logo'; +import { functionWrapper, elasticOutline, elasticLogo } from '../../../presentation_util/public'; import { getFunctionErrors } from '../../common/i18n'; import { revealImageFunction } from './reveal_image_function'; import { Origin } from '../../common/types/expression_functions'; diff --git a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts index 8aea1318c8764..786db903b1836 100644 --- a/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts +++ b/src/plugins/expression_reveal_image/public/expression_functions/reveal_image_function.ts @@ -6,8 +6,7 @@ * Side Public License, v 1. */ -import { resolveWithMissingImage } from '../../common/lib/resolve_dataurl'; -import { elasticOutline } from '../../common/lib/elastic_outline'; +import { resolveWithMissingImage, elasticOutline } from '../../../presentation_util/public'; import { getFunctionHelp, getFunctionErrors } from '../../common/i18n'; import { ExpressionRevealImageFunction, Origin } from '../../common/types'; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx index 550c7b1fb9ac2..822b996b2940f 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx @@ -9,9 +9,7 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { revealImageRenderer } from '../'; -import { Render } from '../../__stories__'; -import { elasticOutline } from '../../../common/lib/elastic_outline'; -import { elasticLogo } from '../../../common/lib/elastic_logo'; +import { Render, elasticOutline, elasticLogo } from '../../../../presentation_util/public'; import { Origin } from '../../../common/types/expression_functions'; import './reveal_image.scss'; diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx index 0ca4337e43deb..a3243db97cb9d 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx @@ -9,14 +9,15 @@ import React, { lazy } from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; import { ExpressionRenderDefinition, IInterpreterRenderHandlers } from 'src/plugins/expressions'; +import { withSuspense } from '../../../presentation_util/public'; import { getRendererStrings } from '../../common/i18n'; import { RevealImageRendererConfig } from '../../common/types'; -import { RendererWrapper } from '../components/renderer_wrapper'; import './reveal_image.scss'; const { revealImage: revealImageStrings } = getRendererStrings(); -const RevealImageComponent = lazy(() => import('../components/reveal_image_component')); +const LazyRevealImageComponent = lazy(() => import('../components/reveal_image_component')); +const RevealImageComponent = withSuspense(LazyRevealImageComponent, null); export const revealImageRenderer = (): ExpressionRenderDefinition => ({ name: 'revealImage', @@ -34,9 +35,7 @@ export const revealImageRenderer = (): ExpressionRenderDefinition - - - + , domNode ); diff --git a/src/plugins/expression_reveal_image/tsconfig.json b/src/plugins/expression_reveal_image/tsconfig.json index 09a6d24dd7839..aa4562ec73576 100644 --- a/src/plugins/expression_reveal_image/tsconfig.json +++ b/src/plugins/expression_reveal_image/tsconfig.json @@ -15,6 +15,7 @@ ], "references": [ { "path": "../../core/tsconfig.json" }, + { "path": "../presentation_util/tsconfig.json" }, { "path": "../expressions/tsconfig.json" }, ] } diff --git a/src/plugins/presentation_util/common/index.ts b/src/plugins/presentation_util/common/index.ts index bf8819b13a92d..5aa67da3d3416 100644 --- a/src/plugins/presentation_util/common/index.ts +++ b/src/plugins/presentation_util/common/index.ts @@ -10,3 +10,5 @@ export const PLUGIN_ID = 'presentationUtil'; export const PLUGIN_NAME = 'presentationUtil'; export * from './labs'; +export * from './lib'; +export * from './test_helpers'; diff --git a/src/plugins/expression_reveal_image/common/lib/dataurl.test.ts b/src/plugins/presentation_util/common/lib/dataurl.test.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/dataurl.test.ts rename to src/plugins/presentation_util/common/lib/dataurl.test.ts diff --git a/src/plugins/expression_reveal_image/common/lib/dataurl.ts b/src/plugins/presentation_util/common/lib/dataurl.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/dataurl.ts rename to src/plugins/presentation_util/common/lib/dataurl.ts diff --git a/src/plugins/expression_reveal_image/common/lib/elastic_logo.ts b/src/plugins/presentation_util/common/lib/elastic_logo.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/elastic_logo.ts rename to src/plugins/presentation_util/common/lib/elastic_logo.ts diff --git a/src/plugins/expression_reveal_image/common/lib/elastic_outline.ts b/src/plugins/presentation_util/common/lib/elastic_outline.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/elastic_outline.ts rename to src/plugins/presentation_util/common/lib/elastic_outline.ts diff --git a/src/plugins/expression_reveal_image/common/lib/httpurl.test.ts b/src/plugins/presentation_util/common/lib/httpurl.test.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/httpurl.test.ts rename to src/plugins/presentation_util/common/lib/httpurl.test.ts diff --git a/src/plugins/expression_reveal_image/common/lib/httpurl.ts b/src/plugins/presentation_util/common/lib/httpurl.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/httpurl.ts rename to src/plugins/presentation_util/common/lib/httpurl.ts diff --git a/src/plugins/presentation_util/common/lib/index.ts b/src/plugins/presentation_util/common/lib/index.ts new file mode 100644 index 0000000000000..eed4acf78b2be --- /dev/null +++ b/src/plugins/presentation_util/common/lib/index.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export * from './dataurl'; +export * from './elastic_logo'; +export * from './elastic_outline'; +export * from './httpurl'; +export * from './missing_asset'; +export * from './resolve_dataurl'; +export * from './url'; diff --git a/src/plugins/expression_reveal_image/common/lib/missing_asset.ts b/src/plugins/presentation_util/common/lib/missing_asset.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/missing_asset.ts rename to src/plugins/presentation_util/common/lib/missing_asset.ts diff --git a/src/plugins/expression_reveal_image/common/lib/resolve_dataurl.test.ts b/src/plugins/presentation_util/common/lib/resolve_dataurl.test.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/resolve_dataurl.test.ts rename to src/plugins/presentation_util/common/lib/resolve_dataurl.test.ts diff --git a/src/plugins/expression_reveal_image/common/lib/resolve_dataurl.ts b/src/plugins/presentation_util/common/lib/resolve_dataurl.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/resolve_dataurl.ts rename to src/plugins/presentation_util/common/lib/resolve_dataurl.ts diff --git a/src/plugins/expression_reveal_image/common/lib/url.test.ts b/src/plugins/presentation_util/common/lib/url.test.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/url.test.ts rename to src/plugins/presentation_util/common/lib/url.test.ts diff --git a/src/plugins/expression_reveal_image/common/lib/url.ts b/src/plugins/presentation_util/common/lib/url.ts similarity index 100% rename from src/plugins/expression_reveal_image/common/lib/url.ts rename to src/plugins/presentation_util/common/lib/url.ts diff --git a/src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts b/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts similarity index 69% rename from src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts rename to src/plugins/presentation_util/common/test_helpers/function_wrapper.ts index 4b0ef266f974d..601b02ff11793 100644 --- a/src/plugins/expression_reveal_image/common/test_helpers/function_wrapper.ts +++ b/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts @@ -7,12 +7,17 @@ */ import { mapValues } from 'lodash'; -import { ExpressionRevealImageFunction } from '../types'; +import { ExpressionFunctionDefinition, ExpressionValueRender } from '../../../expressions'; + +type FnType = () => ExpressionFunctionDefinition< + string, + number, + Record, + ExpressionValueRender +>; // It takes a function spec and passes in default args into the spec fn -export const functionWrapper = ( - fnSpec: ExpressionRevealImageFunction -): ReturnType['fn'] => { +export const functionWrapper = (fnSpec: FnType): ReturnType['fn'] => { const spec = fnSpec(); const defaultArgs = mapValues(spec.args, (argSpec) => { return argSpec.default; diff --git a/src/plugins/presentation_util/common/test_helpers/index.ts b/src/plugins/presentation_util/common/test_helpers/index.ts new file mode 100644 index 0000000000000..a6ea8da6ac6e9 --- /dev/null +++ b/src/plugins/presentation_util/common/test_helpers/index.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export * from './function_wrapper'; diff --git a/src/plugins/expression_reveal_image/public/__stories__/index.tsx b/src/plugins/presentation_util/public/__stories__/index.tsx similarity index 100% rename from src/plugins/expression_reveal_image/public/__stories__/index.tsx rename to src/plugins/presentation_util/public/__stories__/index.tsx diff --git a/src/plugins/expression_reveal_image/public/__stories__/render.tsx b/src/plugins/presentation_util/public/__stories__/render.tsx similarity index 100% rename from src/plugins/expression_reveal_image/public/__stories__/render.tsx rename to src/plugins/presentation_util/public/__stories__/render.tsx diff --git a/src/plugins/presentation_util/public/index.ts b/src/plugins/presentation_util/public/index.ts index 5ad81c7e759bc..257a878dee79d 100644 --- a/src/plugins/presentation_util/public/index.ts +++ b/src/plugins/presentation_util/public/index.ts @@ -18,12 +18,16 @@ export { export { PresentationUtilPluginSetup, PresentationUtilPluginStart } from './types'; export { SaveModalDashboardProps } from './components/types'; export { projectIDs, ProjectID, Project } from '../common/labs'; +export * from '../common/lib'; +export * from '../common/test_helpers'; +export * from './__stories__'; export { LazyLabsBeakerButton, LazyLabsFlyout, LazyDashboardPicker, LazySavedObjectSaveModalDashboard, + RendererWrapper, withSuspense, } from './components'; From 7e71064641b4c0d9dc73366cdc6b2eeef94c96be Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 16:51:35 +0300 Subject: [PATCH 47/77] Fixed one mistake. --- src/plugins/presentation_util/public/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/plugins/presentation_util/public/index.ts b/src/plugins/presentation_util/public/index.ts index 257a878dee79d..f523793e4e027 100644 --- a/src/plugins/presentation_util/public/index.ts +++ b/src/plugins/presentation_util/public/index.ts @@ -27,7 +27,6 @@ export { LazyLabsFlyout, LazyDashboardPicker, LazySavedObjectSaveModalDashboard, - RendererWrapper, withSuspense, } from './components'; From 199e16a8a6d46b775dec892b72c5398ebc709fd0 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 17:15:47 +0300 Subject: [PATCH 48/77] removed dataurl lib. --- src/plugins/presentation_util/tsconfig.json | 3 + .../uis/arguments/image_upload/index.js | 2 +- .../plugins/canvas/common/lib/dataurl.test.ts | 97 ------------------- x-pack/plugins/canvas/common/lib/dataurl.ts | 67 ------------- x-pack/plugins/canvas/common/lib/index.ts | 1 - x-pack/plugins/canvas/common/lib/url.ts | 2 +- .../components/asset_manager/asset_manager.ts | 2 +- .../custom_element_modal.tsx | 2 +- .../public/components/download/download.tsx | 2 +- 9 files changed, 8 insertions(+), 170 deletions(-) delete mode 100644 x-pack/plugins/canvas/common/lib/dataurl.test.ts delete mode 100644 x-pack/plugins/canvas/common/lib/dataurl.ts diff --git a/src/plugins/presentation_util/tsconfig.json b/src/plugins/presentation_util/tsconfig.json index c0fafe8c3aaba..b389d94b19413 100644 --- a/src/plugins/presentation_util/tsconfig.json +++ b/src/plugins/presentation_util/tsconfig.json @@ -7,6 +7,9 @@ "declaration": true, "declarationMap": true }, + "extraPublicDirs": [ + "common" + ], "include": [ "common/**/*", "public/**/*", diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js index 2caf41f0777e1..5fb827af077c9 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js @@ -13,7 +13,7 @@ import { AssetPicker } from '../../../../public/components/asset_picker'; import { elasticOutline } from '../../../lib/elastic_outline'; import { resolveFromArgs } from '../../../../common/lib/resolve_dataurl'; import { isValidHttpUrl } from '../../../../common/lib/httpurl'; -import { encode } from '../../../../common/lib/dataurl'; +import { encode } from '../../../../../../../src/plugins/presentation_util/public'; import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component'; import { VALID_IMAGE_TYPES } from '../../../../common/lib/constants'; import { ArgumentStrings } from '../../../../i18n'; diff --git a/x-pack/plugins/canvas/common/lib/dataurl.test.ts b/x-pack/plugins/canvas/common/lib/dataurl.test.ts deleted file mode 100644 index 9ddd0a50ea9d5..0000000000000 --- a/x-pack/plugins/canvas/common/lib/dataurl.test.ts +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { isValidDataUrl, parseDataUrl } from './dataurl'; - -const BASE64_TEXT = 'data:text/plain;charset=utf-8;base64,VGhpcyBpcyBhIHRlc3Q='; -const BASE64_SVG = - 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='; -const BASE64_PIXEL = - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk8PxfDwADYgHJvQ16TAAAAABJRU5ErkJggg=='; -const INVALID_BASE64_PIXEL = - 'data:image/png;%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%01%00%00%00%01%08%06%00%00%00%1F%15%C4%89%0'; - -const RAW_TEXT = 'data:text/plain;charset=utf-8,This%20is%20a%20test'; -const RAW_SVG = - 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%2F%3E'; -const RAW_PIXEL = - 'data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%01%00%00%00%01%08%06%00%00%00%1F%15%C4%89%00%00%00%0DIDATx%DAcd%F0%FC_%0F%00%03b%01%C9%BD%0DzL%00%00%00%00IEND%AEB%60%82'; - -describe('dataurl', () => { - describe('isValidDataUrl', () => { - it('returns false for an invalid data url', () => { - expect(isValidDataUrl('somestring')).toBe(false); - }); - it('returns false for an empty string', () => { - expect(isValidDataUrl('')).toBe(false); - }); - it('returns true for valid data urls', () => { - expect(isValidDataUrl(BASE64_TEXT)).toBe(true); - expect(isValidDataUrl(BASE64_SVG)).toBe(true); - expect(isValidDataUrl(BASE64_PIXEL)).toBe(true); - expect(isValidDataUrl(RAW_TEXT)).toBe(true); - expect(isValidDataUrl(RAW_SVG)).toBe(true); - expect(isValidDataUrl(RAW_PIXEL)).toBe(true); - }); - }); - - describe('dataurl.parseDataUrl', () => { - it('returns null for an invalid data url', () => { - expect(parseDataUrl('somestring')).toBeNull(); - }); - it('returns null for an invalid base64 image', () => { - expect(parseDataUrl(INVALID_BASE64_PIXEL)).toBeNull(); - }); - it('returns correct values for text data urls', () => { - expect(parseDataUrl(BASE64_TEXT)).toEqual({ - charset: 'utf-8', - data: null, - encoding: 'base64', - extension: 'txt', - isImage: false, - mimetype: 'text/plain', - }); - expect(parseDataUrl(RAW_TEXT)).toEqual({ - charset: 'utf-8', - data: null, - encoding: undefined, - extension: 'txt', - isImage: false, - mimetype: 'text/plain', - }); - }); - it('returns correct values for png data urls', () => { - expect(parseDataUrl(RAW_PIXEL)).toBeNull(); - expect(parseDataUrl(BASE64_PIXEL)).toEqual({ - charset: undefined, - data: null, - encoding: 'base64', - extension: 'png', - isImage: true, - mimetype: 'image/png', - }); - }); - it('returns correct values for svg data urls', () => { - expect(parseDataUrl(RAW_SVG)).toEqual({ - charset: undefined, - data: null, - encoding: undefined, - extension: 'svg', - isImage: true, - mimetype: 'image/svg+xml', - }); - expect(parseDataUrl(BASE64_SVG)).toEqual({ - charset: undefined, - data: null, - encoding: 'base64', - extension: 'svg', - isImage: true, - mimetype: 'image/svg+xml', - }); - }); - }); -}); diff --git a/x-pack/plugins/canvas/common/lib/dataurl.ts b/x-pack/plugins/canvas/common/lib/dataurl.ts deleted file mode 100644 index 2ae28b621c425..0000000000000 --- a/x-pack/plugins/canvas/common/lib/dataurl.ts +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { fromByteArray } from 'base64-js'; - -// @ts-expect-error @types/mime doesn't resolve mime/lite for some reason. -import mime from 'mime/lite'; - -const dataurlRegex = /^data:([a-z]+\/[a-z0-9-+.]+)(;[a-z-]+=[a-z0-9-]+)?(;([a-z0-9]+))?,/; - -export const imageTypes = ['image/svg+xml', 'image/jpeg', 'image/png', 'image/gif']; - -export function parseDataUrl(str: string, withData = false) { - if (typeof str !== 'string') { - return null; - } - - const matches = str.match(dataurlRegex); - - if (!matches) { - return null; - } - - const [, mimetype, charset, , encoding] = matches; - - // all types except for svg need to be base64 encoded - const imageTypeIndex = imageTypes.indexOf(matches[1]); - if (imageTypeIndex > 0 && encoding !== 'base64') { - return null; - } - - return { - mimetype, - encoding, - charset: charset && charset.split('=')[1], - data: !withData ? null : str.split(',')[1], - isImage: imageTypeIndex >= 0, - extension: mime.getExtension(mimetype), - }; -} - -export function isValidDataUrl(str?: string) { - if (!str) { - return false; - } - return dataurlRegex.test(str); -} - -export function encode(data: any | null, type = 'text/plain') { - // use FileReader if it's available, like in the browser - if (FileReader) { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onloadend = () => resolve(reader.result as string); - reader.onerror = (err) => reject(err); - reader.readAsDataURL(data); - }); - } - - // otherwise fall back to fromByteArray - // note: Buffer doesn't seem to correctly base64 encode binary data - return Promise.resolve(`data:${type};base64,${fromByteArray(data)}`); -} diff --git a/x-pack/plugins/canvas/common/lib/index.ts b/x-pack/plugins/canvas/common/lib/index.ts index afce09c6d5ee9..6471a0d39139e 100644 --- a/x-pack/plugins/canvas/common/lib/index.ts +++ b/x-pack/plugins/canvas/common/lib/index.ts @@ -8,7 +8,6 @@ export * from './datatable'; export * from './autocomplete'; export * from './constants'; -export * from './dataurl'; export * from './errors'; export * from './expression_form_handlers'; export * from './fetch'; diff --git a/x-pack/plugins/canvas/common/lib/url.ts b/x-pack/plugins/canvas/common/lib/url.ts index 5018abc027713..5050651472ea5 100644 --- a/x-pack/plugins/canvas/common/lib/url.ts +++ b/x-pack/plugins/canvas/common/lib/url.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { isValidDataUrl } from '../../common/lib/dataurl'; +import { isValidDataUrl } from '../../../../../src/plugins/presentation_util/common'; import { isValidHttpUrl } from '../../common/lib/httpurl'; export function isValidUrl(url: string) { diff --git a/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.ts b/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.ts index f8c6354d3935f..e3824798d1df1 100644 --- a/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.ts +++ b/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.ts @@ -13,7 +13,7 @@ import { getId } from '../../lib/get_id'; // @ts-expect-error untyped local import { findExistingAsset } from '../../lib/find_existing_asset'; import { VALID_IMAGE_TYPES } from '../../../common/lib/constants'; -import { encode } from '../../../common/lib/dataurl'; +import { encode } from '../../../../../../src/plugins/presentation_util/public'; // @ts-expect-error untyped local import { elementsRegistry } from '../../lib/elements_registry'; // @ts-expect-error untyped local diff --git a/x-pack/plugins/canvas/public/components/custom_element_modal/custom_element_modal.tsx b/x-pack/plugins/canvas/public/components/custom_element_modal/custom_element_modal.tsx index 5d9cccba924a9..69d432d2ccfb4 100644 --- a/x-pack/plugins/canvas/public/components/custom_element_modal/custom_element_modal.tsx +++ b/x-pack/plugins/canvas/public/components/custom_element_modal/custom_element_modal.tsx @@ -27,7 +27,7 @@ import { EuiTitle, } from '@elastic/eui'; import { VALID_IMAGE_TYPES } from '../../../common/lib/constants'; -import { encode } from '../../../common/lib/dataurl'; +import { encode } from '../../../../../../src/plugins/presentation_util/public'; import { ElementCard } from '../element_card'; import { ComponentStrings } from '../../../i18n/components'; diff --git a/x-pack/plugins/canvas/public/components/download/download.tsx b/x-pack/plugins/canvas/public/components/download/download.tsx index 856d6cb7e080e..89cd999481007 100644 --- a/x-pack/plugins/canvas/public/components/download/download.tsx +++ b/x-pack/plugins/canvas/public/components/download/download.tsx @@ -9,7 +9,7 @@ import { toByteArray } from 'base64-js'; import fileSaver from 'file-saver'; import PropTypes from 'prop-types'; import React, { ReactElement } from 'react'; -import { parseDataUrl } from '../../../common/lib/dataurl'; +import { parseDataUrl } from '../../../../../../src/plugins/presentation_util/public'; interface Props { children: ReactElement; From fd998f1ab1e3996886fe9e64fc5f6cf671400f25 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 17:19:45 +0300 Subject: [PATCH 49/77] Fixed jest files. --- src/plugins/presentation_util/jest.config.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/plugins/presentation_util/jest.config.js diff --git a/src/plugins/presentation_util/jest.config.js b/src/plugins/presentation_util/jest.config.js new file mode 100644 index 0000000000000..2250d70acb475 --- /dev/null +++ b/src/plugins/presentation_util/jest.config.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test', + rootDir: '../../..', + roots: ['/src/plugins/presentation_util'], +}; From 5b95af7503e25268d4d2aad5522121636b487113 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 17:36:45 +0300 Subject: [PATCH 50/77] elasticLogo removed. --- src/plugins/presentation_util/kibana.json | 3 +++ .../functions/common/__fixtures__/test_styles.js | 2 +- .../functions/common/container_style.test.js | 2 +- .../canvas_plugin_src/functions/common/image.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/image.ts | 2 +- .../functions/common/repeat_image.test.js | 2 +- .../plugins/canvas/canvas_plugin_src/lib/elastic_logo.ts | 2 -- .../renderers/__stories__/image.stories.tsx | 2 +- .../renderers/__stories__/repeat_image.stories.tsx | 2 +- .../plugins/canvas/canvas_plugin_src/renderers/image.tsx | 2 +- .../plugins/canvas/canvas_plugin_src/uis/views/image.js | 2 +- .../__stories__/custom_element_modal.stories.tsx | 2 +- .../element_card/__stories__/element_card.stories.tsx | 2 +- .../__stories__/fixtures/test_elements.tsx | 2 +- x-pack/plugins/canvas/public/lib/elastic_logo.ts | 9 --------- 15 files changed, 15 insertions(+), 23 deletions(-) delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/lib/elastic_logo.ts delete mode 100644 x-pack/plugins/canvas/public/lib/elastic_logo.ts diff --git a/src/plugins/presentation_util/kibana.json b/src/plugins/presentation_util/kibana.json index c7d272dcd02a1..de37355797a44 100644 --- a/src/plugins/presentation_util/kibana.json +++ b/src/plugins/presentation_util/kibana.json @@ -4,6 +4,9 @@ "kibanaVersion": "kibana", "server": true, "ui": true, + "extraPublicDirs": [ + "common" + ], "requiredPlugins": [ "savedObjects" ], diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__fixtures__/test_styles.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__fixtures__/test_styles.js index d61fef7abced8..462020f06ebb3 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__fixtures__/test_styles.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__fixtures__/test_styles.js @@ -5,7 +5,7 @@ * 2.0. */ -import { elasticLogo } from '../../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../../src/plugins/presentation_util/common'; export const fontStyle = { type: 'style', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js index b0a6ddf2caa74..5e097bf0c3ebe 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js @@ -6,7 +6,7 @@ */ import { functionWrapper } from '../../../test_helpers/function_wrapper'; -import { elasticLogo } from '../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { containerStyle } from './containerStyle'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js index cd0809d9b30a2..b4af357be0422 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; // import { functionWrapper } from '../../../test_helpers/function_wrapper'; -import { elasticLogo } from '../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; import { elasticOutline } from '../../lib/elastic_outline'; // import { image } from './image'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts index b4d067280cb69..8e46cb63c91d8 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts @@ -9,7 +9,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; import { getFunctionHelp, getFunctionErrors } from '../../../i18n'; import { resolveWithMissingImage } from '../../../common/lib/resolve_dataurl'; -import { elasticLogo } from '../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; export enum ImageMode { CONTAIN = 'contain', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js index f95d3d0ec03d0..9bb5925ff01ed 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js @@ -7,7 +7,7 @@ import { functionWrapper } from '../../../test_helpers/function_wrapper'; import { elasticOutline } from '../../lib/elastic_outline'; -import { elasticLogo } from '../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; import { repeatImage } from './repeat_image'; describe('repeatImage', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/lib/elastic_logo.ts b/x-pack/plugins/canvas/canvas_plugin_src/lib/elastic_logo.ts deleted file mode 100644 index 1ade7f1f269c0..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/lib/elastic_logo.ts +++ /dev/null @@ -1,2 +0,0 @@ -/* eslint-disable */ -export const elasticLogo = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgdmlld0JveD0iMCAwIDI3MC42MDAwMSAyNjkuNTQ2NjYiCiAgIGhlaWdodD0iMjY5LjU0NjY2IgogICB3aWR0aD0iMjcwLjYwMDAxIgogICB4bWw6c3BhY2U9InByZXNlcnZlIgogICBpZD0ic3ZnMiIKICAgdmVyc2lvbj0iMS4xIj48bWV0YWRhdGEKICAgICBpZD0ibWV0YWRhdGE4Ij48cmRmOlJERj48Y2M6V29yawogICAgICAgICByZGY6YWJvdXQ9IiI+PGRjOmZvcm1hdD5pbWFnZS9zdmcreG1sPC9kYzpmb3JtYXQ+PGRjOnR5cGUKICAgICAgICAgICByZGY6cmVzb3VyY2U9Imh0dHA6Ly9wdXJsLm9yZy9kYy9kY21pdHlwZS9TdGlsbEltYWdlIiAvPjwvY2M6V29yaz48L3JkZjpSREY+PC9tZXRhZGF0YT48ZGVmcwogICAgIGlkPSJkZWZzNiIgLz48ZwogICAgIHRyYW5zZm9ybT0ibWF0cml4KDEuMzMzMzMzMywwLDAsLTEuMzMzMzMzMywwLDI2OS41NDY2NykiCiAgICAgaWQ9ImcxMCI+PGcKICAgICAgIHRyYW5zZm9ybT0ic2NhbGUoMC4xKSIKICAgICAgIGlkPSJnMTIiPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMTQiCiAgICAgICAgIHN0eWxlPSJmaWxsOiNmZmZmZmY7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gMjAyOS40OCw5NjIuNDQxIGMgMCwxNzAuMDk5IC0xMDUuNDYsMzE4Ljc5OSAtMjY0LjE3LDM3Ni42NTkgNi45OCwzNS44NiAxMC42Miw3MS43MSAxMC42MiwxMDkuMDUgMCwzMTYuMTkgLTI1Ny4yNCw1NzMuNDMgLTU3My40Nyw1NzMuNDMgLTE4NC43MiwwIC0zNTYuNTU4LC04OC41OSAtNDY0LjUzLC0yMzcuODUgLTUzLjA5LDQxLjE4IC0xMTguMjg1LDYzLjc1IC0xODYuMzA1LDYzLjc1IC0xNjcuODM2LDAgLTMwNC4zODMsLTEzNi41NCAtMzA0LjM4MywtMzA0LjM4IDAsLTM3LjA4IDYuNjE3LC03Mi41OCAxOS4wMzEsLTEwNi4wOCBDIDEwOC40ODgsMTM4MC4wOSAwLDEyMjcuODkgMCwxMDU4Ljg4IDAsODg3LjkxIDEwNS45NzcsNzM4LjUzOSAyNjUuMzk4LDY4MS4wOSBjIC02Ljc2OSwtMzUuNDQyIC0xMC40NiwtNzIuMDIgLTEwLjQ2LC0xMDkgQyAyNTQuOTM4LDI1Ni42MjEgNTExLjU2NiwwIDgyNy4wMjcsMCAxMDEyLjIsMCAxMTgzLjk0LDg4Ljk0MTQgMTI5MS4zLDIzOC44MzIgYyA1My40NSwtNDEuOTYxIDExOC44LC02NC45OTIgMTg2LjU2LC02NC45OTIgMTY3LjgzLDAgMzA0LjM4LDEzNi40OTIgMzA0LjM4LDMwNC4zMzIgMCwzNy4wNzggLTYuNjIsNzIuNjI5IC0xOS4wMywxMDYuMTI5IDE1Ny43OCw1Ni44NzkgMjY2LjI3LDIwOS4xMjkgMjY2LjI3LDM3OC4xNCIgLz48cGF0aAogICAgICAgICBpZD0icGF0aDE2IgogICAgICAgICBzdHlsZT0iZmlsbDojZmFjZjA5O2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIgogICAgICAgICBkPSJtIDc5Ny44OTgsMTE1MC45MyA0NDQuMDcyLC0yMDIuNDUgNDQ4LjA1LDM5Mi41OCBjIDYuNDksMzIuMzkgOS42Niw2NC42NyA5LjY2LDk4LjQ2IDAsMjc2LjIzIC0yMjQuNjgsNTAwLjk1IC01MDAuOSw1MDAuOTUgLTE2NS4yNCwwIC0zMTkuMzcsLTgxLjM2IC00MTMuMDUzLC0yMTcuNzkgbCAtNzQuNTI0LC0zODYuNjQgODYuNjk1LC0xODUuMTEiIC8+PHBhdGgKICAgICAgICAgaWQ9InBhdGgxOCIKICAgICAgICAgc3R5bGU9ImZpbGw6IzQ5YzFhZTtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6bm9uZSIKICAgICAgICAgZD0ibSAzMzguMjIzLDY4MC42NzIgYyAtNi40ODksLTMyLjM4MyAtOS44MDksLTY1Ljk4MSAtOS44MDksLTk5Ljk3MyAwLC0yNzYuOTI5IDIyNS4zMzYsLTUwMi4yNTc2IDUwMi4zMTMsLTUwMi4yNTc2IDE2Ni41OTMsMCAzMjEuNDczLDgyLjExNzYgNDE1LjAxMywyMTkuOTQ5NiBsIDczLjk3LDM4NS4zNDcgLTk4LjcyLDE4OC42MjEgTCA3NzUuMTU2LDEwNzUuNTcgMzM4LjIyMyw2ODAuNjcyIiAvPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMjAiCiAgICAgICAgIHN0eWxlPSJmaWxsOiNlZjI5OWI7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gMzM1LjQxLDE0NDkuMTggMzA0LjMzMiwtNzEuODYgNjYuNjgsMzQ2LjAyIGMgLTQxLjU4NiwzMS43OCAtOTIuOTMsNDkuMTggLTE0NS43MzEsNDkuMTggLTEzMi4yNSwwIC0yMzkuODEyLC0xMDcuNjEgLTIzOS44MTIsLTIzOS44NyAwLC0yOS4yMSA0Ljg3OSwtNTcuMjIgMTQuNTMxLC04My40NyIgLz48cGF0aAogICAgICAgICBpZD0icGF0aDIyIgogICAgICAgICBzdHlsZT0iZmlsbDojNGNhYmU0O2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIgogICAgICAgICBkPSJNIDMwOC45OTIsMTM3Ni43IEMgMTczLjAyLDEzMzEuNjQgNzguNDgwNSwxMjAxLjMgNzguNDgwNSwxMDU3LjkzIDc4LjQ4MDUsOTE4LjM0IDE2NC44Miw3OTMuNjggMjk0LjQwNiw3NDQuMzUyIGwgNDI2Ljk4MSwzODUuOTM4IC03OC4zOTUsMTY3LjUxIC0zMzQsNzguOSIgLz48cGF0aAogICAgICAgICBpZD0icGF0aDI0IgogICAgICAgICBzdHlsZT0iZmlsbDojODVjZTI2O2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIgogICAgICAgICBkPSJtIDEzMjMuOCwyOTguNDEgYyA0MS43NCwtMzIuMDkgOTIuODMsLTQ5LjU5IDE0NC45OCwtNDkuNTkgMTMyLjI1LDAgMjM5LjgxLDEwNy41NTkgMjM5LjgxLDIzOS44MjEgMCwyOS4xNiAtNC44OCw1Ny4xNjggLTE0LjUzLDgzLjQxOCBsIC0zMDQuMDgsNzEuMTYgLTY2LjE4LC0zNDQuODA5IiAvPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMjYiCiAgICAgICAgIHN0eWxlPSJmaWxsOiMzMTc3YTc7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gMTM4NS42Nyw3MjIuOTMgMzM0Ljc2LC03OC4zMDEgYyAxMzYuMDIsNDQuOTYxIDIzMC41NiwxNzUuMzUxIDIzMC41NiwzMTguNzYyIDAsMTM5LjMzOSAtODYuNTQsMjYzLjg1OSAtMjE2LjM4LDMxMy4wMzkgbCAtNDM3Ljg0LC0zODMuNTkgODguOSwtMTY5LjkxIiAvPjwvZz48L2c+PC9zdmc+'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/image.stories.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/image.stories.tsx index 7276a55bdf49d..186f3281a8ef7 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/image.stories.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/image.stories.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { image } from '../image'; import { Render } from './render'; -import { elasticLogo } from '../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; storiesOf('renderers/image', module).add('default', () => { const config = { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx index 8dd059cf7a32f..30d46e26c706c 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { repeatImage } from '../repeat_image'; import { Render } from './render'; -import { elasticLogo } from '../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; import { elasticOutline } from '../../lib/elastic_outline'; storiesOf('renderers/repeatImage', module).add('default', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx index 8c88fe820d5d3..97a63eed7ecf0 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx @@ -7,7 +7,7 @@ import ReactDOM from 'react-dom'; import React from 'react'; -import { elasticLogo } from '../lib/elastic_logo'; +import { elasticLogo } from '../../../../../src/plugins/presentation_util/common'; import { isValidUrl } from '../../common/lib/url'; import { Return as Arguments } from '../functions/common/image'; import { RendererStrings } from '../../i18n'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js index 37b22e376141f..c6c06feea4605 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js @@ -5,7 +5,7 @@ * 2.0. */ -import { elasticLogo } from '../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; import { resolveFromArgs } from '../../../common/lib/resolve_dataurl'; import { ViewStrings } from '../../../i18n'; diff --git a/x-pack/plugins/canvas/public/components/custom_element_modal/__stories__/custom_element_modal.stories.tsx b/x-pack/plugins/canvas/public/components/custom_element_modal/__stories__/custom_element_modal.stories.tsx index 2e6d83cb1c8ac..b278510945946 100644 --- a/x-pack/plugins/canvas/public/components/custom_element_modal/__stories__/custom_element_modal.stories.tsx +++ b/x-pack/plugins/canvas/public/components/custom_element_modal/__stories__/custom_element_modal.stories.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { action } from '@storybook/addon-actions'; import { CustomElementModal } from '../custom_element_modal'; -import { elasticLogo } from '../../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../../src/plugins/presentation_util/common'; storiesOf('components/Elements/CustomElementModal', module) .add('with title', () => ( diff --git a/x-pack/plugins/canvas/public/components/element_card/__stories__/element_card.stories.tsx b/x-pack/plugins/canvas/public/components/element_card/__stories__/element_card.stories.tsx index ae0d4328aa98d..832d56650d810 100644 --- a/x-pack/plugins/canvas/public/components/element_card/__stories__/element_card.stories.tsx +++ b/x-pack/plugins/canvas/public/components/element_card/__stories__/element_card.stories.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { action } from '@storybook/addon-actions'; import { ElementCard } from '../element_card'; -import { elasticLogo } from '../../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../../src/plugins/presentation_util/common'; storiesOf('components/Elements/ElementCard', module) .addDecorator((story) => ( diff --git a/x-pack/plugins/canvas/public/components/saved_elements_modal/__stories__/fixtures/test_elements.tsx b/x-pack/plugins/canvas/public/components/saved_elements_modal/__stories__/fixtures/test_elements.tsx index 17d6a3d11b60f..e8dc8e61cbd41 100644 --- a/x-pack/plugins/canvas/public/components/saved_elements_modal/__stories__/fixtures/test_elements.tsx +++ b/x-pack/plugins/canvas/public/components/saved_elements_modal/__stories__/fixtures/test_elements.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { elasticLogo } from '../../../../lib/elastic_logo'; +import { elasticLogo } from '../../../../../../../../src/plugins/presentation_util/common'; export const testCustomElements = [ { diff --git a/x-pack/plugins/canvas/public/lib/elastic_logo.ts b/x-pack/plugins/canvas/public/lib/elastic_logo.ts deleted file mode 100644 index 81c79c39143d6..0000000000000 --- a/x-pack/plugins/canvas/public/lib/elastic_logo.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export const elasticLogo = - 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgdmlld0JveD0iMCAwIDI3MC42MDAwMSAyNjkuNTQ2NjYiCiAgIGhlaWdodD0iMjY5LjU0NjY2IgogICB3aWR0aD0iMjcwLjYwMDAxIgogICB4bWw6c3BhY2U9InByZXNlcnZlIgogICBpZD0ic3ZnMiIKICAgdmVyc2lvbj0iMS4xIj48bWV0YWRhdGEKICAgICBpZD0ibWV0YWRhdGE4Ij48cmRmOlJERj48Y2M6V29yawogICAgICAgICByZGY6YWJvdXQ9IiI+PGRjOmZvcm1hdD5pbWFnZS9zdmcreG1sPC9kYzpmb3JtYXQ+PGRjOnR5cGUKICAgICAgICAgICByZGY6cmVzb3VyY2U9Imh0dHA6Ly9wdXJsLm9yZy9kYy9kY21pdHlwZS9TdGlsbEltYWdlIiAvPjwvY2M6V29yaz48L3JkZjpSREY+PC9tZXRhZGF0YT48ZGVmcwogICAgIGlkPSJkZWZzNiIgLz48ZwogICAgIHRyYW5zZm9ybT0ibWF0cml4KDEuMzMzMzMzMywwLDAsLTEuMzMzMzMzMywwLDI2OS41NDY2NykiCiAgICAgaWQ9ImcxMCI+PGcKICAgICAgIHRyYW5zZm9ybT0ic2NhbGUoMC4xKSIKICAgICAgIGlkPSJnMTIiPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMTQiCiAgICAgICAgIHN0eWxlPSJmaWxsOiNmZmZmZmY7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gMjAyOS40OCw5NjIuNDQxIGMgMCwxNzAuMDk5IC0xMDUuNDYsMzE4Ljc5OSAtMjY0LjE3LDM3Ni42NTkgNi45OCwzNS44NiAxMC42Miw3MS43MSAxMC42MiwxMDkuMDUgMCwzMTYuMTkgLTI1Ny4yNCw1NzMuNDMgLTU3My40Nyw1NzMuNDMgLTE4NC43MiwwIC0zNTYuNTU4LC04OC41OSAtNDY0LjUzLC0yMzcuODUgLTUzLjA5LDQxLjE4IC0xMTguMjg1LDYzLjc1IC0xODYuMzA1LDYzLjc1IC0xNjcuODM2LDAgLTMwNC4zODMsLTEzNi41NCAtMzA0LjM4MywtMzA0LjM4IDAsLTM3LjA4IDYuNjE3LC03Mi41OCAxOS4wMzEsLTEwNi4wOCBDIDEwOC40ODgsMTM4MC4wOSAwLDEyMjcuODkgMCwxMDU4Ljg4IDAsODg3LjkxIDEwNS45NzcsNzM4LjUzOSAyNjUuMzk4LDY4MS4wOSBjIC02Ljc2OSwtMzUuNDQyIC0xMC40NiwtNzIuMDIgLTEwLjQ2LC0xMDkgQyAyNTQuOTM4LDI1Ni42MjEgNTExLjU2NiwwIDgyNy4wMjcsMCAxMDEyLjIsMCAxMTgzLjk0LDg4Ljk0MTQgMTI5MS4zLDIzOC44MzIgYyA1My40NSwtNDEuOTYxIDExOC44LC02NC45OTIgMTg2LjU2LC02NC45OTIgMTY3LjgzLDAgMzA0LjM4LDEzNi40OTIgMzA0LjM4LDMwNC4zMzIgMCwzNy4wNzggLTYuNjIsNzIuNjI5IC0xOS4wMywxMDYuMTI5IDE1Ny43OCw1Ni44NzkgMjY2LjI3LDIwOS4xMjkgMjY2LjI3LDM3OC4xNCIgLz48cGF0aAogICAgICAgICBpZD0icGF0aDE2IgogICAgICAgICBzdHlsZT0iZmlsbDojZmFjZjA5O2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIgogICAgICAgICBkPSJtIDc5Ny44OTgsMTE1MC45MyA0NDQuMDcyLC0yMDIuNDUgNDQ4LjA1LDM5Mi41OCBjIDYuNDksMzIuMzkgOS42Niw2NC42NyA5LjY2LDk4LjQ2IDAsMjc2LjIzIC0yMjQuNjgsNTAwLjk1IC01MDAuOSw1MDAuOTUgLTE2NS4yNCwwIC0zMTkuMzcsLTgxLjM2IC00MTMuMDUzLC0yMTcuNzkgbCAtNzQuNTI0LC0zODYuNjQgODYuNjk1LC0xODUuMTEiIC8+PHBhdGgKICAgICAgICAgaWQ9InBhdGgxOCIKICAgICAgICAgc3R5bGU9ImZpbGw6IzQ5YzFhZTtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6bm9uZSIKICAgICAgICAgZD0ibSAzMzguMjIzLDY4MC42NzIgYyAtNi40ODksLTMyLjM4MyAtOS44MDksLTY1Ljk4MSAtOS44MDksLTk5Ljk3MyAwLC0yNzYuOTI5IDIyNS4zMzYsLTUwMi4yNTc2IDUwMi4zMTMsLTUwMi4yNTc2IDE2Ni41OTMsMCAzMjEuNDczLDgyLjExNzYgNDE1LjAxMywyMTkuOTQ5NiBsIDczLjk3LDM4NS4zNDcgLTk4LjcyLDE4OC42MjEgTCA3NzUuMTU2LDEwNzUuNTcgMzM4LjIyMyw2ODAuNjcyIiAvPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMjAiCiAgICAgICAgIHN0eWxlPSJmaWxsOiNlZjI5OWI7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gMzM1LjQxLDE0NDkuMTggMzA0LjMzMiwtNzEuODYgNjYuNjgsMzQ2LjAyIGMgLTQxLjU4NiwzMS43OCAtOTIuOTMsNDkuMTggLTE0NS43MzEsNDkuMTggLTEzMi4yNSwwIC0yMzkuODEyLC0xMDcuNjEgLTIzOS44MTIsLTIzOS44NyAwLC0yOS4yMSA0Ljg3OSwtNTcuMjIgMTQuNTMxLC04My40NyIgLz48cGF0aAogICAgICAgICBpZD0icGF0aDIyIgogICAgICAgICBzdHlsZT0iZmlsbDojNGNhYmU0O2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIgogICAgICAgICBkPSJNIDMwOC45OTIsMTM3Ni43IEMgMTczLjAyLDEzMzEuNjQgNzguNDgwNSwxMjAxLjMgNzguNDgwNSwxMDU3LjkzIDc4LjQ4MDUsOTE4LjM0IDE2NC44Miw3OTMuNjggMjk0LjQwNiw3NDQuMzUyIGwgNDI2Ljk4MSwzODUuOTM4IC03OC4zOTUsMTY3LjUxIC0zMzQsNzguOSIgLz48cGF0aAogICAgICAgICBpZD0icGF0aDI0IgogICAgICAgICBzdHlsZT0iZmlsbDojODVjZTI2O2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIgogICAgICAgICBkPSJtIDEzMjMuOCwyOTguNDEgYyA0MS43NCwtMzIuMDkgOTIuODMsLTQ5LjU5IDE0NC45OCwtNDkuNTkgMTMyLjI1LDAgMjM5LjgxLDEwNy41NTkgMjM5LjgxLDIzOS44MjEgMCwyOS4xNiAtNC44OCw1Ny4xNjggLTE0LjUzLDgzLjQxOCBsIC0zMDQuMDgsNzEuMTYgLTY2LjE4LC0zNDQuODA5IiAvPjxwYXRoCiAgICAgICAgIGlkPSJwYXRoMjYiCiAgICAgICAgIHN0eWxlPSJmaWxsOiMzMTc3YTc7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOm5vbnplcm87c3Ryb2tlOm5vbmUiCiAgICAgICAgIGQ9Im0gMTM4NS42Nyw3MjIuOTMgMzM0Ljc2LC03OC4zMDEgYyAxMzYuMDIsNDQuOTYxIDIzMC41NiwxNzUuMzUxIDIzMC41NiwzMTguNzYyIDAsMTM5LjMzOSAtODYuNTQsMjYzLjg1OSAtMjE2LjM4LDMxMy4wMzkgbCAtNDM3Ljg0LC0zODMuNTkgODguOSwtMTY5LjkxIiAvPjwvZz48L2c+PC9zdmc+'; From a290c31afcd4b4f114535fe5fc986cf1c9dbd2db Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 17:46:35 +0300 Subject: [PATCH 51/77] Removed elastic_outline. --- .../canvas/canvas_plugin_src/functions/common/image.test.js | 6 ++++-- .../canvas_plugin_src/functions/common/repeat_image.test.js | 6 ++++-- .../canvas_plugin_src/functions/common/repeat_image.ts | 2 +- .../plugins/canvas/canvas_plugin_src/lib/elastic_outline.ts | 2 -- .../renderers/__stories__/repeat_image.stories.tsx | 6 ++++-- .../canvas/canvas_plugin_src/renderers/repeat_image.ts | 2 +- .../canvas_plugin_src/uis/arguments/image_upload/index.js | 3 +-- x-pack/plugins/canvas/public/lib/elastic_outline.js | 2 -- 8 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/lib/elastic_outline.ts delete mode 100644 x-pack/plugins/canvas/public/lib/elastic_outline.js diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js index b4af357be0422..89788d900d3c1 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js @@ -7,8 +7,10 @@ import expect from '@kbn/expect'; // import { functionWrapper } from '../../../test_helpers/function_wrapper'; -import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; -import { elasticOutline } from '../../lib/elastic_outline'; +import { + elasticLogo, + elasticOutline, +} from '../../../../../../src/plugins/presentation_util/common'; // import { image } from './image'; // TODO: the test was not running and is not up to date diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js index 9bb5925ff01ed..7d00c6c9e3642 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js @@ -6,8 +6,10 @@ */ import { functionWrapper } from '../../../test_helpers/function_wrapper'; -import { elasticOutline } from '../../lib/elastic_outline'; -import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; +import { + elasticLogo, + elasticOutline, +} from '../../../../../../src/plugins/presentation_util/common'; import { repeatImage } from './repeat_image'; describe('repeatImage', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts index 6e62139e4da0d..e31fed86ff72a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts @@ -7,7 +7,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; import { resolveWithMissingImage } from '../../../common/lib/resolve_dataurl'; -import { elasticOutline } from '../../lib/elastic_outline'; +import { elasticOutline } from '../../../../../../src/plugins/presentation_util/common'; import { Render } from '../../../types'; import { getFunctionHelp } from '../../../i18n'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/lib/elastic_outline.ts b/x-pack/plugins/canvas/canvas_plugin_src/lib/elastic_outline.ts deleted file mode 100644 index 7271f5b32d547..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/lib/elastic_outline.ts +++ /dev/null @@ -1,2 +0,0 @@ -/* eslint-disable */ -export const elasticOutline = 'data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3Csvg%20viewBox%3D%22-3.948730230331421%20-1.7549896240234375%20245.25946044921875%20241.40370178222656%22%20width%3D%22245.25946044921875%22%20height%3D%22241.40370178222656%22%20style%3D%22enable-background%3Anew%200%200%20686.2%20235.7%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%20%20%3Cdefs%3E%0A%20%20%20%20%3Cstyle%20type%3D%22text%2Fcss%22%3E%0A%09.st0%7Bfill%3A%232D2D2D%3B%7D%0A%3C%2Fstyle%3E%0A%20%20%3C%2Fdefs%3E%0A%20%20%3Cg%20transform%3D%22matrix%281%2C%200%2C%200%2C%201%2C%200%2C%200%29%22%3E%0A%20%20%20%20%3Cg%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M329.4%2C160.3l4.7-0.5l0.3%2C9.6c-12.4%2C1.7-23%2C2.6-31.8%2C2.6c-11.7%2C0-20-3.4-24.9-10.2%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-4.9-6.8-7.3-17.4-7.3-31.7c0-28.6%2C11.4-42.9%2C34.1-42.9c11%2C0%2C19.2%2C3.1%2C24.6%2C9.2c5.4%2C6.1%2C8.1%2C15.8%2C8.1%2C28.9l-0.7%2C9.3h-53.8%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc0%2C9%2C1.6%2C15.7%2C4.9%2C20c3.3%2C4.3%2C8.9%2C6.5%2C17%2C6.5C312.8%2C161.2%2C321.1%2C160.9%2C329.4%2C160.3z%20M325%2C124.9c0-10-1.6-17.1-4.8-21.2%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-3.2-4.1-8.4-6.2-15.6-6.2c-7.2%2C0-12.7%2C2.2-16.3%2C6.5c-3.6%2C4.3-5.5%2C11.3-5.6%2C20.9H325z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M354.3%2C171.4V64h12.2v107.4H354.3z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M443.5%2C113.5v41.1c0%2C4.1%2C10.1%2C3.9%2C10.1%2C3.9l-0.6%2C10.8c-8.6%2C0-15.7%2C0.7-20-3.4c-9.8%2C4.3-19.5%2C6.1-29.3%2C6.1%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-7.5%2C0-13.2-2.1-17.1-6.4c-3.9-4.2-5.9-10.3-5.9-18.3c0-7.9%2C2-13.8%2C6-17.5c4-3.7%2C10.3-6.1%2C18.9-6.9l25.6-2.4v-7%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc0-5.5-1.2-9.5-3.6-11.9c-2.4-2.4-5.7-3.6-9.8-3.6l-32.1%2C0V87.2h31.3c9.2%2C0%2C15.9%2C2.1%2C20.1%2C6.4C441.4%2C97.8%2C443.5%2C104.5%2C443.5%2C113.5%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bz%20M393.3%2C146.7c0%2C10%2C4.1%2C15%2C12.4%2C15c7.4%2C0%2C14.7-1.2%2C21.8-3.7l3.7-1.3v-26.9l-24.1%2C2.3c-4.9%2C0.4-8.4%2C1.8-10.6%2C4.2%26%2310%3B%26%239%3B%26%239%3B%26%239%3BC394.4%2C138.7%2C393.3%2C142.2%2C393.3%2C146.7z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M491.2%2C98.2c-11.8%2C0-17.8%2C4.1-17.8%2C12.4c0%2C3.8%2C1.4%2C6.5%2C4.1%2C8.1c2.7%2C1.6%2C8.9%2C3.2%2C18.6%2C4.9%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc9.7%2C1.7%2C16.5%2C4%2C20.5%2C7.1c4%2C3%2C6%2C8.7%2C6%2C17.1c0%2C8.4-2.7%2C14.5-8.1%2C18.4c-5.4%2C3.9-13.2%2C5.9-23.6%2C5.9c-6.7%2C0-29.2-2.5-29.2-2.5%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bl0.7-10.6c12.9%2C1.2%2C22.3%2C2.2%2C28.6%2C2.2c6.3%2C0%2C11.1-1%2C14.4-3c3.3-2%2C5-5.4%2C5-10.1c0-4.7-1.4-7.9-4.2-9.6c-2.8-1.7-9-3.3-18.6-4.8%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-9.6-1.5-16.4-3.7-20.4-6.7c-4-2.9-6-8.4-6-16.3c0-7.9%2C2.8-13.8%2C8.4-17.6c5.6-3.8%2C12.6-5.7%2C20.9-5.7c6.6%2C0%2C29.6%2C1.7%2C29.6%2C1.7%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bv10.7C508.1%2C99%2C498.2%2C98.2%2C491.2%2C98.2z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M581.7%2C99.5h-25.9v39c0%2C9.3%2C0.7%2C15.5%2C2%2C18.4c1.4%2C2.9%2C4.6%2C4.4%2C9.7%2C4.4l14.5-1l0.8%2C10.1%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-7.3%2C1.2-12.8%2C1.8-16.6%2C1.8c-8.5%2C0-14.3-2.1-17.6-6.2c-3.3-4.1-4.9-12-4.9-23.6V99.5h-11.6V88.9h11.6V63.9h12.1v24.9h25.9V99.5z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M598.7%2C78.4V64.3h12.2v14.2H598.7z%20M598.7%2C171.4V88.9h12.2v82.5H598.7z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M663.8%2C87.2c3.6%2C0%2C9.7%2C0.7%2C18.3%2C2l3.9%2C0.5l-0.5%2C9.9c-8.7-1-15.1-1.5-19.2-1.5c-9.2%2C0-15.5%2C2.2-18.8%2C6.6%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-3.3%2C4.4-5%2C12.6-5%2C24.5c0%2C11.9%2C1.5%2C20.2%2C4.6%2C24.9c3.1%2C4.7%2C9.5%2C7%2C19.3%2C7l19.2-1.5l0.5%2C10.1c-10.1%2C1.5-17.7%2C2.3-22.7%2C2.3%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-12.7%2C0-21.5-3.3-26.3-9.8c-4.8-6.5-7.3-17.5-7.3-33c0-15.5%2C2.6-26.4%2C7.8-32.6C643%2C90.4%2C651.7%2C87.2%2C663.8%2C87.2z%22%2F%3E%0A%20%20%20%20%3C%2Fg%3E%0A%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M236.6%2C123.5c0-19.8-12.3-37.2-30.8-43.9c0.8-4.2%2C1.2-8.4%2C1.2-12.7C207%2C30%2C177%2C0%2C140.2%2C0%26%2310%3B%26%239%3B%26%239%3BC118.6%2C0%2C98.6%2C10.3%2C86%2C27.7c-6.2-4.8-13.8-7.4-21.7-7.4c-19.6%2C0-35.5%2C15.9-35.5%2C35.5c0%2C4.3%2C0.8%2C8.5%2C2.2%2C12.4%26%2310%3B%26%239%3B%26%239%3BC12.6%2C74.8%2C0%2C92.5%2C0%2C112.2c0%2C19.9%2C12.4%2C37.3%2C30.9%2C44c-0.8%2C4.1-1.2%2C8.4-1.2%2C12.7c0%2C36.8%2C29.9%2C66.7%2C66.7%2C66.7%26%2310%3B%26%239%3B%26%239%3Bc21.6%2C0%2C41.6-10.4%2C54.1-27.8c6.2%2C4.9%2C13.8%2C7.6%2C21.7%2C7.6c19.6%2C0%2C35.5-15.9%2C35.5-35.5c0-4.3-0.8-8.5-2.2-12.4%26%2310%3B%26%239%3B%26%239%3BC223.9%2C160.9%2C236.6%2C143.2%2C236.6%2C123.5z%20M91.6%2C34.8c10.9-15.9%2C28.9-25.4%2C48.1-25.4c32.2%2C0%2C58.4%2C26.2%2C58.4%2C58.4%26%2310%3B%26%239%3B%26%239%3Bc0%2C3.9-0.4%2C7.7-1.1%2C11.5l-52.2%2C45.8L93%2C101.5L82.9%2C79.9L91.6%2C34.8z%20M65.4%2C29c6.2%2C0%2C12.1%2C2%2C17%2C5.7l-7.8%2C40.3l-35.5-8.4%26%2310%3B%26%239%3B%26%239%3Bc-1.1-3.1-1.7-6.3-1.7-9.7C37.4%2C41.6%2C49.9%2C29%2C65.4%2C29z%20M9.1%2C112.3c0-16.7%2C11-31.9%2C26.9-37.2L75%2C84.4l9.1%2C19.5l-49.8%2C45%26%2310%3B%26%239%3B%26%239%3BC19.2%2C143.1%2C9.1%2C128.6%2C9.1%2C112.3z%20M145.2%2C200.9c-10.9%2C16.1-29%2C25.6-48.4%2C25.6c-32.3%2C0-58.6-26.3-58.6-58.5c0-4%2C0.4-7.9%2C1.1-11.7%26%2310%3B%26%239%3B%26%239%3Bl50.9-46l52%2C23.7l11.5%2C22L145.2%2C200.9z%20M171.2%2C206.6c-6.1%2C0-12-2-16.9-5.8l7.7-40.2l35.4%2C8.3c1.1%2C3.1%2C1.7%2C6.3%2C1.7%2C9.7%26%2310%3B%26%239%3B%26%239%3BC199.2%2C194.1%2C186.6%2C206.6%2C171.2%2C206.6z%20M200.5%2C160.5l-39-9.1l-10.4-19.8l51-44.7c15.1%2C5.7%2C25.2%2C20.2%2C25.2%2C36.5%26%2310%3B%26%239%3B%26%239%3BC227.4%2C140.1%2C216.4%2C155.3%2C200.5%2C160.5z%22%2F%3E%0A%20%20%3C%2Fg%3E%0A%3C%2Fsvg%3E'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx index 30d46e26c706c..050d7c7eff12f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx @@ -9,8 +9,10 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { repeatImage } from '../repeat_image'; import { Render } from './render'; -import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; -import { elasticOutline } from '../../lib/elastic_outline'; +import { + elasticLogo, + elasticOutline, +} from '../../../../../../src/plugins/presentation_util/common'; storiesOf('renderers/repeatImage', module).add('default', () => { const config = { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts b/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts index 8286609aa334f..730366f6a5fba 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts @@ -7,7 +7,7 @@ import $ from 'jquery'; import { times } from 'lodash'; -import { elasticOutline } from '../lib/elastic_outline'; +import { elasticOutline } from '../../../../../src/plugins/presentation_util/common'; import { isValidUrl } from '../../common/lib/url'; import { RendererStrings, ErrorStrings } from '../../i18n'; import { Return as Arguments } from '../functions/common/repeat_image'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js index 5fb827af077c9..a4b3191c90d61 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js @@ -10,10 +10,9 @@ import PropTypes from 'prop-types'; import { EuiSpacer, EuiFormRow, EuiButtonGroup } from '@elastic/eui'; import { get } from 'lodash'; import { AssetPicker } from '../../../../public/components/asset_picker'; -import { elasticOutline } from '../../../lib/elastic_outline'; import { resolveFromArgs } from '../../../../common/lib/resolve_dataurl'; import { isValidHttpUrl } from '../../../../common/lib/httpurl'; -import { encode } from '../../../../../../../src/plugins/presentation_util/public'; +import { encode, elasticOutline } from '../../../../../../../src/plugins/presentation_util/public'; import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component'; import { VALID_IMAGE_TYPES } from '../../../../common/lib/constants'; import { ArgumentStrings } from '../../../../i18n'; diff --git a/x-pack/plugins/canvas/public/lib/elastic_outline.js b/x-pack/plugins/canvas/public/lib/elastic_outline.js deleted file mode 100644 index 7271f5b32d547..0000000000000 --- a/x-pack/plugins/canvas/public/lib/elastic_outline.js +++ /dev/null @@ -1,2 +0,0 @@ -/* eslint-disable */ -export const elasticOutline = 'data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3Csvg%20viewBox%3D%22-3.948730230331421%20-1.7549896240234375%20245.25946044921875%20241.40370178222656%22%20width%3D%22245.25946044921875%22%20height%3D%22241.40370178222656%22%20style%3D%22enable-background%3Anew%200%200%20686.2%20235.7%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%0A%20%20%3Cdefs%3E%0A%20%20%20%20%3Cstyle%20type%3D%22text%2Fcss%22%3E%0A%09.st0%7Bfill%3A%232D2D2D%3B%7D%0A%3C%2Fstyle%3E%0A%20%20%3C%2Fdefs%3E%0A%20%20%3Cg%20transform%3D%22matrix%281%2C%200%2C%200%2C%201%2C%200%2C%200%29%22%3E%0A%20%20%20%20%3Cg%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M329.4%2C160.3l4.7-0.5l0.3%2C9.6c-12.4%2C1.7-23%2C2.6-31.8%2C2.6c-11.7%2C0-20-3.4-24.9-10.2%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-4.9-6.8-7.3-17.4-7.3-31.7c0-28.6%2C11.4-42.9%2C34.1-42.9c11%2C0%2C19.2%2C3.1%2C24.6%2C9.2c5.4%2C6.1%2C8.1%2C15.8%2C8.1%2C28.9l-0.7%2C9.3h-53.8%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc0%2C9%2C1.6%2C15.7%2C4.9%2C20c3.3%2C4.3%2C8.9%2C6.5%2C17%2C6.5C312.8%2C161.2%2C321.1%2C160.9%2C329.4%2C160.3z%20M325%2C124.9c0-10-1.6-17.1-4.8-21.2%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-3.2-4.1-8.4-6.2-15.6-6.2c-7.2%2C0-12.7%2C2.2-16.3%2C6.5c-3.6%2C4.3-5.5%2C11.3-5.6%2C20.9H325z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M354.3%2C171.4V64h12.2v107.4H354.3z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M443.5%2C113.5v41.1c0%2C4.1%2C10.1%2C3.9%2C10.1%2C3.9l-0.6%2C10.8c-8.6%2C0-15.7%2C0.7-20-3.4c-9.8%2C4.3-19.5%2C6.1-29.3%2C6.1%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-7.5%2C0-13.2-2.1-17.1-6.4c-3.9-4.2-5.9-10.3-5.9-18.3c0-7.9%2C2-13.8%2C6-17.5c4-3.7%2C10.3-6.1%2C18.9-6.9l25.6-2.4v-7%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc0-5.5-1.2-9.5-3.6-11.9c-2.4-2.4-5.7-3.6-9.8-3.6l-32.1%2C0V87.2h31.3c9.2%2C0%2C15.9%2C2.1%2C20.1%2C6.4C441.4%2C97.8%2C443.5%2C104.5%2C443.5%2C113.5%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bz%20M393.3%2C146.7c0%2C10%2C4.1%2C15%2C12.4%2C15c7.4%2C0%2C14.7-1.2%2C21.8-3.7l3.7-1.3v-26.9l-24.1%2C2.3c-4.9%2C0.4-8.4%2C1.8-10.6%2C4.2%26%2310%3B%26%239%3B%26%239%3B%26%239%3BC394.4%2C138.7%2C393.3%2C142.2%2C393.3%2C146.7z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M491.2%2C98.2c-11.8%2C0-17.8%2C4.1-17.8%2C12.4c0%2C3.8%2C1.4%2C6.5%2C4.1%2C8.1c2.7%2C1.6%2C8.9%2C3.2%2C18.6%2C4.9%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc9.7%2C1.7%2C16.5%2C4%2C20.5%2C7.1c4%2C3%2C6%2C8.7%2C6%2C17.1c0%2C8.4-2.7%2C14.5-8.1%2C18.4c-5.4%2C3.9-13.2%2C5.9-23.6%2C5.9c-6.7%2C0-29.2-2.5-29.2-2.5%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bl0.7-10.6c12.9%2C1.2%2C22.3%2C2.2%2C28.6%2C2.2c6.3%2C0%2C11.1-1%2C14.4-3c3.3-2%2C5-5.4%2C5-10.1c0-4.7-1.4-7.9-4.2-9.6c-2.8-1.7-9-3.3-18.6-4.8%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-9.6-1.5-16.4-3.7-20.4-6.7c-4-2.9-6-8.4-6-16.3c0-7.9%2C2.8-13.8%2C8.4-17.6c5.6-3.8%2C12.6-5.7%2C20.9-5.7c6.6%2C0%2C29.6%2C1.7%2C29.6%2C1.7%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bv10.7C508.1%2C99%2C498.2%2C98.2%2C491.2%2C98.2z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M581.7%2C99.5h-25.9v39c0%2C9.3%2C0.7%2C15.5%2C2%2C18.4c1.4%2C2.9%2C4.6%2C4.4%2C9.7%2C4.4l14.5-1l0.8%2C10.1%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-7.3%2C1.2-12.8%2C1.8-16.6%2C1.8c-8.5%2C0-14.3-2.1-17.6-6.2c-3.3-4.1-4.9-12-4.9-23.6V99.5h-11.6V88.9h11.6V63.9h12.1v24.9h25.9V99.5z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M598.7%2C78.4V64.3h12.2v14.2H598.7z%20M598.7%2C171.4V88.9h12.2v82.5H598.7z%22%2F%3E%0A%20%20%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M663.8%2C87.2c3.6%2C0%2C9.7%2C0.7%2C18.3%2C2l3.9%2C0.5l-0.5%2C9.9c-8.7-1-15.1-1.5-19.2-1.5c-9.2%2C0-15.5%2C2.2-18.8%2C6.6%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-3.3%2C4.4-5%2C12.6-5%2C24.5c0%2C11.9%2C1.5%2C20.2%2C4.6%2C24.9c3.1%2C4.7%2C9.5%2C7%2C19.3%2C7l19.2-1.5l0.5%2C10.1c-10.1%2C1.5-17.7%2C2.3-22.7%2C2.3%26%2310%3B%26%239%3B%26%239%3B%26%239%3Bc-12.7%2C0-21.5-3.3-26.3-9.8c-4.8-6.5-7.3-17.5-7.3-33c0-15.5%2C2.6-26.4%2C7.8-32.6C643%2C90.4%2C651.7%2C87.2%2C663.8%2C87.2z%22%2F%3E%0A%20%20%20%20%3C%2Fg%3E%0A%20%20%20%20%3Cpath%20class%3D%22st0%22%20d%3D%22M236.6%2C123.5c0-19.8-12.3-37.2-30.8-43.9c0.8-4.2%2C1.2-8.4%2C1.2-12.7C207%2C30%2C177%2C0%2C140.2%2C0%26%2310%3B%26%239%3B%26%239%3BC118.6%2C0%2C98.6%2C10.3%2C86%2C27.7c-6.2-4.8-13.8-7.4-21.7-7.4c-19.6%2C0-35.5%2C15.9-35.5%2C35.5c0%2C4.3%2C0.8%2C8.5%2C2.2%2C12.4%26%2310%3B%26%239%3B%26%239%3BC12.6%2C74.8%2C0%2C92.5%2C0%2C112.2c0%2C19.9%2C12.4%2C37.3%2C30.9%2C44c-0.8%2C4.1-1.2%2C8.4-1.2%2C12.7c0%2C36.8%2C29.9%2C66.7%2C66.7%2C66.7%26%2310%3B%26%239%3B%26%239%3Bc21.6%2C0%2C41.6-10.4%2C54.1-27.8c6.2%2C4.9%2C13.8%2C7.6%2C21.7%2C7.6c19.6%2C0%2C35.5-15.9%2C35.5-35.5c0-4.3-0.8-8.5-2.2-12.4%26%2310%3B%26%239%3B%26%239%3BC223.9%2C160.9%2C236.6%2C143.2%2C236.6%2C123.5z%20M91.6%2C34.8c10.9-15.9%2C28.9-25.4%2C48.1-25.4c32.2%2C0%2C58.4%2C26.2%2C58.4%2C58.4%26%2310%3B%26%239%3B%26%239%3Bc0%2C3.9-0.4%2C7.7-1.1%2C11.5l-52.2%2C45.8L93%2C101.5L82.9%2C79.9L91.6%2C34.8z%20M65.4%2C29c6.2%2C0%2C12.1%2C2%2C17%2C5.7l-7.8%2C40.3l-35.5-8.4%26%2310%3B%26%239%3B%26%239%3Bc-1.1-3.1-1.7-6.3-1.7-9.7C37.4%2C41.6%2C49.9%2C29%2C65.4%2C29z%20M9.1%2C112.3c0-16.7%2C11-31.9%2C26.9-37.2L75%2C84.4l9.1%2C19.5l-49.8%2C45%26%2310%3B%26%239%3B%26%239%3BC19.2%2C143.1%2C9.1%2C128.6%2C9.1%2C112.3z%20M145.2%2C200.9c-10.9%2C16.1-29%2C25.6-48.4%2C25.6c-32.3%2C0-58.6-26.3-58.6-58.5c0-4%2C0.4-7.9%2C1.1-11.7%26%2310%3B%26%239%3B%26%239%3Bl50.9-46l52%2C23.7l11.5%2C22L145.2%2C200.9z%20M171.2%2C206.6c-6.1%2C0-12-2-16.9-5.8l7.7-40.2l35.4%2C8.3c1.1%2C3.1%2C1.7%2C6.3%2C1.7%2C9.7%26%2310%3B%26%239%3B%26%239%3BC199.2%2C194.1%2C186.6%2C206.6%2C171.2%2C206.6z%20M200.5%2C160.5l-39-9.1l-10.4-19.8l51-44.7c15.1%2C5.7%2C25.2%2C20.2%2C25.2%2C36.5%26%2310%3B%26%239%3B%26%239%3BC227.4%2C140.1%2C216.4%2C155.3%2C200.5%2C160.5z%22%2F%3E%0A%20%20%3C%2Fg%3E%0A%3C%2Fsvg%3E'; From 29e37124349027a3cbe9e1abe74b92c1d3c1cc81 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 17:50:39 +0300 Subject: [PATCH 52/77] removed httpurl. --- .../uis/arguments/image_upload/index.js | 7 +++-- .../plugins/canvas/common/lib/httpurl.test.ts | 31 ------------------- x-pack/plugins/canvas/common/lib/httpurl.ts | 13 -------- x-pack/plugins/canvas/common/lib/index.ts | 1 - x-pack/plugins/canvas/common/lib/url.ts | 6 ++-- 5 files changed, 9 insertions(+), 49 deletions(-) delete mode 100644 x-pack/plugins/canvas/common/lib/httpurl.test.ts delete mode 100644 x-pack/plugins/canvas/common/lib/httpurl.ts diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js index a4b3191c90d61..e8ee2c25e75c3 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js @@ -11,8 +11,11 @@ import { EuiSpacer, EuiFormRow, EuiButtonGroup } from '@elastic/eui'; import { get } from 'lodash'; import { AssetPicker } from '../../../../public/components/asset_picker'; import { resolveFromArgs } from '../../../../common/lib/resolve_dataurl'; -import { isValidHttpUrl } from '../../../../common/lib/httpurl'; -import { encode, elasticOutline } from '../../../../../../../src/plugins/presentation_util/public'; +import { + encode, + elasticOutline, + isValidHttpUrl, +} from '../../../../../../../src/plugins/presentation_util/public'; import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component'; import { VALID_IMAGE_TYPES } from '../../../../common/lib/constants'; import { ArgumentStrings } from '../../../../i18n'; diff --git a/x-pack/plugins/canvas/common/lib/httpurl.test.ts b/x-pack/plugins/canvas/common/lib/httpurl.test.ts deleted file mode 100644 index 1cd00114bf7ca..0000000000000 --- a/x-pack/plugins/canvas/common/lib/httpurl.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { isValidHttpUrl } from './httpurl'; - -describe('httpurl.isValidHttpUrl', () => { - it('matches HTTP URLs', () => { - expect(isValidHttpUrl('http://server.com/veggie/hamburger.jpg')).toBe(true); - expect(isValidHttpUrl('https://server.com:4443/veggie/hamburger.jpg')).toBe(true); - expect(isValidHttpUrl('http://user:password@server.com:4443/veggie/hamburger.jpg')).toBe(true); - expect(isValidHttpUrl('http://virtual-machine/veggiehamburger.jpg')).toBe(true); - expect(isValidHttpUrl('https://virtual-machine:44330/veggie.jpg?hamburger')).toBe(true); - expect(isValidHttpUrl('http://192.168.1.50/veggie/hamburger.jpg')).toBe(true); - expect(isValidHttpUrl('https://2600::/veggie/hamburger.jpg')).toBe(true); // ipv6 - expect(isValidHttpUrl('http://2001:4860:4860::8844/veggie/hamburger.jpg')).toBe(true); // ipv6 - }); - it('rejects non-HTTP URLs', () => { - expect(isValidHttpUrl('')).toBe(false); - expect(isValidHttpUrl('http://server.com')).toBe(false); - expect(isValidHttpUrl('file:///Users/programmer/Pictures/hamburger.jpeg')).toBe(false); - expect(isValidHttpUrl('ftp://hostz.com:1111/path/to/image.png')).toBe(false); - expect(isValidHttpUrl('ftp://user:password@host:1111/path/to/image.png')).toBe(false); - expect( - isValidHttpUrl('data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+...') - ).toBe(false); - }); -}); diff --git a/x-pack/plugins/canvas/common/lib/httpurl.ts b/x-pack/plugins/canvas/common/lib/httpurl.ts deleted file mode 100644 index 4f8b03aa2a062..0000000000000 --- a/x-pack/plugins/canvas/common/lib/httpurl.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -// A cheap regex to distinguish an HTTP URL string from a data URL string -const httpurlRegex = /^https?:\/\/\S+(?:[0-9]+)?\/\S{1,}/; - -export function isValidHttpUrl(str: string): boolean { - return httpurlRegex.test(str); -} diff --git a/x-pack/plugins/canvas/common/lib/index.ts b/x-pack/plugins/canvas/common/lib/index.ts index 6471a0d39139e..c25ec858df350 100644 --- a/x-pack/plugins/canvas/common/lib/index.ts +++ b/x-pack/plugins/canvas/common/lib/index.ts @@ -15,7 +15,6 @@ export * from './fonts'; export * from './get_field_type'; export * from './get_legend_config'; export * from './hex_to_rgb'; -export * from './httpurl'; export * from './missing_asset'; export * from './palettes'; export * from './pivot_object_array'; diff --git a/x-pack/plugins/canvas/common/lib/url.ts b/x-pack/plugins/canvas/common/lib/url.ts index 5050651472ea5..62cc5a9bcfe48 100644 --- a/x-pack/plugins/canvas/common/lib/url.ts +++ b/x-pack/plugins/canvas/common/lib/url.ts @@ -5,8 +5,10 @@ * 2.0. */ -import { isValidDataUrl } from '../../../../../src/plugins/presentation_util/common'; -import { isValidHttpUrl } from '../../common/lib/httpurl'; +import { + isValidDataUrl, + isValidHttpUrl, +} from '../../../../../src/plugins/presentation_util/common'; export function isValidUrl(url: string) { return isValidDataUrl(url) || isValidHttpUrl(url); From 4f2b9f9533056cd8213e3be8e296d903f6fd57dd Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 17:52:51 +0300 Subject: [PATCH 53/77] Removed missing_asset. --- x-pack/plugins/canvas/common/lib/index.ts | 1 - x-pack/plugins/canvas/common/lib/missing_asset.ts | 3 --- x-pack/plugins/canvas/common/lib/resolve_dataurl.test.js | 2 +- x-pack/plugins/canvas/common/lib/resolve_dataurl.ts | 2 +- x-pack/plugins/canvas/common/lib/url.test.ts | 2 +- 5 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 x-pack/plugins/canvas/common/lib/missing_asset.ts diff --git a/x-pack/plugins/canvas/common/lib/index.ts b/x-pack/plugins/canvas/common/lib/index.ts index c25ec858df350..ddc705bb7b67d 100644 --- a/x-pack/plugins/canvas/common/lib/index.ts +++ b/x-pack/plugins/canvas/common/lib/index.ts @@ -15,7 +15,6 @@ export * from './fonts'; export * from './get_field_type'; export * from './get_legend_config'; export * from './hex_to_rgb'; -export * from './missing_asset'; export * from './palettes'; export * from './pivot_object_array'; export * from './resolve_dataurl'; diff --git a/x-pack/plugins/canvas/common/lib/missing_asset.ts b/x-pack/plugins/canvas/common/lib/missing_asset.ts deleted file mode 100644 index d47648b44059c..0000000000000 --- a/x-pack/plugins/canvas/common/lib/missing_asset.ts +++ /dev/null @@ -1,3 +0,0 @@ -/* eslint-disable */ -// CC0, source: https://pixabay.com/en/question-mark-confirmation-question-838656/ -export const missingImage = 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHZpZXdCb3g9IjAgMCAzMSAzMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZGVmcz48ZmlsdGVyIGlkPSJiIiB4PSItLjM2IiB5PSItLjM2IiB3aWR0aD0iMS43MiIgaGVpZ2h0PSIxLjcyIiBjb2xvci1pbnRlcnBvbGF0aW9uLWZpbHRlcnM9InNSR0IiPjxmZUdhdXNzaWFuQmx1ciBzdGREZXZpYXRpb249IjIuNDY0Ii8+PC9maWx0ZXI+PGxpbmVhckdyYWRpZW50IGlkPSJhIiB4MT0iMTU5LjM0IiB4Mj0iMTg0LjQ4IiB5MT0iNzI3LjM2IiB5Mj0iNzQ5Ljg5IiBncmFkaWVudFRyYW5zZm9ybT0idHJhbnNsYXRlKC0xMTEuNTMgLTU0OS42OCkgc2NhbGUoLjc3MDAyKSIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPjxzdG9wIHN0b3AtY29sb3I9IiNlYmYwZWQiIG9mZnNldD0iMCIvPjxzdG9wIHN0b3AtY29sb3I9IiNmYWZhZmEiIG9mZnNldD0iMSIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxwYXRoIGQ9Ik0xNS40MzcgMi42OTVsMTQuNTA2IDI0LjQ3NkgxLjI4N2wxNC4xNS0yNC40NzZ6IiBmaWxsPSJ1cmwoI2EpIiBzdHJva2U9InJlZCIgc3Ryb2tlLWxpbmVjYXA9InNxdWFyZSIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIyIi8+PHBhdGggdHJhbnNmb3JtPSJtYXRyaXgoLjgzMTk3IDAgMCAuNTU0NjYgLTc4LjU4MyAtMzgzLjUxKSIgZD0iTTExMS4zMSA3MzEuMmMtMy4yODMtMy45MjUtMy41OTUtNi4xNDgtMi4wMjQtMTAuNDM4IDMuMzM2LTYuMTQ1IDQuNDk2LTguMDY4IDUuNDEtOS40MDUgMS45MDEgNS4xNjIgMi4xMjYgMTkuMTQtMy4zODYgMTkuODQzeiIgZmlsbD0iI2ZmZiIgZmlsbC1vcGFjaXR5PSIuODc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGZpbHRlcj0idXJsKCNiKSIvPjxnIGZpbGwtb3BhY2l0eT0iLjgyIj48cGF0aCBkPSJNMTUuMDQ2IDIwLjIyN2gtLjQxNWMtLjAxMy0uNzQ4LjAyLTEuMzA4LjEwMS0xLjY3OC4wODgtLjM3MS4zMDctLjg4LjY1OC0xLjUyOC4zNTctLjY1NC41OS0xLjE3Ni42OTctMS41NjcuMTE1LS4zOTguMTcyLS44ODcuMTcyLTEuNDY3IDAtLjg5Ni0uMTc1LTEuNTU3LS41MjYtMS45ODItLjM1LS40MjUtLjc2NS0uNjM3LTEuMjQ0LS42MzctLjM2NCAwLS42Ny4wOTgtLjkyLjI5My0uMTg5LjE0OS0uMjgzLjMwNC0uMjgzLjQ2NiAwIC4xMDcuMDY0LjI3Ni4xOTIuNTA1LjI5LjUyLjQzNS45NjEuNDM1IDEuMzI1IDAgLjMzLS4xMTUuNjA3LS4zNDQuODNhMS4xMzggMS4xMzggMCAwIDEtLjg0LjMzM2MtLjM3NyAwLS42OTQtLjEzMS0uOTUtLjM5NC0uMjU2LS4yNy0uMzg0LS42MjQtLjM4NC0xLjA2MiAwLS43OTYuMzQ0LTEuNDk0IDEuMDMxLTIuMDk0LjY4OC0uNiAxLjY0OS0uOSAyLjg4My0uOSAxLjMwOCAwIDIuMzAyLjMxNCAyLjk4My45NC42ODguNjIxIDEuMDMyIDEuMzczIDEuMDMyIDIuMjU2IDAgLjY0LS4xNzYgMS4yMzQtLjUyNiAxLjc4LS4zNTEuNTQtMS4wMjkgMS4xNC0yLjAzMyAxLjgtLjY3NC40NDUtMS4xMi44NDMtMS4zMzUgMS4xOTQtLjIxLjM0My0uMzM3Ljg3My0uMzg0IDEuNTg3bS0uMTEyIDEuNDc3Yy40NTIgMCAuODM2LjE1OCAxLjE1My40NzUuMzE3LjMxNy40NzYuNzAxLjQ3NiAxLjE1MyAwIC40NTItLjE1OS44NC0uNDc2IDEuMTYzYTEuNTcgMS41NyAwIDAgMS0xLjE1My40NzUgMS41NyAxLjU3IDAgMCAxLTEuMTUzLS40NzUgMS42MDQgMS42MDQgMCAwIDEtLjQ3NS0xLjE2M2MwLS40NTIuMTU5LS44MzYuNDc1LTEuMTUzYTEuNTcgMS41NyAwIDAgMSAxLjE1My0uNDc1IiBmaWxsPSIjZmZmIiBmaWxsLW9wYWNpdHk9Ii40ODYiLz48cGF0aCBkPSJNMTUuMzI3IDIwLjUwOGgtLjQxNWMtLjAxMy0uNzQ4LjAyLTEuMzA4LjEwMS0xLjY3OC4wODgtLjM3MS4zMDctLjg4LjY1OC0xLjUyOC4zNTctLjY1NC41OS0xLjE3Ni42OTctMS41NjcuMTE1LS4zOTguMTcyLS44ODcuMTcyLTEuNDY2IDAtLjg5Ny0uMTc1LTEuNTU4LS41MjYtMS45ODMtLjM1LS40MjQtLjc2NS0uNjM3LTEuMjQzLS42MzctLjM2NSAwLS42NzEuMDk4LS45Mi4yOTMtLjE5LjE0OS0uMjg0LjMwNC0uMjg0LjQ2NiAwIC4xMDguMDY0LjI3Ni4xOTIuNTA1LjI5LjUyLjQzNS45NjEuNDM1IDEuMzI1IDAgLjMzLS4xMTUuNjA3LS4zNDQuODNhMS4xMzggMS4xMzggMCAwIDEtLjg0LjMzM2MtLjM3NyAwLS42OTQtLjEzMS0uOTUtLjM5NC0uMjU2LS4yNy0uMzg0LS42MjQtLjM4NC0xLjA2MiAwLS43OTYuMzQ0LTEuNDkzIDEuMDMxLTIuMDk0LjY4OC0uNiAxLjY0OS0uOSAyLjg4My0uOSAxLjMwOCAwIDIuMzAyLjMxNCAyLjk4My45NC42ODguNjIxIDEuMDMyIDEuMzczIDEuMDMyIDIuMjU2IDAgLjY0LS4xNzYgMS4yMzQtLjUyNiAxLjc4LS4zNS41NC0xLjAyOCAxLjE0LTIuMDMzIDEuOC0uNjc0LjQ0NS0uODUzLjg0My0xLjA2OCAxLjE5NC0uMjEuMzQzLS4zMzcuODczLS4zODUgMS41ODdtLS4zNzggMS40NzdjLjQ1MiAwIC44MzYuMTU4IDEuMTUzLjQ3NS4zMTcuMzE3LjQ3Ni43MDEuNDc2IDEuMTUzIDAgLjQ1Mi0uMTU5Ljg0LS40NzYgMS4xNjNhMS41NyAxLjU3IDAgMCAxLTEuMTUzLjQ3NiAxLjU3IDEuNTcgMCAwIDEtMS4xNTMtLjQ3NiAxLjYwNCAxLjYwNCAwIDAgMS0uNDc1LTEuMTYzYzAtLjQ1Mi4xNTktLjgzNi40NzUtMS4xNTNhMS41NyAxLjU3IDAgMCAxIDEuMTUzLS40NzUiIGZpbGwtb3BhY2l0eT0iLjgyIi8+PC9nPjwvc3ZnPg=='; diff --git a/x-pack/plugins/canvas/common/lib/resolve_dataurl.test.js b/x-pack/plugins/canvas/common/lib/resolve_dataurl.test.js index 72aaa1dfbd502..e670edf5b3aca 100644 --- a/x-pack/plugins/canvas/common/lib/resolve_dataurl.test.js +++ b/x-pack/plugins/canvas/common/lib/resolve_dataurl.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { missingImage } from '../../common/lib/missing_asset'; +import { missingImage } from '../../../../../src/plugins/presentation_util/common'; import { resolveFromArgs, resolveWithMissingImage } from './resolve_dataurl'; describe('resolve_dataurl', () => { diff --git a/x-pack/plugins/canvas/common/lib/resolve_dataurl.ts b/x-pack/plugins/canvas/common/lib/resolve_dataurl.ts index 79e49c0595355..bb8931692af48 100644 --- a/x-pack/plugins/canvas/common/lib/resolve_dataurl.ts +++ b/x-pack/plugins/canvas/common/lib/resolve_dataurl.ts @@ -7,7 +7,7 @@ import { get } from 'lodash'; import { isValidUrl } from '../../common/lib/url'; -import { missingImage } from '../../common/lib/missing_asset'; +import { missingImage } from '../../../../../src/plugins/presentation_util/common'; /* * NOTE: args.dataurl can come as an expression here. diff --git a/x-pack/plugins/canvas/common/lib/url.test.ts b/x-pack/plugins/canvas/common/lib/url.test.ts index 654602eea2093..75fb7c07588cf 100644 --- a/x-pack/plugins/canvas/common/lib/url.test.ts +++ b/x-pack/plugins/canvas/common/lib/url.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { missingImage } from '../../common/lib/missing_asset'; +import { missingImage } from '../../../../../src/plugins/presentation_util/common'; import { isValidUrl } from './url'; describe('resolve_dataurl', () => { From 94dbd16c11fb6ef190c2f2fbbd1a52f8f5881e1c Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 17:58:53 +0300 Subject: [PATCH 54/77] removed url. --- .../functions/common/containerStyle.ts | 2 +- .../functions/common/image.ts | 7 ++-- .../functions/common/repeat_image.ts | 6 ++- .../canvas_plugin_src/renderers/image.tsx | 3 +- .../renderers/repeat_image.ts | 3 +- .../uis/arguments/image_upload/index.js | 2 +- .../canvas_plugin_src/uis/views/image.js | 6 ++- x-pack/plugins/canvas/common/lib/index.ts | 2 - .../canvas/common/lib/resolve_dataurl.test.js | 42 ------------------- .../canvas/common/lib/resolve_dataurl.ts | 33 --------------- x-pack/plugins/canvas/common/lib/url.test.ts | 22 ---------- x-pack/plugins/canvas/common/lib/url.ts | 15 ------- 12 files changed, 16 insertions(+), 127 deletions(-) delete mode 100644 x-pack/plugins/canvas/common/lib/resolve_dataurl.test.js delete mode 100644 x-pack/plugins/canvas/common/lib/resolve_dataurl.ts delete mode 100644 x-pack/plugins/canvas/common/lib/url.test.ts delete mode 100644 x-pack/plugins/canvas/common/lib/url.ts diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.ts index d30324e0e2bfe..64c11cd89115e 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.ts @@ -8,7 +8,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; import { ContainerStyle, Overflow, BackgroundRepeat, BackgroundSize } from '../../../types'; import { getFunctionHelp, getFunctionErrors } from '../../../i18n'; -import { isValidUrl } from '../../../common/lib/url'; +import { isValidUrl } from '../../../../../../src/plugins/presentation_util/common'; interface Output extends ContainerStyle { type: 'containerStyle'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts index 8e46cb63c91d8..3448ea6f577d8 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts @@ -7,9 +7,10 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; import { getFunctionHelp, getFunctionErrors } from '../../../i18n'; - -import { resolveWithMissingImage } from '../../../common/lib/resolve_dataurl'; -import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; +import { + elasticLogo, + resolveWithMissingImage, +} from '../../../../../../src/plugins/presentation_util/common'; export enum ImageMode { CONTAIN = 'contain', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts index e31fed86ff72a..8e663e5e3b918 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts @@ -6,8 +6,10 @@ */ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; -import { resolveWithMissingImage } from '../../../common/lib/resolve_dataurl'; -import { elasticOutline } from '../../../../../../src/plugins/presentation_util/common'; +import { + elasticOutline, + resolveWithMissingImage, +} from '../../../../../../src/plugins/presentation_util/common'; import { Render } from '../../../types'; import { getFunctionHelp } from '../../../i18n'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx index 97a63eed7ecf0..cc31201bac532 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx @@ -7,8 +7,7 @@ import ReactDOM from 'react-dom'; import React from 'react'; -import { elasticLogo } from '../../../../../src/plugins/presentation_util/common'; -import { isValidUrl } from '../../common/lib/url'; +import { elasticLogo, isValidUrl } from '../../../../../src/plugins/presentation_util/common'; import { Return as Arguments } from '../functions/common/image'; import { RendererStrings } from '../../i18n'; import { RendererFactory } from '../../types'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts b/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts index 730366f6a5fba..0bd2695487a3b 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts @@ -7,8 +7,7 @@ import $ from 'jquery'; import { times } from 'lodash'; -import { elasticOutline } from '../../../../../src/plugins/presentation_util/common'; -import { isValidUrl } from '../../common/lib/url'; +import { elasticOutline, isValidUrl } from '../../../../../src/plugins/presentation_util/common'; import { RendererStrings, ErrorStrings } from '../../i18n'; import { Return as Arguments } from '../functions/common/repeat_image'; import { RendererFactory } from '../../types'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js index e8ee2c25e75c3..480d8ea364c42 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/arguments/image_upload/index.js @@ -10,11 +10,11 @@ import PropTypes from 'prop-types'; import { EuiSpacer, EuiFormRow, EuiButtonGroup } from '@elastic/eui'; import { get } from 'lodash'; import { AssetPicker } from '../../../../public/components/asset_picker'; -import { resolveFromArgs } from '../../../../common/lib/resolve_dataurl'; import { encode, elasticOutline, isValidHttpUrl, + resolveFromArgs, } from '../../../../../../../src/plugins/presentation_util/public'; import { templateFromReactComponent } from '../../../../public/lib/template_from_react_component'; import { VALID_IMAGE_TYPES } from '../../../../common/lib/constants'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js index c6c06feea4605..937e6daa0b9d0 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js @@ -5,8 +5,10 @@ * 2.0. */ -import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; -import { resolveFromArgs } from '../../../common/lib/resolve_dataurl'; +import { + elasticLogo, + resolveFromArgs, +} from '../../../../../../src/plugins/presentation_util/common'; import { ViewStrings } from '../../../i18n'; const { Image: strings } = ViewStrings; diff --git a/x-pack/plugins/canvas/common/lib/index.ts b/x-pack/plugins/canvas/common/lib/index.ts index ddc705bb7b67d..a23b569640f5a 100644 --- a/x-pack/plugins/canvas/common/lib/index.ts +++ b/x-pack/plugins/canvas/common/lib/index.ts @@ -17,6 +17,4 @@ export * from './get_legend_config'; export * from './hex_to_rgb'; export * from './palettes'; export * from './pivot_object_array'; -export * from './resolve_dataurl'; export * from './unquote_string'; -export * from './url'; diff --git a/x-pack/plugins/canvas/common/lib/resolve_dataurl.test.js b/x-pack/plugins/canvas/common/lib/resolve_dataurl.test.js deleted file mode 100644 index e670edf5b3aca..0000000000000 --- a/x-pack/plugins/canvas/common/lib/resolve_dataurl.test.js +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { missingImage } from '../../../../../src/plugins/presentation_util/common'; -import { resolveFromArgs, resolveWithMissingImage } from './resolve_dataurl'; - -describe('resolve_dataurl', () => { - describe('resolveFromArgs', () => { - it('finds and returns the dataurl from args successfully', () => { - const args = { - name: 'dataurl', - argType: 'imageUpload', - dataurl: [missingImage, 'test2'], - }; - expect(resolveFromArgs(args)).toBe(missingImage); - }); - it('finds and returns null for invalid dataurl', () => { - const args = { - name: 'dataurl', - argType: 'imageUpload', - dataurl: ['invalid url', 'test2'], - }; - expect(resolveFromArgs(args)).toBe(null); - }); - }); - - describe('resolveWithMissingImage', () => { - it('returns valid dataurl', () => { - expect(resolveWithMissingImage(missingImage)).toBe(missingImage); - }); - it('returns missingImage for invalid dataurl', () => { - expect(resolveWithMissingImage('invalid dataurl')).toBe(missingImage); - }); - it('returns null for null dataurl', () => { - expect(resolveWithMissingImage(null)).toBe(null); - }); - }); -}); diff --git a/x-pack/plugins/canvas/common/lib/resolve_dataurl.ts b/x-pack/plugins/canvas/common/lib/resolve_dataurl.ts deleted file mode 100644 index bb8931692af48..0000000000000 --- a/x-pack/plugins/canvas/common/lib/resolve_dataurl.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { get } from 'lodash'; -import { isValidUrl } from '../../common/lib/url'; -import { missingImage } from '../../../../../src/plugins/presentation_util/common'; - -/* - * NOTE: args.dataurl can come as an expression here. - * For example: - * [{"type":"expression","chain":[{"type":"function","function":"asset","arguments":{"_":["..."]}}]}] - */ -export const resolveFromArgs = (args: any, defaultDataurl: string | null = null): string => { - const dataurl = get(args, 'dataurl.0', null); - return isValidUrl(dataurl) ? dataurl : defaultDataurl; -}; - -export const resolveWithMissingImage = ( - img: string | null, - alt: string | null = null -): string | null => { - if (img !== null && isValidUrl(img)) { - return img; - } - if (img === null) { - return alt; - } - return missingImage; -}; diff --git a/x-pack/plugins/canvas/common/lib/url.test.ts b/x-pack/plugins/canvas/common/lib/url.test.ts deleted file mode 100644 index 75fb7c07588cf..0000000000000 --- a/x-pack/plugins/canvas/common/lib/url.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { missingImage } from '../../../../../src/plugins/presentation_util/common'; -import { isValidUrl } from './url'; - -describe('resolve_dataurl', () => { - it('returns valid dataurl', () => { - expect(isValidUrl(missingImage)).toBe(true); - }); - it('returns valid http url', () => { - const httpurl = 'https://test.com/s/'; - expect(isValidUrl(httpurl)).toBe(true); - }); - it('returns false for invalid url', () => { - expect(isValidUrl('test')).toBe(false); - }); -}); diff --git a/x-pack/plugins/canvas/common/lib/url.ts b/x-pack/plugins/canvas/common/lib/url.ts deleted file mode 100644 index 62cc5a9bcfe48..0000000000000 --- a/x-pack/plugins/canvas/common/lib/url.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - isValidDataUrl, - isValidHttpUrl, -} from '../../../../../src/plugins/presentation_util/common'; - -export function isValidUrl(url: string) { - return isValidDataUrl(url) || isValidHttpUrl(url); -} From ce8c17b0b9eff268accfa47f838c100be6764bd4 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Thu, 17 Jun 2021 18:11:59 +0300 Subject: [PATCH 55/77] replaced mostly all tests. --- .../canvas_plugin_src/functions/browser/markdown.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/all.test.js | 2 +- .../canvas_plugin_src/functions/common/alterColumn.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/any.test.js | 3 +-- .../canvas/canvas_plugin_src/functions/common/as.test.js | 2 +- .../canvas_plugin_src/functions/common/axis_config.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/case.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/clear.test.js | 3 +-- .../canvas_plugin_src/functions/common/columns.test.js | 2 +- .../canvas_plugin_src/functions/common/compare.test.js | 2 +- .../functions/common/container_style.test.js | 6 ++++-- .../canvas_plugin_src/functions/common/context.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/date.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/do.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/eq.test.js | 2 +- .../canvas_plugin_src/functions/common/exactly.test.js | 2 +- .../canvas_plugin_src/functions/common/filterrows.test.js | 2 +- .../canvas_plugin_src/functions/common/formatdate.test.js | 2 +- .../canvas_plugin_src/functions/common/formatnumber.test.js | 2 +- .../canvas_plugin_src/functions/common/getCell.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/gt.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/gte.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/head.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/if.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/image.test.js | 2 -- .../canvas_plugin_src/functions/common/join_rows.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/lt.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/lte.test.js | 2 +- .../canvas_plugin_src/functions/common/metric.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/neq.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/ply.test.js | 2 +- .../canvas_plugin_src/functions/common/progress.test.js | 2 +- .../canvas_plugin_src/functions/common/render.test.js | 2 +- .../canvas_plugin_src/functions/common/repeat_image.test.js | 2 +- .../canvas_plugin_src/functions/common/replace.test.js | 2 +- .../canvas_plugin_src/functions/common/rounddate.test.js | 2 +- .../canvas_plugin_src/functions/common/rowCount.test.js | 2 +- .../canvas_plugin_src/functions/common/series_style.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/sort.test.js | 2 +- .../canvas_plugin_src/functions/common/staticColumn.test.js | 2 +- .../canvas_plugin_src/functions/common/string.test.js | 2 +- .../canvas_plugin_src/functions/common/switch.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/table.test.js | 2 +- .../canvas/canvas_plugin_src/functions/common/tail.test.js | 2 +- .../canvas_plugin_src/functions/common/timefilter.test.js | 2 +- .../functions/common/timefilter_control.test.js | 2 +- x-pack/plugins/canvas/public/functions/pie.test.js | 2 +- x-pack/plugins/canvas/public/functions/plot.test.js | 2 +- 48 files changed, 50 insertions(+), 52 deletions(-) diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.test.js index 0e7a1afb0dbb1..dff9e1eba687e 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { testTable } from '../common/__fixtures__/test_tables'; import { fontStyle } from '../common/__fixtures__/test_styles'; import { markdown } from './markdown'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.test.js index c09c3ff99d89c..a5ea4984e4aba 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { all } from './all'; describe('all', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.test.js index 7e018427dc4c7..78c8c8641ce1e 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { alterColumn } from './alterColumn'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.test.js index d95029fef8144..006dae5c0f9e7 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.test.js @@ -4,8 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { any } from './any'; describe('any', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.test.js index e7c2d3047bb91..311c0ff4f2d03 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { asFn } from './as'; describe('as', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axis_config.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axis_config.test.js index 491558486eb44..0708a0ba4d5de 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axis_config.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axis_config.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { testTable } from './__fixtures__/test_tables'; import { axisConfig } from './axisConfig'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.test.js index adee8a56dea49..5c4c91aa25176 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { caseFn } from './case'; describe('case', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clear.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clear.test.js index 43c24f10c0465..35449eadb20e1 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clear.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clear.test.js @@ -4,8 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { testTable } from './__fixtures__/test_tables'; import { clear } from './clear'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.test.js index d76c7a9174b81..acf1ede483696 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { columns } from './columns'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.test.js index b0d80debf4ec3..9a7d6ea9b23fb 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { compare } from './compare'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js index 5e097bf0c3ebe..00a33e628f2a5 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js @@ -5,8 +5,10 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; -import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; +import { + elasticLogo, + functionWrapper, +} from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { containerStyle } from './containerStyle'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/context.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/context.test.js index 7cefb41754fd4..cc97dd0ffaefd 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/context.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/context.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { testTable, emptyTable } from './__fixtures__/test_tables'; import { context } from './context'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.test.js index 08c43caaf8b9e..af2261b421ae4 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.test.js @@ -6,7 +6,7 @@ */ import sinon from 'sinon'; -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { date } from './date'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.test.js index f19318753611c..30ea031fec98f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { doFn } from './do'; describe('do', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.test.js index 5f8d9e042125f..bb2b31805a577 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { eq } from './eq'; describe('eq', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.test.js index 10781a7af452d..5ae43fb3076fa 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { emptyFilter } from './__fixtures__/test_filters'; import { exactly } from './exactly'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.test.js index 8c328e3d8adf6..c97f592aaed18 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { testTable } from './__fixtures__/test_tables'; import { filterrows } from './filterrows'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.test.js index 6fda32dfef51a..24ee5edcb33a9 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { formatdate } from './formatdate'; describe('formatdate', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.test.js index 37d3d2d905e67..47efec2f29ac2 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { formatnumber } from './formatnumber'; describe('formatnumber', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.test.js index 2dda4d8f4258e..35013506db533 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { getCell } from './getCell'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.test.js index 576d2a54dd59b..34f563fb2c7fc 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { gt } from './gt'; describe('gt', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.test.js index 174f617f47a8c..192c994ee972f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { gte } from './gte'; describe('gte', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/head.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/head.test.js index c25d0f7ae727f..d64ea6d512ed5 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/head.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/head.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { head } from './head'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.test.js index cab331807e44c..c867df9aa5052 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { ifFn } from './if'; describe('if', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js index 89788d900d3c1..d68228ac31346 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js @@ -6,7 +6,6 @@ */ import expect from '@kbn/expect'; -// import { functionWrapper } from '../../../test_helpers/function_wrapper'; import { elasticLogo, elasticOutline, @@ -15,7 +14,6 @@ import { // TODO: the test was not running and is not up to date describe.skip('image', () => { - // const fn = functionWrapper(image); const fn = jest.fn(); it('returns an image object using a dataUrl', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/join_rows.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/join_rows.test.js index 12b1002d1e377..1bb41078c0564 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/join_rows.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/join_rows.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { testTable } from './__fixtures__/test_tables'; import { joinRows } from './join_rows'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.test.js index 8f16e446997ea..e49a4ce9f498e 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { lt } from './lt'; describe('lt', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.test.js index 954b30e8c3c92..d4b6c59aaa3d6 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { lte } from './lte'; describe('lte', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.test.js index a99d4823e5930..97598196df88a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { fontStyle } from './__fixtures__/test_styles'; import { metric } from './metric'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.test.js index 0a1980760cd09..92d1181be73ee 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { neq } from './neq'; describe('neq', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.test.js index 5bf100eb90f4c..a8e0980560c11 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { testTable } from './__fixtures__/test_tables'; import { ply } from './ply'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.test.js index f516cbbe5258f..4bf305a14aa7c 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.test.js @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { progress } from './progress'; import { fontStyle } from './__fixtures__/test_styles'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.test.js index 6a91f4c280692..8153fe5861382 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { DEFAULT_ELEMENT_CSS } from '../../../common/lib/constants'; import { testTable } from './__fixtures__/test_tables'; import { fontStyle, containerStyle } from './__fixtures__/test_styles'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js index 7d00c6c9e3642..367cd338409e3 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js @@ -5,10 +5,10 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; import { elasticLogo, elasticOutline, + functionWrapper, } from '../../../../../../src/plugins/presentation_util/common'; import { repeatImage } from './repeat_image'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/replace.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/replace.test.js index 26e44f48f685d..ce1ed4805d95f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/replace.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/replace.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { replace } from './replace'; describe('replace', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.test.js index f2c2f8af50a81..63302b7e42f76 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { rounddate } from './rounddate'; describe('rounddate', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.test.js index b47bb662f43d4..5b4ca82206c88 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { rowCount } from './rowCount'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/series_style.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/series_style.test.js index ebd1f370db343..889aa403c9390 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/series_style.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/series_style.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { seriesStyle } from './seriesStyle'; describe('seriesStyle', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.test.js index 97f8b20c57efa..500123315afd2 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { testTable } from './__fixtures__/test_tables'; import { sort } from './sort'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.test.js index 3a3bb46e4d395..1cd11bdb54af1 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { testTable, emptyTable } from './__fixtures__/test_tables'; import { staticColumn } from './staticColumn'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.test.js index c598c036bcaa9..63b63b4c72113 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { string } from './string'; describe('string', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.test.js index 7a6d483d6c72b..b07170b40d039 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { switchFn } from './switch'; describe('switch', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/table.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/table.test.js index 2eff610ac8ee5..8689c696ef3eb 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/table.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/table.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { testTable } from './__fixtures__/test_tables'; import { fontStyle } from './__fixtures__/test_styles'; import { table } from './table'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.test.js index 93461a2ef4575..d3ec242399798 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { tail } from './tail'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.test.js index e45a11b786d19..12e197e0de540 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.test.js @@ -6,7 +6,7 @@ */ import sinon from 'sinon'; -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { emptyFilter } from './__fixtures__/test_filters'; import { timefilter } from './timefilter'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter_control.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter_control.test.js index cf2c316507c35..23c492bada49f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter_control.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter_control.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { timefilterControl } from './timefilterControl'; describe('timefilterControl', () => { diff --git a/x-pack/plugins/canvas/public/functions/pie.test.js b/x-pack/plugins/canvas/public/functions/pie.test.js index b1c1746340892..cd4b42138859e 100644 --- a/x-pack/plugins/canvas/public/functions/pie.test.js +++ b/x-pack/plugins/canvas/public/functions/pie.test.js @@ -5,8 +5,8 @@ * 2.0. */ -import { functionWrapper } from '../../test_helpers/function_wrapper'; import { testPie } from '../../canvas_plugin_src/functions/common/__fixtures__/test_pointseries'; +import { functionWrapper } from '../../../../../src/plugins/presentation_util/common'; import { fontStyle, grayscalePalette, diff --git a/x-pack/plugins/canvas/public/functions/plot.test.js b/x-pack/plugins/canvas/public/functions/plot.test.js index 5ed858961d798..7f9c43d027ee9 100644 --- a/x-pack/plugins/canvas/public/functions/plot.test.js +++ b/x-pack/plugins/canvas/public/functions/plot.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../src/plugins/presentation_util/common'; import { testPlot } from '../../canvas_plugin_src/functions/common/__fixtures__/test_pointseries'; import { fontStyle, From 7dc4ae53422ba3b35471d79010f1e3b1a51f8d3b Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 09:09:27 +0300 Subject: [PATCH 56/77] Fixed types. --- .../generate_function_reference.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/canvas/public/components/function_reference_generator/generate_function_reference.ts b/x-pack/plugins/canvas/public/components/function_reference_generator/generate_function_reference.ts index 8f9b3923ff120..075e65bc24dab 100644 --- a/x-pack/plugins/canvas/public/components/function_reference_generator/generate_function_reference.ts +++ b/x-pack/plugins/canvas/public/components/function_reference_generator/generate_function_reference.ts @@ -10,7 +10,8 @@ import pluralize from 'pluralize'; import { ExpressionFunction, ExpressionFunctionParameter } from 'src/plugins/expressions'; import { functions as browserFunctions } from '../../../canvas_plugin_src/functions/browser'; import { functions as serverFunctions } from '../../../canvas_plugin_src/functions/server'; -import { isValidDataUrl, DATATABLE_COLUMN_TYPES } from '../../../common/lib'; +import { DATATABLE_COLUMN_TYPES } from '../../../common/lib'; +import { isValidDataUrl } from '../../../../../../src/plugins/presentation_util/public'; import { getFunctionExamples, FunctionExample } from './function_examples'; const ALPHABET = 'abcdefghijklmnopqrstuvwxyz'.split(''); From b2cd92338d5accc97d7241f6522588a838df1a57 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 09:26:51 +0300 Subject: [PATCH 57/77] Fixed types and removed function_wrapper.ts --- .../common/test_helpers/function_wrapper.ts | 8 ++------ .../functions/common/csv.test.ts | 2 +- .../functions/common/dropdown_control.test.ts | 2 +- .../canvas/test_helpers/function_wrapper.js | 19 ------------------- 4 files changed, 4 insertions(+), 27 deletions(-) delete mode 100644 x-pack/plugins/canvas/test_helpers/function_wrapper.js diff --git a/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts b/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts index 601b02ff11793..25c82db7f273f 100644 --- a/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts +++ b/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts @@ -8,13 +8,9 @@ import { mapValues } from 'lodash'; import { ExpressionFunctionDefinition, ExpressionValueRender } from '../../../expressions'; +import { typeSpecs } from '../../../expressions/common'; -type FnType = () => ExpressionFunctionDefinition< - string, - number, - Record, - ExpressionValueRender ->; +type FnType = () => typeof typeSpecs[number]; // It takes a function spec and passes in default args into the spec fn export const functionWrapper = (fnSpec: FnType): ReturnType['fn'] => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts index 93cf07a9dd5dd..8402e1026d295 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts @@ -6,7 +6,7 @@ */ // @ts-expect-error untyped lib -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { csv } from './csv'; import { Datatable } from 'src/plugins/expressions'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts index d8f2e8518daf0..ecf21619f9cac 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts @@ -6,7 +6,7 @@ */ // @ts-expect-error untyped local -import { functionWrapper } from '../../../test_helpers/function_wrapper'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { testTable, relationalTable } from './__fixtures__/test_tables'; import { dropdownControl } from './dropdownControl'; diff --git a/x-pack/plugins/canvas/test_helpers/function_wrapper.js b/x-pack/plugins/canvas/test_helpers/function_wrapper.js deleted file mode 100644 index d20cac18cbb54..0000000000000 --- a/x-pack/plugins/canvas/test_helpers/function_wrapper.js +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { mapValues } from 'lodash'; - -// It takes a function spec and passes in default args into the spec fn -export const functionWrapper = (fnSpec, mockReduxStore) => { - const spec = fnSpec(); - const defaultArgs = mapValues(spec.args, (argSpec) => { - return argSpec.default; - }); - - return (context, args, handlers) => - spec.fn(context, { ...defaultArgs, ...args }, handlers, mockReduxStore); -}; From cc7c509ced0aa51602ace2c67c6b16d50da5b9f6 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 09:59:00 +0300 Subject: [PATCH 58/77] Fixed types of test helpers. --- .../common/test_helpers/function_wrapper.ts | 7 +- .../functions/common/csv.test.ts | 80 +++++++++++++------ .../functions/common/dropdown_control.test.ts | 74 ++++++++++++----- 3 files changed, 112 insertions(+), 49 deletions(-) diff --git a/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts b/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts index 25c82db7f273f..00b4220b76500 100644 --- a/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts +++ b/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts @@ -7,10 +7,11 @@ */ import { mapValues } from 'lodash'; -import { ExpressionFunctionDefinition, ExpressionValueRender } from '../../../expressions'; -import { typeSpecs } from '../../../expressions/common'; +import { ExpressionFunctionDefinition } from '../../../expressions'; +import { ExpressionValueBoxed, typeSpecs } from '../../../expressions/common'; -type FnType = () => typeof typeSpecs[number]; +type FnType = () => typeof typeSpecs[number] & + ExpressionFunctionDefinition, ExpressionValueBoxed>; // It takes a function spec and passes in default args into the spec fn export const functionWrapper = (fnSpec: FnType): ReturnType['fn'] => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts index 8402e1026d295..dc3497b7db301 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts @@ -5,11 +5,11 @@ * 2.0. */ -// @ts-expect-error untyped lib import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { getFunctionErrors } from '../../../i18n'; import { csv } from './csv'; -import { Datatable } from 'src/plugins/expressions'; +import { Datatable, ExecutionContext, SerializableState } from 'src/plugins/expressions'; +import { Adapters } from 'src/plugins/inspector'; const errors = getFunctionErrors().csv; @@ -30,43 +30,59 @@ describe('csv', () => { it('should return a datatable', () => { expect( - fn(null, { - data: `name,number + fn( + null, + { + data: `name,number one,1 two,2 fourty two,42`, - }) + }, + {} as ExecutionContext + ) ).toEqual(expected); }); it('should allow custom delimiter', () => { expect( - fn(null, { - data: `name\tnumber + fn( + null, + { + data: `name\tnumber one\t1 two\t2 fourty two\t42`, - delimiter: '\t', - }) + delimiter: '\t', + }, + {} as ExecutionContext + ) ).toEqual(expected); expect( - fn(null, { - data: `name%SPLIT%number + fn( + null, + { + data: `name%SPLIT%number one%SPLIT%1 two%SPLIT%2 fourty two%SPLIT%42`, - delimiter: '%SPLIT%', - }) + delimiter: '%SPLIT%', + }, + {} as ExecutionContext + ) ).toEqual(expected); }); it('should allow custom newline', () => { expect( - fn(null, { - data: `name,number\rone,1\rtwo,2\rfourty two,42`, - newline: '\r', - }) + fn( + null, + { + data: `name,number\rone,1\rtwo,2\rfourty two,42`, + newline: '\r', + }, + {} as ExecutionContext + ) ).toEqual(expected); }); @@ -83,10 +99,14 @@ fourty two%SPLIT%42`, }; expect( - fn(null, { - data: `foo," bar ", baz, " buz " + fn( + null, + { + data: `foo," bar ", baz, " buz " 1,2,3,4`, - }) + }, + {} as ExecutionContext + ) ).toEqual(expectedResult); }); @@ -106,22 +126,30 @@ fourty two%SPLIT%42`, }; expect( - fn(null, { - data: `foo," bar ", baz, " buz " + fn( + null, + { + data: `foo," bar ", baz, " buz " 1," best ",3, " ok" " good", bad, better , " worst " `, - }) + }, + {} as ExecutionContext + ) ).toEqual(expectedResult); }); it('throws when given invalid csv', () => { expect(() => { - fn(null, { - data: `name,number + fn( + null, + { + data: `name,number one|1 two.2 fourty two,42`, - }); + }, + {} as ExecutionContext + ); }).toThrow(new RegExp(errors.invalidInputCSV().message)); }); }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts index ecf21619f9cac..8a69a16f7e65a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts @@ -5,23 +5,30 @@ * 2.0. */ -// @ts-expect-error untyped local import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; import { testTable, relationalTable } from './__fixtures__/test_tables'; import { dropdownControl } from './dropdownControl'; +import { ExecutionContext, SerializableState } from 'src/plugins/expressions'; +import { Adapters } from 'src/plugins/inspector'; describe('dropdownControl', () => { const fn = functionWrapper(dropdownControl); it('returns a render as dropdown_filter', () => { - expect(fn(testTable, { filterColumn: 'name', valueColumn: 'name' })).toHaveProperty( - 'type', - 'render' - ); - expect(fn(testTable, { filterColumn: 'name', valueColumn: 'name' })).toHaveProperty( - 'as', - 'dropdown_filter' - ); + expect( + fn( + testTable, + { filterColumn: 'name', valueColumn: 'name' }, + {} as ExecutionContext + ) + ).toHaveProperty('type', 'render'); + expect( + fn( + testTable, + { filterColumn: 'name', valueColumn: 'name' }, + {} as ExecutionContext + ) + ).toHaveProperty('as', 'dropdown_filter'); }); describe('args', () => { @@ -32,12 +39,24 @@ describe('dropdownControl', () => { unique.find(([value, label]) => value === name) ? unique : [...unique, [name, name]], [] ); - expect(fn(testTable, { valueColumn: 'name' }).value.choices).toEqual(uniqueNames); + expect( + fn( + testTable, + { valueColumn: 'name' }, + {} as ExecutionContext + )?.value?.choices + ).toEqual(uniqueNames); }); it('returns an empty array when provided an invalid column', () => { - expect(fn(testTable, { valueColumn: 'foo' }).value.choices).toEqual([]); - expect(fn(testTable, { valueColumn: '' }).value.choices).toEqual([]); + expect( + fn(testTable, { valueColumn: 'foo' }, {} as ExecutionContext) + ?.value?.choices + ).toEqual([]); + expect( + fn(testTable, { valueColumn: '' }, {} as ExecutionContext) + ?.value?.choices + ).toEqual([]); }); }); @@ -45,7 +64,11 @@ describe('dropdownControl', () => { it('populates dropdown choices with labels from label column', () => { const expectedChoices = relationalTable.rows.map((row) => [row.id, row.name]); expect( - fn(relationalTable, { valueColumn: 'id', labelColumn: 'name' }).value.choices + fn( + relationalTable, + { valueColumn: 'id', labelColumn: 'name' }, + {} as ExecutionContext + )?.value?.choices ).toEqual(expectedChoices); }); }); @@ -53,19 +76,30 @@ describe('dropdownControl', () => { describe('filterColumn', () => { it('sets which column the filter is applied to', () => { - expect(fn(testTable, { filterColumn: 'name' }).value).toHaveProperty('column', 'name'); - expect(fn(testTable, { filterColumn: 'name', valueColumn: 'price' }).value).toHaveProperty( - 'column', - 'name' - ); + expect( + fn(testTable, { filterColumn: 'name' }, {} as ExecutionContext) + ?.value + ).toHaveProperty('column', 'name'); + expect( + fn( + testTable, + { filterColumn: 'name', valueColumn: 'price' }, + {} as ExecutionContext + )?.value + ).toHaveProperty('column', 'name'); }); it('defaults to valueColumn if not provided', () => { - expect(fn(testTable, { valueColumn: 'price' }).value).toHaveProperty('column', 'price'); + expect( + fn(testTable, { valueColumn: 'price' }, {} as ExecutionContext) + ?.value + ).toHaveProperty('column', 'price'); }); it('sets column to undefined if no args are provided', () => { - expect(fn(testTable).value).toHaveProperty('column', undefined); + expect( + fn(testTable, {}, {} as ExecutionContext)?.value + ).toHaveProperty('column', undefined); }); }); }); From 340093f53652e7bc21b19a0c1047f34886372281 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 10:33:12 +0300 Subject: [PATCH 59/77] Changed limits of presentationUtil plugin. --- packages/kbn-optimizer/limits.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 4b5abae02c6e3..cc41b1e0f5210 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -99,7 +99,7 @@ pageLoadAssetSize: watcher: 43598 runtimeFields: 41752 stackAlerts: 29684 - presentationUtil: 49767 + presentationUtil: 418850 spacesOss: 18817 indexPatternFieldEditor: 90489 osquery: 107090 @@ -112,4 +112,3 @@ pageLoadAssetSize: visTypePie: 35583 expressionRevealImage: 62826 cases: 144442 - \ No newline at end of file From 1e98dc0c447d6ddabd82b02335eace0d95df532d Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 13:40:16 +0300 Subject: [PATCH 60/77] Fixed imports. --- .../presentation_util/common/lib/resolve_dataurl.ts | 2 +- .../common/test_helpers/function_wrapper.ts | 7 +++++-- .../public/finder/saved_object_finder.tsx | 4 ++-- .../public/saved_object/helpers/apply_es_resp.ts | 10 +++++----- .../public/saved_object/helpers/create_source.ts | 4 ++-- .../saved_object/helpers/initialize_saved_object.ts | 6 +++--- .../saved_object/helpers/serialize_saved_object.ts | 4 ++-- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/plugins/presentation_util/common/lib/resolve_dataurl.ts b/src/plugins/presentation_util/common/lib/resolve_dataurl.ts index db94bdf04c32b..ff09eef98b18e 100644 --- a/src/plugins/presentation_util/common/lib/resolve_dataurl.ts +++ b/src/plugins/presentation_util/common/lib/resolve_dataurl.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { get } from 'lodash'; +import get from 'lodash/get'; import { isValidUrl } from './url'; import { missingImage } from './missing_asset'; diff --git a/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts b/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts index 00b4220b76500..ef5ed607ffd4e 100644 --- a/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts +++ b/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts @@ -7,8 +7,11 @@ */ import { mapValues } from 'lodash'; -import { ExpressionFunctionDefinition } from '../../../expressions'; -import { ExpressionValueBoxed, typeSpecs } from '../../../expressions/common'; +import { + ExpressionValueBoxed, + typeSpecs, + ExpressionFunctionDefinition, +} from '../../../expressions/common'; type FnType = () => typeof typeSpecs[number] & ExpressionFunctionDefinition, ExpressionValueBoxed>; diff --git a/src/plugins/saved_objects/public/finder/saved_object_finder.tsx b/src/plugins/saved_objects/public/finder/saved_object_finder.tsx index da65b5b9fdda8..0a2e4ff78be26 100644 --- a/src/plugins/saved_objects/public/finder/saved_object_finder.tsx +++ b/src/plugins/saved_objects/public/finder/saved_object_finder.tsx @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import _ from 'lodash'; +import { debounce } from 'lodash'; import PropTypes from 'prop-types'; import React from 'react'; @@ -116,7 +116,7 @@ class SavedObjectFinderUi extends React.Component< private isComponentMounted: boolean = false; - private debouncedFetch = _.debounce(async (query: string) => { + private debouncedFetch = debounce(async (query: string) => { const metaDataMap = this.getSavedObjectMetaDataMap(); const fields = Object.values(metaDataMap) diff --git a/src/plugins/saved_objects/public/saved_object/helpers/apply_es_resp.ts b/src/plugins/saved_objects/public/saved_object/helpers/apply_es_resp.ts index 1f2f7dc573dc7..40baff22f52c8 100644 --- a/src/plugins/saved_objects/public/saved_object/helpers/apply_es_resp.ts +++ b/src/plugins/saved_objects/public/saved_object/helpers/apply_es_resp.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import _ from 'lodash'; +import { cloneDeep, defaults, forOwn, assign } from 'lodash'; import { EsResponse, SavedObject, SavedObjectConfig, SavedObjectKibanaServices } from '../../types'; import { SavedObjectNotFound } from '../../../../kibana_utils/public'; import { @@ -28,7 +28,7 @@ export async function applyESResp( ) { const mapping = expandShorthand(config.mapping ?? {}); const savedObjectType = config.type || ''; - savedObject._source = _.cloneDeep(resp._source); + savedObject._source = cloneDeep(resp._source); if (typeof resp.found === 'boolean' && !resp.found) { throw new SavedObjectNotFound(savedObjectType, savedObject.id || ''); } @@ -42,10 +42,10 @@ export async function applyESResp( } // assign the defaults to the response - _.defaults(savedObject._source, savedObject.defaults); + defaults(savedObject._source, savedObject.defaults); // transform the source using _deserializers - _.forOwn(mapping, (fieldMapping, fieldName) => { + forOwn(mapping, (fieldMapping, fieldName) => { if (fieldMapping._deserialize && typeof fieldName === 'string') { savedObject._source[fieldName] = fieldMapping._deserialize( savedObject._source[fieldName] as string @@ -54,7 +54,7 @@ export async function applyESResp( }); // Give obj all of the values in _source.fields - _.assign(savedObject, savedObject._source); + assign(savedObject, savedObject._source); savedObject.lastSavedTitle = savedObject.title; if (meta.searchSourceJSON) { diff --git a/src/plugins/saved_objects/public/saved_object/helpers/create_source.ts b/src/plugins/saved_objects/public/saved_object/helpers/create_source.ts index f1bc614dd1197..7ed729b4b7a0f 100644 --- a/src/plugins/saved_objects/public/saved_object/helpers/create_source.ts +++ b/src/plugins/saved_objects/public/saved_object/helpers/create_source.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import _ from 'lodash'; +import { get } from 'lodash'; import { i18n } from '@kbn/i18n'; import { SavedObjectAttributes } from 'kibana/public'; import { SavedObject, SavedObjectKibanaServices } from '../../types'; @@ -40,7 +40,7 @@ export async function createSource( return await savedObjectsClient.create(esType, source, options); } catch (err) { // record exists, confirm overwriting - if (_.get(err, 'res.status') === 409) { + if (get(err, 'res.status') === 409) { const confirmMessage = i18n.translate( 'savedObjects.confirmModal.overwriteConfirmationMessage', { diff --git a/src/plugins/saved_objects/public/saved_object/helpers/initialize_saved_object.ts b/src/plugins/saved_objects/public/saved_object/helpers/initialize_saved_object.ts index cf0cea8d368da..b6dddf8d82b72 100644 --- a/src/plugins/saved_objects/public/saved_object/helpers/initialize_saved_object.ts +++ b/src/plugins/saved_objects/public/saved_object/helpers/initialize_saved_object.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import _ from 'lodash'; +import { cloneDeep, assign } from 'lodash'; import { SavedObjectsClientContract } from 'kibana/public'; import { SavedObject, SavedObjectConfig } from '../../types'; @@ -24,7 +24,7 @@ export async function intializeSavedObject( if (!savedObject.id) { // just assign the defaults and be done - _.assign(savedObject, savedObject.defaults); + assign(savedObject, savedObject.defaults); await savedObject.hydrateIndexPattern!(); if (typeof config.afterESResp === 'function') { savedObject = await config.afterESResp(savedObject); @@ -36,7 +36,7 @@ export async function intializeSavedObject( const respMapped = { _id: resp.id, _type: resp.type, - _source: _.cloneDeep(resp.attributes), + _source: cloneDeep(resp.attributes), references: resp.references, found: !!resp._version, }; diff --git a/src/plugins/saved_objects/public/saved_object/helpers/serialize_saved_object.ts b/src/plugins/saved_objects/public/saved_object/helpers/serialize_saved_object.ts index eb9bef788fcdc..efe7a85f8f1e1 100644 --- a/src/plugins/saved_objects/public/saved_object/helpers/serialize_saved_object.ts +++ b/src/plugins/saved_objects/public/saved_object/helpers/serialize_saved_object.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import _ from 'lodash'; +import { forOwn } from 'lodash'; import { SavedObject, SavedObjectConfig } from '../../types'; import { extractSearchSourceReferences } from '../../../../data/public'; import { expandShorthand } from './field_mapping'; @@ -17,7 +17,7 @@ export function serializeSavedObject(savedObject: SavedObject, config: SavedObje const attributes = {} as Record; const references = []; - _.forOwn(mapping, (fieldMapping, fieldName) => { + forOwn(mapping, (fieldMapping, fieldName) => { if (typeof fieldName !== 'string') { return; } From 84d193c024ac8fa7de91be2e04fb3e6509415dca Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 13:41:34 +0300 Subject: [PATCH 61/77] One more fix. --- src/plugins/presentation_util/common/lib/resolve_dataurl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/presentation_util/common/lib/resolve_dataurl.ts b/src/plugins/presentation_util/common/lib/resolve_dataurl.ts index ff09eef98b18e..db94bdf04c32b 100644 --- a/src/plugins/presentation_util/common/lib/resolve_dataurl.ts +++ b/src/plugins/presentation_util/common/lib/resolve_dataurl.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import get from 'lodash/get'; +import { get } from 'lodash'; import { isValidUrl } from './url'; import { missingImage } from './missing_asset'; From e97aa5b0a2b8b22017e65ea76b95aacf8260494e Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 16:37:26 +0300 Subject: [PATCH 62/77] Fixed huge size of bundle. --- .../__stories__/reveal_image_renderer.stories.tsx | 8 ++++++-- src/plugins/presentation_util/public/index.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx index 822b996b2940f..ab315fa22f3b8 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/__stories__/reveal_image_renderer.stories.tsx @@ -9,9 +9,13 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { revealImageRenderer } from '../'; -import { Render, elasticOutline, elasticLogo } from '../../../../presentation_util/public'; +import { elasticOutline, elasticLogo } from '../../../../presentation_util/public'; + +// This is required only for stories, no need to put it to a bundle +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { Render } from '../../../../presentation_util/public/__stories__'; + import { Origin } from '../../../common/types/expression_functions'; -import './reveal_image.scss'; storiesOf('renderers/revealImage', module).add('default', () => { const config = { diff --git a/src/plugins/presentation_util/public/index.ts b/src/plugins/presentation_util/public/index.ts index f523793e4e027..c641181a0dfa5 100644 --- a/src/plugins/presentation_util/public/index.ts +++ b/src/plugins/presentation_util/public/index.ts @@ -20,7 +20,7 @@ export { SaveModalDashboardProps } from './components/types'; export { projectIDs, ProjectID, Project } from '../common/labs'; export * from '../common/lib'; export * from '../common/test_helpers'; -export * from './__stories__'; +// export * from './__stories__'; export { LazyLabsBeakerButton, From 3be24f6a257784aa95cad5cd9a4cc8c816e8fe38 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 16:39:36 +0300 Subject: [PATCH 63/77] Reduced allow limit for presentationUtil --- packages/kbn-optimizer/limits.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index cc41b1e0f5210..9f40d2b8f35f9 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -99,7 +99,7 @@ pageLoadAssetSize: watcher: 43598 runtimeFields: 41752 stackAlerts: 29684 - presentationUtil: 418850 + presentationUtil: 49767 spacesOss: 18817 indexPatternFieldEditor: 90489 osquery: 107090 From 9bf774c06a78ecce0be0c505737d81bc503f31fd Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 17:07:49 +0300 Subject: [PATCH 64/77] Updated limits for presentationUtil. --- packages/kbn-optimizer/limits.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 9f40d2b8f35f9..c9ec09760986c 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -99,7 +99,7 @@ pageLoadAssetSize: watcher: 43598 runtimeFields: 41752 stackAlerts: 29684 - presentationUtil: 49767 + presentationUtil: 94301 spacesOss: 18817 indexPatternFieldEditor: 90489 osquery: 107090 From fec9bedbe573ab52b47ee5e8f9fd766c2f48177c Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 21:38:47 +0300 Subject: [PATCH 65/77] Fixed public API. --- src/plugins/presentation_util/common/index.ts | 2 -- src/plugins/presentation_util/common/lib/index.ts | 9 ++------- .../{ => lib}/test_helpers/function_wrapper.ts | 0 .../common/{ => lib}/test_helpers/index.ts | 0 .../common/lib/{ => utils}/dataurl.test.ts | 0 .../common/lib/{ => utils}/dataurl.ts | 0 .../common/lib/{ => utils}/elastic_logo.ts | 0 .../common/lib/{ => utils}/elastic_outline.ts | 0 .../common/lib/{ => utils}/httpurl.test.ts | 0 .../common/lib/{ => utils}/httpurl.ts | 0 .../presentation_util/common/lib/utils/index.ts | 15 +++++++++++++++ .../common/lib/{ => utils}/missing_asset.ts | 0 .../lib/{ => utils}/resolve_dataurl.test.ts | 0 .../common/lib/{ => utils}/resolve_dataurl.ts | 0 .../common/lib/{ => utils}/url.test.ts | 0 .../common/lib/{ => utils}/url.ts | 0 src/plugins/presentation_util/kibana.json | 2 +- src/plugins/presentation_util/public/index.ts | 2 -- .../functions/browser/markdown.test.js | 2 +- .../functions/common/__fixtures__/test_styles.js | 2 +- .../functions/common/all.test.js | 2 +- .../functions/common/alterColumn.test.js | 2 +- .../functions/common/any.test.js | 2 +- .../canvas_plugin_src/functions/common/as.test.js | 2 +- .../functions/common/axis_config.test.js | 2 +- .../functions/common/case.test.js | 2 +- .../functions/common/clear.test.js | 2 +- .../functions/common/columns.test.js | 2 +- .../functions/common/compare.test.js | 2 +- .../functions/common/containerStyle.ts | 2 +- .../functions/common/container_style.test.js | 2 +- .../functions/common/context.test.js | 2 +- .../functions/common/csv.test.ts | 2 +- .../functions/common/date.test.js | 2 +- .../canvas_plugin_src/functions/common/do.test.js | 2 +- .../functions/common/dropdown_control.test.ts | 2 +- .../canvas_plugin_src/functions/common/eq.test.js | 2 +- .../functions/common/exactly.test.js | 2 +- .../functions/common/filterrows.test.js | 2 +- .../functions/common/formatdate.test.js | 2 +- .../functions/common/formatnumber.test.js | 2 +- .../functions/common/getCell.test.js | 2 +- .../canvas_plugin_src/functions/common/gt.test.js | 2 +- .../functions/common/gte.test.js | 2 +- .../functions/common/head.test.js | 2 +- .../canvas_plugin_src/functions/common/if.test.js | 2 +- .../functions/common/image.test.js | 2 +- .../canvas_plugin_src/functions/common/image.ts | 2 +- .../functions/common/join_rows.test.js | 2 +- .../canvas_plugin_src/functions/common/lt.test.js | 2 +- .../functions/common/lte.test.js | 2 +- .../functions/common/metric.test.js | 2 +- .../functions/common/neq.test.js | 2 +- .../functions/common/ply.test.js | 2 +- .../functions/common/progress.test.js | 2 +- .../functions/common/render.test.js | 2 +- .../functions/common/repeat_image.test.js | 2 +- .../functions/common/repeat_image.ts | 2 +- .../functions/common/replace.test.js | 2 +- .../functions/common/rounddate.test.js | 2 +- .../functions/common/rowCount.test.js | 2 +- .../functions/common/series_style.test.js | 2 +- .../functions/common/sort.test.js | 2 +- .../functions/common/staticColumn.test.js | 2 +- .../functions/common/string.test.js | 2 +- .../functions/common/switch.test.js | 2 +- .../functions/common/table.test.js | 2 +- .../functions/common/tail.test.js | 2 +- .../functions/common/timefilter.test.js | 2 +- .../functions/common/timefilter_control.test.js | 2 +- .../renderers/__stories__/image.stories.tsx | 2 +- .../__stories__/repeat_image.stories.tsx | 2 +- .../canvas/canvas_plugin_src/renderers/image.tsx | 2 +- .../canvas_plugin_src/renderers/repeat_image.ts | 5 ++++- .../canvas/canvas_plugin_src/uis/views/image.js | 2 +- .../__stories__/custom_element_modal.stories.tsx | 2 +- .../__stories__/element_card.stories.tsx | 2 +- .../__stories__/fixtures/test_elements.tsx | 2 +- .../plugins/canvas/public/functions/pie.test.js | 2 +- .../plugins/canvas/public/functions/plot.test.js | 2 +- 80 files changed, 83 insertions(+), 74 deletions(-) rename src/plugins/presentation_util/common/{ => lib}/test_helpers/function_wrapper.ts (100%) rename src/plugins/presentation_util/common/{ => lib}/test_helpers/index.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/dataurl.test.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/dataurl.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/elastic_logo.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/elastic_outline.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/httpurl.test.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/httpurl.ts (100%) create mode 100644 src/plugins/presentation_util/common/lib/utils/index.ts rename src/plugins/presentation_util/common/lib/{ => utils}/missing_asset.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/resolve_dataurl.test.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/resolve_dataurl.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/url.test.ts (100%) rename src/plugins/presentation_util/common/lib/{ => utils}/url.ts (100%) diff --git a/src/plugins/presentation_util/common/index.ts b/src/plugins/presentation_util/common/index.ts index 5aa67da3d3416..bf8819b13a92d 100644 --- a/src/plugins/presentation_util/common/index.ts +++ b/src/plugins/presentation_util/common/index.ts @@ -10,5 +10,3 @@ export const PLUGIN_ID = 'presentationUtil'; export const PLUGIN_NAME = 'presentationUtil'; export * from './labs'; -export * from './lib'; -export * from './test_helpers'; diff --git a/src/plugins/presentation_util/common/lib/index.ts b/src/plugins/presentation_util/common/lib/index.ts index eed4acf78b2be..3fe90009ad8df 100644 --- a/src/plugins/presentation_util/common/lib/index.ts +++ b/src/plugins/presentation_util/common/lib/index.ts @@ -6,10 +6,5 @@ * Side Public License, v 1. */ -export * from './dataurl'; -export * from './elastic_logo'; -export * from './elastic_outline'; -export * from './httpurl'; -export * from './missing_asset'; -export * from './resolve_dataurl'; -export * from './url'; +export * from './utils'; +export * from './test_helpers'; diff --git a/src/plugins/presentation_util/common/test_helpers/function_wrapper.ts b/src/plugins/presentation_util/common/lib/test_helpers/function_wrapper.ts similarity index 100% rename from src/plugins/presentation_util/common/test_helpers/function_wrapper.ts rename to src/plugins/presentation_util/common/lib/test_helpers/function_wrapper.ts diff --git a/src/plugins/presentation_util/common/test_helpers/index.ts b/src/plugins/presentation_util/common/lib/test_helpers/index.ts similarity index 100% rename from src/plugins/presentation_util/common/test_helpers/index.ts rename to src/plugins/presentation_util/common/lib/test_helpers/index.ts diff --git a/src/plugins/presentation_util/common/lib/dataurl.test.ts b/src/plugins/presentation_util/common/lib/utils/dataurl.test.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/dataurl.test.ts rename to src/plugins/presentation_util/common/lib/utils/dataurl.test.ts diff --git a/src/plugins/presentation_util/common/lib/dataurl.ts b/src/plugins/presentation_util/common/lib/utils/dataurl.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/dataurl.ts rename to src/plugins/presentation_util/common/lib/utils/dataurl.ts diff --git a/src/plugins/presentation_util/common/lib/elastic_logo.ts b/src/plugins/presentation_util/common/lib/utils/elastic_logo.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/elastic_logo.ts rename to src/plugins/presentation_util/common/lib/utils/elastic_logo.ts diff --git a/src/plugins/presentation_util/common/lib/elastic_outline.ts b/src/plugins/presentation_util/common/lib/utils/elastic_outline.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/elastic_outline.ts rename to src/plugins/presentation_util/common/lib/utils/elastic_outline.ts diff --git a/src/plugins/presentation_util/common/lib/httpurl.test.ts b/src/plugins/presentation_util/common/lib/utils/httpurl.test.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/httpurl.test.ts rename to src/plugins/presentation_util/common/lib/utils/httpurl.test.ts diff --git a/src/plugins/presentation_util/common/lib/httpurl.ts b/src/plugins/presentation_util/common/lib/utils/httpurl.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/httpurl.ts rename to src/plugins/presentation_util/common/lib/utils/httpurl.ts diff --git a/src/plugins/presentation_util/common/lib/utils/index.ts b/src/plugins/presentation_util/common/lib/utils/index.ts new file mode 100644 index 0000000000000..eed4acf78b2be --- /dev/null +++ b/src/plugins/presentation_util/common/lib/utils/index.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +export * from './dataurl'; +export * from './elastic_logo'; +export * from './elastic_outline'; +export * from './httpurl'; +export * from './missing_asset'; +export * from './resolve_dataurl'; +export * from './url'; diff --git a/src/plugins/presentation_util/common/lib/missing_asset.ts b/src/plugins/presentation_util/common/lib/utils/missing_asset.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/missing_asset.ts rename to src/plugins/presentation_util/common/lib/utils/missing_asset.ts diff --git a/src/plugins/presentation_util/common/lib/resolve_dataurl.test.ts b/src/plugins/presentation_util/common/lib/utils/resolve_dataurl.test.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/resolve_dataurl.test.ts rename to src/plugins/presentation_util/common/lib/utils/resolve_dataurl.test.ts diff --git a/src/plugins/presentation_util/common/lib/resolve_dataurl.ts b/src/plugins/presentation_util/common/lib/utils/resolve_dataurl.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/resolve_dataurl.ts rename to src/plugins/presentation_util/common/lib/utils/resolve_dataurl.ts diff --git a/src/plugins/presentation_util/common/lib/url.test.ts b/src/plugins/presentation_util/common/lib/utils/url.test.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/url.test.ts rename to src/plugins/presentation_util/common/lib/utils/url.test.ts diff --git a/src/plugins/presentation_util/common/lib/url.ts b/src/plugins/presentation_util/common/lib/utils/url.ts similarity index 100% rename from src/plugins/presentation_util/common/lib/url.ts rename to src/plugins/presentation_util/common/lib/utils/url.ts diff --git a/src/plugins/presentation_util/kibana.json b/src/plugins/presentation_util/kibana.json index de37355797a44..22ec919457cce 100644 --- a/src/plugins/presentation_util/kibana.json +++ b/src/plugins/presentation_util/kibana.json @@ -5,7 +5,7 @@ "server": true, "ui": true, "extraPublicDirs": [ - "common" + "common/lib" ], "requiredPlugins": [ "savedObjects" diff --git a/src/plugins/presentation_util/public/index.ts b/src/plugins/presentation_util/public/index.ts index c641181a0dfa5..435c51ca73e6e 100644 --- a/src/plugins/presentation_util/public/index.ts +++ b/src/plugins/presentation_util/public/index.ts @@ -19,8 +19,6 @@ export { PresentationUtilPluginSetup, PresentationUtilPluginStart } from './type export { SaveModalDashboardProps } from './components/types'; export { projectIDs, ProjectID, Project } from '../common/labs'; export * from '../common/lib'; -export * from '../common/test_helpers'; -// export * from './__stories__'; export { LazyLabsBeakerButton, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.test.js index dff9e1eba687e..dcb6035dbb687 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { testTable } from '../common/__fixtures__/test_tables'; import { fontStyle } from '../common/__fixtures__/test_styles'; import { markdown } from './markdown'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__fixtures__/test_styles.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__fixtures__/test_styles.js index 462020f06ebb3..fa831cacbcb18 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__fixtures__/test_styles.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__fixtures__/test_styles.js @@ -5,7 +5,7 @@ * 2.0. */ -import { elasticLogo } from '../../../../../../../src/plugins/presentation_util/common'; +import { elasticLogo } from '../../../../../../../src/plugins/presentation_util/common/lib'; export const fontStyle = { type: 'style', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.test.js index a5ea4984e4aba..7d983e02f1123 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { all } from './all'; describe('all', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.test.js index 78c8c8641ce1e..85e062f454bc5 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { alterColumn } from './alterColumn'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.test.js index 006dae5c0f9e7..b691595409c62 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.test.js @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { any } from './any'; describe('any', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.test.js index 311c0ff4f2d03..fe297e00e7b35 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/as.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { asFn } from './as'; describe('as', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axis_config.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axis_config.test.js index 0708a0ba4d5de..1538ee8254ec3 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axis_config.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axis_config.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { testTable } from './__fixtures__/test_tables'; import { axisConfig } from './axisConfig'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.test.js index 5c4c91aa25176..d5621943bccaf 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { caseFn } from './case'; describe('case', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clear.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clear.test.js index 35449eadb20e1..0834dc27d321b 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clear.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/clear.test.js @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { testTable } from './__fixtures__/test_tables'; import { clear } from './clear'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.test.js index acf1ede483696..d7f28559ee0ef 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { columns } from './columns'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.test.js index 9a7d6ea9b23fb..c04f132a577fd 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { compare } from './compare'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.ts index 64c11cd89115e..12aad5d609414 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/containerStyle.ts @@ -8,7 +8,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; import { ContainerStyle, Overflow, BackgroundRepeat, BackgroundSize } from '../../../types'; import { getFunctionHelp, getFunctionErrors } from '../../../i18n'; -import { isValidUrl } from '../../../../../../src/plugins/presentation_util/common'; +import { isValidUrl } from '../../../../../../src/plugins/presentation_util/common/lib'; interface Output extends ContainerStyle { type: 'containerStyle'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js index 00a33e628f2a5..7a3599f47ec86 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/container_style.test.js @@ -8,7 +8,7 @@ import { elasticLogo, functionWrapper, -} from '../../../../../../src/plugins/presentation_util/common'; +} from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { containerStyle } from './containerStyle'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/context.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/context.test.js index cc97dd0ffaefd..e4c45f228aa17 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/context.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/context.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { testTable, emptyTable } from './__fixtures__/test_tables'; import { context } from './context'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts index dc3497b7db301..cfef618bee39d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { csv } from './csv'; import { Datatable, ExecutionContext, SerializableState } from 'src/plugins/expressions'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.test.js index af2261b421ae4..cd06ce5fbb463 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.test.js @@ -6,7 +6,7 @@ */ import sinon from 'sinon'; -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { date } from './date'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.test.js index 30ea031fec98f..00429779e2ff1 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { doFn } from './do'; describe('do', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts index 8a69a16f7e65a..254efd9f5f0d9 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdown_control.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { testTable, relationalTable } from './__fixtures__/test_tables'; import { dropdownControl } from './dropdownControl'; import { ExecutionContext, SerializableState } from 'src/plugins/expressions'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.test.js index bb2b31805a577..5e710fc109396 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { eq } from './eq'; describe('eq', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.test.js index 5ae43fb3076fa..9d3dcb6a99167 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { emptyFilter } from './__fixtures__/test_filters'; import { exactly } from './exactly'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.test.js index c97f592aaed18..edc2c1db18f64 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { testTable } from './__fixtures__/test_tables'; import { filterrows } from './filterrows'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.test.js index 24ee5edcb33a9..e725dccc8ca34 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { formatdate } from './formatdate'; describe('formatdate', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.test.js index 47efec2f29ac2..e957bf115198f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { formatnumber } from './formatnumber'; describe('formatnumber', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.test.js index 35013506db533..a556c2ddeb48a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/getCell.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { getCell } from './getCell'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.test.js index 34f563fb2c7fc..53675fca2b3ae 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { gt } from './gt'; describe('gt', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.test.js index 192c994ee972f..aefb2ccf926ae 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { gte } from './gte'; describe('gte', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/head.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/head.test.js index d64ea6d512ed5..4721eaf6cb530 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/head.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/head.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { head } from './head'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.test.js index c867df9aa5052..df576a6a2507f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { ifFn } from './if'; describe('if', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js index d68228ac31346..45b26cd25937d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.test.js @@ -9,7 +9,7 @@ import expect from '@kbn/expect'; import { elasticLogo, elasticOutline, -} from '../../../../../../src/plugins/presentation_util/common'; +} from '../../../../../../src/plugins/presentation_util/common/lib'; // import { image } from './image'; // TODO: the test was not running and is not up to date diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts index 3448ea6f577d8..c3e64e48b23fc 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/image.ts @@ -10,7 +10,7 @@ import { getFunctionHelp, getFunctionErrors } from '../../../i18n'; import { elasticLogo, resolveWithMissingImage, -} from '../../../../../../src/plugins/presentation_util/common'; +} from '../../../../../../src/plugins/presentation_util/common/lib'; export enum ImageMode { CONTAIN = 'contain', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/join_rows.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/join_rows.test.js index 1bb41078c0564..94fef857983bc 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/join_rows.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/join_rows.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { testTable } from './__fixtures__/test_tables'; import { joinRows } from './join_rows'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.test.js index e49a4ce9f498e..1ecfca9fc2f94 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { lt } from './lt'; describe('lt', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.test.js index d4b6c59aaa3d6..f32d2d23027c3 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { lte } from './lte'; describe('lte', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.test.js index 97598196df88a..3f2d0ad2cb76e 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { fontStyle } from './__fixtures__/test_styles'; import { metric } from './metric'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.test.js index 92d1181be73ee..88c7a5c18bc7a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { neq } from './neq'; describe('neq', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.test.js index a8e0980560c11..282cb2460d61c 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { testTable } from './__fixtures__/test_tables'; import { ply } from './ply'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.test.js index 4bf305a14aa7c..6438e2a4d19c0 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/progress.test.js @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { progress } from './progress'; import { fontStyle } from './__fixtures__/test_styles'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.test.js index 8153fe5861382..3248af5504093 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/render.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { DEFAULT_ELEMENT_CSS } from '../../../common/lib/constants'; import { testTable } from './__fixtures__/test_tables'; import { fontStyle, containerStyle } from './__fixtures__/test_styles'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js index 367cd338409e3..97f0552721ccf 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.test.js @@ -9,7 +9,7 @@ import { elasticLogo, elasticOutline, functionWrapper, -} from '../../../../../../src/plugins/presentation_util/common'; +} from '../../../../../../src/plugins/presentation_util/common/lib'; import { repeatImage } from './repeat_image'; describe('repeatImage', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts index 8e663e5e3b918..904b2478760ab 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeat_image.ts @@ -9,7 +9,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common'; import { elasticOutline, resolveWithMissingImage, -} from '../../../../../../src/plugins/presentation_util/common'; +} from '../../../../../../src/plugins/presentation_util/common/lib'; import { Render } from '../../../types'; import { getFunctionHelp } from '../../../i18n'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/replace.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/replace.test.js index ce1ed4805d95f..6025ff354cd8d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/replace.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/replace.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { replace } from './replace'; describe('replace', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.test.js index 63302b7e42f76..0ef832d973271 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rounddate.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { rounddate } from './rounddate'; describe('rounddate', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.test.js index 5b4ca82206c88..7a32849e9161a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { rowCount } from './rowCount'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/series_style.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/series_style.test.js index 889aa403c9390..6e91b84d82b6f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/series_style.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/series_style.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { seriesStyle } from './seriesStyle'; describe('seriesStyle', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.test.js index 500123315afd2..f59c517c91d88 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { testTable } from './__fixtures__/test_tables'; import { sort } from './sort'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.test.js index 1cd11bdb54af1..0260c9e77c424 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/staticColumn.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { testTable, emptyTable } from './__fixtures__/test_tables'; import { staticColumn } from './staticColumn'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.test.js index 63b63b4c72113..48af07b7cd880 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { string } from './string'; describe('string', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.test.js index b07170b40d039..c6f592889c991 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.test.js @@ -7,7 +7,7 @@ import { of } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { switchFn } from './switch'; describe('switch', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/table.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/table.test.js index 8689c696ef3eb..42e5150b03637 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/table.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/table.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { testTable } from './__fixtures__/test_tables'; import { fontStyle } from './__fixtures__/test_styles'; import { table } from './table'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.test.js index d3ec242399798..420489754d20e 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { emptyTable, testTable } from './__fixtures__/test_tables'; import { tail } from './tail'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.test.js index 12e197e0de540..f45ec981b1a8a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.test.js @@ -6,7 +6,7 @@ */ import sinon from 'sinon'; -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { getFunctionErrors } from '../../../i18n'; import { emptyFilter } from './__fixtures__/test_filters'; import { timefilter } from './timefilter'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter_control.test.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter_control.test.js index 23c492bada49f..b4a476807b7ee 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter_control.test.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter_control.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../../src/plugins/presentation_util/common/lib'; import { timefilterControl } from './timefilterControl'; describe('timefilterControl', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/image.stories.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/image.stories.tsx index 186f3281a8ef7..8839910d78e0d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/image.stories.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/image.stories.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { image } from '../image'; import { Render } from './render'; -import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common'; +import { elasticLogo } from '../../../../../../src/plugins/presentation_util/common/lib'; storiesOf('renderers/image', module).add('default', () => { const config = { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx index 050d7c7eff12f..ed2706389d83d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/repeat_image.stories.tsx @@ -12,7 +12,7 @@ import { Render } from './render'; import { elasticLogo, elasticOutline, -} from '../../../../../../src/plugins/presentation_util/common'; +} from '../../../../../../src/plugins/presentation_util/common/lib'; storiesOf('renderers/repeatImage', module).add('default', () => { const config = { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx index cc31201bac532..86e9daed105db 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/image.tsx @@ -7,7 +7,7 @@ import ReactDOM from 'react-dom'; import React from 'react'; -import { elasticLogo, isValidUrl } from '../../../../../src/plugins/presentation_util/common'; +import { elasticLogo, isValidUrl } from '../../../../../src/plugins/presentation_util/common/lib'; import { Return as Arguments } from '../functions/common/image'; import { RendererStrings } from '../../i18n'; import { RendererFactory } from '../../types'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts b/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts index 0bd2695487a3b..149a887683413 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/repeat_image.ts @@ -7,7 +7,10 @@ import $ from 'jquery'; import { times } from 'lodash'; -import { elasticOutline, isValidUrl } from '../../../../../src/plugins/presentation_util/common'; +import { + elasticOutline, + isValidUrl, +} from '../../../../../src/plugins/presentation_util/common/lib'; import { RendererStrings, ErrorStrings } from '../../i18n'; import { Return as Arguments } from '../functions/common/repeat_image'; import { RendererFactory } from '../../types'; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js index 937e6daa0b9d0..f974667b7fad9 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/image.js @@ -8,7 +8,7 @@ import { elasticLogo, resolveFromArgs, -} from '../../../../../../src/plugins/presentation_util/common'; +} from '../../../../../../src/plugins/presentation_util/common/lib'; import { ViewStrings } from '../../../i18n'; const { Image: strings } = ViewStrings; diff --git a/x-pack/plugins/canvas/public/components/custom_element_modal/__stories__/custom_element_modal.stories.tsx b/x-pack/plugins/canvas/public/components/custom_element_modal/__stories__/custom_element_modal.stories.tsx index b278510945946..93574270757f6 100644 --- a/x-pack/plugins/canvas/public/components/custom_element_modal/__stories__/custom_element_modal.stories.tsx +++ b/x-pack/plugins/canvas/public/components/custom_element_modal/__stories__/custom_element_modal.stories.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { action } from '@storybook/addon-actions'; import { CustomElementModal } from '../custom_element_modal'; -import { elasticLogo } from '../../../../../../../src/plugins/presentation_util/common'; +import { elasticLogo } from '../../../../../../../src/plugins/presentation_util/public'; storiesOf('components/Elements/CustomElementModal', module) .add('with title', () => ( diff --git a/x-pack/plugins/canvas/public/components/element_card/__stories__/element_card.stories.tsx b/x-pack/plugins/canvas/public/components/element_card/__stories__/element_card.stories.tsx index 832d56650d810..4c68f185b196f 100644 --- a/x-pack/plugins/canvas/public/components/element_card/__stories__/element_card.stories.tsx +++ b/x-pack/plugins/canvas/public/components/element_card/__stories__/element_card.stories.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { storiesOf } from '@storybook/react'; import { action } from '@storybook/addon-actions'; import { ElementCard } from '../element_card'; -import { elasticLogo } from '../../../../../../../src/plugins/presentation_util/common'; +import { elasticLogo } from '../../../../../../../src/plugins/presentation_util/public'; storiesOf('components/Elements/ElementCard', module) .addDecorator((story) => ( diff --git a/x-pack/plugins/canvas/public/components/saved_elements_modal/__stories__/fixtures/test_elements.tsx b/x-pack/plugins/canvas/public/components/saved_elements_modal/__stories__/fixtures/test_elements.tsx index e8dc8e61cbd41..ef48b9815062c 100644 --- a/x-pack/plugins/canvas/public/components/saved_elements_modal/__stories__/fixtures/test_elements.tsx +++ b/x-pack/plugins/canvas/public/components/saved_elements_modal/__stories__/fixtures/test_elements.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { elasticLogo } from '../../../../../../../../src/plugins/presentation_util/common'; +import { elasticLogo } from '../../../../../../../../src/plugins/presentation_util/public'; export const testCustomElements = [ { diff --git a/x-pack/plugins/canvas/public/functions/pie.test.js b/x-pack/plugins/canvas/public/functions/pie.test.js index cd4b42138859e..5e35cc3bf523c 100644 --- a/x-pack/plugins/canvas/public/functions/pie.test.js +++ b/x-pack/plugins/canvas/public/functions/pie.test.js @@ -6,7 +6,7 @@ */ import { testPie } from '../../canvas_plugin_src/functions/common/__fixtures__/test_pointseries'; -import { functionWrapper } from '../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../src/plugins/presentation_util/public'; import { fontStyle, grayscalePalette, diff --git a/x-pack/plugins/canvas/public/functions/plot.test.js b/x-pack/plugins/canvas/public/functions/plot.test.js index 7f9c43d027ee9..8dd2470ea17dc 100644 --- a/x-pack/plugins/canvas/public/functions/plot.test.js +++ b/x-pack/plugins/canvas/public/functions/plot.test.js @@ -5,7 +5,7 @@ * 2.0. */ -import { functionWrapper } from '../../../../../src/plugins/presentation_util/common'; +import { functionWrapper } from '../../../../../src/plugins/presentation_util/public'; import { testPlot } from '../../canvas_plugin_src/functions/common/__fixtures__/test_pointseries'; import { fontStyle, From b65b887cdc65cd624f56fe0ad5f48fc5fa06b7be Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Fri, 18 Jun 2021 22:57:43 +0300 Subject: [PATCH 66/77] fixed type errors. --- .../common/lib/test_helpers/function_wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/presentation_util/common/lib/test_helpers/function_wrapper.ts b/src/plugins/presentation_util/common/lib/test_helpers/function_wrapper.ts index ef5ed607ffd4e..4ec02fd622cf7 100644 --- a/src/plugins/presentation_util/common/lib/test_helpers/function_wrapper.ts +++ b/src/plugins/presentation_util/common/lib/test_helpers/function_wrapper.ts @@ -11,7 +11,7 @@ import { ExpressionValueBoxed, typeSpecs, ExpressionFunctionDefinition, -} from '../../../expressions/common'; +} from '../../../../expressions/common'; type FnType = () => typeof typeSpecs[number] & ExpressionFunctionDefinition, ExpressionValueBoxed>; From 292c3822d7c2823fd1659341170a2de97428100b Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 21 Jun 2021 13:34:33 +0300 Subject: [PATCH 67/77] Added `on(...)` handler. --- .../components/reveal_image_component.tsx | 2 +- .../common/expression_renderers/types.ts | 1 + .../public/__stories__/render.tsx | 1 + .../renderers/__stories__/render.tsx | 5 +- .../renderers/embeddable/embeddable.tsx | 4 +- .../canvas/public/lib/create_handlers.ts | 78 ++++++++++++++----- x-pack/plugins/canvas/types/renderers.ts | 7 +- 7 files changed, 68 insertions(+), 30 deletions(-) diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx index 14fb6cc73f6a0..4a1a4aec7f565 100644 --- a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -59,7 +59,7 @@ function RevealImageComponent({ }, [imgRef, handlers]); useEffect(() => { - handlers.event({ name: 'onResize', data: updateImageView }); + handlers.on('resize', updateImageView); return () => { handlers.event({ name: 'destroy' }); }; diff --git a/src/plugins/expressions/common/expression_renderers/types.ts b/src/plugins/expressions/common/expression_renderers/types.ts index 239cff6143ae7..6109cd8ed7fe2 100644 --- a/src/plugins/expressions/common/expression_renderers/types.ts +++ b/src/plugins/expressions/common/expression_renderers/types.ts @@ -72,6 +72,7 @@ export interface IInterpreterRenderHandlers { hasCompatibleActions?: (event: any) => Promise; getRenderMode: () => RenderMode; isSyncColorsEnabled: () => boolean; + on: (event: any, fn: (...args: any) => void) => void; /** * This uiState interface is actually `PersistedState` from the visualizations plugin, * but expressions cannot know about vis or it creates a mess of circular dependencies. diff --git a/src/plugins/presentation_util/public/__stories__/render.tsx b/src/plugins/presentation_util/public/__stories__/render.tsx index 29d95e6bf2819..4da225d04a05f 100644 --- a/src/plugins/presentation_util/public/__stories__/render.tsx +++ b/src/plugins/presentation_util/public/__stories__/render.tsx @@ -18,6 +18,7 @@ export const defaultHandlers: IInterpreterRenderHandlers = { reload: action('reload'), update: action('update'), event: action('event'), + on: action('on'), }; /* diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/render.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/render.tsx index d87c24b1b7e86..cb26c6803ea1f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/render.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/__stories__/render.tsx @@ -16,8 +16,8 @@ export const defaultHandlers: RendererHandlers = { getRenderMode: () => 'display', isSyncColorsEnabled: () => false, onComplete: (fn) => undefined, - onEmbeddableDestroyed: action('onEmbeddableDestroyed'), - onEmbeddableInputChange: action('onEmbeddableInputChange'), + embeddableInputChange: action('embeddableInputChange'), + embeddableDestroyed: action('embeddableDestroyed'), onResize: action('onResize'), resize: action('resize'), setFilter: action('setFilter'), @@ -26,6 +26,7 @@ export const defaultHandlers: RendererHandlers = { reload: action('reload'), update: action('update'), event: action('event'), + on: action('on'), }; /* diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable.tsx index 73e839433c25e..a5c79364fb92e 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable.tsx +++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable.tsx @@ -90,7 +90,7 @@ export const embeddableRendererFactory = ( ); if (updatedExpression) { - handlers.onEmbeddableInputChange(updatedExpression); + handlers.embeddableInputChange(updatedExpression); } }); @@ -106,7 +106,7 @@ export const embeddableRendererFactory = ( handlers.onDestroy(() => { subscription.unsubscribe(); - handlers.onEmbeddableDestroyed(); + handlers.embeddableDestroyed(); delete embeddablesRegistry[uniqueId]; diff --git a/x-pack/plugins/canvas/public/lib/create_handlers.ts b/x-pack/plugins/canvas/public/lib/create_handlers.ts index 9f531d6921417..bcd9526d755a9 100644 --- a/x-pack/plugins/canvas/public/lib/create_handlers.ts +++ b/x-pack/plugins/canvas/public/lib/create_handlers.ts @@ -27,8 +27,23 @@ export const createBaseHandlers = (): IInterpreterRenderHandlers => ({ onDestroy() {}, getRenderMode: () => 'display', isSyncColorsEnabled: () => false, + on: (event: any, fn: (...args: any) => void) => {}, }); +interface RenderEmitters { + done: () => boolean | void; + resize: (_size: { height: number; width: number }) => boolean | void; + embeddableDestroyed: () => boolean | void; + embeddableInputChange: (embeddableExpression: string) => boolean | void; +} + +interface RenderListeners { + complete: Pick; + resize: Pick; + embeddableDestroyed: Pick; + embeddableInputChange: Pick; +} + export const createHandlers = (baseHandlers = createBaseHandlers()): RendererHandlers => ({ ...baseHandlers, destroy() {}, @@ -44,13 +59,12 @@ export const createHandlers = (baseHandlers = createBaseHandlers()): RendererHan this.done = fn; }, - // TODO: these functions do not match the `onXYZ` and `xyz` pattern elsewhere. - onEmbeddableDestroyed() {}, - onEmbeddableInputChange() {}, onResize(fn: (size: { height: number; width: number }) => void) { this.resize = fn; }, + embeddableDestroyed() {}, + embeddableInputChange() {}, resize(_size: { height: number; width: number }) {}, setFilter() {}, }); @@ -64,7 +78,6 @@ export const createDispatchedHandlerFactory = ( ): ((element: CanvasElement) => RendererHandlers) => { let isComplete = false; let oldElement: CanvasElement | undefined; - let completeFn = () => {}; return (element: CanvasElement) => { // reset isComplete when element changes @@ -76,30 +89,49 @@ export const createDispatchedHandlerFactory = ( const handlers: RendererHandlers & { event: IInterpreterRenderHandlers['event']; done: IInterpreterRenderHandlers['done']; - } = { + } & RenderEmitters = { ...createHandlers(), event(event: ExpressionRendererEvent) { switch (event.name) { case 'embeddableInputChange': - this.onEmbeddableInputChange(event.data); + this.embeddableInputChange(event.data); break; case 'setFilter': this.setFilter(event.data); break; - case 'onComplete': - this.onComplete(event.data); - break; case 'embeddableDestroyed': - this.onEmbeddableDestroyed(); + this.embeddableDestroyed(); break; case 'resize': this.resize(event.data); break; - case 'onResize': - this.onResize(event.data); - break; } }, + on(event: keyof RenderListeners, fn: (...args: any[]) => void) { + const listenerToEvent: { [k in keyof RenderListeners]: keyof RenderEmitters } = { + complete: 'done', + resize: 'resize', + embeddableDestroyed: 'embeddableDestroyed', + embeddableInputChange: 'embeddableInputChange', + }; + + if (listenerToEvent[event]) { + const eventCall: ((...args: any[]) => boolean | void) | null = + typeof this[listenerToEvent[event]] === 'function' + ? this[listenerToEvent[event]] + : null; + + if (!eventCall) return true; + + this[listenerToEvent[event]] = (...args: any[]) => { + const preventFromCallingListener: void | boolean = eventCall(...args); + if (fn && typeof fn === 'function' && !preventFromCallingListener) { + fn(...args); + } + }; + } + }, + setFilter(text: string) { dispatch(setFilter(text, element.id, true)); }, @@ -108,31 +140,35 @@ export const createDispatchedHandlerFactory = ( return element.filter; }, - onComplete(fn: () => void) { - completeFn = fn; + onComplete(fn: () => void | boolean) { + this.on('complete', fn); }, getElementId: () => element.id, - onEmbeddableInputChange(embeddableExpression: string) { + embeddableInputChange(embeddableExpression: string) { dispatch(updateEmbeddableExpression({ elementId: element.id, embeddableExpression })); }, - onEmbeddableDestroyed() { + embeddableDestroyed() { dispatch(fetchEmbeddableRenderable(element.id)); }, done() { // don't emit if the element is already done - if (isComplete) { - return; - } + if (isComplete) return true; isComplete = true; - completeFn(); }, }; + Object.keys(handlers).forEach((value: string) => { + const key = value as keyof typeof handlers; + if (handlers[key] && typeof handlers[key] === 'function') { + handlers[key] = (handlers[key] as Function).bind(handlers); + } + }); + return handlers; }; }; diff --git a/x-pack/plugins/canvas/types/renderers.ts b/x-pack/plugins/canvas/types/renderers.ts index 2c3931485757d..5c18dfbbf28d4 100644 --- a/x-pack/plugins/canvas/types/renderers.ts +++ b/x-pack/plugins/canvas/types/renderers.ts @@ -18,16 +18,15 @@ export interface CanvasSpecificRendererHandlers { getFilter: () => string; /** Handler to invoke when a renderer is considered complete */ onComplete: (fn: () => void) => void; - /** Handler to invoke when a rendered embeddable is destroyed */ - onEmbeddableDestroyed: () => void; - /** Handler to invoke when the input to a function has changed internally */ - onEmbeddableInputChange: (expression: string) => void; /** Handler to invoke when an element's dimensions have changed*/ onResize: GenericRendererCallback; /** Handler to invoke when an element should be resized. */ resize: (size: { height: number; width: number }) => void; /** Sets the value of the filter property on the element object persisted on the workpad */ setFilter: (filter: string) => void; + + embeddableInputChange: (expression: string) => void; + embeddableDestroyed: () => void; } export type RendererHandlers = IInterpreterRenderHandlers & CanvasSpecificRendererHandlers; From 8ef28377186ce25a24d14e9535984e477181be36 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Mon, 21 Jun 2021 19:07:59 +0300 Subject: [PATCH 68/77] added Types for on(...). --- .../common/expression_renderers/types.ts | 41 +++++++++++++++++++ src/plugins/expressions/public/render.ts | 15 +++++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/plugins/expressions/common/expression_renderers/types.ts b/src/plugins/expressions/common/expression_renderers/types.ts index 6109cd8ed7fe2..9b758efbe2914 100644 --- a/src/plugins/expressions/common/expression_renderers/types.ts +++ b/src/plugins/expressions/common/expression_renderers/types.ts @@ -80,3 +80,44 @@ export interface IInterpreterRenderHandlers { */ uiState?: unknown; } + +type DefaultEmitters = Pick; + +export class DefaultInterpreterRenderHandlers implements IInterpreterRenderHandlers { + done() {} + onDestroy(fn: () => void) {} + reload() {} + update(params: any) {} + event(event: any) {} + getRenderMode() { + return 'noInteractivity' as RenderMode; + } + isSyncColorsEnabled() { + return false; + } + hasCompatibleActions?: (event: any) => Promise; + + on(event: keyof Emitters | keyof DefaultEmitters, fn: (...args: any) => void) { + if (this[event as keyof this]) { + const eventCall = this[event as keyof this]; + if (!eventCall || typeof eventCall !== 'function') return true; + + const updatedEvent = (...args: unknown[]) => { + const preventFromCallingListener: void | boolean = eventCall(...args); + if (fn && typeof fn === 'function' && preventFromCallingListener === null) { + fn(...args); + } + return preventFromCallingListener; + }; + this[event as keyof this] = (updatedEvent as unknown) as typeof eventCall; + } + } + + uiState?: unknown; +} + +export type InterpreterRenderHandlers = T & DefaultInterpreterRenderHandlers; + +export function getDefaultHandlers(): InterpreterRenderHandlers { + return new DefaultInterpreterRenderHandlers() as InterpreterRenderHandlers; +} diff --git a/src/plugins/expressions/public/render.ts b/src/plugins/expressions/public/render.ts index e7a00867c1005..e27b0ca162f8f 100644 --- a/src/plugins/expressions/public/render.ts +++ b/src/plugins/expressions/public/render.ts @@ -11,7 +11,12 @@ import { Observable } from 'rxjs'; import { filter } from 'rxjs/operators'; import { ExpressionRenderError, RenderErrorHandlerFnType, IExpressionLoaderParams } from './types'; import { renderErrorHandler as defaultRenderErrorHandler } from './render_error_handler'; -import { IInterpreterRenderHandlers, ExpressionAstExpression, RenderMode } from '../common'; +import { + ExpressionAstExpression, + RenderMode, + getDefaultHandlers, + InterpreterRenderHandlers, +} from '../common'; import { getRenderersRegistry } from './services'; @@ -45,7 +50,7 @@ export class ExpressionRenderHandler { private renderSubject: Rx.BehaviorSubject; private eventsSubject: Rx.Subject; private updateSubject: Rx.Subject; - private handlers: IInterpreterRenderHandlers; + private handlers: InterpreterRenderHandlers; private onRenderError: RenderErrorHandlerFnType; constructor( @@ -71,8 +76,9 @@ export class ExpressionRenderHandler { this.updateSubject = new Rx.Subject(); this.update$ = this.updateSubject.asObservable(); - + this.handlers = getDefaultHandlers(); this.handlers = { + on: this.handlers.on, onDestroy: (fn: any) => { this.destroyFn = fn; }, @@ -89,6 +95,7 @@ export class ExpressionRenderHandler { event: (data) => { this.eventsSubject.next(data); }, + getRenderMode: () => { return renderMode || 'display'; }, @@ -126,7 +133,7 @@ export class ExpressionRenderHandler { ...this.handlers, uiState, } as any); - } catch (e) { + } catch (e: any) { return this.handleRenderError(e); } }; From 973343db4e4abc0a0e4c9a72249221956aa0aefe Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 22 Jun 2021 10:54:11 +0300 Subject: [PATCH 69/77] Fixed types and handlers. --- .../common/types/expression_renderers.ts | 4 + .../components/reveal_image_component.tsx | 11 +- .../reveal_image_renderer.tsx | 6 +- .../common/expression_renderers/types.ts | 6 +- src/plugins/expressions/public/render.ts | 7 +- .../canvas/public/lib/create_handlers.ts | 116 ++++++------------ 6 files changed, 60 insertions(+), 90 deletions(-) diff --git a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts index 2162b025d7596..47f17031a2955 100644 --- a/src/plugins/expression_reveal_image/common/types/expression_renderers.ts +++ b/src/plugins/expression_reveal_image/common/types/expression_renderers.ts @@ -18,3 +18,7 @@ export interface NodeDimensions { width: number; height: number; } + +export interface HandlerEmitters { + resize?: (size: { height: number; width: number }) => void; +} diff --git a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx index 4a1a4aec7f565..c3cb46f5689c3 100644 --- a/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx +++ b/src/plugins/expression_reveal_image/public/components/reveal_image_component.tsx @@ -7,12 +7,17 @@ */ import React, { useRef, useState, useEffect, useCallback } from 'react'; -import { IInterpreterRenderHandlers } from 'src/plugins/expressions'; -import { NodeDimensions, RevealImageRendererConfig, OriginString } from '../../common/types'; +import { InterpreterRenderHandlers } from 'src/plugins/expressions'; +import { + NodeDimensions, + RevealImageRendererConfig, + OriginString, + HandlerEmitters, +} from '../../common/types'; import { isValidUrl, elasticOutline } from '../../../presentation_util/public'; interface RevealImageComponentProps extends RevealImageRendererConfig { - handlers: IInterpreterRenderHandlers; + handlers: InterpreterRenderHandlers; parentNode: HTMLElement; } diff --git a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx index a3243db97cb9d..55350a9f39b3b 100644 --- a/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx +++ b/src/plugins/expression_reveal_image/public/expression_renderers/reveal_image_renderer.tsx @@ -8,10 +8,10 @@ import React, { lazy } from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; -import { ExpressionRenderDefinition, IInterpreterRenderHandlers } from 'src/plugins/expressions'; +import { ExpressionRenderDefinition, InterpreterRenderHandlers } from 'src/plugins/expressions'; import { withSuspense } from '../../../presentation_util/public'; import { getRendererStrings } from '../../common/i18n'; -import { RevealImageRendererConfig } from '../../common/types'; +import { HandlerEmitters, RevealImageRendererConfig } from '../../common/types'; import './reveal_image.scss'; const { revealImage: revealImageStrings } = getRendererStrings(); @@ -27,7 +27,7 @@ export const revealImageRenderer = (): ExpressionRenderDefinition ) => { handlers.onDestroy(() => { unmountComponentAtNode(domNode); diff --git a/src/plugins/expressions/common/expression_renderers/types.ts b/src/plugins/expressions/common/expression_renderers/types.ts index 9b758efbe2914..e447f633cdd55 100644 --- a/src/plugins/expressions/common/expression_renderers/types.ts +++ b/src/plugins/expressions/common/expression_renderers/types.ts @@ -97,14 +97,14 @@ export class DefaultInterpreterRenderHandlers implements IInterpr } hasCompatibleActions?: (event: any) => Promise; - on(event: keyof Emitters | keyof DefaultEmitters, fn: (...args: any) => void) { + on(event: keyof Emitters | keyof DefaultEmitters, fn: (...args: any) => void): void { if (this[event as keyof this]) { const eventCall = this[event as keyof this]; - if (!eventCall || typeof eventCall !== 'function') return true; + if (!eventCall || typeof eventCall !== 'function') return; const updatedEvent = (...args: unknown[]) => { const preventFromCallingListener: void | boolean = eventCall(...args); - if (fn && typeof fn === 'function' && preventFromCallingListener === null) { + if (fn && typeof fn === 'function' && !preventFromCallingListener) { fn(...args); } return preventFromCallingListener; diff --git a/src/plugins/expressions/public/render.ts b/src/plugins/expressions/public/render.ts index e27b0ca162f8f..3934c6f99fc8e 100644 --- a/src/plugins/expressions/public/render.ts +++ b/src/plugins/expressions/public/render.ts @@ -77,8 +77,7 @@ export class ExpressionRenderHandler { this.updateSubject = new Rx.Subject(); this.update$ = this.updateSubject.asObservable(); this.handlers = getDefaultHandlers(); - this.handlers = { - on: this.handlers.on, + this.handlers = Object.assign(this.handlers, { onDestroy: (fn: any) => { this.destroyFn = fn; }, @@ -92,7 +91,7 @@ export class ExpressionRenderHandler { update: (params: UpdateValue) => { this.updateSubject.next(params); }, - event: (data) => { + event: (data: any) => { this.eventsSubject.next(data); }, @@ -103,7 +102,7 @@ export class ExpressionRenderHandler { return syncColors || false; }, hasCompatibleActions, - }; + }); } render = async (value: any, uiState?: any) => { diff --git a/x-pack/plugins/canvas/public/lib/create_handlers.ts b/x-pack/plugins/canvas/public/lib/create_handlers.ts index bcd9526d755a9..3184f14f72b96 100644 --- a/x-pack/plugins/canvas/public/lib/create_handlers.ts +++ b/x-pack/plugins/canvas/public/lib/create_handlers.ts @@ -13,61 +13,53 @@ import { // @ts-expect-error untyped local import { setFilter } from '../state/actions/elements'; import { updateEmbeddableExpression, fetchEmbeddableRenderable } from '../state/actions/embeddable'; -import { RendererHandlers, CanvasElement } from '../../types'; +import { + RendererHandlers, + CanvasElement, + getDefaultHandlers, + InterpreterRenderHandlers, +} from '../../types'; // This class creates stub handlers to ensure every element and renderer fulfills the contract. // TODO: consider warning if these methods are invoked but not implemented by the renderer...? // We need to move towards only using these handlers and ditching our canvas specific ones -export const createBaseHandlers = (): IInterpreterRenderHandlers => ({ - done() {}, - reload() {}, - update() {}, - event() {}, - onDestroy() {}, - getRenderMode: () => 'display', - isSyncColorsEnabled: () => false, - on: (event: any, fn: (...args: any) => void) => {}, -}); interface RenderEmitters { - done: () => boolean | void; resize: (_size: { height: number; width: number }) => boolean | void; embeddableDestroyed: () => boolean | void; embeddableInputChange: (embeddableExpression: string) => boolean | void; + hasCompatibleActions: () => Promise; } -interface RenderListeners { - complete: Pick; - resize: Pick; - embeddableDestroyed: Pick; - embeddableInputChange: Pick; -} - -export const createHandlers = (baseHandlers = createBaseHandlers()): RendererHandlers => ({ - ...baseHandlers, - destroy() {}, - - getElementId() { - return ''; - }, - getFilter() { - return ''; - }, - - onComplete(fn: () => void) { - this.done = fn; - }, - - onResize(fn: (size: { height: number; width: number }) => void) { - this.resize = fn; - }, - - embeddableDestroyed() {}, - embeddableInputChange() {}, - resize(_size: { height: number; width: number }) {}, - setFilter() {}, -}); +export const createHandlers = (): RendererHandlers & InterpreterRenderHandlers => { + const defaultHandlers: IInterpreterRenderHandlers & + RenderEmitters = getDefaultHandlers(); + + const handlers = { + ...defaultHandlers, + destroy() {}, + getElementId() { + return ''; + }, + getFilter() { + return ''; + }, + setFilter() {}, + onComplete(fn: () => void) { + this.done = fn; + }, + + onResize(fn: (size: { height: number; width: number }) => void) { + this.resize = fn; + }, + + embeddableDestroyed() {}, + embeddableInputChange() {}, + resize(_size: { height: number; width: number }) {}, + }; + return Object.assign(defaultHandlers, handlers); +}; export const assignHandlers = (handlers: Partial = {}): RendererHandlers => Object.assign(createHandlers(), handlers); @@ -86,11 +78,12 @@ export const createDispatchedHandlerFactory = ( oldElement = element; } + const defaultHandlers = createHandlers(); const handlers: RendererHandlers & { event: IInterpreterRenderHandlers['event']; done: IInterpreterRenderHandlers['done']; } & RenderEmitters = { - ...createHandlers(), + ...defaultHandlers, event(event: ExpressionRendererEvent) { switch (event.name) { case 'embeddableInputChange': @@ -107,30 +100,6 @@ export const createDispatchedHandlerFactory = ( break; } }, - on(event: keyof RenderListeners, fn: (...args: any[]) => void) { - const listenerToEvent: { [k in keyof RenderListeners]: keyof RenderEmitters } = { - complete: 'done', - resize: 'resize', - embeddableDestroyed: 'embeddableDestroyed', - embeddableInputChange: 'embeddableInputChange', - }; - - if (listenerToEvent[event]) { - const eventCall: ((...args: any[]) => boolean | void) | null = - typeof this[listenerToEvent[event]] === 'function' - ? this[listenerToEvent[event]] - : null; - - if (!eventCall) return true; - - this[listenerToEvent[event]] = (...args: any[]) => { - const preventFromCallingListener: void | boolean = eventCall(...args); - if (fn && typeof fn === 'function' && !preventFromCallingListener) { - fn(...args); - } - }; - } - }, setFilter(text: string) { dispatch(setFilter(text, element.id, true)); @@ -141,7 +110,7 @@ export const createDispatchedHandlerFactory = ( }, onComplete(fn: () => void | boolean) { - this.on('complete', fn); + defaultHandlers.on('done', fn); }, getElementId: () => element.id, @@ -162,13 +131,6 @@ export const createDispatchedHandlerFactory = ( }, }; - Object.keys(handlers).forEach((value: string) => { - const key = value as keyof typeof handlers; - if (handlers[key] && typeof handlers[key] === 'function') { - handlers[key] = (handlers[key] as Function).bind(handlers); - } - }); - - return handlers; + return Object.assign(defaultHandlers, handlers); }; }; From 447ca299e5ad03251d0fe113da8ce8c70a278b8d Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 22 Jun 2021 10:58:32 +0300 Subject: [PATCH 70/77] Updated docs. --- ...s-expressions-public.iinterpreterrenderhandlers.md | 1 + ...xpressions-public.iinterpreterrenderhandlers.on.md | 11 +++++++++++ ...s-expressions-server.iinterpreterrenderhandlers.md | 1 + ...xpressions-server.iinterpreterrenderhandlers.on.md | 11 +++++++++++ src/plugins/expressions/public/public.api.md | 2 ++ src/plugins/expressions/server/server.api.md | 2 ++ 6 files changed, 28 insertions(+) create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md create mode 100644 docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.md index 0b39a9b4b3ea2..daa98a89f093b 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.md @@ -19,6 +19,7 @@ export interface IInterpreterRenderHandlers | [getRenderMode](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.getrendermode.md) | () => RenderMode | | | [hasCompatibleActions](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.hascompatibleactions.md) | (event: any) => Promise<boolean> | | | [isSyncColorsEnabled](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.issynccolorsenabled.md) | () => boolean | | +| [on](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md) | (event: any, fn: (...args: any) => void) => void | | | [onDestroy](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.ondestroy.md) | (fn: () => void) => void | | | [reload](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.reload.md) | () => void | | | [uiState](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.uistate.md) | unknown | This uiState interface is actually PersistedState from the visualizations plugin, but expressions cannot know about vis or it creates a mess of circular dependencies. Downstream consumers of the uiState handler will need to cast for now. | diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md new file mode 100644 index 0000000000000..cc76b2e1d519b --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [IInterpreterRenderHandlers](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.md) > [on](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md) + +## IInterpreterRenderHandlers.on property + +Signature: + +```typescript +on: (event: any, fn: (...args: any) => void) => void; +``` diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.md index 831c9023c7e48..aadb7945fe7d8 100644 --- a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.md +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.md @@ -19,6 +19,7 @@ export interface IInterpreterRenderHandlers | [getRenderMode](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.getrendermode.md) | () => RenderMode | | | [hasCompatibleActions](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.hascompatibleactions.md) | (event: any) => Promise<boolean> | | | [isSyncColorsEnabled](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.issynccolorsenabled.md) | () => boolean | | +| [on](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md) | (event: any, fn: (...args: any) => void) => void | | | [onDestroy](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.ondestroy.md) | (fn: () => void) => void | | | [reload](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.reload.md) | () => void | | | [uiState](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.uistate.md) | unknown | This uiState interface is actually PersistedState from the visualizations plugin, but expressions cannot know about vis or it creates a mess of circular dependencies. Downstream consumers of the uiState handler will need to cast for now. | diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md new file mode 100644 index 0000000000000..43c31df72bee3 --- /dev/null +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-server](./kibana-plugin-plugins-expressions-server.md) > [IInterpreterRenderHandlers](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.md) > [on](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md) + +## IInterpreterRenderHandlers.on property + +Signature: + +```typescript +on: (event: any, fn: (...args: any) => void) => void; +``` diff --git a/src/plugins/expressions/public/public.api.md b/src/plugins/expressions/public/public.api.md index 97009ae543b97..b6878056bb060 100644 --- a/src/plugins/expressions/public/public.api.md +++ b/src/plugins/expressions/public/public.api.md @@ -937,6 +937,8 @@ export interface IInterpreterRenderHandlers { // (undocumented) isSyncColorsEnabled: () => boolean; // (undocumented) + on: (event: any, fn: (...args: any) => void) => void; + // (undocumented) onDestroy: (fn: () => void) => void; // (undocumented) reload: () => void; diff --git a/src/plugins/expressions/server/server.api.md b/src/plugins/expressions/server/server.api.md index 8d2e113e6b6ed..3a2ec242a5972 100644 --- a/src/plugins/expressions/server/server.api.md +++ b/src/plugins/expressions/server/server.api.md @@ -742,6 +742,8 @@ export interface IInterpreterRenderHandlers { // (undocumented) isSyncColorsEnabled: () => boolean; // (undocumented) + on: (event: any, fn: (...args: any) => void) => void; + // (undocumented) onDestroy: (fn: () => void) => void; // (undocumented) reload: () => void; From 5520b090582ac84ddf6d7a1350496cc99e341cc4 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 22 Jun 2021 11:23:36 +0300 Subject: [PATCH 71/77] Small refactor. --- .../expression_renderers/expression_handlers.ts | 13 +++++++++++++ .../common/expression_renderers/index.ts | 1 + .../common/expression_renderers/types.ts | 4 ---- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/plugins/expressions/common/expression_renderers/expression_handlers.ts diff --git a/src/plugins/expressions/common/expression_renderers/expression_handlers.ts b/src/plugins/expressions/common/expression_renderers/expression_handlers.ts new file mode 100644 index 0000000000000..d6fb78c7d714c --- /dev/null +++ b/src/plugins/expressions/common/expression_renderers/expression_handlers.ts @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { DefaultInterpreterRenderHandlers, InterpreterRenderHandlers } from './types'; + +export function getDefaultHandlers(): InterpreterRenderHandlers { + return new DefaultInterpreterRenderHandlers() as InterpreterRenderHandlers; +} diff --git a/src/plugins/expressions/common/expression_renderers/index.ts b/src/plugins/expressions/common/expression_renderers/index.ts index 2a09f59a7a3e0..c2f0a6f9ffb1e 100644 --- a/src/plugins/expressions/common/expression_renderers/index.ts +++ b/src/plugins/expressions/common/expression_renderers/index.ts @@ -9,3 +9,4 @@ export * from './types'; export * from './expression_renderer'; export * from './expression_renderer_registry'; +export * from './expression_handlers'; diff --git a/src/plugins/expressions/common/expression_renderers/types.ts b/src/plugins/expressions/common/expression_renderers/types.ts index e447f633cdd55..2923b0754ac19 100644 --- a/src/plugins/expressions/common/expression_renderers/types.ts +++ b/src/plugins/expressions/common/expression_renderers/types.ts @@ -117,7 +117,3 @@ export class DefaultInterpreterRenderHandlers implements IInterpr } export type InterpreterRenderHandlers = T & DefaultInterpreterRenderHandlers; - -export function getDefaultHandlers(): InterpreterRenderHandlers { - return new DefaultInterpreterRenderHandlers() as InterpreterRenderHandlers; -} From fc8574b8ab5137e3c2793bda96faa25e5f0d7862 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 22 Jun 2021 13:46:59 +0300 Subject: [PATCH 72/77] Types fixed. --- .../common/expression_renderers/types.ts | 3 +- .../canvas/public/lib/create_handlers.ts | 33 ++++++------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/plugins/expressions/common/expression_renderers/types.ts b/src/plugins/expressions/common/expression_renderers/types.ts index 2923b0754ac19..c80d0a102c1fc 100644 --- a/src/plugins/expressions/common/expression_renderers/types.ts +++ b/src/plugins/expressions/common/expression_renderers/types.ts @@ -116,4 +116,5 @@ export class DefaultInterpreterRenderHandlers implements IInterpr uiState?: unknown; } -export type InterpreterRenderHandlers = T & DefaultInterpreterRenderHandlers; +export type InterpreterRenderHandlers = Emitters & + DefaultInterpreterRenderHandlers; diff --git a/x-pack/plugins/canvas/public/lib/create_handlers.ts b/x-pack/plugins/canvas/public/lib/create_handlers.ts index 3184f14f72b96..10631c16c2bc2 100644 --- a/x-pack/plugins/canvas/public/lib/create_handlers.ts +++ b/x-pack/plugins/canvas/public/lib/create_handlers.ts @@ -6,37 +6,25 @@ */ import { isEqual } from 'lodash'; -import { - ExpressionRendererEvent, - IInterpreterRenderHandlers, -} from 'src/plugins/expressions/public'; +import { ExpressionRendererEvent } from 'src/plugins/expressions/public'; // @ts-expect-error untyped local import { setFilter } from '../state/actions/elements'; import { updateEmbeddableExpression, fetchEmbeddableRenderable } from '../state/actions/embeddable'; import { - RendererHandlers, CanvasElement, getDefaultHandlers, InterpreterRenderHandlers, + CanvasSpecificRendererHandlers, } from '../../types'; // This class creates stub handlers to ensure every element and renderer fulfills the contract. // TODO: consider warning if these methods are invoked but not implemented by the renderer...? // We need to move towards only using these handlers and ditching our canvas specific ones +export const createHandlers = (): InterpreterRenderHandlers => { + const defaultHandlers = getDefaultHandlers(); -interface RenderEmitters { - resize: (_size: { height: number; width: number }) => boolean | void; - embeddableDestroyed: () => boolean | void; - embeddableInputChange: (embeddableExpression: string) => boolean | void; - hasCompatibleActions: () => Promise; -} - -export const createHandlers = (): RendererHandlers & InterpreterRenderHandlers => { - const defaultHandlers: IInterpreterRenderHandlers & - RenderEmitters = getDefaultHandlers(); - - const handlers = { + const handlers: Partial = { ...defaultHandlers, destroy() {}, getElementId() { @@ -61,13 +49,15 @@ export const createHandlers = (): RendererHandlers & InterpreterRenderHandlers = {}): RendererHandlers => +export const assignHandlers = ( + handlers: Partial> = {} +): InterpreterRenderHandlers => Object.assign(createHandlers(), handlers); // TODO: this is a legacy approach we should unravel in the near future. export const createDispatchedHandlerFactory = ( dispatch: (action: any) => void -): ((element: CanvasElement) => RendererHandlers) => { +): ((element: CanvasElement) => InterpreterRenderHandlers) => { let isComplete = false; let oldElement: CanvasElement | undefined; @@ -79,10 +69,7 @@ export const createDispatchedHandlerFactory = ( } const defaultHandlers = createHandlers(); - const handlers: RendererHandlers & { - event: IInterpreterRenderHandlers['event']; - done: IInterpreterRenderHandlers['done']; - } & RenderEmitters = { + const handlers = { ...defaultHandlers, event(event: ExpressionRendererEvent) { switch (event.name) { From 8613a24679be418c2f544a8c40d9d504be5e98ae Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 22 Jun 2021 13:50:32 +0300 Subject: [PATCH 73/77] Made some type improvement. --- .../expressions/common/expression_renderers/types.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/expressions/common/expression_renderers/types.ts b/src/plugins/expressions/common/expression_renderers/types.ts index c80d0a102c1fc..ae5d68dce4172 100644 --- a/src/plugins/expressions/common/expression_renderers/types.ts +++ b/src/plugins/expressions/common/expression_renderers/types.ts @@ -98,8 +98,9 @@ export class DefaultInterpreterRenderHandlers implements IInterpr hasCompatibleActions?: (event: any) => Promise; on(event: keyof Emitters | keyof DefaultEmitters, fn: (...args: any) => void): void { - if (this[event as keyof this]) { - const eventCall = this[event as keyof this]; + const eventName = event as keyof this; + if (this[eventName]) { + const eventCall = this[eventName]; if (!eventCall || typeof eventCall !== 'function') return; const updatedEvent = (...args: unknown[]) => { @@ -109,7 +110,7 @@ export class DefaultInterpreterRenderHandlers implements IInterpr } return preventFromCallingListener; }; - this[event as keyof this] = (updatedEvent as unknown) as typeof eventCall; + this[eventName] = (updatedEvent as unknown) as typeof eventCall; } } From fb655d027cd2b5d68dcf0a387a11d799b97eaedb Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 22 Jun 2021 15:12:26 +0300 Subject: [PATCH 74/77] Typeof function check fixed. --- src/plugins/expressions/common/expression_renderers/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/expressions/common/expression_renderers/types.ts b/src/plugins/expressions/common/expression_renderers/types.ts index ae5d68dce4172..a4fbcf36fc8d7 100644 --- a/src/plugins/expressions/common/expression_renderers/types.ts +++ b/src/plugins/expressions/common/expression_renderers/types.ts @@ -101,11 +101,11 @@ export class DefaultInterpreterRenderHandlers implements IInterpr const eventName = event as keyof this; if (this[eventName]) { const eventCall = this[eventName]; - if (!eventCall || typeof eventCall !== 'function') return; + if (typeof eventCall !== 'function') return; const updatedEvent = (...args: unknown[]) => { const preventFromCallingListener: void | boolean = eventCall(...args); - if (fn && typeof fn === 'function' && !preventFromCallingListener) { + if (typeof fn === 'function' && !preventFromCallingListener) { fn(...args); } return preventFromCallingListener; From b9afc4a5578d4e0c4cef22e4af7f32907dad16e5 Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 22 Jun 2021 15:57:36 +0300 Subject: [PATCH 75/77] Refactored. --- .../common/expression_renderers/types.ts | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/plugins/expressions/common/expression_renderers/types.ts b/src/plugins/expressions/common/expression_renderers/types.ts index a4fbcf36fc8d7..ac462aa69bccc 100644 --- a/src/plugins/expressions/common/expression_renderers/types.ts +++ b/src/plugins/expressions/common/expression_renderers/types.ts @@ -99,19 +99,17 @@ export class DefaultInterpreterRenderHandlers implements IInterpr on(event: keyof Emitters | keyof DefaultEmitters, fn: (...args: any) => void): void { const eventName = event as keyof this; - if (this[eventName]) { - const eventCall = this[eventName]; - if (typeof eventCall !== 'function') return; + const eventCall = this[eventName]; + if (typeof eventCall !== 'function') return; - const updatedEvent = (...args: unknown[]) => { - const preventFromCallingListener: void | boolean = eventCall(...args); - if (typeof fn === 'function' && !preventFromCallingListener) { - fn(...args); - } - return preventFromCallingListener; - }; - this[eventName] = (updatedEvent as unknown) as typeof eventCall; - } + const updatedEvent = (...args: unknown[]) => { + const preventFromCallingListener: void | boolean = eventCall(...args); + if (typeof fn === 'function' && !preventFromCallingListener) { + fn(...args); + } + return preventFromCallingListener; + }; + this[eventName] = (updatedEvent as unknown) as typeof eventCall; } uiState?: unknown; From 7c95c90b0018ef6a13b7cee3fcd70a57ad056a8a Mon Sep 17 00:00:00 2001 From: Yaroslav Kuznietsov Date: Tue, 22 Jun 2021 19:49:08 +0300 Subject: [PATCH 76/77] Fixed `magic` at `on(...)` function. --- .../expression_handlers.ts | 35 +++++++++++++-- .../common/expression_renderers/types.ts | 43 +++++-------------- src/plugins/expressions/public/render.ts | 7 +-- .../canvas/public/lib/create_handlers.ts | 7 +-- 4 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/plugins/expressions/common/expression_renderers/expression_handlers.ts b/src/plugins/expressions/common/expression_renderers/expression_handlers.ts index d6fb78c7d714c..f5fdb725ca4ed 100644 --- a/src/plugins/expressions/common/expression_renderers/expression_handlers.ts +++ b/src/plugins/expressions/common/expression_renderers/expression_handlers.ts @@ -6,8 +6,37 @@ * Side Public License, v 1. */ -import { DefaultInterpreterRenderHandlers, InterpreterRenderHandlers } from './types'; +import { InterpreterRenderHandlers, RenderMode } from './types'; -export function getDefaultHandlers(): InterpreterRenderHandlers { - return new DefaultInterpreterRenderHandlers() as InterpreterRenderHandlers; +function on(this: T, event: keyof T, fn: (...args: any) => void): void { + const eventCall = this[event]; + if (typeof eventCall !== 'function') return; + + const updatedEvent = (...args: unknown[]) => { + const preventFromCallingListener: void | boolean = eventCall(...args); + if (typeof fn === 'function' && !preventFromCallingListener) { + fn(...args); + } + return preventFromCallingListener; + }; + this[event] = (updatedEvent as unknown) as typeof eventCall; +} + +export function getDefaultHandlers(): InterpreterRenderHandlers { + const handlers = { + done() {}, + onDestroy(fn: () => void) {}, + reload() {}, + update(params: any) {}, + event(event: any) {}, + getRenderMode() { + return 'noInteractivity' as RenderMode; + }, + isSyncColorsEnabled() { + return false; + }, + on, + } as InterpreterRenderHandlers; + + return handlers; } diff --git a/src/plugins/expressions/common/expression_renderers/types.ts b/src/plugins/expressions/common/expression_renderers/types.ts index ac462aa69bccc..406b8245627c2 100644 --- a/src/plugins/expressions/common/expression_renderers/types.ts +++ b/src/plugins/expressions/common/expression_renderers/types.ts @@ -72,7 +72,7 @@ export interface IInterpreterRenderHandlers { hasCompatibleActions?: (event: any) => Promise; getRenderMode: () => RenderMode; isSyncColorsEnabled: () => boolean; - on: (event: any, fn: (...args: any) => void) => void; + on: (this: any, event: any, fn: (...args: any) => void) => void; /** * This uiState interface is actually `PersistedState` from the visualizations plugin, * but expressions cannot know about vis or it creates a mess of circular dependencies. @@ -83,37 +83,16 @@ export interface IInterpreterRenderHandlers { type DefaultEmitters = Pick; -export class DefaultInterpreterRenderHandlers implements IInterpreterRenderHandlers { - done() {} - onDestroy(fn: () => void) {} - reload() {} - update(params: any) {} - event(event: any) {} - getRenderMode() { - return 'noInteractivity' as RenderMode; - } - isSyncColorsEnabled() { - return false; - } - hasCompatibleActions?: (event: any) => Promise; - - on(event: keyof Emitters | keyof DefaultEmitters, fn: (...args: any) => void): void { - const eventName = event as keyof this; - const eventCall = this[eventName]; - if (typeof eventCall !== 'function') return; - - const updatedEvent = (...args: unknown[]) => { - const preventFromCallingListener: void | boolean = eventCall(...args); - if (typeof fn === 'function' && !preventFromCallingListener) { - fn(...args); - } - return preventFromCallingListener; - }; - this[eventName] = (updatedEvent as unknown) as typeof eventCall; - } - - uiState?: unknown; -} +type DefaultInterpreterRenderHandlers = IInterpreterRenderHandlers & + { + [K in keyof Emitters]: Emitters[K]; + } & { + on: ( + this: any, + event: keyof Emitters | keyof DefaultEmitters, + fn: (...args: any) => void + ) => void; + }; export type InterpreterRenderHandlers = Emitters & DefaultInterpreterRenderHandlers; diff --git a/src/plugins/expressions/public/render.ts b/src/plugins/expressions/public/render.ts index 3934c6f99fc8e..4b48a352c52f1 100644 --- a/src/plugins/expressions/public/render.ts +++ b/src/plugins/expressions/public/render.ts @@ -76,8 +76,9 @@ export class ExpressionRenderHandler { this.updateSubject = new Rx.Subject(); this.update$ = this.updateSubject.asObservable(); - this.handlers = getDefaultHandlers(); - this.handlers = Object.assign(this.handlers, { + const handlers = getDefaultHandlers(); + this.handlers = { + ...handlers, onDestroy: (fn: any) => { this.destroyFn = fn; }, @@ -102,7 +103,7 @@ export class ExpressionRenderHandler { return syncColors || false; }, hasCompatibleActions, - }); + }; } render = async (value: any, uiState?: any) => { diff --git a/x-pack/plugins/canvas/public/lib/create_handlers.ts b/x-pack/plugins/canvas/public/lib/create_handlers.ts index 10631c16c2bc2..1b0d188edf48f 100644 --- a/x-pack/plugins/canvas/public/lib/create_handlers.ts +++ b/x-pack/plugins/canvas/public/lib/create_handlers.ts @@ -22,10 +22,8 @@ import { // We need to move towards only using these handlers and ditching our canvas specific ones export const createHandlers = (): InterpreterRenderHandlers => { - const defaultHandlers = getDefaultHandlers(); - - const handlers: Partial = { - ...defaultHandlers, + return { + ...getDefaultHandlers(), destroy() {}, getElementId() { return ''; @@ -46,7 +44,6 @@ export const createHandlers = (): InterpreterRenderHandlers Date: Tue, 22 Jun 2021 20:25:26 +0300 Subject: [PATCH 77/77] docs updated. --- ...gin-plugins-expressions-public.iinterpreterrenderhandlers.md | 2 +- ...-plugins-expressions-public.iinterpreterrenderhandlers.on.md | 2 +- ...gin-plugins-expressions-server.iinterpreterrenderhandlers.md | 2 +- ...-plugins-expressions-server.iinterpreterrenderhandlers.on.md | 2 +- src/plugins/expressions/public/public.api.md | 2 +- src/plugins/expressions/server/server.api.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.md index daa98a89f093b..37bafcda62761 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.md @@ -19,7 +19,7 @@ export interface IInterpreterRenderHandlers | [getRenderMode](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.getrendermode.md) | () => RenderMode | | | [hasCompatibleActions](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.hascompatibleactions.md) | (event: any) => Promise<boolean> | | | [isSyncColorsEnabled](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.issynccolorsenabled.md) | () => boolean | | -| [on](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md) | (event: any, fn: (...args: any) => void) => void | | +| [on](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md) | (this: any, event: any, fn: (...args: any) => void) => void | | | [onDestroy](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.ondestroy.md) | (fn: () => void) => void | | | [reload](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.reload.md) | () => void | | | [uiState](./kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.uistate.md) | unknown | This uiState interface is actually PersistedState from the visualizations plugin, but expressions cannot know about vis or it creates a mess of circular dependencies. Downstream consumers of the uiState handler will need to cast for now. | diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md index cc76b2e1d519b..719edc1460aa6 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.iinterpreterrenderhandlers.on.md @@ -7,5 +7,5 @@ Signature: ```typescript -on: (event: any, fn: (...args: any) => void) => void; +on: (this: any, event: any, fn: (...args: any) => void) => void; ``` diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.md index aadb7945fe7d8..035a685e9c74c 100644 --- a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.md +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.md @@ -19,7 +19,7 @@ export interface IInterpreterRenderHandlers | [getRenderMode](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.getrendermode.md) | () => RenderMode | | | [hasCompatibleActions](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.hascompatibleactions.md) | (event: any) => Promise<boolean> | | | [isSyncColorsEnabled](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.issynccolorsenabled.md) | () => boolean | | -| [on](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md) | (event: any, fn: (...args: any) => void) => void | | +| [on](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md) | (this: any, event: any, fn: (...args: any) => void) => void | | | [onDestroy](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.ondestroy.md) | (fn: () => void) => void | | | [reload](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.reload.md) | () => void | | | [uiState](./kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.uistate.md) | unknown | This uiState interface is actually PersistedState from the visualizations plugin, but expressions cannot know about vis or it creates a mess of circular dependencies. Downstream consumers of the uiState handler will need to cast for now. | diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md index 43c31df72bee3..72c100a24d192 100644 --- a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.iinterpreterrenderhandlers.on.md @@ -7,5 +7,5 @@ Signature: ```typescript -on: (event: any, fn: (...args: any) => void) => void; +on: (this: any, event: any, fn: (...args: any) => void) => void; ``` diff --git a/src/plugins/expressions/public/public.api.md b/src/plugins/expressions/public/public.api.md index b6878056bb060..f1194bf9d751f 100644 --- a/src/plugins/expressions/public/public.api.md +++ b/src/plugins/expressions/public/public.api.md @@ -937,7 +937,7 @@ export interface IInterpreterRenderHandlers { // (undocumented) isSyncColorsEnabled: () => boolean; // (undocumented) - on: (event: any, fn: (...args: any) => void) => void; + on: (this: any, event: any, fn: (...args: any) => void) => void; // (undocumented) onDestroy: (fn: () => void) => void; // (undocumented) diff --git a/src/plugins/expressions/server/server.api.md b/src/plugins/expressions/server/server.api.md index 3a2ec242a5972..faf925702c988 100644 --- a/src/plugins/expressions/server/server.api.md +++ b/src/plugins/expressions/server/server.api.md @@ -742,7 +742,7 @@ export interface IInterpreterRenderHandlers { // (undocumented) isSyncColorsEnabled: () => boolean; // (undocumented) - on: (event: any, fn: (...args: any) => void) => void; + on: (this: any, event: any, fn: (...args: any) => void) => void; // (undocumented) onDestroy: (fn: () => void) => void; // (undocumented)