From 3c9182f4b19ddf792923e9dd7b18fe610b6b301c Mon Sep 17 00:00:00 2001 From: Catherine Liu Date: Fri, 7 Jun 2019 14:32:12 -0700 Subject: [PATCH] [Canvas] Clean up expression function definitions (#37305) * Cleaned up common function defs fixed broken tests Remove boolean and null as context/arg valid types in lt, lte, gt, and gte Added 'function' alias Updated comparator tests Added neq to options in compare function null audit * Deleted obsolete 'browser' and 'server' functions * More clean up * Removed server and browser function i18n strings * Fixed broken tests * Addressing feedback * Removed browser and server from function_help * Added ts-ignore for constant import * Fixed help text label * Fixed font --- .../functions/browser/browser.ts | 19 --------- .../functions/browser/index.ts | 3 +- .../functions/browser/markdown.ts | 10 ++--- .../functions/browser/urlparam.ts | 1 + .../functions/common/__tests__/axis_config.js | 2 +- .../common/__tests__/container_style.js | 9 +++- .../functions/common/__tests__/gt.js | 8 ++-- .../functions/common/__tests__/gte.js | 9 ++-- .../functions/common/__tests__/lt.js | 9 ++-- .../functions/common/__tests__/lte.js | 9 ++-- .../functions/common/__tests__/render.js | 5 ++- .../canvas_plugin_src/functions/common/all.ts | 11 +++-- .../functions/common/alterColumn.ts | 9 ++-- .../canvas_plugin_src/functions/common/any.ts | 9 ++-- .../functions/common/axisConfig.ts | 10 ++--- .../functions/common/case.ts | 1 + .../functions/common/clear.ts | 3 ++ .../functions/common/columns.ts | 6 +-- .../functions/common/compare.ts | 10 +++-- .../functions/common/containerStyle.ts | 13 +++--- .../canvas_plugin_src/functions/common/csv.ts | 1 + .../functions/common/date.ts | 4 +- .../canvas_plugin_src/functions/common/do.ts | 2 +- .../functions/common/dropdownControl.ts | 6 ++- .../canvas_plugin_src/functions/common/eq.ts | 9 ++-- .../functions/common/exactly.ts | 6 ++- .../functions/common/filterrows.ts | 3 +- .../functions/common/font.ts | 12 +++--- .../functions/common/formatdate.ts | 1 + .../functions/common/formatnumber.ts | 1 + .../canvas_plugin_src/functions/common/gt.ts | 8 ++-- .../canvas_plugin_src/functions/common/gte.ts | 8 ++-- .../functions/common/image.ts | 2 +- .../canvas_plugin_src/functions/common/lt.ts | 7 +++- .../canvas_plugin_src/functions/common/lte.ts | 7 +++- .../functions/common/mapColumn.ts | 3 +- .../functions/common/metric.ts | 4 +- .../canvas_plugin_src/functions/common/pie.ts | 8 ++-- .../functions/common/plot/index.ts | 4 +- .../common/plot/series_style_to_flot.ts | 2 +- .../canvas_plugin_src/functions/common/ply.ts | 2 +- .../functions/common/render.ts | 39 +++++++++++++----- .../functions/common/repeatImage.ts | 4 +- .../functions/common/rowCount.ts | 2 +- .../functions/common/seriesStyle.ts | 41 ++++++++++--------- .../functions/common/shape.ts | 18 ++++---- .../functions/common/sort.ts | 1 + .../functions/common/string.ts | 5 ++- .../functions/common/timefilter.ts | 12 +++--- .../functions/common/timefilterControl.ts | 5 ++- .../functions/server/demodata/index.ts | 4 +- .../functions/server/escount.ts | 2 +- .../functions/server/esdocs.ts | 16 ++++---- .../functions/server/index.ts | 3 +- .../functions/server/pointseries/index.ts | 10 ++--- .../functions/server/server.ts | 18 -------- .../strings/functions/browser.ts | 17 -------- .../strings/functions/compare.ts | 3 +- .../strings/functions/function_help.ts | 4 -- .../strings/functions/markdown.ts | 2 +- .../strings/functions/server.ts | 17 -------- .../canvas_plugin_src/uis/views/render.js | 6 +-- x-pack/plugins/canvas/common/lib/constants.ts | 1 + .../plugins/canvas/public/functions/asset.js | 3 +- 64 files changed, 237 insertions(+), 252 deletions(-) delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/functions/browser/browser.ts delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/functions/server/server.ts delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/strings/functions/browser.ts delete mode 100644 x-pack/plugins/canvas/canvas_plugin_src/strings/functions/server.ts diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/browser.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/browser.ts deleted file mode 100644 index 8ceaa8ce7850d..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/browser.ts +++ /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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; -import { getFunctionHelp } from '../../strings'; - -export function browser(): ExpressionFunction<'browser', any, {}, any> { - const { help } = getFunctionHelp().browser; - - return { - name: 'browser', - help, - args: {}, - fn: context => context, - }; -} diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/index.ts index 803f793f96690..1d1df54d62f70 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/index.ts @@ -5,9 +5,8 @@ */ import { functions as commonFunctions } from '../common'; -import { browser } from './browser'; import { location } from './location'; import { markdown } from './markdown'; import { urlparam } from './urlparam'; -export const functions = [browser, location, markdown, urlparam, ...commonFunctions]; +export const functions = [location, markdown, urlparam, ...commonFunctions]; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.ts index df93de974814b..be42f9a9fba91 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/markdown.ts @@ -13,7 +13,7 @@ import { getFunctionHelp } from '../../strings'; type Context = Datatable | null; interface Arguments { - expression: string[]; + content: string[]; font: Style; } @@ -34,10 +34,10 @@ export function markdown(): ExpressionFunction<'markdown', Context, Arguments, R types: ['datatable', 'null'], }, args: { - expression: { - aliases: ['_'], + content: { + aliases: ['_', 'expression'], types: ['string'], - help: argHelp.expression, + help: argHelp.content, default: '""', multi: true, }, @@ -48,7 +48,7 @@ export function markdown(): ExpressionFunction<'markdown', Context, Arguments, R }, }, fn: (context, args) => { - const compileFunctions = args.expression.map(str => + const compileFunctions = args.content.map(str => Handlebars.compile(String(str), { knownHelpersOnly: true }) ); const ctx = { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/urlparam.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/urlparam.ts index db72abef3fe08..1cbd0b1accfd1 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/urlparam.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/browser/urlparam.ts @@ -30,6 +30,7 @@ export function urlparam(): ExpressionFunction<'urlparam', null, Arguments, stri aliases: ['_', 'var', 'variable'], help: argHelp.param, multi: false, + required: true, }, default: { types: ['string'], diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/axis_config.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/axis_config.js index f1669ba6341fc..3a8749470160d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/axis_config.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/axis_config.js @@ -55,7 +55,7 @@ describe('axisConfig', () => { it('defaults to "left" if not provided', () => { const result = fn(testTable); - expect(result).to.have.property('position', ''); + expect(result).to.have.property('position', 'left'); }); it('throws when given an invalid position', () => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/container_style.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/container_style.js index 06e51be8fb056..d56e1a9dba8e2 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/container_style.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/container_style.js @@ -22,8 +22,9 @@ describe('containerStyle', () => { expect(result).to.have.property('type', 'containerStyle'); }); - it('all style properties are omitted if args not provided', () => { - expect(result).to.only.have.key('type'); + it('all style properties except `overflow` are omitted if args not provided', () => { + expect(result).to.have.keys('type', 'overflow'); + expect(result).to.have.property('overflow', 'hidden'); }); }); @@ -131,6 +132,10 @@ describe('containerStyle', () => { result = fn(null, { overflow: 'hidden' }); expect(result).to.have.property('overflow', 'hidden'); }); + it(`defaults to 'hidden'`, () => { + const result = fn(null); + expect(result).to.have.property('overflow', 'hidden'); + }); }); }); }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/gt.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/gt.js index 7f0e259a5211f..7ad6b84edd79b 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/gt.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/gt.js @@ -13,22 +13,20 @@ describe('gt', () => { it('should return false when the types are different', () => { expect(fn(1, { value: '1' })).to.be(false); - expect(fn(true, { value: 'true' })).to.be(false); - expect(fn(null, { value: 'null' })).to.be(false); + expect(fn('3', { value: 3 })).to.be(false); }); it('should return true when greater than', () => { expect(fn(2, { value: 1 })).to.be(true); + expect(fn('b', { value: 'a' })).to.be(true); expect(fn('foo', { value: 'bar' })).to.be(true); - expect(fn(true, { value: false })).to.be(true); }); it('should return false when less than or equal to', () => { expect(fn(1, { value: 2 })).to.be(false); expect(fn(2, { value: 2 })).to.be(false); + expect(fn('a', { value: 'b' })).to.be(false); expect(fn('bar', { value: 'foo' })).to.be(false); expect(fn('foo', { value: 'foo' })).to.be(false); - expect(fn(false, { value: true })).to.be(false); - expect(fn(true, { value: true })).to.be(false); }); }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/gte.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/gte.js index a6d88b2d839a7..6be24dca9e66a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/gte.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/gte.js @@ -13,22 +13,21 @@ describe('gte', () => { it('should return false when the types are different', () => { expect(fn(1, { value: '1' })).to.be(false); - expect(fn(true, { value: 'true' })).to.be(false); - expect(fn(null, { value: 'null' })).to.be(false); + expect(fn(3, { value: '3' })).to.be(false); }); it('should return true when greater than or equal to', () => { expect(fn(2, { value: 1 })).to.be(true); expect(fn(2, { value: 2 })).to.be(true); + expect(fn('b', { value: 'a' })).to.be(true); + expect(fn('b', { value: 'b' })).to.be(true); expect(fn('foo', { value: 'bar' })).to.be(true); expect(fn('foo', { value: 'foo' })).to.be(true); - expect(fn(true, { value: false })).to.be(true); - expect(fn(true, { value: true })).to.be(true); }); it('should return false when less than', () => { expect(fn(1, { value: 2 })).to.be(false); + expect(fn('a', { value: 'b' })).to.be(false); expect(fn('bar', { value: 'foo' })).to.be(false); - expect(fn(false, { value: true })).to.be(false); }); }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/lt.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/lt.js index abc0f6e66641c..2ad49a0e9b071 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/lt.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/lt.js @@ -13,22 +13,21 @@ describe('lt', () => { it('should return false when the types are different', () => { expect(fn(1, { value: '1' })).to.be(false); - expect(fn(true, { value: 'true' })).to.be(false); - expect(fn(null, { value: 'null' })).to.be(false); + expect(fn('3', { value: 3 })).to.be(false); }); it('should return false when greater than or equal to', () => { expect(fn(2, { value: 1 })).to.be(false); expect(fn(2, { value: 2 })).to.be(false); + expect(fn('b', { value: 'a' })).to.be(false); + expect(fn('b', { value: 'b' })).to.be(false); expect(fn('foo', { value: 'bar' })).to.be(false); expect(fn('foo', { value: 'foo' })).to.be(false); - expect(fn(true, { value: false })).to.be(false); - expect(fn(true, { value: true })).to.be(false); }); it('should return true when less than', () => { expect(fn(1, { value: 2 })).to.be(true); + expect(fn('a', { value: 'b' })).to.be(true); expect(fn('bar', { value: 'foo' })).to.be(true); - expect(fn(false, { value: true })).to.be(true); }); }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/lte.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/lte.js index 3eeadbb62b272..7da341f929d56 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/lte.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/lte.js @@ -13,22 +13,21 @@ describe('lte', () => { it('should return false when the types are different', () => { expect(fn(1, { value: '1' })).to.be(false); - expect(fn(true, { value: 'true' })).to.be(false); - expect(fn(null, { value: 'null' })).to.be(false); + expect(fn('3', { value: 3 })).to.be(false); }); it('should return false when greater than', () => { expect(fn(2, { value: 1 })).to.be(false); + expect(fn('b', { value: 'a' })).to.be(false); expect(fn('foo', { value: 'bar' })).to.be(false); - expect(fn(true, { value: false })).to.be(false); }); it('should return true when less than or equal to', () => { expect(fn(1, { value: 2 })).to.be(true); expect(fn(2, { value: 2 })).to.be(true); + expect(fn('a', { value: 'b' })).to.be(true); + expect(fn('a', { value: 'a' })).to.be(true); expect(fn('bar', { value: 'foo' })).to.be(true); expect(fn('foo', { value: 'foo' })).to.be(true); - expect(fn(false, { value: true })).to.be(true); - expect(fn(true, { value: true })).to.be(true); }); }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/render.js b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/render.js index c29df283fdc1d..f1251bb9948f5 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/render.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/__tests__/render.js @@ -7,6 +7,7 @@ import expect from '@kbn/expect'; import { render } from '../render'; import { functionWrapper } from '../../../../__tests__/helpers/function_wrapper'; +import { DEFAULT_ELEMENT_CSS } from '../../../../common/lib/constants'; import { testTable } from './fixtures/test_tables'; import { fontStyle, containerStyle } from './fixtures/test_styles'; @@ -56,9 +57,9 @@ describe('render', () => { expect(result).to.have.property('css', '".canvasRenderEl { background-color: red; }"'); }); - it("defaults to '* > * {}'", () => { + it(`defaults to '${DEFAULT_ELEMENT_CSS}'`, () => { const result = fn(renderTable); - expect(result).to.have.property('css', '"* > * {}"'); + expect(result).to.have.property('css', `"${DEFAULT_ELEMENT_CSS}"`); }); }); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.ts index 3d9e7240d5a72..798f524061156 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.ts @@ -8,23 +8,26 @@ import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; import { getFunctionHelp } from '../../strings'; interface Arguments { - condition: boolean[] | null; + condition: boolean[]; } -export function all(): ExpressionFunction<'all', any, Arguments, boolean> { +export function all(): ExpressionFunction<'all', null, Arguments, boolean> { const { help, args: argHelp } = getFunctionHelp().all; return { name: 'all', type: 'boolean', help, + context: { + types: ['null'], + }, args: { condition: { aliases: ['_'], - types: ['boolean', 'null'], + types: ['boolean'], + help: argHelp.condition, required: true, multi: true, - help: argHelp.condition, }, }, fn: (_context, args) => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.ts index ae3d61b3d105c..2da2b6e8e2ad9 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/alterColumn.ts @@ -12,7 +12,7 @@ import { getFunctionHelp, getFunctionErrors } from '../../strings'; interface Arguments { column: string; type: DatatableColumnType | null; - name: string | null; + name: string; } export function alterColumn(): ExpressionFunction<'alterColumn', Datatable, Arguments, Datatable> { @@ -30,18 +30,17 @@ export function alterColumn(): ExpressionFunction<'alterColumn', Datatable, Argu column: { aliases: ['_'], types: ['string'], + required: true, help: argHelp.column, }, type: { types: ['string'], help: argHelp.type, - default: null, - options: ['null', 'boolean', 'number', 'string'], + options: ['null', 'boolean', 'number', 'string', 'date'], }, name: { - types: ['string', 'null'], + types: ['string'], help: argHelp.name, - default: null, }, }, fn: (context, args) => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.ts index da205776c6d3c..137317a2459a0 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/any.ts @@ -8,20 +8,23 @@ import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; import { getFunctionHelp } from '../../strings'; interface Arguments { - condition: boolean[] | null; + condition: boolean[]; } -export function any(): ExpressionFunction<'any', any, Arguments, boolean> { +export function any(): ExpressionFunction<'any', null, Arguments, boolean> { const { help, args: argHelp } = getFunctionHelp().any; return { name: 'any', type: 'boolean', + context: { + types: ['null'], + }, help, args: { condition: { aliases: ['_'], - types: ['boolean', 'null'], + types: ['boolean'], required: true, multi: true, help: argHelp.condition, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axisConfig.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axisConfig.ts index d162ba7725b31..f2dcdce932f53 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axisConfig.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/axisConfig.ts @@ -6,7 +6,7 @@ import moment from 'moment'; import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; -import { Datatable, Position } from '../types'; +import { Position } from '../types'; import { getFunctionHelp, getFunctionErrors } from '../../strings'; interface Arguments { @@ -21,7 +21,7 @@ interface AxisConfig extends Arguments { type: 'axisConfig'; } -export function axisConfig(): ExpressionFunction<'axisConfig', Datatable, Arguments, AxisConfig> { +export function axisConfig(): ExpressionFunction<'axisConfig', null, Arguments, AxisConfig> { const { help, args: argHelp } = getFunctionHelp().axisConfig; const errors = getFunctionErrors().axisConfig; @@ -30,7 +30,7 @@ export function axisConfig(): ExpressionFunction<'axisConfig', Datatable, Argume aliases: [], type: 'axisConfig', context: { - types: ['datatable'], + types: ['null'], }, help, args: { @@ -46,11 +46,11 @@ export function axisConfig(): ExpressionFunction<'axisConfig', Datatable, Argume default: 'left', }, min: { - types: ['number', 'date', 'string', 'null'], + types: ['number', 'string', 'null'], help: argHelp.min, }, max: { - types: ['number', 'date', 'string', 'null'], + types: ['number', 'string', 'null'], help: argHelp.max, }, tickSize: { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.ts index 9da4b750898c3..724cc9eadcf5b 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/case.ts @@ -37,6 +37,7 @@ export function caseFn(): ExpressionFunction<'case', any, Arguments, Promise { name: 'clear', type: 'null', help, + context: { + types: ['null'], + }, args: {}, fn: () => null, }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.ts index 8d47745a72bb1..91b3e2ff245ef 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/columns.ts @@ -10,8 +10,8 @@ import { Datatable, DatatableColumn } from '../types'; import { getFunctionHelp } from '../../strings'; interface Arguments { - include: string | null; - exclude: string | null; + include: string; + exclude: string; } export function columns(): ExpressionFunction<'columns', Datatable, Arguments, Datatable> { @@ -28,12 +28,10 @@ export function columns(): ExpressionFunction<'columns', Datatable, Arguments, D include: { types: ['string'], help: argHelp.include, - default: null, }, exclude: { types: ['string'], help: argHelp.exclude, - default: null, }, }, fn: (context, args) => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.ts index e154cabe55eb7..041cb9eb9ac89 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/compare.ts @@ -8,11 +8,12 @@ import { getFunctionHelp, getFunctionErrors } from '../../strings'; export enum Operation { EQ = 'eq', - NE = 'ne', - LT = 'lt', GT = 'gt', - LTE = 'lte', GTE = 'gte', + LT = 'lt', + LTE = 'lte', + NE = 'ne', + NEQ = 'neq', } interface Arguments { @@ -32,7 +33,7 @@ export function compare(): ExpressionFunction<'compare', Context, Arguments, boo aliases: ['condition'], type: 'boolean', context: { - types: ['null', 'string', 'number', 'boolean'], + types: ['string', 'number', 'boolean', 'null'], }, args: { op: { @@ -56,6 +57,7 @@ export function compare(): ExpressionFunction<'compare', Context, Arguments, boo case Operation.EQ: return a === b; case Operation.NE: + case Operation.NEQ: return a !== b; case Operation.LT: if (typesMatch) { 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 0c1fd0a2215ac..e25d3187a1e01 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 @@ -32,23 +32,23 @@ export function containerStyle(): ExpressionFunction< help, args: { border: { - types: ['string', 'null'], + types: ['string'], help: argHelp.border, }, borderRadius: { - types: ['string', 'null'], + types: ['string'], help: argHelp.borderRadius, }, padding: { - types: ['string', 'null'], + types: ['string'], help: argHelp.padding, }, backgroundColor: { - types: ['string', 'null'], + types: ['string'], help: argHelp.backgroundColor, }, backgroundImage: { - types: ['string', 'null'], + types: ['string'], help: argHelp.backgroundImage, }, backgroundSize: { @@ -64,13 +64,14 @@ export function containerStyle(): ExpressionFunction< options: ['repeat-x', 'repeat', 'space', 'round', 'no-repeat', 'space'], }, opacity: { - types: ['number', 'null'], + types: ['number'], help: argHelp.opacity, }, overflow: { types: ['string'], help: argHelp.overflow, options: ['visible', 'hidden', 'scroll', 'auto'], + default: 'hidden', }, }, fn: (_context, args) => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.ts index ba781ab4be441..884337243944c 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/csv.ts @@ -30,6 +30,7 @@ export function csv(): ExpressionFunction<'csv', null, Arguments, Datatable> { data: { aliases: ['_'], types: ['string'], + required: true, help: argHelp.data, }, delimiter: { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.ts index efe8bbc7b30c9..f45c9dd205844 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/date.ts @@ -9,7 +9,7 @@ import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; import { getFunctionHelp, getFunctionErrors } from '../../strings'; interface Arguments { - value: string | null; + value: string; format: string; } @@ -27,7 +27,7 @@ export function date(): ExpressionFunction<'date', null, Arguments, number> { args: { value: { aliases: ['_'], - types: ['string', 'null'], + types: ['string'], help: argHelp.value, }, format: { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.ts index 8cc2096595a83..43c58e1a0a3fe 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/do.ts @@ -18,7 +18,7 @@ export function doFn(): ExpressionFunction<'do', any, Arguments, any> { help, args: { fn: { - aliases: ['_'], + aliases: ['_', 'exp', 'expression', 'function'], multi: true, help: argHelp.fn, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdownControl.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdownControl.ts index a2a497ba267f9..c3a5ea025ad4f 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdownControl.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/dropdownControl.ts @@ -12,7 +12,7 @@ import { getFunctionHelp } from '../../strings'; interface Arguments { filterColumn: string; valueColumn: string; - filterGroup: string | null; + filterGroup: string; } interface Return { @@ -39,14 +39,16 @@ export function dropdownControl(): ExpressionFunction< args: { filterColumn: { types: ['string'], + required: true, help: argHelp.filterColumn, }, valueColumn: { types: ['string'], + required: true, help: argHelp.valueColumn, }, filterGroup: { - types: ['string', 'null'], + types: ['string'], help: argHelp.filterGroup, }, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.ts index 95727fbd4d891..ea330ef35462e 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/eq.ts @@ -7,18 +7,21 @@ import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; import { getFunctionHelp } from '../../strings'; interface Arguments { - value: Return; + value: Context; } -type Return = boolean | number | string | null; +type Context = boolean | number | string | null; -export function eq(): ExpressionFunction<'eq', any, Arguments, Return> { +export function eq(): ExpressionFunction<'eq', Context, Arguments, boolean> { const { help, args: argHelp } = getFunctionHelp().eq; return { name: 'eq', type: 'boolean', help, + context: { + types: ['boolean', 'number', 'string', 'null'], + }, args: { value: { aliases: ['_'], diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.ts index d07344bf4d0d6..1b4cbde62a851 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/exactly.ts @@ -10,7 +10,7 @@ import { getFunctionHelp } from '../../strings'; interface Arguments { column: string; value: string; - filterGroup: string | null; + filterGroup: string; } export function exactly(): ExpressionFunction<'exactly', Filter, Arguments, Filter> { @@ -28,15 +28,17 @@ export function exactly(): ExpressionFunction<'exactly', Filter, Arguments, Filt column: { types: ['string'], aliases: ['field', 'c'], + required: true, help: argHelp.column, }, value: { types: ['string'], aliases: ['v', 'val'], + required: true, help: argHelp.value, }, filterGroup: { - types: ['string', 'null'], + types: ['string'], help: argHelp.filterGroup, }, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.ts index 8592a7795a684..59822ea640286 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/filterrows.ts @@ -30,8 +30,9 @@ export function filterrows(): ExpressionFunction< args: { fn: { resolve: false, - aliases: ['_'], + aliases: ['_', 'exp', 'expression', 'function'], types: ['boolean'], + required: true, help: argHelp.fn, }, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/font.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/font.ts index ffd26d6025931..cae926c7d899a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/font.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/font.ts @@ -13,10 +13,10 @@ import { CSSStyle, FontFamily, FontWeight, Style, TextAlignment, TEXT_ALIGNMENTS interface Arguments { align: TextAlignment; - color: string | null; + color: string; family: FontFamily; italic: boolean; - lHeight: number; + lHeight: number | null; size: number; underline: boolean; weight: FontWeight; @@ -43,7 +43,7 @@ export function font(): ExpressionFunction<'font', null, Arguments, Style> { }, color: { help: argHelp.color, - types: ['string', 'null'], + types: ['string'], }, family: { default: `"${openSans.value}"`, @@ -59,12 +59,12 @@ export function font(): ExpressionFunction<'font', null, Arguments, Style> { lHeight: { aliases: ['lineHeight'], help: argHelp.lHeight, - types: ['number'], + types: ['number', 'null'], }, size: { + types: ['number'], default: 14, help: argHelp.size, - types: ['number'], }, underline: { default: false, @@ -89,7 +89,7 @@ export function font(): ExpressionFunction<'font', null, Arguments, Style> { // the line height shouldn't ever be lower than the size, and apply as a // pixel setting - const lineHeight = args.lHeight ? `${args.lHeight}px` : 1; + const lineHeight = args.lHeight != null ? `${args.lHeight}px` : '1'; const spec: CSSStyle = { fontFamily: args.family, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.ts index 29fc25facecd8..f8b3a50921cd0 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatdate.ts @@ -26,6 +26,7 @@ export function formatdate(): ExpressionFunction<'formatdate', number | string, format: { aliases: ['_'], types: ['string'], + required: true, help: argHelp.format, }, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.ts index ca0bd6d1edadd..f0e94badea234 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/formatnumber.ts @@ -27,6 +27,7 @@ export function formatnumber(): ExpressionFunction<'formatnumber', number, Argum aliases: ['_'], types: ['string'], help: argHelp.format, + required: true, }, }, fn: (context, args) => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.ts index e4ac6cdee9abe..de420bfcb383e 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gt.ts @@ -6,7 +6,7 @@ import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; import { getFunctionHelp } from '../../strings'; -type Context = boolean | number | string | null; +type Context = number | string; interface Arguments { value: Context; @@ -18,11 +18,14 @@ export function gt(): ExpressionFunction<'gt', Context, Arguments, boolean> { return { name: 'gt', type: 'boolean', + context: { + types: ['number', 'string'], + }, help, args: { value: { aliases: ['_'], - types: ['boolean', 'number', 'string', 'null'], + types: ['number', 'string'], required: true, help: argHelp.value, }, @@ -34,7 +37,6 @@ export function gt(): ExpressionFunction<'gt', Context, Arguments, boolean> { return false; } - // @ts-ignore #35433 This is a wonky comparison for nulls return context > value; }, }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.ts index add9c462fb529..d24c58632fa2d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/gte.ts @@ -6,7 +6,7 @@ import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; import { getFunctionHelp } from '../../strings'; -type Context = boolean | number | string | null; +type Context = number | string; interface Arguments { value: Context; @@ -18,11 +18,14 @@ export function gte(): ExpressionFunction<'gte', Context, Arguments, boolean> { return { name: 'gte', type: 'boolean', + context: { + types: ['number', 'string'], + }, help, args: { value: { aliases: ['_'], - types: ['boolean', 'number', 'string', 'null'], + types: ['number', 'string'], required: true, help: argHelp.value, }, @@ -34,7 +37,6 @@ export function gte(): ExpressionFunction<'gte', Context, Arguments, boolean> { return false; } - // @ts-ignore #35433 This is a wonky comparison for nulls return context >= value; }, }; 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 a08e4648d2dec..dcce6fe4605ee 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 @@ -49,7 +49,7 @@ export function image(): ExpressionFunction<'image', null, Arguments, Return> { default: elasticLogo, }, mode: { - types: ['string', 'null'], + types: ['string'], help: argHelp.mode, default: 'contain', options: Object.values(ImageMode), diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.ts index 82fe8e3d31bbc..d7a0ffd410dc3 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lt.ts @@ -6,7 +6,7 @@ import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; import { getFunctionHelp } from '../../strings'; -type Context = boolean | number | string | null; +type Context = number | string; interface Arguments { value: Context; @@ -18,11 +18,14 @@ export function lt(): ExpressionFunction<'lt', Context, Arguments, boolean> { return { name: 'lt', type: 'boolean', + context: { + types: ['number', 'string'], + }, help, args: { value: { aliases: ['_'], - types: ['boolean', 'number', 'string', 'null'], + types: ['number', 'string'], required: true, help: argHelp.value, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.ts index 23c3a92f11c62..7e965a8514230 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/lte.ts @@ -6,7 +6,7 @@ import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; import { getFunctionHelp } from '../../strings'; -type Context = boolean | number | string | null; +type Context = number | string; interface Arguments { value: Context; @@ -18,11 +18,14 @@ export function lte(): ExpressionFunction<'lte', Context, Arguments, boolean> { return { name: 'lte', type: 'boolean', + context: { + types: ['number', 'string'], + }, help, args: { value: { aliases: ['_'], - types: ['boolean', 'number', 'string', 'null'], + types: ['number', 'string'], required: true, help: argHelp.value, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.ts index 31db61ebf7cf8..16efe474c7fe2 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/mapColumn.ts @@ -41,8 +41,9 @@ export function mapColumn(): ExpressionFunction< expression: { types: ['boolean', 'number', 'string', 'null'], resolve: false, - aliases: ['exp', 'fn'], + aliases: ['exp', 'fn', 'function'], help: argHelp.expression, + required: true, }, }, fn: (context, args) => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.ts index ee5649ba24465..06898c2f54ecf 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/metric.ts @@ -9,7 +9,7 @@ import { openSans } from '../../../common/lib/fonts'; import { Render, Style } from '../types'; import { getFunctionHelp } from '../../strings'; -type Context = string | null; +type Context = number | string | null; interface Arguments { label: string; @@ -26,7 +26,7 @@ export function metric(): ExpressionFunction<'metric', Context, Arguments, Rende type: 'render', help, context: { - types: ['string', 'null'], + types: ['number', 'string', 'null'], }, args: { label: { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/pie.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/pie.ts index 9a58ea436a9de..ab7ea1542d4e8 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/pie.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/pie.ts @@ -59,8 +59,8 @@ interface Pie { } interface Arguments { - palette: Palette | null; - seriesStyle: SeriesStyle[] | null; + palette: Palette; + seriesStyle: SeriesStyle[]; radius: number | 'auto'; hole: number; labels: boolean; @@ -83,13 +83,13 @@ export function pie(): ExpressionFunction<'pie', PointSeries, Arguments, Render< }, args: { palette: { - types: ['palette', 'null'], + types: ['palette'], help: argHelp.palette, default: '{palette}', }, seriesStyle: { multi: true, - types: ['seriesStyle', 'null'], + types: ['seriesStyle'], help: argHelp.seriesStyle, }, radius: { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/index.ts index 0ac9ad3ecc167..13bf0b4fdd727 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/index.ts @@ -20,7 +20,7 @@ import { getFunctionHelp } from '../../../strings'; import { AxisConfig, PointSeries, Render, SeriesStyle, Style, Palette, Legend } from '../../types'; interface Arguments { - seriesStyle: SeriesStyle[] | null; + seriesStyle: SeriesStyle[]; defaultStyle: SeriesStyle; palette: Palette; font: Style; @@ -43,7 +43,7 @@ export function plot(): ExpressionFunction<'plot', PointSeries, Arguments, Rende args: { seriesStyle: { multi: true, - types: ['seriesStyle', 'null'], + types: ['seriesStyle'], help: argHelp.seriesStyle, }, defaultStyle: { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/series_style_to_flot.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/series_style_to_flot.ts index b57b6efeb784d..d8c7c656445ee 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/series_style_to_flot.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/plot/series_style_to_flot.ts @@ -46,7 +46,7 @@ export const seriesStyleToFlot = (seriesStyle: SeriesStyle) => { }, }; - if (stack) { + if (stack != null) { (flotStyle as any).stack = stack; } if (color) { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.ts index a9e18c9320bc4..ab6bb1ae148a6 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/ply.ts @@ -37,7 +37,7 @@ export function ply(): ExpressionFunction<'ply', Datatable, Arguments, Return> { types: ['datatable'], resolve: false, multi: true, - aliases: ['fn', 'function'], + aliases: ['exp', 'fn', 'function'], help: argHelp.expression, }, // In the future it may make sense to add things like shape, or tooltip values, but I think what we have is good for now 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 af413b6b9c126..d546f224ddf7f 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 @@ -7,17 +7,18 @@ import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; import { Render, ContainerStyle } from '../types'; import { getFunctionHelp } from '../../strings'; +// @ts-ignore unconverted local file +import { DEFAULT_ELEMENT_CSS } from '../../../common/lib/constants'; interface ContainerStyleArgument extends ContainerStyle { type: 'containerStyle'; } interface Arguments { - as: string | null; - css: string | null; - containerStyle: ContainerStyleArgument | null; + as: string; + css: string; + containerStyle: ContainerStyleArgument; } - export function render(): ExpressionFunction<'render', Render, Arguments, Render> { const { help, args: argHelp } = getFunctionHelp().render; @@ -31,25 +32,43 @@ export function render(): ExpressionFunction<'render', Render, Arguments, R }, args: { as: { - types: ['string', 'null'], + types: ['string'], help: argHelp.as, - options: ['debug', 'error', 'image', 'pie', 'plot', 'shape', 'table', 'text'], + options: [ + 'advanced_filter', + 'debug', + 'dropdown_filter', + 'error', + 'image', + 'markdown', + 'metric', + 'pie', + 'plot', + 'progress', + 'repeatImage', + 'revealImage', + 'shape', + 'table', + 'time_filter', + 'text', + ], }, css: { - types: ['string', 'null'], - default: '"* > * {}"', + types: ['string'], help: argHelp.css, + default: `"${DEFAULT_ELEMENT_CSS}"`, }, containerStyle: { - types: ['containerStyle', 'null'], + types: ['containerStyle'], help: argHelp.containerStyle, + default: '{containerStyle}', }, }, fn: (context, args) => { return { ...context, as: args.as || context.as, - css: args.css, + css: args.css || DEFAULT_ELEMENT_CSS, containerStyle: args.containerStyle, }; }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeatImage.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeatImage.ts index 7678349b039f0..fa8bb6ecf6428 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeatImage.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/repeatImage.ts @@ -15,7 +15,7 @@ import { getFunctionHelp } from '../../strings'; interface Arguments { image: string | null; size: number; - max: number | null; + max: number; emptyImage: string | null; } @@ -47,7 +47,7 @@ export function repeatImage(): ExpressionFunction< help: argHelp.size, }, max: { - types: ['number', 'null'], + types: ['number'], help: argHelp.max, default: 1000, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.ts index 1c0e0db9218fb..f665cf4fc6a65 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/rowCount.ts @@ -15,10 +15,10 @@ export function rowCount(): ExpressionFunction<'rowCount', Datatable, {}, number name: 'rowCount', aliases: [], type: 'number', + help, context: { types: ['datatable'], }, - help, args: {}, fn: context => context.rows.length, }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/seriesStyle.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/seriesStyle.ts index d07ca7a45d66a..2cbe1a05728fa 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/seriesStyle.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/seriesStyle.ts @@ -10,7 +10,7 @@ const name = 'seriesStyle'; interface Arguments { bars: number; - color: string | null; + color: string; fill: number | boolean; horizontalBars: boolean; label: string; @@ -29,29 +29,18 @@ export function seriesStyle(): ExpressionFunction<'seriesStyle', null, Arguments return { name, help, + type: 'seriesStyle', context: { types: ['null'], }, args: { - label: { - types: ['string'], - help: argHelp.label, - }, - color: { - types: ['string', 'null'], - help: argHelp.color, - }, - lines: { - types: ['number'], - help: argHelp.lines, - }, bars: { types: ['number'], help: argHelp.bars, }, - points: { - types: ['number'], - help: argHelp.points, + color: { + types: ['string'], + help: argHelp.color, }, fill: { types: ['number', 'boolean'], @@ -59,15 +48,27 @@ export function seriesStyle(): ExpressionFunction<'seriesStyle', null, Arguments default: false, options: [true, false], }, - stack: { - types: ['number', 'null'], - help: argHelp.stack, - }, horizontalBars: { types: ['boolean'], help: argHelp.horizontalBars, options: [true, false], }, + label: { + types: ['string'], + help: argHelp.label, + }, + lines: { + types: ['number'], + help: argHelp.lines, + }, + points: { + types: ['number'], + help: argHelp.points, + }, + stack: { + types: ['number', 'null'], + help: argHelp.stack, + }, }, fn: (_context, args) => ({ type: name, ...args }), }; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/shape.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/shape.ts index f2c33821b0fa9..915f4ccc7ae9c 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/shape.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/shape.ts @@ -26,10 +26,10 @@ export enum Shape { } interface Arguments { - border: string | null; - borderWidth: number | null; - shape: Shape | null; - fill: string | null; + border: string; + borderWidth: number; + shape: Shape; + fill: string; maintainAspect: boolean; } @@ -50,25 +50,25 @@ export function shape(): ExpressionFunction<'shape', null, Arguments, Return> { }, args: { border: { - types: ['string', 'null'], + types: ['string'], aliases: ['stroke'], help: argHelp.border, }, borderWidth: { - types: ['number', 'null'], + types: ['number'], aliases: ['strokeWidth'], help: argHelp.borderWidth, - default: '0', + default: 0, }, shape: { - types: ['string', 'null'], + types: ['string'], help: argHelp.shape, aliases: ['_'], default: 'square', options: Object.values(Shape), }, fill: { - types: ['string', 'null'], + types: ['string'], help: argHelp.fill, default: 'black', }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.ts index d1e1c9e2e5e55..f6144c4c5b97a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/sort.ts @@ -35,6 +35,7 @@ export function sort(): ExpressionFunction<'sort', Datatable, Arguments, Datatab types: ['boolean'], help: argHelp.reverse, options: [true, false], + default: false, }, }, fn: (context, args) => { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.ts index 30fe2f623fad7..0e38abb68a1eb 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/string.ts @@ -10,11 +10,14 @@ interface Arguments { value: string[]; } -export function string(): ExpressionFunction<'string', any, Arguments, string> { +export function string(): ExpressionFunction<'string', null, Arguments, string> { const { help, args: argHelp } = getFunctionHelp().string; return { name: 'string', + context: { + types: ['null'], + }, aliases: [], type: 'string', help, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.ts index c659b49ae8fbd..4852c2d79fdc8 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilter.ts @@ -11,9 +11,9 @@ import { getFunctionHelp, getFunctionErrors } from '../../strings'; interface Arguments { column: string; - from: string | null; - to: string | null; - filterGroup: string | null; + from: string; + to: string; + filterGroup: string; } export function timefilter(): ExpressionFunction<'timefilter', Filter, Arguments, Filter> { @@ -36,17 +36,17 @@ export function timefilter(): ExpressionFunction<'timefilter', Filter, Arguments help: argHelp.column, }, from: { - types: ['string', 'null'], + types: ['string'], aliases: ['f', 'start'], help: argHelp.from, }, to: { - types: ['string', 'null'], + types: ['string'], aliases: ['t', 'end'], help: argHelp.to, }, filterGroup: { - types: ['string', 'null'], + types: ['string'], help: 'Group name for the filter', }, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilterControl.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilterControl.ts index 81a0cd9882ae1..52af021506823 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilterControl.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/timefilterControl.ts @@ -11,7 +11,7 @@ import { getFunctionHelp } from '../../strings'; interface Arguments { column: string; compact: boolean; - filterGroup: string | null; + filterGroup: string; } export function timefilterControl(): ExpressionFunction< 'timefilterControl', @@ -34,6 +34,7 @@ export function timefilterControl(): ExpressionFunction< types: ['string'], aliases: ['field', 'c'], help: argHelp.column, + default: '@timestamp', }, compact: { types: ['boolean'], @@ -42,7 +43,7 @@ export function timefilterControl(): ExpressionFunction< options: [true, false], }, filterGroup: { - types: ['string', 'null'], + types: ['string'], help: argHelp.filterGroup, }, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/demodata/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/demodata/index.ts index 472eef0f9d1ea..5bebb2020c92d 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/demodata/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/demodata/index.ts @@ -13,7 +13,7 @@ import { Filter, Datatable, DatatableColumn, DatatableRow } from '../../types'; import { getFunctionHelp } from '../../../strings'; interface Arguments { - type: string | null; + type: string; } export function demodata(): ExpressionFunction<'demodata', Filter, Arguments, Datatable> { @@ -29,7 +29,7 @@ export function demodata(): ExpressionFunction<'demodata', Filter, Arguments, Da }, args: { type: { - types: ['string', 'null'], + types: ['string'], aliases: ['_'], help: argHelp.type, default: 'ci', diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/escount.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/escount.ts index 0b7581e99970c..9e93104d5e657 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/escount.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/escount.ts @@ -27,7 +27,7 @@ export function escount(): ExpressionFunction<'escount', Filter, Arguments, any> }, args: { index: { - types: ['string', 'null'], + types: ['string'], default: '_all', help: argHelp.index, }, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts index 2d391fad00599..db5cadebd2345 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts @@ -12,11 +12,11 @@ import { Filter } from '../types'; import { getFunctionHelp } from '../../strings'; interface Arguments { - index: string | null; + index: string; query: string; - sort: string | null; - fields: string | null; - metaFields: string | null; + sort: string; + fields: string; + metaFields: string; count: number; } @@ -32,7 +32,7 @@ export function esdocs(): ExpressionFunction<'esdocs', Filter, Arguments, any> { }, args: { index: { - types: ['string', 'null'], + types: ['string'], default: '_all', help: argHelp.index, }, @@ -43,16 +43,16 @@ export function esdocs(): ExpressionFunction<'esdocs', Filter, Arguments, any> { default: '-_index:.kibana', }, sort: { - types: ['string', 'null'], + types: ['string'], help: argHelp.sort, }, fields: { help: argHelp.fields, - types: ['string', 'null'], + types: ['string'], }, metaFields: { help: argHelp.metaFields, - types: ['string', 'null'], + types: ['string'], }, count: { types: ['number'], diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/index.ts index f16d462852ca6..324468c868705 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/index.ts @@ -8,7 +8,6 @@ import { demodata } from './demodata'; import { escount } from './escount'; import { esdocs } from './esdocs'; import { pointseries } from './pointseries'; -import { server } from './server'; import { essql } from './essql'; -export const functions = [demodata, esdocs, escount, essql, pointseries, server]; +export const functions = [demodata, esdocs, escount, essql, pointseries]; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/pointseries/index.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/pointseries/index.ts index 93eb2ac9bd1ef..96469ed3f0c1c 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/pointseries/index.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/pointseries/index.ts @@ -56,23 +56,23 @@ export function pointseries(): ExpressionFunction< }, args: { x: { - types: ['string', 'null'], + types: ['string'], help: argHelp.x, }, y: { - types: ['string', 'null'], + types: ['string'], help: argHelp.y, }, color: { - types: ['string', 'null'], + types: ['string'], help: argHelp.color, // If you need categorization, transform the field. }, size: { - types: ['string', 'null'], + types: ['string'], help: argHelp.size, }, text: { - types: ['string', 'null'], + types: ['string'], help: argHelp.text, }, // In the future it may make sense to add things like shape, or tooltip values, but I think what we have is good for now diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/server.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/server.ts deleted file mode 100644 index e49f96e3e5bbb..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/server.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; - * you may not use this file except in compliance with the Elastic License. - */ -import { ExpressionFunction } from 'src/legacy/core_plugins/interpreter/public'; -import { getFunctionHelp } from '../../strings'; - -export function server(): ExpressionFunction<'server', any, {}, any> { - const { help } = getFunctionHelp().server; - - return { - name: 'server', - help, - args: {}, - fn: context => context, - }; -} diff --git a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/browser.ts b/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/browser.ts deleted file mode 100644 index ef8884765fb4d..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/browser.ts +++ /dev/null @@ -1,17 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { i18n } from '@kbn/i18n'; -import { browser } from '../../functions/browser/browser'; -import { FunctionHelp } from '.'; -import { FunctionFactory } from '../../functions/types'; - -export const help: FunctionHelp> = { - help: i18n.translate('xpack.canvas.functions.browserHelpText', { - defaultMessage: 'Force the interpreter to return to the browser', - }), - args: {}, -}; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/compare.ts b/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/compare.ts index 7fab52aaa42d2..3bae4f2bd74ba 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/compare.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/compare.ts @@ -23,7 +23,7 @@ export const help: FunctionHelp> = { op: i18n.translate('xpack.canvas.functions.compare.args.opHelpText', { defaultMessage: 'The operator to use in the comparison: {eq} (equal to), {gt} (greater than), {gte} (greater than or equal to)' + - ', {lt} (less than), {lte} (less than or equal to), {ne} (not equal to)', + ', {lt} (less than), {lte} (less than or equal to), {ne} or {neq} (not equal to)', values: { eq: Operation.EQ, gt: Operation.GT, @@ -31,6 +31,7 @@ export const help: FunctionHelp> = { lt: Operation.LT, lte: Operation.LTE, ne: Operation.NE, + neq: Operation.NEQ, }, }), to: i18n.translate('xpack.canvas.functions.compare.args.toHelpText', { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/function_help.ts b/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/function_help.ts index 674309a513e7c..948f73805e546 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/function_help.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/function_help.ts @@ -13,7 +13,6 @@ import { help as alterColumn } from './alterColumn'; import { help as any } from './any'; import { help as asFn } from './as'; import { help as axisConfig } from './axisConfig'; -import { help as browser } from './browser'; import { help as caseFn } from './case'; import { help as clear } from './clear'; import { help as columns } from './columns'; @@ -61,7 +60,6 @@ import { help as revealImage } from './revealImage'; import { help as rounddate } from './rounddate'; import { help as rowCount } from './rowCount'; import { help as seriesStyle } from './seriesStyle'; -import { help as server } from './server'; import { help as shape } from './shape'; import { help as sort } from './sort'; import { help as staticColumn } from './staticColumn'; @@ -121,7 +119,6 @@ export const getFunctionHelp = (): FunctionHelpDict => ({ any, as: asFn, axisConfig, - browser, case: caseFn, clear, columns, @@ -169,7 +166,6 @@ export const getFunctionHelp = (): FunctionHelpDict => ({ rounddate, rowCount, seriesStyle, - server, shape, sort, staticColumn, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/markdown.ts b/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/markdown.ts index 057ec58d00a22..cefa708529904 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/markdown.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/markdown.ts @@ -18,7 +18,7 @@ export const help: FunctionHelp> = { }, }), args: { - expression: i18n.translate('xpack.canvas.functions.markdown.args.expressionHelpText', { + content: i18n.translate('xpack.canvas.functions.markdown.args.contentHelpText', { defaultMessage: 'A {markdown} expression. You can pass this multiple times to achieve concatenation', values: { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/server.ts b/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/server.ts deleted file mode 100644 index 5e9f9664856e4..0000000000000 --- a/x-pack/plugins/canvas/canvas_plugin_src/strings/functions/server.ts +++ /dev/null @@ -1,17 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { i18n } from '@kbn/i18n'; -import { server } from '../../functions/server/server'; -import { FunctionHelp } from '.'; -import { FunctionFactory } from '../../functions/types'; - -export const help: FunctionHelp> = { - help: i18n.translate('xpack.canvas.functions.serverHelpText', { - defaultMessage: 'Force the interpreter to return to the server', - }), - args: {}, -}; diff --git a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/render.js b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/render.js index af87174a8cd11..fc5ea42202a28 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/uis/views/render.js +++ b/x-pack/plugins/canvas/canvas_plugin_src/uis/views/render.js @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +import { DEFAULT_ELEMENT_CSS } from '../../../common/lib/constants'; + export const render = () => ({ name: 'render', displayName: 'Element style', @@ -20,9 +22,7 @@ export const render = () => ({ displayName: 'CSS', help: 'A CSS stylesheet scoped to your element', argType: 'textarea', - default: `".canvasRenderEl { - -}"`, + default: `"${DEFAULT_ELEMENT_CSS}"`, options: { confirm: 'Apply stylesheet', }, diff --git a/x-pack/plugins/canvas/common/lib/constants.ts b/x-pack/plugins/canvas/common/lib/constants.ts index 8e34031ddb554..3f5efd70bd4d6 100644 --- a/x-pack/plugins/canvas/common/lib/constants.ts +++ b/x-pack/plugins/canvas/common/lib/constants.ts @@ -22,5 +22,6 @@ export const LOCALSTORAGE_LASTPAGE = 'canvas:lastpage'; export const FETCH_TIMEOUT = 30000; // 30 seconds export const CANVAS_USAGE_TYPE = 'canvas'; export const DEFAULT_WORKPAD_CSS = '.canvasPage {\n\n}'; +export const DEFAULT_ELEMENT_CSS = '.canvasRenderEl{\n\n}'; export const VALID_IMAGE_TYPES = ['gif', 'jpeg', 'png', 'svg+xml']; export const ASSET_MAX_SIZE = 25000; diff --git a/x-pack/plugins/canvas/public/functions/asset.js b/x-pack/plugins/canvas/public/functions/asset.js index 115bdc2ab257d..cb032f2b54441 100644 --- a/x-pack/plugins/canvas/public/functions/asset.js +++ b/x-pack/plugins/canvas/public/functions/asset.js @@ -21,9 +21,10 @@ export const asset = () => ({ types: ['string'], help: 'The ID of the asset value to return', multi: false, + required: true, }, }, - fn: (context, args) => { + fn: (_context, args) => { const assetId = args.id; const asset = getAssetById(getState(), assetId); if (asset !== undefined) {