Skip to content

product list and inventory list default order#14911

Open
majianbing wants to merge 1 commit intomedusajs:developfrom
majianbing:feat/dashboard-list-orders
Open

product list and inventory list default order#14911
majianbing wants to merge 1 commit intomedusajs:developfrom
majianbing:feat/dashboard-list-orders

Conversation

@majianbing
Copy link
Copy Markdown

@majianbing majianbing commented Mar 19, 2026

Summary

What — What changes are introduced in this PR?

In the dashboard, the product list and inventory list default order is ascending. But users care more about the most recent added items.

Why — Why are these changes relevant or necessary?

Yes, I think so. users care more about the most recent added items.

How — How have these changes been implemented?

simply use order -xxx

Testing — How have these changes been tested, or how can the reviewer test the feature?

yes


Examples

Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice.
This helps with documentation and ensures maintainers can quickly understand and verify the change.

const inventoryDetailQuery = (id: string) => ({
  queryKey: inventoryItemsQueryKeys.detail(id),
  queryFn: async () =>
    sdk.admin.inventoryItem.retrieve(id, {
      fields: INVENTORY_DETAIL_FIELDS,
      order: "-created_at", // <- this line
    }),
})

Checklist

Please ensure the following before requesting a review:

  • I have added a changeset for this PR
    • Every non-breaking change should be marked as a patch
    • To add a changeset, run yarn changeset and follow the prompts
  • The changes are covered by relevant tests
  • I have verified the code works as intended locally
  • I have linked the related issue(s) if applicable

Additional Context

Add any additional context, related issues, or references that might help the reviewer understand this PR.


Note

Low Risk
Low risk UI data-fetch parameter change; main impact is that list/detail fetches will return items in a different default order.

Overview
Updates dashboard data loaders to request newest-first ordering by adding order: "-created_at" to the inventory item retrieve call and the products list query, so recently created items appear first by default.

Written by Cursor Bugbot for commit 1d52299. This will update automatically on new commits. Configure here.

@majianbing majianbing requested a review from a team as a code owner March 19, 2026 03:02
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 19, 2026

⚠️ No Changeset found

Latest commit: 1d52299

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 19, 2026

Someone is attempting to deploy a commit to the medusajs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

queryFn: async () =>
sdk.admin.inventoryItem.retrieve(id, {
fields: INVENTORY_DETAIL_FIELDS,
order: "-created_at",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order parameter added to detail query instead of list

Medium Severity

The order: "-created_at" parameter is added to inventoryDetailQuery, which calls sdk.admin.inventoryItem.retrieve(id, ...) — a single-item retrieval endpoint. Ordering is meaningless when fetching one item by ID. The PR intends to change the default sort order of the inventory list, but the inventory list table (in inventory-list-table.tsx) is untouched. This change has no user-visible effect and the actual intended inventory list ordering fix is missing.

Fix in Cursor Fix in Web

limit: 20,
offset: 0,
is_giftcard: false,
order: "-created_at",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loader query key mismatches component query key causing flicker

Medium Severity

The loader now pre-fetches with order: "-created_at", but the actual product list table component (product-list-table.tsx) calls useProducts with query params from useProductTableQuery, which defaults order to undefined when there's no URL parameter. This creates a query key mismatch: the loader caches under a key containing order: "-created_at", while the component queries under a different key without order. The loader's initialData (sorted descending) briefly displays, then gets replaced by a background refetch using the default ascending order — resulting in a visible flicker and the intended sort order not persisting.

Fix in Cursor Fix in Web

@medusa-os-bot
Copy link
Copy Markdown

medusa-os-bot bot commented Apr 9, 2026

Thank you for your contribution!

After reviewing this PR, we need a few things addressed before we can move forward:

Required changes:

  • Add a changeset for this PR. Since changes are under packages/, a changeset is required. Run yarn changeset and select @medusajs/dashboard as a patch. The changeset message must follow the format: chore(dashboard): short description
  • Fix the inventory detail loader — order: "-created_at" is added to a single-item retrieve(id, ...) call, which retrieves one record by ID. Ordering a single result has no effect and is semantically incorrect. This line should be removed from inventory-detail/loader.ts
  • Update the Testing section in the PR description — "yes" does not explain how the changes were tested or how a reviewer can verify them. Please describe the steps to reproduce and verify (e.g., open the product list page and confirm items are sorted newest-first)

Potential Bugs:

⚠️ packages/admin/dashboard/src/routes/products/product-list/loader.ts — possible query key / fetch param mismatch

queryKey: productsQueryKeys.list({ limit: 20, offset: 0, is_giftcard: false }),
queryFn: async () =>
  sdk.admin.product.list({ limit: 20, offset: 0, is_giftcard: false, order: "-created_at" }),

If order: "-created_at" is only added to the queryFn params but not to the queryKey, React Query may serve cached responses that were fetched without the ordering. Please ensure order: "-created_at" is included in both the queryKey and the queryFn params.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant