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

Use React components for footer and header #3257

Merged
merged 10 commits into from
Nov 20, 2017

Conversation

prinzdezibel
Copy link
Contributor

@prinzdezibel prinzdezibel commented Nov 8, 2017

This changeset is about using React components for header and footer.
Additionally, the old way of customizing parts of the layout is retained,
namely to use registry's layout structure to decide on a per-workflow
basis which footer & header component is choosen.

If this prooves to be unnecessary, we could eliminate that part
altogether. This changeset is also about ensuring feature-parity with old
system:

                         |      Old:                |   New:
-------------------------+--------------------------+--------------------------
 Replacing components    | Template.replace         |   replaceComponent
    in general           |                          |
-------------------------+--------------------------+--------------------------
 Replacing parts of      | layoutHeader designates  | layoutHeader designates
    layout per workflow  |   Blaze template name    |   React comp's name
                         | layoutFooter designates  | layoutFooter designates
                         |   Blaze template name    |   React comp's name

      1) layoutHeader
         This template was used for most cases (coreLayout). But since
         coreLayout.js does include the new Components.NavBar React
         component, it's obsolete
      2) checkoutHeader
         This was a customized version of the header for the checkout
         workflow. Nowadays the checkout workflow also uses the standard
         NavBar component. Therefore it's obsolete, too.
Additionally, the old way of customizing parts of the layout is retained,
namely to use registry's layout structure to decide on a per-workflow
basis which footer & header component is choosen.

If this prooves to be unnecessary, we could eliminate that part
altogether. This changeset only does ensure feature-parity with old
system:

                         |      Old:                |   New:
-------------------------+--------------------------+--------------------------
 Replacing components    | Template.replace         |   replaceComponent
    in general           |                          |
-------------------------+--------------------------+--------------------------
 Replacing parts of      | layoutHeader designates  | layoutHeader designates
    layout per workflow  |   Blaze template name    |   React comp's name
                         | layoutFooter designates  | layoutFooter designates
                         |   Blaze template name    |   React comp's name
@@ -50,7 +50,7 @@ Reaction.registerPackage({
enabled: true,
structure: {
template: "dashboardPackages",
layoutHeader: "layoutHeader",
layoutHeader: "NavBar",
Copy link
Member

Choose a reason for hiding this comment

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

Any time these values change, you'll need to write a migration. This goes for all the register.js files modified.

Migrations can be found in /imports/plugins/core/versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks. I've written a migration for it.

return (
<div className={pageClassName} id="reactionAppContainer">
<Components.NavBar />

{ headerComponent && React.createElement(headerComponent, {}) }
Copy link
Member

Choose a reason for hiding this comment

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

No extra space with the {} in JSX templates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Btw, is this enforced by eslint?

import { registerComponent } from "/imports/plugins/core/components/lib";
import { Reaction } from "/client/api";

const Footer = () =>
Copy link
Member

Choose a reason for hiding this comment

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

Always wrap arrow functions in () or {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I'm assuming you mean like this:

const Footer = () => (
  <div/>
);

@@ -21,11 +21,11 @@
{{> Template.dynamic template=template}}
Copy link
Member

Choose a reason for hiding this comment

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

Do we even need this file anymore? This should no longer be used, as it's been replaced with React components app.js (located in core/ui package) and coreLayout.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 think not, as i've stated in the getFooterComponent helper function. I'm going to delete this file.

@@ -10,6 +10,7 @@ import ToolbarContainer from "/imports/plugins/core/dashboard/client/containers/
import Toolbar from "/imports/plugins/core/dashboard/client/components/toolbar";
Copy link
Member

Choose a reason for hiding this comment

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

Do we even need this file anymore? I think all of this has been moved to various react components.

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 think not, as i've stated in the getFooterComponent helper function. I'm going to delete this file.

layoutFooter: "",
// layoutFooter: "Footer", // TODO: decide if it's desirable to display standard footer in product grid for a stock installation
Copy link
Member

Choose a reason for hiding this comment

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

No commented code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deleted comment. layout is retained as was, e.g. no footer will be displayed.

@@ -0,0 +1,19 @@
import React from "react";
Copy link
Member

Choose a reason for hiding this comment

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

Adding a footer requires design direction from @rymorgan since for the longest time, we've not had one displayed. And the question is, should we even be adding visible one now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Footer should not be displayed anywhere, if it wasn't already before..
Right now it's nothing more than an exemplary placeholder that's available for usage when implementing plugins.

Copy link
Contributor Author

@prinzdezibel prinzdezibel Nov 8, 2017

Choose a reason for hiding this comment

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

But then, a plugin would have its own requirements on how the Footer is supposed to be rendered. Maybe it's just unnecessary to have it in its own place.


const Footer = () =>
<div className="reaction-navigation-footer footer-default">
<nav className="navbar-bottom " role="navigation">
Copy link
Member

Choose a reason for hiding this comment

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

extra space in quote "navbar-bottom "

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@prinzdezibel
Copy link
Contributor Author

@mikemurray Changes implemented. Btw, is there a button or something to signal you, when I've done the requested changes? Or how is your workflow regarding review->change->review cycle?

@mikemurray
Copy link
Member

@prinzdezibel there is no magic ping button other than [at]-ing someone in a comment, they noticing changes to the PR / branch, or notifying directly.

I'll take a look at this soon.

Copy link
Member

@mikemurray mikemurray left a comment

Choose a reason for hiding this comment

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

Getting this error on an existing app on the homepage

layoutHeader not registered.
    at _getComponent (app.js:102296)
    at CoreLayout (app.js:61466)
    at modules.js:108189
    at measureLifeCyclePerf (modules.js:107959)
    at ReactCompositeComponentWrapper._constructComponentWithoutOwner (modules.js:108188)
    at ReactCompositeComponentWrapper._constructComponent (modules.js:108163)
    at ReactCompositeComponentWrapper.mountComponent (modules.js:108071)
    at Object.mountComponent (modules.js:100902)
    at ReactCompositeComponentWrapper.performInitialMount (modules.js:108254)
    at ReactCompositeComponentWrapper.mountComponent (modules.js:108141)

@prinzdezibel
Copy link
Contributor Author

@mikemurray Sorry, I've forgotten to also migrate the Shops collection and additionally there were an error with my previous attempt. (using Packages.update(id,..., { validate: false})

I was ensuring that migration was executing properly, but only in RoboMongo. Should have tested it better. Sorry for that.

@prinzdezibel
Copy link
Contributor Author

@mikemurray Hi Mike, maybe you can have another look into it. should work as suspected now.

@mikemurray
Copy link
Member

@prinzdezibel looking now

Copy link
Member

@mikemurray mikemurray left a comment

Choose a reason for hiding this comment

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

Getting the following error:

Uncaught Error: Component checkoutHeader not registered.
    at _getComponent (components.js:92)
    at CoreLayout (coreLayout.js:16)
    at modules.js?hash=1d95b8a00969795e9c25b7e6569113f786616bf2:108189
    at measureLifeCyclePerf (modules.js?hash=1d95b8a00969795e9c25b7e6569113f786616bf2:107959)
    at ReactCompositeComponentWrapper._constructComponentWithoutOwner (modules.js?hash=1d95b8a00969795e9c25b7e6569113f786616bf2:108188)
    at ReactCompositeComponentWrapper._constructComponent (modules.js?hash=1d95b8a00969795e9c25b7e6569113f786616bf2:108163)
    at ReactCompositeComponentWrapper.mountComponent (modules.js?hash=1d95b8a00969795e9c25b7e6569113f786616bf2:108071)
    at Object.mountComponent (modules.js?hash=1d95b8a00969795e9c25b7e6569113f786616bf2:100902)
    at ReactCompositeComponentWrapper.performInitialMount (modules.js?hash=1d95b8a00969795e9c25b7e6569113f786616bf2:108254)
    at ReactCompositeComponentWrapper.mountComponent (modules.js?hash=1d95b8a00969795e9c25b7e6569113f786616bf2:108141)

Checkout header is used, needs to be converted to react. #3255

@rymorgan
Copy link
Contributor

rymorgan commented Nov 14, 2017

@prinzdezibel I don't think we should be working on a footer w/out thinking of what the broader approach to having a footer? Can you outline your plan for adding a footer is in this PR? Are you going to add an empty footer that will make it easier down the line when we're ready to add a footer option for admins?

@prinzdezibel
Copy link
Contributor Author

@rymorgan Right now the Footer is just a placeholder that basically doesn't (read: should not do) anything. As long as the footer was not shown before in any of the available views/routes, it also will not be displayed now. It's purpose is more to serve as hint for plugin developers/ customers on how to override/use this Footer. Albeit the footer is really just a link to the root URL, a.k.a. home. It's not useful to use as off-the-shelf component - really it's more the starting point that's getting copied from the developer into his custom plugin directory and modded there.

Maybe it can serve as base for later plans, when we're going to offer Footer - Declarations through the Admin-UI (if you meant that – not sure), but then again: We're talking about 10 lines of code. Not really something of substance.

@prinzdezibel
Copy link
Contributor Author

After talking to @mikemurray it seems that the migration has failed, because it was locked in db. Now for the PR to work it's absolutely necessary that the migrations run.
After removing the lock, the migration worked as expected.

@rymorgan
Copy link
Contributor

@prinzdezibel That makes sense 👍

@prinzdezibel
Copy link
Contributor Author

prinzdezibel commented Nov 15, 2017

@mikemurray Please give it another try from a fresh master with this feature branch merged into.
(Reverse migration will not work 100%, because the migration's inverse function isn't lossless. Not sure if I should invest more time into that)

Copy link
Member

@mikemurray mikemurray left a comment

Choose a reason for hiding this comment

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

Other than the comments above, I like your updates the navbar for visibility

@@ -36,4 +37,23 @@ function composer(props, onData) {

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

registerComponent("NavBarCheckout", (props, context) => {
Copy link
Member

Choose a reason for hiding this comment

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

One component per file. Also, separate the registration of the component and the definition of the component like we do in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

<div className="reaction-navigation-footer footer-default">
<nav className="navbar-bottom" role="navigation">
<div className="row">
<a href={Reaction.Router.pathFor("/")}>Home</a>
Copy link
Member

Choose a reason for hiding this comment

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

Remove this link for now. This template is valuable to have from a replaceComponent standpoint, but the link shows up and doesn't look good.

The below is the profile page.

account_profile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, removed the link from the component.

- One component per file
- Separate component and hoc container
- Remove link  from Footer component
@prinzdezibel
Copy link
Contributor Author

prinzdezibel commented Nov 16, 2017

@mikemurray Hope that's ok now. Thanks for your time!

mikemurray
mikemurray previously approved these changes Nov 16, 2017
@mikemurray
Copy link
Member

@prinzdezibel looks good but you have some linting issues.

@mikemurray
Copy link
Member

@prinzdezibel I went ahead and fixed the linting issues. Adding @zenweasel as a reviewer to take it over the line if necessary.

@brent-hoover
Copy link
Collaborator

brent-hoover commented Nov 17, 2017

@rymorgan
I know some of this discussion happened on the previous PR but just triple checking that we are cool with this change to the checkout header with just the "home" link?
cart_checkout

as opposed to this on master
cart_checkout

@rymorgan
Copy link
Contributor

@zenweasel Yep, we're reverting back to how it was originally. Navigation at checkout is a conversion no-no.

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.

I saw one React error but have not been able to reproduce it so I removed that comment. Tested with the fixed version of the example-plugin and all works great. Nice work!

@prinzdezibel
Copy link
Contributor Author

@mikemurray thanks for the fixing the linting errors. I'm still not familiar with my new IDE.

@spencern spencern changed the base branch from master to release-1.5.9 November 20, 2017 23:46
@spencern spencern merged commit 0d8030e into release-1.5.9 Nov 20, 2017
@spencern spencern deleted the michael-use-react-for-footer-and-header branch November 20, 2017 23:46
@spencern spencern mentioned this pull request Nov 21, 2017
@ghost
Copy link

ghost commented Dec 1, 2017

Previously, I use custom footer template to replace core footer template.

Template.my_custom_footer.replaces("layoutFooter")

Then I updated Reaction it's self with some "fix" release.
Then my footer disappear, cause no more template base footer.

If you guys made some changes that break some thing, please do not put it under "Fixes".
Fix do not mean to break some things(generally.

image

Peace ✌️

@brent-hoover
Copy link
Collaborator

@yiwan In the future how do you think we could do a better job of communicating "breaking" changes? We have an ongoing project to replace Blaze components with React which will shortly result in the complete elimination of Blaze.

@ghost
Copy link

ghost commented Dec 1, 2017

image

Just give breaking change a Big and Bold styled section.
It would be better not mixing with other bug fix.

P.S.
I saw the plan, switch to React which I think it's cool.

Akarshit pushed a commit that referenced this pull request Jan 7, 2018
…footer-and-header

Use React components for footer and header
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants