From 24d25a7b4fa69b8aa8b1cd9dafee441a86fd9158 Mon Sep 17 00:00:00 2001 From: Maryia Lapata Date: Tue, 13 Aug 2019 12:03:16 +0300 Subject: [PATCH] [Vis Default editor] Fix issue with Rollup (#42430) (#43172) * Fix issue with Rollup * Use useMemo for editorConfig * Wrap makeLabel with try catch * Revert fetch to fetchForWildcard * Update useEffect dependencies --- .../public/controls/point_series/series.js | 4 +++- .../public/controls/point_series/value_axes.js | 4 +++- .../step_time_field/step_time_field.js | 2 +- .../vis/editors/default/components/agg.tsx | 16 +++++++++++++--- .../editors/default/components/agg_params.tsx | 11 +++++------ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/controls/point_series/series.js b/src/legacy/core_plugins/kbn_vislib_vis_types/public/controls/point_series/series.js index 5a98e63d2c79f..3e52df4a4d5c1 100644 --- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/controls/point_series/series.js +++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/controls/point_series/series.js @@ -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 () { @@ -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; diff --git a/src/legacy/core_plugins/kbn_vislib_vis_types/public/controls/point_series/value_axes.js b/src/legacy/core_plugins/kbn_vislib_vis_types/public/controls/point_series/value_axes.js index e9f839da4ad37..252e9b8a6fa50 100644 --- a/src/legacy/core_plugins/kbn_vislib_vis_types/public/controls/point_series/value_axes.js +++ b/src/legacy/core_plugins/kbn_vislib_vis_types/public/controls/point_series/value_axes.js @@ -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 () { @@ -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(); diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js index 4476ad868cbcf..37591d484d201 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_time_field/step_time_field.js @@ -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); diff --git a/src/legacy/ui/public/vis/editors/default/components/agg.tsx b/src/legacy/ui/public/vis/editors/default/components/agg.tsx index e510c8313a105..d29e48e269e59 100644 --- a/src/legacy/ui/public/vis/editors/default/components/agg.tsx +++ b/src/legacy/ui/public/vis/editors/default/components/agg.tsx @@ -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( @@ -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) { diff --git a/src/legacy/ui/public/vis/editors/default/components/agg_params.tsx b/src/legacy/ui/public/vis/editors/default/components/agg_params.tsx index 29a2421121fd5..2a8e7f9002a22 100644 --- a/src/legacy/ui/public/vis/editors/default/components/agg_params.tsx +++ b/src/legacy/ui/public/vis/editors/default/components/agg_params.tsx @@ -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'; @@ -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]; @@ -147,7 +146,7 @@ function DefaultEditorAggParams({ onAggParamsChange(agg.params, param, newValue); } }); - }, [agg.type]); + }, [editorConfig]); useEffect(() => { setTouched(false);