Skip to content

Commit

Permalink
fixed editor state updates for parent pipeline aggs (elastic#22874)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Sep 12, 2018
1 parent 2b1dacc commit b816a51
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions test/functional/apps/visualize/_vertical_bar_chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"');
});

});
});
}
7 changes: 7 additions & 0 deletions test/functional/page_objects/visualize_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b816a51

Please sign in to comment.