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

[Vis Default editor] Fix issue with Rollup #42430

Merged
merged 10 commits into from
Aug 13, 2019
16 changes: 13 additions & 3 deletions src/legacy/ui/public/vis/editors/default/components/agg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ function DefaultEditorAgg({
}
}

// A description of the aggregation, for displaying in the collapsed agg header
let aggDescription = '';

if (agg.type && agg.type.makeLabel) {
try {
aggDescription = agg.type.makeLabel(agg);
} catch (e) {
// Date Histogram's `makeLabel` implementation invokes 'write' method for each param, including interval's 'write',
// which throws an error when interval is undefined.
aggDescription = '';
}
}

useEffect(() => {
if (isLastBucketAgg && ['date_histogram', 'histogram'].includes(agg.type.name)) {
onAggParamsChange(
Expand All @@ -98,9 +111,6 @@ function DefaultEditorAgg({
}
}, [lastParentPipelineAggTitle, isLastBucket, agg.type]);

// A description of the aggregation, for displaying in the collapsed agg header
const aggDescription = agg.type && agg.type.makeLabel ? agg.type.makeLabel(agg) : '';
maryia-lapata marked this conversation as resolved.
Show resolved Hide resolved

const onToggle = (isOpen: boolean) => {
setIsEditorOpen(isOpen);
if (!isOpen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import React, { useReducer, useEffect } from 'react';
import React, { useReducer, useEffect, useMemo } from 'react';
import { EuiForm, EuiAccordion, EuiSpacer, EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

Expand Down Expand Up @@ -94,10 +94,9 @@ function DefaultEditorAggParams({
const groupedAggTypeOptions = getAggTypeOptions(agg, indexPattern, groupName);
const errors = getError(agg, aggIsTooLow);

const editorConfig = editorConfigProviders.getConfigForAgg(
aggTypes.byType[groupName],
indexPattern,
agg
const editorConfig = useMemo(
() => editorConfigProviders.getConfigForAgg(aggTypes.byType[groupName], indexPattern, agg),
[groupName, agg.type]
);
const params = getAggParamsToRender({ agg, editorConfig, metricAggs, state });
const allParams = [...params.basic, ...params.advanced];
Expand Down Expand Up @@ -147,7 +146,7 @@ function DefaultEditorAggParams({
onAggParamsChange(agg.params, param, newValue);
}
});
}, [agg.type]);
}, [editorConfig]);

useEffect(() => {
setTouched(false);
Expand Down