Merge pull request #3093 from woocommerce/PCP-4206-things-to-do-sort-todos-by-priority-and-limit-to-5

Settings UI: Sort todos and limit to 5 (4206)
This commit is contained in:
Emili Castells 2025-02-11 16:02:41 +01:00 committed by GitHub
commit 69a9090e4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 5 deletions

View file

@ -63,10 +63,10 @@ const TodoSettingsBlock = ( {
} }
}; };
// Filter out dismissed todos for display // Filter out dismissed todos for display and limit to 5.
const visibleTodos = todosData.filter( const visibleTodos = todosData
( todo ) => ! dismissedTodos.includes( todo.id ) .filter( ( todo ) => ! dismissedTodos.includes( todo.id ) )
); .slice( 0, 5 );
return ( return (
<div <div

View file

@ -67,6 +67,7 @@ class TodosDefinition {
'section' => 'ppcp-axo-gateway', 'section' => 'ppcp-axo-gateway',
'highlight' => 'ppcp-axo-gateway', 'highlight' => 'ppcp-axo-gateway',
), ),
'priority' => 1,
), ),
'enable_credit_debit_cards' => array( 'enable_credit_debit_cards' => array(
'title' => __( 'Enable Credit and Debit Cards on your checkout', 'woocommerce-paypal-payments' ), 'title' => __( 'Enable Credit and Debit Cards on your checkout', 'woocommerce-paypal-payments' ),
@ -78,6 +79,7 @@ class TodosDefinition {
'section' => 'ppcp-card-button-gateway', 'section' => 'ppcp-card-button-gateway',
'highlight' => 'ppcp-card-button-gateway', 'highlight' => 'ppcp-card-button-gateway',
), ),
'priority' => 2,
), ),
'enable_pay_later_messaging' => array( 'enable_pay_later_messaging' => array(
'title' => __( 'Enable Pay Later messaging', 'woocommerce-paypal-payments' ), 'title' => __( 'Enable Pay Later messaging', 'woocommerce-paypal-payments' ),
@ -87,6 +89,7 @@ class TodosDefinition {
'type' => 'tab', 'type' => 'tab',
'tab' => 'pay_later_messaging', 'tab' => 'pay_later_messaging',
), ),
'priority' => 3,
), ),
'add_pay_later_messaging_product_page' => array( 'add_pay_later_messaging_product_page' => array(
'title' => __( 'Add Pay Later messaging to the Product page', 'woocommerce-paypal-payments' ), 'title' => __( 'Add Pay Later messaging to the Product page', 'woocommerce-paypal-payments' ),
@ -96,6 +99,7 @@ class TodosDefinition {
'type' => 'tab', 'type' => 'tab',
'tab' => 'pay_later_messaging', 'tab' => 'pay_later_messaging',
), ),
'priority' => 4,
), ),
'add_pay_later_messaging_cart' => array( 'add_pay_later_messaging_cart' => array(
'title' => __( 'Add Pay Later messaging to the Cart page', 'woocommerce-paypal-payments' ), 'title' => __( 'Add Pay Later messaging to the Cart page', 'woocommerce-paypal-payments' ),
@ -105,6 +109,7 @@ class TodosDefinition {
'type' => 'tab', 'type' => 'tab',
'tab' => 'pay_later_messaging', 'tab' => 'pay_later_messaging',
), ),
'priority' => 4,
), ),
'add_pay_later_messaging_checkout' => array( 'add_pay_later_messaging_checkout' => array(
'title' => __( 'Add Pay Later messaging to the Checkout page', 'woocommerce-paypal-payments' ), 'title' => __( 'Add Pay Later messaging to the Checkout page', 'woocommerce-paypal-payments' ),
@ -114,6 +119,7 @@ class TodosDefinition {
'type' => 'tab', 'type' => 'tab',
'tab' => 'pay_later_messaging', 'tab' => 'pay_later_messaging',
), ),
'priority' => 4,
), ),
'configure_paypal_subscription' => array( 'configure_paypal_subscription' => array(
'title' => __( 'Configure a PayPal Subscription', 'woocommerce-paypal-payments' ), 'title' => __( 'Configure a PayPal Subscription', 'woocommerce-paypal-payments' ),
@ -123,6 +129,7 @@ class TodosDefinition {
'type' => 'external', 'type' => 'external',
'url' => admin_url( 'edit.php?post_type=product&product_type=subscription' ), 'url' => admin_url( 'edit.php?post_type=product&product_type=subscription' ),
), ),
'priority' => 5,
), ),
'add_paypal_buttons' => array( 'add_paypal_buttons' => array(
'title' => __( 'Add PayPal buttons', 'woocommerce-paypal-payments' ), 'title' => __( 'Add PayPal buttons', 'woocommerce-paypal-payments' ),
@ -132,6 +139,7 @@ class TodosDefinition {
'type' => 'tab', 'type' => 'tab',
'tab' => 'styling', 'tab' => 'styling',
), ),
'priority' => 6,
), ),
'register_domain_apple_pay' => array( 'register_domain_apple_pay' => array(
'title' => __( 'Register Domain for Apple Pay', 'woocommerce-paypal-payments' ), 'title' => __( 'Register Domain for Apple Pay', 'woocommerce-paypal-payments' ),
@ -144,6 +152,7 @@ class TodosDefinition {
: 'https://www.paypal.com/uccservicing/apm/applepay', : 'https://www.paypal.com/uccservicing/apm/applepay',
'completeOnClick' => true, 'completeOnClick' => true,
), ),
'priority' => 7,
), ),
'add_digital_wallets' => array( 'add_digital_wallets' => array(
'title' => __( 'Add digital wallets to your account', 'woocommerce-paypal-payments' ), 'title' => __( 'Add digital wallets to your account', 'woocommerce-paypal-payments' ),
@ -153,6 +162,7 @@ class TodosDefinition {
'type' => 'external', 'type' => 'external',
'url' => 'https://www.paypal.com/businessmanage/account/settings', 'url' => 'https://www.paypal.com/businessmanage/account/settings',
), ),
'priority' => 8,
), ),
'add_apple_pay' => array( 'add_apple_pay' => array(
'title' => __( 'Add Apple Pay to your account', 'woocommerce-paypal-payments' ), 'title' => __( 'Add Apple Pay to your account', 'woocommerce-paypal-payments' ),
@ -162,6 +172,7 @@ class TodosDefinition {
'type' => 'external', 'type' => 'external',
'url' => 'https://www.paypal.com/businessmanage/account/settings', 'url' => 'https://www.paypal.com/businessmanage/account/settings',
), ),
'priority' => 9,
), ),
'add_google_pay' => array( 'add_google_pay' => array(
'title' => __( 'Add Google Pay to your account', 'woocommerce-paypal-payments' ), 'title' => __( 'Add Google Pay to your account', 'woocommerce-paypal-payments' ),
@ -171,6 +182,7 @@ class TodosDefinition {
'type' => 'external', 'type' => 'external',
'url' => 'https://www.paypal.com/businessmanage/account/settings', 'url' => 'https://www.paypal.com/businessmanage/account/settings',
), ),
'priority' => 10,
), ),
'enable_apple_pay' => array( 'enable_apple_pay' => array(
'title' => __( 'Enable Apple Pay', 'woocommerce-paypal-payments' ), 'title' => __( 'Enable Apple Pay', 'woocommerce-paypal-payments' ),
@ -182,6 +194,7 @@ class TodosDefinition {
'section' => 'ppcp-applepay', 'section' => 'ppcp-applepay',
'highlight' => 'ppcp-applepay', 'highlight' => 'ppcp-applepay',
), ),
'priority' => 11,
), ),
'enable_google_pay' => array( 'enable_google_pay' => array(
'title' => __( 'Enable Google Pay', 'woocommerce-paypal-payments' ), 'title' => __( 'Enable Google Pay', 'woocommerce-paypal-payments' ),
@ -193,6 +206,7 @@ class TodosDefinition {
'section' => 'ppcp-googlepay', 'section' => 'ppcp-googlepay',
'highlight' => 'ppcp-googlepay', 'highlight' => 'ppcp-googlepay',
), ),
'priority' => 12,
), ),
); );
} }

View file

@ -157,7 +157,8 @@ class TodosRestEndpoint extends RestEndpoint {
} }
} }
$filtered_todos = $this->filter_pay_later_todos( $todos ); $sorted_todos = $this->sort_todos_by_priority( $todos );
$filtered_todos = $this->filter_pay_later_todos( $sorted_todos );
return $this->return_success( return $this->return_success(
array( array(
@ -288,4 +289,23 @@ class TodosRestEndpoint extends RestEndpoint {
? array_merge( $other_todos, array( $priority_pay_later_todo ) ) ? array_merge( $other_todos, array( $priority_pay_later_todo ) )
: $other_todos; : $other_todos;
} }
/**
* Sorts todos by their priority value.
*
* @param array $todos Array of todos to sort.
* @return array Sorted array of todos.
*/
private function sort_todos_by_priority( array $todos ): array {
usort(
$todos,
function( $a, $b ) {
$priority_a = $a['priority'] ?? 999;
$priority_b = $b['priority'] ?? 999;
return $priority_a <=> $priority_b;
}
);
return $todos;
}
} }