diff --git a/.changeset/big-shrimps-press.md b/.changeset/big-shrimps-press.md new file mode 100644 index 0000000000..f0d5011433 --- /dev/null +++ b/.changeset/big-shrimps-press.md @@ -0,0 +1,5 @@ +--- +"@graphcommerce/magento-customer": patch +--- + +Change sorting for customer orders diff --git a/packages/magento-customer/components/AccountOrders/AccountOrders.graphql b/packages/magento-customer/components/AccountOrders/AccountOrders.graphql index 78a7c25a9a..392f45fce9 100644 --- a/packages/magento-customer/components/AccountOrders/AccountOrders.graphql +++ b/packages/magento-customer/components/AccountOrders/AccountOrders.graphql @@ -1,5 +1,5 @@ fragment AccountOrders on Customer { - orders(filter: {}, pageSize: $pageSize, currentPage: $currentPage) { + orders(filter: {}, pageSize: $pageSize, currentPage: $currentPage, sort: $sort) { items { ...OrderCard } diff --git a/packages/magento-customer/components/AccountOrders/AccountOrders.tsx b/packages/magento-customer/components/AccountOrders/AccountOrders.tsx index c42a032269..4acc84c0ad 100644 --- a/packages/magento-customer/components/AccountOrders/AccountOrders.tsx +++ b/packages/magento-customer/components/AccountOrders/AccountOrders.tsx @@ -20,16 +20,14 @@ export function AccountOrders(props: AccountOrdersProps) { const pageInfo = orders?.page_info const isFirstPage = pageInfo?.current_page === 1 - // whenever it's possible, pick last {amountLatestOrders} items, then reverse the resulting array, - // because we want to render the latest order first, - // but the API returns the orders in ASC order... - const latestOrders = orders?.items - .slice(Math.max((orders?.items?.length ?? 0) - 2, 0), orders?.items?.length) - .reverse() + const endLatestIndex = Math.min(2, orders?.items?.length || 2) + const latestOrders = orders?.items?.slice(0, endLatestIndex) + const startOlderIndex = Math.min(2, orders?.items?.length || 0) + const endOlderIndex = orders?.items?.length || 0 const olderOrders = isFirstPage - ? orders?.items.slice(0, Math.max((orders?.items?.length ?? 0) - 2, 0)).reverse() - : orders?.items + ? orders?.items?.slice(startOlderIndex, endOlderIndex) + : orders?.items return (