Skip to content

Commit

Permalink
Settings UI: Sort todos and limit to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldudzic committed Feb 11, 2025
1 parent d2685d8 commit 9c65ea6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ const TodoSettingsBlock = ( {
}
};

// Filter out dismissed todos for display
const visibleTodos = todosData.filter(
( todo ) => ! dismissedTodos.includes( todo.id )
);
// Filter out dismissed todos for display and limit to 5.
const visibleTodos = todosData
.filter( ( todo ) => ! dismissedTodos.includes( todo.id ) )
.slice( 0, 5 );

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

$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(
array(
Expand Down Expand Up @@ -288,4 +289,23 @@ function( $todo ) use ( $pay_later_id ) {
? array_merge( $other_todos, array( $priority_pay_later_todo ) )
: $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;
}
}

0 comments on commit 9c65ea6

Please sign in to comment.