-
Notifications
You must be signed in to change notification settings - Fork 4
feature: typescript support, build optimizations and currency support #125
Conversation
Instead of Weback, We are now using Rollup as our bundler as it has better build times and better support for JavaScript/TypeScript Library building. Side Effects: - Structure is slightly different but importing is the same
Some of the functionality was failing for the most part. I have redid the snapshots using the -u flag. useLocaleNumber hook now provides formatted numbers based on the provided Locale and Currency.
List.js - getVisibleColumns was being imported from the wrong place Table.js - Selection would be 'all' and it would not be filterable. instead i have removed the filter if selection is all
|
My slight concern is we are going from one ball of complexity to another (webpack -> rollup). There seems to be equally a lot of configuration required WRT babel/eslint/rollup as there was before. I do appreciate the better build times and bundle size. I wonder if there is a way to simplify the build? Also have we tested this with |
uptickmetachu
left a comment
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.
Same as my comments above, otherwise looking good!
Regarding the actual frontend changes can you add a comment to sections that reviewers should look at? It has become hard to navigate due to all the format changes.
| "style-loader": "^2.0.0", | ||
| "ts-jest": "^26.5.6", | ||
| "typescript": "^4.2.4", | ||
| "typescript-eslint": "^0.0.1-alpha.0" |
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.
o,o is this the correct plugin?
https://www.npmjs.com/package/@typescript-eslint/eslint-plugin
Perhaps we mean this one?
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.
oops, you're right. I will rectify this :)
| output: [ | ||
| // Common JS Support. | ||
| { | ||
| file: packageJson.main, |
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.
oh neat! I like this importing the package.json and referencing the file for linking the build tools to the packaging. 👍🏼
| }, | ||
| }), | ||
|
|
||
| // Do Babel transpilation. |
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.
:( Somehow I assumed we could get rid of babel if we adopted TS.
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 believe we still need to transpile it back to es6 - I don't think tsc does that, does it?
|
I fully agree that going from webpack -> rollup doesn't change things in terms of configuration and does add a bit of complexity if you don't know rollup but i chose it simply for the sake of having a large amount of community maintained plugins that work out of the box without much configuration. while the actually rollup config itself does require you incorporate the plugins, the plugins themselves don't need much configuration. if it makes things easier, we can try esbuilding everything without having rollup :) the configuration is also minimal for that :)) |
|
In terms of testing with workforce, I haven't fully tried every place where this library is used but I did yarn link and have a go on a demo version I setup, which worked as intended :) |
adamdickinson
left a comment
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.
Relatively quick pass from me. Awesome attention to detail in many parts - loving what you've done! I've noted a few things, queried a few parts and suggested some things along the way.
I will flag that I'm concerned we won't be able to give this a thorough and proper review due to its size, but I'll do my best :)
Also apologies for the short/sharp/inconsiderate comments! Loving your work, just short on time this morning 😬.
| { | ||
| "name": "react-object-list", | ||
| "version": "0.2.10", | ||
| "version": "0.3.00", |
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 could be a typo? Also, what is the breaking change with this new version?
| "version": "0.3.00", | |
| "version": "0.3.0", |
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 only changed the middle value to represent the minor update in accordance with SemVer to represent the new currency feature.
| import List from './data-renderers/List' | ||
|
|
||
| const mockData = require('./demo.data.json') | ||
| const mockData = require('../samples/people.json') |
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.
Thought - could we lean on something like faker to generate this data for us?
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.
We should. Faker is really nice for dev / showcasing :)
| "babel" | ||
| ], | ||
| "parser": "babel-eslint", | ||
| "plugins": ["babel", "react", "react-hooks", "@typescript-eslint"], |
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.
Do you think it could be worth us creating an uptick/lint-config package to keep all our standard eslint (and prettier) rules in the one place? It'll make it easy for us to have the one, unified uptick standard across the board.
As a side-thought, this would be nice too - just want to drop the idea of it though:
https://github.com/tclindner/npm-package-json-lint
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 was thinking the same thing. I think we should all have a standardised version which should be version controlled and then be available via npm :)
| }, | ||
| }), | ||
|
|
||
| // Do Babel transpilation. |
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 believe we still need to transpile it back to es6 - I don't think tsc does that, does it?
| import React from 'react' | ||
| import { shallow } from 'enzyme' | ||
| import { snapshotTest } from 'utils/tests' | ||
| import { snapshotTest } from '../../../../utils/tests' |
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.
Out of curiosity - what benefit do we get from switching away from the aliased paths?
| @@ -0,0 +1,16 @@ | |||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | |||
|
|
|||
| exports[`Currency Snapshots enders default 1`] = ` | |||
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.
Typo here too?
| return <div>{format(value)}</div> | ||
| } | ||
|
|
||
| describe('Convert Number To Locale', () => { |
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.
Question on consistency - we use lowercase in our other test files, but Title Case throughout this one. I think the convention is the former. Could we update to lowercase to stay with convention?
| describe('Convert Number To Locale', () => { | |
| describe('convert number to locale', () => { |
|
|
||
| // add override from context if provided. | ||
| ...context, | ||
|
|
||
| // add override if params are provided. | ||
| ...params, |
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 think you've done a good enough job making the code explain this for you :)
| // add override from context if provided. | |
| ...context, | |
| // add override if params are provided. | |
| ...params, | |
| ...context, | |
| ...params, |
| export default function translate(path: string) { | ||
| const travel = regexp => | ||
| String.prototype.split | ||
| .call(path, regexp) | ||
| .filter(Boolean) | ||
| .reduce((res, key) => (res !== null && res !== undefined ? res[key] : res)) | ||
|
|
||
| const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/) | ||
| const payload = result === undefined | ||
|
|
||
| return payload | ||
| } |
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.
What... does this function do?
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.
Ah, I forgot to remove this. I was planning to write a locale function to get strings from objects. like lodash/get. however, i moved away from this. I just forgot to remove the function.
Co-authored-by: Adam Dickinson <adam@renegadedigital.com.au>
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.
Mammoth effort!
I'm not strong on reviewing frontend code, so just going to provide cursory comments.
- The size of this PR is very hard to review properly. If it's relatively straightforward to cut a couple more branches from master, cherry pick individual changes into them, and open up a couple of smaller PRs, I'd strongly recommend that. This is especially important when it comes to codestyle changes vs business logic changes. At the very least, the currency changes need to be moved out of here and done separately.
- My vote would be to use esbuild over rollup here too, just so that we're not spreading ourselves thing on bundler prerequisite knowledge..
Love what you've done, but yeah if we can get it through in some smaller logical smaller chunks, will be a much saner exercise for all involved.
| Currency.defaultProps = { | ||
| currencySymbol: 'AUD', | ||
| } |
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 doesn't look right -- "currencySymbol" suggests '$', not 'AUD'..
The way I'd see this working is the widget reads in locale info from a higher context, and then applies the appropriate formatting.
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 native Intl.NumberFormat function takes in the standard currency symbols.
This works a lot better as it's built into JS and means we only have to provide the following. Locale, Currency Format and Decimals to the context provider upon invocation.
Function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
List: https://www.currency-iso.org/en/home/tables/table-a1.html
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.
gotcha; can we rename it just to currency then?
|
I 100% agree that this was should have been broken down into multiple PRs. I do apologise for that. |
|
Ok, if not planning to split this up, we'll want to publish this with at least a minor version release bump (ie 0.3.0). Then will probs be best to test by plugging it directly into workforce and clicking through to see how it all works. I suspect there'll need to be followup patch versions needed for the stuff we haven't picked up in this review. |
|
The changes here won't quite work. This package is set up kind of like a PWA where
In your changes Please either
|
|
wow, thanks for all that. it's nice to get some feedback on someone who worked on it :) |
The Problem
First of all I Apologize for the large chunk of changes. I tried to minimize it as much as possible.
This entire library has been stuck in a bit of a time machine. It's quite dated with failing tests, mismatched versioning and lack of proper development tools.
The List of Problems:
The Goal
What has been done