Skip to content

Commit

Permalink
[Block Library - Query Loop]: Reorganise inspector controls + order
Browse files Browse the repository at this point in the history
… selection bug (#37949)

* [Block Library - Query Loop]: Reorganise inspector controls

* fix typo
  • Loading branch information
ntsekouras authored Jan 14, 2022
1 parent 3a4fe34 commit e781ffe
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/block-library/src/query/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { __ } from '@wordpress/i18n';
* Internal dependencies
*/
import QueryToolbar from './query-toolbar';
import QueryInspectorControls from './query-inspector-controls';
import QueryInspectorControls from './inspector-controls';
import QueryPlaceholder from './query-placeholder';
import { DEFAULTS_POSTS_PER_PAGE } from '../constants';
import { getFirstQueryClientIdFromBlocks } from '../utils';
Expand Down Expand Up @@ -65,7 +65,7 @@ export function QueryContent( { attributes, setAttributes } ) {

// Changes in query property (which is an object) need to be in the same callback,
// because updates are batched after the render and changes in different query properties
// would cause to overide previous wanted changes.
// would cause to override previous wanted changes.
useEffect( () => {
const newQuery = {};
if ( ! query.perPage && postsPerPage ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import { store as coreStore } from '@wordpress/core-data';
/**
* Internal dependencies
*/
import { getTermsInfo, usePostTypes } from '../utils';
import { MAX_FETCHED_TERMS } from '../constants';
import OrderControl from './order-control';
import { getTermsInfo, usePostTypes } from '../../utils';
import { MAX_FETCHED_TERMS } from '../../constants';

const stickyOptions = [
{ label: __( 'Include' ), value: '' },
Expand Down Expand Up @@ -217,14 +218,9 @@ export default function QueryInspectorControls( {
</>
) }
{ ! inherit && (
<QueryControls
<OrderControl
{ ...{ order, orderBy } }
onOrderChange={ ( value ) =>
setQuery( { order: value } )
}
onOrderByChange={ ( value ) =>
setQuery( { orderBy: value } )
}
onChange={ setQuery }
/>
) }
{ showSticky && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* WordPress dependencies
*/
import { SelectControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

const orderOptions = [
{
label: __( 'Newest to oldest' ),
value: 'date/desc',
},
{
label: __( 'Oldest to newest' ),
value: 'date/asc',
},
{
/* translators: label for ordering posts by title in ascending order */
label: __( 'A → Z' ),
value: 'title/asc',
},
{
/* translators: label for ordering posts by title in descending order */
label: __( 'Z → A' ),
value: 'title/desc',
},
];
function OrderControl( { order, orderBy, onChange } ) {
return (
<SelectControl
label={ __( 'Order by' ) }
value={ `${ orderBy }/${ order }` }
options={ orderOptions }
onChange={ ( value ) => {
const [ newOrderBy, newOrder ] = value.split( '/' );
onChange( { order: newOrder, orderBy: newOrderBy } );
} }
/>
);
}

export default OrderControl;

0 comments on commit e781ffe

Please sign in to comment.