Fix store item variant defaults and listing sorting
Auto-select first option in variation modals and sort store items by availability, then update time. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
b861ab3dc1
commit
5f4b0b4f92
@@ -83,6 +83,32 @@ export function EditStoreItemsModal({
|
||||
[variations],
|
||||
)
|
||||
|
||||
// When modal loads, ensure each variation select has a valid default selection.
|
||||
// This fixes cases where existing store-item variants don't return selections for all variations.
|
||||
useEffect(() => {
|
||||
if (!mounted || closing) return
|
||||
if (formVariations.length === 0) return
|
||||
|
||||
setRows((prev) => {
|
||||
let changed = false
|
||||
const next = prev.map((row) => {
|
||||
const nextSelections = { ...row.selections }
|
||||
for (const variation of formVariations) {
|
||||
const current = nextSelections[variation.id]
|
||||
if (current) continue
|
||||
const options = getVariationOptions(variation)
|
||||
const first = options[0]
|
||||
if (first?.id) {
|
||||
nextSelections[variation.id] = first.id
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
return changed ? { ...row, selections: nextSelections } : row
|
||||
})
|
||||
return changed ? next : prev
|
||||
})
|
||||
}, [formVariations, mounted, closing])
|
||||
|
||||
const gridTemplate = useMemo(() => {
|
||||
const variationCols = formVariations.map(() => 'minmax(110px, 1fr)').join(' ')
|
||||
const cols = [variationCols, 'minmax(120px, 1fr)', '90px', '72px', '32px']
|
||||
|
||||
Reference in New Issue
Block a user