Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing the way aggconfig field filter works #22756

Merged
merged 4 commits into from
Sep 11, 2018

Conversation

ppisljar
Copy link
Member

@ppisljar ppisljar commented Sep 6, 2018

for #21827 we need to change the way we filter which fields aggregation supports.

currently the top hit aggregation would show all the fields on table or metric visualization and only number fields on other visualizations.

the filtering should not happen on aggconfigs level, as as far as aggregations are concerned top_hit can
work with every field type. We need to have additional level of filtering on the editor level however.

qa: nothing should change, top_hits should still show all fields with table or metric visualization and only number fields otherwise, just implementation is different.

Dev Docs

AggConfig field param

Every aggregation (AggConfig) with field parameter type needs to set the type to field now (as before setting the name to field was sufficient.)

We don't recommend writing your own aggregations. We don't consider this to be a public API, and it's very likely this will change in the future. Since we know a couple of plugins use this nevertheless, we are announcing this change here.

@@ -54,8 +54,7 @@ function AggParams(params) {
AggParams.Super.call(this, {
index: ['name'],
initialSet: params.map(function (config) {
const type = config.name === 'field' ? config.name : config.type;
const Class = paramTypeMap[type] || paramTypeMap._default;
const Class = paramTypeMap[config.type] || paramTypeMap._default;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting param type is now obligatory (before we defaulted to field type if name was field)


const isNumber = function (type) {
return type === 'number';
};

aggTypeFieldFilters.addFilter(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

top_hit now adds a filter for the fields which will be used by editor

/**
* Get the options for this field from the indexPattern
*/
FieldParamType.prototype.getFieldOptions = function (aggConfig) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method was renamed to getAvailableFields

*/
FieldParamType.prototype.getAvailableFields = function (fields) {

return new IndexedArray({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it filters all the fields down to the fields supported by this aggregation

indexPattern: IndexPattern,
aggConfig: AggConfig
) {
public filter(fields: any[], fieldParamType: FieldParamType, aggConfig: AggConfig, vis: Vis) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this filters are executed by editor now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(so we can have access to vis object)

@@ -19,7 +19,7 @@

import 'angular-ui-select';
import { uiModules } from '../modules';
import { getFieldOptions } from './lib/filter_editor_utils';
import { getFilterableFields } from './lib/filter_editor_utils';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was renamed as the old name was used for multiple functions, where none of them got you the field options :)

@ppisljar ppisljar added review Feature:Visualizations Generic visualization features (in case no more specific feature label is available) v6.5.0 labels Sep 6, 2018
@markov00 markov00 added the release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. label Sep 6, 2018
@markov00
Copy link
Member

markov00 commented Sep 6, 2018

@ppisljar Please check this: https://l7xor5om2l.codesandbox.io/ to conform the dev docs to the "standard"

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM. Added some minor questions.

if (aggConfig.type.name !== 'top_hit' || vis.type.name === 'table' || vis.type.name === 'metric') {
return true;
}
return field.type === 'number';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: because we have a isNumber function above, we can use it :)

src/ui/public/agg_types/metrics/top_hit.js Show resolved Hide resolved
}

return filterByType([field], filterFieldTypes).length !== 0;
}), ['type', 'name']),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we first filter to an object and than sort by? it will be a bit more readable so you dont have to look 10 rows below to understand what is the sorting by params

src/ui/public/agg_types/metrics/top_hit.js Show resolved Hide resolved
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@ppisljar
Copy link
Member Author

ppisljar commented Sep 7, 2018

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@timroes
Copy link
Contributor

timroes commented Sep 9, 2018

@jen-huang could you please check that these changes will still work for roll-up support. We needed to change the existing implementation a bit for the pipeline refactoring.

@ppisljar ppisljar merged commit 6246c58 into elastic:master Sep 11, 2018
@elasticmachine
Copy link
Contributor

💔 Build Failed

@markov00 markov00 mentioned this pull request May 29, 2019
@markov00 markov00 mentioned this pull request Jun 7, 2019
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Visualizations Generic visualization features (in case no more specific feature label is available) release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. review v6.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants