Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

feat: update ChartFormData and QueryObject to support filters. #164

Merged
merged 14 commits into from
May 23, 2019

Conversation

kristw
Copy link
Contributor

@kristw kristw commented May 22, 2019

💔 Breaking Changes

Rename types to make it clearer. The metric types in ChartFormData and QueryObject are different.

  • FormDataMetric => ChartFormDataMetric
  • Metrics => ChartFormDataMetrics
  • Metric => QueryObjectMetric

This is pretty mild breaking change as these are internally used types so I would incline to not bump major version.

🏆 Enhancements

  • Update type of ChartFormData and QueryObject to support filters.
  • Update buildQueryObject to convert filters from ChartFormData and put into corresponding fields in QueryObject. See processFilters.ts and convertFilter.ts.
  • Improve typings of the QueryObject fields.
  • Add type guards

📜 Documentation

  • Add comments for fields on QueryObject

🏠 Internal

  • Remove Metrics class and replace with two functions processMetrics and convertMetric.
  • Migrate old unit tests and add new unit tests to ensure coverage.

@kristw kristw requested a review from a team as a code owner May 22, 2019 19:15
@codecov
Copy link

codecov bot commented May 22, 2019

Codecov Report

Merging #164 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #164   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          81     88    +7     
  Lines        1050   1095   +45     
  Branches      259    263    +4     
=====================================
+ Hits         1050   1095   +45
Impacted Files Coverage Δ
...es/superset-ui-chart/src/query/buildQueryObject.ts 100% <100%> (ø) ⬆️
...kages/superset-ui-chart/src/query/processExtras.ts 100% <100%> (ø)
...ages/superset-ui-chart/src/query/processFilters.ts 100% <100%> (ø)
...ages/superset-ui-chart/src/query/processMetrics.ts 100% <100%> (ø)
...kages/superset-ui-chart/src/query/convertMetric.ts 100% <100%> (ø)
packages/superset-ui-chart/src/types/Operator.ts 100% <100%> (ø)
packages/superset-ui-chart/src/types/Filter.ts 100% <100%> (ø)
...kages/superset-ui-chart/src/query/convertFilter.ts 100% <100%> (ø)
...kages/superset-ui-chart/src/types/ChartFormData.ts 100% <100%> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c732ec...f702ca1. Read the comment docs.

@netlify
Copy link

netlify bot commented May 22, 2019

Deploy preview for superset-ui ready!

Built with commit 1e8853e

https://deploy-preview-164--superset-ui.netlify.com

@kristw kristw changed the title [WIP] feat: add filter feat: update ChartFormData and QueryObject to support filters. May 23, 2019
@kristw kristw requested review from conglei and xtinec May 23, 2019 00:54
row_limit?: number;
/** Maximum number of series */
timeseries_limit?: number;
/** TODO: Doc */
Copy link
Contributor

Choose a reason for hiding this comment

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

The metric used to sort the returned result.

export default function convertFilter(filter: SimpleAdhocFilter): QueryObjectFilterClause {
const { subject } = filter;
if (isUnaryAdhocFilter(filter)) {
const { operator } = filter;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can put it outside the current block to reduce the duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Has to be inside the block to infer the correct Operator type

@@ -0,0 +1,43 @@
/** List of operators that do not require another operand */
export const UNARY_OPERATORS = ['IS NOT NULL', 'IS NULL'] as const;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to export UNARY_OPERATORS etc? seems there is no other place to use them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not being used at the moment. I will remove export

// TODO: Implement
// utils.convert_legacy_filters_into_adhoc(self.form_data)

// TODO: Implement
Copy link
Contributor

Choose a reason for hiding this comment

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

Will these two in the scope of this PR?

Copy link
Contributor Author

@kristw kristw May 23, 2019

Choose a reason for hiding this comment

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

These will be beyond the scope. Right now this PR will handle adhoc_filters (which is the standard filters) correctly plus provide typings.

Copy link
Contributor

Choose a reason for hiding this comment

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

do you think we should console.warn if we see legacy filters? (fine if not)

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 legacy filters are using fields filters and having_filters which do not exist on type ChartFormData, so typescript would complain.

I am wondering if we want to support this utils.convert_legacy_filters_into_adhoc(self.form_data) going forward. Not sure how long since we have moved from the legacy filters.

Copy link
Contributor

@conglei conglei left a comment

Choose a reason for hiding this comment

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

Thanks for adding this and refactoring the code overall! it looks good overall

order_desc: orderDesc,
is_timeseries: groupbySet.has(DTTM_ALIAS),
metrics: processMetrics(formData),
order_desc: order_desc === undefined ? true : order_desc,
Copy link
Contributor

@williaster williaster May 23, 2019

Choose a reason for hiding this comment

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

typeof order_desc === 'undefined'?

@@ -0,0 +1,43 @@
/** List of operators that do not require another operand */
Copy link
Contributor

Choose a reason for hiding this comment

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

wow these are great!

// TODO: Implement
// merge_extra_filters(self.form_data)

// utils.split_adhoc_filters_into_base_filters(self.form_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this just indicating what the logic below mapped to? (i.e., it's not part of the TODOs above) should we remove it or keep for context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove or change to simple sentence. Seem not necessary any more

// eslint-disable-next-line camelcase
const { adhoc_filters } = formData;
if (Array.isArray(adhoc_filters)) {
const simpleWhere: QueryObjectFilterClause[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

(not blocking) the type helps but I find these a little confusing name-wise, not sure what to expect simple to mean, maybe whereFilter <> whereFreeform and havingFilter <> havingFreeform?

SIMPLE = 'SIMPLE',
SQL = 'SQL',
}
export type Aggregate = 'AVG' | 'COUNT' | 'COUNT_DISTINCT' | 'MAX' | 'MIN' | 'SUM';
Copy link
Contributor

Choose a reason for hiding this comment

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

nice 👌

Copy link
Contributor

@williaster williaster left a comment

Choose a reason for hiding this comment

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

really solid! Hard to find anything to improve significantly I had only nit/non-blocking thoughts 😍 👏 💯

@kristw kristw merged commit 025d5bc into master May 23, 2019
@delete-merged-branch delete-merged-branch bot deleted the kristw--filter branch May 23, 2019 20:05
kristw pushed a commit that referenced this pull request Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants