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 Post Type label for Document tab in Settings Header #17311

Merged
merged 38 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d88a370
Introduce a filter to overrider Document label in Document Settings H…
desaiuditd Sep 3, 2019
0de2bb4
Move the translator comment for ARIA label.
desaiuditd Sep 4, 2019
c2d4dc0
Replace string concatenation with sprintf.
desaiuditd Sep 4, 2019
a8a3e86
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd Apr 5, 2020
8652601
Introduce useFilters React hook.
desaiuditd Apr 5, 2020
d92d8ee
Prefer template literal over string concatenation.
desaiuditd Apr 17, 2020
16bbbe6
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd Apr 24, 2020
cf78029
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd May 10, 2020
8338a94
Use PHP filter instead of JS filter.
desaiuditd May 10, 2020
f6c3cc6
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd May 11, 2020
ce39586
Use Post Type label for Custom Post Types.
desaiuditd May 15, 2020
0d427f8
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd May 15, 2020
1187645
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd May 18, 2020
63b44ef
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd May 30, 2020
2b4f1e9
Re-use post type labels for Document label.
desaiuditd May 30, 2020
465f432
Clean up & remove extra code.
desaiuditd May 30, 2020
bd6957a
Fix typo.
desaiuditd May 30, 2020
5055638
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd Jun 27, 2020
38cb8f6
Use post type label in Document settings tab in sidebar for all post …
desaiuditd Jun 27, 2020
663a56e
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd Jun 27, 2020
921b22f
Fix e2e tests.
desaiuditd Jun 28, 2020
061ac29
Fix e2e tests.
desaiuditd Jun 28, 2020
a6d2ffc
Update docs.
desaiuditd Jun 28, 2020
1524a7c
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd Jul 7, 2020
17dd927
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd Jul 11, 2020
977b450
Remove complexities around e2e tests.
desaiuditd Jul 11, 2020
2afc3e2
Clean up.
desaiuditd Jul 11, 2020
9b120ee
Clean up.
desaiuditd Jul 11, 2020
bc7b25b
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd Jul 22, 2020
7f24673
Update packages/edit-post/src/components/sidebar/settings-header/inde…
desaiuditd Jul 22, 2020
fbb64d4
Update packages/edit-post/src/components/sidebar/settings-header/inde…
desaiuditd Jul 22, 2020
14f0f0a
Fix nits.
desaiuditd Jul 22, 2020
b3a060e
Fix nits.
desaiuditd Jul 22, 2020
92b292d
Fix nits.
desaiuditd Jul 22, 2020
bd71179
Merge branch 'master' into add/filter-to-override-document-label-in-s…
desaiuditd Jul 24, 2020
ea95b73
Add shim to override post type labels for Reusable blocks.
desaiuditd Jul 24, 2020
aa791f1
Adds trac link.
desaiuditd Jul 24, 2020
b9e551b
Fix i18n.
desaiuditd Jul 24, 2020
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
39 changes: 39 additions & 0 deletions lib/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,42 @@ function gutenberg_preload_edit_post( $preload_paths ) {
}

add_filter( 'block_editor_preload_paths', 'gutenberg_preload_edit_post' );

/**
* Override post type labels for Reusable Block custom post type.
*
* This shim can be removed when the Gutenberg plugin requires a WordPress
* version that has the ticket below.
*
* @see https://core.trac.wordpress.org/ticket/50755
*
* @since 8.6.0
*
* @return array Array of new labels for Reusable Block post type.
*/
function gutenberg_override_reusable_block_post_type_labels() {
return array(
'name' => _x( 'Reusable Blocks', 'post type general name', 'gutenberg' ),
'singular_name' => _x( 'Reusable Block', 'post type singular name', 'gutenberg' ),
'menu_name' => _x( 'Reusable Blocks', 'admin menu', 'gutenberg' ),
'name_admin_bar' => _x( 'Reusable Block', 'add new on admin bar', 'gutenberg' ),
'add_new' => _x( 'Add New', 'Reusable Block', 'gutenberg' ),
'add_new_item' => __( 'Add New Reusable Block', 'gutenberg' ),
'new_item' => __( 'New Reusable Block', 'gutenberg' ),
'edit_item' => __( 'Edit Reusable Block', 'gutenberg' ),
'view_item' => __( 'View Reusable Block', 'gutenberg' ),
'all_items' => __( 'All Reusable Blocks', 'gutenberg' ),
'search_items' => __( 'Search Reusable Blocks', 'gutenberg' ),
'not_found' => __( 'No reusable blocks found.', 'gutenberg' ),
'not_found_in_trash' => __( 'No reusable blocks found in Trash.', 'gutenberg' ),
'filter_items_list' => __( 'Filter reusable blocks list', 'gutenberg' ),
'items_list_navigation' => __( 'Reusable Blocks list navigation', 'gutenberg' ),
'items_list' => __( 'Reusable Blocks list', 'gutenberg' ),
'item_published' => __( 'Reusable Block published.', 'gutenberg' ),
'item_published_privately' => __( 'Reusable Block published privately.', 'gutenberg' ),
'item_reverted_to_draft' => __( 'Reusable Block reverted to draft.', 'gutenberg' ),
'item_scheduled' => __( 'Reusable Block scheduled.', 'gutenberg' ),
'item_updated' => __( 'Reusable Block updated.', 'gutenberg' ),
);
}
add_filter( 'post_type_labels_wp_block', 'gutenberg_override_reusable_block_post_type_labels', 10, 0 );
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe( 'Order of block keyboard navigation', () => {
expect( await getActiveLabel() ).toBe( 'Multiple selected blocks' );

await page.keyboard.press( 'Tab' );
await expect( await getActiveLabel() ).toBe( 'Document' );
await expect( await getActiveLabel() ).toBe( 'Post' );

await pressKeyWithModifier( 'shift', 'Tab' );
await expect( await getActiveLabel() ).toBe(
Expand Down
4 changes: 2 additions & 2 deletions packages/e2e-tests/specs/editor/various/preferences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe( 'preferences', () => {

it( 'remembers sidebar dismissal between sessions', async () => {
// Open by default.
expect( await getActiveSidebarTabText() ).toBe( 'Document' );
expect( await getActiveSidebarTabText() ).toBe( 'Post' );

// Change to "Block" tab.
await page.click( '.edit-post-sidebar__panel-tab[aria-label="Block"]' );
Expand All @@ -41,7 +41,7 @@ describe( 'preferences', () => {
// See: https://github.com/WordPress/gutenberg/issues/6377
// See: https://github.com/WordPress/gutenberg/pull/8995
await page.reload();
expect( await getActiveSidebarTabText() ).toBe( 'Document' );
expect( await getActiveSidebarTabText() ).toBe( 'Post' );

// Dismiss
await page.click(
Expand Down
6 changes: 3 additions & 3 deletions packages/e2e-tests/specs/editor/various/sidebar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

const SIDEBAR_SELECTOR = '.edit-post-sidebar';
const ACTIVE_SIDEBAR_TAB_SELECTOR = '.edit-post-sidebar__panel-tab.is-active';
const ACTIVE_SIDEBAR_BUTTON_TEXT = 'Document';
const ACTIVE_SIDEBAR_BUTTON_TEXT = 'Post';

describe( 'Sidebar', () => {
afterEach( () => {
Expand Down Expand Up @@ -99,11 +99,11 @@ describe( 'Sidebar', () => {
await pressKeyWithModifier( 'ctrl', '`' );
await pressKeyWithModifier( 'ctrl', '`' );

// Tab lands at first (presumed selected) option "Document".
// Tab lands at first (presumed selected) option "Post".
await page.keyboard.press( 'Tab' );
const isActiveDocumentTab = await page.evaluate(
() =>
document.activeElement.textContent === 'Document' &&
document.activeElement.textContent === 'Post' &&
document.activeElement.classList.contains( 'is-active' )
);
expect( isActiveDocumentTab ).toBe( true );
Expand Down
64 changes: 35 additions & 29 deletions packages/edit-post/src/components/sidebar/settings-header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,39 @@
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { withDispatch } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';

const SettingsHeader = ( { sidebarName } ) => {
const { openGeneralSidebar } = useDispatch( 'core/edit-post' );
const openDocumentSettings = () =>
openGeneralSidebar( 'edit-post/document' );
const openBlockSettings = () => openGeneralSidebar( 'edit-post/block' );

const documentLabel = useSelect( ( select ) => {
const currentPostType = select( 'core/editor' ).getCurrentPostType();
const postType = select( 'core' ).getPostType( currentPostType );

return (
// Disable reason: Post type labels object is shaped like this.
// eslint-disable-next-line camelcase
postType?.labels?.singular_name ??
// translators: Default label for the Document sidebar tab, not selected.
__( 'Document' )
);
} );

const SettingsHeader = ( {
openDocumentSettings,
openBlockSettings,
sidebarName,
} ) => {
const blockLabel = __( 'Block' );
const [ documentAriaLabel, documentActiveClass ] =
sidebarName === 'edit-post/document'
? // translators: ARIA label for the Document sidebar tab, selected.
[ __( 'Document (selected)' ), 'is-active' ]
: // translators: ARIA label for the Document sidebar tab, not selected.
[ __( 'Document' ), '' ];
? // translators: ARIA label for the Document sidebar tab, selected. %s: Document label.
[ sprintf( __( '%s (selected)' ), documentLabel ), 'is-active' ]
: [ documentLabel, '' ];

const [ blockAriaLabel, blockActiveClass ] =
sidebarName === 'edit-post/block'
? // translators: ARIA label for the Settings Sidebar tab, selected.
? // translators: ARIA label for the Block Settings Sidebar tab, selected.
[ __( 'Block (selected)' ), 'is-active' ]
: // translators: ARIA label for the Settings Sidebar tab, not selected.
: // translators: ARIA label for the Block Settings Sidebar tab, not selected.
[ __( 'Block' ), '' ];

/* Use a list so screen readers will announce how many tabs there are. */
Expand All @@ -33,33 +45,27 @@ const SettingsHeader = ( {
onClick={ openDocumentSettings }
className={ `edit-post-sidebar__panel-tab ${ documentActiveClass }` }
aria-label={ documentAriaLabel }
data-label={ __( 'Document' ) }
data-label={ documentLabel }
>
{ __( 'Document' ) }
{ documentLabel }
</Button>
</li>
<li>
<Button
onClick={ openBlockSettings }
className={ `edit-post-sidebar__panel-tab ${ blockActiveClass }` }
aria-label={ blockAriaLabel }
data-label={ blockLabel }
// translators: Data label for the Block Settings Sidebar tab.
data-label={ __( 'Block' ) }
>
{ blockLabel }
{
// translators: Text label for the Block Settings Sidebar tab.
__( 'Block' )
}
</Button>
</li>
</ul>
);
};

export default withDispatch( ( dispatch ) => {
const { openGeneralSidebar } = dispatch( 'core/edit-post' );
return {
openDocumentSettings() {
openGeneralSidebar( 'edit-post/document' );
},
openBlockSettings() {
openGeneralSidebar( 'edit-post/block' );
},
};
} )( SettingsHeader );
desaiuditd marked this conversation as resolved.
Show resolved Hide resolved
export default SettingsHeader;