diff --git a/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_controller.js b/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_controller.js index a2df4ec6ac977..610dc59309243 100644 --- a/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_controller.js +++ b/src/ui/public/agg_types/metrics/lib/parent_pipeline_agg_controller.js @@ -28,7 +28,7 @@ const parentPipelineAggController = function ($scope) { $scope.$watch('agg.params.metricAgg', updateOrderAgg); $scope.$on('$destroy', function () { - const lastBucket = _.findLast($scope.vis.getAggConfig(), agg => agg.type.type === 'buckets'); + const lastBucket = _.findLast($scope.state.aggs, agg => agg.type.type === 'buckets'); if ($scope.aggForm && $scope.aggForm.agg) { $scope.aggForm.agg.$setValidity('bucket', true); } @@ -43,13 +43,13 @@ const parentPipelineAggController = function ($scope) { }; function checkBuckets() { - const lastBucket = _.findLast($scope.vis.getAggConfig(), agg => agg.type.type === 'buckets'); + const lastBucket = _.findLast($scope.state.aggs, agg => agg.type.type === 'buckets'); const bucketHasType = lastBucket && lastBucket.type; const bucketIsHistogram = bucketHasType && ['date_histogram', 'histogram'].includes(lastBucket.type.name); const canUseAggregation = lastBucket && bucketIsHistogram; // remove errors on all buckets - _.each($scope.vis.aggs, agg => { if (agg.error) delete agg.error; }); + _.each($scope.state.aggs, agg => { if (agg.error) delete agg.error; }); if ($scope.aggForm.agg) { $scope.aggForm.agg.$setValidity('bucket', canUseAggregation); @@ -75,7 +75,7 @@ const parentPipelineAggController = function ($scope) { // we aren't creating a custom aggConfig if (metricAgg !== 'custom') { - if (!$scope.vis.getAggConfig().find(agg => agg.id === metricAgg)) { + if (!$scope.state.aggs.find(agg => agg.id === metricAgg)) { params.metricAgg = null; } params.customMetric = null; diff --git a/test/functional/apps/visualize/_vertical_bar_chart.js b/test/functional/apps/visualize/_vertical_bar_chart.js index a623a3e2e3261..546897c74b3f3 100644 --- a/test/functional/apps/visualize/_vertical_bar_chart.js +++ b/test/functional/apps/visualize/_vertical_bar_chart.js @@ -284,6 +284,17 @@ export default function ({ getService, getPageObjects }) { expect(legendEntries).to.eql(expectedEntries); }); + it('should show an error if last bucket aggregation is terms', async () => { + await PageObjects.visualize.toggleOpenEditor(2, 'false'); + await PageObjects.visualize.clickAddBucket(); + await PageObjects.visualize.clickBucket('Split Series'); + await PageObjects.visualize.selectAggregation('Terms'); + await PageObjects.visualize.selectField('response.raw'); + + const errorMessage = await PageObjects.visualize.getBucketErrorMessage(); + expect(errorMessage).to.contain('Last bucket aggregation must be "Date Histogram"'); + }); + }); }); } diff --git a/test/functional/page_objects/visualize_page.js b/test/functional/page_objects/visualize_page.js index d182025363035..aa2a0b17e38f3 100644 --- a/test/functional/page_objects/visualize_page.js +++ b/test/functional/page_objects/visualize_page.js @@ -1133,6 +1133,13 @@ export function VisualizePageProvider({ getService, getPageObjects }) { return await Promise.all(pieSlices.map(async pieSlice => await pieSlice.getAttribute('style'))); } + async getBucketErrorMessage() { + const error = await find.byCssSelector('.vis-editor-agg-error'); + const errorMessage = await error.getProperty('innerText'); + log.debug(errorMessage); + return errorMessage; + } + async selectSortMetric(agg, metric) { const sortMetric = await find.byCssSelector(`[data-test-subj="visEditorOrder${agg}-${metric}"]`); return await sortMetric.click();