woocommerce/pinterest-for-woocommerce

Issues table pagination does not respect the page number and page size, and always return all issues

ecgan opened this issue · 0 comments

Describe the bug:

Related to issue #882.

In the Issues table, I have pagination in the table footer like this:

image

There are issues with the pagination:

  • When I go to page 2, I noticed that the data is the same as page 1.
  • The "Rows per page" is set to 25, but there are 40 issues in the table.
  • This means 40 issues in page 1, and the same 40 issues in page 2.

Here's a screenshot of the API call:

image

From the client side, we pass paged and per_page parameters to the API.

However, on the server side, those parameters are not really used:

/**
* Main endpoint callback.
*
* @param WP_REST_Request $request The request object.
* @return array[]|WP_REST_Response
*/
public function get_feed_issues( WP_REST_Request $request ) {
$ad_account_id = Pinterest_For_Woocommerce()::get_setting( 'tracking_advertiser' );
$feed_id = FeedRegistration::get_locally_stored_registered_feed_id();
if ( ! Pinterest\ProductSync::is_product_sync_enabled() || ! $feed_id || ! $ad_account_id ) {
return array( 'lines' => array() );
}
$results = Pinterest\Feeds::get_feed_recent_processing_results( $feed_id );
if ( empty( $results ) ) {
return array( 'lines' => array() );
}
$per_page = $request->has_param( 'per_page' ) ? (int) $request->get_param( 'per_page' ) : 25;
$feed_item_details = Pinterest\Feeds::get_feed_processing_result_items_issues( $results['id'], 250 );
$lines = array_reduce( $feed_item_details, array( __CLASS__, 'prepare_issue_lines' ), array() );
array_multisort( $lines, SORT_ASC, array_column( $lines, 'status' ) );
$response = new WP_REST_Response(
array(
'lines' => $lines,
'total_rows' => count( $lines ),
)
);
$response->header( 'X-WP-Total', count( $lines ) );
$response->header( 'X-WP-TotalPages', ceil( count( $lines ) / $per_page ) );
return $response;
}

Specifically, in the following line, we set the limit to be 250, instead of the per_page value:

$feed_item_details = Pinterest\Feeds::get_feed_processing_result_items_issues( $results['id'], 250 );

I believe the above is the cause of issue.

Steps to reproduce:

  1. Go to Issues table in the Catalog page.
  2. Test pagination in the Issues table footer.

Expected behavior:

Pagination should work as expected.

Actual behavior:

The table will always show all data, regardless of how you set pagination.