fix(dashboard): allow clearing optional collection, type, and country fields#14012
fix(dashboard): allow clearing optional collection, type, and country fields#14012bqst wants to merge 5 commits intomedusajs:developfrom
Conversation
🦋 Changeset detectedLatest commit: 72c2b49 The changes in this PR will be included in the next version bump. This PR includes changesets to release 74 packages
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 |
|
@bqst is attempting to deploy a commit to the medusajs Team on Vercel. A member of the Team first needs to authorize it. |
packages/admin/dashboard/src/components/inputs/country-select/country-select.tsx
Outdated
Show resolved
Hide resolved
|
Deployment failed with the following error: |
|
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. |
|
unstale |
|
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. |
|
This PR was closed because it has been stalled for 5 days with no activity. |
|
Thank you for your contribution! After reviewing this PR, we need a few things addressed before we can move forward: Required changes:
Potential Bugs:
// submit handler (unchanged by this PR)
origin_country: data.origin_country,When the field is cleared, the CountrySelect normalizes the value to type_id: data.type_id || null,
collection_id: data.collection_id || null,Depending on how the backend handles |
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:
CountrySelectcomponent has been refactored to useComboboxinternally, enabling search and clear functionalityWhy — 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:
This is an UX issue for optional fields that should allow users to remove their selection.
How — How have these changes been implemented?
CountrySelect Component Refactor:
Selectcomponent withComboboxinternallyallowClearprop support"") andundefinedProduct Organization Forms (create & edit):
allowClearprop tocollection_idandtype_idCombobox fieldsvalue={field.value || undefined}onChange={(value) => field.onChange(value || "")}Country of Origin Fields:
allowClearprop to CountrySelect in:Testing — How have these changes been tested, or how can the reviewer test the feature?
Manual Testing Steps:
Product Collection/Type:
Country of Origin:
Inventory Items:
Expected Behavior:
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:
""(empty string) ornullundefined(empty) orstringvalueChecklist
Please ensure the following before requesting a review:
yarn changesetand follow the promptsAdditional 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.
Combobox: Treat""as no value for single-select; only show clear when value is non-empty; minor visibility logic tweaks.CountrySelect: Refactored to useCombobox; adds search andallowClear; normalizesvalueandonChangebetween""andundefined.Comboboxfortype_idandcollection_idnowallowClearwithvalue={field.value || ""}andonChange={(v) => field.onChange(v || "")}.origin_countryusesCountrySelectwithallowClear; label marked optional where applicable.origin_countrynow clearable viaCountrySelectwithallowClear.@medusajs/dashboard.Written by Cursor Bugbot for commit e58c751. This will update automatically on new commits. Configure here.