Skip to content

Commit

Permalink
feat(GCOM-1316): change customer order sorting in Descending order fr…
Browse files Browse the repository at this point in the history
…om Created at date
  • Loading branch information
LaurensFranken committed Jan 25, 2024
1 parent 83ecb7d commit 816d789
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-mice-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/magento-customer": patch
---

Change sorting for customer orders in Descending Created at order
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fragment AccountOrders on Customer {
orders(filter: {}, pageSize: $pageSize, currentPage: $currentPage) {
orders(filter: {}, pageSize: $pageSize, currentPage: $currentPage, sort: $sort) {
items {
...OrderCard
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Box
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
query AccountDashboardOrders($currentPage: Int!, $pageSize: Int!) {
query AccountDashboardOrders(
$currentPage: Int!,
$pageSize: Int!,
$sort: CustomerOrderSortInput = { sort_direction: DESC, sort_field: CREATED_AT }) {
customer {
...AccountOrders
}
Expand Down

0 comments on commit 816d789

Please sign in to comment.