Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const browser = () => ({
name: 'browser',
help: 'Force the interpreter to return to the browser',
args: {},
fn: context => context,
});
export function browser() {
return {
name: 'browser',
help: 'Force the interpreter to return to the browser',
args: {},
fn: context => context,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@

const noop = () => {};

export const location = () => ({
name: 'location',
type: 'datatable',
context: {
types: ['null'],
},
help:
"Use the browser's location functionality to get your current location. Usually quite slow, but fairly accurate",
fn: () => {
return new Promise(resolve => {
function createLocation(geoposition) {
const { latitude, longitude } = geoposition.coords;
return resolve({
type: 'datatable',
columns: [{ name: 'latitude', type: 'number' }, { name: 'longitude', type: 'number' }],
rows: [{ latitude, longitude }],
export function location() {
return {
name: 'location',
type: 'datatable',
context: {
types: ['null'],
},
help:
"Use the browser's location functionality to get your current location. Usually quite slow, but fairly accurate",
fn: () => {
return new Promise(resolve => {
function createLocation(geoposition) {
const { latitude, longitude } = geoposition.coords;
return resolve({
type: 'datatable',
columns: [{ name: 'latitude', type: 'number' }, { name: 'longitude', type: 'number' }],
rows: [{ latitude, longitude }],
});
}
return navigator.geolocation.getCurrentPosition(createLocation, noop, {
maximumAge: 5000,
});
}
return navigator.geolocation.getCurrentPosition(createLocation, noop, {
maximumAge: 5000,
});
});
},
});
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,49 @@

import { Handlebars } from '../../../common/lib/handlebars';

export const markdown = () => ({
name: 'markdown',
aliases: [],
type: 'render',
help:
'An element for rendering markdown text. Great for single numbers, metrics or paragraphs of text.',
context: {
types: ['datatable', 'null'],
},
args: {
expression: {
aliases: ['_'],
types: ['string'],
help: 'A markdown expression. You can pass this multiple times to achieve concatenation',
default: '""',
multi: true,
export function markdown() {
return {
name: 'markdown',
aliases: [],
type: 'render',
help:
'An element for rendering markdown text. Great for single numbers, metrics or paragraphs of text.',
context: {
types: ['datatable', 'null'],
},
font: {
types: ['style'],
help: 'Font settings. Technically, you can add other styles in here as well',
default: '{font}',
args: {
expression: {
aliases: ['_'],
types: ['string'],
help: 'A markdown expression. You can pass this multiple times to achieve concatenation',
default: '""',
multi: true,
},
font: {
types: ['style'],
help: 'Font settings. Technically, you can add other styles in here as well',
default: '{font}',
},
},
},
fn: (context, args) => {
const compileFunctions = args.expression.map(str =>
Handlebars.compile(String(str), { knownHelpersOnly: true })
);
const ctx = {
columns: [],
rows: [],
type: null,
...context,
};
fn: (context, args) => {
const compileFunctions = args.expression.map(str =>
Handlebars.compile(String(str), { knownHelpersOnly: true })
);
const ctx = {
columns: [],
rows: [],
type: null,
...context,
};

return {
type: 'render',
as: 'markdown',
value: {
content: compileFunctions.map(fn => fn(ctx)).join(''),
font: args.font,
},
};
},
});
return {
type: 'render',
as: 'markdown',
value: {
content: compileFunctions.map(fn => fn(ctx)).join(''),
font: args.font,
},
};
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,32 @@

import { parse } from 'url';

export const urlparam = () => ({
name: 'urlparam',
aliases: [],
type: 'string',
help:
'Access URL parameters and use them in expressions. Eg https://localhost:5601/app/canvas?myVar=20. This will always return a string',
context: {
types: ['null'],
},
args: {
param: {
types: ['string'],
aliases: ['_', 'var', 'variable'],
help: 'The URL hash parameter to access',
multi: false,
export function urlparam() {
return {
name: 'urlparam',
aliases: [],
type: 'string',
help:
'Access URL parameters and use them in expressions. Eg https://localhost:5601/app/canvas?myVar=20. This will always return a string',
context: {
types: ['null'],
},
default: {
types: ['string'],
default: '""',
help: 'Return this string if the url parameter is not defined',
args: {
param: {
types: ['string'],
aliases: ['_', 'var', 'variable'],
help: 'The URL hash parameter to access',
multi: false,
},
default: {
types: ['string'],
default: '""',
help: 'Return this string if the url parameter is not defined',
},
},
},
fn: (context, args) => {
const query = parse(window.location.href, true).query;
return query[args.param] || args.default;
},
});
fn: (context, args) => {
const query = parse(window.location.href, true).query;
return query[args.param] || args.default;
},
};
}
36 changes: 19 additions & 17 deletions x-pack/plugins/canvas/canvas_plugin_src/functions/common/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const all = () => ({
name: 'all',
type: 'boolean',
help: 'Return true if all of the conditions are true',
args: {
condition: {
aliases: ['_'],
types: ['boolean', 'null'],
required: true,
multi: true,
help: 'One or more conditions to check',
export function all() {
return {
name: 'all',
type: 'boolean',
help: 'Return true if all of the conditions are true',
args: {
condition: {
aliases: ['_'],
types: ['boolean', 'null'],
required: true,
multi: true,
help: 'One or more conditions to check',
},
},
},
fn: (context, args) => {
const conditions = args.condition || [];
return conditions.every(Boolean);
},
});
fn: (context, args) => {
const conditions = args.condition || [];
return conditions.every(Boolean);
},
};
}
Loading