Skip to content

Commit 5e9bedc

Browse files
authored
Fix error sorting the Uncaptured table using Capture by column (#5185)
This change fixes an error in the Uncaptured transactions table, when the table is sorted clicking on the Capture by column. The error is caused by a 500 response from the endpoint, because 'capture_by' is not a valid sorting field in the API, since it is a value calculated in the front end, derived from the 'created' field. To solve the issue, I am rewriting the orderby field in the resolver to 'created', in case the 'capture_by' field is specified. This has the same effect, and does not cause an error in the API endpoint.
1 parent f5962d9 commit 5e9bedc

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fix
3+
4+
Fix an error in the Uncaptured transactions table when it is sorted using the Capture by column.

client/data/authorizations/resolvers.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ import { NAMESPACE } from '../constants';
2727
import { ApiError } from 'wcpay/types/errors';
2828

2929
export function* getAuthorizations( query: Query ): Generator< unknown > {
30-
const {
30+
let {
3131
paged = 1,
3232
per_page: perPage = 25,
3333
orderby = 'created',
3434
order = 'desc',
3535
} = query;
3636

37+
if ( orderby === 'capture_by' ) {
38+
// The API does not expect 'capture_by' to be a valid sorting field, since it is a derived field, calculated from the 'created' field.
39+
orderby = 'created';
40+
}
41+
3742
const path = addQueryArgs( `${ NAMESPACE }/authorizations`, {
3843
page: paged,
3944
pagesize: perPage,

client/transactions/uncaptured/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ const getColumns = (): Column[] =>
5555
screenReaderLabel: __( 'Capture by', 'woocommerce-payments' ),
5656
required: true,
5757
isLeftAligned: true,
58-
defaultOrder: 'desc',
5958
cellClassName: 'date-time',
6059
isSortable: true,
61-
defaultSort: true,
6260
},
6361
{
6462
key: 'order',

0 commit comments

Comments
 (0)