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

Create an API for registering and replacing React components #2536

Merged
merged 103 commits into from
Jul 25, 2017

Conversation

jshimko
Copy link
Contributor

@jshimko jshimko commented Jul 7, 2017

This adds and uses an API for registering/replacing React components across the Reaction UI. Most of the front end of Reaction has been registered (and is now replaceable). Registering the admin components will come afterward in a separate PR.

Several new higher order components (HOC's) have been added for common use cases (injecting the current user, checking whether they are admin or owner, etc). More details in the docs (link below).

With the merge of this PR, we will need to discuss as a group what the workflow for adding new components and HOC's looks like so that we make sure to have consistency. One of the hardest parts of all of these updates was that there was not a lot of consistency in how components were structured and a lot of them were not set up in a way that made overrides or customization easy to implement. Hopefully this new pattern will solve that.

For more detail, see preliminary docs PR branch:

https://github.com/reactioncommerce/reaction-docs/blob/components-api/developer/components/API.md

jshimko and others added 30 commits July 7, 2017 12:57
* development:
  Fix order action button reverting status to processing (#2541)
…reaction into register-component-api

* 'register-component-api' of github.com:reactioncommerce/reaction:
  Fix issue 2535. Transliteration in Safari/IE (#2553)
  fix 2547: vertically-center navbar link using @navbar-height height variable instead of percentage height (#2551)
Simply import component for tag item in tag list component
…reaction into register-component-api

* 'register-component-api' of github.com:reactioncommerce/reaction:
  Release 1.4.1 (#2583)
  LingoHub based on development (#2591)
  Fix Setting product visibility is not reflected in the Product Grid reactively (#2561)
@jshimko
Copy link
Contributor Author

jshimko commented Jul 25, 2017

The issue with the MediaItem component reported by @zenweasel has been fixed. Along with that, I turned the SortableItem container into a true factory function so it could be used as a HOC with registerComponent. (HOC's need to be a function that takes a component and returns another component. Previously, SortableItem took both options and a component).

Anyway, all issues discovered by @zenweasel were ironed out with my last few commits and our conversation in Slack. Thanks for the thorough code review!

Copy link
Contributor

@aaronjudd aaronjudd left a comment

Choose a reason for hiding this comment

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

Lots of good stuff here. I found very little not working, (media, etc all working now) and overall seems to be solid and ready to go.

i18n doesn't appear to be working (reactively) -> choose a new language and no changes. when you navigate, updates become visible, but this is a bug.

.babelrc Outdated
@@ -0,0 +1,25 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we're moving this back from package.json?

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 thinking here was for two reasons. NPM keeps jacking up the formatting and because babelrc is a file specifically for this use. As our package.json continues to get longer, it's nice to not have it be a place for a bunch of different kinds of configs.

Copy link
Contributor

@aaronjudd aaronjudd Jul 25, 2017

Choose a reason for hiding this comment

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

true regarding npm jacking up the formatting. I had just moved the babelrc in 1.4 for the same reason -> as the number of aliases grow, the natural spot to maintain them all is in the same place where we load other packages.. my logic: why have our aliases hidden in babelrc... when it doesn't have to go there and we don't need to maintain multiple files..

(but hey-> let's go with this, for now, not a big deal to me, until I get annoyed by aliases I can't find again).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough

Copy link
Contributor

@aaronjudd aaronjudd left a comment

Choose a reason for hiding this comment

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

  • Would like to see i18n working.
  • Currency doesn't appear to be changing on PDP variants. (same behavior as i18n)
  • .babelrc reverted. (not a blocker)

Copy link
Contributor

@aaronjudd aaronjudd left a comment

Choose a reason for hiding this comment

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

Error opening SMS settings..

meteor.js?hash=814eae5…:934 Error: In template smsSettings, call to `{{> React ... }}` missing `component` argument.
    at Blaze.View.<anonymous> (react-template-helper.js:24)
    at blaze.js?hash=f33d3df…:1934
    at Function.Template._withTemplateInstanceFunc (blaze.js?hash=f33d3df…:3744)
    at blaze.js?hash=f33d3df…:1932```

Copy link
Contributor

@aaronjudd aaronjudd left a comment

Choose a reason for hiding this comment

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

Error opening dashboard email panel:

20modules.js?hash=c62f8dd…:85278 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of `ReactTable`.
    in ReactTable (created by SortableTable)
    in div (created by SortableTable)
    in SortableTable (created by Reaction(EmailLogs))
    in div (created by Reaction(CardBody))
    in VelocityTransitionGroupChild (created by TransitionGroup)
    in span (created by TransitionGroup)
    in TransitionGroup (created by VelocityTransitionGroup)
    in VelocityTransitionGroup (created by Reaction(CardBody))
    in Reaction(CardBody) (created by Reaction(EmailLogs))
    in div (created by Reaction(Card))
    in Reaction(Card) (created by Reaction(EmailLogs))
    in div (created by Reaction(CardGroup))
    in Reaction(CardGroup) (created by Reaction(EmailLogs))
    in Reaction(EmailLogs) (created by withProps(EmailLogs))
    in withProps(EmailLogs) (created by Tracker(withProps(EmailLogs)))
    in Tracker(withProps(EmailLogs))
printWarning @ modules.js?hash=c62f8dd…:85278

@jshimko
Copy link
Contributor Author

jshimko commented Jul 25, 2017

  • babelrc reverted
  • Translation and Currency components no longer pure (so should re-render properly again)

@brent-hoover
Copy link
Collaborator

Yeah I just saw those email/SMS panel errors as well

@aaronjudd
Copy link
Contributor

@jshimko might as well update the version to 1.5.0 as well -> this is big enough we're going to want to identify it in dev...

@jshimko
Copy link
Contributor Author

jshimko commented Jul 25, 2017

SMS and email settings errors should be fixed.

@jshimko
Copy link
Contributor Author

jshimko commented Jul 25, 2017

Version bumped to 1.5.0

Copy link
Contributor

@aaronjudd aaronjudd left a comment

Choose a reason for hiding this comment

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

SMS/etc all looks good now. I'm still seeing some funky behavior with i18n and currency, although it is now acting reactively. Just switching languages/currency logged in and logged out, non-update elements start appearing. I have the feeling this should be a new issue, as I'm not sure it's enough to block this migrating to development.

Copy link
Collaborator

@brent-hoover brent-hoover left a comment

Choose a reason for hiding this comment

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

A couple of style notes and we need to figure out if importing from @reactioncommerce/reaction-components is a local or an NPM import because we are doing it both ways. But I don't see anything here worth holding up the PR for.

@@ -0,0 +1,77 @@
import { composeWithTracker } from "./composer";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Import order

@@ -1,10 +1,9 @@
import React from "react";
import { composeWithTracker } from "@reactioncommerce/reaction-components";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Import order

} else {
this.setState({ status: "error" });
componentWillMount() {
const { settings } = this.props;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we aren't using settings, couldn't we destructure a nested object in one step? (says guy who just recently reread the destructuring docs)

@@ -0,0 +1,38 @@
import { compose, withProps } from "recompose";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generally I don't know if I am favor of renaming these. I found having container in the name makes it easier to find the appropriate file, and no one died from being too explicit.

@@ -1,47 +1,50 @@
import React, { Component } from "react";
import React, { PureComponent } from "react";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, if we are going to remove container from some file names because they are in a container directory we should probably do that everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agreed @zenweasel. Adding the word "container" to every file name felt really unnecessary to me when they're already in a /container directory. Also, the base component name (without "container" appended) is how they should be referenced with the new API and you should be able to assume that the final component has that name regardless of whether higher order components are being used.

The only reason I didn't do it across the app is because I already edited almost 300 files. The PR had to end somewhere. :)

But yeah, as components get updated to use the new API, my vote is to remove the container from the name and standardize things.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I am against renaming these but oh well.

Logger.error(error);
throw new Meteor.Error(error);
}
Meteor.call("products/updateProductPosition", productId, position, tag, error => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

(this is inherited code but since I noticed) Parenthesis around error?

@aaronjudd aaronjudd merged commit d9e6fb4 into development Jul 25, 2017
@aaronjudd
Copy link
Contributor

@jshimko @zenweasel has some valid style points... but I couldn't take it anymore.. merged to development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement For issues that describe a feature that needs to be added, changed, or removed, but is not a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants