Skip to content

Commit

Permalink
[Vis Default editor] Fix issue with Rollup (elastic#42430) (elastic#4…
Browse files Browse the repository at this point in the history
…3172)

* Fix issue with Rollup

* Use useMemo for editorConfig

* Wrap makeLabel with try catch

* Revert fetch to fetchForWildcard

* Update useEffect dependencies
  • Loading branch information
maryia-lapata authored Aug 13, 2019
1 parent 18befc6 commit 24d25a7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import _ from 'lodash';
import { uiModules } from 'ui/modules';
import vislibSeriesTemplate from './series.html';
import { safeMakeLabel } from 'ui/agg_types/agg_utils';

const module = uiModules.get('kibana');

module.directive('vislibSeries', function () {
Expand Down Expand Up @@ -49,7 +51,7 @@ module.directive('vislibSeries', function () {
$scope.series = $scope.editorState.params.seriesParams;
$scope.$watch(() => {
return $scope.editorState.aggs.map(agg => {
return agg.makeLabel();
return safeMakeLabel(agg);
}).join();
}, () => {
const schemaTitle = $scope.vis.type.schemas.metrics[0].title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import _ from 'lodash';
import { uiModules } from 'ui/modules';
import vislibValueAxesTemplate from './value_axes.html';
import { safeMakeLabel } from 'ui/agg_types/agg_utils';

const module = uiModules.get('kibana');

module.directive('vislibValueAxes', function () {
Expand Down Expand Up @@ -193,7 +195,7 @@ module.directive('vislibValueAxes', function () {

$scope.$watch(() => {
return $scope.editorState.aggs.map(agg => {
return agg.makeLabel();
return safeMakeLabel(agg);
}).join();
}, () => {
$scope.updateAxisTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class StepTimeFieldComponent extends Component {

this.setState({ isFetchingTimeFields: true });
const fields = await ensureMinimumTime(
indexPattern.fieldsFetcher.fetch(getFetchForWildcardOptions())
indexPattern.fieldsFetcher.fetchForWildcard(pattern, getFetchForWildcardOptions())
);
const timeFields = extractTimeFields(fields);

Expand Down
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) : '';

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

0 comments on commit 24d25a7

Please sign in to comment.