Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Conversation

@dreadera
Copy link
Contributor

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:

  • Lack of TypeScript Support
  • Failing Builds
  • Failing Tests
  • Webpack
  • Chunky Bundle
  • No Currency Support for the Currency Type Filter

The Goal

  • Update dependencies.
  • Introduce new building tools.
  • TypeScript support.
  • Fix the buggy tests
  • Add Multiple Currency / Locale Number Formatting

What has been done

  • Introduced Rollup as our default bundler.
  • Introduced TypeScript support.
  • Introduced the useLocaleNumber hook.
  • Introduced new Currency Filter Type Component.
  • Introduced React Context Provider to act as a store.
  • Existing Test Cases Updated.
  • Existing Storybooks Updated.
  • New Tests cases Added.
  • Updated Storybooks.
  • Updated Version Number.
  • Dependency Clean up

dreadera added 12 commits May 24, 2021 07:00
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
@uptickmetachu
Copy link

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 yarn link against workforce to make sure the built version works with workforce (minus the janky stuff in workforce webpack).

Copy link

@uptickmetachu uptickmetachu left a 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"

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?

Copy link
Contributor Author

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,

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.

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.

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?

@dreadera
Copy link
Contributor Author

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 :))

@dreadera
Copy link
Contributor Author

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 :)

Copy link

@adamdickinson adamdickinson left a 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",

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?

Suggested change
"version": "0.3.00",
"version": "0.3.0",

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 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')

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?

Copy link
Contributor Author

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"],

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

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 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.

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'

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`] = `

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', () => {

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?

Suggested change
describe('Convert Number To Locale', () => {
describe('convert number to locale', () => {

Comment on lines +10 to +15

// add override from context if provided.
...context,

// add override if params are provided.
...params,

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 :)

Suggested change
// add override from context if provided.
...context,
// add override if params are provided.
...params,
...context,
...params,

Comment on lines +1 to +12
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
}

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?

Copy link
Contributor Author

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>
Copy link
Member

@jarekwg jarekwg left a 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.

Comment on lines +48 to +50
Currency.defaultProps = {
currencySymbol: 'AUD',
}
Copy link
Member

@jarekwg jarekwg May 28, 2021

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.

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 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

Copy link
Member

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?

@dreadera
Copy link
Contributor Author

I 100% agree that this was should have been broken down into multiple PRs. I do apologise for that.

@jarekwg
Copy link
Member

jarekwg commented May 28, 2021

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.

@scaredcat
Copy link
Contributor

The changes here won't quite work. This package is set up kind of like a PWA where

  • src/index is the skeleton app. Placeholders for the filers (top section) and renderer (table/list)
  • src/filters/index is the filters to display at the top of the app
  • src/data-renderers/index is the content of the app (also imported directly into the skeleton app -- bad practice, but programmers are lazy. 99% of the time we will use Table renderer)
  • src/icons -- us trying to be fancy with too much customization. We should just use one icon set and stick with that.
  • src/types aka cells -- fine grained control of the type of data rendered within a table

In your changes rollup.config.js only references src/index which also includes the default data renderer and probably some cells. Its tree-shaking functionality is quite good so it will get rid of things that are not exported/referenced.

Please either

  1. Export all the things from src/index to make sure it comes with all the necessary parts (preferred option)
  2. Update rollup to continue delivering this package as a Frankenstein for self-assembly at the other end

@dreadera
Copy link
Contributor Author

dreadera commented Jun 1, 2021

wow, thanks for all that. it's nice to get some feedback on someone who worked on it :)
I'll improve this PR with the notes you have given. Thank you @scaredcat

@dreadera dreadera changed the title Typescript Support, Build Optimizations, Bug Fixes and Feature Request feature: typescript support, build optimizations and currency support Jun 7, 2021
@dreadera dreadera closed this Jan 24, 2022
@dreadera dreadera deleted the develop branch January 24, 2022 22:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants