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 iframes in legacy widget preview. #14643

Merged
merged 7 commits into from
Sep 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't hardcode preview URL
  • Loading branch information
adamziel committed Sep 18, 2020
commit 43ec0cc94562b9ac4a1ec452aa0f55b0fe0c5ee5
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { get } from 'lodash';
*/
import { addQueryArgs } from '@wordpress/url';
import { Disabled, FocusableIframe } from '@wordpress/components';
import { withSelect } from '@wordpress/data';
import { useState } from '@wordpress/element';

function WidgetPreview( { postLink, widgetAreaId, attributes, ...props } ) {
function WidgetPreview( { widgetAreaId, attributes, ...props } ) {
const DEFAULT_HEIGHT = 300;
const HEIGTH_MARGIN = 20;
const HEIGHT_MARGIN = 20;
const [ height, setHeight ] = useState( DEFAULT_HEIGHT );
const iframeUrl = addQueryArgs( postLink, {
const currentUrl = document.location.href;
const siteUrl = currentUrl.substr( 0, currentUrl.indexOf( 'wp-admin/' ) );
Copy link
Contributor

@adamziel adamziel Sep 18, 2020

Choose a reason for hiding this comment

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

Anyone aware of any better way of getting site's URL?

Copy link
Member

Choose a reason for hiding this comment

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

It is available in the REST API index at wp-json.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually there is another place in navigation editor that could also use this correction - let's address both in a separate PR

const iframeUrl = addQueryArgs( siteUrl, {
widgetPreview: {
...attributes,
sidebarId: widgetAreaId,
Expand All @@ -36,16 +37,11 @@ function WidgetPreview( { postLink, widgetAreaId, attributes, ...props } ) {
}
} }
src={ iframeUrl }
height={ height + HEIGTH_MARGIN }
height={ height + HEIGHT_MARGIN }
{ ...props }
/>
</Disabled>
);
}

export default withSelect( () => {
return {
// @TODO: Don't hardcode preview URL
postLink: '/?p=1',
};
} )( WidgetPreview );
export default WidgetPreview;