Closed MAX-786 closed 2 months ago
@MAX-786 you got a video of it working where if you change pages in the frontend the sidebar changes so if.you click contents it is based on the current page you are looking at it.
@MAX-786 you got a video of it working where if you change pages in the frontend the sidebar changes so if.you click contents it is based on the current page you are looking at it.
Currently to change pages in the frontend you have to manually update the slug in the input field which will redirect you to that page in adminUI and this will update the sidebar too and if you click on the contents page it will show the contents of that pages.
https://github.com/collective/volto-hydra/assets/99530996/9f7c38a9-e2c3-4e76-b1c5-b1b72d63c717
I have also tried to update the adminUI when you move from one page to another inside iframe, this will send the postMessage to the parent frame with the updated url and parent listens to the messages and if the type of message is 'urlChange' it will update the adminUI url.
But the problem was frontend was setting the click event listener for each <a>
tag. I am thinking to find the different way achieve this.
Yep, tried this earlier it was giving permission denied. I'll look more into it
You might need to update CSP to allow it
On Mon, 3 June 2024, 10:38 pm Mohammad K. Hussain, @.***> wrote:
Yep, tried this earlier it was giving permission denied. I'll look more into it
— Reply to this email directly, view it on GitHub https://github.com/collective/volto-hydra/pull/38#issuecomment-2145533671, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAKFZHDXP6IBFTQDT7FETLZFSEV7AVCNFSM6AAAAABIVC7GMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBVGUZTGNRXGE . You are receiving this because you commented.Message ID: @.***>
@MAX-786 just to be clear. Watching the url change is the only feasible way to solve this I think since you can't possibly know what kinds of ways the page will change. So it's a waste of time looking into a links. So you have to solve the CORS issue and that is probably needed going forward for the iframe bridge and other things anyway.
So it's a waste of time looking into a links. So you have to solve the CORS issue and that is probably needed going forward for the iframe bridge and other things anyway.
The CORS issue can be solved by allowing those origin explicitly. I'll push the code how i did it.
So iframeBridge would use postMessage
which would enable 2 way comm. We can use that for tracking url changes in the iframe too. And use the message
event to handle it.
It is also updating the adminUI to show the content of the page which iframe has just navigated to.
https://github.com/collective/volto-hydra/assets/99530996/b591d964-9ccb-49d1-aedd-3868acca1c11
BUT for CORS, we should make sure to properly assign the targetOrgin
in postMessage on frontend side and check the origin of message
while handling messages in adminUI side. (For now hardcoded these but later on we can use env or anyother way to set them according to developer)
Yes later on the ifrajebridge can we used to track the url changes but the idea is always to offer the option for the least amount of effort for the integrators part. The idea is still to offer a iframebridge free version that requires almost no integration code but still works but in a much more limited UX for the editor. So requiring the iframebridge for the most basic version is not ideal unless that is the only way.
@MAX-786 in the video there seems to be a reload of the whole admin UI when the page changes. Why?
The idea is still to offer a iframebridge free version that requires almost no integration code but still works but in a much more limited UX for the editor. So requiring the iframebridge for the most basic version is not ideal unless that is the only way.
Yeah I looked but to access iframe.contentWindow
both needs to be on same domain, which is not always true. Thats why this approach is what I thought would be feasible.
@MAX-786 in the video there seems to be a reload of the whole admin UI when the page changes. Why?
To update to the content of the adminUI, directly navigating it to the same path as of the iframe bcz as we discussed that we are assuming frontend would be folderish type. But to update the content of the adminUI without navigation, is by dispatching the redux action and updating the redux store, which will update the content page and sidebar also.
@MAX-786 ok. If post message is the only way then that's how it will have to be. Please start to document what the integrator has to do to get this working in the readme.
The reload explanation I didn't understand. If the ifrsme page changes then the admin UI should change via redux and not a full ssr reload. If that's what you've done then great.
The reload explanation I didn't understand. If the ifrsme page changes then the admin UI should change via redux and not a full ssr reload. If that's what you've done then great.
For now, I am updating the adminUI url to the same as iframe by changing the host, and the content fetching on the adminUI is already done by itself based on updated URL. And yeah the redux approach what i said is I have done on different branch bcz there's some errors I am having, once they are fixed I'll update it replacing this approach.
something like this is happening right now in adminUI whenever iframe src is updated:
const handleNavigateToUrl = (givenUrl = '') => {
// Update adminUI URL with the new URL
const formattedUrl = url ? new URL(url) : new URL(givenUrl);
formattedUrl.host = 'localhost:3000';
window.location.href = window.location.pathname.endsWith('/edit')
? `${formattedUrl.href}/edit`
: formattedUrl.href;
};
@MAX-786 let me know when it works for any frontend, then can merge and deploy it
Addding this snippet in script tag or in layout.js of any frontend, will connect it with the adminUI. (assuming volto is running on 3000).
window.navigation.addEventListener("navigate", (event) => {
parent.postMessage({type: 'URL_CHANGE', url: event.destination.url}, 'http://localhost:3000');
})
@MAX-786 I think you need to put this into the start of the iframe bridge. ie the instructions should be, add a script tag to load our iframebridge/connector and thats all you have to do. Can this js code be loaded from the demo server to being with or does it need to be a published npm package?
@MAX-786 also this the place where instructions to the frontend developer/integrator should go. https://github.com/collective/volto-hydra/pull/38/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R3. in the readme.
Can this js code be loaded from the demo server to being with or does it need to be a published npm package?
It has to be added by integrator in the frontend and it doesn't need to be a package for now.
Please check this out, and let me know what do you think.
https://github.com/collective/volto-hydra/tree/update-readme
Please check this out, and let me know what do you think.
https://github.com/collective/volto-hydra/tree/update-readme
@MAX-786 Iif you make a pull request against main
from the update-readme
branch, then people can provide a proper review.
@MAX-786 yes it's a good start. but I'd suggest the following changes
<script src="https://hydra.pretagov.com/editor.js"/>
@MAX-786 Iif you make a pull request against main from the update-readme branch, then people can provide a proper review.
Sure, thanks.
the curent code for enabling the editing is too complex. it should be just including a script. Remember the goal is always to make this easy for integrators so the less code and complexity and explanation then the better you are doing. it should be as easy as
So should i put this script codesnippet in a file, and tell the integrator to add this script tag? Just clarifying it more.
put in links to the roadmap to show what currently works and what doesn't. You might need to explain more explictly you can do at this point and how going forward more apis will be added to enable more editing experience.
Oh ok means directly linking to the issues in the roadmap which are done and working and also listing what might be added in future.
put in using https://hydra.pretagov.com/ (demo server) as the first option to test out against as it's simplest, then have building your own hydra as an alternative option.
sure, makes more sense for providing a demo.
Put in the url of where you test frontend is deployed so people can test that without running anything local
Yep got it deployed but needs a deployed plone backend too (right now showing 404 here) . So this https://hydra.pretagov.com/ (demo site) must be connected to a backend, should'nt frontend and adminUI be connected to same plone backend? That's why I'll need access to it, so I can access content for the nextjs-frontend.
And if i deploy my seperate plone backend for the frontend then I have to connect this demo site with it.
@MAX-786
So should i put this script codesnippet in a file, and tell the integrator to add this script tag? Just clarifying it more.
yes. this is the start of the iframebridge code. That will be lib they can include in their project that will where all the editing functionality will come from and they will need to register events from.
Yep got it deployed but needs a deployed plone backend too (right now showing 404 here) . So this https://hydra.pretagov.com/ (demo site) must be connected to a backend, should'nt frontend and adminUI be connected to same plone backend? That's why I'll need access to it, so I can access content for the nextjs-frontend.
yes. the demo backend. you will need to deploy your demo frontend so it connects back to the hydra demo backend, https://hydra.pretagov.com/++api++ And anyone else wanting to follow along with the progress will need to be instructed to do the same. Then they log into admin ui https://hydra.pretagov.com/login and put in the url of their deployed frontend and go ahead and edit it.
Css is fixed and now whole page is not reloaded when navigating in the iframe.
https://github.com/collective/volto-hydra/assets/99530996/2a51bb8f-217d-40ae-ab83-2d6b774418db
Currently this PR provides the following features:
You can:
provide the frontend URL and preview it.
navigate in iframe then adminUI url and the content of the sidebar will get updated based on the src of the iframe.
click on edit button, change the title of the page and save it. Title of the page will be updated. (same for the shortname)
click on content view to have a simpler view of contents (pages, files etc.) of that page.
click on 'View' option to in the content view to preview that page.
Assumptions:
Fixes #8 Fixes #7 Fixes #9 Fixes #12 Fixes #13 Fixes #17 Fixes #15 Fixes #18 Fixes #10
Usage
Approach
View.jsx
&Form.jsx
to Show iframe component.Problems