mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Refactoring series a bit
This commit is contained in:
parent
5d2bf42680
commit
f1ff1988ce
6 changed files with 37 additions and 21 deletions
|
@ -0,0 +1,23 @@
|
|||
import _ from 'lodash';
|
||||
import newMetricAggFn from 'plugins/metrics/components/vis_editor/lib/new_metric_agg_fn';
|
||||
import { isBasicAgg } from 'plugins/metrics/components/vis_editor/lib/agg_lookup';
|
||||
import {
|
||||
handleAdd,
|
||||
handleChange
|
||||
} from 'plugins/metrics/lib/collection_actions';
|
||||
export default (props, items) => doc => {
|
||||
// If we only have one sibling and the user changes to a pipeline
|
||||
// agg we are going to add the pipeline instead of changing the
|
||||
// current item.
|
||||
if (items.length === 1 && !isBasicAgg(doc)) {
|
||||
handleAdd.call(null, props, () => {
|
||||
const metric = newMetricAggFn();
|
||||
metric.type = doc.type;
|
||||
const incompatPipelines = ['calculation', 'series_agg'];
|
||||
if (!_.contains(incompatPipelines, doc.type)) metric.field = doc.id;
|
||||
return metric;
|
||||
});
|
||||
} else {
|
||||
handleChange.call(null, props, doc);
|
||||
}
|
||||
};
|
|
@ -13,12 +13,14 @@ import {
|
|||
handleDelete,
|
||||
handleChange
|
||||
} from 'plugins/metrics/lib/collection_actions';
|
||||
import seriesChangeHandler from 'plugins/metrics/components/vis_editor/lib/series_change_handler';
|
||||
|
||||
export default React.createClass({
|
||||
|
||||
renderRow(row, index, items) {
|
||||
const { props } = this;
|
||||
const { panel, model, fields } = props;
|
||||
const changeHandler = seriesChangeHandler(props, items);
|
||||
return (
|
||||
<Agg
|
||||
key={row.id}
|
||||
|
@ -28,7 +30,7 @@ export default React.createClass({
|
|||
model={row}
|
||||
onAdd={handleAdd.bind(null, props, newMetricAggFn)}
|
||||
onDelete={handleDelete.bind(null, props, row)}
|
||||
onChange={handleChange.bind(null, props)}
|
||||
onChange={changeHandler}
|
||||
disableDelete={items.length < 2}
|
||||
fields={fields}/>
|
||||
);
|
||||
|
|
|
@ -14,12 +14,14 @@ import {
|
|||
handleDelete,
|
||||
handleChange
|
||||
} from 'plugins/metrics/lib/collection_actions';
|
||||
import seriesChangeHandler from 'plugins/metrics/components/vis_editor/lib/series_change_handler';
|
||||
|
||||
export default React.createClass({
|
||||
|
||||
renderRow(row, index, items) {
|
||||
const { props } = this;
|
||||
const { panel, model, fields } = props;
|
||||
const changeHandler = seriesChangeHandler(props, items);
|
||||
return (
|
||||
<Agg
|
||||
key={row.id}
|
||||
|
@ -29,7 +31,7 @@ export default React.createClass({
|
|||
model={row}
|
||||
onAdd={handleAdd.bind(null, props, newMetricAggFn)}
|
||||
onDelete={handleDelete.bind(null, props, row)}
|
||||
onChange={handleChange.bind(null, props)}
|
||||
onChange={changeHandler}
|
||||
disableDelete={items.length < 2}
|
||||
fields={fields}/>
|
||||
);
|
||||
|
|
|
@ -13,12 +13,14 @@ import {
|
|||
handleDelete,
|
||||
handleChange
|
||||
} from 'plugins/metrics/lib/collection_actions';
|
||||
import seriesChangeHandler from 'plugins/metrics/components/vis_editor/lib/series_change_handler';
|
||||
|
||||
export default React.createClass({
|
||||
|
||||
renderRow(row, index, items) {
|
||||
const { props } = this;
|
||||
const { panel, model, fields } = props;
|
||||
const changeHandler = seriesChangeHandler(props, items);
|
||||
return (
|
||||
<Agg
|
||||
key={row.id}
|
||||
|
@ -28,7 +30,7 @@ export default React.createClass({
|
|||
model={row}
|
||||
onAdd={handleAdd.bind(null, props, newMetricAggFn)}
|
||||
onDelete={handleDelete.bind(null, props, row)}
|
||||
onChange={handleChange.bind(null, props)}
|
||||
onChange={changeHandler}
|
||||
disableDelete={items.length < 2}
|
||||
fields={fields}/>
|
||||
);
|
||||
|
|
|
@ -8,7 +8,7 @@ import SeriesConfig from './config';
|
|||
import Sortable from 'react-anything-sortable';
|
||||
import Tooltip from 'plugins/metrics/components/tooltip';
|
||||
import Split from 'plugins/metrics/components/vis_editor/split';
|
||||
import { isBasicAgg } from 'plugins/metrics/components/vis_editor/lib/agg_lookup';
|
||||
import seriesChangeHandler from 'plugins/metrics/components/vis_editor/lib/series_change_handler';
|
||||
import {
|
||||
handleAdd,
|
||||
handleDelete,
|
||||
|
@ -20,22 +20,7 @@ export default React.createClass({
|
|||
renderRow(row, index, items) {
|
||||
const { props } = this;
|
||||
const { model, panel, fields } = props;
|
||||
const changeHandler = doc => {
|
||||
// If we only have one sibling and the user changes to a pipeline
|
||||
// agg we are going to add the pipeline instead of changing the
|
||||
// current item.
|
||||
if (items.length === 1 && !isBasicAgg(doc)) {
|
||||
handleAdd.call(null, props, () => {
|
||||
const metric = newMetricAggFn();
|
||||
metric.type = doc.type;
|
||||
const incompatPipelines = ['calculation', 'series_agg'];
|
||||
if (!_.contains(incompatPipelines, doc.type)) metric.field = doc.id;
|
||||
return metric;
|
||||
});
|
||||
} else {
|
||||
handleChange.call(null, props, doc);
|
||||
}
|
||||
};
|
||||
const changeHandler = seriesChangeHandler(props, items);
|
||||
return (
|
||||
<Agg
|
||||
key={row.id}
|
||||
|
|
|
@ -12,6 +12,7 @@ import createSelectHandler from 'plugins/metrics/lib/create_select_handler';
|
|||
import createTextHandler from 'plugins/metrics/lib/create_text_handler';
|
||||
import createNumberHandler from 'plugins/metrics/lib/create_number_handler';
|
||||
import Split from 'plugins/metrics/components/vis_editor/split';
|
||||
import seriesChangeHandler from 'plugins/metrics/components/vis_editor/lib/series_change_handler';
|
||||
|
||||
import {
|
||||
handleAdd,
|
||||
|
@ -24,6 +25,7 @@ export default React.createClass({
|
|||
renderRow(row, index, items) {
|
||||
const { props } = this;
|
||||
const { panel, model, fields } = props;
|
||||
const changeHandler = seriesChangeHandler(props, items);
|
||||
return (
|
||||
<Agg
|
||||
key={row.id}
|
||||
|
@ -33,7 +35,7 @@ export default React.createClass({
|
|||
model={row}
|
||||
onAdd={handleAdd.bind(null, props, newMetricAggFn)}
|
||||
onDelete={handleDelete.bind(null, props, row)}
|
||||
onChange={handleChange.bind(null, props)}
|
||||
onChange={changeHandler}
|
||||
disableDelete={items.length < 2}
|
||||
fields={fields}/>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue