Skip to content

Conversation

@adevinwild
Copy link
Contributor

@adevinwild adevinwild commented Nov 27, 2025

Summary

What — What changes are introduced in this PR?

This PR introduce filtering by order total on the Admin UI and on the API side using operators ($eq, $gte, $lte...)

Why — Why are these changes relevant or necessary?

Currently it is not possible

How — How have these changes been implemented?

To achieve this multiple parts of the code have been updated :

  • The AdminGetOrdersParams API validator had to be modified to accept the total key, which will then be mapped to the correct field on the order_summary table ( total is mapped to summary.totals.current_order_total, as it is the field synecd with the order's total)
  • Fix of the operators insertion in the URL on the NumberFilter component as it was not matching the createOperatorMap validator util ( operator was not inserted with prefix $ for the API, e.g gt instead of $gt )
  • Added new filters on the orders table filters

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

  • Build the packages
  • Try to filter by Order total

Examples

You can filter orders using the API by doing so :

http://localhost:9000/admin/orders?total[<operator>]=<value>

For example if you want to fetch all orders with a total of $100 :

http://localhost:9000/admin/orders?total[$eq]=100

If you want greater than $100 :

http://localhost:9000/admin/orders?total[$gt]=100

You get the idea, you can use all the common operators that are used in Medusa and listed here :
https://docs.medusajs.com/resources/service-factory-reference/tips/filtering#supported-filter-operators-list


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

Related to the following RFC
#14154


Note

Adds operator-based filtering by order total to the Admin Orders API and UI, with validator mapping, UI filter/operator fixes, query support, and tests.

  • Backend/API:
    • Extend AdminGetOrdersParams to accept total with operator maps and transform to summary.totals.current_order_total.
    • Refactor version parsing to use isString in validators.ts.
  • Admin UI:
    • Update NumberFilter to use $eq/$gt/$lt operators and adjust display/parsing.
    • Add total number filter in use-order-table-filters.tsx.
    • Include total in use-order-table-query.tsx and JSON-parse its value.
    • In configurable-data-table.tsx, add filter id/key compatibility and JSON-parse filter query params.
  • Tests:
    • Add integration tests for filtering orders by total using $eq, $gte, $lte in integration-tests/http/__tests__/order/admin/order.spec.ts.
  • Changeset:
    • Add changeset marking @medusajs/dashboard minor and @medusajs/medusa patch.

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

…consistency

Based on the `createOperatorMap`, changed the operator key in selectedParams from `[operator]` to `[$${operator}]` to ensure consistent formatting across the filter logic (e.g `$lte` instead of `lte`)
- this points to the order_summary table
…lters

- Introduced a new filter for `total` in the order table query and updated the filters to include it.
- This enhancement allows users to filter orders based on the total amount.
@changeset-bot
Copy link

changeset-bot bot commented Nov 27, 2025

🦋 Changeset detected

Latest commit: f3b5272

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 74 packages
Name Type
@medusajs/dashboard Major
@medusajs/medusa Major
@medusajs/admin-bundler Major
@medusajs/test-utils Major
@medusajs/medusa-oas-cli Major
integration-tests-http Patch
@medusajs/analytics Major
@medusajs/api-key Major
@medusajs/auth Major
@medusajs/caching Major
@medusajs/cart Major
@medusajs/currency Major
@medusajs/customer Major
@medusajs/file Major
@medusajs/fulfillment Major
@medusajs/index Major
@medusajs/inventory Major
@medusajs/link-modules Major
@medusajs/locking Major
@medusajs/notification Major
@medusajs/order Major
@medusajs/payment Major
@medusajs/pricing Major
@medusajs/product Major
@medusajs/promotion Major
@medusajs/region Major
@medusajs/sales-channel Major
@medusajs/settings Major
@medusajs/stock-location Major
@medusajs/store Major
@medusajs/tax Major
@medusajs/user Major
@medusajs/workflow-engine-inmemory Major
@medusajs/workflow-engine-redis Major
@medusajs/draft-order Major
@medusajs/oas-github-ci Major
@medusajs/cache-inmemory Major
@medusajs/cache-redis Major
@medusajs/event-bus-local Major
@medusajs/event-bus-redis Major
@medusajs/analytics-local Major
@medusajs/analytics-posthog Major
@medusajs/auth-emailpass Major
@medusajs/auth-github Major
@medusajs/auth-google Major
@medusajs/caching-redis Major
@medusajs/file-local Major
@medusajs/file-s3 Major
@medusajs/fulfillment-manual Major
@medusajs/locking-postgres Major
@medusajs/locking-redis Major
@medusajs/notification-local Major
@medusajs/notification-sendgrid Major
@medusajs/payment-stripe Major
@medusajs/core-flows Major
@medusajs/framework Major
@medusajs/js-sdk Major
@medusajs/modules-sdk Major
@medusajs/orchestration Major
@medusajs/types Major
@medusajs/utils Major
@medusajs/workflows-sdk Major
@medusajs/cli Major
@medusajs/deps Major
@medusajs/telemetry Major
@medusajs/admin-sdk Major
@medusajs/admin-shared Major
@medusajs/admin-vite-plugin Major
@medusajs/icons Major
@medusajs/toolbox Major
@medusajs/ui-preset Major
create-medusa-app Major
medusa-dev-cli Major
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel
Copy link

vercel bot commented Nov 27, 2025

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

A member of the Team first needs to authorize it.

@adevinwild adevinwild changed the title feat: Introduce filtering by orders total on the Admin UI RFC - feat: Introduce filtering by orders total on the Admin UI Nov 28, 2025
@adevinwild adevinwild marked this pull request as ready for review November 28, 2025 13:52
@adevinwild adevinwild requested a review from a team as a code owner November 28, 2025 13:52
Copy link

@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.

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on December 17

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

adrien2p
adrien2p previously approved these changes Dec 1, 2025
Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

This looks good to me, do you have a video or screen shot of the result?

…r explicit versioning

so far if we just try to filter summary total, it will get all versions, leading to potential inconsistency if you have multiple versions for an order when you want to filter by total
…pport for explicit versioning"

This reverts commit 483dac7.
@adrien2p adrien2p dismissed their stale review December 1, 2025 13:55

Waiting for the end

@adevinwild
Copy link
Contributor Author

adevinwild commented Dec 1, 2025

This looks good to me, do you have a video or screen shot of the result?

Yes here it is, but there is two issues I discovered while testing edge cases :
CleanShot 2025-12-01 at 15 12 04
CleanShot 2025-12-01 at 15 12 52

Problems :

  • If you have multiple versions on a summary, it will look for all versions, I'm trying to find a solution for that where I could filter by the latest summary version 🤔
  • Need to handle the NumberFilter on the view configurations FF too just to make sure it is compatible with that change

@adevinwild adevinwild marked this pull request as draft December 1, 2025 14:14
…keys to IDs

Updated the filter processing logic to assign 'key' as 'id' when 'id' is not present, enhancing compatibility with existing filter structures. This change ensures that filters are correctly parsed and utilized in query parameters.
@adevinwild
Copy link
Contributor Author

Ok fixed the filter issue that was setting undefined instead of o_total
For the orders that were returned with the not correct amount, the issue is coming from my dataset 🙌

@adevinwild adevinwild marked this pull request as ready for review December 1, 2025 15:38
@adevinwild
Copy link
Contributor Author

@adrien2p here is the demo

CleanShot.2025-12-01.at.16.45.08.yafw.balanced.mp4

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

thanks man 🎉 should we add a new integration tests that filters with summary total on the order?

z.number().optional()
)
version: z.preprocess((val) => {
if (val && typeof val === "string") {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: could we use isString

…$gte, and $lte operators

Implemented a series of tests to verify the functionality of filtering orders based on total using various operators. The tests cover matching and non-matching scenarios for each operator, ensuring accurate filtering behavior.
@adevinwild
Copy link
Contributor Author

thanks man 🎉 should we add a new integration tests that filters with summary total on the order?

hey @adrien2p , I addressed the feedacks, is it ok to have a describe in the tests this way to better organize the operators ? 🤔

@adrien2p
Copy link
Member

adrien2p commented Dec 3, 2025

thanks man 🎉 should we add a new integration tests that filters with summary total on the order?

hey @adrien2p , I addressed the feedacks, is it ok to have a describe in the tests this way to better organize the operators ? 🤔

Yes thats alright, If I could make a suggestion it would be to maybe use it.each with operator and object for filter and expectation. So that if new operators would be added in the future it would make it easier to add new test expectation for new operators. But no strong opinion on that let me know what you think

@adevinwild
Copy link
Contributor Author

thanks man 🎉 should we add a new integration tests that filters with summary total on the order?

hey @adrien2p , I addressed the feedacks, is it ok to have a describe in the tests this way to better organize the operators ? 🤔

Yes thats alright, If I could make a suggestion it would be to maybe use it.each with operator and object for filter and expectation. So that if new operators would be added in the future it would make it easier to add new test expectation for new operators. But no strong opinion on that let me know what you think

I wasn't familiar with it.each, it's so much cleaner I agree!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants