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

Add AggTypeFieldFilters to filter out fields in vis editor #20539

Merged
merged 3 commits into from
Jul 10, 2018

Conversation

jen-huang
Copy link
Contributor

@jen-huang jen-huang commented Jul 7, 2018

Similar to #19913, this adds an additional AggTypeFieldFilters registry to filter out fields for an aggregation type.

This is need to support rollups (#20004). Rollups not only limits the agg type users can query, but also limits fields for a particular agg type.

The current filtering performed by FieldParamType.prototype.getFieldOptions() has been converted to be a registered filter.

@jen-huang jen-huang added Feature:Visualizations Generic visualization features (in case no more specific feature label is available) v7.0.0 v6.4.0 labels Jul 7, 2018
@cjcenizal cjcenizal mentioned this pull request Jul 7, 2018
52 tasks
@elasticmachine
Copy link
Contributor

💔 Build Failed

@timroes timroes requested a review from ppisljar July 7, 2018 12:23
@@ -0,0 +1,20 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should be named .d.ts not .d.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the .d.ts version already existed. not sure how the compiled version got generated and committed 😳anyway - removed 🙂

const filterByType = propFilter('type');

/**
* This filter checks the defined aggFilter in the schemas of that visualization
Copy link
Contributor

Choose a reason for hiding this comment

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

This documentation doesn't look quiet right :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!


if (fieldParamType.filterFieldTypes) {
let filters = fieldParamType.filterFieldTypes;
if (_.isFunction(fieldParamType.filterFieldTypes)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we use lodash here we need to import it. I would also suggest that we import it named import { isFunction } from 'lodash'; due to better tree shaking in the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

import { AggConfig } from '../../../vis';

type AggTypeFieldFilter = (
fields: any[],
Copy link
Contributor

Choose a reason for hiding this comment

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

This signature is wrong. It should be field: any. TypeScript don't catch this error, since we use any in this place, and any[] is always assignable to any anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!


return new IndexedArray({
index: ['name'],
group: ['type'],
initialSet: fields
initialSet: _.sortBy(fields, ['type', 'name']),
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that's not introduced by you, but since that's the only line using lodash in that file, maybe switch over to named import: import { sortBy } from 'lodash';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

I love these tests! I had one small suggestion. I'd like to do another pass once the CI passes and Tim's suggestions are addressed.

return false;
}

if (fieldParamType.filterFieldTypes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use destructuring here to reduce repetition, and use an early exit so that the bulk of the work is done at the end of the function? We could also use a ternary to make the binary assignment of filters clearer.

    const { filterFieldTypes } = fieldParamType;
    
    if (!filterFieldTypes) {
      return true;
    }

    let filters = _.isFunction(filterFieldTypes)
      ? filterFieldTypes.bind(this, aggConfig.vis)
      : filterFieldTypes;

    return filterByType([field], filters).length !== 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

restructured this function with this feedback 🙂


type AggTypeFieldFilter = (
fields: any[],
aggType: AggType,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not pass in aggType directly to the filters. aggConfig.type will always retrieve the type and we have no ambitions to remove that, since aggConfig is pretty much just one specifically configered aggregation that always will have a type. So I think we should rather reduce this to just pass in aggConfig here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed references to aggType

Copy link
Contributor

@cjcenizal cjcenizal 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!

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@timroes timroes 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.

@bhavyarm
Copy link
Contributor

@jen-huang how do I test this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Rollups Feature:Visualizations Generic visualization features (in case no more specific feature label is available) v6.4.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants