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

feat(table): enable table filter and better typing #344

Merged
merged 3 commits into from
Apr 21, 2020

Conversation

ktmud
Copy link
Contributor

@ktmud ktmud commented Apr 6, 2020

🏆 Enhancements
🐛 Bug Fix

  • Add back "emit filter" support to Table chart.
  • Refactor typing for both Table and Big Number, make more strict or give more hints when possible.

@ktmud ktmud requested a review from a team as a code owner April 6, 2020 23:48
@vercel
Copy link

vercel bot commented Apr 6, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/superset/superset-ui/fq9g998vh
✅ Preview: https://superset-ui-git-fork-ktmud-fix-clientside-filter.superset.now.sh

@codecov
Copy link

codecov bot commented Apr 6, 2020

Codecov Report

Merging #344 into master will decrease coverage by 0.09%.
The diff coverage is 40.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #344      +/-   ##
==========================================
- Coverage   26.35%   26.25%   -0.10%     
==========================================
  Files         192      192              
  Lines        5256     5287      +31     
  Branches      459      473      +14     
==========================================
+ Hits         1385     1388       +3     
- Misses       3842     3864      +22     
- Partials       29       35       +6     
Impacted Files Coverage Δ
...rset-ui-chart/src/components/ChartDataProvider.tsx 100.00% <ø> (ø)
...number/src/utils/getTimeFormatterForGranularity.ts 83.33% <0.00%> (ø)
plugins/big-number/src/BigNumber/transformProps.ts 52.00% <11.11%> (-5.15%) ⬇️
plugins/table/src/ReactDataTable.tsx 64.86% <42.10%> (-14.90%) ⬇️
plugins/table/test/testData.ts 83.33% <50.00%> (-16.67%) ⬇️
plugins/table/src/transformProps.ts 48.14% <57.14%> (-3.86%) ⬇️
...kages/superset-ui-chart/src/clients/ChartClient.ts 100.00% <100.00%> (ø)
...ackages/superset-ui-chart/src/models/ChartProps.ts 100.00% <100.00%> (ø)

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 fb9cce3...231bea3. Read the comment docs.

packages/superset-ui-chart/src/models/ChartProps.ts Outdated Show resolved Hide resolved
packages/superset-ui-chart/src/models/ChartProps.ts Outdated Show resolved Hide resolved
packages/superset-ui-chart/src/models/ChartProps.ts Outdated Show resolved Hide resolved
plugins/big-number/src/BigNumber/transformProps.ts Outdated Show resolved Hide resolved
compareLag?: string | number;
yAxisFormat?: string;
timeGrainSqla?: TimeGranularity;
} & ChartProps['formData'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need & ChartProps['formData']?

Copy link
Contributor Author

@ktmud ktmud Apr 17, 2020

Choose a reason for hiding this comment

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

Thought it was more semantically correct to include it. Can probably drop since we've been exhaustive listing all the fields. Actually, it'd be easier to just do this because some shared properties are indeed useful to keep in ChartProps and it doesn't make sense to exhaustively list them for every chart type.

Copy link
Contributor

Choose a reason for hiding this comment

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

two questions:

  • should it be Partial<ChartProps['formData']>? or all of them?
  • are there duplicate keys in ChartProps['formData']? I'm not sure order of override for TS, just wanted to make sure if there are duplicates that the BigNumberFormData values take precedent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it'd be easier to just do this because some shared properties are indeed useful to keep in ChartProps and it doesn't make sense to exhaustively list them for every chart type.

Strike again. formData and queryData are basically PlainObject, which accepts any key with any values. Partial or not it doesn't make any difference, at least for now. I was thinking & ChartProps.

@williaster thanks for the reminder about overrides. I should have placed ChartProps['formData'] at the front.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'm going to avoid Partial as it makes all properties optional, which is probably not what we want in this case.

@vercel vercel bot requested a deployment to Preview April 20, 2020 06:50 Abandoned
@vercel vercel bot requested a deployment to Preview April 20, 2020 07:01 Abandoned
@apache-superset apache-superset deleted a comment from vercel bot Apr 20, 2020
@apache-superset apache-superset deleted a comment from vercel bot Apr 20, 2020
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.

lgtm overall 👍

type: DatasourceType;
columns: Column[];
metrics: QueryObjectMetric[];
description?: string;
columnFormats?: {
[key: string]: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

could we be any more specific about what key is here + verboseMap below? like name or id or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I always thought it's good to be generic in indexable types so that new TypeScript users don't confuse it with an actual property name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add some inline comments instead.

compareLag?: string | number;
yAxisFormat?: string;
timeGrainSqla?: TimeGranularity;
} & ChartProps['formData'];
Copy link
Contributor

Choose a reason for hiding this comment

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

two questions:

  • should it be Partial<ChartProps['formData']>? or all of them?
  • are there duplicate keys in ChartProps['formData']? I'm not sure order of override for TS, just wanted to make sure if there are duplicates that the BigNumberFormData values take precedent.

const {
colorPicker,
compareLag: compareLagInput,
compareLag: compareLag_,
Copy link
Contributor

Choose a reason for hiding this comment

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

readability nit – I think compareLagInput is a clearer name, not sure what _ means tho I guess it's used a few places here

Copy link
Contributor Author

@ktmud ktmud Apr 20, 2020

Choose a reason for hiding this comment

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

I use dangling "_" for arguments that will be immediately overridden by simple argument processing. It indicates a sense of temporariness and keeps the variable names clean.

let value = val;
if (typeof val === 'string') {
// force UTC time zone if is an ISO timestamp without timezone
// e.g. "2020-10-12T00:00:00"
value = val.match(/T(\d{2}:){2}\d{2}$/) ? `${val}Z` : val;
value = new Date(value);
}
return formatTimestamp(value) as string;
return formatTimestamp(value as Date | number | null) as string;
Copy link
Contributor

Choose a reason for hiding this comment

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

can you set this above instead of coercing? let value: Date | number | null = val; ...

Copy link
Contributor Author

@ktmud ktmud Apr 20, 2020

Choose a reason for hiding this comment

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

Actually tried that, but ran into error when passing it to new Date. Obviously new Date doesn't accept nulls.

cursor: pointer;
}
.superset-legacy-chart-table td.dt-is-filter:hover {
background-color: linen;
Copy link
Contributor

Choose a reason for hiding this comment

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

curious how these were chosen? should we get any design feedback?

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 original color is:

  background-color: lighten(desaturate(@brand-primary, 50%), 50%);

apache/superset@cbf38ff#diff-9479060a8cb28b444d0ce7f5df0a33ccL577

image

Which translates to #bce9e5. I just picked a named color that is close to it and does not look bad. Wanted to use the original color, but it kind of looked too dark to me.

This will probably eventually become customizable with the introduction of the superset-ui/style package.

@ktmud ktmud changed the title feat: enable table filter and better typing feat(table): enable table filter and better typing Apr 21, 2020
@ktmud ktmud merged commit fdf6514 into apache-superset:master Apr 21, 2020
@ktmud ktmud deleted the fix-clientside-filter branch April 21, 2020 01:03
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.

None yet

3 participants