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

chore: migrate FormattedNumber component from jsx to tsx #17361

Merged
merged 4 commits into from Nov 22, 2021

Conversation

Damans227
Copy link
Contributor

SUMMARY

PR for migrating FormattedNumberProps functional react component from JSX to TSX

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • [TRACKER] Migrate JavaScript files to TypeScript #10004
  • Enhancement (new features, refinement)
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@Damans227
Copy link
Contributor Author

@etr2460 ptal, thx!

@codecov
Copy link

codecov bot commented Nov 5, 2021

Codecov Report

Merging #17361 (a4f2fff) into master (f05a32e) will decrease coverage by 0.22%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17361      +/-   ##
==========================================
- Coverage   77.14%   76.91%   -0.23%     
==========================================
  Files        1036     1039       +3     
  Lines       55759    56185     +426     
  Branches     7628     7794     +166     
==========================================
+ Hits        43013    43216     +203     
- Misses      12490    12713     +223     
  Partials      256      256              
Flag Coverage Δ
javascript 71.04% <0.00%> (-0.38%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...d/src/visualizations/TimeTable/FormattedNumber.tsx 0.00% <0.00%> (ø)
...ols/DndColumnSelectControl/utils/optionSelector.ts 35.55% <0.00%> (-10.60%) ⬇️
superset-frontend/src/explore/constants.ts 90.38% <0.00%> (-6.99%) ⬇️
...hboard/components/nativeFilters/FilterBar/state.ts 82.81% <0.00%> (-4.69%) ⬇️
...ols/FilterControl/AdhocFilterEditPopover/index.jsx 64.91% <0.00%> (-4.54%) ⬇️
...ents/controls/DateFilterControl/utils/constants.ts 96.77% <0.00%> (-3.23%) ⬇️
...ols/DndColumnSelectControl/ColumnSelectPopover.tsx 12.96% <0.00%> (-3.17%) ⬇️
superset-frontend/src/chart/Chart.jsx 40.29% <0.00%> (-3.04%) ⬇️
...et-frontend/src/dashboard/actions/nativeFilters.ts 45.55% <0.00%> (-2.68%) ⬇️
...ColumnSelectControl/ColumnSelectPopoverTrigger.tsx 80.95% <0.00%> (-2.39%) ⬇️
... and 115 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 f05a32e...a4f2fff. Read the comment docs.

if (format) {
return <span title={num}>{formatNumber(format, num)}</span>;
return (
<span title={num as string}>{formatNumber(format, num as number)}</span>
Copy link
Member

Choose a reason for hiding this comment

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

it looks like formatNumber might actually support strings already (according to the old code). could you check the function in superset-ui and see if that type needs to be changed?

also, for title, let's do title={`${num}`} instead asserting and overriding the type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it looks like formatNumber might actually support strings already (according to the old code). could you check the function in superset-ui and see if that type needs to be changed?

Sure thing.

also, for title, let's do title={`${num}`} instead asserting and overriding the type

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etr2460

it looks like formatNumber might actually support strings already (according to the old code). could you check the function in superset-ui and see if that type needs to be changed?

As per the superset-ui documentation for number-format, it looks like formatNumber fallbacks to d3.format to handle the error for invalid format like string.

However, changing:

<span title={num as string}>{formatNumber(format, num as number)}</span>

to

<span title={num as string}>{formatNumber(format, num)}</span>;

in the tsx file is throwing an error:

Argument of type 'string | number' is not assignable to parameter of type 'number | null | undefined'.
Type 'string' is not assignable to type 'number | null | undefined'.

Copy link
Member

Choose a reason for hiding this comment

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

thanks for looking into this. Since formatNumber(format, num) has been working today already, and i'm a bit hesitant to parseInt the string in case we lose accuracy for very large numbers, I think it's ok to override typescript here. Once change I might make though is insead of doing num as number (which would imply that it's always a number, even when it isn't) I would add a // @ts-expect-error formatNumber can actually accept strings, even though it's not typed as such comment to bypass the TS error

Copy link
Member

Choose a reason for hiding this comment

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

@Damans227 @etr2460 Just to be sure here. The superset-ui documentation for number-format referenced above states the following:

It is powered by a registry to support registration of custom formatting, with fallback to d3.format and handle error for invalid format string.

It's talking about the formatting string, which is the first parameter of the function, and not about invalid formats for the num (second parameter). Are you sure the value can be interpreted as strings?

Copy link
Member

Choose a reason for hiding this comment

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

@michael-s-molina @Damans227 so this uses d3-format under the hood, which is untyped, but as far as i can tell does support strings (see where it converts it here):
https://github.com/d3/d3-format/blob/main/src/locale.js#L74

But more importantly than that, before we allowed all strings through here, so i don't think adding a parseInt is correct since that could change the behavior. coercing the type with an as number also doesn't feel right since we don't know it's a number. That's why i recommended the options above

@junlincc junlincc added this to fix in progress in Community issues Nov 12, 2021
@junlincc junlincc moved this from fix in progress to review in progress in Community issues Nov 12, 2021
@pkdotson
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@pkdotson Ephemeral environment spinning up at http://34.221.117.162:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

lgtm, thanks for the iteration!

@etr2460
Copy link
Member

etr2460 commented Nov 18, 2021

@pkdotson did you want to test anything here before we merge them?

@pkdotson
Copy link
Member

LGTM!

Copy link
Member

@pkdotson pkdotson left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the chore!

@pkdotson pkdotson merged commit daff9b4 into apache:master Nov 22, 2021
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

AAfghahi pushed a commit that referenced this pull request Jan 10, 2022
* migrate FormattedNumber component from jsx to tsx

* Unset default prop on format

* undo asserting and overriding the type for num

* Add a ts comment to ignore error
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/S 🚢 1.5.0
Projects
Community issues
review in progress
Development

Successfully merging this pull request may close these issues.

None yet

6 participants