-
Notifications
You must be signed in to change notification settings - Fork 273
refactor(plugin-chart-table): migrate to API v1 #889
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/superset/superset-ui/6b34umm1l |
4faffc4
to
addec6e
Compare
4d9faf1
to
38640a7
Compare
6f10263
to
7fb0819
Compare
7fb0819
to
63a9943
Compare
} | ||
}); | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may be only Set
enougph? if I got correctly logic do it like (but not sure):
items.forEach(x => {
if (!hash || !hash(x));
seen.add(x);
}
});
return [...seen]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does set spread preserve orders?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MDN says yes, but this still wouldn't work for my needs because I need to check uniqueness by hash, not the item itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideas: can short circuit when hash
is not used and only check hash
once.
function removeDuplicates<T>(items: T[], hash?: (item: T) => unknown): T[] {
if (hash) {
const seen = new Set();
return items.filter(x => {
const itemHash = hash(x);
if (seen.has(itemHash)) return false;
seen.add(itemHash);
return true;
});
}
return [...new Set(items)];
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Updated.
Codecov Report
@@ Coverage Diff @@
## master #889 +/- ##
==========================================
+ Coverage 27.04% 27.14% +0.09%
==========================================
Files 407 410 +3
Lines 8241 8264 +23
Branches 1119 1125 +6
==========================================
+ Hits 2229 2243 +14
- Misses 5885 5893 +8
- Partials 127 128 +1
Continue to review full report at Codecov.
|
2225370
to
7f6bea2
Compare
7f6bea2
to
244eeed
Compare
5d3f1e2
to
70accce
Compare
70accce
to
9a4d061
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few things here and there. Overall lgtm
if (normalizedKey === 'groupby') { | ||
normalizedKey = 'columns'; | ||
} | ||
if (normalizedKey === 'metrics') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit else if
or can also use switch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to avoid switch
nowadays since Python has taught me switch
is just a syntactic sugar for if else's. Plus I hate it when I forgot to call break
.
} | ||
}); | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideas: can short circuit when hash
is not used and only check hash
once.
function removeDuplicates<T>(items: T[], hash?: (item: T) => unknown): T[] {
if (hash) {
const seen = new Set();
return items.filter(x => {
const itemHash = hash(x);
if (seen.has(itemHash)) return false;
seen.add(itemHash);
return true;
});
}
return [...new Set(items)];
}
@@ -3,7 +3,7 @@ | |||
"composite": false, | |||
"emitDeclarationOnly": false, | |||
"noEmit": true, | |||
"rootDir": "." | |||
"rootDir": "../../../" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes as I need to import a contextualized enzyme
mount from root: https://github.com/ktmud/superset-ui/blob/8e744a77751fc8863522c8938974262e7e3463bd/plugins/plugin-chart-table/test/TableChart.test.tsx#L21
getChartComponentRegistry().registerLoader(key as string, this.loadChart); | ||
getChartControlPanelRegistry().registerValue(key as string, this.controlPanel); | ||
getChartTransformPropsRegistry().registerLoader(key as string, this.loadTransformProps); | ||
const key: string = this.config.key || isRequired('config.key'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given we are all in with typescript now. Could also remove the legacy isRequired
trick that was before the age of typescript. (No need to do in this pr).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. Let's do this when all major plugins (at least their index.js file) are migrated to typescript.
9a4d061
to
8ae7f07
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is amazing stuff, thanks so much for all the improvements here. Let's get this in and deal with any potential issues with higi priority, as I feel the improvements here far outweigh any potential regressions caused by it.
it('should remove duplciages from a simple list', () => { | ||
expect(removeDuplicates([1, 2, 4, 1, 1, 5, 2])).toEqual([1, 2, 4, 5]); | ||
}); | ||
it('should remove duplciages by key getter', () => { | ||
expect(removeDuplicates([{ a: 1 }, { a: 1 }, { b: 2 }], x => x.a)).toEqual([ | ||
{ a: 1 }, | ||
{ b: 2 }, | ||
]); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('should remove duplciages from a simple list', () => { | |
expect(removeDuplicates([1, 2, 4, 1, 1, 5, 2])).toEqual([1, 2, 4, 5]); | |
}); | |
it('should remove duplciages by key getter', () => { | |
expect(removeDuplicates([{ a: 1 }, { a: 1 }, { b: 2 }], x => x.a)).toEqual([ | |
{ a: 1 }, | |
{ b: 2 }, | |
]); | |
}); | |
it('should remove duplicates from a simple list', () => { | |
expect(removeDuplicates([1, 2, 4, 1, 1, 5, 2])).toEqual([1, 2, 4, 5]); | |
}); | |
it('should remove duplicates by key getter', () => { | |
expect(removeDuplicates([{ a: 1 }, { a: 1 }, { b: 2 }], x => x.a)).toEqual([ | |
{ a: 1 }, | |
{ b: 2 }, | |
]); | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding more comments and replies
@@ -149,7 +154,7 @@ export interface DruidFormData extends BaseFormData { | |||
druid_time_origin?: string; | |||
} | |||
|
|||
export type QueryFormData = SqlaFormData | DruidFormData; | |||
export type QueryFormData = DruidFormData | SqlaFormData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching order so if something doesn't add up, it will fallback to SqlaFormData
} | ||
}); | ||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Updated.
it('should remove duplciages from a simple list', () => { | ||
expect(removeDuplicates([1, 2, 4, 1, 1, 5, 2])).toEqual([1, 2, 4, 5]); | ||
}); | ||
it('should remove duplciages by key getter', () => { | ||
expect(removeDuplicates([{ a: 1 }, { a: 1 }, { b: 2 }], x => x.a)).toEqual([ | ||
{ a: 1 }, | ||
{ b: 2 }, | ||
]); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
metrics: metrics_, | ||
percentMetrics: percentMetrics_, | ||
percent_metrics: percentMetrics_, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just sick and tire of worrying about casing so I choose to use raw form data here. Should probably gradually deprecating this auto-case-transformation for the final charting API as well...
colorPn?: boolean; | ||
includeSearch?: boolean; | ||
pageLength?: string | number | null; // null means auto-paginate | ||
export type TableChartFormData = QueryFormData & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The benefit of not doing case transformation is that we can directly reuse this typing for both formData
sent to the API and received by the chart renderer (e.g. in both buildQuery
and transformProps
.)
Thank you, @villebro ! I've tested ECharts, NVD3, Box plot, Word Cloud and tried to be as comprehensive as I can. Also wanted to add the missing Cypress tests for more chart types (boxplot, time series table, for example) before merging, but didn't have enough time since a lot of my time has been spent on updating Cypress itself.. It would be super nice if someone from Preset could prioritize adding E2E tests for viz types or completing existing ones with more use cases so we can have more confidence in doing bigger viz plugin improvements like this. cc @junlincc |
I'm going to a new minor version and update apache/superset#10270 |
🏆 Enhancements
Migrate the table viz to use API v1, along with some refactoring related to QueryContext.
post_processing
ChartPlugin
to have customChartProps
groupby
fromqueryFields
as it is deprecated.GenericDataType
, the chart data type hints for renderingThis PR is a prerequisite of apache/superset#10270