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

Bold preview #176

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quintype/components",
"version": "2.27.2",
"version": "2.27.3-bold-preview.2",
"description": "Components to help build Quintype Node.js apps",
"main": "dist/cjs/index.js",
"module": "dist/es/index.js",
Expand Down
23 changes: 13 additions & 10 deletions src/components/with-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";

/**
* This higher order function can be used for the home or story page preview. It takes a component, and a function to map the story into props suitable for the component
*
*
* Preview in the Quintype CMS works by sending a postMessage to an iframe every time the story changes. This file abstracts this for you, and will just render the given component
*
* Example
Expand Down Expand Up @@ -36,20 +36,23 @@ export function WithPreview(klazz, updateData) {
}

componentDidMount() {
global.addEventListener("message", event => {
if (event.data && event.data.action == 'reloadStory' && event.data.story) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. The bold issue occurs only for whoever is using the WithPreview component from quintype-node-components.
  2. Initially we were getting event.data.action as reloadStory, but as we debugged we are now getting sendStoryToIframe .
  3. Then it is recommended to test with this version.
  4. We need to now test if the preview is working on tq/malibu for both home and story.
  5. If it works, we will have to confirm with the platform team if event.data.action is set to sendStoryToIframe.(Akshay Gupta and Prabu has some context on this)
  6. If not there are 2 solutions:
    a. Platform will have to debug from where the sendStoryToIframe is coming from.
    b. We will have to check and validate if only event.data && event.data.story checks are sufficient.(Confirm with Ram/Amogh)

this.setState({ story: event.data.story })
global.addEventListener("message", (event) => {
if (event.data && event.data.story) {
this.setState({ story: event.data.story });
}
});
}

render() {
if(!this.state.story) {
return <div style={{minHeight: 200}} />
if (!this.state.story) {
return <div style={{ minHeight: 200 }} />;
}
return React.createElement(klazz, Object.assign({}, this.props, {
data: updateData(this.props.data, this.state.story)
}))
return React.createElement(
klazz,
Object.assign({}, this.props, {
data: updateData(this.props.data, this.state.story),
})
);
}
}
};
}