From f0c3039ce8be2f10187dd0674d299ffd0b25fa4c Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 10:45:11 +0200 Subject: [PATCH 1/5] Add support for menu order --- packages/components/src/query-controls/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/query-controls/types.ts b/packages/components/src/query-controls/types.ts index eb004bf8215b0a..91807e006c7c78 100644 --- a/packages/components/src/query-controls/types.ts +++ b/packages/components/src/query-controls/types.ts @@ -45,7 +45,7 @@ export type AuthorSelectProps = Pick< }; type Order = 'asc' | 'desc'; -type OrderBy = 'date' | 'title'; +type OrderBy = 'date' | 'title' | 'menu_order'; type BaseQueryControlsProps = { /** From 11fca2eb793d7082b31463df54bfbe8c0522c5c8 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 10:45:22 +0200 Subject: [PATCH 2/5] Add the menu order option --- .../components/src/query-controls/index.tsx | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/packages/components/src/query-controls/index.tsx b/packages/components/src/query-controls/index.tsx index 452dd303c778bb..e6518fc44cc947 100644 --- a/packages/components/src/query-controls/index.tsx +++ b/packages/components/src/query-controls/index.tsx @@ -75,6 +75,37 @@ export function QueryControls( { // but instead are destructured inline where necessary. ...props }: QueryControlsProps ) { + const orderByList = [ + { + 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/desc', + }, + ]; + return ( { [ @@ -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; From 681186c03c93c520dc9cdada5f517397cfb53ab2 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 11:53:14 +0200 Subject: [PATCH 3/5] Two more copy-paste location --- .../src/query/edit/inspector-controls/order-control.js | 10 ++++++++++ packages/components/src/query-controls/index.native.js | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/block-library/src/query/edit/inspector-controls/order-control.js b/packages/block-library/src/query/edit/inspector-controls/order-control.js index 23802f844359d7..5bf49e4eae0b10 100644 --- a/packages/block-library/src/query/edit/inspector-controls/order-control.js +++ b/packages/block-library/src/query/edit/inspector-controls/order-control.js @@ -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 ( diff --git a/packages/components/src/query-controls/index.native.js b/packages/components/src/query-controls/index.native.js index 4e687f4af09d57..119748a307b753 100644 --- a/packages/components/src/query-controls/index.native.js +++ b/packages/components/src/query-controls/index.native.js @@ -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( From 27dd5a149de4083fa86aac7cfad92f32cc7e3183 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Mon, 20 Jan 2025 11:53:32 +0200 Subject: [PATCH 4/5] Match the order --- packages/components/src/query-controls/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/query-controls/index.tsx b/packages/components/src/query-controls/index.tsx index e6518fc44cc947..356d0e1175f5ca 100644 --- a/packages/components/src/query-controls/index.tsx +++ b/packages/components/src/query-controls/index.tsx @@ -102,7 +102,7 @@ export function QueryControls( { { /* translators: Label for ordering posts by menu order in descending order. */ label: __( 'Menu order ascending' ), - value: 'menu_order/desc', + value: 'menu_order/asc', }, ]; From a50362f9238cc5c0eafb0d9836cb795a76bebeb6 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Tue, 21 Jan 2025 15:01:21 +0200 Subject: [PATCH 5/5] Update labels per discussion --- .../query/edit/inspector-controls/order-control.js | 12 ++++++------ .../components/src/query-controls/index.native.js | 12 ++++++------ packages/components/src/query-controls/index.tsx | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/block-library/src/query/edit/inspector-controls/order-control.js b/packages/block-library/src/query/edit/inspector-controls/order-control.js index 5bf49e4eae0b10..f233f7b2878ecb 100644 --- a/packages/block-library/src/query/edit/inspector-controls/order-control.js +++ b/packages/block-library/src/query/edit/inspector-controls/order-control.js @@ -24,14 +24,14 @@ const orderOptions = [ 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 ascending menu order. */ + label: __( 'Ascending by order' ), + value: 'menu_order/asc', }, { - /* translators: Label for ordering posts by menu order in descending order. */ - label: __( 'Menu order ascending' ), - value: 'menu_order/asc', + /* translators: Label for ordering posts by descending menu order. */ + label: __( 'Descending by order' ), + value: 'menu_order/desc', }, ]; function OrderControl( { order, orderBy, onChange } ) { diff --git a/packages/components/src/query-controls/index.native.js b/packages/components/src/query-controls/index.native.js index 119748a307b753..d6c9c35b23d5d2 100644 --- a/packages/components/src/query-controls/index.native.js +++ b/packages/components/src/query-controls/index.native.js @@ -34,14 +34,14 @@ const options = [ 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 ascending menu order. */ + label: __( 'Ascending by order' ), + value: 'menu_order/asc', }, { - /* translators: Label for ordering posts by menu order in descending order. */ - label: __( 'Menu order ascending' ), - value: 'menu_order/asc', + /* translators: Label for ordering posts by descending menu order. */ + label: __( 'Descending by order' ), + value: 'menu_order/desc', }, ]; diff --git a/packages/components/src/query-controls/index.tsx b/packages/components/src/query-controls/index.tsx index 356d0e1175f5ca..ee0c84c8424739 100644 --- a/packages/components/src/query-controls/index.tsx +++ b/packages/components/src/query-controls/index.tsx @@ -95,14 +95,14 @@ export function QueryControls( { 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 ascending menu order. */ + label: __( 'Ascending by order' ), + value: 'menu_order/asc', }, { - /* translators: Label for ordering posts by menu order in descending order. */ - label: __( 'Menu order ascending' ), - value: 'menu_order/asc', + /* translators: Label for ordering posts by descending menu order. */ + label: __( 'Descending by order' ), + value: 'menu_order/desc', }, ];