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: add ui-components package #2321

Merged
merged 4 commits into from
Mar 22, 2021
Merged

chore: add ui-components package #2321

merged 4 commits into from
Mar 22, 2021

Conversation

katelynsills
Copy link
Contributor

@katelynsills katelynsills commented Feb 3, 2021

Add ui-components package to agoric-sdk, with tests.

Still to do:

  • Run tests successfully under SES (currently errors, see below)
  • Use @agoric/ertp in the component (needed to be run under SES)
  • Copy over the actual display.js, not the mock here (needs to be run under SES because uses @agoric/assert)
  • Use Bigints
  • Further test functionality by replacing React components in dapp-token-economy

Closes: #2320

@katelynsills katelynsills self-assigned this Feb 3, 2021
@michaelfig
Copy link
Member

Removing intrinsics.Object.assign.getPolyfill
Removing intrinsics.Object.assign.implementation
Removing intrinsics.Object.assign.shim
Removing intrinsics.Object.values.getPolyfill
Removing intrinsics.Object.values.implementation
Removing intrinsics.Object.values.shim

These messages are likely describing the source of the errors. SES is finding nonstandard properties on Object.assign and Object.values.

We don't want Babel to polyfill anything, IIUC.

Can you disable core-js if that is being used? It has bad interactions with SES.

@katelynsills
Copy link
Contributor Author

Removing intrinsics.Object.assign.getPolyfill
Removing intrinsics.Object.assign.implementation
Removing intrinsics.Object.assign.shim
Removing intrinsics.Object.values.getPolyfill
Removing intrinsics.Object.values.implementation
Removing intrinsics.Object.values.shim

These messages are likely describing the source of the errors. SES is finding nonstandard properties on Object.assign and Object.values.

We don't want Babel to polyfill anything, IIUC.

Can you disable core-js if that is being used? It has bad interactions with SES.

Thanks for the tip! Let me see what I can do

@katelynsills
Copy link
Contributor Author

There are two separate issues here:

  1. enzyme, AVA's recommended react testing library is trying to add properties to Object.assign and Object.values.
  2. A dependency ofmaterial-ui/core is trying to get globalThis without using globalThis. It returns undefined under SES, and a few lines later, the code tries to get a property of undefined and errors.

(I had forgotten that I had Enzyme setup code running before each test, so that explains how Enzyme was able to execute before lockdown.)

@katelynsills
Copy link
Contributor Author

External PR to change the jss package which MaterialUI depends on: cssinjs/jss#1449

@katelynsills
Copy link
Contributor Author

Update as of 2/10/2021:

With these two fixes, my tests pass. I'm going to put this on the back-burner to work on ERTP Beta tasks, but will come back to this once JSS gets a new release, or if we reprioritize this.

@katelynsills
Copy link
Contributor Author

The new version of JSS has been released, and tests now pass on Node 14! (have not tried Node 15).

@katelynsills katelynsills force-pushed the 2320-ui-components branch 2 times, most recently from 21f6983 to a321a7b Compare March 19, 2021 21:33
@katelynsills katelynsills marked this pull request as ready for review March 19, 2021 22:43
@katelynsills
Copy link
Contributor Author

@michaelfig, I think the NatAmountInput itself is good, with correct decimalPlaces handling and tests. However, I'm having trouble importing it in dapp-token-economy, especally since dapp-token-economy isn't ejected. I am wondering if we can merge this in even if I can't get the packaging/import to work yet.

Copy link
Member

@dtribble dtribble left a comment

Choose a reason for hiding this comment

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

Minor optional comments. GREAT tests.

packages/ui-components/src/display/display.js Outdated Show resolved Hide resolved
packages/ui-components/src/display/display.js Outdated Show resolved Hide resolved
* @param {number=} decimalPlaces - places to move the decimal to the left
* @returns {Value}
*/
export const parseAsValue = (
Copy link
Member

Choose a reason for hiding this comment

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

why clutter the name with As? parseValue says what I want it to do and what I'm expecting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me, it wasn't clear in parseX whether x was the input type or the output type. In parseValue, value is the output type, but that doesn't match how we usually say it in English: "parse this string as a value". In English, the input directly follows parse, and the output is prefixed with as. So to make the name clearer since it is the opposite of how we would speak normally, I added the As.

* @param {number=} decimalPlaces - places to move the decimal to the left
* @returns {Amount}
*/
export const parseAsAmount = (
Copy link
Member

Choose a reason for hiding this comment

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

Unless it's well motivated, the As is also an unnecessary renaming over what's there, resulting in merge overhead. Of course it might be well-motivated.

packages/ui-components/src/display/display.js Outdated Show resolved Hide resolved
@michaelfig
Copy link
Member

I am wondering if we can merge this in even if I can't get the packaging/import to work yet.

I'm happy for you to make forward progress by merging this, and deal with the finicky (mostly unrelated to your PR) import/export issues later. I may get to review this on the weekend, but don't feel obligated to wait for me.

Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

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

Just a few suggestions. Take or leave them.

packages/ui-components/README.md Outdated Show resolved Hide resolved
packages/ui-components/jsconfig.json Outdated Show resolved Hide resolved
packages/ui-components/README.md Show resolved Hide resolved
"name": "ui-components",
"version": "0.0.1",
"description": "Reusable UI Components for Agoric Dapps, built with React and MaterialUI",
"main": "dist/index.js",
Copy link
Member

Choose a reason for hiding this comment

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

This is probably the source of the import problems. React components can't easily be imported from bundles, IIUC. The build step has to be performed only once, in the app that imports all the other components. Otherwise, your app can't tree-shake the components that it doesn't use that are already bundled with other things.

If this change doesn't fix it for you, you might have instead to import the components as import NatAmountInput from '@agoric/ui-components/src/components/NatAmountInput'

Suggested change
"main": "dist/index.js",
"main": "src/index.js",

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 tried using the src directly, and it doesn't work in dapp-token-economy. I get an error message telling me to change my Babel settings to allow for JSX, but since we haven't ejected, I haven't found an easy way to change the Babel settings :/ There must be a way to bundle it correctly, though, since we can import MaterialUI components from packages.

packages/ui-components/package.json Outdated Show resolved Hide resolved
Comment on lines +11 to +12
// @ts-ignore path is correct for compiled output
import { NatAmountInput } from '../../../dist'; // eslint-disable-line import/no-unresolved
Copy link
Member

Choose a reason for hiding this comment

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

Can you please try this out? With the "main" change in package.json this should always work.

Suggested change
// @ts-ignore path is correct for compiled output
import { NatAmountInput } from '../../../dist'; // eslint-disable-line import/no-unresolved
import { NatAmountInput } from '../../..';

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 don't think this will work, because the source needs to be compiled for the tests to run. I am compiling manually through babel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested and confirmed that the compiled version is necessary because of the JSX:

 Uncaught exception in compiled/test/components/test-NatAmountInput.js

  /Users/katesills/code/agoric-sdk/packages/ui-components/src/components/NatAmountInput.js:31
      <TextField
      ^

  SyntaxError: Invalid or unexpected token

@katelynsills katelynsills enabled auto-merge (squash) March 22, 2021 20:39
@katelynsills katelynsills merged commit 770542e into master Mar 22, 2021
@katelynsills katelynsills deleted the 2320-ui-components branch March 22, 2021 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

We and external developers have reusable UI components that are tested and dependable
3 participants