[Canvas] Clean up expression function definitions (#37305) (#38476)

* 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
This commit is contained in:
Catherine Liu 2019-06-10 11:21:49 -07:00 committed by GitHub
parent 92d9535bd1
commit d976a2423c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 237 additions and 252 deletions

View file

@ -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,
};
}

View file

@ -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];

View file

@ -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 = {

View file

@ -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'],

View file

@ -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', () => {

View file

@ -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');
});
});
});
});

View file

@ -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);
});
});

View file

@ -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);
});
});

View file

@ -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);
});
});

View file

@ -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);
});
});

View file

@ -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}"`);
});
});

View file

@ -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) => {

View file

@ -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) => {

View file

@ -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,

View file

@ -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: {

View file

@ -37,6 +37,7 @@ export function caseFn(): ExpressionFunction<'case', any, Arguments, Promise<Cas
},
then: {
resolve: false,
required: true,
help: argHelp.then,
},
},

View file

@ -13,6 +13,9 @@ export function clear(): ExpressionFunction<'clear', any, {}, null> {
name: 'clear',
type: 'null',
help,
context: {
types: ['null'],
},
args: {},
fn: () => null,
};

View file

@ -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) => {

View file

@ -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) {

View file

@ -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) => {

View file

@ -30,6 +30,7 @@ export function csv(): ExpressionFunction<'csv', null, Arguments, Datatable> {
data: {
aliases: ['_'],
types: ['string'],
required: true,
help: argHelp.data,
},
delimiter: {

View file

@ -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: {

View file

@ -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,
},

View file

@ -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,
},
},

View file

@ -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: ['_'],

View file

@ -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,
},
},

View file

@ -30,8 +30,9 @@ export function filterrows(): ExpressionFunction<
args: {
fn: {
resolve: false,
aliases: ['_'],
aliases: ['_', 'exp', 'expression', 'function'],
types: ['boolean'],
required: true,
help: argHelp.fn,
},
},

View file

@ -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,

View file

@ -26,6 +26,7 @@ export function formatdate(): ExpressionFunction<'formatdate', number | string,
format: {
aliases: ['_'],
types: ['string'],
required: true,
help: argHelp.format,
},
},

View file

@ -27,6 +27,7 @@ export function formatnumber(): ExpressionFunction<'formatnumber', number, Argum
aliases: ['_'],
types: ['string'],
help: argHelp.format,
required: true,
},
},
fn: (context, args) => {

View file

@ -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;
},
};

View file

@ -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;
},
};

View file

@ -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),

View file

@ -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,
},

View file

@ -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,
},

View file

@ -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) => {

View file

@ -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: {

View file

@ -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: {

View file

@ -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: {

View file

@ -46,7 +46,7 @@ export const seriesStyleToFlot = (seriesStyle: SeriesStyle) => {
},
};
if (stack) {
if (stack != null) {
(flotStyle as any).stack = stack;
}
if (color) {

View file

@ -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

View file

@ -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<any>, Arguments, Render<Arguments>> {
const { help, args: argHelp } = getFunctionHelp().render;
@ -31,25 +32,43 @@ export function render(): ExpressionFunction<'render', Render<any>, 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,
};
},

View file

@ -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,
},

View file

@ -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,
};

View file

@ -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 }),
};

View file

@ -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',
},

View file

@ -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) => {

View file

@ -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,

View file

@ -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',
},
},

View file

@ -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,
},
},

View file

@ -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',

View file

@ -27,7 +27,7 @@ export function escount(): ExpressionFunction<'escount', Filter, Arguments, any>
},
args: {
index: {
types: ['string', 'null'],
types: ['string'],
default: '_all',
help: argHelp.index,
},

View file

@ -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'],

View file

@ -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];

View file

@ -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

View file

@ -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,
};
}

View file

@ -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<FunctionFactory<typeof browser>> = {
help: i18n.translate('xpack.canvas.functions.browserHelpText', {
defaultMessage: 'Force the interpreter to return to the browser',
}),
args: {},
};

View file

@ -23,7 +23,7 @@ export const help: FunctionHelp<FunctionFactory<typeof compare>> = {
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<FunctionFactory<typeof compare>> = {
lt: Operation.LT,
lte: Operation.LTE,
ne: Operation.NE,
neq: Operation.NEQ,
},
}),
to: i18n.translate('xpack.canvas.functions.compare.args.toHelpText', {

View file

@ -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,

View file

@ -18,7 +18,7 @@ export const help: FunctionHelp<FunctionFactory<typeof markdown>> = {
},
}),
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: {

View file

@ -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<FunctionFactory<typeof server>> = {
help: i18n.translate('xpack.canvas.functions.serverHelpText', {
defaultMessage: 'Force the interpreter to return to the server',
}),
args: {},
};

View file

@ -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',
},

View file

@ -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;

View file

@ -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) {