mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[canvas] remove unnecessary eslint style overrides, use curlys (#27176)
* [canvas] remove styling rules that are handled by prettier, always use curlys in if * [eslint] autofix missing curly brackets * [eslint/canvas] remove redundant prettier plugin config * autofix lint errors in canvas_plugin_src/renderers/time_filter/components/datetime_range_absolute/datetime_range_absolute.js
This commit is contained in:
parent
4eb5e64758
commit
ccfa8a3530
195 changed files with 1566 additions and 571 deletions
46
.eslintrc.js
46
.eslintrc.js
|
@ -72,6 +72,7 @@ module.exports = {
|
|||
'packages/kbn-test/**/*',
|
||||
'packages/kbn-eslint-import-resolver-kibana/**/*',
|
||||
'x-pack/plugins/apm/**/*',
|
||||
'x-pack/plugins/canvas/**/*',
|
||||
],
|
||||
plugins: ['prettier'],
|
||||
rules: Object.assign(
|
||||
|
@ -368,43 +369,30 @@ module.exports = {
|
|||
*/
|
||||
{
|
||||
files: ['x-pack/plugins/canvas/**/*'],
|
||||
plugins: ['prettier'],
|
||||
rules: {
|
||||
// preferences
|
||||
'comma-dangle': [2, 'always-multiline'],
|
||||
'no-multiple-empty-lines': [2, { max: 1, maxEOF: 1 }],
|
||||
'no-multi-spaces': 2,
|
||||
radix: 2,
|
||||
curly: [2, 'multi-or-nest', 'consistent'],
|
||||
|
||||
// annoying rules that conflict with prettier
|
||||
'space-before-function-paren': 0,
|
||||
indent: 0,
|
||||
'wrap-iife': 0,
|
||||
'max-len': 0,
|
||||
radix: 'error',
|
||||
curly: ['error', 'all'],
|
||||
|
||||
// module importing
|
||||
'import/order': [
|
||||
2,
|
||||
{ groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'] },
|
||||
'error',
|
||||
{
|
||||
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
|
||||
},
|
||||
],
|
||||
'import/extensions': [2, 'never', { json: 'always', less: 'always', svg: 'always' }],
|
||||
|
||||
// prettier
|
||||
'prettier/prettier': 2,
|
||||
'import/extensions': ['error', 'never', { json: 'always', less: 'always', svg: 'always' }],
|
||||
|
||||
// react
|
||||
'jsx-quotes': 2,
|
||||
'react/no-did-mount-set-state': 2,
|
||||
'react/no-did-update-set-state': 2,
|
||||
'react/no-multi-comp': [2, { ignoreStateless: true }],
|
||||
'react/self-closing-comp': 2,
|
||||
'react/sort-comp': 2,
|
||||
'react/jsx-boolean-value': 2,
|
||||
'react/jsx-wrap-multilines': 2,
|
||||
'react/no-unescaped-entities': [2, { forbid: ['>', '}'] }],
|
||||
'react/no-did-mount-set-state': 'error',
|
||||
'react/no-did-update-set-state': 'error',
|
||||
'react/no-multi-comp': ['error', { ignoreStateless: true }],
|
||||
'react/self-closing-comp': 'error',
|
||||
'react/sort-comp': 'error',
|
||||
'react/jsx-boolean-value': 'error',
|
||||
'react/jsx-wrap-multilines': 'error',
|
||||
'react/no-unescaped-entities': ['error', { forbid: ['>', '}'] }],
|
||||
'react/forbid-elements': [
|
||||
2,
|
||||
'error',
|
||||
{
|
||||
forbid: [
|
||||
{
|
||||
|
|
|
@ -13,7 +13,9 @@ describe('sort', () => {
|
|||
const fn = functionWrapper(sort);
|
||||
|
||||
const isSorted = (rows, column, reverse) => {
|
||||
if (reverse) return !rows.some((row, i) => rows[i + 1] && row[column] < rows[i + 1][column]);
|
||||
if (reverse) {
|
||||
return !rows.some((row, i) => rows[i + 1] && row[column] < rows[i + 1][column]);
|
||||
}
|
||||
return !rows.some((row, i) => rows[i + 1] && row[column] > rows[i + 1][column]);
|
||||
};
|
||||
|
||||
|
|
|
@ -32,18 +32,25 @@ export const alterColumn = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (!args.column || (!args.type && !args.name)) return context;
|
||||
if (!args.column || (!args.type && !args.name)) {
|
||||
return context;
|
||||
}
|
||||
|
||||
const column = context.columns.find(col => col.name === args.column);
|
||||
if (!column) throw new Error(`Column not found: '${args.column}'`);
|
||||
if (!column) {
|
||||
throw new Error(`Column not found: '${args.column}'`);
|
||||
}
|
||||
|
||||
const name = args.name || column.name;
|
||||
const type = args.type || column.type;
|
||||
|
||||
const columns = context.columns.reduce((all, col) => {
|
||||
if (col.name !== args.name) {
|
||||
if (col.name !== column.name) all.push(col);
|
||||
else all.push({ name, type });
|
||||
if (col.name !== column.name) {
|
||||
all.push(col);
|
||||
} else {
|
||||
all.push({ name, type });
|
||||
}
|
||||
}
|
||||
return all;
|
||||
}, []);
|
||||
|
@ -54,7 +61,9 @@ export const alterColumn = () => ({
|
|||
handler = (function getHandler() {
|
||||
switch (type) {
|
||||
case 'string':
|
||||
if (column.type === 'date') return v => new Date(v).toISOString();
|
||||
if (column.type === 'date') {
|
||||
return v => new Date(v).toISOString();
|
||||
}
|
||||
return String;
|
||||
case 'number':
|
||||
return Number;
|
||||
|
|
|
@ -42,7 +42,9 @@ export const axisConfig = () => ({
|
|||
},
|
||||
fn: (context, args) => {
|
||||
const positions = ['top', 'bottom', 'left', 'right', ''];
|
||||
if (!positions.includes(args.position)) throw new Error(`Invalid position ${args.position}`);
|
||||
if (!positions.includes(args.position)) {
|
||||
throw new Error(`Invalid position ${args.position}`);
|
||||
}
|
||||
|
||||
const min = typeof args.min === 'string' ? moment.utc(args.min).valueOf() : args.min;
|
||||
const max = typeof args.max === 'string' ? moment.utc(args.max).valueOf() : args.max;
|
||||
|
|
|
@ -33,12 +33,18 @@ export const caseFn = () => ({
|
|||
});
|
||||
|
||||
async function doesMatch(context, args) {
|
||||
if (typeof args.if !== 'undefined') return args.if;
|
||||
if (typeof args.when !== 'undefined') return (await args.when()) === context;
|
||||
if (typeof args.if !== 'undefined') {
|
||||
return args.if;
|
||||
}
|
||||
if (typeof args.when !== 'undefined') {
|
||||
return (await args.when()) === context;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function getResult(context, args) {
|
||||
if (typeof args.then !== 'undefined') return await args.then();
|
||||
if (typeof args.then !== 'undefined') {
|
||||
return await args.then();
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -46,7 +46,9 @@ export const columns = () => ({
|
|||
const columns = [];
|
||||
fields.forEach(field => {
|
||||
const column = find(result.columns, { name: field });
|
||||
if (column) columns.push(column);
|
||||
if (column) {
|
||||
columns.push(column);
|
||||
}
|
||||
});
|
||||
const rows = columns.length > 0 ? result.rows.map(row => pick(row, fields)) : [];
|
||||
result = { ...result, rows, columns };
|
||||
|
|
|
@ -41,16 +41,24 @@ export const compare = () => ({
|
|||
case 'ne':
|
||||
return a !== b;
|
||||
case 'lt':
|
||||
if (typesMatch) return a < b;
|
||||
if (typesMatch) {
|
||||
return a < b;
|
||||
}
|
||||
return false;
|
||||
case 'lte':
|
||||
if (typesMatch) return a <= b;
|
||||
if (typesMatch) {
|
||||
return a <= b;
|
||||
}
|
||||
return false;
|
||||
case 'gt':
|
||||
if (typesMatch) return a > b;
|
||||
if (typesMatch) {
|
||||
return a > b;
|
||||
}
|
||||
return false;
|
||||
case 'gte':
|
||||
if (typesMatch) return a >= b;
|
||||
if (typesMatch) {
|
||||
return a >= b;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
throw new Error('Invalid compare operator. Use eq, ne, lt, gt, lte, or gte.');
|
||||
|
|
|
@ -67,8 +67,9 @@ export const containerStyle = () => ({
|
|||
};
|
||||
|
||||
if (backgroundImage) {
|
||||
if (!isValidUrl(backgroundImage))
|
||||
if (!isValidUrl(backgroundImage)) {
|
||||
throw new Error('Invalid backgroundImage. Please provide an asset or a URL.');
|
||||
}
|
||||
style.backgroundImage = `url(${backgroundImage})`;
|
||||
style.backgroundSize = backgroundSize;
|
||||
style.backgroundRepeat = backgroundRepeat;
|
||||
|
|
|
@ -41,8 +41,12 @@ export const csv = () => ({
|
|||
},
|
||||
};
|
||||
|
||||
if (delimiter != null) config.delimiter = delimiter;
|
||||
if (newline != null) config.newline = newline;
|
||||
if (delimiter != null) {
|
||||
config.delimiter = delimiter;
|
||||
}
|
||||
if (newline != null) {
|
||||
config.newline = newline;
|
||||
}
|
||||
|
||||
// TODO: handle errors, check output.errors
|
||||
const output = Papa.parse(csvString, config);
|
||||
|
|
|
@ -8,7 +8,9 @@ import moment from 'moment';
|
|||
|
||||
const getInputDate = input => {
|
||||
// return current date if no input
|
||||
if (!input) return new Date();
|
||||
if (!input) {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
// return the input
|
||||
return input;
|
||||
|
@ -40,7 +42,9 @@ export const date = () => ({
|
|||
const useMoment = date && format;
|
||||
const outputDate = useMoment ? moment.utc(date, format).toDate() : new Date(getInputDate(date));
|
||||
|
||||
if (isNaN(outputDate.getTime())) throw new Error(`Invalid date input: ${date}`);
|
||||
if (isNaN(outputDate.getTime())) {
|
||||
throw new Error(`Invalid date input: ${date}`);
|
||||
}
|
||||
|
||||
return outputDate.valueOf();
|
||||
},
|
||||
|
|
|
@ -26,8 +26,9 @@ export const dropdownControl = () => ({
|
|||
},
|
||||
fn: (context, { valueColumn, filterColumn }) => {
|
||||
let choices = [];
|
||||
if (context.rows[0][valueColumn])
|
||||
if (context.rows[0][valueColumn]) {
|
||||
choices = uniq(context.rows.map(row => row[valueColumn])).sort();
|
||||
}
|
||||
|
||||
const column = filterColumn || valueColumn;
|
||||
|
||||
|
|
|
@ -79,8 +79,12 @@ export const font = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (!weights.includes(args.weight)) throw new Error(`Invalid font weight: ${args.weight}`);
|
||||
if (!alignments.includes(args.align)) throw new Error(`Invalid text alignment: ${args.align}`);
|
||||
if (!weights.includes(args.weight)) {
|
||||
throw new Error(`Invalid font weight: ${args.weight}`);
|
||||
}
|
||||
if (!alignments.includes(args.align)) {
|
||||
throw new Error(`Invalid text alignment: ${args.align}`);
|
||||
}
|
||||
|
||||
// the line height shouldn't ever be lower than the size
|
||||
const lineHeight = args.lHeight ? `${args.lHeight}px` : 1;
|
||||
|
@ -96,7 +100,9 @@ export const font = () => ({
|
|||
};
|
||||
|
||||
// conditionally apply styles based on input
|
||||
if (args.color) spec.color = args.color;
|
||||
if (args.color) {
|
||||
spec.color = args.color;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'style',
|
||||
|
|
|
@ -20,7 +20,9 @@ export const formatdate = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (!args.format) return moment.utc(new Date(context)).toISOString();
|
||||
if (!args.format) {
|
||||
return moment.utc(new Date(context)).toISOString();
|
||||
}
|
||||
return moment.utc(new Date(context)).format(args.format);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -21,7 +21,9 @@ export const formatnumber = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (!args.format) return String(context);
|
||||
if (!args.format) {
|
||||
return String(context);
|
||||
}
|
||||
return numeral(context).format(args.format);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -25,12 +25,16 @@ export const getCell = () => ({
|
|||
},
|
||||
fn: (context, args) => {
|
||||
const row = context.rows[args.row];
|
||||
if (!row) throw new Error(`Row not found: ${args.row}`);
|
||||
if (!row) {
|
||||
throw new Error(`Row not found: ${args.row}`);
|
||||
}
|
||||
|
||||
const { column = context.columns[0].name } = args;
|
||||
const value = row[column];
|
||||
|
||||
if (typeof value === 'undefined') throw new Error(`Column not found: ${column}`);
|
||||
if (typeof value === 'undefined') {
|
||||
throw new Error(`Column not found: ${column}`);
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
|
|
|
@ -17,7 +17,9 @@ export const gt = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (typeof context !== typeof args.value) return false;
|
||||
if (typeof context !== typeof args.value) {
|
||||
return false;
|
||||
}
|
||||
return context > args.value;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -17,7 +17,9 @@ export const gte = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (typeof context !== typeof args.value) return false;
|
||||
if (typeof context !== typeof args.value) {
|
||||
return false;
|
||||
}
|
||||
return context >= args.value;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -27,10 +27,14 @@ export const ifFn = () => ({
|
|||
},
|
||||
fn: async (context, args) => {
|
||||
if (args.condition) {
|
||||
if (typeof args.then === 'undefined') return context;
|
||||
if (typeof args.then === 'undefined') {
|
||||
return context;
|
||||
}
|
||||
return await args.then();
|
||||
} else {
|
||||
if (typeof args.else === 'undefined') return context;
|
||||
if (typeof args.else === 'undefined') {
|
||||
return context;
|
||||
}
|
||||
return await args.else();
|
||||
}
|
||||
},
|
||||
|
|
|
@ -36,7 +36,9 @@ export const image = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, { dataurl, mode }) => {
|
||||
if (!modes.includes(mode)) throw '"mode" must be "contain", "cover", or "stretch"';
|
||||
if (!modes.includes(mode)) {
|
||||
throw '"mode" must be "contain", "cover", or "stretch"';
|
||||
}
|
||||
|
||||
const modeStyle = mode === 'stretch' ? '100% 100%' : mode;
|
||||
|
||||
|
|
|
@ -17,7 +17,9 @@ export const lt = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (typeof context !== typeof args.value) return false;
|
||||
if (typeof context !== typeof args.value) {
|
||||
return false;
|
||||
}
|
||||
return context < args.value;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -17,7 +17,9 @@ export const lte = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (typeof context !== typeof args.value) return false;
|
||||
if (typeof context !== typeof args.value) {
|
||||
return false;
|
||||
}
|
||||
return context <= args.value;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -49,8 +49,11 @@ export const mapColumn = () => ({
|
|||
const existingColumnIndex = columns.findIndex(({ name }) => name === args.name);
|
||||
const type = getType(rows[0][args.name]);
|
||||
const newColumn = { name: args.name, type };
|
||||
if (existingColumnIndex === -1) columns.push(newColumn);
|
||||
else columns[existingColumnIndex] = newColumn;
|
||||
if (existingColumnIndex === -1) {
|
||||
columns.push(newColumn);
|
||||
} else {
|
||||
columns[existingColumnIndex] = newColumn;
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'datatable',
|
||||
|
|
|
@ -25,7 +25,9 @@ export const math = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (!args.expression || args.expression.trim() === '') throw new Error('Empty expression');
|
||||
if (!args.expression || args.expression.trim() === '') {
|
||||
throw new Error('Empty expression');
|
||||
}
|
||||
|
||||
const isDatatable = context && context.type === 'datatable';
|
||||
const mathContext = isDatatable
|
||||
|
@ -34,17 +36,23 @@ export const math = () => ({
|
|||
try {
|
||||
const result = evaluate(args.expression, mathContext);
|
||||
if (Array.isArray(result)) {
|
||||
if (result.length === 1) return result[0];
|
||||
if (result.length === 1) {
|
||||
return result[0];
|
||||
}
|
||||
throw new Error(
|
||||
'Expressions must return a single number. Try wrapping your expression in mean() or sum()'
|
||||
);
|
||||
}
|
||||
if (isNaN(result))
|
||||
if (isNaN(result)) {
|
||||
throw new Error('Failed to execute math expression. Check your column names');
|
||||
}
|
||||
return result;
|
||||
} catch (e) {
|
||||
if (context.rows.length === 0) throw new Error('Empty datatable');
|
||||
else throw e;
|
||||
if (context.rows.length === 0) {
|
||||
throw new Error('Empty datatable');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -79,7 +79,9 @@ export const pie = () => ({
|
|||
const seriesStyle = seriesStyles[label];
|
||||
|
||||
// append series style, if there is a match
|
||||
if (seriesStyle) item.color = get(seriesStyle, 'color');
|
||||
if (seriesStyle) {
|
||||
item.color = get(seriesStyle, 'color');
|
||||
}
|
||||
|
||||
return item;
|
||||
});
|
||||
|
|
|
@ -8,7 +8,9 @@ import { get, map } from 'lodash';
|
|||
import { getType } from '@kbn/interpreter/common';
|
||||
|
||||
export const getFlotAxisConfig = (axis, argValue, { columns, ticks, font } = {}) => {
|
||||
if (!argValue || argValue.show === false) return { show: false };
|
||||
if (!argValue || argValue.show === false) {
|
||||
return { show: false };
|
||||
}
|
||||
|
||||
const config = { show: true };
|
||||
const axisType = get(columns, `${axis}.type`);
|
||||
|
@ -21,19 +23,30 @@ export const getFlotAxisConfig = (axis, argValue, { columns, ticks, font } = {})
|
|||
config.position = acceptedPositions.includes(position) ? position : acceptedPositions[0];
|
||||
|
||||
if (axisType === 'number' || axisType === 'date') {
|
||||
if (min) config.min = min;
|
||||
if (max) config.max = max;
|
||||
if (min) {
|
||||
config.min = min;
|
||||
}
|
||||
if (max) {
|
||||
config.max = max;
|
||||
}
|
||||
}
|
||||
|
||||
if (tickSize && axisType === 'number') config.tickSize = tickSize;
|
||||
if (tickSize && axisType === 'number') {
|
||||
config.tickSize = tickSize;
|
||||
}
|
||||
}
|
||||
|
||||
if (axisType === 'string')
|
||||
if (axisType === 'string') {
|
||||
config.ticks = map(ticks[axis].hash, (position, name) => [position, name]);
|
||||
}
|
||||
|
||||
if (axisType === 'date') config.mode = 'time';
|
||||
if (axisType === 'date') {
|
||||
config.mode = 'time';
|
||||
}
|
||||
|
||||
if (typeof font === 'object') config.font = font;
|
||||
if (typeof font === 'object') {
|
||||
config.font = font;
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
|
|
|
@ -17,7 +17,9 @@ export const defaultSpec = {
|
|||
};
|
||||
|
||||
export const getFontSpec = argFont => {
|
||||
if (!argFont || !argFont.spec) return defaultSpec;
|
||||
if (!argFont || !argFont.spec) {
|
||||
return defaultSpec;
|
||||
}
|
||||
|
||||
const { fontSize, lineHeight, fontStyle, fontWeight, fontFamily, color } = argFont.spec;
|
||||
const size = fontSize && Number(fontSize.replace('px', ''));
|
||||
|
|
|
@ -20,7 +20,9 @@ export const getTickHash = (columns, rows) => {
|
|||
|
||||
if (get(columns, 'x.type') === 'string') {
|
||||
sortBy(rows, ['x']).forEach(row => {
|
||||
if (!ticks.x.hash[row.x]) ticks.x.hash[row.x] = ticks.x.counter++;
|
||||
if (!ticks.x.hash[row.x]) {
|
||||
ticks.x.hash[row.x] = ticks.x.counter++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -28,7 +30,9 @@ export const getTickHash = (columns, rows) => {
|
|||
sortBy(rows, ['y'])
|
||||
.reverse()
|
||||
.forEach(row => {
|
||||
if (!ticks.y.hash[row.y]) ticks.y.hash[row.y] = ticks.y.counter++;
|
||||
if (!ticks.y.hash[row.y]) {
|
||||
ticks.y.hash[row.y] = ticks.y.counter++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,9 @@ export const plot = () => ({
|
|||
set(flotStyle, 'bubbles.size.min', seriesStyle.points);
|
||||
}
|
||||
|
||||
if (point.text != null) attrs.text = point.text;
|
||||
if (point.text != null) {
|
||||
attrs.text = point.text;
|
||||
}
|
||||
|
||||
return [x, y, attrs];
|
||||
}),
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
import { get } from 'lodash';
|
||||
|
||||
export const seriesStyleToFlot = seriesStyle => {
|
||||
if (!seriesStyle) return {};
|
||||
if (!seriesStyle) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const lines = get(seriesStyle, 'lines');
|
||||
const bars = get(seriesStyle, 'bars');
|
||||
|
@ -42,8 +44,12 @@ export const seriesStyleToFlot = seriesStyle => {
|
|||
},
|
||||
};
|
||||
|
||||
if (stack) flotStyle.stack = stack;
|
||||
if (color) flotStyle.color = color;
|
||||
if (stack) {
|
||||
flotStyle.stack = stack;
|
||||
}
|
||||
if (color) {
|
||||
flotStyle.color = color;
|
||||
}
|
||||
|
||||
return flotStyle;
|
||||
};
|
||||
|
|
|
@ -10,8 +10,11 @@ function combineColumns(arrayOfColumnsArrays) {
|
|||
return arrayOfColumnsArrays.reduce((resultingColumns, columns) => {
|
||||
if (columns) {
|
||||
columns.forEach(column => {
|
||||
if (resultingColumns.find(resultingColumn => resultingColumn.name === column.name)) return;
|
||||
else resultingColumns.push(column);
|
||||
if (resultingColumns.find(resultingColumn => resultingColumn.name === column.name)) {
|
||||
return;
|
||||
} else {
|
||||
resultingColumns.push(column);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -27,8 +30,9 @@ function combineAcross(datatableArray) {
|
|||
|
||||
// Sanity check
|
||||
datatableArray.forEach(datatable => {
|
||||
if (datatable.rows.length !== targetRowLength)
|
||||
if (datatable.rows.length !== targetRowLength) {
|
||||
throw new Error('All expressions must return the same number of rows');
|
||||
}
|
||||
});
|
||||
|
||||
// Merge columns and rows.
|
||||
|
@ -81,14 +85,18 @@ export const ply = () => ({
|
|||
// The way the function below is written you can add as many arbitrary named args as you want.
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (!args) return context;
|
||||
if (!args) {
|
||||
return context;
|
||||
}
|
||||
let byColumns;
|
||||
let originalDatatables;
|
||||
|
||||
if (args.by) {
|
||||
byColumns = args.by.map(by => {
|
||||
const column = context.columns.find(column => column.name === by);
|
||||
if (!column) throw new Error(`No such column: ${by}`);
|
||||
if (!column) {
|
||||
throw new Error(`No such column: ${by}`);
|
||||
}
|
||||
return column;
|
||||
});
|
||||
const keyedDatatables = groupBy(context.rows, row => JSON.stringify(pick(row, args.by)));
|
||||
|
@ -103,9 +111,11 @@ export const ply = () => ({
|
|||
const datatablePromises = originalDatatables.map(originalDatatable => {
|
||||
let expressionResultPromises = [];
|
||||
|
||||
if (args.expression)
|
||||
if (args.expression) {
|
||||
expressionResultPromises = args.expression.map(expression => expression(originalDatatable));
|
||||
else expressionResultPromises.push(Promise.resolve(originalDatatable));
|
||||
} else {
|
||||
expressionResultPromises.push(Promise.resolve(originalDatatable));
|
||||
}
|
||||
|
||||
return Promise.all(expressionResultPromises).then(combineAcross);
|
||||
});
|
||||
|
|
|
@ -71,11 +71,17 @@ export const progress = () => ({
|
|||
},
|
||||
},
|
||||
fn: (value, args) => {
|
||||
if (args.max <= 0) throw new Error(`'max' must be greater than 0`);
|
||||
if (value > args.max || value < 0) throw new Error(`Context must be between 0 and ${args.max}`);
|
||||
if (args.max <= 0) {
|
||||
throw new Error(`'max' must be greater than 0`);
|
||||
}
|
||||
if (value > args.max || value < 0) {
|
||||
throw new Error(`Context must be between 0 and ${args.max}`);
|
||||
}
|
||||
|
||||
let label = '';
|
||||
if (args.label) label = typeof args.label === 'string' ? args.label : `${value}`;
|
||||
if (args.label) {
|
||||
label = typeof args.label === 'string' ? args.label : `${value}`;
|
||||
}
|
||||
|
||||
let font = {};
|
||||
|
||||
|
|
|
@ -34,7 +34,9 @@ export const revealImage = () => ({
|
|||
},
|
||||
},
|
||||
fn: (percent, args) => {
|
||||
if (percent > 1 || percent < 0) throw new Error('input must be between 0 and 1');
|
||||
if (percent > 1 || percent < 0) {
|
||||
throw new Error('input must be between 0 and 1');
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'render',
|
||||
|
|
|
@ -22,7 +22,9 @@ export const rounddate = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (!args.format) return context;
|
||||
if (!args.format) {
|
||||
return context;
|
||||
}
|
||||
return moment.utc(moment.utc(context).format(args.format), args.format).valueOf();
|
||||
},
|
||||
});
|
||||
|
|
|
@ -34,8 +34,11 @@ export const staticColumn = () => ({
|
|||
const existingColumnIndex = columns.findIndex(({ name }) => name === args.name);
|
||||
const newColumn = { name: args.name, type };
|
||||
|
||||
if (existingColumnIndex > -1) columns[existingColumnIndex] = newColumn;
|
||||
else columns.push(newColumn);
|
||||
if (existingColumnIndex > -1) {
|
||||
columns[existingColumnIndex] = newColumn;
|
||||
} else {
|
||||
columns.push(newColumn);
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'datatable',
|
||||
|
|
|
@ -25,9 +25,13 @@ export const switchFn = () => ({
|
|||
const cases = args.case || [];
|
||||
for (let i = 0; i < cases.length; i++) {
|
||||
const { matches, result } = await cases[i]();
|
||||
if (matches) return result;
|
||||
if (matches) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (typeof args.default !== 'undefined') {
|
||||
return await args.default();
|
||||
}
|
||||
if (typeof args.default !== 'undefined') return await args.default();
|
||||
return context;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -33,7 +33,9 @@ export const timefilter = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args) => {
|
||||
if (!args.from && !args.to) return context;
|
||||
if (!args.from && !args.to) {
|
||||
return context;
|
||||
}
|
||||
|
||||
const { from, to, column } = args;
|
||||
const filter = {
|
||||
|
@ -42,16 +44,24 @@ export const timefilter = () => ({
|
|||
};
|
||||
|
||||
function parseAndValidate(str) {
|
||||
if (!str) return;
|
||||
if (!str) {
|
||||
return;
|
||||
}
|
||||
|
||||
const moment = dateMath.parse(str);
|
||||
if (!moment || !moment.isValid()) throw new Error(`Invalid date/time string ${str}`);
|
||||
if (!moment || !moment.isValid()) {
|
||||
throw new Error(`Invalid date/time string ${str}`);
|
||||
}
|
||||
return moment.toISOString();
|
||||
}
|
||||
|
||||
if (to != null) filter.to = parseAndValidate(to);
|
||||
if (to != null) {
|
||||
filter.to = parseAndValidate(to);
|
||||
}
|
||||
|
||||
if (from != null) filter.from = parseAndValidate(from);
|
||||
if (from != null) {
|
||||
filter.from = parseAndValidate(from);
|
||||
}
|
||||
|
||||
return { ...context, and: [...context.and, filter] };
|
||||
},
|
||||
|
|
|
@ -9,7 +9,11 @@ import ci from './ci.json';
|
|||
import shirts from './shirts.json';
|
||||
|
||||
export function getDemoRows(arg) {
|
||||
if (arg === 'ci') return cloneDeep(ci);
|
||||
if (arg === 'shirts') return cloneDeep(shirts);
|
||||
if (arg === 'ci') {
|
||||
return cloneDeep(ci);
|
||||
}
|
||||
if (arg === 'shirts') {
|
||||
return cloneDeep(shirts);
|
||||
}
|
||||
throw new Error(`Invalid data set: ${arg}, use 'ci' or 'shirts'.`);
|
||||
}
|
||||
|
|
|
@ -70,7 +70,9 @@ export const esdocs = () => ({
|
|||
|
||||
if (args.sort) {
|
||||
const [sortField, sortOrder] = args.sort.split(',').map(str => str.trim());
|
||||
if (sortField) query.order(`"${sortField}"`, sortOrder.toLowerCase() === 'asc');
|
||||
if (sortField) {
|
||||
query.order(`"${sortField}"`, sortOrder.toLowerCase() === 'asc');
|
||||
}
|
||||
}
|
||||
|
||||
return queryEsSQL(handlers.elasticsearchClient, {
|
||||
|
|
|
@ -56,7 +56,9 @@ export const pointseries = () => ({
|
|||
const columnNames = context.columns.map(col => col.name);
|
||||
const mathScope = pivotObjectArray(context.rows, columnNames);
|
||||
const autoQuoteColumn = col => {
|
||||
if (!columnNames.includes(col)) return col;
|
||||
if (!columnNames.includes(col)) {
|
||||
return col;
|
||||
}
|
||||
return col.match(/\s/) ? `'${col}'` : col;
|
||||
};
|
||||
|
||||
|
@ -78,7 +80,9 @@ export const pointseries = () => ({
|
|||
|
||||
if (isColumnReference(mathExp)) {
|
||||
// TODO: Do something better if the column does not exist
|
||||
if (!columnExists(columnNames, mathExp)) return;
|
||||
if (!columnExists(columnNames, mathExp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
dimensions.push({
|
||||
name: arg,
|
||||
|
@ -147,8 +151,9 @@ export const pointseries = () => ({
|
|||
const measureValues = measureNames.map(measure => {
|
||||
try {
|
||||
const ev = evaluate(args[measure], subScope);
|
||||
if (Array.isArray(ev))
|
||||
if (Array.isArray(ev)) {
|
||||
throw new Error('Expressions must be wrapped in a function such as sum()');
|
||||
}
|
||||
|
||||
return ev;
|
||||
} catch (e) {
|
||||
|
|
|
@ -12,7 +12,9 @@ import { getFieldNames } from './get_field_names';
|
|||
export function getExpressionType(columns, mathExpression) {
|
||||
// if isColumnReference returns true, then mathExpression is just a string
|
||||
// referencing a column in a datatable
|
||||
if (isColumnReference(mathExpression)) return getFieldType(columns, mathExpression);
|
||||
if (isColumnReference(mathExpression)) {
|
||||
return getFieldType(columns, mathExpression);
|
||||
}
|
||||
|
||||
const parsedMath = parse(mathExpression);
|
||||
|
||||
|
@ -22,7 +24,9 @@ export function getExpressionType(columns, mathExpression) {
|
|||
if (fieldNames.length > 0) {
|
||||
const fieldTypes = fieldNames.reduce((types, name) => {
|
||||
const type = getFieldType(columns, name);
|
||||
if (type !== 'null' && types.indexOf(type) === -1) return types.concat(type);
|
||||
if (type !== 'null' && types.indexOf(type) === -1) {
|
||||
return types.concat(type);
|
||||
}
|
||||
|
||||
return types;
|
||||
}, []);
|
||||
|
|
|
@ -5,9 +5,13 @@
|
|||
*/
|
||||
|
||||
export function getFieldNames(names, arg) {
|
||||
if (arg.args != null) return names.concat(arg.args.reduce(getFieldNames, []));
|
||||
if (arg.args != null) {
|
||||
return names.concat(arg.args.reduce(getFieldNames, []));
|
||||
}
|
||||
|
||||
if (typeof arg === 'string') return names.concat(arg);
|
||||
if (typeof arg === 'string') {
|
||||
return names.concat(arg);
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
import { parse } from 'tinymath';
|
||||
|
||||
export function isColumnReference(mathExpression) {
|
||||
if (mathExpression == null) mathExpression = 'null';
|
||||
if (mathExpression == null) {
|
||||
mathExpression = 'null';
|
||||
}
|
||||
const parsedMath = parse(mathExpression);
|
||||
return typeof parsedMath === 'string';
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ export const pie = () => ({
|
|||
help: 'Render a pie chart from data',
|
||||
reuseDomNode: false,
|
||||
render(domNode, config, handlers) {
|
||||
if (!includes($.plot.plugins, piePlugin)) $.plot.plugins.push(piePlugin);
|
||||
if (!includes($.plot.plugins, piePlugin)) {
|
||||
$.plot.plugins.push(piePlugin);
|
||||
}
|
||||
|
||||
config.options.legend.labelBoxBorderColor = 'transparent';
|
||||
|
||||
|
@ -49,12 +51,17 @@ export const pie = () => ({
|
|||
|
||||
let plot;
|
||||
function draw() {
|
||||
if (domNode.clientHeight < 1 || domNode.clientWidth < 1) return;
|
||||
if (domNode.clientHeight < 1 || domNode.clientWidth < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$(domNode).empty();
|
||||
if (!config.data || !config.data.length) $(domNode).empty();
|
||||
else plot = $.plot($(domNode), config.data, config.options);
|
||||
if (!config.data || !config.data.length) {
|
||||
$(domNode).empty();
|
||||
} else {
|
||||
plot = $.plot($(domNode), config.data, config.options);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
// Nope
|
||||
|
@ -62,7 +69,9 @@ export const pie = () => ({
|
|||
}
|
||||
|
||||
function destroy() {
|
||||
if (plot) plot.shutdown();
|
||||
if (plot) {
|
||||
plot.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
handlers.onDestroy(destroy);
|
||||
|
|
|
@ -96,46 +96,65 @@ function init(plot) {
|
|||
// set labels.show
|
||||
|
||||
if (options.series.pie.label.show === 'auto') {
|
||||
if (options.legend.show) options.series.pie.label.show = false;
|
||||
else options.series.pie.label.show = true;
|
||||
if (options.legend.show) {
|
||||
options.series.pie.label.show = false;
|
||||
} else {
|
||||
options.series.pie.label.show = true;
|
||||
}
|
||||
}
|
||||
|
||||
// set radius
|
||||
|
||||
if (options.series.pie.radius === 'auto') {
|
||||
if (options.series.pie.label.show) options.series.pie.radius = 3 / 4;
|
||||
else options.series.pie.radius = 1;
|
||||
if (options.series.pie.label.show) {
|
||||
options.series.pie.radius = 3 / 4;
|
||||
} else {
|
||||
options.series.pie.radius = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// ensure sane tilt
|
||||
|
||||
if (options.series.pie.tilt > 1) options.series.pie.tilt = 1;
|
||||
else if (options.series.pie.tilt < 0) options.series.pie.tilt = 0;
|
||||
if (options.series.pie.tilt > 1) {
|
||||
options.series.pie.tilt = 1;
|
||||
} else if (options.series.pie.tilt < 0) {
|
||||
options.series.pie.tilt = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plot.hooks.bindEvents.push(function(plot, eventHolder) {
|
||||
const options = plot.getOptions();
|
||||
if (options.series.pie.show) {
|
||||
if (options.grid.hoverable) eventHolder.unbind('mousemove').mousemove(onMouseMove);
|
||||
if (options.grid.hoverable) {
|
||||
eventHolder.unbind('mousemove').mousemove(onMouseMove);
|
||||
}
|
||||
|
||||
if (options.grid.clickable) eventHolder.unbind('click').click(onClick);
|
||||
if (options.grid.clickable) {
|
||||
eventHolder.unbind('click').click(onClick);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
plot.hooks.processDatapoints.push(function(plot, series, data, datapoints) {
|
||||
const options = plot.getOptions();
|
||||
if (options.series.pie.show) processDatapoints(plot, series, data, datapoints);
|
||||
if (options.series.pie.show) {
|
||||
processDatapoints(plot, series, data, datapoints);
|
||||
}
|
||||
});
|
||||
|
||||
plot.hooks.drawOverlay.push(function(plot, octx) {
|
||||
const options = plot.getOptions();
|
||||
if (options.series.pie.show) drawOverlay(plot, octx);
|
||||
if (options.series.pie.show) {
|
||||
drawOverlay(plot, octx);
|
||||
}
|
||||
});
|
||||
|
||||
plot.hooks.draw.push(function(plot, newCtx) {
|
||||
const options = plot.getOptions();
|
||||
if (options.series.pie.show) draw(plot, newCtx);
|
||||
if (options.series.pie.show) {
|
||||
draw(plot, newCtx);
|
||||
}
|
||||
});
|
||||
|
||||
function processDatapoints(plot) {
|
||||
|
@ -167,12 +186,17 @@ function init(plot) {
|
|||
// new one; this is more efficient and preserves any extra data
|
||||
// that the user may have stored in higher indexes.
|
||||
|
||||
if (Array.isArray(value) && value.length === 1) value = value[0];
|
||||
if (Array.isArray(value) && value.length === 1) {
|
||||
value = value[0];
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
// Equivalent to $.isNumeric() but compatible with jQuery < 1.7
|
||||
if (!isNaN(parseFloat(value[1])) && isFinite(value[1])) value[1] = +value[1];
|
||||
else value[1] = 0;
|
||||
if (!isNaN(parseFloat(value[1])) && isFinite(value[1])) {
|
||||
value[1] = +value[1];
|
||||
} else {
|
||||
value[1] = 0;
|
||||
}
|
||||
} else if (!isNaN(parseFloat(value)) && isFinite(value)) {
|
||||
value = [1, +value];
|
||||
} else {
|
||||
|
@ -184,7 +208,9 @@ function init(plot) {
|
|||
|
||||
// Sum up all the slices, so we can calculate percentages for each
|
||||
|
||||
for (let i = 0; i < data.length; ++i) total += data[i].data[0][1];
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
total += data[i].data[0][1];
|
||||
}
|
||||
|
||||
// Count the number of slices with percentages below the combine
|
||||
// threshold; if it turns out to be just one, we won't combine.
|
||||
|
@ -194,7 +220,9 @@ function init(plot) {
|
|||
if (value / total <= options.series.pie.combine.threshold) {
|
||||
combined += value;
|
||||
numCombined++;
|
||||
if (!color) color = data[i].color;
|
||||
if (!color) {
|
||||
color = data[i].color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -229,7 +257,9 @@ function init(plot) {
|
|||
}
|
||||
|
||||
function draw(plot, newCtx) {
|
||||
if (!target) return; // if no series were passed
|
||||
if (!target) {
|
||||
return;
|
||||
} // if no series were passed
|
||||
|
||||
const canvasWidth = plot.getPlaceholder().width();
|
||||
const canvasHeight = plot.getPlaceholder().height();
|
||||
|
@ -272,11 +302,17 @@ function init(plot) {
|
|||
centerLeft = canvasWidth / 2;
|
||||
|
||||
if (options.series.pie.offset.left === 'auto') {
|
||||
if (options.legend.position.match('w')) centerLeft += legendWidth / 2;
|
||||
else centerLeft -= legendWidth / 2;
|
||||
if (options.legend.position.match('w')) {
|
||||
centerLeft += legendWidth / 2;
|
||||
} else {
|
||||
centerLeft -= legendWidth / 2;
|
||||
}
|
||||
|
||||
if (centerLeft < maxRadius) centerLeft = maxRadius;
|
||||
else if (centerLeft > canvasWidth - maxRadius) centerLeft = canvasWidth - maxRadius;
|
||||
if (centerLeft < maxRadius) {
|
||||
centerLeft = maxRadius;
|
||||
} else if (centerLeft > canvasWidth - maxRadius) {
|
||||
centerLeft = canvasWidth - maxRadius;
|
||||
}
|
||||
} else {
|
||||
centerLeft += options.series.pie.offset.left;
|
||||
}
|
||||
|
@ -288,11 +324,15 @@ function init(plot) {
|
|||
// indicating that all the labels fit, or we try too many times.
|
||||
|
||||
do {
|
||||
if (attempts > 0) maxRadius *= REDRAW_SHRINK;
|
||||
if (attempts > 0) {
|
||||
maxRadius *= REDRAW_SHRINK;
|
||||
}
|
||||
|
||||
attempts += 1;
|
||||
clear();
|
||||
if (options.series.pie.tilt <= 0.8) drawShadow();
|
||||
if (options.series.pie.tilt <= 0.8) {
|
||||
drawShadow();
|
||||
}
|
||||
} while (!drawPie() && attempts < REDRAW_ATTEMPTS);
|
||||
|
||||
if (attempts >= REDRAW_ATTEMPTS) {
|
||||
|
@ -331,8 +371,9 @@ function init(plot) {
|
|||
radius >= canvasWidth / 2 - shadowLeft ||
|
||||
radius * options.series.pie.tilt >= canvasHeight / 2 - shadowTop ||
|
||||
radius <= edge
|
||||
)
|
||||
return; // shadow would be outside canvas, so don't draw it
|
||||
) {
|
||||
return;
|
||||
} // shadow would be outside canvas, so don't draw it
|
||||
|
||||
ctx.save();
|
||||
ctx.translate(shadowLeft, shadowTop);
|
||||
|
@ -386,8 +427,9 @@ function init(plot) {
|
|||
ctx.save();
|
||||
ctx.lineWidth = options.series.pie.stroke.width;
|
||||
currentAngle = startAngle;
|
||||
for (let i = 0; i < slices.length; ++i)
|
||||
for (let i = 0; i < slices.length; ++i) {
|
||||
drawSlice(slices[i].angle, options.series.pie.stroke.color, false);
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
}
|
||||
|
@ -400,11 +442,16 @@ function init(plot) {
|
|||
|
||||
// Draw the labels, returning true if they fit within the plot
|
||||
|
||||
if (options.series.pie.label.show) return drawLabels();
|
||||
else return true;
|
||||
if (options.series.pie.label.show) {
|
||||
return drawLabels();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
function drawSlice(angle, color, fill) {
|
||||
if (angle <= 0 || isNaN(angle)) return;
|
||||
if (angle <= 0 || isNaN(angle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fill) {
|
||||
ctx.fillStyle = color;
|
||||
|
@ -414,7 +461,9 @@ function init(plot) {
|
|||
}
|
||||
|
||||
ctx.beginPath();
|
||||
if (Math.abs(angle - Math.PI * 2) > 0.000000001) ctx.moveTo(0, 0); // Center of the pie
|
||||
if (Math.abs(angle - Math.PI * 2) > 0.000000001) {
|
||||
ctx.moveTo(0, 0);
|
||||
} // Center of the pie
|
||||
|
||||
//ctx.arc(0, 0, radius, 0, angle, false); // This doesn't work properly in Opera
|
||||
ctx.arc(0, 0, radius, currentAngle, currentAngle + angle / 2, false);
|
||||
|
@ -423,8 +472,11 @@ function init(plot) {
|
|||
//ctx.rotate(angle); // This doesn't work properly in Opera
|
||||
currentAngle += angle;
|
||||
|
||||
if (fill) ctx.fill();
|
||||
else ctx.stroke();
|
||||
if (fill) {
|
||||
ctx.fill();
|
||||
} else {
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
function drawLabels() {
|
||||
|
@ -435,8 +487,11 @@ function init(plot) {
|
|||
: maxRadius * options.series.pie.label.radius;
|
||||
|
||||
for (let i = 0; i < slices.length; ++i) {
|
||||
if (slices[i].percent >= options.series.pie.label.threshold * 100)
|
||||
if (!drawLabel(slices[i], currentAngle, i)) return false;
|
||||
if (slices[i].percent >= options.series.pie.label.threshold * 100) {
|
||||
if (!drawLabel(slices[i], currentAngle, i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
currentAngle += slices[i].angle;
|
||||
}
|
||||
|
@ -444,7 +499,9 @@ function init(plot) {
|
|||
return true;
|
||||
|
||||
function drawLabel(slice, startAngle, index) {
|
||||
if (slice.data[0][1] === 0) return true;
|
||||
if (slice.data[0][1] === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// format label text
|
||||
|
||||
|
@ -452,10 +509,15 @@ function init(plot) {
|
|||
let text;
|
||||
const plf = options.series.pie.label.formatter;
|
||||
|
||||
if (lf) text = lf(slice.label, slice);
|
||||
else text = slice.label;
|
||||
if (lf) {
|
||||
text = lf(slice.label, slice);
|
||||
} else {
|
||||
text = slice.label;
|
||||
}
|
||||
|
||||
if (plf) text = plf(text, slice);
|
||||
if (plf) {
|
||||
text = plf(text, slice);
|
||||
}
|
||||
|
||||
const halfAngle = (startAngle + slice.angle + startAngle) / 2;
|
||||
const x = centerLeft + Math.round(Math.cos(halfAngle) * radius);
|
||||
|
@ -487,15 +549,18 @@ function init(plot) {
|
|||
0 - labelLeft > 0 ||
|
||||
canvasHeight - (labelTop + label.height()) < 0 ||
|
||||
canvasWidth - (labelLeft + label.width()) < 0
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.series.pie.label.background.opacity !== 0) {
|
||||
// put in the transparent background separately to avoid blended labels and label boxes
|
||||
|
||||
let c = options.series.pie.label.background.color;
|
||||
|
||||
if (c == null) c = slice.color;
|
||||
if (c == null) {
|
||||
c = slice.color;
|
||||
}
|
||||
|
||||
const pos = 'top:' + labelTop + 'px;left:' + labelLeft + 'px;';
|
||||
$(
|
||||
|
@ -662,13 +727,17 @@ function init(plot) {
|
|||
|
||||
for (let i = 0; i < highlights.length; ++i) {
|
||||
const h = highlights[i];
|
||||
if (h.auto === eventname && !(item && h.series === item.series)) unhighlight(h.series);
|
||||
if (h.auto === eventname && !(item && h.series === item.series)) {
|
||||
unhighlight(h.series);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// highlight the slice
|
||||
|
||||
if (item) highlight(item.series, eventname);
|
||||
if (item) {
|
||||
highlight(item.series, eventname);
|
||||
}
|
||||
|
||||
// trigger any hover bind events
|
||||
|
||||
|
@ -712,7 +781,9 @@ function init(plot) {
|
|||
function indexOfHighlight(s) {
|
||||
for (let i = 0; i < highlights.length; ++i) {
|
||||
const h = highlights[i];
|
||||
if (h.series === s) return i;
|
||||
if (h.series === s) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -729,19 +800,25 @@ function init(plot) {
|
|||
octx.translate(centerLeft, centerTop);
|
||||
octx.scale(1, options.series.pie.tilt);
|
||||
|
||||
for (let i = 0; i < highlights.length; ++i) drawHighlight(highlights[i].series);
|
||||
for (let i = 0; i < highlights.length; ++i) {
|
||||
drawHighlight(highlights[i].series);
|
||||
}
|
||||
|
||||
drawDonutHole(octx);
|
||||
|
||||
octx.restore();
|
||||
|
||||
function drawHighlight(series) {
|
||||
if (series.angle <= 0 || isNaN(series.angle)) return;
|
||||
if (series.angle <= 0 || isNaN(series.angle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//octx.fillStyle = parseColor(options.series.pie.highlight.color).scale(null, null, null, options.series.pie.highlight.opacity).toString();
|
||||
octx.fillStyle = 'rgba(255, 255, 255, ' + options.series.pie.highlight.opacity + ')'; // this is temporary until we have access to parseColor
|
||||
octx.beginPath();
|
||||
if (Math.abs(series.angle - Math.PI * 2) > 0.000000001) octx.moveTo(0, 0); // Center of the pie
|
||||
if (Math.abs(series.angle - Math.PI * 2) > 0.000000001) {
|
||||
octx.moveTo(0, 0);
|
||||
} // Center of the pie
|
||||
|
||||
octx.arc(0, 0, radius, series.startAngle, series.startAngle + series.angle / 2, false);
|
||||
octx.arc(
|
||||
|
|
|
@ -15,12 +15,18 @@ import './plot.scss';
|
|||
|
||||
const render = (domNode, config, handlers) => {
|
||||
// TODO: OH NOES
|
||||
if (!includes($.plot.plugins, size)) $.plot.plugins.push(size);
|
||||
if (!includes($.plot.plugins, text)) $.plot.plugins.push(text);
|
||||
if (!includes($.plot.plugins, size)) {
|
||||
$.plot.plugins.push(size);
|
||||
}
|
||||
if (!includes($.plot.plugins, text)) {
|
||||
$.plot.plugins.push(text);
|
||||
}
|
||||
|
||||
let plot;
|
||||
function draw() {
|
||||
if (domNode.clientHeight < 1 || domNode.clientWidth < 1) return;
|
||||
if (domNode.clientHeight < 1 || domNode.clientWidth < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.font) {
|
||||
const legendFormatter = label => {
|
||||
|
@ -46,7 +52,9 @@ const render = (domNode, config, handlers) => {
|
|||
}
|
||||
|
||||
function destroy() {
|
||||
if (plot) plot.shutdown();
|
||||
if (plot) {
|
||||
plot.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
handlers.onDestroy(destroy);
|
||||
|
|
|
@ -53,7 +53,9 @@ const options = {
|
|||
|
||||
function drawbubbleDefault(ctx, series, x, y, radius, c) {
|
||||
ctx.fillStyle = c;
|
||||
if (series.bubbles.fill) ctx.globalAlpha = series.bubbles.fill;
|
||||
if (series.bubbles.fill) {
|
||||
ctx.globalAlpha = series.bubbles.fill;
|
||||
}
|
||||
ctx.strokeStyle = c;
|
||||
|
||||
ctx.lineWidth = Math.round(radius / 3);
|
||||
|
@ -61,15 +63,20 @@ function drawbubbleDefault(ctx, series, x, y, radius, c) {
|
|||
|
||||
ctx.arc(x, y, radius, 0, Math.PI * 2, true);
|
||||
ctx.closePath();
|
||||
if (series.bubbles.fill) ctx.fill();
|
||||
else ctx.stroke();
|
||||
if (series.bubbles.fill) {
|
||||
ctx.fill();
|
||||
} else {
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
function init(plot) {
|
||||
plot.hooks.processOptions.push(processOptions);
|
||||
|
||||
function processOptions(plot, options) {
|
||||
if (options.series.bubbles.active) plot.hooks.drawSeries.push(drawSeries);
|
||||
if (options.series.bubbles.active) {
|
||||
plot.hooks.drawSeries.push(drawSeries);
|
||||
}
|
||||
}
|
||||
|
||||
function drawSeries(plot, ctx, series) {
|
||||
|
@ -88,8 +95,12 @@ function init(plot) {
|
|||
|
||||
const delta = maxPoint - minPoint;
|
||||
const radius = (function() {
|
||||
if (size == null) return 0; // If there is no size, draw nothing
|
||||
if (delta === 0) return series.bubbles.size.min; // If there is no difference between the min and the max, draw the minimum bubble.
|
||||
if (size == null) {
|
||||
return 0;
|
||||
} // If there is no size, draw nothing
|
||||
if (delta === 0) {
|
||||
return series.bubbles.size.min;
|
||||
} // If there is no difference between the min and the max, draw the minimum bubble.
|
||||
|
||||
// Otherwise draw something between the min and max acceptable radius.
|
||||
return (
|
||||
|
|
|
@ -30,7 +30,9 @@ function draw(plot, ctx) {
|
|||
$('.valueLabel', plot.getPlaceholder()).remove();
|
||||
plot.getData().forEach(function(series) {
|
||||
const show = get(series.numbers, 'show');
|
||||
if (!show) return;
|
||||
if (!show) {
|
||||
return;
|
||||
}
|
||||
|
||||
let points = series.data;
|
||||
|
||||
|
@ -54,7 +56,9 @@ function draw(plot, ctx) {
|
|||
ctx.textAlign = 'center';
|
||||
|
||||
function writeText(text, x, y) {
|
||||
if (typeof text === 'undefined') return;
|
||||
if (typeof text === 'undefined') {
|
||||
return;
|
||||
}
|
||||
const textNode = $('<div/>')
|
||||
.text(String(text))
|
||||
.addClass('valueLabel')
|
||||
|
|
|
@ -72,10 +72,12 @@ export const progress = () => ({
|
|||
text.textContent = label;
|
||||
text.setAttribute('className', 'canvasProgress__label');
|
||||
|
||||
if (shape === 'horizontalPill')
|
||||
if (shape === 'horizontalPill') {
|
||||
text.setAttribute('x', parseInt(text.getAttribute('x'), 10) + offset / 2);
|
||||
if (shape === 'verticalPill')
|
||||
}
|
||||
if (shape === 'verticalPill') {
|
||||
text.setAttribute('y', parseInt(text.getAttribute('y'), 10) - offset / 2);
|
||||
}
|
||||
|
||||
Object.assign(text.style, font.spec);
|
||||
shapeSvg.appendChild(text);
|
||||
|
@ -101,7 +103,9 @@ export const progress = () => ({
|
|||
shapeSvg.setAttribute('width', domNode.offsetWidth);
|
||||
shapeSvg.setAttribute('height', domNode.offsetHeight);
|
||||
|
||||
if (domNode.firstChild) domNode.removeChild(domNode.firstChild);
|
||||
if (domNode.firstChild) {
|
||||
domNode.removeChild(domNode.firstChild);
|
||||
}
|
||||
domNode.appendChild(shapeSvg);
|
||||
|
||||
handlers.onResize(() => {
|
||||
|
|
|
@ -24,8 +24,11 @@ export const repeatImage = () => ({
|
|||
const container = $('<div class="repeatImage" style="pointer-events: none;">');
|
||||
|
||||
function setSize(img) {
|
||||
if (img.naturalHeight > img.naturalWidth) img.height = settings.size;
|
||||
else img.width = settings.size;
|
||||
if (img.naturalHeight > img.naturalWidth) {
|
||||
img.height = settings.size;
|
||||
} else {
|
||||
img.width = settings.size;
|
||||
}
|
||||
}
|
||||
|
||||
function finish() {
|
||||
|
@ -36,11 +39,15 @@ export const repeatImage = () => ({
|
|||
const img = new Image();
|
||||
img.onload = function() {
|
||||
setSize(img);
|
||||
if (settings.max && settings.count > settings.max) settings.count = settings.max;
|
||||
if (settings.max && settings.count > settings.max) {
|
||||
settings.count = settings.max;
|
||||
}
|
||||
times(settings.count, () => container.append(img.cloneNode(true)));
|
||||
|
||||
if (isValidUrl(settings.emptyImage)) {
|
||||
if (settings.max == null) throw new Error('max must be set if using an emptyImage');
|
||||
if (settings.max == null) {
|
||||
throw new Error('max must be set if using an emptyImage');
|
||||
}
|
||||
|
||||
const emptyImage = new Image();
|
||||
emptyImage.onload = function() {
|
||||
|
|
|
@ -42,8 +42,11 @@ export const revealImage = () => ({
|
|||
|
||||
function finish() {
|
||||
const firstChild = domNode.firstChild;
|
||||
if (firstChild) domNode.replaceChild(aligner, firstChild);
|
||||
else domNode.appendChild(aligner);
|
||||
if (firstChild) {
|
||||
domNode.replaceChild(aligner, firstChild);
|
||||
} else {
|
||||
domNode.appendChild(aligner);
|
||||
}
|
||||
handlers.done();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,12 @@ export const shape = () => ({
|
|||
|
||||
const shapeContent = shapeSvg.firstElementChild;
|
||||
|
||||
if (fill) shapeContent.setAttribute('fill', fill);
|
||||
if (border) shapeContent.setAttribute('stroke', border);
|
||||
if (fill) {
|
||||
shapeContent.setAttribute('fill', fill);
|
||||
}
|
||||
if (border) {
|
||||
shapeContent.setAttribute('stroke', border);
|
||||
}
|
||||
const strokeWidth = Math.max(borderWidth, 0);
|
||||
shapeContent.setAttribute('stroke-width', strokeWidth);
|
||||
shapeContent.setAttribute('stroke-miterlimit', 999);
|
||||
|
@ -64,7 +68,9 @@ export const shape = () => ({
|
|||
shapeSvg.setAttribute('viewBox', [minX, minY, shapeWidth, shapeHeight].join(' '));
|
||||
|
||||
const oldShape = domNode.firstElementChild;
|
||||
if (oldShape) domNode.removeChild(oldShape);
|
||||
if (oldShape) {
|
||||
domNode.removeChild(oldShape);
|
||||
}
|
||||
|
||||
domNode.appendChild(shapeSvg);
|
||||
};
|
||||
|
|
|
@ -12,7 +12,9 @@ export const DatetimeInput = compose(
|
|||
withState('strValue', 'setStrValue', ({ moment }) => moment.format('YYYY-MM-DD HH:mm:ss')),
|
||||
lifecycle({
|
||||
componentWillReceiveProps({ moment, setStrValue, setValid }) {
|
||||
if (this.props.moment.isSame(moment)) return;
|
||||
if (this.props.moment.isSame(moment)) {
|
||||
return;
|
||||
}
|
||||
setStrValue(moment.format('YYYY-MM-DD HH:mm:ss'));
|
||||
setValid(true);
|
||||
},
|
||||
|
|
|
@ -20,9 +20,11 @@ export const DatetimeRangeAbsolute = ({ from, to, onSelect }) => (
|
|||
onValueChange={val => onSelect(val, to)}
|
||||
onSelect={val => {
|
||||
// sets the time to start of day if only the date was selected
|
||||
if (moment(from).format('hh:mm:ss a') === val.format('hh:mm:ss a'))
|
||||
if (moment(from).format('hh:mm:ss a') === val.format('hh:mm:ss a')) {
|
||||
onSelect(val.startOf('day'), to);
|
||||
else onSelect(val, to);
|
||||
} else {
|
||||
onSelect(val, to);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
@ -34,9 +36,11 @@ export const DatetimeRangeAbsolute = ({ from, to, onSelect }) => (
|
|||
onValueChange={val => onSelect(from, val)}
|
||||
onSelect={val => {
|
||||
// set the time to end of day if only the date was selected
|
||||
if (moment(to).format('hh:mm:ss a') === val.format('hh:mm:ss a'))
|
||||
if (moment(to).format('hh:mm:ss a') === val.format('hh:mm:ss a')) {
|
||||
onSelect(from, moment(val).endOf('day'));
|
||||
else onSelect(from, val);
|
||||
} else {
|
||||
onSelect(from, val);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -43,7 +43,9 @@ export function formatDuration(from, to) {
|
|||
if (to.toString() === 'now' && fromParts[0] === 'now' && fromParts[1]) {
|
||||
const rounded = fromParts[1].split('/');
|
||||
text = 'Last ' + rounded[0];
|
||||
if (rounded[1]) text = text + ' rounded to the ' + timeUnits[rounded[1]];
|
||||
if (rounded[1]) {
|
||||
text = text + ' rounded to the ' + timeUnits[rounded[1]];
|
||||
}
|
||||
|
||||
return text;
|
||||
} else {
|
||||
|
|
|
@ -26,8 +26,11 @@ export const TimeFilter = ({ compact, filter, setFilter, commit }) => {
|
|||
commit(filter);
|
||||
}
|
||||
|
||||
if (compact) return <TimePickerMini from={from} to={to} onSelect={doSetFilter} />;
|
||||
else return <TimePicker from={from} to={to} onSelect={doSetFilter} />;
|
||||
if (compact) {
|
||||
return <TimePickerMini from={from} to={to} onSelect={doSetFilter} />;
|
||||
} else {
|
||||
return <TimePicker from={from} to={to} onSelect={doSetFilter} />;
|
||||
}
|
||||
};
|
||||
|
||||
TimeFilter.propTypes = {
|
||||
|
|
|
@ -51,7 +51,9 @@ export class ExtendedTemplate extends React.PureComponent {
|
|||
render() {
|
||||
const isDisabled = typeof this.props.argValue === 'boolean' && this.props.argValue === false;
|
||||
|
||||
if (isDisabled) return <EuiText color="subdued">The axis is disabled</EuiText>;
|
||||
if (isDisabled) {
|
||||
return <EuiText color="subdued">The axis is disabled</EuiText>;
|
||||
}
|
||||
|
||||
const positions = {
|
||||
xaxis: ['bottom', 'top'],
|
||||
|
|
|
@ -58,14 +58,20 @@ class DatacolumnArgInput extends Component {
|
|||
// if setting size, auto-select the first column if no column is already set
|
||||
if (fn === 'size') {
|
||||
const col = column || (columns[0] && columns[0].name);
|
||||
if (col) return onValueChange(`${fn}(${maybeQuoteValue(col)})`);
|
||||
if (col) {
|
||||
return onValueChange(`${fn}(${maybeQuoteValue(col)})`);
|
||||
}
|
||||
}
|
||||
|
||||
// this.inputRefs.column is the column selection, if there is no value, do nothing
|
||||
if (valueNotSet(column)) return setMathFunction(fn);
|
||||
if (valueNotSet(column)) {
|
||||
return setMathFunction(fn);
|
||||
}
|
||||
|
||||
// this.inputRefs.fn is the math function to use, if it's not set, just use the value input
|
||||
if (valueNotSet(fn)) return onValueChange(column);
|
||||
if (valueNotSet(fn)) {
|
||||
return onValueChange(column);
|
||||
}
|
||||
|
||||
// this.inputRefs.fn has a value, so use it as a math.js expression
|
||||
onValueChange(`${fn}(${maybeQuoteValue(column)})`);
|
||||
|
@ -76,7 +82,9 @@ class DatacolumnArgInput extends Component {
|
|||
const options = [{ value: '', text: 'select column', disabled: true }];
|
||||
|
||||
sortBy(columns, 'name').forEach(column => {
|
||||
if (allowedTypes && !allowedTypes.includes(column.type)) return;
|
||||
if (allowedTypes && !allowedTypes.includes(column.type)) {
|
||||
return;
|
||||
}
|
||||
options.push({ value: column.name, text: column.name });
|
||||
});
|
||||
|
||||
|
@ -108,7 +116,9 @@ class DatacolumnArgInput extends Component {
|
|||
const EnhancedDatacolumnArgInput = compose(
|
||||
withPropsOnChange(['argValue', 'columns'], ({ argValue, columns }) => ({
|
||||
mathValue: (argValue => {
|
||||
if (getType(argValue) !== 'string') return { error: 'argValue is not a string type' };
|
||||
if (getType(argValue) !== 'string') {
|
||||
return { error: 'argValue is not a string type' };
|
||||
}
|
||||
try {
|
||||
const matchedCol = columns.find(({ name }) => argValue === name);
|
||||
const val = matchedCol ? maybeQuoteValue(matchedCol.name) : argValue;
|
||||
|
|
|
@ -21,7 +21,9 @@ export const SimpleMathFunction = ({ onChange, value, inputRef, onlymath }) => {
|
|||
{ text: 'Unique', value: 'unique' },
|
||||
];
|
||||
|
||||
if (!onlymath) options.unshift({ text: 'Value', value: '' });
|
||||
if (!onlymath) {
|
||||
options.unshift({ text: 'Value', value: '' });
|
||||
}
|
||||
|
||||
return (
|
||||
<EuiSelect compressed options={options} inputRef={inputRef} value={value} onChange={onChange} />
|
||||
|
|
|
@ -32,7 +32,9 @@ class ImageUpload extends React.Component {
|
|||
|
||||
let urlType = Object.keys(props.assets).length ? 'asset' : 'file';
|
||||
// if not a valid base64 string, will show as missing asset icon
|
||||
if (isValidHttpUrl(url)) urlType = 'link';
|
||||
if (isValidHttpUrl(url)) {
|
||||
urlType = 'link';
|
||||
}
|
||||
|
||||
this.inputRefs = {};
|
||||
|
||||
|
|
|
@ -19,10 +19,14 @@ const PaletteArgInput = ({ onValueChange, argValue, renderError }) => {
|
|||
// TODO: This is weird, its basically a reimplementation of what the interpretter would return.
|
||||
// Probably a better way todo this, and maybe a better way to handle template stype objects in general?
|
||||
function astToPalette({ chain }) {
|
||||
if (chain.length !== 1 || chain[0].function !== 'palette') throwNotParsed();
|
||||
if (chain.length !== 1 || chain[0].function !== 'palette') {
|
||||
throwNotParsed();
|
||||
}
|
||||
try {
|
||||
const colors = chain[0].arguments._.map(astObj => {
|
||||
if (getType(astObj) !== 'string') throwNotParsed();
|
||||
if (getType(astObj) !== 'string') {
|
||||
throwNotParsed();
|
||||
}
|
||||
return astObj;
|
||||
});
|
||||
|
||||
|
|
|
@ -11,7 +11,9 @@ import { templateFromReactComponent } from '../../../public/lib/template_from_re
|
|||
|
||||
const ToggleArgInput = ({ onValueChange, argValue, argId, renderError }) => {
|
||||
const handleChange = () => onValueChange(!argValue);
|
||||
if (typeof argValue !== 'boolean') renderError();
|
||||
if (typeof argValue !== 'boolean') {
|
||||
renderError();
|
||||
}
|
||||
return <EuiSwitch id={argId} checked={argValue} onChange={handleChange} />;
|
||||
};
|
||||
|
||||
|
|
|
@ -13,8 +13,11 @@ import { templateFromReactComponent } from '../../../public/lib/template_from_re
|
|||
class EssqlDatasource extends PureComponent {
|
||||
componentDidMount() {
|
||||
const query = this.getQuery();
|
||||
if (typeof query !== 'string') this.setArg(this.getArgName(), this.defaultQuery);
|
||||
else this.props.setInvalid(!query.trim());
|
||||
if (typeof query !== 'string') {
|
||||
this.setArg(this.getArgName(), this.defaultQuery);
|
||||
} else {
|
||||
this.props.setInvalid(!query.trim());
|
||||
}
|
||||
}
|
||||
|
||||
defaultQuery = 'SELECT * FROM "logstash*"';
|
||||
|
@ -25,8 +28,12 @@ class EssqlDatasource extends PureComponent {
|
|||
// and set them for the data source UI.
|
||||
getArgName = () => {
|
||||
const { args } = this.props;
|
||||
if (getSimpleArg('_', args)[0]) return '_';
|
||||
if (getSimpleArg('q', args)[0]) return 'q';
|
||||
if (getSimpleArg('_', args)[0]) {
|
||||
return '_';
|
||||
}
|
||||
if (getSimpleArg('q', args)[0]) {
|
||||
return 'q';
|
||||
}
|
||||
return 'query';
|
||||
};
|
||||
|
||||
|
|
|
@ -28,8 +28,12 @@ const TimelionDatasource = ({ args, updateArgs }) => {
|
|||
};
|
||||
|
||||
const getArgName = () => {
|
||||
if (getSimpleArg('_', args)[0]) return '_';
|
||||
if (getSimpleArg('q', args)[0]) return 'q';
|
||||
if (getSimpleArg('_', args)[0]) {
|
||||
return '_';
|
||||
}
|
||||
if (getSimpleArg('q', args)[0]) {
|
||||
return 'q';
|
||||
}
|
||||
return 'query';
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,9 @@ export const math = () => ({
|
|||
},
|
||||
],
|
||||
resolve({ context }) {
|
||||
if (getState(context) !== 'ready') return { columns: [] };
|
||||
if (getState(context) !== 'ready') {
|
||||
return { columns: [] };
|
||||
}
|
||||
return { columns: get(getValue(context), 'columns', []) };
|
||||
},
|
||||
});
|
||||
|
|
|
@ -43,7 +43,9 @@ export const pointseries = () => ({
|
|||
},
|
||||
],
|
||||
resolve({ context }) {
|
||||
if (getState(context) !== 'ready') return { columns: [] };
|
||||
if (getState(context) !== 'ready') {
|
||||
return { columns: [] };
|
||||
}
|
||||
return { columns: get(getValue(context), 'columns', []) };
|
||||
},
|
||||
});
|
||||
|
|
|
@ -23,7 +23,9 @@ export const sort = () => ({
|
|||
},
|
||||
],
|
||||
resolve({ context }) {
|
||||
if (getState(context) === 'ready') return { columns: get(getValue(context), 'columns', []) };
|
||||
if (getState(context) === 'ready') {
|
||||
return { columns: get(getValue(context), 'columns', []) };
|
||||
}
|
||||
|
||||
return { columns: [] };
|
||||
},
|
||||
|
|
|
@ -32,7 +32,9 @@ export const dropdownControl = () => ({
|
|||
},
|
||||
],
|
||||
resolve({ context }) {
|
||||
if (getState(context) !== 'ready') return { columns: [] };
|
||||
if (getState(context) !== 'ready') {
|
||||
return { columns: [] };
|
||||
}
|
||||
return { columns: get(getValue(context), 'columns', []) };
|
||||
},
|
||||
});
|
||||
|
|
|
@ -81,7 +81,9 @@ export const pie = () => ({
|
|||
},
|
||||
],
|
||||
resolve({ context }) {
|
||||
if (getState(context) !== 'ready') return { labels: [] };
|
||||
if (getState(context) !== 'ready') {
|
||||
return { labels: [] };
|
||||
}
|
||||
return { labels: uniq(map(getValue(context).rows, 'color').filter(v => v !== undefined)) };
|
||||
},
|
||||
});
|
||||
|
|
|
@ -67,7 +67,9 @@ export const plot = () => ({
|
|||
},
|
||||
],
|
||||
resolve({ context }) {
|
||||
if (getState(context) !== 'ready') return { labels: [] };
|
||||
if (getState(context) !== 'ready') {
|
||||
return { labels: [] };
|
||||
}
|
||||
return { labels: uniq(map(getValue(context).rows, 'color').filter(v => v !== undefined)) };
|
||||
},
|
||||
});
|
||||
|
|
|
@ -23,7 +23,9 @@ export const timefilterControl = () => ({
|
|||
},
|
||||
],
|
||||
resolve({ context }) {
|
||||
if (getState(context) !== 'ready') return { columns: [] };
|
||||
if (getState(context) !== 'ready') {
|
||||
return { columns: [] };
|
||||
}
|
||||
return { columns: get(getValue(context), 'columns', []) };
|
||||
},
|
||||
});
|
||||
|
|
|
@ -20,7 +20,9 @@ export const to = () => ({
|
|||
},
|
||||
},
|
||||
fn: (context, args, { types }) => {
|
||||
if (!args.type) throw new Error('Must specify a casting type');
|
||||
if (!args.type) {
|
||||
throw new Error('Must specify a casting type');
|
||||
}
|
||||
|
||||
return castProvider(types)(context, args.type);
|
||||
},
|
||||
|
|
|
@ -46,11 +46,17 @@ export function getAutocompleteSuggestions(specs, expression, position) {
|
|||
const { ast: newAst, fnIndex, argName, argIndex } = getFnArgAtPosition(ast, position);
|
||||
const fn = newAst.node.chain[fnIndex].node;
|
||||
|
||||
if (fn.function.includes(MARKER)) return getFnNameSuggestions(specs, newAst, fnIndex);
|
||||
if (fn.function.includes(MARKER)) {
|
||||
return getFnNameSuggestions(specs, newAst, fnIndex);
|
||||
}
|
||||
|
||||
if (argName === '_') return getArgNameSuggestions(specs, newAst, fnIndex, argName, argIndex);
|
||||
if (argName === '_') {
|
||||
return getArgNameSuggestions(specs, newAst, fnIndex, argName, argIndex);
|
||||
}
|
||||
|
||||
if (argName) return getArgValueSuggestions(specs, newAst, fnIndex, argName, argIndex);
|
||||
if (argName) {
|
||||
return getArgValueSuggestions(specs, newAst, fnIndex, argName, argIndex);
|
||||
}
|
||||
} catch (e) {
|
||||
// Fail silently
|
||||
}
|
||||
|
@ -67,8 +73,9 @@ function getFnArgAtPosition(ast, position) {
|
|||
for (let argIndex = 0; argIndex < argValues.length; argIndex++) {
|
||||
const value = argValues[argIndex];
|
||||
if (value.start <= position && position <= value.end) {
|
||||
if (value.node !== null && value.node.type === 'expression')
|
||||
if (value.node !== null && value.node.type === 'expression') {
|
||||
return getFnArgAtPosition(value, position);
|
||||
}
|
||||
return { ast, fnIndex, argName, argIndex };
|
||||
}
|
||||
}
|
||||
|
@ -103,7 +110,9 @@ function getArgNameSuggestions(specs, ast, fnIndex, argName, argIndex) {
|
|||
// Get the list of args from the function definition
|
||||
const fn = ast.node.chain[fnIndex].node;
|
||||
const fnDef = getByAlias(specs, fn.function);
|
||||
if (!fnDef) return [];
|
||||
if (!fnDef) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// We use the exact text instead of the value because it is always a string and might be quoted
|
||||
const { text, start, end } = fn.arguments[argName][argIndex];
|
||||
|
@ -117,7 +126,9 @@ function getArgNameSuggestions(specs, ast, fnIndex, argName, argIndex) {
|
|||
return [name, values.filter(value => !value.text.includes(MARKER))];
|
||||
});
|
||||
const unusedArgDefs = matchingArgDefs.filter(argDef => {
|
||||
if (argDef.multi) return true;
|
||||
if (argDef.multi) {
|
||||
return true;
|
||||
}
|
||||
return !argEntries.some(([name, values]) => {
|
||||
return values.length && (name === argDef.name || argDef.aliases.includes(name));
|
||||
});
|
||||
|
@ -141,9 +152,13 @@ function getArgValueSuggestions(specs, ast, fnIndex, argName, argIndex) {
|
|||
// Get the list of values from the argument definition
|
||||
const fn = ast.node.chain[fnIndex].node;
|
||||
const fnDef = getByAlias(specs, fn.function);
|
||||
if (!fnDef) return [];
|
||||
if (!fnDef) {
|
||||
return [];
|
||||
}
|
||||
const argDef = getByAlias(fnDef.args, argName);
|
||||
if (!argDef) return [];
|
||||
if (!argDef) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Get suggestions from the argument definition, including the default
|
||||
const { start, end, node } = fn.arguments[argName][argIndex];
|
||||
|
@ -169,7 +184,9 @@ function textMatches(text, query) {
|
|||
|
||||
function maybeQuote(value) {
|
||||
if (typeof value === 'string') {
|
||||
if (value.match(/^\{.*\}$/)) return value;
|
||||
if (value.match(/^\{.*\}$/)) {
|
||||
return value;
|
||||
}
|
||||
return `"${value.replace(/"/g, '\\"')}"`;
|
||||
}
|
||||
return value;
|
||||
|
@ -186,8 +203,12 @@ function unnamedArgComparator(a, b) {
|
|||
}
|
||||
|
||||
function alphanumericalComparator(a, b) {
|
||||
if (a < b) return -1;
|
||||
if (a > b) return 1;
|
||||
if (a < b) {
|
||||
return -1;
|
||||
}
|
||||
if (a > b) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -198,7 +219,9 @@ function startsWithComparator(query) {
|
|||
function combinedComparator(...comparators) {
|
||||
return (a, b) =>
|
||||
comparators.reduce((acc, comparator) => {
|
||||
if (acc !== 0) return acc;
|
||||
if (acc !== 0) {
|
||||
return acc;
|
||||
}
|
||||
return comparator(a, b);
|
||||
}, 0);
|
||||
}
|
||||
|
|
|
@ -12,17 +12,23 @@ const dataurlRegex = /^data:([a-z]+\/[a-z0-9-+.]+)(;[a-z-]+=[a-z0-9-]+)?(;([a-z0
|
|||
export const imageTypes = ['image/svg+xml', 'image/jpeg', 'image/png', 'image/gif'];
|
||||
|
||||
export function parseDataUrl(str, withData = false) {
|
||||
if (typeof str !== 'string') return;
|
||||
if (typeof str !== 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
const matches = str.match(dataurlRegex);
|
||||
|
||||
if (!matches) return;
|
||||
if (!matches) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [, mimetype, charset, , encoding] = matches;
|
||||
|
||||
// all types except for svg need to be base64 encoded
|
||||
const imageTypeIndex = imageTypes.indexOf(matches[1]);
|
||||
if (imageTypeIndex > 0 && encoding !== 'base64') return;
|
||||
if (imageTypeIndex > 0 && encoding !== 'base64') {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
mimetype,
|
||||
|
|
|
@ -8,8 +8,12 @@ import { each } from 'lodash';
|
|||
|
||||
export function findInObject(o, fn, memo, name) {
|
||||
memo = memo || [];
|
||||
if (fn(o, name)) memo.push(o);
|
||||
if (o != null && typeof o === 'object') each(o, (val, name) => findInObject(val, fn, memo, name));
|
||||
if (fn(o, name)) {
|
||||
memo.push(o);
|
||||
}
|
||||
if (o != null && typeof o === 'object') {
|
||||
each(o, (val, name) => findInObject(val, fn, memo, name));
|
||||
}
|
||||
|
||||
return memo;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
import { unquoteString } from './unquote_string';
|
||||
|
||||
export function getFieldType(columns, field) {
|
||||
if (!field) return 'null';
|
||||
if (!field) {
|
||||
return 'null';
|
||||
}
|
||||
const realField = unquoteString(field);
|
||||
const column = columns.find(column => column.name === realField);
|
||||
return column ? column.type : 'null';
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
*/
|
||||
|
||||
export const getLegendConfig = (legend, size) => {
|
||||
if (!legend || size < 2) return { show: false };
|
||||
if (!legend || size < 2) {
|
||||
return { show: false };
|
||||
}
|
||||
|
||||
const config = {
|
||||
show: true,
|
||||
|
|
|
@ -10,7 +10,9 @@ import { pivotObjectArray } from './pivot_object_array';
|
|||
|
||||
// example use: {{math rows 'mean(price - cost)' 2}}
|
||||
Hbars.registerHelper('math', (rows, expression, precision) => {
|
||||
if (!Array.isArray(rows)) return 'MATH ERROR: first argument must be an array';
|
||||
if (!Array.isArray(rows)) {
|
||||
return 'MATH ERROR: first argument must be an array';
|
||||
}
|
||||
const value = evaluate(expression, pivotObjectArray(rows));
|
||||
try {
|
||||
return precision ? value.toFixed(precision) : value;
|
||||
|
|
|
@ -9,10 +9,14 @@ export const hexToRgb = hex => {
|
|||
const hexColor = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
|
||||
|
||||
const shorthandMatches = shorthandHexColor.exec(hex);
|
||||
if (shorthandMatches) return shorthandMatches.slice(1, 4).map(hex => parseInt(hex + hex, 16));
|
||||
if (shorthandMatches) {
|
||||
return shorthandMatches.slice(1, 4).map(hex => parseInt(hex + hex, 16));
|
||||
}
|
||||
|
||||
const hexMatches = hexColor.exec(hex);
|
||||
if (hexMatches) return hexMatches.slice(1, 4).map(hex => parseInt(hex, 16));
|
||||
if (hexMatches) {
|
||||
return hexMatches.slice(1, 4).map(hex => parseInt(hex, 16));
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
|
|
@ -10,7 +10,9 @@ const isString = val => typeof val === 'string';
|
|||
|
||||
export function pivotObjectArray(rows, columns) {
|
||||
const columnNames = columns || Object.keys(rows[0]);
|
||||
if (!columnNames.every(isString)) throw new Error('Columns should be an array of strings');
|
||||
if (!columnNames.every(isString)) {
|
||||
throw new Error('Columns should be an array of strings');
|
||||
}
|
||||
|
||||
const columnValues = map(columnNames, name => map(rows, name));
|
||||
return zipObject(columnNames, columnValues);
|
||||
|
|
|
@ -19,7 +19,11 @@ export const resolveFromArgs = (args, defaultDataurl = null) => {
|
|||
};
|
||||
|
||||
export const resolveWithMissingImage = (img, alt = null) => {
|
||||
if (isValidUrl(img)) return img;
|
||||
if (img === null) return alt;
|
||||
if (isValidUrl(img)) {
|
||||
return img;
|
||||
}
|
||||
if (img === null) {
|
||||
return alt;
|
||||
}
|
||||
return missingImage;
|
||||
};
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
*/
|
||||
|
||||
export const unquoteString = str => {
|
||||
if (/^"/.test(str)) return str.replace(/^"(.+(?="$))"$/, '$1');
|
||||
if (/^'/.test(str)) return str.replace(/^'(.+(?='$))'$/, '$1');
|
||||
if (/^"/.test(str)) {
|
||||
return str.replace(/^"(.+(?="$))"$/, '$1');
|
||||
}
|
||||
if (/^'/.test(str)) {
|
||||
return str.replace(/^'(.+(?='$))'$/, '$1');
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
|
|
@ -17,7 +17,9 @@ export default async function(server /*options*/) {
|
|||
const basePath = config.get('server.basePath');
|
||||
const reportingBrowserType = (() => {
|
||||
const configKey = 'xpack.reporting.capture.browser.type';
|
||||
if (!config.has(configKey)) return null;
|
||||
if (!config.has(configKey)) {
|
||||
return null;
|
||||
}
|
||||
return config.get(configKey);
|
||||
})();
|
||||
const kibanaVars = await server.getInjectedUiAppVars('kibana');
|
||||
|
|
|
@ -24,7 +24,9 @@ export const routes = [
|
|||
const pageNumber = parseInt(params.page, 10);
|
||||
|
||||
// redirect to home app on invalid workpad id or page number
|
||||
if (fetchedWorkpad == null && isNaN(pageNumber)) return router.redirectTo('home');
|
||||
if (fetchedWorkpad == null && isNaN(pageNumber)) {
|
||||
return router.redirectTo('home');
|
||||
}
|
||||
|
||||
const { assets, ...workpad } = fetchedWorkpad;
|
||||
dispatch(setAssets(assets));
|
||||
|
|
|
@ -33,7 +33,9 @@ export const routes = [
|
|||
notify.error(err, { title: `Couldn't create workpad` });
|
||||
// TODO: remove this and switch to checking user privileges when canvas loads when granular app privileges are introduced
|
||||
// https://github.com/elastic/kibana/issues/20277
|
||||
if (err.response.status === 403) dispatch(setCanUserWrite(false));
|
||||
if (err.response.status === 403) {
|
||||
dispatch(setCanUserWrite(false));
|
||||
}
|
||||
router.redirectTo('home');
|
||||
}
|
||||
},
|
||||
|
@ -59,7 +61,9 @@ export const routes = [
|
|||
// TODO: remove this and switch to checking user privileges when canvas loads when granular app privileges are introduced
|
||||
// https://github.com/elastic/kibana/issues/20277
|
||||
workpadService.update(params.id, fetchedWorkpad).catch(err => {
|
||||
if (err.response.status === 403) dispatch(setCanUserWrite(false));
|
||||
if (err.response.status === 403) {
|
||||
dispatch(setCanUserWrite(false));
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
notify.error(err, { title: `Couldn't load workpad with ID` });
|
||||
|
@ -72,12 +76,15 @@ export const routes = [
|
|||
const pageNumber = parseInt(params.page, 10);
|
||||
|
||||
// no page provided, append current page to url
|
||||
if (isNaN(pageNumber))
|
||||
if (isNaN(pageNumber)) {
|
||||
return router.redirectTo('loadWorkpad', { id: workpad.id, page: workpad.page + 1 });
|
||||
}
|
||||
|
||||
// set the active page using the number provided in the url
|
||||
const pageIndex = pageNumber - 1;
|
||||
if (pageIndex !== workpad.page) dispatch(gotoPage(pageIndex));
|
||||
if (pageIndex !== workpad.page) {
|
||||
dispatch(gotoPage(pageIndex));
|
||||
}
|
||||
|
||||
// update the application's breadcrumb
|
||||
setBreadcrumb([getBaseBreadcrumb(), getWorkpadBreadcrumb(workpad)]);
|
||||
|
|
|
@ -49,7 +49,9 @@ export class App extends React.PureComponent {
|
|||
};
|
||||
|
||||
render() {
|
||||
if (this.props.appState instanceof Error) return this.renderError();
|
||||
if (this.props.appState instanceof Error) {
|
||||
return this.renderError();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="canvas canvasContainer">
|
||||
|
|
|
@ -27,7 +27,9 @@ export const AdvancedFailureComponent = props => {
|
|||
|
||||
resetErrorState(); // when setting a new value, attempt to reset the error state
|
||||
|
||||
if (valid) return onValueChange(fromExpression(argExpression.trim(), 'argument'));
|
||||
if (valid) {
|
||||
return onValueChange(fromExpression(argExpression.trim(), 'argument'));
|
||||
}
|
||||
};
|
||||
|
||||
const confirmReset = ev => {
|
||||
|
|
|
@ -21,7 +21,9 @@ const branches = [
|
|||
const { argType } = argTypeInstance;
|
||||
|
||||
// arg does not need to be resolved, no need to branch
|
||||
if (!argType.resolveArgValue) return false;
|
||||
if (!argType.resolveArgValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// arg needs to be resolved, render pending if the value is not defined
|
||||
return typeof resolvedArgValue === 'undefined';
|
||||
|
|
|
@ -32,10 +32,14 @@ class ArgTemplateFormComponent extends React.Component {
|
|||
|
||||
componentWillUpdate(prevProps) {
|
||||
//see if error state changed
|
||||
if (this.props.error !== prevProps.error) this.props.handlers.destroy();
|
||||
if (this.props.error !== prevProps.error) {
|
||||
this.props.handlers.destroy();
|
||||
}
|
||||
}
|
||||
componentDidUpdate() {
|
||||
if (this.props.error) return this.renderErrorTemplate();
|
||||
if (this.props.error) {
|
||||
return this.renderErrorTemplate();
|
||||
}
|
||||
this.renderTemplate(this.domNode);
|
||||
}
|
||||
|
||||
|
@ -45,7 +49,9 @@ class ArgTemplateFormComponent extends React.Component {
|
|||
|
||||
renderTemplate = domNode => {
|
||||
const { template, argumentProps, handlers } = this.props;
|
||||
if (template) return template(domNode, argumentProps, handlers);
|
||||
if (template) {
|
||||
return template(domNode, argumentProps, handlers);
|
||||
}
|
||||
};
|
||||
|
||||
renderErrorTemplate = () => {
|
||||
|
@ -56,9 +62,13 @@ class ArgTemplateFormComponent extends React.Component {
|
|||
render() {
|
||||
const { template, error } = this.props;
|
||||
|
||||
if (error) return this.renderErrorTemplate();
|
||||
if (error) {
|
||||
return this.renderErrorTemplate();
|
||||
}
|
||||
|
||||
if (!template) return null;
|
||||
if (!template) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<RenderToDom
|
||||
|
|
|
@ -17,7 +17,9 @@ export class AssetPicker extends PureComponent {
|
|||
|
||||
componentDidMount() {
|
||||
const selectedAsset = document.getElementById('canvasAssetPicker__selectedAsset');
|
||||
if (selectedAsset) selectedAsset.scrollIntoView();
|
||||
if (selectedAsset) {
|
||||
selectedAsset.scrollIntoView();
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -56,10 +56,13 @@ export class Autocomplete extends React.Component {
|
|||
prevProps.items !== this.props.items &&
|
||||
this.props.items.length === 1 &&
|
||||
this.state.selectedIndex !== 0
|
||||
)
|
||||
) {
|
||||
this.selectFirst();
|
||||
}
|
||||
|
||||
if (prevState.selectedIndex !== this.state.selectedIndex) this.scrollIntoView();
|
||||
if (prevState.selectedIndex !== this.state.selectedIndex) {
|
||||
this.scrollIntoView();
|
||||
}
|
||||
}
|
||||
|
||||
selectFirst() {
|
||||
|
@ -86,16 +89,21 @@ export class Autocomplete extends React.Component {
|
|||
selectPrevious() {
|
||||
const { items } = this.props;
|
||||
const { selectedIndex } = this.state;
|
||||
if (selectedIndex > 0) this.setState({ selectedIndex: selectedIndex - 1 });
|
||||
else this.setState({ selectedIndex: items.length - 1 });
|
||||
if (selectedIndex > 0) {
|
||||
this.setState({ selectedIndex: selectedIndex - 1 });
|
||||
} else {
|
||||
this.setState({ selectedIndex: items.length - 1 });
|
||||
}
|
||||
}
|
||||
|
||||
selectNext() {
|
||||
const { items } = this.props;
|
||||
const { selectedIndex } = this.state;
|
||||
if (selectedIndex >= 0 && selectedIndex < items.length - 1)
|
||||
if (selectedIndex >= 0 && selectedIndex < items.length - 1) {
|
||||
this.setState({ selectedIndex: selectedIndex + 1 });
|
||||
else this.setState({ selectedIndex: 0 });
|
||||
} else {
|
||||
this.setState({ selectedIndex: 0 });
|
||||
}
|
||||
}
|
||||
|
||||
scrollIntoView() {
|
||||
|
@ -105,7 +113,9 @@ export class Autocomplete extends React.Component {
|
|||
state: { selectedIndex },
|
||||
} = this;
|
||||
const itemRef = itemRefs[selectedIndex];
|
||||
if (!containerRef || !itemRef) return;
|
||||
if (!containerRef || !itemRef) {
|
||||
return;
|
||||
}
|
||||
containerRef.scrollTop = Math.max(
|
||||
Math.min(containerRef.scrollTop, itemRef.offsetTop),
|
||||
itemRef.offsetTop + itemRef.offsetHeight - containerRef.offsetHeight
|
||||
|
@ -129,7 +139,9 @@ export class Autocomplete extends React.Component {
|
|||
const { items } = this.props;
|
||||
const { isOpen, selectedIndex } = this.state;
|
||||
|
||||
if ([ESCAPE, LEFT, RIGHT].includes(keyCode)) this.setState({ isOpen: false });
|
||||
if ([ESCAPE, LEFT, RIGHT].includes(keyCode)) {
|
||||
this.setState({ isOpen: false });
|
||||
}
|
||||
|
||||
if ([TAB, ENTER].includes(keyCode) && isOpen && selectedIndex >= 0) {
|
||||
e.preventDefault();
|
||||
|
|
|
@ -21,7 +21,9 @@ export class Clipboard extends React.PureComponent {
|
|||
|
||||
const result = copy(content, { debug: true });
|
||||
|
||||
if (typeof onCopy === 'function') onCopy(result);
|
||||
if (typeof onCopy === 'function') {
|
||||
onCopy(result);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
|
|
|
@ -31,7 +31,9 @@ export const ConfirmModal = props => {
|
|||
};
|
||||
|
||||
// render nothing if this component isn't open
|
||||
if (!isOpen) return null;
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<EuiOverlayMask>
|
||||
|
|
|
@ -43,9 +43,13 @@ export class DatasourceComponent extends PureComponent {
|
|||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { args, resetArgs, datasource, selectDatasource } = this.props;
|
||||
if (!isEqual(prevProps.args, args)) resetArgs();
|
||||
if (!isEqual(prevProps.args, args)) {
|
||||
resetArgs();
|
||||
}
|
||||
|
||||
if (!isEqual(prevProps.datasource, datasource)) selectDatasource(datasource);
|
||||
if (!isEqual(prevProps.datasource, datasource)) {
|
||||
selectDatasource(datasource);
|
||||
}
|
||||
}
|
||||
|
||||
getDatasourceFunctionNode = (name, args) => ({
|
||||
|
@ -96,8 +100,9 @@ export class DatasourceComponent extends PureComponent {
|
|||
setInvalid,
|
||||
} = this.props;
|
||||
|
||||
if (selecting)
|
||||
if (selecting) {
|
||||
return <DatasourceSelector datasources={datasources} onSelect={this.setSelectedDatasource} />;
|
||||
}
|
||||
|
||||
const datasourcePreview = previewing ? (
|
||||
<DatasourcePreview
|
||||
|
|
|
@ -39,12 +39,16 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
|
|||
const datasourceAst = get(element, 'ast.chain', [])
|
||||
.map((astDef, i) => {
|
||||
// if it's not a function, it's can't be a datasource
|
||||
if (astDef.type !== 'function') return;
|
||||
if (astDef.type !== 'function') {
|
||||
return;
|
||||
}
|
||||
const args = astDef.arguments;
|
||||
|
||||
// if there's no matching datasource in the registry, we're done
|
||||
const datasource = datasourceRegistry.get(astDef.function);
|
||||
if (!datasource) return;
|
||||
if (!datasource) {
|
||||
return;
|
||||
}
|
||||
|
||||
const datasourceDef = getDataTableFunctionsByName(datasource.name);
|
||||
|
||||
|
|
|
@ -11,7 +11,9 @@ import moment from 'moment';
|
|||
import { Paginate } from '../paginate';
|
||||
|
||||
const getIcon = type => {
|
||||
if (type === null) return;
|
||||
if (type === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let icon;
|
||||
switch (type) {
|
||||
|
@ -39,7 +41,9 @@ const getColumnName = col => (typeof col === 'string' ? col : col.name);
|
|||
const getColumnType = col => col.type || null;
|
||||
|
||||
const getFormattedValue = (val, type) => {
|
||||
if (type === 'date') return moment(val).format();
|
||||
if (type === 'date') {
|
||||
return moment(val).format();
|
||||
}
|
||||
return String(val);
|
||||
};
|
||||
|
||||
|
|
|
@ -38,7 +38,9 @@ export class DomPreview extends React.Component {
|
|||
}
|
||||
|
||||
update = original => () => {
|
||||
if (!this.content || !this.container) return;
|
||||
if (!this.content || !this.container) {
|
||||
return;
|
||||
}
|
||||
|
||||
const thumb = original.cloneNode(true);
|
||||
|
||||
|
@ -50,7 +52,9 @@ export class DomPreview extends React.Component {
|
|||
const scale = thumbHeight / originalHeight;
|
||||
const thumbWidth = originalWidth * scale;
|
||||
|
||||
if (this.content.hasChildNodes()) this.content.removeChild(this.content.firstChild);
|
||||
if (this.content.hasChildNodes()) {
|
||||
this.content.removeChild(this.content.firstChild);
|
||||
}
|
||||
this.content.appendChild(thumb);
|
||||
|
||||
this.content.style.cssText = `transform: scale(${scale}); transform-origin: top left;`;
|
||||
|
|
|
@ -37,7 +37,9 @@ export class ElementShareContainer extends React.PureComponent {
|
|||
// dispatches a custom DOM event on the container when the element is complete
|
||||
onComplete(() => {
|
||||
clearTimeout(this.timeout);
|
||||
if (!this.sharedItemRef) return; // without this, crazy fast forward/backward paging leads to an error
|
||||
if (!this.sharedItemRef) {
|
||||
return;
|
||||
} // without this, crazy fast forward/backward paging leads to an error
|
||||
const ev = new CustomEvent('renderComplete');
|
||||
this.sharedItemRef.dispatchEvent(ev);
|
||||
|
||||
|
|
|
@ -39,10 +39,18 @@ export const ElementTypes = ({ elements, onClick, search, setSearch }) => {
|
|||
</EuiFlexItem>
|
||||
);
|
||||
|
||||
if (!search) return card;
|
||||
if (includes(lowerCase(name), search)) return card;
|
||||
if (includes(lowerCase(displayName), search)) return card;
|
||||
if (includes(lowerCase(help), search)) return card;
|
||||
if (!search) {
|
||||
return card;
|
||||
}
|
||||
if (includes(lowerCase(name), search)) {
|
||||
return card;
|
||||
}
|
||||
if (includes(lowerCase(displayName), search)) {
|
||||
return card;
|
||||
}
|
||||
if (includes(lowerCase(help), search)) {
|
||||
return card;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
|
|
|
@ -32,7 +32,9 @@ export class ElementWrapper extends React.PureComponent {
|
|||
|
||||
render() {
|
||||
// wait until the handlers have been created
|
||||
if (!this.state.handlers) return null;
|
||||
if (!this.state.handlers) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { renderable, transformMatrix, width, height, state } = this.props;
|
||||
|
||||
|
|
|
@ -24,7 +24,9 @@ export function createHandlers(element, pageId, dispatch) {
|
|||
},
|
||||
|
||||
done() {
|
||||
if (isComplete) return; // don't emit if the element is already done
|
||||
if (isComplete) {
|
||||
return;
|
||||
} // don't emit if the element is already done
|
||||
isComplete = true;
|
||||
completeFn();
|
||||
},
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue