Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change customer order sorting in Descending rder from Created at date (GCOM-1316) #2198

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-shrimps-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/magento-customer": patch
---

Change sorting for customer orders
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
Loading