-
Notifications
You must be signed in to change notification settings - Fork 142
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
[V3] Update Page Designer #1128
Changes from 10 commits
f87be2c
83f5d54
787a1df
88d40c3
0fd0463
05cbea5
f119274
8342b58
f34999e
90e8428
7fb2d35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,10 +7,12 @@ | |||||||||
|
||||||||||
--- | ||||||||||
|
||||||||||
This folder contains React components and utilities that render pages from [Page Designer](https://documentation.b2c.commercecloud.salesforce.com/DOC2/topic/com.demandware.dochelp/content/b2c_commerce/topics/page_designer/b2c_creating_pd_pages.html). | ||||||||||
This folder contains the React components used when rendering the pages from [Page Designer](https://documentation.b2c.commercecloud.salesforce.com/DOC2/topic/com.demandware.dochelp/content/b2c_commerce/topics/page_designer/b2c_creating_pd_pages.html). | ||||||||||
|
||||||||||
Use this folder to add React components that can render Page Designer components that have been serialized to JSON. | ||||||||||
|
||||||||||
> NOTE: If you are creating components that do not already exist in Page Designer, follow [this](https://documentation.b2c.commercecloud.salesforce.com/DOC1/index.jsp) guide to first create your Page Designer components before creating their matching PWA-Kit React components. | ||||||||||
|
||||||||||
This folder includes components for layout and visualization of images, grids, and carousels. | ||||||||||
|
||||||||||
**By default, Page Designer integration is not enabled in the Retail React App.** Additionally, to utilize the `shopperExperience` | ||||||||||
|
@@ -20,8 +22,7 @@ for more information on configuring your SLAS client. | |||||||||
|
||||||||||
## Folder Structure | ||||||||||
|
||||||||||
- **`/core`** - Base components for rendering: `<Page>`, `<Region>`, and `<Component>`. Use `<Page>` to render Page Designer content. Use `<Region>` and `<Component>` for creating new assets. | ||||||||||
- **`/assets`** - Non-visual components used in Page Designer. Includes `<Image>` and `<ImageWithText>` as well as any other Page Designer assets that you want to use in your PWA-Kit app. If you need to visualize a component, add it here. | ||||||||||
- **`/assets`** - Visual components used in Page Designer. Includes `<Image>` and `<ImageWithText>` as well as any other Page Designer assets that you want to use in your PWA-Kit app. If you need to visualize a component, add it here. | ||||||||||
- **`/layouts`** - Components responsible for layout. Includes various grids and a `<Carousel>` component. | ||||||||||
|
||||||||||
## Sample Usage | ||||||||||
|
@@ -32,8 +33,10 @@ Create a new file called `app/pages/page-viewer/index.jsx`, and add the followin | |||||||||
// app/pages/page-viewer/index.jsx | ||||||||||
|
||||||||||
import React from 'react' | ||||||||||
import {useParams} from 'react-router-dom' | ||||||||||
import {Box} from '@chakra-ui/react' | ||||||||||
import {Page, pageType} from '../../page-designer' | ||||||||||
import {usePage} from 'commerce-sdk-react-preview' | ||||||||||
import {Page} from 'commerce-sdk-react-preview/components' | ||||||||||
import {ImageTile, ImageWithText} from '../../page-designer/assets' | ||||||||||
import { | ||||||||||
Carousel, | ||||||||||
|
@@ -59,32 +62,24 @@ const PAGEDESIGNER_TO_COMPONENT = { | |||||||||
'commerce_layouts.mobileGrid3r2c': MobileGrid3r2c | ||||||||||
} | ||||||||||
|
||||||||||
const PageViewer = ({page}) => ( | ||||||||||
<Box layerStyle={'page'}> | ||||||||||
<Page page={page} components={PAGEDESIGNER_TO_COMPONENT} /> | ||||||||||
</Box> | ||||||||||
) | ||||||||||
|
||||||||||
PageViewer.getProps = async ({api, params}) => { | ||||||||||
const {pageId} = params | ||||||||||
const page = await api.shopperExperience.getPage({ | ||||||||||
parameters: {pageId} | ||||||||||
}) | ||||||||||
|
||||||||||
if (page.isError) { | ||||||||||
let ErrorClass = page.type?.endsWith('page-not-found') ? HTTPNotFound : HTTPError | ||||||||||
throw new ErrorClass(page.detail) | ||||||||||
const PageViewer = () => { | ||||||||||
const {pageId} = useParams() | ||||||||||
const {data: page, error}= usePage({parameters: {pageId}}) | ||||||||||
|
||||||||||
if (error) { | ||||||||||
let ErrorClass = error.response?.status === 404 ? HTTPNotFound : HTTPError | ||||||||||
throw new ErrorClass(error.response?.statusText) | ||||||||||
} | ||||||||||
|
||||||||||
return {page} | ||||||||||
return ( | ||||||||||
<Box layerStyle={'page'}> | ||||||||||
<Page page={page} components={PAGEDESIGNER_TO_COMPONENT} /> | ||||||||||
</Box> | ||||||||||
) | ||||||||||
} | ||||||||||
|
||||||||||
PageViewer.displayName = 'PageViewer' | ||||||||||
|
||||||||||
PageViewer.propTypes = { | ||||||||||
page: pageType.isRequired | ||||||||||
} | ||||||||||
|
||||||||||
export default PageViewer | ||||||||||
``` | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: You may want to mention, for people unfamiliar with react-router, the route needs to be added before the catch-all route. pwa-kit/packages/template-retail-react-app/app/routes.jsx Lines 100 to 103 in 83f5d54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I feel like at this point in time the developer should be aware as to what a router is and how it's used by going through the doc's on developer.salesforce.com. I'm hesitant to add router specific documentation outside of the context of the router incase it ever changes we might have to go back and change all the other doc's instead of only changing one place. |
||||||||||
|
This file was deleted.
This file was deleted.
This file was deleted.
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.
Nit: At the end.
pwa-kit/packages/template-retail-react-app/app/page-designer/README.md
Line 102 in 0fd0463
...by providing their
pageid
defined in Bussiness Manager.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.
Thats clearer. Thanks