Skip to content

fix(dashboard): allow clearing optional collection, type, and country fields#14012

Open
bqst wants to merge 5 commits intomedusajs:developfrom
bqst:fix/combobox-allow-clear
Open

fix(dashboard): allow clearing optional collection, type, and country fields#14012
bqst wants to merge 5 commits intomedusajs:developfrom
bqst:fix/combobox-allow-clear

Conversation

@bqst
Copy link
Copy Markdown
Contributor

@bqst bqst commented Nov 7, 2025

Summary

What — What changes are introduced in this PR?

This PR adds the ability to clear/unset optional fields in product and inventory forms. Specifically:

  • Product collection and type selectors can now be cleared
  • Country of origin fields can now be cleared in product, product variant, and inventory forms
  • The CountrySelect component has been refactored to use Combobox internally, enabling search and clear functionality

Why — Why are these changes relevant or necessary?

Currently, when a user assigns a collection, type, or country of origin to a product/variant/inventory item, there is no way to unset that value through the UI. Once selected, the field is locked to that value, forcing users to either:

  • Keep the unwanted value
  • Delete and recreate the resource
  • Manually update via API

This is an UX issue for optional fields that should allow users to remove their selection.

How — How have these changes been implemented?

  1. CountrySelect Component Refactor:

    • Replaced Select component with Combobox internally
    • Added allowClear prop support
    • Implemented proper value handling to convert between empty string ("") and undefined
    • Now provides search functionality as a bonus
  2. Product Organization Forms (create & edit):

    • Added allowClear prop to collection_id and type_id Combobox fields
    • Added value normalization: value={field.value || undefined}
    • Added onChange handler: onChange={(value) => field.onChange(value || "")}
    • Ensures cleared values convert to empty string to match default values
  3. Country of Origin Fields:

    • Added allowClear prop to CountrySelect in:
      • Product variant edit form
      • Product attributes form (create & edit)
      • Inventory item form (create & edit)

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

Manual Testing Steps:

  1. Product Collection/Type:

    • Navigate to any product → Edit → Organization
    • Select a collection and/or type
    • Save the form
    • Edit organization again → Click the "X" button on collection/type
    • Verify the value clears and the field shows as empty
    • Save and verify the collection/type is removed from the product
  2. Country of Origin:

    • Navigate to product → Edit → Attributes
    • Select a country of origin
    • Save the form
    • Edit attributes again → Click the "X" button on country
    • Verify the country clears
    • Save and verify the country is removed
  3. Inventory Items:

    • Create or edit an inventory item
    • Select a country of origin in the attributes section
    • Click the clear button
    • Verify the country field clears properly

Expected Behavior:

  • Clear button (X icon) appears when a value is selected
  • Clicking clear removes the selected value
  • Field returns to empty state
  • Form can be saved with the cleared value
  • Value is properly removed from the resource

Examples

Using allowClear with Combobox

// Product collection selector - optional field
<Combobox
{...field}
value={field.value || undefined}
onChange={(value) => field.onChange(value || "")}
options={collections.options}
allowClear // Enables the clear button
/>### Updated CountrySelect component

// Before: Used Select component (no search, no clear)
<CountrySelect {...field} />

// After: Uses Combobox internally (searchable + clearable)
<CountrySelect {...field} allowClear /> // For optional fields
<CountrySelect {...field} /> // For required fields (no clear button)### Value Handling Pattern

// The pattern used for optional single-select Combobox fields:
<Combobox
{...field}
value={field.value || undefined} // Convert "" to undefined for Combobox
onChange={(value) => field.onChange(value || "")} // Convert undefined to "" for form
allowClear
/>This ensures proper conversion between:

  • Form uses: "" (empty string) or null
  • Combobox uses: undefined (empty) or string value

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

This fix addresses a recurring UX issue where users had no way to unset optional fields once a value was selected, improving the overall form editing experience.


Note

Enable clearing product type/collection and country-of-origin across product, variant, and inventory forms by refactoring CountrySelect to Combobox and adjusting Combobox value handling.

  • UI Inputs:
    • Combobox: Treat "" as no value for single-select; only show clear when value is non-empty; minor visibility logic tweaks.
    • CountrySelect: Refactored to use Combobox; adds search and allowClear; normalizes value and onChange between "" and undefined.
  • Forms:
    • Product Organization (create/edit): Combobox for type_id and collection_id now allowClear with value={field.value || ""} and onChange={(v) => field.onChange(v || "")}.
    • Product Attributes & Variant Edit: origin_country uses CountrySelect with allowClear; label marked optional where applicable.
    • Inventory (create/edit): origin_country now clearable via CountrySelect with allowClear.
  • Release: Add patch changeset for @medusajs/dashboard.

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

@bqst bqst requested a review from a team as a code owner November 7, 2025 20:55
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Nov 7, 2025

🦋 Changeset detected

Latest commit: 72c2b49

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

vercel bot commented Nov 7, 2025

@bqst 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
Contributor

@fPolic fPolic left a comment

Choose a reason for hiding this comment

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

looks good overall @bqst!
have one discussion comment

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 3, 2025

Deployment failed with the following error:

The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 4, 2026

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Jan 4, 2026
@bqst
Copy link
Copy Markdown
Contributor Author

bqst commented Jan 5, 2026

unstale

@github-actions github-actions bot removed the Stale label Jan 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 6, 2026

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Feb 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 5 days with no activity.

@github-actions github-actions bot closed this Feb 11, 2026
@NicolasGorga NicolasGorga reopened this Mar 1, 2026
@NicolasGorga NicolasGorga removed the Stale label Mar 1, 2026
@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:

  • Please link a related issue using a closing keyword (e.g. Closes #XXXX) in the PR description. Per our contribution guidelines, non-trivial changes require a linked issue so the team can track context and ensure alignment before significant work is merged.

Potential Bugs:

⚠️ product-attributes-form.tsx — Clearing origin_country submits "" instead of null

// submit handler (unchanged by this PR)
origin_country: data.origin_country,

When the field is cleared, the CountrySelect normalizes the value to "" (empty string). The submit handler then sends origin_country: "" to the API. Compare with the organization form, where type_id and collection_id explicitly convert to null on submit:

type_id: data.type_id || null,
collection_id: data.collection_id || null,

Depending on how the backend handles origin_country: "" vs null, clearing the country may silently fail. The same concern applies to the inventory and variant forms. Please verify the backend accepts "" to clear these string fields, or convert to null in the submit handlers similar to the organization form.

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.

3 participants