Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/block-library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Post Navigation Link: Use the UI SelectControl for the Filter by taxonomy setting ([#86557](https://github.com/WordPress/gutenberg/pull/86557)).
- Navigation: Use the UI SelectControl for the Overlay template setting ([#86619](https://github.com/WordPress/gutenberg/pull/86619)).
- Terms Query: Use the UI SelectControl for the Taxonomy and Order by settings ([#86558](https://github.com/WordPress/gutenberg/pull/86558)).
- Query Loop: Use the UI SelectControl for the Post type, Order by, and Sticky posts settings ([#86560](https://github.com/WordPress/gutenberg/pull/86560)).
- Categories List: Use the UI SelectControl for the Taxonomy setting ([#86197](https://github.com/WordPress/gutenberg/pull/86197)).
- Template Part: Use the UI SelectControl for the Area and Import widget area settings ([#86565](https://github.com/WordPress/gutenberg/pull/86565)).
- Cover: Move the minimum height to the `dimensions` block support ([#83447](https://github.com/WordPress/gutenberg/pull/83447)).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
TextControl,
SelectControl as WCSelectControl,
Notice as WCNotice,
__experimentalVStack as VStack,
__experimentalToolsPanel as ToolsPanel,
Expand All @@ -14,6 +13,7 @@ import { store as coreStore } from '@wordpress/core-data';
import { __, _x, sprintf } from '@wordpress/i18n';
import { debounce } from '@wordpress/compose';
import { useState, useMemo } from '@wordpress/element';
import { SelectControl } from '@wordpress/ui';
import OrderControl from './order-control';
import AuthorControl from './author-control';
import ParentControl from './parent-control';
Expand Down Expand Up @@ -275,12 +275,20 @@ export default function QueryInspectorControls( props ) {
isShownByDefault
>
{ postTypesSelectOptions.length > 2 ? (
<WCSelectControl
options={ postTypesSelectOptions }
value={ postType }
<SelectControl
items={ postTypesSelectOptions }
value={
postTypesSelectOptions.find(
( item ) => item.value === postType
) ?? postTypesSelectOptions[ 0 ]
}
label={ postTypeControlLabel }
onChange={ onPostTypeChange }
help={ postTypeControlHelp }
onValueChange={ ( item ) => {
if ( item && item.value !== postType ) {
onPostTypeChange( item.value );
}
} }
description={ postTypeControlHelp }
/>
) : (
<ToggleGroupControl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SelectControl as WCSelectControl } from '@wordpress/components';
import { SelectControl } from '@wordpress/ui';
import { __ } from '@wordpress/i18n';

const defaultOrderByOptions = [
Expand Down Expand Up @@ -29,12 +29,21 @@ function OrderControl( {
onChange,
} ) {
return (
<WCSelectControl
<SelectControl
label={ __( 'Order by' ) }
value={ `${ orderBy }/${ order }` }
options={ orderByOptions }
onChange={ ( value ) => {
const [ newOrderBy, newOrder ] = value.split( '/' );
value={
orderByOptions.find(
( item ) => item.value === `${ orderBy }/${ order }`
) ??
orderByOptions[ 0 ] ??
null
}
items={ orderByOptions }
onValueChange={ ( item ) => {
Comment thread
ciampo marked this conversation as resolved.
Resolved
if ( ! item || item.value === `${ orderBy }/${ order }` ) {
return;
}
const [ newOrderBy, newOrder ] = item.value.split( '/' );
onChange( { order: newOrder, orderBy: newOrderBy } );
} }
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SelectControl as WCSelectControl } from '@wordpress/components';
import { SelectControl } from '@wordpress/ui';
import { __ } from '@wordpress/i18n';

const stickyOptions = [
Expand All @@ -10,12 +10,20 @@ const stickyOptions = [

export default function StickyControl( { value, onChange } ) {
return (
<WCSelectControl
<SelectControl
label={ __( 'Sticky posts' ) }
options={ stickyOptions }
value={ value }
onChange={ onChange }
help={ __(
items={ stickyOptions }
value={
stickyOptions.find( ( item ) => item.value === value ) ??
stickyOptions[ 0 ]
}
itemToStringValue={ ( item ) => `sticky:${ item.value }` }
onValueChange={ ( item ) => {
if ( item && item.value !== value ) {
onChange( item.value );
}
} }
description={ __(
'Sticky posts always appear first, regardless of their publish date.'
) }
/>
Expand Down
138 changes: 138 additions & 0 deletions test/e2e/specs/editor/blocks/query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,144 @@ test.describe( 'Query block', () => {
] );
} );

test.describe( 'Query selectors', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activatePlugin(
'gutenberg-test-custom-post-types'
);
} );

test.beforeEach( async ( { page, editor } ) => {
await editor.insertBlock( {
name: 'core/query',
attributes: { query: { inherit: false, postType: 'post' } },
innerBlocks: [
{
name: 'core/post-template',
innerBlocks: [ { name: 'core/post-title' } ],
},
],
} );
await editor.selectBlocks(
editor.canvas.getByRole( 'document', {
name: 'Block: Query Loop',
} )
);
await editor.openDocumentSettingsSidebar();
await expect(
page.getByRole( 'combobox', { name: 'Post type', exact: true } )
).toBeVisible();
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.deactivatePlugin(
'gutenberg-test-custom-post-types'
);
} );

for ( const { label, options } of [
{
label: 'Order by',
options: [ 'Newest to oldest', 'Oldest to newest' ],
},
{ label: 'Sticky posts', options: [ 'Include', 'Exclude' ] },
] ) {
test( `keeps a saved post unchanged when reselecting ${ label }`, async ( {
page,
editor,
} ) => {
const control = page.getByRole( 'combobox', {
name: label,
exact: true,
} );
for ( const option of options ) {
await control.click();
await page
.getByRole( 'option', { name: option, exact: true } )
.click();
await editor.saveDraft();
const before = ( await editor.getBlocks() )[ 0 ].attributes
.query;
await expect
.poll( () =>
page.evaluate( () =>
window.wp.data
.select( 'core/editor' )
.isEditedPostDirty()
)
)
.toBe( false );
await control.click();
await page
.getByRole( 'option', { name: option, exact: true } )
.click();
await expect( control ).toHaveAttribute(
'aria-expanded',
'false'
);
expect(
await page.evaluate( () =>
window.wp.data
.select( 'core/editor' )
.isEditedPostDirty()
)
).toBe( false );
expect(
( await editor.getBlocks() )[ 0 ].attributes.query
).toEqual( before );
}
} );
}

test( 'keeps query state when reselecting the current post type', async ( {
page,
editor,
} ) => {
for ( const postType of [ 'post', 'page' ] ) {
await page.evaluate( ( type ) => {
const { getBlocks } =
window.wp.data.select( 'core/block-editor' );
const block = getBlocks()[ 0 ];
window.wp.data
.dispatch( 'core/block-editor' )
.updateBlockAttributes( block.clientId, {
query: {
...block.attributes.query,
postType: type,
taxQuery: { include: { category: [ 1 ] } },
parents: [ 123 ],
format: [ 'aside' ],
sticky: type === 'post' ? 'exclude' : '',
author: '1',
search: 'Post',
offset: 2,
},
} );
}, postType );
const before = ( await editor.getBlocks() )[ 0 ].attributes
.query;
const control = page.getByRole( 'combobox', {
name: 'Post type',
exact: true,
} );
await control.click();
await page
.getByRole( 'option', {
name: postType === 'post' ? 'Post' : 'Page',
exact: true,
} )
.click();
await expect( control ).toHaveAttribute(
'aria-expanded',
'false'
);
expect(
( await editor.getBlocks() )[ 0 ].attributes.query
).toEqual( before );
}
} );
} );

test.describe( 'Post Template block movers', () => {
test( 'should show vertical movers for blocks inside a grid Post Template', async ( {
page,
Expand Down
Loading