Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time Series Visual Builder: Modify Behavior for Aggregation Selection #10890

Merged
merged 13 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 10 additions & 4 deletions src/core_plugins/metrics/common/agg_lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,21 @@ export function isBasicAgg(item) {
return _.includes(Object.keys(byType.basic), item.type);
}

export function createOptions(type = '_all') {
export function createOptions(type = '_all', siblings = []) {
let aggs = byType[type];
if (!aggs) aggs = byType._all;
let enablePipelines = siblings.some(isBasicAgg);
if (siblings.length <= 1) enablePipelines = false;
return _(aggs)
.map((label, value) => {
const disabled = false;
return { label, value, disabled };
const disabled = _.includes(pipeline, value) ? !enablePipelines : false;
return {
label: disabled ? `${label} (use the "+" button to add this pipeline agg)` : label,
value,
disabled
};
})
.sortBy('label')
.value();
}

export default lookup;
15 changes: 12 additions & 3 deletions src/core_plugins/metrics/public/components/add_delete_buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function AddDeleteButtons(props) {
return null;
}
return (
<Tooltip text="Delete">
<Tooltip text={props.deleteTooltip}>
<a className="thor__button-outlined-danger sm" onClick={ props.onDelete }>
<i className="fa fa-trash-o"></i>
</a>
Expand All @@ -19,7 +19,7 @@ function AddDeleteButtons(props) {
return null;
}
return (
<Tooltip text="Add">
<Tooltip text={props.addTooltip}>
<a className="thor__button-outlined-default sm" onClick={ props.onAdd }>
<i className="fa fa-plus"></i>
</a>
Expand All @@ -31,7 +31,7 @@ function AddDeleteButtons(props) {
let clone;
if (props.onClone && !props.disableAdd) {
clone = (
<Tooltip text="Clone">
<Tooltip text={props.cloneTooltip}>
<a className="thor__button-outlined-default sm" onClick={ props.onClone }>
<i className="fa fa-files-o"></i>
</a>
Expand All @@ -47,7 +47,16 @@ function AddDeleteButtons(props) {
);
}

AddDeleteButtons.defaultProps = {
addTooltip: 'Add',
deleteTooltip: 'Delete',
cloneTooltip: 'Clone'
};

AddDeleteButtons.propTypes = {
addTooltip: PropTypes.string,
deleteTooltip: PropTypes.string,
cloneTooltip: PropTypes.string,
disableAdd: PropTypes.bool,
disableDelete: PropTypes.bool,
onClone: PropTypes.func,
Expand Down
2 changes: 2 additions & 0 deletions src/core_plugins/metrics/public/components/aggs/agg_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function AggRow(props) {
{props.children}
{ dragHandle }
<AddDeleteButtons
addTooltip="Add Metric"
deleteTooltip="Delete Metric"
onAdd={props.onAdd}
onDelete={props.onDelete}
disableDelete={props.disableDelete}/>
Expand Down
140 changes: 135 additions & 5 deletions src/core_plugins/metrics/public/components/aggs/agg_select.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,147 @@
import React, { PropTypes } from 'react';
import React, { PropTypes, Component } from 'react';
import Select from 'react-select';
import { createOptions } from '../../../common/agg_lookup';

const metricAggs = [
{ label: 'Average', value: 'avg' },
{ label: 'Cardinality', value: 'cardinality' },
{ label: 'Count', value: 'count' },
{ label: 'Filter Ratio', value: 'filter_ratio' },
{ label: 'Max', value: 'max' },
{ label: 'Min', value: 'min' },
{ label: 'Percentile', value: 'percentile' },
{ label: 'Percentile Rank', value: 'percentile_rank' },
{ label: 'Std. Deviation', value: 'std_deviation' },
{ label: 'Sum', value: 'sum' },
{ label: 'Sum of Squares', value: 'sum_of_squares' },
{ label: 'Value Count', value: 'value_count' },
{ label: 'Variance', value: 'variance' }
];

const pipelineAggs = [
{ label: 'Calculation', value: 'calculation' },
{ label: 'Cumulative Sum', value: 'cumulative_sum' },
{ label: 'Derivative', value: 'derivative' },
{ label: 'Moving Average', value: 'moving_average' },
{ label: 'Serial Difference', value: 'serial_diff' },
{ label: 'Series Agg', value: 'series_agg' }
];

const siblingAggs = [
{ label: 'Overall Average', value: 'avg_bucket' },
{ label: 'Overall Max', value: 'max_bucket' },
{ label: 'Overall Min', value: 'min_bucket' },
{ label: 'Overall Std. Deviation', value: 'std_deviation_bucket' },
{ label: 'Overall Sum', value: 'sum_bucket' },
{ label: 'Overall Sum of Squares', value: 'sum_of_squares_bucket' },
{ label: 'Overall Variance', value: 'variance_bucket' }
];

class AggSelectOption extends Component {

constructor(props) {
super(props);
this.handleMouseMove = this.handleMouseMove.bind(this);
this.handleMouseEnter = this.handleMouseEnter.bind(this);
this.handleMouseDown = this.handleMouseDown.bind(this);
}

handleMouseDown(event) {
event.preventDefault();
event.stopPropagation();
this.props.onSelect(this.props.option, event);
}

handleMouseEnter(event) {
this.props.onFocus(this.props.option, event);
}

handleMouseMove(event) {
if (this.props.isFocused) return;
this.props.onFocus(this.props.option, event);
}

render() {
const { label, heading, pipeline } = this.props.option;
const style = {
paddingLeft: heading ? 0 : 10
};
if (heading) {
let note;
if (pipeline) {
note = (<span className="vis_editor__agg_select-note">(requires child aggregation)</span>);
}
return (
<div className="Select-option vis_editor__agg_select-heading"
onMouseEnter={this.handleMouseEnter}
onMouseDown={this.handleMouseDown}
onMouseMove={this.handleMouseMove}
title={label}>
<span className="Select-value-label" style={style}>
<strong>{label}</strong>
{note}
</span>
</div>
);
}
return (
<div className={this.props.className}
onMouseEnter={this.handleMouseEnter}
onMouseDown={this.handleMouseDown}
onMouseMove={this.handleMouseMove}
title={label}>
<span className="Select-value-label" style={style}>
{ this.props.children }
</span>
</div>
);
}

}

AggSelectOption.props = {
children: PropTypes.node,
className: PropTypes.string,
isDisabled: PropTypes.bool,
isFocused: PropTypes.bool,
isSelected: PropTypes.bool,
onFocus: PropTypes.func,
onSelect: PropTypes.func,
option: PropTypes.object.isRequired,
};

function AggSelect(props) {
const { siblings, panelType } = props;
const options = createOptions(panelType, siblings);

let enablePipelines = siblings.some(s => !!metricAggs.find(m => m.value === s.type));
if (siblings.length <= 1) enablePipelines = false;

let options;
if (panelType === 'metrics') {
options = metricAggs;
} else {
options = [
{ label: 'Metric Aggregations', value: null, heading: true, disabled: true },
...metricAggs,
{ label: 'Parent Pipeline Aggregations', value: null, pipeline: true, heading: true, disabled: true },
...pipelineAggs.map(agg => ({ ...agg, disabled: !enablePipelines })),
{ label: 'Sibling Pipeline Aggregations', value: null, pipeline: true, heading: true, disabled: true },
...siblingAggs.map(agg => ({ ...agg, disabled: !enablePipelines }))
];
}

const handleChange = (value) => {
if (value.disabled) return;
if (value.value) props.onChange(value);
};

return (
<div className="vis_editor__row_item">
<Select
clearable={false}
options={options}
value={props.value || 'count'}
onChange={props.onChange}/>
value={props.value}
optionComponent={AggSelectOption}
onChange={handleChange}/>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CalculationAgg extends Component {
}

render() {
const { panel, siblings } = this.props;
const { siblings } = this.props;

const defaults = { script: '' };
const model = { ...defaults, ...this.props.model };
Expand All @@ -41,7 +41,6 @@ class CalculationAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={this.props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
<div className="vis_editor__variables">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import createChangeHandler from '../lib/create_change_handler';
import createSelectHandler from '../lib/create_select_handler';

function CumlativeSumAgg(props) {
const { model, panel, siblings } = props;
const { model, siblings } = props;
const handleChange = createChangeHandler(props.onChange, model);
const handleSelectChange = createSelectHandler(handleChange);
return (
Expand All @@ -20,7 +20,6 @@ function CumlativeSumAgg(props) {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import createTextHandler from '../lib/create_text_handler';
class DerivativeAgg extends Component {

render() {
const { siblings, panel } = this.props;
const { siblings } = this.props;

const defaults = { unit: '' };
const model = { ...defaults, ...this.props.model };
Expand All @@ -29,7 +29,6 @@ class DerivativeAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={this.props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class FilterRatioAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={this.props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import createNumberHandler from '../lib/create_number_handler';

class MovingAverageAgg extends Component {
render() {
const { panel, siblings } = this.props;
const { siblings } = this.props;
const defaults = {
settings: '',
minimize: 0,
Expand Down Expand Up @@ -46,7 +46,6 @@ class MovingAverageAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={this.props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class PercentileAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={this.props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class PercentileRankAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={this.props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import createNumberHandler from '../lib/create_number_handler';
class SerialDiffAgg extends Component {

render() {
const { siblings, panel } = this.props;
const { siblings } = this.props;
const defaults = { lag: '' };
const model = { ...defaults, ...this.props.model };

Expand All @@ -28,7 +28,6 @@ class SerialDiffAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={this.props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import createChangeHandler from '../lib/create_change_handler';
import createSelectHandler from '../lib/create_select_handler';

function SeriesAgg(props) {
const {
model,
panel
} = props;
const { model } = props;

const handleChange = createChangeHandler(props.onChange, model);
const handleSelectChange = createSelectHandler(handleChange);
Expand Down Expand Up @@ -37,7 +34,6 @@ function SeriesAgg(props) {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/core_plugins/metrics/public/components/aggs/std_agg.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function StandardAgg(props) {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class StandardDeviationAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={this.props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import createTextHandler from '../lib/create_text_handler';
class StandardSiblingAgg extends Component {

render() {
const { siblings, panel } = this.props;
const { siblings } = this.props;
const defaults = { sigma: '' };
const model = { ...defaults, ...this.props.model };

Expand Down Expand Up @@ -59,7 +59,6 @@ class StandardSiblingAgg extends Component {
<div className="vis_editor__label">Aggregation</div>
<AggSelect
siblings={this.props.siblings}
panelType={panel.type}
value={model.type}
onChange={handleSelectChange('type')}/>
</div>
Expand Down
Loading