Skip to content
Closed
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
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ module.exports = {
'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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export const math = () => ({
'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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export const getFlotAxisConfig = (axis, argValue, { columns, ticks, font } = {})
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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,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.
Expand Down Expand Up @@ -103,9 +104,9 @@ 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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates the styleguide: https://github.com/elastic/kibana/blob/master/style_guides/js_style_guide.md#always-use-braces-for-conditionals-and-loops

I think the requirement of human review for this seems to indicate a problem upstream though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for clarity, I'm totally cool with you merging this ahead of an upstream fix as long as you manually fix these.


return Promise.all(expressionResultPromises).then(combineAcross);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,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);
Expand Down Expand Up @@ -386,8 +387,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();
}
Expand Down Expand Up @@ -435,8 +437,9 @@ 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 (slices[i].percent >= options.series.pie.label.threshold * 100) {
if (!drawLabel(slices[i], currentAngle, i)) return false;
}

currentAngle += slices[i].angle;
}
Expand Down Expand Up @@ -487,8 +490,9 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/canvas/common/lib/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,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 };
}
}
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/canvas/public/apps/workpad/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ 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();
}
Expand Down Expand Up @@ -93,9 +94,9 @@ export class Autocomplete extends React.Component {
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 });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

scrollIntoView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ export class DatasourceComponent extends PureComponent {
setInvalid,
} = this.props;

if (selecting)
if (selecting) {
return <DatasourceSelector datasources={datasources} onSelect={this.setSelectedDatasource} />;
}

const datasourcePreview = previewing ? (
<DatasourcePreview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export const ESFieldsSelect = compose(
withState('fields', 'setFields', []),
lifecycle({
componentDidMount() {
if (this.props.index)
if (this.props.index) {
getFields(this.props.index).then((fields = []) => this.props.setFields(fields));
}
},
componentDidUpdate({ index }) {
const { setFields, onChange, selected } = this.props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export class FullscreenControl extends React.PureComponent {
const { children, isFullscreen } = this.props;

const keyHandler = action => {
if (action === 'FULLSCREEN' || (isFullscreen && action === 'FULLSCREEN_EXIT'))
if (action === 'FULLSCREEN' || (isFullscreen && action === 'FULLSCREEN_EXIT')) {
this.toggleFullscreen();
}
};

return (
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/canvas/public/components/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export class Router extends React.PureComponent {

if (!component) {
// TODO: render some kind of 404 page, maybe from a prop?
if (process.env.NODE_ENV !== 'production')
if (process.env.NODE_ENV !== 'production') {
console.warn(`No component defined on route: ${route.name}`);
}

return;
}
Expand All @@ -73,8 +74,9 @@ export class Router extends React.PureComponent {

render() {
// show loading
if (this.props.showLoading)
if (this.props.showLoading) {
return React.createElement(CanvasLoading, { msg: this.props.loadingMessage });
}

// show the activeComponent
return isClassComponent(this.state.activeComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ export const WorkpadExport = compose(
throw new Error(`Unknown export type: ${type}`);
},
onCopy: type => {
if (type === 'pdf')
if (type === 'pdf') {
return notify.info('The PDF generation URL was copied to your clipboard.');
}

throw new Error(`Unknown export type: ${type}`);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export function getPdfUrl({ id, name: title, width, height }, { pageCount }) {

// build a list of all page urls for exporting, they are captured one at a time
const workpadUrls = [];
for (let i = 1; i <= pageCount; i++)
for (let i = 1; i <= pageCount; i++) {
workpadUrls.push(rison.encode(`${canvasEntry}/export/workpad/pdf/${id}/page/${i}`));
}

const jobParams = {
browserTimezone: 'America/Phoenix', // TODO: get browser timezone, or Kibana setting?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ export const WorkpadPage = compose(
let element = null;
if (elementLookup.has(shape.id)) {
element = elementLookup.get(shape.id);
if (selectedElementIds.indexOf(shape.id) > -1)
if (selectedElementIds.indexOf(shape.id) > -1) {
selectedElements.push({ ...element, id: shape.id });
}
}
// instead of just combining `element` with `shape`, we make property transfer explicit
return element ? { ...shape, filter: element.filter } : shape;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const EnhancedExtendedTemplate = lifecycle({
},
componentWillReceiveProps(newProps) {
const newLabel = get(newProps.argValue, 'chain.0.arguments.label.0', '');
if (newLabel && this.props.label !== this.formatLabel(newLabel))
if (newLabel && this.props.label !== this.formatLabel(newLabel)) {
this.props.setLabel(this.formatLabel(newLabel));
}
},
})(ExtendedTemplate);

Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/canvas/public/expression_types/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export class View extends FunctionForm {

this.modelArgs = this.modelArgs || [];

if (!Array.isArray(this.modelArgs))
if (!Array.isArray(this.modelArgs)) {
throw new Error(`${this.name} element is invalid, modelArgs must be an array`);
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions x-pack/plugins/canvas/public/lib/aeroelastic/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,9 @@ const alignmentGuides = (shapes, guidedShapes, draggedShape) => {
// moved midpoint on vertical border
(extremeVertical === 0 && l !== 0 && extremeHorizontal === k)
)
)
) {
continue;
}
const D = landmarkPoint(d, k, l);
for (let m = -1; m < 2; m++) {
for (let n = -1; n < 2; n++) {
Expand Down Expand Up @@ -906,8 +907,9 @@ function resizeAnnotation(shapes, selectedShapes, shape) {
: [];
return result;
}
if (foundShape.type === 'annotation')
if (foundShape.type === 'annotation') {
return resizeAnnotation(shapes, selectedShapes, shapes.find(s => foundShape.parent === s.id));
}

// fixme left active: snap wobble. right active: opposite side wobble.
const a = snappedA(properShape);
Expand Down Expand Up @@ -1057,8 +1059,9 @@ const snappedShapes = select(
const subtype = draggedShape && draggedShape.subtype;
// snapping doesn't come into play if there's no dragging, or it's not a resize drag or translate drag on a
// leaf element or a group element:
if (subtype && [config.resizeHandleName, config.adHocGroupName].indexOf(subtype) === -1)
if (subtype && [config.resizeHandleName, config.adHocGroupName].indexOf(subtype) === -1) {
return contentShapes;
}
const constraints = alignmentGuideAnnotations; // fixme split concept of snap constraints and their annotations
const relaxed = alterSnapGesture.indexOf('relax') !== -1;
const constrained = config.snapConstraint && !relaxed;
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/canvas/public/lib/aeroelastic/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const selectReduce = (fun, previousValue, mapFun = d => d, logFun) => (...inputs
if (
shallowEqual(argumentValues, (argumentValues = inputs.map(input => input(state)))) &&
value === prevValue
)
) {
return mappedValue;
}

prevValue = value;
value = fun(prevValue, ...argumentValues);
Expand All @@ -45,8 +46,9 @@ const select = (fun, logFun) => (...inputs) => {
if (
actionId === lastActionId ||
shallowEqual(argumentValues, (argumentValues = inputs.map(input => input(state))))
)
) {
return value;
}

value = fun(...argumentValues);
actionId = lastActionId;
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/canvas/public/lib/router_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ export function routerProvider(routes) {
updateLocation(name, params, state, true);
},
onPathChange(fn) {
if (componentListener != null)
if (componentListener != null) {
throw new Error('Only one route component listener is allowed');
}

const execOnMatch = location => {
const { pathname } = location;
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/canvas/public/lib/time_duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export const timeDuration = (time, format) => {

if (format === 'days' || days >= 1) return { length: days, format: getLabel('day', days) };
if (format === 'hours' || hours >= 1) return { length: hours, format: getLabel('hour', hours) };
if (format === 'minutes' || minutes >= 1)
if (format === 'minutes' || minutes >= 1) {
return { length: seconds / 60, format: getLabel('minute', minutes) };
}
return { length: seconds, format: getLabel('second', seconds) };
};

Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/canvas/public/state/middleware/aeroelastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ export const aeroelastic = ({ dispatch, getState }) => {
// set the selected element on the global store, if one element is selected
const selectedShape = nextScene.selectedPrimaryShapes[0];
if (nextScene.selectedShapes.length === 1) {
if (selectedShape && selectedShape !== selectedElement)
if (selectedShape && selectedShape !== selectedElement) {
dispatch(selectElement(selectedShape));
}
} else {
// otherwise, clear the selected element state
dispatch(selectElement(null));
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/canvas/public/state/middleware/breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const breadcrumbs = ({ getState }) => next => action => {
const updatedWorkpad = getWorkpad(getState());

// if the workpad name changed, update the breadcrumb data
if (currentWorkpad.name !== updatedWorkpad.name)
if (currentWorkpad.name !== updatedWorkpad.name) {
setBreadcrumb([getBaseBreadcrumb(), getWorkpadBreadcrumb(updatedWorkpad)]);
}
};
Loading