-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix/update cms component with meta data #2159
Fix/update cms component with meta data #2159
Conversation
This update ensures that CMS editable content actually has a way of making it to the store front, so admins aren't confused why content isn't changing
…omponent_with_meta_data
Otherwise it will affect the home page too, which is likely undesirable
…omponent_with_meta_data
|
content = ( | ||
<> | ||
<Title>{data.cmsPage.title}</Title> | ||
{data.cmsPage.content_heading !== '' && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For readability, we avoid multiline JSX expressions, since they defeat the readability advantages of JSX. Try extracting this to a const
.
const { content_heading, title } = data.cmsPage
// conditionally define an element
// note that the alternative is null, not undefined
const headingElement = content_heading ? (
<h1>
{content_heading}
</h1>
) : null
// more readable without the conditional expression in brackets
const content = foo ? (
<Fragment>
<Title>{title}</Title>
{headingElement}
</Fragment>
) : (
<CategoryList />
)
/* ... */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jimbo, I would have to disagree with this approach being better for readability, I'm very much disliking having to work with the code that's been broken up like this when molding PWA Studio to my needs. In saying that, I'll happily make the changes to match Magento's standards
@@ -35,7 +35,17 @@ const CMSPage = props => { | |||
data.cmsPage.content.length > 0 && | |||
!data.cmsPage.content.includes('CMS homepage content goes here.') | |||
) { | |||
content = <RichContent html={data.cmsPage.content} />; | |||
content = ( | |||
<> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but we prefer <Fragment>
. Be sure to import it at the top.
import React, { Fragment } from "react"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to make this update, but would just like to point out that the only reason I used the shorthand here is because I thought Magento were preferring it, as it's used in many files in PWA Studio. A simple Find In Files in the codebase will find 8 other places that the shorthand is used, including the very file that I've edited
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I started out liking React.Fragment
but found a typo broke the whole build with a non-helpful error. We ended up switcing everything to Fragment
destructured because that error is dev-traceable.
And we specifically avoided <>
because at least one major editor (Atom) doesn't understand how to auto-close tags with no node-name, which is frustrating.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing! I totally agree, I much prefer seeing <Fragment>
rather than the magic <>
. I just wanted to point out the use of the shorthand because I'm being told that the full tag is preferred, when in the actual component I'm editing it's clearly not being used. If the decision has been made since this code was written, that's totally fine, but just need to make sure we're aware of these sort of things when making statements like X is preferred over Y
<> | ||
<Title>{data.cmsPage.title}</Title> | ||
{data.cmsPage.content_heading !== '' && ( | ||
<h1 className="cms__content-heading"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have use global classnames in our components, and we don't target them with global CSS. If you'd like to render this element with some styles, consider defining a .heading
classname in cms.css
.
If styles are not being imported in this component yet, have a look at another component in the codebase to see how to import them, merge the classes, and apply them to elements. Something like the following:
import defaultClasses from "./cms.css"
const CMSPage = props => {
const classes = mergeClasses(defaultClasses, props.classes)
return (
<div className={classes.root} />
)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, can make this update
…omponent_with_meta_data
Wrapping a big chunk of code in an if block is poor for readability
Includes removing an import of the prop type `number`, which wasn't being used anywhere. Elected to only accept `heading` as a property in the `classes` prop as that is the only class that is going to be used. Even though there is a cms.css file in the same directory, it wasn't being used previously, therefore I don't know what its purpose is, so I'm just playing it safe and leaving the code base as unchanged from my direct change.
Thanks for the review @jimbo, I've made the requested changes now and this is ready for a second review. Thanks! |
@jimbo Just wanted to bump this, as I've implemented the requested changes |
@luke-denton-aligent - There is a prettier failure (packages/venia-ui/lib/RootComponents/CMS/cms.js) and home page does not load at https://pr-2159.pwa-venia.com/ ( tried on my local as well |
Hi @dpatil-magento, thanks for the feedback. I've just loaded up the PR URL, and while I'm also seeing as red banner, I don't see any errors in the console. It would be really great if the screenshot of devtools wasn't cut off - we can't currently see where that reference error is being thrown |
@@ -1,12 +1,12 @@ | |||
import React, { Fragment } from 'react'; | |||
import { shape, string } from 'prop-types'; | |||
import { number, shape, string } from 'prop-types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks!
@luke-denton-aligent - Those PR instances are in production mode that have terser suppressing all console logs, so @dpatil-magento must have grabbed that locally, sorry for the confusion. This was just a tiny import missing and needing |
Description
This PR updates the cms.js component to make use of
data.cmsPage.title
anddata.cmsPage.content_heading
, that otherwise seems to be ignored.I have placed the
<Title>
and<h1>
in this location so that it doesn't affect the home page. I am by no means saying this is the perfect place to put it, I'm very open to suggestions of where to move these elements, but I think they should be included somewhere.I have attached a couple of screenshots, showing an "about-us" page with and without this update. In the "before" screenshot, we can see how hard it is to determine which page we're on, especially if we have multiple tabs open on the storefront.
The classname given to the
<h1>
is also a bit of a guess, so I'm open to updating this to better suit.Related Issue
Closes #2158.
Acceptance
Verification Stakeholders
Specification
Verification Steps
Screenshots / Screen Captures (if appropriate)
Before Update

After Update
