feat(core): add applied_time_extras to QueryObject#809
feat(core): add applied_time_extras to QueryObject#809villebro merged 2 commits intoapache-superset:masterfrom
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/superset/superset-ui/57hllvjrw |
Codecov Report
@@ Coverage Diff @@
## master #809 +/- ##
=======================================
Coverage 25.57% 25.57%
=======================================
Files 359 359
Lines 7949 7949
Branches 1056 1055 -1
=======================================
Hits 2033 2033
Misses 5796 5796
Partials 120 120
Continue to review full report at Codecov.
|
|
Thanks @pkdotson ! |
ktmud
left a comment
There was a problem hiding this comment.
Added a couple of naming suggestions. I'm also not fully getting what is this used for. Can you also add more context on how is this going to be used in superset-frontend code (maybe a linked PR?) and what are we constrained with if we don't do this?
| const queryField = reservedColumnsToQueryField[filter.col]; | ||
| partialQueryObject[queryField] = filter.val; | ||
| // @ts-ignore | ||
| partialQueryObject.applied_time_extras[filter.col] = filter.val; |
There was a problem hiding this comment.
Instead of ts-ignore, can use type assertion somewhere to make the typings compatible?
partialQueryObject.applied_time_extras[filter.col as QueryObjectAppliedTimeExtraKey] = filter.val;| where?: string; | ||
| }>; | ||
|
|
||
| export type QueryObjectAppliedTimeExtraKey = |
There was a problem hiding this comment.
Can we rename this to something more generic such as TimeColumnConfigKey? Also, maybe put this into Time.ts ?
| applied_time_extras: {}, | ||
| }; | ||
|
|
||
| const reservedColumnsToQueryField: Record<string, keyof QueryObject> = { |
There was a problem hiding this comment.
Looks like this could be Record<QueryObjectAppliedTimeExtraKey, keyof QueryObject> or Record<TimeColumnConfigKey, keyof QueryObject>.
| }; | ||
|
|
||
| export type QueryObject = { | ||
| /** Extra filters that have been applied to the query object */ |
There was a problem hiding this comment.
This comment doesn't seem to indicate how is this is different from extra.
|
Thanks for comments @ktmud , I'll add some more context to make this clearer and do the suggested code improvements. This is something that is needed to be able to complete the p0 filter indicator feature (filter indicators will otherwise not work with the chart data endpoint). I envision this and other related structures, namely how ad-hoc filters are transformed into simple filters + static |
| | '__granularity'; | ||
|
|
||
| export type QueryObjectAppliedTimeExtras = { | ||
| QueryObjectAppliedTimeExtraKey?: string; |
There was a problem hiding this comment.
I don't think this type is doing what you think it's doing
|
I'm not sure what |
| const { extras = {}, filters = [] } = formData; | ||
| const partialQueryObject: Partial<QueryObject> = { | ||
| filters: formData.filters || [], | ||
| extras: formData.extras || {}, | ||
| filters, | ||
| extras, | ||
| applied_time_extras, |
There was a problem hiding this comment.
Bycatch: change to use destructuring here.
12b97bb to
4127393
Compare
| partialQueryObject.extras = { | ||
| druid_time_origin: formData.druid_time_origin, | ||
| }; | ||
| extras.druid_time_origin = formData.druid_time_origin; |
There was a problem hiding this comment.
bycatch: better to add to the object than discard the original one.
| partialQueryObject.extras = { | ||
| ...partialQueryObject.extras, | ||
| time_grain_sqla: partialQueryObject.time_grain_sqla || formData.time_grain_sqla, | ||
| }; | ||
| extras.time_grain_sqla = partialQueryObject.time_grain_sqla || formData.time_grain_sqla; |
🏆 Enhancements
Add
applied_time_extrastoQueryObjectto be able to identify which filters have been set/overridden byextra_filters. Please see apache/superset#11325 for additional context.