From 2df6eed0516d6c638a3ebe773f0480548d3924fc Mon Sep 17 00:00:00 2001 From: Peter Pisljar Date: Thu, 12 Jul 2018 11:01:39 +0200 Subject: [PATCH] removing schema references from vis types (#20489) (#20704) --- .../public/__tests__/metric_vis_controller.js | 2 +- .../public/metric_vis_controller.js | 2 +- .../__tests__/transform_aggregation.js | 2 +- .../agg_response/tabify/_get_columns.js | 2 +- src/ui/public/agg_response/tabify/tabify.js | 4 +- .../agg_types/__tests__/agg_param_writer.js | 50 ++++--------------- .../buckets/_terms_other_bucket_helper.js | 3 -- src/ui/public/agg_types/buckets/geo_hash.js | 3 +- .../lib/parent_pipeline_agg_controller.js | 4 +- src/ui/public/agg_types/metrics/top_hit.js | 2 +- src/ui/public/vis/agg_config_result.js | 2 +- src/ui/public/vis/agg_configs.js | 4 +- .../visualize/loader/visualize_data_loader.js | 2 +- 13 files changed, 23 insertions(+), 59 deletions(-) diff --git a/src/core_plugins/metric_vis/public/__tests__/metric_vis_controller.js b/src/core_plugins/metric_vis/public/__tests__/metric_vis_controller.js index 313872b4fd093..7ce5cb6ab1824 100644 --- a/src/core_plugins/metric_vis/public/__tests__/metric_vis_controller.js +++ b/src/core_plugins/metric_vis/public/__tests__/metric_vis_controller.js @@ -42,7 +42,7 @@ describe('metric vis', function () { fieldFormatter: () => { return formatter; }, - schema: {} + type: {} }; let metricController; diff --git a/src/core_plugins/metric_vis/public/metric_vis_controller.js b/src/core_plugins/metric_vis/public/metric_vis_controller.js index 5a09ef58b561e..fa9adb7885ced 100644 --- a/src/core_plugins/metric_vis/public/metric_vis_controller.js +++ b/src/core_plugins/metric_vis/public/metric_vis_controller.js @@ -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. diff --git a/src/ui/public/agg_response/hierarchical/__tests__/transform_aggregation.js b/src/ui/public/agg_response/hierarchical/__tests__/transform_aggregation.js index 86b5b1b44938f..ba8b72636b647 100644 --- a/src/ui/public/agg_response/hierarchical/__tests__/transform_aggregation.js +++ b/src/ui/public/agg_response/hierarchical/__tests__/transform_aggregation.js @@ -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) }; diff --git a/src/ui/public/agg_response/tabify/_get_columns.js b/src/ui/public/agg_response/tabify/_get_columns.js index 46c3059feaaba..e5010f0f0358a 100644 --- a/src/ui/public/agg_response/tabify/_get_columns.js +++ b/src/ui/public/agg_response/tabify/_get_columns.js @@ -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) { diff --git a/src/ui/public/agg_response/tabify/tabify.js b/src/ui/public/agg_response/tabify/tabify.js index e12d4e43c45f2..05ec560d5214a 100644 --- a/src/ui/public/agg_response/tabify/tabify.js +++ b/src/ui/public/agg_response/tabify/tabify.js @@ -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); diff --git a/src/ui/public/agg_types/__tests__/agg_param_writer.js b/src/ui/public/agg_types/__tests__/agg_param_writer.js index c9182b2271428..bddb4a9a7f3dc 100644 --- a/src/ui/public/agg_types/__tests__/agg_param_writer.js +++ b/src/ui/public/agg_types/__tests__/agg_param_writer.js @@ -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 - }); - - self.vis.setState({ - type: self.vis.type.name, - aggs: [agg.toJSON()] - }); - - const aggConfig = _.find(self.vis.aggs, function (aggConfig) { - return aggConfig.type === self.aggType; - }); + const aggConfig = self.vis.aggs[0]; + aggConfig.setParams(paramValues); - return aggConfig.type.params.write(aggConfig, self.vis.aggs); + return aggConfig.write(self.vis.aggs); }; return AggParamWriter; diff --git a/src/ui/public/agg_types/buckets/_terms_other_bucket_helper.js b/src/ui/public/agg_types/buckets/_terms_other_bucket_helper.js index 4b02c08e0a197..e683386c81b12 100644 --- a/src/ui/public/agg_types/buckets/_terms_other_bucket_helper.js +++ b/src/ui/public/agg_types/buckets/_terms_other_bucket_helper.js @@ -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 diff --git a/src/ui/public/agg_types/buckets/geo_hash.js b/src/ui/public/agg_types/buckets/geo_hash.js index 9770d4742fef8..37a65430ef465 100644 --- a/src/ui/public/agg_types/buckets/geo_hash.js +++ b/src/ui/public/agg_types/buckets/geo_hash.js @@ -159,8 +159,7 @@ export const geoHashBucketAgg = new BucketAggType({ enabled: true, params: { field: agg.getField() - }, - schema: 'metric' + } })); } 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 ddd642b463fe6..a2df4ec6ac977 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.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; diff --git a/src/ui/public/agg_types/metrics/top_hit.js b/src/ui/public/agg_types/metrics/top_hit.js index 9b44f4938b8f8..a20d88eafa520 100644 --- a/src/ui/public/agg_types/metrics/top_hit.js +++ b/src/ui/public/agg_types/metrics/top_hit.js @@ -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); diff --git a/src/ui/public/vis/agg_config_result.js b/src/ui/public/vis/agg_config_result.js index c8bf67cdcc535..75da837e6ee1c 100644 --- a/src/ui/public/vis/agg_config_result.js +++ b/src/ui/public/vis/agg_config_result.js @@ -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'; diff --git a/src/ui/public/vis/agg_configs.js b/src/ui/public/vis/agg_configs.js index c6c688db666f1..de7e805158641 100644 --- a/src/ui/public/vis/agg_configs.js +++ b/src/ui/public/vis/agg_configs.js @@ -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); } /** diff --git a/src/ui/public/visualize/loader/visualize_data_loader.js b/src/ui/public/visualize/loader/visualize_data_loader.js index c93351ff9bd82..3cd5d5472aa70 100644 --- a/src/ui/public/visualize/loader/visualize_data_loader.js +++ b/src/ui/public/visualize/loader/visualize_data_loader.js @@ -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(