diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/agg_row.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/agg_row.js index b07e1cef4fc8..a2f1640904dd 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/agg_row.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/agg_row.js @@ -22,14 +22,13 @@ import React from 'react'; import { last } from 'lodash'; import { AddDeleteButtons } from '../add_delete_buttons'; import { EuiIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; -import { injectI18n } from '@kbn/i18n/react'; import { SeriesDragHandler } from '../series_drag_handler'; +import { i18n } from '@kbn/i18n'; -function AggRowUi(props) { +export function AggRow(props) { let iconType = 'eyeClosed'; let iconColor = 'subdued'; const lastSibling = last(props.siblings); - const { intl } = props; if (lastSibling.id === props.model.id) { iconType = 'eye'; @@ -57,12 +56,10 @@ function AggRowUi(props) { { return value === option.value && isMetricEnabled(option.value, uiRestrictions); @@ -247,8 +247,7 @@ function AggSelectUi(props) { options = [ { - label: intl.formatMessage({ - id: 'visTypeTimeseries.aggSelect.aggGroups.metricAggLabel', + label: i18n.translate('visTypeTimeseries.aggSelect.aggGroups.metricAggLabel', { defaultMessage: 'Metric Aggregations', }), options: metricAggs.map(agg => ({ @@ -257,22 +256,19 @@ function AggSelectUi(props) { })), }, { - label: intl.formatMessage({ - id: 'visTypeTimeseries.aggSelect.aggGroups.parentPipelineAggLabel', + label: i18n.translate('visTypeTimeseries.aggSelect.aggGroups.parentPipelineAggLabel', { defaultMessage: 'Parent Pipeline Aggregations', }), options: pipelineAggs.filter(filterByPanelType(panelType)).map(disableSiblingAggs), }, { - label: intl.formatMessage({ - id: 'visTypeTimeseries.aggSelect.aggGroups.siblingPipelineAggLabel', + label: i18n.translate('visTypeTimeseries.aggSelect.aggGroups.siblingPipelineAggLabel', { defaultMessage: 'Sibling Pipeline Aggregations', }), options: siblingAggs.map(disableSiblingAggs), }, { - label: intl.formatMessage({ - id: 'visTypeTimeseries.aggSelect.aggGroups.specialAggLabel', + label: i18n.translate('visTypeTimeseries.aggSelect.aggGroups.specialAggLabel', { defaultMessage: 'Special Aggregations', }), options: specialAggs.map(disableSiblingAggs), @@ -289,8 +285,7 @@ function AggSelectUi(props) {
Array.isArray(model.variables) && model.script !== undefined; + +export function CalculationAgg(props) { + const htmlId = htmlIdGenerator(); + const { siblings, model } = props; + + const handleChange = createChangeHandler(props.onChange, model); + const handleSelectChange = createSelectHandler(handleChange); + const handleTextChange = createTextHandler(handleChange); + + useEffect(() => { + if (!checkModel(model)) { + handleChange({ + variables: [newVariable()], + script: '', + }); } - } + }, [handleChange, model]); - render() { - const { siblings } = this.props; - - const defaults = { script: '' }; - const model = { ...defaults, ...this.props.model }; - - const handleChange = createChangeHandler(this.props.onChange, model); - const handleSelectChange = createSelectHandler(handleChange); - const handleTextChange = createTextHandler(handleChange); - - const htmlId = htmlIdGenerator(); - - return ( - - - - - - - - + + + + - + + + + - - - - - - + + - + + + + - - + + } + fullWidth + helpText={ +
- } - fullWidth - helpText={ -
- params, - paramsName: params.<name>, - paramsInterval: params._interval, - }} - /> -
- } - > - - - - - - ); - } + values={{ + params: params, + paramsName: params.<name>, + paramsInterval: params._interval, + }} + /> +
+ } + > + +
+
+
+
+ ); } CalculationAgg.propTypes = { diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/math.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/math.js index c62012927f95..5ffcef12c3fc 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/math.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/math.js @@ -17,17 +17,15 @@ * under the License. */ -import React, { Component } from 'react'; +import React, { useEffect } from 'react'; import PropTypes from 'prop-types'; -import _ from 'lodash'; -import uuid from 'uuid'; import { AggRow } from './agg_row'; import { AggSelect } from './agg_select'; import { createChangeHandler } from '../lib/create_change_handler'; import { createSelectHandler } from '../lib/create_select_handler'; import { createTextHandler } from '../lib/create_text_handler'; -import { CalculationVars } from './vars'; +import { CalculationVars, newVariable } from './vars'; import { htmlIdGenerator, EuiFlexGroup, @@ -41,125 +39,121 @@ import { } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -export class MathAgg extends Component { - UNSAFE_componentWillMount() { - if (!this.props.model.variables) { - this.props.onChange( - _.assign({}, this.props.model, { - variables: [{ id: uuid.v1() }], - }) - ); +const checkModel = model => Array.isArray(model.variables) && model.script !== undefined; + +export function MathAgg(props) { + const { siblings, model } = props; + const htmlId = htmlIdGenerator(); + + const handleChange = createChangeHandler(props.onChange, model); + const handleSelectChange = createSelectHandler(handleChange); + const handleTextChange = createTextHandler(handleChange); + + useEffect(() => { + if (!checkModel(model)) { + handleChange({ + variables: [newVariable()], + script: '', + }); } - } + }, [handleChange, model]); - render() { - const { siblings } = this.props; - const htmlId = htmlIdGenerator(); - - const defaults = { script: '' }; - const model = { ...defaults, ...this.props.model }; - - const handleChange = createChangeHandler(this.props.onChange, model); - const handleSelectChange = createSelectHandler(handleChange); - const handleTextChange = createTextHandler(handleChange); - - return ( - - - - - - - - + + + + - + + + + - - - - - - + + - + + + + - - - } - fullWidth - helpText={ - + } + fullWidth + helpText={ + - - - ), - params: params, - paramsName: params.<name>, - paramsValues: params._all.<name>.values, - paramsTimestamps: params._all.<name>.timestamps, - paramsTimestamp: params._timestamp, - paramsIndex: params._index, - paramsInterval: params._interval, - }} - /> - } - > - + + + ), + params: params, + paramsName: params.<name>, + paramsValues: params._all.<name>.values, + paramsTimestamps: params._all.<name>.timestamps, + paramsTimestamp: params._timestamp, + paramsIndex: params._index, + paramsInterval: params._interval, + }} /> - - - - - ); - } + } + > + + + + + + ); } MathAgg.propTypes = { diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/percentile.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/percentile.js index 3ce5be5b6875..500bba14d66c 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/percentile.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/percentile.js @@ -18,8 +18,7 @@ */ import PropTypes from 'prop-types'; -import React, { Component } from 'react'; -import _ from 'lodash'; +import React, { useEffect } from 'react'; import { AggSelect } from './agg_select'; import { FieldSelect } from './field_select'; import { AggRow } from './agg_row'; @@ -39,82 +38,78 @@ import { Percentiles, newPercentile } from './percentile_ui'; const RESTRICT_FIELDS = [KBN_FIELD_TYPES.NUMBER]; -export class PercentileAgg extends Component { - // eslint-disable-line react/no-multi-comp +const checkModel = model => Array.isArray(model.percentiles); - UNSAFE_componentWillMount() { - if (!this.props.model.percentiles) { - this.props.onChange( - _.assign({}, this.props.model, { - percentiles: [newPercentile({ value: 50 })], - }) - ); +export function PercentileAgg(props) { + const { series, model, panel, fields } = props; + const htmlId = htmlIdGenerator(); + + const handleChange = createChangeHandler(props.onChange, model); + const handleSelectChange = createSelectHandler(handleChange); + const indexPattern = + (series.override_index_pattern && series.series_index_pattern) || panel.index_pattern; + + useEffect(() => { + if (!checkModel(model)) { + handleChange({ + percentiles: [newPercentile({ value: 50 })], + }); } - } + }, [handleChange, model]); - render() { - const { series, model, panel, fields } = this.props; - - const handleChange = createChangeHandler(this.props.onChange, model); - const handleSelectChange = createSelectHandler(handleChange); - const indexPattern = - (series.override_index_pattern && series.series_index_pattern) || panel.index_pattern; - const htmlId = htmlIdGenerator(); - - return ( - - - - - - - - + + + + - - - - } - > - + + + + + - - - + } + > + + + + - + - - - ); - } + + + ); } PercentileAgg.propTypes = { diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/vars.js b/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/vars.js index 8553f08af135..3d4ce601c724 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/vars.js +++ b/src/legacy/core_plugins/vis_type_timeseries/public/components/aggs/vars.js @@ -19,14 +19,17 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; +import uuid from 'uuid'; +import { i18n } from '@kbn/i18n'; import _ from 'lodash'; import { AddDeleteButtons } from '../add_delete_buttons'; import { collectionActions } from '../lib/collection_actions'; import { MetricSelect } from './metric_select'; import { EuiFlexGroup, EuiFlexItem, EuiFieldText } from '@elastic/eui'; -import { injectI18n } from '@kbn/i18n/react'; -class CalculationVarsUi extends Component { +export const newVariable = opts => ({ id: uuid.v1(), name: '', field: '', ...opts }); + +export class CalculationVars extends Component { constructor(props) { super(props); this.renderRow = this.renderRow.bind(this); @@ -42,21 +45,19 @@ class CalculationVarsUi extends Component { } renderRow(row, i, items) { - const handleAdd = collectionActions.handleAdd.bind(null, this.props); + const handleAdd = collectionActions.handleAdd.bind(null, this.props, newVariable); const handleDelete = collectionActions.handleDelete.bind(null, this.props, row); - const { intl } = this.props; + return (