removing schema references from vis types (#20489)

This commit is contained in:
Peter Pisljar 2018-07-12 08:55:06 +02:00 committed by GitHub
parent 1157a59d59
commit 240b94f724
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 23 additions and 59 deletions

View file

@ -42,7 +42,7 @@ describe('metric vis', function () {
fieldFormatter: () => {
return formatter;
},
schema: {}
type: {}
};
let metricController;

View file

@ -105,7 +105,7 @@ export class MetricVisComponent extends Component {
table.columns.forEach((column, columnIndex) => {
const aggConfig = column.aggConfig;
if (aggConfig && aggConfig.schema.group === 'buckets') {
if (aggConfig && aggConfig.type.type === 'buckets') {
bucketAgg = aggConfig;
// Store the current index, so we later know in which position in the
// row array, the bucket agg key will be, so we can create filters on it.

View file

@ -38,7 +38,7 @@ describe('buildHierarchicalData()', function () {
return {
id: id,
name: name,
schema: { group: 'buckets' },
type: { type: 'buckets' },
getKey: (bucket) => bucket.key,
fieldFormatter: _.constant(String)
};

View file

@ -35,7 +35,7 @@ export function tabifyGetColumns(aggs, minimal, hierarchical) {
// separate the metrics
const grouped = _.groupBy(aggs, function (agg) {
return agg.schema.group;
return agg.type.type;
});
if (!grouped.buckets) {

View file

@ -47,7 +47,7 @@ function collectBucket(write, bucket, key, aggScale) {
const aggInfo = agg.write(write.aggs);
aggScale *= aggInfo.metricScale || 1;
switch (agg.schema.group) {
switch (agg.type.type) {
case 'buckets':
const buckets = new TabifyBuckets(bucket[agg.id], agg.params);
if (buckets.length) {
@ -103,7 +103,7 @@ function collectBucket(write, bucket, key, aggScale) {
function passEmptyBuckets(write, bucket, key, aggScale) {
const agg = write.aggStack.shift();
switch (agg.schema.group) {
switch (agg.type.type) {
case 'metrics':
// pass control back to collectBucket()
write.aggStack.unshift(agg);

View file

@ -20,14 +20,11 @@
import _ from 'lodash';
import { VisProvider } from '../../vis';
import { aggTypes } from '..';
import { VisTypesRegistryProvider } from '../../registry/vis_types';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { AggConfig } from '../../vis/agg_config';
// eslint-disable-next-line @elastic/kibana-custom/no-default-export
export default function AggParamWriterHelper(Private) {
const Vis = Private(VisProvider);
const visTypes = Private(VisTypesRegistryProvider);
const stubbedLogstashIndexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
/**
@ -60,32 +57,16 @@ export default function AggParamWriterHelper(Private) {
// not configurable right now, but totally required
self.indexPattern = stubbedLogstashIndexPattern;
// the vis type we will use to write the aggParams
self.visType = null;
// the schema that the aggType satisfies
self.visAggSchema = null;
// find a suitable vis type and schema
_.find(visTypes, function (visType) {
const schema = _.find(visType.schemas.all, function (schema) {
// type, type, type, type, type... :(
return schema.group === self.aggType.type;
});
if (schema) {
self.visType = visType;
self.visAggSchema = schema;
return true;
}
});
if (!self.aggType || !self.visType || !self.visAggSchema) {
throw new Error('unable to find a usable visType and schema for the ' + opts.aggType + ' agg type');
}
self.vis = new Vis(self.indexPattern, {
type: self.visType.name
type: 'histogram',
aggs: [{
id: 1,
type: self.aggType.name,
params: {}
}]
});
}
@ -108,23 +89,10 @@ export default function AggParamWriterHelper(Private) {
}
const agg = new AggConfig(self.vis, {
id: 1,
schema: self.visAggSchema.name,
type: self.aggType.name,
params: paramValues
});
const aggConfig = self.vis.aggs[0];
aggConfig.setParams(paramValues);
self.vis.setState({
type: self.vis.type.name,
aggs: [agg.toJSON()]
});
const aggConfig = _.find(self.vis.aggs, function (aggConfig) {
return aggConfig.type === self.aggType;
});
return aggConfig.type.params.write(aggConfig, self.vis.aggs);
return aggConfig.write(self.vis.aggs);
};
return AggParamWriter;

View file

@ -113,9 +113,6 @@ const buildOtherBucketAgg = (aggConfigs, aggWithOtherBucket, response) => {
const filterAgg = new AggConfig(aggConfigs[index].vis, {
type: 'filters',
id: 'other',
schema: {
group: 'buckets'
}
});
// nest all the child aggregations of aggWithOtherBucket

View file

@ -159,8 +159,7 @@ export const geoHashBucketAgg = new BucketAggType({
enabled: true,
params: {
field: agg.getField()
},
schema: 'metric'
}
}));
}

View file

@ -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.schema.group === 'buckets');
const lastBucket = _.findLast($scope.vis.getAggConfig(), agg => agg.type.type === 'buckets');
if ($scope.aggForm && $scope.aggForm.agg) {
$scope.aggForm.agg.$setValidity('bucket', true);
}
@ -43,7 +43,7 @@ const parentPipelineAggController = function ($scope) {
};
function checkBuckets() {
const lastBucket = _.findLast($scope.vis.getAggConfig(), agg => agg.schema.group === 'buckets');
const lastBucket = _.findLast($scope.vis.getAggConfig(), agg => agg.type.type === 'buckets');
const bucketHasType = lastBucket && lastBucket.type;
const bucketIsHistogram = bucketHasType && ['date_histogram', 'histogram'].includes(lastBucket.type.name);
const canUseAggregation = lastBucket && bucketIsHistogram;

View file

@ -113,7 +113,7 @@ export const topHitMetricAgg = new MetricAggType({
],
controller: function ($scope) {
$scope.options = [];
$scope.$watchGroup([ 'agg.vis.type.name', 'agg.params.field.type' ], function ([ visName, fieldType ]) {
$scope.$watchGroup([ 'vis.type.name', 'agg.params.field.type' ], function ([ visName, fieldType ]) {
if (fieldType && visName) {
$scope.options = _.filter($scope.aggParam.options, option => {
return option.isCompatibleVis(visName) && option.isCompatibleType(fieldType);

View file

@ -27,7 +27,7 @@ export default function AggConfigResult(aggConfig, parent, value, key, filters)
this.filters = filters;
this.$parent = parent;
if (aggConfig.schema.group === 'buckets') {
if (aggConfig.type.type === 'buckets') {
this.type = 'bucket';
} else {
this.type = 'metric';

View file

@ -144,7 +144,7 @@ class AggConfigs extends IndexedArray {
parseParentAggs(dslLvlCursor, dsl);
if (config.schema.group === 'buckets' && i < list.length - 1) {
if (config.type.type === 'buckets' && i < list.length - 1) {
// buckets that are not the last item in the list accept sub-aggs
subAggs = dsl.aggs || (dsl.aggs = {});
}
@ -167,7 +167,7 @@ class AggConfigs extends IndexedArray {
return aggs ? requestValuesAggs.concat(aggs) : requestValuesAggs;
}, []);
//move metrics to the end
return _.sortBy(aggregations, agg => agg.schema.group === 'metrics' ? 1 : 0);
return _.sortBy(aggregations, agg => agg.type.type === 'metrics' ? 1 : 0);
}
/**

View file

@ -69,7 +69,7 @@ export class VisualizeDataLoader {
return this._visData;
}
catch (e) {
this.props.searchSource.cancelQueued();
props.searchSource.cancelQueued();
this._vis.requestError = e;
if (isTermSizeZeroError(e)) {
return toastNotifications.addDanger(