Hide already-selected option values from variant dropdowns#13721
Open
Hide already-selected option values from variant dropdowns#13721
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Free Tier 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.
Bugbot Autofix prepared fixes for both issues found in the latest run.
- ✅ Fixed: Stale preloaded options reappear after option name change
- I now refresh
preloadedOptionsValuefrom the currently loaded TomSelect options before handling selection changes so stale option-type values are not reintroduced.
- I now refresh
- ✅ Fixed: Event listener accumulates on controller reconnect
- I replaced the anonymous listener with a stored handler and remove it in
disconnect()to prevent duplicate listeners after reconnects.
- I replaced the anonymous listener with a stored handler and remove it in
Or push these changes by commenting:
@cursor push 35d59c5935
Preview (35d59c5935)
diff --git a/spree/admin/app/javascript/spree/admin/controllers/multi_tom_select_controller.js b/spree/admin/app/javascript/spree/admin/controllers/multi_tom_select_controller.js
--- a/spree/admin/app/javascript/spree/admin/controllers/multi_tom_select_controller.js
+++ b/spree/admin/app/javascript/spree/admin/controllers/multi_tom_select_controller.js
@@ -12,11 +12,16 @@
this.element.reset = this.reset.bind(this)
this.element.values = this.values.bind(this)
this.element.setValues = this.setValues.bind(this)
- this.element.addEventListener('tomSelectInitialized', () => this.refreshAvailableOptions())
+ this.tomSelectInitializedHandler = this.refreshAvailableOptions.bind(this)
+ this.element.addEventListener('tomSelectInitialized', this.tomSelectInitializedHandler)
this.setValues(this.preloadedValuesValue)
}
+ disconnect() {
+ this.element.removeEventListener('tomSelectInitialized', this.tomSelectInitializedHandler)
+ }
+
reset(addBlankSelect = true) {
this.selectTargets.forEach((container) => container.remove())
@@ -42,6 +47,7 @@
handleSelect(event) {
const ts = event.target.tomselect
+ this.refreshPreloadedOptions()
if (ts && ts.getValue().length > 0 && (this.lastSelect === event.target || this.selectTargets.length === 1)) {
this.addSelect()
@@ -53,6 +59,29 @@
this.refreshAvailableOptions()
}
+ refreshPreloadedOptions() {
+ const options = new Map()
+
+ this.selectTargets.forEach((target) => {
+ const ts = target.querySelector('select')?.tomselect
+ if (!ts) return
+
+ Object.values(ts.options).forEach((option) => {
+ const optionId = String(option.id)
+ if (!options.has(optionId)) {
+ options.set(optionId, {
+ id: optionId,
+ name: option.name || option.text
+ })
+ }
+ })
+ })
+
+ if (options.size > 0) {
+ this.preloadedOptionsValue = Array.from(options.values())
+ }
+ }
+
removeSelect(container) {
if (this.selectTargets.length > 1) {
const select = container.querySelector('select')
spree/admin/app/javascript/spree/admin/controllers/multi_tom_select_controller.js
Show resolved
Hide resolved
spree/admin/app/javascript/spree/admin/controllers/multi_tom_select_controller.js
Outdated
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13721 +/- ##
=======================================
Coverage 89.73% 89.73%
=======================================
Files 819 819
Lines 24045 24045
=======================================
Hits 21577 21577
Misses 2468 2468
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

https://linear.app/vendo/issue/V-3161/product-form-option-values-can-select-already-added-values
Note
Cursor Bugbot is generating a summary for commit c048085. Configure here.