From e07b2c2afd80ba14eb1cc83dd9b89d4df0ebcf63 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Thu, 14 Jun 2018 19:01:43 +0200 Subject: [PATCH 1/8] Add AggTypeFilters to filter out aggs in editor --- package.json | 1 + src/core_plugins/kibana/public/kibana.js | 1 + .../kibana/public/visualize/editor/editor.js | 1 - src/ui/public/agg_types/agg_type.d.ts | 20 +++++ .../agg_types/filter/agg_type_filters.test.ts | 75 +++++++++++++++++++ .../agg_types/filter/agg_type_filters.ts | 70 +++++++++++++++++ src/ui/public/agg_types/filter/index.ts | 20 +++++ src/ui/public/agg_types/index.d.ts | 20 +++++ .../public/filters/_prop_filter.d.ts} | 11 +-- src/ui/public/vis/agg_config.d.ts | 20 +++++ .../public/vis/editors/default/agg_params.js | 10 ++- .../vis/editors/default/agg_select.html | 1 - src/ui/public/vis/editors/default/default.js | 1 + .../editors/default/vis_type_agg_filter.ts | 29 +++++++ src/ui/public/vis/index.d.ts | 21 ++++++ src/ui/public/vis/vis.d.ts | 22 ++++++ src/ui/ui_exports/ui_export_types/index.js | 1 + .../ui_export_types/ui_app_extensions.js | 2 + yarn.lock | 4 + 19 files changed, 320 insertions(+), 10 deletions(-) create mode 100644 src/ui/public/agg_types/agg_type.d.ts create mode 100644 src/ui/public/agg_types/filter/agg_type_filters.test.ts create mode 100644 src/ui/public/agg_types/filter/agg_type_filters.ts create mode 100644 src/ui/public/agg_types/filter/index.ts create mode 100644 src/ui/public/agg_types/index.d.ts rename src/{core_plugins/kibana/public/visualize/editor/agg_filter.js => ui/public/filters/_prop_filter.d.ts} (80%) create mode 100644 src/ui/public/vis/agg_config.d.ts create mode 100644 src/ui/public/vis/editors/default/vis_type_agg_filter.ts create mode 100644 src/ui/public/vis/index.d.ts create mode 100644 src/ui/public/vis/vis.d.ts diff --git a/package.json b/package.json index de5153c278ca21..b4fa039586e819 100644 --- a/package.json +++ b/package.json @@ -231,6 +231,7 @@ "@types/execa": "^0.9.0", "@types/getopts": "^2.0.0", "@types/glob": "^5.0.35", + "@types/jest": "^22.2.3", "@types/listr": "^0.13.0", "@types/minimatch": "^2.0.29", "@types/react": "^16.3.14", diff --git a/src/core_plugins/kibana/public/kibana.js b/src/core_plugins/kibana/public/kibana.js index 11d4343b7b530f..e9fe111b4cf975 100644 --- a/src/core_plugins/kibana/public/kibana.js +++ b/src/core_plugins/kibana/public/kibana.js @@ -30,6 +30,7 @@ import 'uiExports/visTypes'; import 'uiExports/visResponseHandlers'; import 'uiExports/visRequestHandlers'; import 'uiExports/visEditorTypes'; +import 'uiExports/visualize'; import 'uiExports/savedObjectTypes'; import 'uiExports/spyModes'; import 'uiExports/fieldFormats'; diff --git a/src/core_plugins/kibana/public/visualize/editor/editor.js b/src/core_plugins/kibana/public/visualize/editor/editor.js index 4a0bfbb686b64f..2df064fd7df30d 100644 --- a/src/core_plugins/kibana/public/visualize/editor/editor.js +++ b/src/core_plugins/kibana/public/visualize/editor/editor.js @@ -20,7 +20,6 @@ import _ from 'lodash'; import '../saved_visualizations/saved_visualizations'; import 'ui/vis/editors/default/sidebar'; -import './agg_filter'; import 'ui/visualize'; import 'ui/collapsible_sidebar'; import 'ui/share'; diff --git a/src/ui/public/agg_types/agg_type.d.ts b/src/ui/public/agg_types/agg_type.d.ts new file mode 100644 index 00000000000000..5485221cb54310 --- /dev/null +++ b/src/ui/public/agg_types/agg_type.d.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export type AggType = any; diff --git a/src/ui/public/agg_types/filter/agg_type_filters.test.ts b/src/ui/public/agg_types/filter/agg_type_filters.test.ts new file mode 100644 index 00000000000000..78c9af41e5ed01 --- /dev/null +++ b/src/ui/public/agg_types/filter/agg_type_filters.test.ts @@ -0,0 +1,75 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { AggTypeFilters } from './agg_type_filters'; + +describe('AggTypeFilters', () => { + let registry: AggTypeFilters; + const vis = {}; + const aggConfig = {}; + + beforeEach(() => { + registry = new AggTypeFilters(); + }); + + it('should filter nothing without registered filters', async () => { + const aggTypes = [{ name: 'count' }, { name: 'sum' }]; + const observable = registry.filter$(aggTypes, vis, aggConfig); + const filtered = await observable.first().toPromise(); + expect(filtered).toEqual(aggTypes); + }); + + it('should emit a new filtered list when registering a new filter', async () => { + const aggTypes = [{ name: 'count' }, { name: 'sum' }]; + const observable = registry.filter$(aggTypes, vis, aggConfig); + const spy = jest.fn(); + observable.subscribe(spy); + expect(spy).toHaveBeenCalledTimes(1); + registry.register(() => true); + expect(spy).toHaveBeenCalledTimes(2); + }); + + it('should pass all aggTypes to the registered filter', async () => { + const aggTypes = [{ name: 'count' }, { name: 'sum' }]; + const filter = jest.fn(); + registry.register(filter); + await registry + .filter$(aggTypes, vis, aggConfig) + .first() + .toPromise(); + expect(filter).toHaveBeenCalledWith(aggTypes[0], vis, aggConfig); + expect(filter).toHaveBeenCalledWith(aggTypes[1], vis, aggConfig); + }); + + it('should allow registered filters to filter out aggTypes', async () => { + const aggTypes = [{ name: 'count' }, { name: 'sum' }, { name: 'avg' }]; + const observable = registry.filter$(aggTypes, vis, aggConfig); + let filtered = await observable.first().toPromise(); + expect(filtered).toEqual(aggTypes); + + registry.register(() => true); + registry.register(aggType => aggType.name !== 'count'); + filtered = await observable.first().toPromise(); + expect(filtered).toEqual([aggTypes[1], aggTypes[2]]); + + registry.register(aggType => aggType.name !== 'avg'); + filtered = await observable.first().toPromise(); + expect(filtered).toEqual([aggTypes[1]]); + }); +}); diff --git a/src/ui/public/agg_types/filter/agg_type_filters.ts b/src/ui/public/agg_types/filter/agg_type_filters.ts new file mode 100644 index 00000000000000..395d864a72dfe6 --- /dev/null +++ b/src/ui/public/agg_types/filter/agg_type_filters.ts @@ -0,0 +1,70 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { BehaviorSubject } from 'rxjs'; +import { AggType } from '..'; +import { AggConfig, Vis } from '../../vis'; + +type AggTypeFilter = ( + aggType: AggType, + vis: Vis, + aggConfig: AggConfig +) => boolean; + +/** + * A registry to store {@link AggTypeFilter} which are used to filter down + * available aggregations for a specific visualization and {@link AggConfig}. + */ +class AggTypeFilters { + private filters = new Set(); + private subject = new BehaviorSubject>(this.filters); + + /** + * Register a new {@link AggTypeFilter} with this registry. + * This will emit a new set of filtered aggTypes on every Observer returned + * by the {@link #filter$|filter method}. + * + * @param filter The filter to register. + */ + public register(filter: AggTypeFilter): void { + this.filters.add(filter); + this.subject.next(this.filters); + } + + /** + * Returns an Observable that will emit a filtered list of the passed {@link AggType|aggTypes}. + * A new filtered list will always be emitted when the {@link AggTypeFilter} + * registered with this registry will change. + * + * @param aggTypes A list of aggTypes that will be filtered down by this registry. + * @param vis The vis for which this list should be filtered down. + * @param aggConfig The aggConfig for which the returning list will be used. + * @return A filtered list of the passed aggTypes. + */ + public filter$(aggTypes: AggType[], vis: Vis, aggConfig: AggConfig) { + return this.subject.map(filters => { + return aggTypes.filter(aggType => + Array.from(filters).every(filter => filter(aggType, vis, aggConfig)) + ); + }); + } +} + +const aggTypeFilters = new AggTypeFilters(); + +export { aggTypeFilters, AggTypeFilters }; diff --git a/src/ui/public/agg_types/filter/index.ts b/src/ui/public/agg_types/filter/index.ts new file mode 100644 index 00000000000000..9582119b28b36a --- /dev/null +++ b/src/ui/public/agg_types/filter/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { aggTypeFilters } from './agg_type_filters'; diff --git a/src/ui/public/agg_types/index.d.ts b/src/ui/public/agg_types/index.d.ts new file mode 100644 index 00000000000000..81d52bb8e788bd --- /dev/null +++ b/src/ui/public/agg_types/index.d.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { AggType } from './agg_type'; diff --git a/src/core_plugins/kibana/public/visualize/editor/agg_filter.js b/src/ui/public/filters/_prop_filter.d.ts similarity index 80% rename from src/core_plugins/kibana/public/visualize/editor/agg_filter.js rename to src/ui/public/filters/_prop_filter.d.ts index 782a8fa7a154aa..284619b50fb606 100644 --- a/src/core_plugins/kibana/public/visualize/editor/agg_filter.js +++ b/src/ui/public/filters/_prop_filter.d.ts @@ -17,11 +17,8 @@ * under the License. */ -import { propFilter } from 'ui/filters/_prop_filter'; -import { uiModules } from 'ui/modules'; +type FilterFunc = (item: I) => boolean; -uiModules - .get('kibana') - .filter('aggFilter', function () { - return propFilter('name'); - }); +export const propFilter: ( + prop: string +) => (list: T[], filters: string[] | string | FilterFunc) => T[]; diff --git a/src/ui/public/vis/agg_config.d.ts b/src/ui/public/vis/agg_config.d.ts new file mode 100644 index 00000000000000..8ed9023ab24789 --- /dev/null +++ b/src/ui/public/vis/agg_config.d.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export type AggConfig = any; diff --git a/src/ui/public/vis/editors/default/agg_params.js b/src/ui/public/vis/editors/default/agg_params.js index 9a8660ae5be304..97f1423bcffcee 100644 --- a/src/ui/public/vis/editors/default/agg_params.js +++ b/src/ui/public/vis/editors/default/agg_params.js @@ -27,6 +27,7 @@ import { aggTypes } from '../../../agg_types'; import { uiModules } from '../../../modules'; import { documentationLinks } from '../../../documentation_links/documentation_links'; import aggParamsTemplate from './agg_params.html'; +import { aggTypeFilters } from '../../../agg_types/filter'; uiModules .get('app/visualize') @@ -40,7 +41,14 @@ uiModules $scope.$bind('agg', attr.agg); $scope.$bind('groupName', attr.groupName); - $scope.aggTypeOptions = aggTypes.byType[$scope.groupName]; + const aggTypeSubscription = aggTypeFilters + .filter$(aggTypes.byType[$scope.groupName], $scope.vis, $scope.agg) + .subscribe(aggTypes => $scope.aggTypeOptions = aggTypes); + + $scope.$on('$destroy', () => { + aggTypeSubscription.unsubscribe(); + }); + $scope.advancedToggled = false; // We set up this watch prior to adding the controls below, because when the controls are added, diff --git a/src/ui/public/vis/editors/default/agg_select.html b/src/ui/public/vis/editors/default/agg_select.html index 05910af4a62686..1a966dd31eb75b 100644 --- a/src/ui/public/vis/editors/default/agg_select.html +++ b/src/ui/public/vis/editors/default/agg_select.html @@ -25,7 +25,6 @@ { + return filterByName([aggType], aggConfig.schema.aggFilter).length === 1; +}); diff --git a/src/ui/public/vis/index.d.ts b/src/ui/public/vis/index.d.ts new file mode 100644 index 00000000000000..0ee214507a9f3e --- /dev/null +++ b/src/ui/public/vis/index.d.ts @@ -0,0 +1,21 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { AggConfig } from './agg_config'; +export { Vis, VisProvider } from './vis'; diff --git a/src/ui/public/vis/vis.d.ts b/src/ui/public/vis/vis.d.ts new file mode 100644 index 00000000000000..004795920ab41f --- /dev/null +++ b/src/ui/public/vis/vis.d.ts @@ -0,0 +1,22 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export type Vis = any; + +export type VisProvider = (...dependencies: any[]) => Vis; diff --git a/src/ui/ui_exports/ui_export_types/index.js b/src/ui/ui_exports/ui_export_types/index.js index 394292550d324c..84dab97697d926 100644 --- a/src/ui/ui_exports/ui_export_types/index.js +++ b/src/ui/ui_exports/ui_export_types/index.js @@ -51,6 +51,7 @@ export { home, visTypeEnhancers, aliases, + visualize } from './ui_app_extensions'; export { diff --git a/src/ui/ui_exports/ui_export_types/ui_app_extensions.js b/src/ui/ui_exports/ui_export_types/ui_app_extensions.js index 9a962a8881e56a..b4de729e293341 100644 --- a/src/ui/ui_exports/ui_export_types/ui_app_extensions.js +++ b/src/ui/ui_exports/ui_export_types/ui_app_extensions.js @@ -50,6 +50,8 @@ export const devTools = appExtension; export const docViews = appExtension; export const hacks = appExtension; export const home = appExtension; +// Add a visualize app extension that should be used for visualize specific stuff +export const visualize = appExtension; // aliases visTypeEnhancers to the visTypes group export const visTypeEnhancers = wrap(alias('visTypes'), appExtension); diff --git a/yarn.lock b/yarn.lock index 21d0b75c32a90c..39af83eed438bb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -275,6 +275,10 @@ dependencies: "@types/node" "*" +"@types/jest@^22.2.3": + version "22.2.3" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-22.2.3.tgz#0157c0316dc3722c43a7b71de3fdf3acbccef10d" + "@types/json-schema@*": version "6.0.1" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-6.0.1.tgz#a761975746f1c1b2579c62e3a4b5e88f986f7e2e" From 5e2962c8a09b0b4ba7c69b91e4c3218121cbc0f0 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Thu, 14 Jun 2018 19:13:34 +0200 Subject: [PATCH 2/8] Add documentation --- src/ui/public/vis/editors/default/vis_type_agg_filter.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ui/public/vis/editors/default/vis_type_agg_filter.ts b/src/ui/public/vis/editors/default/vis_type_agg_filter.ts index ab4dcb64abec3a..091796f7ef1ed7 100644 --- a/src/ui/public/vis/editors/default/vis_type_agg_filter.ts +++ b/src/ui/public/vis/editors/default/vis_type_agg_filter.ts @@ -24,6 +24,10 @@ import { propFilter } from '../../../filters/_prop_filter'; const filterByName = propFilter('name'); +/** + * This filter checks the defined aggFilter in the schemas of that visualization + * and limits available aggregations based on that. + */ aggTypeFilters.register((aggType: AggType, vis: Vis, aggConfig: AggConfig) => { return filterByName([aggType], aggConfig.schema.aggFilter).length === 1; }); From 19001da47d46c13b7fa96295e89f7f3740447671 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Fri, 15 Jun 2018 12:56:12 +0200 Subject: [PATCH 3/8] Implement CJ's feedback --- src/core_plugins/kibana/public/visualize/index.js | 1 - .../agg_types/filter/agg_type_filters.test.ts | 10 +++++----- src/ui/public/agg_types/filter/agg_type_filters.ts | 13 +++++++++---- .../vis/editors/default/vis_type_agg_filter.ts | 6 ++++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/core_plugins/kibana/public/visualize/index.js b/src/core_plugins/kibana/public/visualize/index.js index c7b57bcb75f5a2..255e4a2eaea5bf 100644 --- a/src/core_plugins/kibana/public/visualize/index.js +++ b/src/core_plugins/kibana/public/visualize/index.js @@ -20,7 +20,6 @@ import './styles/main.less'; import './editor/editor'; import './wizard/wizard'; -import './editor/agg_filter'; import 'ui/draggable/draggable_container'; import 'ui/draggable/draggable_item'; import 'ui/draggable/draggable_handle'; diff --git a/src/ui/public/agg_types/filter/agg_type_filters.test.ts b/src/ui/public/agg_types/filter/agg_type_filters.test.ts index 78c9af41e5ed01..c2e57cda8b216a 100644 --- a/src/ui/public/agg_types/filter/agg_type_filters.test.ts +++ b/src/ui/public/agg_types/filter/agg_type_filters.test.ts @@ -41,14 +41,14 @@ describe('AggTypeFilters', () => { const spy = jest.fn(); observable.subscribe(spy); expect(spy).toHaveBeenCalledTimes(1); - registry.register(() => true); + registry.addFilter(() => true); expect(spy).toHaveBeenCalledTimes(2); }); it('should pass all aggTypes to the registered filter', async () => { const aggTypes = [{ name: 'count' }, { name: 'sum' }]; const filter = jest.fn(); - registry.register(filter); + registry.addFilter(filter); await registry .filter$(aggTypes, vis, aggConfig) .first() @@ -63,12 +63,12 @@ describe('AggTypeFilters', () => { let filtered = await observable.first().toPromise(); expect(filtered).toEqual(aggTypes); - registry.register(() => true); - registry.register(aggType => aggType.name !== 'count'); + registry.addFilter(() => true); + registry.addFilter(aggType => aggType.name !== 'count'); filtered = await observable.first().toPromise(); expect(filtered).toEqual([aggTypes[1], aggTypes[2]]); - registry.register(aggType => aggType.name !== 'avg'); + registry.addFilter(aggType => aggType.name !== 'avg'); filtered = await observable.first().toPromise(); expect(filtered).toEqual([aggTypes[1]]); }); diff --git a/src/ui/public/agg_types/filter/agg_type_filters.ts b/src/ui/public/agg_types/filter/agg_type_filters.ts index 395d864a72dfe6..fe3bbf9b4ab60c 100644 --- a/src/ui/public/agg_types/filter/agg_type_filters.ts +++ b/src/ui/public/agg_types/filter/agg_type_filters.ts @@ -41,7 +41,7 @@ class AggTypeFilters { * * @param filter The filter to register. */ - public register(filter: AggTypeFilter): void { + public addFilter(filter: AggTypeFilter): void { this.filters.add(filter); this.subject.next(this.filters); } @@ -58,9 +58,14 @@ class AggTypeFilters { */ public filter$(aggTypes: AggType[], vis: Vis, aggConfig: AggConfig) { return this.subject.map(filters => { - return aggTypes.filter(aggType => - Array.from(filters).every(filter => filter(aggType, vis, aggConfig)) - ); + const allFilters = Array.from(filters); + const allowedAggTypes = aggTypes.filter(aggType => { + const isAggTypeAllowed = allFilters.every(filter => + filter(aggType, vis, aggConfig) + ); + return isAggTypeAllowed; + }); + return allowedAggTypes; }); } } diff --git a/src/ui/public/vis/editors/default/vis_type_agg_filter.ts b/src/ui/public/vis/editors/default/vis_type_agg_filter.ts index 091796f7ef1ed7..6b01a5830e24b6 100644 --- a/src/ui/public/vis/editors/default/vis_type_agg_filter.ts +++ b/src/ui/public/vis/editors/default/vis_type_agg_filter.ts @@ -28,6 +28,8 @@ const filterByName = propFilter('name'); * This filter checks the defined aggFilter in the schemas of that visualization * and limits available aggregations based on that. */ -aggTypeFilters.register((aggType: AggType, vis: Vis, aggConfig: AggConfig) => { - return filterByName([aggType], aggConfig.schema.aggFilter).length === 1; +aggTypeFilters.addFilter((aggType: AggType, vis: Vis, aggConfig: AggConfig) => { + const doesSchemaAllowAggType = + filterByName([aggType], aggConfig.schema.aggFilter).length !== 0; + return doesSchemaAllowAggType; }); From e0fd06d524ae8c032afd195f8d997c75e678176e Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Fri, 15 Jun 2018 17:31:16 +0200 Subject: [PATCH 4/8] Add link to missing vis variable --- .../agg_types/__tests__/buckets/date_histogram/_editor.js | 3 ++- src/ui/public/agg_types/controls/order_agg.html | 1 + src/ui/public/agg_types/controls/sub_agg.html | 1 + src/ui/public/agg_types/controls/sub_metric.html | 1 + src/ui/public/agg_types/filter/agg_type_filters.ts | 4 ++-- src/ui/public/vis/editors/default/__tests__/agg_params.js | 3 ++- src/ui/public/vis/editors/default/agg.html | 1 + src/ui/public/vis/editors/default/agg_params.js | 1 + 8 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ui/public/agg_types/__tests__/buckets/date_histogram/_editor.js b/src/ui/public/agg_types/__tests__/buckets/date_histogram/_editor.js index 2fd398a879cde2..f6ec04589485db 100644 --- a/src/ui/public/agg_types/__tests__/buckets/date_histogram/_editor.js +++ b/src/ui/public/agg_types/__tests__/buckets/date_histogram/_editor.js @@ -58,11 +58,12 @@ describe('editor', function () { ] }); - const $el = $(''); + const $el = $(''); const $parentScope = $injector.get('$rootScope').$new(); agg = $parentScope.agg = vis.aggs.bySchemaName.segment[0]; $parentScope.groupName = 'buckets'; + $parentScope.vis = vis; $compile($el)($parentScope); $scope = $el.scope(); diff --git a/src/ui/public/agg_types/controls/order_agg.html b/src/ui/public/agg_types/controls/order_agg.html index 8066dc91da176b..4f2e071100dfd3 100644 --- a/src/ui/public/agg_types/controls/order_agg.html +++ b/src/ui/public/agg_types/controls/order_agg.html @@ -24,6 +24,7 @@
diff --git a/src/ui/public/agg_types/controls/sub_agg.html b/src/ui/public/agg_types/controls/sub_agg.html index 5b99d2de4c7522..1e1be22028d396 100644 --- a/src/ui/public/agg_types/controls/sub_agg.html +++ b/src/ui/public/agg_types/controls/sub_agg.html @@ -25,6 +25,7 @@
diff --git a/src/ui/public/agg_types/controls/sub_metric.html b/src/ui/public/agg_types/controls/sub_metric.html index 88011451676be0..343ca331a96cb0 100644 --- a/src/ui/public/agg_types/controls/sub_metric.html +++ b/src/ui/public/agg_types/controls/sub_metric.html @@ -5,6 +5,7 @@ diff --git a/src/ui/public/agg_types/filter/agg_type_filters.ts b/src/ui/public/agg_types/filter/agg_type_filters.ts index fe3bbf9b4ab60c..6b859e88918821 100644 --- a/src/ui/public/agg_types/filter/agg_type_filters.ts +++ b/src/ui/public/agg_types/filter/agg_type_filters.ts @@ -51,10 +51,10 @@ class AggTypeFilters { * A new filtered list will always be emitted when the {@link AggTypeFilter} * registered with this registry will change. * - * @param aggTypes A list of aggTypes that will be filtered down by this registry. + * @param aggTypes A list of aggTypes that will be filtered down by this registry. * @param vis The vis for which this list should be filtered down. * @param aggConfig The aggConfig for which the returning list will be used. - * @return A filtered list of the passed aggTypes. + * @return A filtered list of the passed aggTypes. */ public filter$(aggTypes: AggType[], vis: Vis, aggConfig: AggConfig) { return this.subject.map(filters => { diff --git a/src/ui/public/vis/editors/default/__tests__/agg_params.js b/src/ui/public/vis/editors/default/__tests__/agg_params.js index 3497db7cec6bea..502cfa87c12bd7 100644 --- a/src/ui/public/vis/editors/default/__tests__/agg_params.js +++ b/src/ui/public/vis/editors/default/__tests__/agg_params.js @@ -77,10 +77,11 @@ describe('Vis-Editor-Agg-Params plugin directive', function () { }); $parentScope.agg = new AggConfig(vis, state); + $parentScope.vis = vis; // make the element $elem = angular.element( - `` + `` ); // compile the html diff --git a/src/ui/public/vis/editors/default/agg.html b/src/ui/public/vis/editors/default/agg.html index 0d2970076be47b..b49e875e8413ef 100644 --- a/src/ui/public/vis/editors/default/agg.html +++ b/src/ui/public/vis/editors/default/agg.html @@ -93,6 +93,7 @@ agg="agg" group-name="groupName" ng-show="editorOpen" + vis="vis" class="vis-editor-agg-editor"> diff --git a/src/ui/public/vis/editors/default/agg_params.js b/src/ui/public/vis/editors/default/agg_params.js index 97f1423bcffcee..a357d4b771c288 100644 --- a/src/ui/public/vis/editors/default/agg_params.js +++ b/src/ui/public/vis/editors/default/agg_params.js @@ -40,6 +40,7 @@ uiModules link: function ($scope, $el, attr) { $scope.$bind('agg', attr.agg); $scope.$bind('groupName', attr.groupName); + $scope.$bind('vis', attr.vis); const aggTypeSubscription = aggTypeFilters .filter$(aggTypes.byType[$scope.groupName], $scope.vis, $scope.agg) From cad0534b8ecccb9b847ca8ec7d28b8c1801e2d43 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Mon, 18 Jun 2018 20:13:39 +0200 Subject: [PATCH 5/8] Fix for RxJS 6 --- .../agg_types/filter/agg_type_filters.ts | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/ui/public/agg_types/filter/agg_type_filters.ts b/src/ui/public/agg_types/filter/agg_type_filters.ts index 6b859e88918821..69ec6af6f00011 100644 --- a/src/ui/public/agg_types/filter/agg_type_filters.ts +++ b/src/ui/public/agg_types/filter/agg_type_filters.ts @@ -17,6 +17,7 @@ * under the License. */ import { BehaviorSubject } from 'rxjs'; +import { map } from 'rxjs/operators'; import { AggType } from '..'; import { AggConfig, Vis } from '../../vis'; @@ -57,16 +58,18 @@ class AggTypeFilters { * @return A filtered list of the passed aggTypes. */ public filter$(aggTypes: AggType[], vis: Vis, aggConfig: AggConfig) { - return this.subject.map(filters => { - const allFilters = Array.from(filters); - const allowedAggTypes = aggTypes.filter(aggType => { - const isAggTypeAllowed = allFilters.every(filter => - filter(aggType, vis, aggConfig) - ); - return isAggTypeAllowed; - }); - return allowedAggTypes; - }); + return this.subject.pipe( + map(filters => { + const allFilters = Array.from(filters); + const allowedAggTypes = aggTypes.filter(aggType => { + const isAggTypeAllowed = allFilters.every(filter => + filter(aggType, vis, aggConfig) + ); + return isAggTypeAllowed; + }); + return allowedAggTypes; + }) + ); } } From fa8bc0a5abbc37310c391dd753d26766d6b0d56c Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Mon, 18 Jun 2018 20:17:09 +0200 Subject: [PATCH 6/8] Add babel-core types and fix tests --- package.json | 1 + .../agg_types/filter/agg_type_filters.test.ts | 11 +++--- yarn.lock | 39 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b4fa039586e819..eeecb42e861cec 100644 --- a/package.json +++ b/package.json @@ -227,6 +227,7 @@ "@kbn/eslint-plugin-license-header": "link:packages/kbn-eslint-plugin-license-header", "@kbn/plugin-generator": "link:packages/kbn-plugin-generator", "@kbn/test": "link:packages/kbn-test", + "@types/babel-core": "^6.25.5", "@types/eslint": "^4.16.2", "@types/execa": "^0.9.0", "@types/getopts": "^2.0.0", diff --git a/src/ui/public/agg_types/filter/agg_type_filters.test.ts b/src/ui/public/agg_types/filter/agg_type_filters.test.ts index c2e57cda8b216a..6cad4d14229a15 100644 --- a/src/ui/public/agg_types/filter/agg_type_filters.test.ts +++ b/src/ui/public/agg_types/filter/agg_type_filters.test.ts @@ -17,6 +17,7 @@ * under the License. */ +import { first } from 'rxjs/operators'; import { AggTypeFilters } from './agg_type_filters'; describe('AggTypeFilters', () => { @@ -31,7 +32,7 @@ describe('AggTypeFilters', () => { it('should filter nothing without registered filters', async () => { const aggTypes = [{ name: 'count' }, { name: 'sum' }]; const observable = registry.filter$(aggTypes, vis, aggConfig); - const filtered = await observable.first().toPromise(); + const filtered = await observable.pipe(first()).toPromise(); expect(filtered).toEqual(aggTypes); }); @@ -51,7 +52,7 @@ describe('AggTypeFilters', () => { registry.addFilter(filter); await registry .filter$(aggTypes, vis, aggConfig) - .first() + .pipe(first()) .toPromise(); expect(filter).toHaveBeenCalledWith(aggTypes[0], vis, aggConfig); expect(filter).toHaveBeenCalledWith(aggTypes[1], vis, aggConfig); @@ -60,16 +61,16 @@ describe('AggTypeFilters', () => { it('should allow registered filters to filter out aggTypes', async () => { const aggTypes = [{ name: 'count' }, { name: 'sum' }, { name: 'avg' }]; const observable = registry.filter$(aggTypes, vis, aggConfig); - let filtered = await observable.first().toPromise(); + let filtered = await observable.pipe(first()).toPromise(); expect(filtered).toEqual(aggTypes); registry.addFilter(() => true); registry.addFilter(aggType => aggType.name !== 'count'); - filtered = await observable.first().toPromise(); + filtered = await observable.pipe(first()).toPromise(); expect(filtered).toEqual([aggTypes[1], aggTypes[2]]); registry.addFilter(aggType => aggType.name !== 'avg'); - filtered = await observable.first().toPromise(); + filtered = await observable.pipe(first()).toPromise(); expect(filtered).toEqual([aggTypes[1]]); }); }); diff --git a/yarn.lock b/yarn.lock index 39af83eed438bb..7f8ac9c96b6e54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -220,6 +220,45 @@ url-join "^4.0.0" ws "^4.1.0" +"@types/babel-core@^6.25.5": + version "6.25.5" + resolved "https://registry.yarnpkg.com/@types/babel-core/-/babel-core-6.25.5.tgz#7598b1287c2cb5a8e9150d60e4d4a8f2dbe29982" + dependencies: + "@types/babel-generator" "*" + "@types/babel-template" "*" + "@types/babel-traverse" "*" + "@types/babel-types" "*" + "@types/babylon" "*" + +"@types/babel-generator@*": + version "6.25.2" + resolved "https://registry.yarnpkg.com/@types/babel-generator/-/babel-generator-6.25.2.tgz#fa13653ec2d34a4037be9c34dec32ae75bea04cc" + dependencies: + "@types/babel-types" "*" + +"@types/babel-template@*": + version "6.25.1" + resolved "https://registry.yarnpkg.com/@types/babel-template/-/babel-template-6.25.1.tgz#03e23a893c16bab2ec00200ab51feccf488cae78" + dependencies: + "@types/babel-types" "*" + "@types/babylon" "*" + +"@types/babel-traverse@*": + version "6.25.4" + resolved "https://registry.yarnpkg.com/@types/babel-traverse/-/babel-traverse-6.25.4.tgz#269af6a25c80419b635c8fa29ae42b0d5ce2418c" + dependencies: + "@types/babel-types" "*" + +"@types/babel-types@*": + version "7.0.3" + resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-7.0.3.tgz#9dc5316090ad99cd2679051ab21a5676c90a2bcc" + +"@types/babylon@*": + version "6.16.3" + resolved "https://registry.yarnpkg.com/@types/babylon/-/babylon-6.16.3.tgz#c2937813a89fcb5e79a00062fc4a8b143e7237bb" + dependencies: + "@types/babel-types" "*" + "@types/delay@^2.0.1": version "2.0.1" resolved "https://registry.yarnpkg.com/@types/delay/-/delay-2.0.1.tgz#61bcf318a74b61e79d1658fbf054f984c90ef901" From 6f00c13fcbb26baff27f7f24d65376e2de777d17 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Wed, 20 Jun 2018 14:11:21 +0200 Subject: [PATCH 7/8] Pass index pattern instead of vis --- .../buckets/date_histogram/_editor.js | 2 +- .../public/agg_types/controls/order_agg.html | 2 +- src/ui/public/agg_types/controls/sub_agg.html | 2 +- .../public/agg_types/controls/sub_metric.html | 2 +- .../agg_types/filter/agg_type_filters.test.ts | 14 ++++++------- .../agg_types/filter/agg_type_filters.ts | 13 ++++++++---- .../public/index_patterns/_index_pattern.d.ts | 20 +++++++++++++++++++ src/ui/public/index_patterns/index.d.ts | 20 +++++++++++++++++++ .../editors/default/__tests__/agg_params.js | 2 +- src/ui/public/vis/editors/default/agg.html | 2 +- .../public/vis/editors/default/agg_params.js | 4 ++-- .../editors/default/vis_type_agg_filter.ts | 15 ++++++++------ 12 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 src/ui/public/index_patterns/_index_pattern.d.ts create mode 100644 src/ui/public/index_patterns/index.d.ts diff --git a/src/ui/public/agg_types/__tests__/buckets/date_histogram/_editor.js b/src/ui/public/agg_types/__tests__/buckets/date_histogram/_editor.js index f6ec04589485db..40202efa568b29 100644 --- a/src/ui/public/agg_types/__tests__/buckets/date_histogram/_editor.js +++ b/src/ui/public/agg_types/__tests__/buckets/date_histogram/_editor.js @@ -58,7 +58,7 @@ describe('editor', function () { ] }); - const $el = $(''); + const $el = $(''); const $parentScope = $injector.get('$rootScope').$new(); agg = $parentScope.agg = vis.aggs.bySchemaName.segment[0]; diff --git a/src/ui/public/agg_types/controls/order_agg.html b/src/ui/public/agg_types/controls/order_agg.html index 4f2e071100dfd3..61f2cec29a490a 100644 --- a/src/ui/public/agg_types/controls/order_agg.html +++ b/src/ui/public/agg_types/controls/order_agg.html @@ -24,7 +24,7 @@
diff --git a/src/ui/public/agg_types/controls/sub_agg.html b/src/ui/public/agg_types/controls/sub_agg.html index 1e1be22028d396..76936a58619605 100644 --- a/src/ui/public/agg_types/controls/sub_agg.html +++ b/src/ui/public/agg_types/controls/sub_agg.html @@ -25,7 +25,7 @@
diff --git a/src/ui/public/agg_types/controls/sub_metric.html b/src/ui/public/agg_types/controls/sub_metric.html index 343ca331a96cb0..d6805e7560b835 100644 --- a/src/ui/public/agg_types/controls/sub_metric.html +++ b/src/ui/public/agg_types/controls/sub_metric.html @@ -5,7 +5,7 @@ diff --git a/src/ui/public/agg_types/filter/agg_type_filters.test.ts b/src/ui/public/agg_types/filter/agg_type_filters.test.ts index 6cad4d14229a15..915f688e7acaf9 100644 --- a/src/ui/public/agg_types/filter/agg_type_filters.test.ts +++ b/src/ui/public/agg_types/filter/agg_type_filters.test.ts @@ -22,7 +22,7 @@ import { AggTypeFilters } from './agg_type_filters'; describe('AggTypeFilters', () => { let registry: AggTypeFilters; - const vis = {}; + const indexPattern = {}; const aggConfig = {}; beforeEach(() => { @@ -31,14 +31,14 @@ describe('AggTypeFilters', () => { it('should filter nothing without registered filters', async () => { const aggTypes = [{ name: 'count' }, { name: 'sum' }]; - const observable = registry.filter$(aggTypes, vis, aggConfig); + const observable = registry.filter$(aggTypes, indexPattern, aggConfig); const filtered = await observable.pipe(first()).toPromise(); expect(filtered).toEqual(aggTypes); }); it('should emit a new filtered list when registering a new filter', async () => { const aggTypes = [{ name: 'count' }, { name: 'sum' }]; - const observable = registry.filter$(aggTypes, vis, aggConfig); + const observable = registry.filter$(aggTypes, indexPattern, aggConfig); const spy = jest.fn(); observable.subscribe(spy); expect(spy).toHaveBeenCalledTimes(1); @@ -51,16 +51,16 @@ describe('AggTypeFilters', () => { const filter = jest.fn(); registry.addFilter(filter); await registry - .filter$(aggTypes, vis, aggConfig) + .filter$(aggTypes, indexPattern, aggConfig) .pipe(first()) .toPromise(); - expect(filter).toHaveBeenCalledWith(aggTypes[0], vis, aggConfig); - expect(filter).toHaveBeenCalledWith(aggTypes[1], vis, aggConfig); + expect(filter).toHaveBeenCalledWith(aggTypes[0], indexPattern, aggConfig); + expect(filter).toHaveBeenCalledWith(aggTypes[1], indexPattern, aggConfig); }); it('should allow registered filters to filter out aggTypes', async () => { const aggTypes = [{ name: 'count' }, { name: 'sum' }, { name: 'avg' }]; - const observable = registry.filter$(aggTypes, vis, aggConfig); + const observable = registry.filter$(aggTypes, indexPattern, aggConfig); let filtered = await observable.pipe(first()).toPromise(); expect(filtered).toEqual(aggTypes); diff --git a/src/ui/public/agg_types/filter/agg_type_filters.ts b/src/ui/public/agg_types/filter/agg_type_filters.ts index 69ec6af6f00011..acd530ece3ca9a 100644 --- a/src/ui/public/agg_types/filter/agg_type_filters.ts +++ b/src/ui/public/agg_types/filter/agg_type_filters.ts @@ -19,11 +19,12 @@ import { BehaviorSubject } from 'rxjs'; import { map } from 'rxjs/operators'; import { AggType } from '..'; -import { AggConfig, Vis } from '../../vis'; +import { IndexPattern } from '../../index_patterns'; +import { AggConfig } from '../../vis'; type AggTypeFilter = ( aggType: AggType, - vis: Vis, + indexPattern: IndexPattern, aggConfig: AggConfig ) => boolean; @@ -57,13 +58,17 @@ class AggTypeFilters { * @param aggConfig The aggConfig for which the returning list will be used. * @return A filtered list of the passed aggTypes. */ - public filter$(aggTypes: AggType[], vis: Vis, aggConfig: AggConfig) { + public filter$( + aggTypes: AggType[], + indexPattern: IndexPattern, + aggConfig: AggConfig + ) { return this.subject.pipe( map(filters => { const allFilters = Array.from(filters); const allowedAggTypes = aggTypes.filter(aggType => { const isAggTypeAllowed = allFilters.every(filter => - filter(aggType, vis, aggConfig) + filter(aggType, indexPattern, aggConfig) ); return isAggTypeAllowed; }); diff --git a/src/ui/public/index_patterns/_index_pattern.d.ts b/src/ui/public/index_patterns/_index_pattern.d.ts new file mode 100644 index 00000000000000..d31b546a6a97a3 --- /dev/null +++ b/src/ui/public/index_patterns/_index_pattern.d.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export type IndexPattern = any; diff --git a/src/ui/public/index_patterns/index.d.ts b/src/ui/public/index_patterns/index.d.ts new file mode 100644 index 00000000000000..44bcd163d17470 --- /dev/null +++ b/src/ui/public/index_patterns/index.d.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { IndexPattern } from './_index_pattern'; diff --git a/src/ui/public/vis/editors/default/__tests__/agg_params.js b/src/ui/public/vis/editors/default/__tests__/agg_params.js index 502cfa87c12bd7..70abf6d676f736 100644 --- a/src/ui/public/vis/editors/default/__tests__/agg_params.js +++ b/src/ui/public/vis/editors/default/__tests__/agg_params.js @@ -81,7 +81,7 @@ describe('Vis-Editor-Agg-Params plugin directive', function () { // make the element $elem = angular.element( - `` + `` ); // compile the html diff --git a/src/ui/public/vis/editors/default/agg.html b/src/ui/public/vis/editors/default/agg.html index b49e875e8413ef..9241473dc07da0 100644 --- a/src/ui/public/vis/editors/default/agg.html +++ b/src/ui/public/vis/editors/default/agg.html @@ -93,7 +93,7 @@ agg="agg" group-name="groupName" ng-show="editorOpen" - vis="vis" + index-pattern="vis.indexPattern" class="vis-editor-agg-editor"> diff --git a/src/ui/public/vis/editors/default/agg_params.js b/src/ui/public/vis/editors/default/agg_params.js index a357d4b771c288..cf4d7b1f7d4991 100644 --- a/src/ui/public/vis/editors/default/agg_params.js +++ b/src/ui/public/vis/editors/default/agg_params.js @@ -40,10 +40,10 @@ uiModules link: function ($scope, $el, attr) { $scope.$bind('agg', attr.agg); $scope.$bind('groupName', attr.groupName); - $scope.$bind('vis', attr.vis); + $scope.$bind('indexPattern', attr.indexPattern); const aggTypeSubscription = aggTypeFilters - .filter$(aggTypes.byType[$scope.groupName], $scope.vis, $scope.agg) + .filter$(aggTypes.byType[$scope.groupName], $scope.indexPattern, $scope.agg) .subscribe(aggTypes => $scope.aggTypeOptions = aggTypes); $scope.$on('$destroy', () => { diff --git a/src/ui/public/vis/editors/default/vis_type_agg_filter.ts b/src/ui/public/vis/editors/default/vis_type_agg_filter.ts index 6b01a5830e24b6..c0369a90eeb5fc 100644 --- a/src/ui/public/vis/editors/default/vis_type_agg_filter.ts +++ b/src/ui/public/vis/editors/default/vis_type_agg_filter.ts @@ -18,7 +18,8 @@ */ import { AggType } from '../../../agg_types'; import { aggTypeFilters } from '../../../agg_types/filter'; -import { AggConfig, Vis } from '../../../vis'; +import { IndexPattern } from '../../../index_patterns'; +import { AggConfig } from '../../../vis'; import { propFilter } from '../../../filters/_prop_filter'; @@ -28,8 +29,10 @@ const filterByName = propFilter('name'); * This filter checks the defined aggFilter in the schemas of that visualization * and limits available aggregations based on that. */ -aggTypeFilters.addFilter((aggType: AggType, vis: Vis, aggConfig: AggConfig) => { - const doesSchemaAllowAggType = - filterByName([aggType], aggConfig.schema.aggFilter).length !== 0; - return doesSchemaAllowAggType; -}); +aggTypeFilters.addFilter( + (aggType: AggType, indexPatterns: IndexPattern, aggConfig: AggConfig) => { + const doesSchemaAllowAggType = + filterByName([aggType], aggConfig.schema.aggFilter).length !== 0; + return doesSchemaAllowAggType; + } +); From bf66cbf05f0a30111d052ac673724f9e4823ba79 Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Mon, 25 Jun 2018 09:23:58 +0200 Subject: [PATCH 8/8] Fix documentation --- src/ui/public/agg_types/filter/agg_type_filters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/public/agg_types/filter/agg_type_filters.ts b/src/ui/public/agg_types/filter/agg_type_filters.ts index acd530ece3ca9a..8840af54e8cd39 100644 --- a/src/ui/public/agg_types/filter/agg_type_filters.ts +++ b/src/ui/public/agg_types/filter/agg_type_filters.ts @@ -54,7 +54,7 @@ class AggTypeFilters { * registered with this registry will change. * * @param aggTypes A list of aggTypes that will be filtered down by this registry. - * @param vis The vis for which this list should be filtered down. + * @param indexPattern The indexPattern for which this list should be filtered down. * @param aggConfig The aggConfig for which the returning list will be used. * @return A filtered list of the passed aggTypes. */