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

Block list: Add option in editor settings to show open list view as default #40757

Merged
merged 6 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function Layout( { styles } ) {
setIsInserterOpened,
} = useDispatch( editPostStore );
const { createErrorNotice } = useDispatch( noticesStore );
const { setIsListViewOpened } = useDispatch( editPostStore );
const {
mode,
isFullscreenActive,
Expand All @@ -89,6 +90,7 @@ function Layout( { styles } ) {
showBlockBreadcrumbs,
isTemplateMode,
documentLabel,
isListViewOpenByDefault,
} = useSelect( ( select ) => {
const { getEditorSettings, getPostTypeLabel } = select( editorStore );
const editorSettings = getEditorSettings();
Expand Down Expand Up @@ -129,6 +131,9 @@ function Layout( { styles } ) {
),
// translators: Default label for the Document in the Block Breadcrumb.
documentLabel: postTypeLabel || _x( 'Document', 'noun' ),
isListViewOpenByDefault: select( editPostStore ).isFeatureActive(
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
'showListViewByDefault'
),
};
}, [] );
const className = classnames( 'edit-post-layout', 'is-mode-' + mode, {
Expand All @@ -142,6 +147,13 @@ function Layout( { styles } ) {
hasBlockSelected ? 'edit-post/block' : 'edit-post/document'
);

// Check if the block list view should be open by default.
useEffect( () => {
if ( isListViewOpenByDefault ) {
setIsListViewOpened( true );
}
}, [] );
ramonjd marked this conversation as resolved.
Show resolved Hide resolved

// Inserter and Sidebars are mutually exclusive
useEffect( () => {
if ( sidebarIsOpened && ! isHugeViewport ) {
Expand Down Expand Up @@ -181,6 +193,7 @@ function Layout( { styles } ) {
if ( mode === 'visual' && isListViewOpened ) {
return <ListViewSidebar />;
}

return null;
};

Expand Down
7 changes: 7 additions & 0 deletions packages/edit-post/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ export default function EditPostPreferencesModal() {
) }
label={ __( 'Spotlight mode' ) }
/>
<EnableFeature
featureName="showListViewByDefault"
help={ __(
'Opens the block list view sidebar by default.'
) }
label={ __( 'Always open list view' ) }
/>
<EnableFeature
featureName="showIconLabels"
help={ __( 'Shows text instead of icons.' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ exports[`EditPostPreferencesModal should match snapshot when the modal is active
help="Highlights the current block and fades other content."
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
label="Spotlight mode"
/>
<WithSelect(WithDispatch(BaseOption))
featureName="showListViewByDefault"
help="Opens the block list view sidebar by default."
label="Always open list view"
/>
<WithSelect(WithDispatch(BaseOption))
featureName="showIconLabels"
help="Shows text instead of icons."
Expand Down Expand Up @@ -158,6 +163,11 @@ exports[`EditPostPreferencesModal should match snapshot when the modal is active
help="Highlights the current block and fades other content."
label="Spotlight mode"
/>
<WithSelect(WithDispatch(BaseOption))
featureName="showListViewByDefault"
help="Opens the block list view sidebar by default."
label="Always open list view"
/>
<WithSelect(WithDispatch(BaseOption))
featureName="showIconLabels"
help="Shows text instead of icons."
Expand Down
16 changes: 15 additions & 1 deletion packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function Editor( { onError } ) {
nextShortcut,
editorMode,
showIconLabels,
isListViewOpenByDefault,
} = useSelect( ( select ) => {
const {
isInserterOpened,
Expand Down Expand Up @@ -114,9 +115,15 @@ function Editor( { onError } ) {
'core/edit-site',
'showIconLabels'
),
isListViewOpenByDefault: select( preferencesStore ).get(
'core/edit-site',
'showListViewByDefault'
),
};
}, [] );
const { setPage, setIsInserterOpened } = useDispatch( editSiteStore );
const { setPage, setIsInserterOpened, setIsListViewOpened } = useDispatch(
editSiteStore
);
const { enableComplementaryArea } = useDispatch( interfaceStore );

const [
Expand Down Expand Up @@ -152,6 +159,13 @@ function Editor( { onError } ) {
[ page?.context ]
);

// Check if the block list view should be open by default.
useEffect( () => {
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
if ( isListViewOpenByDefault ) {
setIsListViewOpened( true );
}
}, [] );

useEffect( () => {
if ( isNavigationOpen ) {
document.body.classList.add( 'is-navigation-sidebar-open' );
Expand Down
7 changes: 7 additions & 0 deletions packages/edit-site/src/components/preferences-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ export default function EditSitePreferencesModal( {
label={ __( 'Show button text labels' ) }
help={ __( 'Show text instead of icons on buttons' ) }
/>
<EnableFeature
featureName="showListViewByDefault"
help={ __(
'Opens the block list view sidebar by default.'
) }
label={ __( 'Always open list view' ) }
/>
</PreferencesModalSection>
),
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ npm run test-e2e:playwright
npm run test-e2e:playwright -- --headed

# Run a single test file.
npm run test-e2e:playwright -- <path_to_test_file>
npm run test-e2e:playwright -- <path_to_test_file> # E.g., npm run test-e2e:playwright -- site-editor/title.spec.js

# Debugging
npm run test-e2e:playwright -- --debug
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/specs/site-editor/block-list-panel-preference.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* WordPress dependencies
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

test.describe( 'Block list view', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'emptytheme' );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

test( 'Should open by default', async ( { page, pageUtils } ) => {
await pageUtils.visitSiteEditor( {
postId: 'emptytheme//index',
postType: 'wp_template',
} );

// Should display the Preview button.
await expect(
page.locator( '.edit-site-editor__list-view-panel' )
).not.toBeVisible();

// Turn on block list view by default.
await page.evaluate( () => {
window.wp.data
.dispatch( 'core/preferences' )
.set( 'core/edit-site', 'showListViewByDefault', true );
} );

await page.reload();

// Should display the Preview button.
await expect(
page.locator( '.edit-site-editor__list-view-panel' )
).toBeVisible();
} );
ramonjd marked this conversation as resolved.
Show resolved Hide resolved
} );