Skip to content

Commit

Permalink
Create an API for registering and replacing React components (#2536)
Browse files Browse the repository at this point in the history
* create API for registering and replacing React components

* register most components in ui plugin

* register all button variants separately

* delete empty file

* cleanup and register checkout components

* load registered components in router startup

* register/cleanup NavBar components and add to CoreLayout

* start on register/cleanup of Tag components

* set default value to Array for hoc arg

* register/cleanup Notification components

* clean up and register accounts components

* move all registered component usage inside of render methods

* register CartPanel container

* mapProps -> withProps

* use registeredf components in NavBar

* register TagNav

* fixing loading issues with navbar

* changed to exports

* export tag nav components and container

* export all ui components

Simply import component for tag item in tag list component

* Fix broken account dropdown

* fix icon button props

* fix cart panel, drawer, icon

* Fix broken product detail page

* export popover and popover content

* refactor NavBar container

* refactor and register CoreLayout

* set default value for hocs in replaceComponent

* set the display name on all registered components

* fix reactive updates in MainDropdown

* fix reactivity issue with currentRoute on logout

* add Link, NavLink, Prompt, withRouter to reaction-router plugin

* fix CartSubtotal component name

* cart components cleanup

* remove unused layout

* fix navbar reactivity

* Brand component cleanup

* remove unnecessary Tracker wrapper

* revert SortableTable components

* register all TagNav components

* don’t register DragDropProvider

* move babel config to babelrc

* clean up and register all email settings components

* set default Loading component for composeWithTracker

* fix export typos

* cleanup and register Auth and MainDropdown components

* register SMS plugin components

* update all composeWithTracker instances to use default Loading component

* make sure SMS package uses registered components

* refactor/register Alerts component

* start making components pure where possible

* refactor Divider component

* remove react-simple-di

* update React packages

* temporarily disable Jest tests

* make notifications components pure

* fix handlers in notification components

* register ProductAdmin components

* register MediaGallery with its container

* register PDP components

* fix textfield prop

* revert Select component to Component class because refs are being used

* add Reaction(ComponentName) display name identifier to all registered components

* register all product-variant components

* move components API to a plugin, add composeWithTracker to it

* add HOC’s for injecting currentUser, isAdmin, or isOwner into components

* remove unnecessary import

* sort modules

* remove plugin package.json for now

* separate components/containers by creating wrapComponent HOC

* add withCurrentAccount HOC and use in MainDropdown

* lint

* remove accidental commit of development experiment

* goodbye react-komposer

* fix import order

* package updates

* allow composeWithTracker to accept options or to disable the Loading component

* jsdoc update

* fix sortable MediaItem

* clean up composer

* turn SortableItem into a factory function so it can be used as a HOC

* separate ProductGridItems from its container

* revert babelrc

* depurify the translations component

* depurify Currency component

* thank you, magic Meteor imports folder

* separate out the Radium HOC from ReactionLayout and depurify it

* fix email settings components

* bump to 1.5.0

* fix npm sources
  • Loading branch information
jshimko authored and Aaron Judd committed Jul 25, 2017
1 parent f4ddf3e commit d9e6fb4
Show file tree
Hide file tree
Showing 254 changed files with 4,916 additions and 5,476 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
name: Restoring Meteor dev_bundle cache
key: dev_bundle

- run: npm test
# - run: npm test
- run: reaction test

- save_cache:
Expand Down
3 changes: 0 additions & 3 deletions client/modules/accounts/components/auth/index.js

This file was deleted.

1 change: 0 additions & 1 deletion client/modules/accounts/components/helpers/index.js

This file was deleted.

41 changes: 0 additions & 41 deletions client/modules/accounts/components/helpers/loginFormMessages.js

This file was deleted.

11 changes: 8 additions & 3 deletions client/modules/accounts/components/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
export { SignIn, SignUp, LoginButtons } from "./auth";
export { Forgot, UpdatePasswordOverlay } from "./passwordReset";
export { LoginFormMessages } from "./helpers";
export { default as ForgotPassword } from "./forgotPassword";
export { default as Login } from "./login";
export { default as LoginButtons } from "./loginButtons";
export { default as LoginFormMessages } from "./loginFormMessages";
export { default as MainDropdown } from "./mainDropdown";
export { default as SignIn } from "./signIn";
export { default as SignUp } from "./signUp";
export { default as UpdatePasswordOverlay } from "./updatePasswordOverlay";
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Components, registerComponent } from "@reactioncommerce/reaction-components";
import { Random } from "meteor/random";
import { composeWithTracker } from "/lib/api/compose";
import AuthContainer from "./authContainer";
import { ForgotContainer } from "../passwordReset";

class LoginContainer extends Component {
class Login extends Component {
static propTypes = {
credentials: PropTypes.object,
loginFormCurrentView: PropTypes.string,
uniqueId: PropTypes.string
}

static defaultProps = {
credentials: {},
loginFormCurrentView: "loginFormSignInView",
uniqueId: Random.id()
}

constructor(props) {
super(props);

Expand Down Expand Up @@ -51,7 +55,7 @@ class LoginContainer extends Component {
render() {
if (this.state.currentView === "loginFormSignInView" || this.state.currentView === "loginFormSignUpView") {
return (
<AuthContainer
<Components.AuthContainer
credentials={this.props.credentials}
uniqueId={this.props.uniqueId}
currentView={this.state.currentView}
Expand All @@ -62,7 +66,7 @@ class LoginContainer extends Component {
);
} else if (this.state.currentView === "loginFormResetPasswordView") {
return (
<ForgotContainer
<Components.ForgotPassword
credentials={this.props.credentials}
uniqueId={this.props.uniqueId}
currentView={this.state.currentView}
Expand All @@ -73,22 +77,6 @@ class LoginContainer extends Component {
}
}

function composer(props, onData) {
let startView = "loginFormSignInView";

if (props) {
if (props.startView) {
startView = props.startView;
}
}
const uniqueId = Random.id();
const credentials = {};

onData(null, {
loginFormCurrentView: startView,
uniqueId,
credentials
});
}
registerComponent("Login", Login);

export default composeWithTracker(composer)(LoginContainer);
export default Login;
32 changes: 32 additions & 0 deletions client/modules/accounts/components/loginFormMessages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import PropTypes from "prop-types";

const LoginFormMessages = (props) => {
if (props.loginFormMessages) {
if (props.formMessages.info) {
return (
<div className="alert alert-info">
<p>
{props.loginFormMessages()}
</p>
</div>
);
} else if (props.formMessages.alerts) {
return (
<div className="alert alert-danger">
<p>
{props.loginFormMessages()}
</p>
</div>
);
}
}
return null;
};

LoginFormMessages.propTypes = {
formMessages: PropTypes.object,
loginFormMessages: PropTypes.func
};

export default LoginFormMessages;
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Components } from "@reactioncommerce/reaction-components";
import { Reaction } from "/client/api";
import { Button, DropDownMenu, MenuItem, Translation } from "/imports/plugins/core/ui/client/components";
import { LoginContainer } from "../../containers/auth";
import { Translation } from "/imports/plugins/core/ui/client/components";
import Login from "./login";

const iconStyle = {
margin: "10px 10px 10px 6px",
Expand All @@ -20,7 +21,7 @@ const menuStyle = {
class MainDropdown extends Component {
static propTypes = {
adminShortcuts: PropTypes.object,
currentUser: PropTypes.oneOfType(
currentAccount: PropTypes.oneOfType(
[PropTypes.bool, PropTypes.object]
),
handleChange: PropTypes.func,
Expand All @@ -33,18 +34,18 @@ class MainDropdown extends Component {

buttonElement() {
return (
<Button containerStyle={{ color: "#000", fontWeight: "normal", letterSpacing: 0.8 }}>
<Components.Button containerStyle={{ color: "#000", fontWeight: "normal", letterSpacing: 0.8 }}>
<img className="accounts-img-tag" src={this.props.userImage} />&nbsp;
<span>{this.props.userName}</span>&nbsp;
<i className="fa fa-caret-down" />
</Button>
</Components.Button>
);
}

renderAdminIcons() {
return (
Reaction.Apps(this.props.adminShortcuts).map((shortcut) => (
<MenuItem
<Components.MenuItem
key={shortcut.packageId}
className="accounts-a-tag"
label={shortcut.label}
Expand All @@ -60,7 +61,7 @@ class MainDropdown extends Component {
renderUserIcons() {
return (
Reaction.Apps(this.props.userShortcuts).map((option) => (
<MenuItem
<Components.MenuItem
key={option.packageId}
className="accounts-a-tag"
label={option.label}
Expand All @@ -75,7 +76,7 @@ class MainDropdown extends Component {

renderSignOutButton() {
return (
<MenuItem
<Components.MenuItem
className="btn btn-primary btn-block accounts-btn-tag"
label="Sign out"
value="logout"
Expand All @@ -93,31 +94,29 @@ class MainDropdown extends Component {
className="accounts-dialog accounts-layout dropdown-menu pull-right"
style={{ padding: "10px 20px" }}
>
<LoginContainer />
<Login />
</div>
</div>
);
}

render() {
return (
<div>
{this.props.currentUser ?
<div className="accounts">
{this.props.currentAccount ?
<div style={{ paddingRight: 5 }}>
<DropDownMenu
<Components.DropDownMenu
buttonElement={this.buttonElement()}
attachment="bottom right"
targetAttachment="top right"
menuStyle={menuStyle}
className="accounts-li-tag"
onChange={this.props.handleChange}
>

{this.renderUserIcons()}
{this.renderAdminIcons()}
{this.renderSignOutButton()}

</DropDownMenu>
</Components.DropDownMenu>
</div>
:
<div className="accounts dropdown" role="menu">
Expand Down
2 changes: 0 additions & 2 deletions client/modules/accounts/components/passwordReset/index.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import _ from "lodash";
import React, { Component } from "react";
import PropTypes from "prop-types";
import { registerComponent, composeWithTracker } from "@reactioncommerce/reaction-components";
import { Meteor } from "meteor/meteor";
import { Accounts } from "meteor/accounts-base";
import { Router } from "/client/api";
import { composeWithTracker } from "/lib/api/compose";
import { SignIn, SignUp, LoginButtons } from "../../components";
import { MessagesContainer } from "../helpers";
import { ServiceConfigHelper } from "../../helpers";
import { SignIn, SignUp, LoginButtons } from "../components";
import MessagesContainer from "./messages";
import { ServiceConfigHelper } from "../helpers";
import { LoginFormSharedHelpers } from "/client/modules/accounts/helpers";
import { LoginFormValidation } from "/lib/api";

Expand All @@ -22,7 +22,7 @@ class AuthContainer extends Component {
super(props);

this.state = {
formMessages: props.formMessages,
formMessages: props.formMessages || {},
isLoading: false
};

Expand Down Expand Up @@ -210,12 +210,9 @@ class AuthContainer extends Component {
}

function composer(props, onData) {
const formMessages = {};

onData(null, {
formMessages,
currentRoute: Router.current()
});
onData(null, { currentRoute: Router.current() });
}

registerComponent("AuthContainer", AuthContainer, composeWithTracker(composer));

export default composeWithTracker(composer)(AuthContainer);
2 changes: 0 additions & 2 deletions client/modules/accounts/containers/auth/index.js

This file was deleted.

Loading

0 comments on commit d9e6fb4

Please sign in to comment.