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

Collapse classic meta boxes under details element #64247

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 23 additions & 2 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,28 @@ function useEditorStyles() {
] );
}

function MetaBoxesDetails() {
const hasMetaboxes = useSelect( ( select ) => {
const { getMetaBoxesPerLocation } = select( editPostStore );
return (
getMetaBoxesPerLocation( 'normal' ).length > 0 ||
getMetaBoxesPerLocation( 'advanced' ).length > 0
);
}, [] );
if ( ! hasMetaboxes ) {
return null;
}
return (
<details className="edit-post-layout__metaboxes-details">
<summary className="edit-post-layout__metaboxes-details-summary">
{ __( 'Meta Boxes' ) }
</summary>
<MetaBoxes location="normal" />
<MetaBoxes location="advanced" />
</details>
);
}

function Layout( {
postId: initialPostId,
postType: initialPostType,
Expand Down Expand Up @@ -361,8 +383,7 @@ function Layout( {
! isDistractionFree &&
showMetaBoxes && (
<div className="edit-post-layout__metaboxes">
<MetaBoxes location="normal" />
<MetaBoxes location="advanced" />
<MetaBoxesDetails />
</div>
)
}
Expand Down
23 changes: 23 additions & 0 deletions packages/edit-post/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
clear: both;
}

.edit-post-layout__metaboxes-details {
background: $white;
border-top: $border-width solid $gray-200;
}

.edit-post-layout__metaboxes-details[open] {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}

.edit-post-layout__metaboxes-details summary {
cursor: pointer;
color: $gray-900;
height: 24px;
line-height: 24px;
font-size: 13px;
list-style-position: outside;
margin-left: 24px;
}

// Adjust the position of the notices
.components-editor-notices__snackbar {
position: fixed;
Expand Down
43 changes: 18 additions & 25 deletions packages/edit-post/src/components/layout/use-should-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,29 @@ import { store as editorStore } from '@wordpress/editor';
import { useSelect } from '@wordpress/data';
import { store as blocksStore } from '@wordpress/blocks';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../store';

const isGutenbergPlugin = globalThis.IS_GUTENBERG_PLUGIN ? true : false;

export function useShouldIframe() {
const {
isBlockBasedTheme,
hasV3BlocksOnly,
isEditingTemplate,
hasMetaBoxes,
} = useSelect( ( select ) => {
const { getEditorSettings, getCurrentPostType } = select( editorStore );
const { getBlockTypes } = select( blocksStore );
const editorSettings = getEditorSettings();
return {
isBlockBasedTheme: editorSettings.__unstableIsBlockBasedTheme,
hasV3BlocksOnly: getBlockTypes().every( ( type ) => {
return type.apiVersion >= 3;
} ),
isEditingTemplate: getCurrentPostType() === 'wp_template',
hasMetaBoxes: select( editPostStore ).hasMetaBoxes(),
};
}, [] );
const { isBlockBasedTheme, hasV3BlocksOnly, isEditingTemplate } = useSelect(
( select ) => {
const { getEditorSettings, getCurrentPostType } =
select( editorStore );
const { getBlockTypes } = select( blocksStore );
const editorSettings = getEditorSettings();
return {
isBlockBasedTheme: editorSettings.__unstableIsBlockBasedTheme,
hasV3BlocksOnly: getBlockTypes().every( ( type ) => {
return type.apiVersion >= 3;
} ),
isEditingTemplate: getCurrentPostType() === 'wp_template',
};
},
[]
);

return (
( ( hasV3BlocksOnly || ( isGutenbergPlugin && isBlockBasedTheme ) ) &&
! hasMetaBoxes ) ||
hasV3BlocksOnly ||
( isGutenbergPlugin && isBlockBasedTheme ) ||
Copy link
Member

Choose a reason for hiding this comment

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

Side note: I think we should remove the special treatment for the Gutenberg plugin. The different behavior from the WP core sometimes results in discovering no-framed editor bugs after the code has shipped.

Sorry, I can't remember examples now, but having the same condition in both builds makes sense, IMO.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking the same as I was reviewing this. The conditional here seems odd at this point

Copy link
Member Author

Choose a reason for hiding this comment

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

We are discussing this, I want to formally remove it in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

100%. My comment was just a side note.

isEditingTemplate
);
}
1 change: 1 addition & 0 deletions packages/editor/src/components/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
position: relative;
display: flex;
background-color: $gray-300;
isolation: isolate;

// Centralize the editor horizontally (flex-direction is column).
align-items: center;
Expand Down
18 changes: 11 additions & 7 deletions test/e2e/specs/editor/plugins/meta-boxes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test.describe( 'Meta boxes', () => {
await expect( saveDraft ).toBeDisabled();

// Add title to enable valid non-empty post save.
await page
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'Hello Meta' );

Expand All @@ -44,7 +44,7 @@ test.describe( 'Meta boxes', () => {
page,
} ) => {
// Publish a post so there's something for the latest posts dynamic block to render.
await page
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'A published post' );
await page.keyboard.press( 'Enter' );
Expand All @@ -53,7 +53,7 @@ test.describe( 'Meta boxes', () => {

// Publish a post with the latest posts dynamic block.
await admin.createNewPost();
await page
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'Dynamic block test' );
await editor.insertBlock( { name: 'core/latest-posts' } );
Expand All @@ -70,10 +70,12 @@ test.describe( 'Meta boxes', () => {
editor,
page,
} ) => {
await page
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'A published post' );
await page.getByRole( 'button', { name: 'Add default block' } ).click();
await editor.canvas
.getByRole( 'button', { name: 'Add default block' } )
.click();
await page.keyboard.type( 'Excerpt from content.' );

const postId = await editor.publishPost();
Expand All @@ -89,9 +91,11 @@ test.describe( 'Meta boxes', () => {
page,
} ) => {
await editor.openDocumentSettingsSidebar();
await page.getByRole( 'button', { name: 'Add default block' } ).click();
await editor.canvas
.getByRole( 'button', { name: 'Add default block' } )
.click();
await page.keyboard.type( 'Excerpt from content.' );
await page
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'A published post' );

Expand Down
6 changes: 5 additions & 1 deletion test/e2e/specs/editor/plugins/wp-editor-meta-box.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ test.describe( 'WP Editor Meta Boxes', () => {
await admin.createNewPost();

// Add title to enable valid non-empty post save.
await page
await editor.canvas
.locator( 'role=textbox[name="Add title"i]' )
.type( 'Hello Meta' );

await page.click(
'summary.edit-post-layout__metaboxes-details-summary'
);

// Switch tinymce to Text mode, first waiting for it to initialize
// because otherwise it will flip back to Visual mode once initialized.
await page.locator( '#test_tinymce_id_ifr' ).waitFor();
Expand Down
7 changes: 3 additions & 4 deletions test/e2e/specs/editor/various/publish-button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ test.describe( 'Post publish button', () => {
admin,
page,
requestUtils,
editor,
} ) => {
await requestUtils.activatePlugin( 'gutenberg-test-plugin-meta-box' );
await admin.createNewPost();
await page
.getByRole( 'textbox', {
name: 'Add title',
} )
await editor.canvas
.getByRole( 'textbox', { name: 'Add title' } )
.fill( 'Test post' );

const topBar = page.getByRole( 'region', { name: 'Editor top bar' } );
Expand Down
Loading