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

Add menu_order sorting option to Query Loop block #68781

Open
wants to merge 27 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f0c3039
Add support for menu order
kasparsd Jan 20, 2025
11fca2e
Add the menu order option
kasparsd Jan 20, 2025
681186c
Two more copy-paste location
kasparsd Jan 20, 2025
27dd5a1
Match the order
kasparsd Jan 20, 2025
a50362f
Update labels per discussion
kasparsd Jan 21, 2025
6def53a
Helper for resolving order by options for a post type
kasparsd Feb 17, 2025
0ed2ac0
Add the option type
kasparsd Feb 17, 2025
066e3e3
Pass in the options
kasparsd Feb 17, 2025
f40d2b6
Restrict the values to only known values
kasparsd Feb 17, 2025
777debf
Keep the order
kasparsd Feb 17, 2025
ba52675
Define the type for just the option
kasparsd Feb 17, 2025
016c83e
Document the updated fields
kasparsd Feb 17, 2025
568fd9d
Update the examples
kasparsd Feb 17, 2025
f6af1ec
Reference the type
kasparsd Feb 17, 2025
27a3c60
This is really required for the drop-down component, keep it simple here
kasparsd Feb 17, 2025
ef44e18
Merge remote-tracking branch 'origin/trunk' into 42710-add-menu-order…
kasparsd Feb 28, 2025
a6c408a
Add back the default options to prevent breaking changes
kasparsd Feb 28, 2025
49affb3
Use memo to avoid rebuilding the list of options
kasparsd Feb 28, 2025
1becd19
Add back the defaults to avoid breaking changes
kasparsd Feb 28, 2025
27c04ea
Keep the default as prefix to match the rest of coding style
kasparsd Feb 28, 2025
924364c
Rely on the default orderby options for now
kasparsd Feb 28, 2025
2cca836
Remove for now
kasparsd Feb 28, 2025
d7e34aa
Resolve the options via the helper instead
kasparsd Feb 28, 2025
ca99bbd
Latest posts list only posts which don’t support custom menu order fo…
kasparsd Feb 28, 2025
3947b6a
Add our changelog
kasparsd Feb 28, 2025
7cc05e8
Formatting
kasparsd Feb 28, 2025
4c6a316
Document the change
kasparsd Feb 28, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ const orderOptions = [
label: __( 'Z → A' ),
value: 'title/desc',
},
{
/* translators: Label for ordering posts by menu order in descending order. */
label: __( 'Menu order descending' ),
value: 'menu_order/desc',
},
{
/* translators: Label for ordering posts by menu order in descending order. */
label: __( 'Menu order ascending' ),
value: 'menu_order/asc',
},
];
function OrderControl( { order, orderBy, onChange } ) {
return (
Expand Down
10 changes: 10 additions & 0 deletions packages/components/src/query-controls/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ const options = [
label: __( 'Z → A' ),
value: 'title/desc',
},
{
/* translators: Label for ordering posts by menu order in descending order. */
label: __( 'Menu order descending' ),
value: 'menu_order/desc',
},
{
/* translators: Label for ordering posts by menu order in descending order. */
label: __( 'Menu order ascending' ),
value: 'menu_order/asc',
},
];

const QueryControls = memo(
Expand Down
52 changes: 32 additions & 20 deletions packages/components/src/query-controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,37 @@ export function QueryControls( {
// but instead are destructured inline where necessary.
...props
}: QueryControlsProps ) {
const orderByList = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name here matches the props.categoriesList convention used below with orderBy being the feature.

{
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',
},
{
/* translators: Label for ordering posts by menu order in descending order. */
label: __( 'Menu order descending' ),
value: 'menu_order/desc',
},
{
/* translators: Label for ordering posts by menu order in descending order. */
label: __( 'Menu order ascending' ),
value: 'menu_order/asc',
},
];

return (
<VStack spacing="4" className="components-query-controls">
{ [
Expand All @@ -89,26 +120,7 @@ export function QueryControls( {
? undefined
: `${ orderBy }/${ order }`
}
options={ [
{
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',
},
] }
options={ orderByList }
onChange={ ( value ) => {
if ( typeof value !== 'string' ) {
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/query-controls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type AuthorSelectProps = Pick<
};

type Order = 'asc' | 'desc';
type OrderBy = 'date' | 'title';
type OrderBy = 'date' | 'title' | 'menu_order';

type BaseQueryControlsProps = {
/**
Expand Down
Loading