Skip to content

Commit

Permalink
remove angular from AggTypes (elastic#17681)
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/ui/public/agg_response/point_series/__tests__/_fake_x_aspect.js
#	src/ui/public/agg_response/point_series/_fake_x_aspect.js
#	src/ui/public/agg_types/__tests__/agg_param_writer.js
#	src/ui/public/agg_types/__tests__/agg_type.js
#	src/ui/public/agg_types/__tests__/buckets/_geo_hash.js
#	src/ui/public/agg_types/__tests__/buckets/_histogram.js
#	src/ui/public/agg_types/__tests__/buckets/_terms_other_bucket_helper.js
#	src/ui/public/agg_types/__tests__/buckets/create_filter/date_histogram.js
#	src/ui/public/agg_types/__tests__/buckets/create_filter/date_range.js
#	src/ui/public/agg_types/__tests__/buckets/create_filter/filters.js
#	src/ui/public/agg_types/__tests__/buckets/create_filter/histogram.js
#	src/ui/public/agg_types/__tests__/buckets/create_filter/ip_range.js
#	src/ui/public/agg_types/__tests__/buckets/create_filter/range.js
#	src/ui/public/agg_types/__tests__/buckets/create_filter/terms.js
#	src/ui/public/agg_types/__tests__/buckets/date_histogram/_editor.js
#	src/ui/public/agg_types/__tests__/buckets/date_histogram/_params.js
#	src/ui/public/agg_types/__tests__/buckets/terms.js
#	src/ui/public/agg_types/__tests__/index.js
#	src/ui/public/agg_types/__tests__/metrics/parent_pipeline.js
#	src/ui/public/agg_types/__tests__/metrics/percentile_ranks.js
#	src/ui/public/agg_types/__tests__/metrics/percentiles.js
#	src/ui/public/agg_types/__tests__/metrics/sibling_pipeline.js
#	src/ui/public/agg_types/__tests__/metrics/std_deviation.js
#	src/ui/public/agg_types/__tests__/metrics/top_hit.js
#	src/ui/public/agg_types/buckets/_bucket_agg_type.js
#	src/ui/public/agg_types/buckets/_terms_other_bucket_helper.js
#	src/ui/public/agg_types/buckets/create_filter/date_range.js
#	src/ui/public/agg_types/buckets/date_histogram.js
#	src/ui/public/agg_types/buckets/date_range.js
#	src/ui/public/agg_types/buckets/filter.js
#	src/ui/public/agg_types/buckets/filters.js
#	src/ui/public/agg_types/buckets/geo_hash.js
#	src/ui/public/agg_types/buckets/histogram.js
#	src/ui/public/agg_types/buckets/ip_range.js
#	src/ui/public/agg_types/buckets/range.js
#	src/ui/public/agg_types/buckets/significant_terms.js
#	src/ui/public/agg_types/buckets/terms.js
#	src/ui/public/agg_types/index.js
#	src/ui/public/agg_types/metrics/avg.js
#	src/ui/public/agg_types/metrics/bucket_avg.js
#	src/ui/public/agg_types/metrics/bucket_max.js
#	src/ui/public/agg_types/metrics/bucket_min.js
#	src/ui/public/agg_types/metrics/bucket_sum.js
#	src/ui/public/agg_types/metrics/cardinality.js
#	src/ui/public/agg_types/metrics/count.js
#	src/ui/public/agg_types/metrics/cumulative_sum.js
#	src/ui/public/agg_types/metrics/derivative.js
#	src/ui/public/agg_types/metrics/geo_bounds.js
#	src/ui/public/agg_types/metrics/geo_centroid.js
#	src/ui/public/agg_types/metrics/max.js
#	src/ui/public/agg_types/metrics/median.js
#	src/ui/public/agg_types/metrics/metric_agg_type.js
#	src/ui/public/agg_types/metrics/min.js
#	src/ui/public/agg_types/metrics/moving_avg.js
#	src/ui/public/agg_types/metrics/percentile_ranks.js
#	src/ui/public/agg_types/metrics/percentiles.js
#	src/ui/public/agg_types/metrics/serial_diff.js
#	src/ui/public/agg_types/metrics/std_deviation.js
#	src/ui/public/agg_types/metrics/sum.js
#	src/ui/public/agg_types/metrics/top_hit.js
#	src/ui/public/courier/data_source/__tests__/decorate_query.js
#	src/ui/public/time_buckets/time_buckets.js
#	src/ui/public/vis/__tests__/_agg_config.js
#	src/ui/public/vis/agg_configs.js
#	src/ui/public/vis/editors/default/agg_params.js
  • Loading branch information
ppisljar committed May 7, 2018
1 parent 4d3b173 commit 0370d68
Show file tree
Hide file tree
Showing 84 changed files with 2,443 additions and 2,737 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BasicResponseHandlerProvider } from 'ui/vis/response_handlers/basic';
import { DocTitleProvider } from 'ui/doc_title';
import PluginsKibanaDiscoverHitSortFnProvider from '../_hit_sort_fn';
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
import { AggTypesBucketsIntervalOptionsProvider } from 'ui/agg_types/buckets/_interval_options';
import { intervalOptions } from 'ui/agg_types/buckets/_interval_options';
import { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
import uiRoutes from 'ui/routes';
import { uiModules } from 'ui/modules';
Expand Down Expand Up @@ -138,7 +138,7 @@ function discoverController(
});

$scope.getDocLink = getDocLink;
$scope.intervalOptions = Private(AggTypesBucketsIntervalOptionsProvider);
$scope.intervalOptions = intervalOptions;
$scope.showInterval = false;
$scope.minimumVisibleRows = 50;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ import expect from 'expect.js';
import ngMock from 'ng_mock';
import { VisProvider } from '../../../vis';
import { AggConfig } from '../../../vis/agg_config';
import { AggTypesAggTypeProvider } from '../../../agg_types/agg_type';
import { AggType } from '../../../agg_types/agg_type';
import { PointSeriesFakeXAxisProvider } from '../_fake_x_aspect';

describe('makeFakeXAspect', function () {

let makeFakeXAspect;
let Vis;
let AggType;
let indexPattern;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
Vis = Private(VisProvider);
AggType = Private(AggTypesAggTypeProvider);
indexPattern = Private(VisProvider);
makeFakeXAspect = Private(PointSeriesFakeXAxisProvider);
}));
Expand Down
5 changes: 2 additions & 3 deletions src/ui/public/agg_response/point_series/_fake_x_aspect.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AggConfig } from '../../vis/agg_config';
import { AggTypesAggTypeProvider } from '../../agg_types/agg_type';
import { AggType } from '../../agg_types/agg_type';

export function PointSeriesFakeXAxisProvider(Private) {
const AggType = Private(AggTypesAggTypeProvider);
export function PointSeriesFakeXAxisProvider() {

const allAgg = new AggType({
name: 'all',
Expand Down
3 changes: 1 addition & 2 deletions src/ui/public/agg_types/__tests__/agg_param_writer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import _ from 'lodash';
import { VisProvider } from '../../vis';
import { AggTypesIndexProvider } from '..';
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 aggTypes = Private(AggTypesIndexProvider);
const visTypes = Private(VisTypesRegistryProvider);
const stubbedLogstashIndexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);

Expand Down
4 changes: 1 addition & 3 deletions src/ui/public/agg_types/__tests__/agg_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import '../../private';
import { AggParams } from '../agg_params';
import { VisProvider } from '../../vis';
import { fieldFormats } from '../../registry/field_formats';
import { AggTypesAggTypeProvider } from '../agg_type';
import { AggType } from '../agg_type';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

describe('AggType Class', function () {
let AggType;
let indexPattern;
let Vis;

Expand All @@ -18,7 +17,6 @@ describe('AggType Class', function () {
beforeEach(ngMock.inject(function (Private) {

Vis = Private(VisProvider);
AggType = Private(AggTypesAggTypeProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

Expand Down
52 changes: 15 additions & 37 deletions src/ui/public/agg_types/__tests__/buckets/_geo_hash.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import expect from 'expect.js';
import sinon from 'sinon';
import ngMock from 'ng_mock';
import { AggTypesBucketsGeoHashProvider } from '../../buckets/geo_hash';
import { geoHashBucketAgg } from '../../buckets/geo_hash';
import * as AggConfigModule from '../../../vis/agg_config';
import { AggTypesIndexProvider } from '../..';
import * as BucketAggTypeModule from '../../buckets/_bucket_agg_type';
import { aggTypes } from '../..';
AggConfigModule.AggConfig.aggTypes = aggTypes;

describe('Geohash Agg', () => {

Expand Down Expand Up @@ -40,27 +41,15 @@ describe('Geohash Agg', () => {
const AggConfigMock = (vis, aggOptions) => {
return aggOptions;
};
const PrivateMock = (provider) => {
switch (provider.name) {
case 'AggTypesBucketsBucketAggTypeProvider':
return BucketAggTypeMock;
break;
default:
return () => {};
}
};
const configMock = {
get: () => {
return 7;//"visualization:tileMap:maxPrecision"
}
};

before(function () {
sinon.stub(AggConfigModule, 'AggConfig', AggConfigMock);
sinon.stub(BucketAggTypeModule, 'BucketAggType', BucketAggTypeMock);
});

after(function () {
AggConfigModule.AggConfig.restore();
BucketAggTypeModule.BucketAggType.restore();
});


Expand Down Expand Up @@ -93,23 +82,12 @@ describe('Geohash Agg', () => {
};
}

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
AggConfigModule.AggConfig.aggTypes = Private(AggTypesIndexProvider);
}));

let geohashAgg;
beforeEach(() => {
geohashAgg = AggTypesBucketsGeoHashProvider(PrivateMock, configMock); // eslint-disable-line new-cap
});


describe('precision parameter', () => {

const PRECISION_PARAM_INDEX = 6;
let precisionParam;
beforeEach(() => {
precisionParam = geohashAgg.params[PRECISION_PARAM_INDEX];
precisionParam = geoHashBucketAgg.params[PRECISION_PARAM_INDEX];
});

it('should select precision parameter', () => {
Expand Down Expand Up @@ -169,7 +147,7 @@ describe('Geohash Agg', () => {
beforeEach(() => {
initVisSessionState();
initAggParams();
requestAggs = geohashAgg.getRequestAggs(aggMock);
requestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
});

it('should create filter, geohash_grid, and geo_centroid aggregations', () => {
Expand All @@ -189,7 +167,7 @@ describe('Geohash Agg', () => {
// there was a bug because of an "&& mapZoom" check which excluded 0 as a valid mapZoom, but it is.
it('should create filter, geohash_grid, and geo_centroid aggregations when zoom level 0', () => {
aggMock.vis.params.mapZoom = 0;
requestAggs = geohashAgg.getRequestAggs(aggMock);
requestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(requestAggs.length).to.equal(3);
expect(requestAggs[0].type).to.equal('filter');
expect(requestAggs[1].type).to.equal('geohash_grid');
Expand All @@ -206,15 +184,15 @@ describe('Geohash Agg', () => {

it('should only create geohash_grid and geo_centroid aggregations when isFilteredByCollar is false', () => {
aggMock.params.isFilteredByCollar = false;
const requestAggs = geohashAgg.getRequestAggs(aggMock);
const requestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(requestAggs.length).to.equal(2);
expect(requestAggs[0].type).to.equal('geohash_grid');
expect(requestAggs[1].type).to.equal('geo_centroid');
});

it('should only create filter and geohash_grid aggregations when useGeocentroid is false', () => {
aggMock.params.useGeocentroid = false;
const requestAggs = geohashAgg.getRequestAggs(aggMock);
const requestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(requestAggs.length).to.equal(2);
expect(requestAggs[0].type).to.equal('filter');
expect(requestAggs[1].type).to.equal('geohash_grid');
Expand All @@ -229,7 +207,7 @@ describe('Geohash Agg', () => {
beforeEach(() => {
resetMap();
initAggParams();
origRequestAggs = geohashAgg.getRequestAggs(aggMock);
origRequestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
origMapCollar = aggMock.vis.sessionState.mapCollar;
});

Expand All @@ -239,7 +217,7 @@ describe('Geohash Agg', () => {
bottom_right: { lat: -0.9, lon: 0.9 }
});

const newRequestAggs = geohashAgg.getRequestAggs(aggMock);
const newRequestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(JSON.stringify(origRequestAggs[0].params, null, '')).to.equal(JSON.stringify(newRequestAggs[0].params, null, ''));

const newMapCollar = aggMock.vis.sessionState.mapCollar;
Expand All @@ -252,7 +230,7 @@ describe('Geohash Agg', () => {
bottom_right: { lat: 9.0, lon: -9.0 }
});

const newRequestAggs = geohashAgg.getRequestAggs(aggMock);
const newRequestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(JSON.stringify(origRequestAggs[0].params, null, '')).not.to.equal(JSON.stringify(newRequestAggs[0].params, null, ''));

const newMapCollar = aggMock.vis.sessionState.mapCollar;
Expand All @@ -262,7 +240,7 @@ describe('Geohash Agg', () => {
it('should change geo_bounding_box filter aggregation and vis session state when map zoom level changes', () => {
zoomMap(-1);

const newRequestAggs = geohashAgg.getRequestAggs(aggMock);
const newRequestAggs = geoHashBucketAgg.getRequestAggs(aggMock);
expect(JSON.stringify(origRequestAggs[0].params, null, '')).not.to.equal(JSON.stringify(newRequestAggs[0].params, null, ''));

const newMapCollar = aggMock.vis.sessionState.mapCollar;
Expand Down
10 changes: 3 additions & 7 deletions src/ui/public/agg_types/__tests__/buckets/_histogram.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { AggTypesIndexProvider } from '../..';
import { aggTypes } from '../..';
import AggParamWriterProvider from '../agg_param_writer';

const histogram = aggTypes.byName.histogram;
describe('Histogram Agg', function () {

describe('ordered', function () {
let histogram;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
histogram = Private(AggTypesIndexProvider).byName.histogram;
}));

it('is ordered', function () {
expect(histogram.ordered).to.be.ok();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { OtherBucketHelperProvider } from '../../buckets/_terms_other_bucket_helper';
import { buildOtherBucketAgg, mergeOtherBucketAggResponse, updateMissingBucket } from '../../buckets/_terms_other_bucket_helper';
import { VisProvider } from '../../../vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

Expand Down Expand Up @@ -118,15 +118,13 @@ const nestedOtherResponse = {

describe('Terms Agg Other bucket helper', () => {

let otherBucketHelper;
let vis;

function init(aggConfig) {
ngMock.module('kibana');
ngMock.inject((Private) => {
const Vis = Private(VisProvider);
const indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
otherBucketHelper = Private(OtherBucketHelperProvider);

vis = new Vis(indexPattern, aggConfig);
});
Expand All @@ -136,13 +134,13 @@ describe('Terms Agg Other bucket helper', () => {

it('returns a function', () => {
init(visConfigSingleTerm);
const agg = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse);
const agg = buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse);
expect(agg).to.be.a('function');
});

it('correctly builds query with single terms agg', () => {
init(visConfigSingleTerm);
const agg = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse)();
const agg = buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse)();
const expectedResponse = {
aggs: undefined,
filters: {
Expand Down Expand Up @@ -171,7 +169,7 @@ describe('Terms Agg Other bucket helper', () => {

it('correctly builds query for nested terms agg', () => {
init(visConfigNestedTerm);
const agg = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[1], nestedTermResponse)();
const agg = buildOtherBucketAgg(vis.aggs, vis.aggs[1], nestedTermResponse)();
const expectedResponse = {
'other-filter': {
aggs: undefined,
Expand Down Expand Up @@ -220,19 +218,23 @@ describe('Terms Agg Other bucket helper', () => {
describe('mergeOtherBucketAggResponse', () => {
it('correctly merges other bucket with single terms agg', () => {
init(visConfigSingleTerm);
const otherAggConfig = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse)();
const mergedResponse = otherBucketHelper
.mergeOtherBucketAggResponse(vis.aggs, singleTermResponse, singleOtherResponse, vis.aggs[0], otherAggConfig);
const otherAggConfig = buildOtherBucketAgg(vis.aggs, vis.aggs[0], singleTermResponse)();
const mergedResponse = mergeOtherBucketAggResponse(
vis.aggs,
singleTermResponse,
singleOtherResponse,
vis.aggs[0],
otherAggConfig);

expect(mergedResponse.aggregations['1'].buckets[3].key).to.equal('Other');
expect(mergedResponse.aggregations['1'].buckets[3].filters.length).to.equal(2);
});

it('correctly merges other bucket with nested terms agg', () => {
init(visConfigNestedTerm);
const otherAggConfig = otherBucketHelper.buildOtherBucketAgg(vis.aggs, vis.aggs[1], nestedTermResponse)();
const mergedResponse = otherBucketHelper
.mergeOtherBucketAggResponse(vis.aggs, nestedTermResponse, nestedOtherResponse, vis.aggs[1], otherAggConfig);
const otherAggConfig = buildOtherBucketAgg(vis.aggs, vis.aggs[1], nestedTermResponse)();
const mergedResponse = mergeOtherBucketAggResponse(vis.aggs, nestedTermResponse,
nestedOtherResponse, vis.aggs[1], otherAggConfig);

expect(mergedResponse.aggregations['1'].buckets[1]['2'].buckets[3].key).to.equal('Other');
expect(mergedResponse.aggregations['1'].buckets[1]['2'].buckets[3].filters.length).to.equal(2);
Expand All @@ -243,12 +245,12 @@ describe('Terms Agg Other bucket helper', () => {
describe('updateMissingBucket', () => {
it('correctly updates missing bucket key', () => {
init(visConfigNestedTerm);
const updatedResponse = otherBucketHelper.updateMissingBucket(singleTermResponse, vis.aggs, vis.aggs[0]);
const updatedResponse = updateMissingBucket(singleTermResponse, vis.aggs, vis.aggs[0]);
expect(updatedResponse.aggregations['1'].buckets.find(bucket => bucket.key === 'Missing')).to.not.be('undefined');
});

it('correctly sets the bucket filter', () => {
const updatedResponse = otherBucketHelper.updateMissingBucket(singleTermResponse, vis.aggs, vis.aggs[0]);
const updatedResponse = updateMissingBucket(singleTermResponse, vis.aggs, vis.aggs[0]);
const missingBucket = updatedResponse.aggregations['1'].buckets.find(bucket => bucket.key === 'Missing');
expect(missingBucket.filters).to.not.be('undefined');
expect(missingBucket.filters[0]).to.eql({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import ngMock from 'ng_mock';
import expect from 'expect.js';
import { VisProvider } from '../../../../vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { AggTypesBucketsCreateFilterDateHistogramProvider } from '../../../buckets/create_filter/date_histogram';
import { AggTypesBucketsIntervalOptionsProvider } from '../../../buckets/_interval_options';
import { createFilterDateHistogram } from '../../../buckets/create_filter/date_histogram';
import { intervalOptions } from '../../../buckets/_interval_options';

describe('AggConfig Filters', function () {
describe('date_histogram', function () {
Expand All @@ -16,16 +16,13 @@ describe('AggConfig Filters', function () {
let filter;
let bucketKey;
let bucketStart;
let intervalOptions;

let init;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
const Vis = Private(VisProvider);
const indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
const createFilter = Private(AggTypesBucketsCreateFilterDateHistogramProvider);
intervalOptions = Private(AggTypesBucketsIntervalOptionsProvider);

init = function (interval, duration) {
interval = interval || 'auto';
Expand Down Expand Up @@ -54,7 +51,7 @@ describe('AggConfig Filters', function () {
});
agg.buckets.setInterval(interval);

filter = createFilter(agg, bucketKey);
filter = createFilterDateHistogram(agg, bucketKey);
};
}));

Expand Down
Loading

0 comments on commit 0370d68

Please sign in to comment.