Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Dashboard: fixed displaying variant names in product form (#14136)
Damian Legawiece0492f5c3401
diff --git a/packages/dashboard/e2e/products-new.spec.ts b/packages/dashboard/e2e/products-new.spec.tsindex 5eaa775858..5d7dcfaff9 100644--- a/packages/dashboard/e2e/products-new.spec.ts+++ b/packages/dashboard/e2e/products-new.spec.ts@@ -87,8 +87,8 @@ test.describe('new product — multi-variant', () => {// 4. Set prices via the inline Prices card.const prices = pricesCard(page)- await fillGridCell(prices.getByRole('textbox', { name: /^price for red$/i }), '20.00')- await fillGridCell(prices.getByRole('textbox', { name: /^price for blue$/i }), '22.50')+ await fillGridCell(prices.getByRole('textbox', { name: /price for .*\bred$/i }), '20.00')+ await fillGridCell(prices.getByRole('textbox', { name: /price for .*\bblue$/i }), '22.50')await page.getByRole('button', { name: /^create product$/i }).click()// Lands on the edit page.@@ -96,8 +96,10 @@ test.describe('new product — multi-variant', () => {timeout: 30_000,})- // 5. Everything round-tripped — SKUs, inventory, prices.- await expect(card.getByText('red / red').or(card.getByText('Red')).first()).toBeVisible({+ // 5. Everything round-tripped — SKUs, inventory, prices. The matrix row+ // label uses `composeOptionsText` ("<Type>: <Value>"), so match the value+ // label suffix instead of the slugged display the matrix used to render.+ await expect(card.getByText(/\bRed$/).first()).toBeVisible({timeout: 15_000,})const reloadedSkus = card.getByRole('textbox', { name: /^sku$/i })@@ -110,9 +112,11 @@ test.describe('new product — multi-variant', () => {await expect(reloadedOnHand.nth(0)).toHaveValue('3')await expect(reloadedOnHand.nth(cellsPerVariant)).toHaveValue('7')- await expect(prices.getByRole('textbox', { name: /^price for red$/i })).toHaveValue(+ await expect(prices.getByRole('textbox', { name: /price for .*\bred$/i })).toHaveValue(/^20([.,]0+)?$/,)- await expect(prices.getByRole('textbox', { name: /^price for blue$/i })).toHaveValue(/^22[.,]5/)+ await expect(prices.getByRole('textbox', { name: /price for .*\bblue$/i })).toHaveValue(+ /^22[.,]5/,+ )})})diff --git a/packages/dashboard/e2e/products-prices-inventory.spec.ts b/packages/dashboard/e2e/products-prices-inventory.spec.tsindex afd97bb148..dedf411f29 100644--- a/packages/dashboard/e2e/products-prices-inventory.spec.ts+++ b/packages/dashboard/e2e/products-prices-inventory.spec.ts@@ -60,13 +60,12 @@ test.describe('product prices — multi-variant', () => {await addOptionToVariants(page, colorLabel, ['Red', 'Blue'])// The Prices card is inline — no dialog. Fill the two cells via their- // aria-labels ("Price for red" / "Price for blue"). The cell ariaLabel- // uses the lowercase option-value name (e.g. "red"), because- // variantDisplayLabel joins `options[].value` which the picker stores- // as the canonical name, not the display label.+ // aria-labels. The cell ariaLabel is `Price for ${variant.label}`, where+ // `label` comes from `composeOptionsText` ("<Type>: <Value>"), so we+ // anchor on the trailing value label.const prices = pricesCard(page)- await fillGridCell(prices.getByRole('textbox', { name: /^price for red$/i }), '19.99')- await fillGridCell(prices.getByRole('textbox', { name: /^price for blue$/i }), '29.99')+ await fillGridCell(prices.getByRole('textbox', { name: /price for .*\bred$/i }), '19.99')+ await fillGridCell(prices.getByRole('textbox', { name: /price for .*\bblue$/i }), '29.99')// Save the product via the page-level Save button — prices ride the same// PATCH as everything else.@@ -77,12 +76,12 @@ test.describe('product prices — multi-variant', () => {// Reload and re-check the inline cells — both prices must round-trip.await page.reload()- await expect(pricesCard(page).getByRole('textbox', { name: /^price for red$/i })).toHaveValue(- /^19[.,]99$/,- )- await expect(pricesCard(page).getByRole('textbox', { name: /^price for blue$/i })).toHaveValue(- /^29[.,]99$/,- )+ await expect(+ pricesCard(page).getByRole('textbox', { name: /price for .*\bred$/i }),+ ).toHaveValue(/^19[.,]99$/)+ await expect(+ pricesCard(page).getByRole('textbox', { name: /price for .*\bblue$/i }),+ ).toHaveValue(/^29[.,]99$/)})})@@ -192,9 +191,9 @@ test.describe('product inventory — multi-variant', () => {const grid = inventoryCard(page)const headers = grid.locator('div.truncate.font-medium')await expect(headers).toHaveCount(3, { timeout: 15_000 })- await expect(headers.nth(0)).toHaveText('red')- await expect(headers.nth(1)).toHaveText('blue')- await expect(headers.nth(2)).toHaveText('green')+ await expect(headers.nth(0)).toHaveText(/\bRed$/)+ await expect(headers.nth(1)).toHaveText(/\bBlue$/)+ await expect(headers.nth(2)).toHaveText(/\bGreen$/)})})@@ -272,8 +271,8 @@ test.describe('product variants × prices × inventory', () => {// product-level Save persists everything (SKUs, inventory, prices)// in one PATCH.const prices = pricesCard(page)- await fillGridCell(prices.getByRole('textbox', { name: /^price for red$/i }), '15.00')- await fillGridCell(prices.getByRole('textbox', { name: /^price for blue$/i }), '17.50')+ await fillGridCell(prices.getByRole('textbox', { name: /price for .*\bred$/i }), '15.00')+ await fillGridCell(prices.getByRole('textbox', { name: /price for .*\bblue$/i }), '17.50')await page.getByRole('button', { name: /save product/i }).click()await expect(page.getByRole('button', { name: /save product/i })).toBeDisabled({timeout: 30_000,@@ -287,11 +286,11 @@ test.describe('product variants × prices × inventory', () => {await expect(reloadedOnHand.nth(0)).toHaveValue('5')await expect(reloadedOnHand.nth(cellsPerVariant)).toHaveValue('10')- await expect(pricesCard(page).getByRole('textbox', { name: /^price for red$/i })).toHaveValue(- /^15([.,]0+)?$/,- )- await expect(pricesCard(page).getByRole('textbox', { name: /^price for blue$/i })).toHaveValue(- /^17[.,]5/,- )+ await expect(+ pricesCard(page).getByRole('textbox', { name: /price for .*\bred$/i }),+ ).toHaveValue(/^15([.,]0+)?$/)+ await expect(+ pricesCard(page).getByRole('textbox', { name: /price for .*\bblue$/i }),+ ).toHaveValue(/^17[.,]5/)})})diff --git a/packages/dashboard/e2e/products-variants.spec.ts b/packages/dashboard/e2e/products-variants.spec.tsindex 29ec3e9d6c..4205321886 100644--- a/packages/dashboard/e2e/products-variants.spec.ts+++ b/packages/dashboard/e2e/products-variants.spec.ts@@ -20,14 +20,10 @@ test.describe('product variants', () => {await addOptionToVariants(page, colorLabel, ['Red', 'Blue', 'Green'])await addOptionToVariants(page, sizeLabel, ['S', 'M', 'L'])- // 3 × 3 = 9 generated rows. Each cell shows the joined label "Red / S".+ // 3 × 3 = 9 generated rows. Each row shows composeOptionsText+ // ("Color: Red, Size: S"); asserting on SKU input count is+ // order-independent — 3 × 3 = 9 variants means 9 SKU inputs.const variantsCard = variantsCardLocator(page)-- // The matrix row label joins canonical option value names with " / "- // (e.g. "red / s" or "s / red"). The slash order depends on the seeded- // option_type positions, which vary between local and CI. Asserting on- // the SKU input count is order-independent — 3 × 3 = 9 variants means- // 9 SKU inputs.const skuInputs = variantsCard.getByRole('textbox', { name: /^sku$/i })await expect(skuInputs).toHaveCount(9, { timeout: 15_000 })@@ -67,8 +63,9 @@ test.describe('product variants', () => {await expect(variantsCard.getByText('Red').first()).toBeVisible({ timeout: 15_000 })await expect(variantsCard.getByText('Blue').first()).toBeVisible()- // Remove the Blue row via its row-level remove button.- await variantsCard.getByRole('button', { name: /^remove blue$/i }).click()+ // Remove the Blue row via its row-level remove button. Aria-label is+ // `Remove ${variant.label}` and label = composeOptionsText → "<Type>: Blue".+ await variantsCard.getByRole('button', { name: /^remove .*\bblue$/i }).click()await expect(variantsCard.getByText('Blue')).toHaveCount(0)await page.getByRole('button', { name: /save product/i }).click()@@ -93,9 +90,9 @@ test.describe('product variants', () => {const variantsCard = variantsCardLocator(page)- await variantsCard.getByRole('button', { name: /^edit red$/i }).click()+ await variantsCard.getByRole('button', { name: /^edit .*\bred$/i }).click()const sheet = page.getByRole('dialog')- await expect(sheet.getByRole('heading', { name: /edit variant — red/i })).toBeVisible()+ await expect(sheet.getByRole('heading', { name: /edit variant — .*\bred$/i })).toBeVisible()// Scope to the sheet so we don't fight with the matrix row's SKU input,// which is registered on the same form path (matrix uses register; the@@ -113,7 +110,7 @@ test.describe('product variants', () => {})await page.reload()- await variantsCard.getByRole('button', { name: /^edit red$/i }).click()+ await variantsCard.getByRole('button', { name: /^edit .*\bred$/i }).click()const reopened = page.getByRole('dialog')await expect(reopened.getByLabel(/^sku$/i)).toHaveValue('SKU-SHEET-1')await expect(reopened.getByLabel(/^weight$/i)).toHaveValue('1.5')diff --git a/packages/dashboard/package.json b/packages/dashboard/package.jsonindex 2aa3f173c8..492c16ec11 100644--- a/packages/dashboard/package.json+++ b/packages/dashboard/package.json@@ -19,6 +19,8 @@"lint:fix": "biome check --fix .","format": "biome format --write .","preview": "vite preview",+ "test": "vitest run",+ "test:watch": "vitest","test:e2e": "playwright test","test:e2e:ui": "playwright test --ui","test:e2e:install": "playwright install chromium"@@ -76,7 +78,8 @@"@vitejs/plugin-react": "^6.0.1","tailwindcss": "^4.2.4","typescript": "~6.0.3",- "vite": "^8.0.11"+ "vite": "^8.0.11",+ "vitest": "^4.1.5"},"pnpm": {"overrides": {diff --git a/packages/dashboard/src/components/spree/bulk-price-editor/product-bulk-price-editor.tsx b/packages/dashboard/src/components/spree/bulk-price-editor/product-bulk-price-editor.tsxindex b6145da9e2..091806406f 100644--- a/packages/dashboard/src/components/spree/bulk-price-editor/product-bulk-price-editor.tsx+++ b/packages/dashboard/src/components/spree/bulk-price-editor/product-bulk-price-editor.tsx@@ -2,6 +2,8 @@ import { type BulkPriceRow, BulkPriceTable } from '@spree/dashboard-ui'import { useCallback, useMemo } from 'react'import { type UseFormReturn, useWatch } from 'react-hook-form'import { useTranslation } from 'react-i18next'+import { composeOptionsText } from '@/components/spree/products/variants-matrix'+import { useOptionTypes } from '@/hooks/use-option-types'import type { ProductFormValues, VariantPriceFormValues } from '@/schemas/product'import { currencyParts } from './currency-parts'@@ -31,6 +33,8 @@ interface Props {export function ProductBulkPriceEditor({ form, currency, productName }: Props) {const { t, i18n } = useTranslation()const variants = useWatch({ control: form.control, name: 'variants' }) ?? []+ const { data: optionTypesData } = useOptionTypes({ limit: 100 })+ const optionTypes = useMemo(() => optionTypesData?.data ?? [], [optionTypesData])const { symbol, decimal } = useMemo(() => currencyParts(currency, i18n.language || 'en'),@@ -46,7 +50,7 @@ export function ProductBulkPriceEditor({ form, currency, productName }: Props) {const out: BulkPriceRow[] = [{ id: `header:product`, kind: 'header', groupLabel: productName }]variants.forEach((v, idx) => {const price = (v.prices ?? []).find((p) => p.currency === currency)- const label = v.options.length > 0 ? v.options.map((o) => o.value).join(' / ') : null+ const label = v.options.length > 0 ? composeOptionsText(v.options, optionTypes) : nullout.push({id: `variant:${idx}`,kind: 'item',@@ -60,7 +64,7 @@ export function ProductBulkPriceEditor({ form, currency, productName }: Props) {})})return out- }, [variants, currency, productName, decimal])+ }, [variants, currency, productName, decimal, optionTypes])const handleChange = useCallback((rowId: string, field: 'amount' | 'compareAt', next: string | null) => {diff --git a/packages/dashboard/src/components/spree/products/inventory-section.tsx b/packages/dashboard/src/components/spree/products/inventory-section.tsxindex b5206b826f..e67ef7b282 100644--- a/packages/dashboard/src/components/spree/products/inventory-section.tsx+++ b/packages/dashboard/src/components/spree/products/inventory-section.tsx@@ -11,8 +11,10 @@ import { ExternalLinkIcon } from 'lucide-react'import { useCallback, useMemo } from 'react'import { type UseFormReturn, useWatch } from 'react-hook-form'import { useTranslation } from 'react-i18next'+import { useOptionTypes } from '@/hooks/use-option-types'import { useStockLocations } from '@/hooks/use-stock-locations'import type { ProductFormValues, StockItemFormValues } from '@/schemas/product'+import { composeOptionsText } from './variants-matrix'interface InventoryRow {/** Composite ID `${variantIndex}.${stockLocationId}` (or `${variantIndex}.header` for headers). */@@ -48,6 +50,8 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {const variants = useWatch({ control: form.control, name: 'variants' }) ?? []const { data: stockLocationsData, isLoading: stockLocationsLoading } = useStockLocations()const stockLocations = stockLocationsData?.data ?? []+ const { data: optionTypesData } = useOptionTypes({ limit: 100 })+ const optionTypes = useMemo(() => optionTypesData?.data ?? [], [optionTypesData])// Derive "this product has real variants" from live form state, not the// API hydration — so adding options to a fresh product immediately groups@@ -59,7 +63,7 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {const out: InventoryRow[] = []variants.forEach((variant, variantIndex) => {const variantLabel =- variant.options.map((o) => o.value).join(' / ') ||+ composeOptionsText(variant.options, optionTypes) ||variant.sku ||t('admin.products.variants.default_variant')if (hasMultipleVariants) {@@ -89,7 +93,7 @@ export function InventorySection({ form, storeId }: InventorySectionProps) {})})return out- }, [variants, stockLocations, hasMultipleVariants, t])+ }, [variants, stockLocations, hasMultipleVariants, optionTypes, t])// Find-or-create the stock_item entry for (variantIndex, stockLocationId)// and patch the given field. Uses form.setValue with the full updateddiff --git a/packages/dashboard/src/components/spree/products/variant-edit-sheet.tsx b/packages/dashboard/src/components/spree/products/variant-edit-sheet.tsxindex ac7820f197..8227f83ca6 100644--- a/packages/dashboard/src/components/spree/products/variant-edit-sheet.tsx+++ b/packages/dashboard/src/components/spree/products/variant-edit-sheet.tsx@@ -18,6 +18,7 @@ import {import { useEffect, useRef } from 'react'import { Controller, type UseFormReturn } from 'react-hook-form'import { useTranslation } from 'react-i18next'+import { useOptionTypes } from '@/hooks/use-option-types'import { useTaxCategories } from '@/hooks/use-tax-categories'import type { ProductFormValues, VariantFormValues } from '@/schemas/product'import { variantDisplayLabel } from './variants-matrix'@@ -42,6 +43,8 @@ export function VariantEditSheet({ form, variantIndex, open, onOpenChange }: Proconst { data: taxCategoriesResponse } = useTaxCategories()const taxCategories = taxCategoriesResponse?.data ?? []const hasTaxCategories = taxCategories.length > 0+ const { data: optionTypesData } = useOptionTypes({ limit: 100 })+ const optionTypes = optionTypesData?.data ?? []// Snapshot the variant when the sheet opens so Cancel can restore it.// Re-snapshot if the user switches between variant rows without closing@@ -73,7 +76,11 @@ export function VariantEditSheet({ form, variantIndex, open, onOpenChange }: Proconst variant = form.watch(`variants.${variantIndex}`)if (!variant) return null- const label = variantDisplayLabel(variant, t('admin.products.variants.default_variant'))+ const label = variantDisplayLabel(+ variant,+ t('admin.products.variants.default_variant'),+ optionTypes,+ )const handleCancel = () => {const snap = snapshotRef.currentdiff --git a/packages/dashboard/src/components/spree/products/variants-matrix.test.ts b/packages/dashboard/src/components/spree/products/variants-matrix.test.tsnew file mode 100644index 0000000000..ac1e202854--- /dev/null+++ b/packages/dashboard/src/components/spree/products/variants-matrix.test.ts@@ -0,0 +1,123 @@+import type { OptionType } from '@spree/admin-sdk'+import { describe, expect, it } from 'vitest'+import { composeOptionsText } from './variants-matrix'++// composeOptionsText only reads name/label/position/option_values; cast minimal+// fixtures rather than fabricating timestamps + ids that the helper ignores.+const COLOR = {+ name: 'color',+ label: 'Color',+ position: 0,+ option_values: [+ { name: 'red', label: 'Red' },+ { name: 'matte-black', label: 'Matte Black' },+ ],+} as OptionType++const SIZE = {+ name: 'size',+ label: 'Size',+ position: 1,+ option_values: [+ { name: 'xs', label: 'XS' },+ { name: 'l', label: 'L' },+ ],+} as OptionType++const MATERIAL = {+ name: 'material',+ label: 'Material',+ position: 2,+ option_values: [{ name: 'steel', label: 'Steel' }],+} as OptionType++describe('composeOptionsText', () => {+ it('returns an empty string when there are no options', () => {+ expect(composeOptionsText([], [COLOR, SIZE])).toBe('')+ })++ it('formats a single option as "Type: Value"', () => {+ expect(composeOptionsText([{ name: 'color', value: 'red' }], [COLOR])).toBe('Color: Red')+ })++ it('joins multiple options with ", " in input order', () => {+ expect(+ composeOptionsText(+ [+ { name: 'color', value: 'matte-black' },+ { name: 'size', value: 'xs' },+ ],+ [COLOR, SIZE],+ ),+ ).toBe('Color: Matte Black, Size: XS')+ })++ it('falls back to the type slug when the option type is not in the registry', () => {+ expect(composeOptionsText([{ name: 'material', value: 'steel' }], [COLOR])).toBe(+ 'material: steel',+ )+ })++ it('falls back to the value slug when the value is not in the registry', () => {+ expect(composeOptionsText([{ name: 'color', value: 'fuchsia' }], [COLOR])).toBe(+ 'Color: fuchsia',+ )+ })++ it('falls back per-component when the type matches but option_values is missing', () => {+ const colorNoValues = { name: 'color', label: 'Color' } as OptionType+ expect(composeOptionsText([{ name: 'color', value: 'red' }], [colorNoValues])).toBe(+ 'Color: red',+ )+ })++ it('handles registry-empty input by returning bare slugs', () => {+ expect(+ composeOptionsText(+ [+ { name: 'color', value: 'red' },+ { name: 'size', value: 'xs' },+ ],+ [],+ ),+ ).toBe('color: red, size: xs')+ })++ it('reorders by option-type position regardless of input order (backend parity)', () => {+ expect(+ composeOptionsText(+ [+ { name: 'size', value: 'l' },+ { name: 'color', value: 'red' },+ ],+ [COLOR, SIZE],+ ),+ ).toBe('Color: Red, Size: L')+ })++ it('uses Oxford "and" for three or more options (matches Rails to_sentence)', () => {+ expect(+ composeOptionsText(+ [+ { name: 'color', value: 'red' },+ { name: 'size', value: 'l' },+ { name: 'material', value: 'steel' },+ ],+ [COLOR, SIZE, MATERIAL],+ ),+ ).toBe('Color: Red, Size: L, and Material: Steel')+ })++ it('appends unknown-type options after registry-known ones in input order', () => {+ expect(+ composeOptionsText(+ [+ { name: 'finish', value: 'matte' },+ { name: 'color', value: 'red' },+ { name: 'pattern', value: 'striped' },+ ],+ [COLOR],+ ),+ ).toBe('Color: Red, finish: matte, and pattern: striped')+ })+})diff --git a/packages/dashboard/src/components/spree/products/variants-matrix.ts b/packages/dashboard/src/components/spree/products/variants-matrix.tsindex 7daebd71fc..5960901c0f 100644--- a/packages/dashboard/src/components/spree/products/variants-matrix.ts+++ b/packages/dashboard/src/components/spree/products/variants-matrix.ts@@ -2,8 +2,9 @@//// The matrix lets a merchant pick option types + values and writes the// resulting cartesian product as RHF form state. These helpers stay pure-// (no React, no SDK) so they can evolve independently of the UI shell.+// (no React) so they can evolve independently of the UI shell.+import type { OptionType } from '@spree/admin-sdk'import type { VariantFormValues } from '@/schemas/product'export interface SelectedOptionValue {@@ -185,14 +186,41 @@ export function blankVariant(}}-// Human-readable label for a variant row: "Red / Small". Falls back to-// SKU, then to a placeholder so the row is never empty.+// Mirrors backend `Spree::Variant#options_text`: "Color: Silver, Size: XS" or+// "Color: Silver, Size: XS, and Material: Steel". Sorts by option-type position+// (backend `option_values.sort_by(&:option_type.position)`) and joins with the+// same `to_sentence(words_connector: ', ', two_words_connector: ', ')` rules —+// `, ` between items and `, and ` before the last when there are 3+. Falls back+// to slugs when a label isn't in the registry (e.g. a value the merchant just+// created in this session) and to input order for types not in the registry.+export function composeOptionsText(+ options: { name: string; value: string }[],+ optionTypes: OptionType[],+): string {+ const parts = options+ .map((o, idx) => {+ const ot = optionTypes.find((x) => x.name === o.name)+ const typeLabel = ot?.label ?? o.name+ const valueLabel = ot?.option_values?.find((v) => v.name === o.value)?.label ?? o.value+ // Stable position: registry value when present, otherwise the input index+ // pushed above any registry value so unknown types trail in input order.+ const position = ot?.position ?? Number.MAX_SAFE_INTEGER - options.length + idx+ return { text: `${typeLabel}: ${valueLabel}`, position, idx }+ })+ .sort((a, b) => a.position - b.position || a.idx - b.idx)+ .map((p) => p.text)++ if (parts.length < 3) return parts.join(', ')+ return `${parts.slice(0, -1).join(', ')}, and ${parts[parts.length - 1]}`+}+export function variantDisplayLabel(variant: Pick<VariantFormValues, 'options' | 'sku'>,fallback: string,+ optionTypes: OptionType[],): string {if (variant.options.length > 0) {- return variant.options.map((o) => o.value).join(' / ')+ return composeOptionsText(variant.options, optionTypes)}if (variant.sku) return variant.skureturn fallbackdiff --git a/packages/dashboard/src/components/spree/products/variants-section.tsx b/packages/dashboard/src/components/spree/products/variants-section.tsxindex d3cd3bfd91..b88eea9dcb 100644--- a/packages/dashboard/src/components/spree/products/variants-section.tsx+++ b/packages/dashboard/src/components/spree/products/variants-section.tsx@@ -14,6 +14,7 @@ import {verticalListSortingStrategy,} from '@dnd-kit/sortable'import { CSS } from '@dnd-kit/utilities'+import type { OptionType } from '@spree/admin-sdk'import {Button,Card,@@ -56,7 +57,7 @@ interface Props {// options; labels + ids are looked up against the global option-type registry.function deriveSelectedFromVariants(variants: VariantFormValues[],- allOptionTypes: { id: string; name: string; label: string; position: number }[],+ allOptionTypes: OptionType[],): SelectedOptionType[] {const namesInOrder: string[] = []const valuesByName = new Map<string, Set<string>>()@@ -80,7 +81,10 @@ function deriveSelectedFromVariants(name: ot.name,label: ot.label,position: ot.position ?? idx,- values: Array.from(valuesByName.get(name) ?? []).map((value) => ({ name: value })),+ values: Array.from(valuesByName.get(name) ?? []).map((value) => ({+ name: value,+ label: ot.option_values?.find((ov) => ov.name === value)?.label,+ })),}}).filter((x): x is SelectedOptionType => x !== null)@@ -89,7 +93,7 @@ function deriveSelectedFromVariants(export function VariantsSection({ form }: Props) {const { t } = useTranslation()const { data: optionTypesData } = useOptionTypes({ limit: 100 })- const allOptionTypes = optionTypesData?.data ?? []+ const allOptionTypes = useMemo(() => optionTypesData?.data ?? [], [optionTypesData])const variantsArray = useFieldArray<ProductFormValues, 'variants', '_key'>({control: form.control,@@ -230,11 +234,15 @@ export function VariantsSection({ form }: Props) {if (!variant) return nullreturn {key,- label: variantDisplayLabel(variant, t('admin.products.variants.default_variant')),+ label: variantDisplayLabel(+ variant,+ t('admin.products.variants.default_variant'),+ allOptionTypes,+ ),}}).filter((entry): entry is { key: string; label: string } => entry !== null)- }, [orphanedKeys, form, t])+ }, [orphanedKeys, form, t, allOptionTypes])return (<Card>@@ -306,6 +314,7 @@ export function VariantsSection({ form }: Props) {form={form}index={index}isSimpleProduct={isSimpleProduct}+ optionTypes={allOptionTypes}onEdit={() => handleEditRow(index)}onRemove={() => handleRowRemove(index)}/>@@ -339,6 +348,7 @@ interface SortableVariantRowProps {form: UseFormReturn<ProductFormValues, any, any>index: numberisSimpleProduct: boolean+ optionTypes: OptionType[]onEdit: () => voidonRemove: () => void}@@ -348,6 +358,7 @@ function SortableVariantRow({form,index,isSimpleProduct,+ optionTypes,onEdit,onRemove,}: SortableVariantRowProps) {@@ -363,7 +374,11 @@ function SortableVariantRow({const variant = form.watch(`variants.${index}`)if (!variant) return null- const label = variantDisplayLabel(variant, t('admin.products.variants.default_variant'))+ const label = variantDisplayLabel(+ variant,+ t('admin.products.variants.default_variant'),+ optionTypes,+ )return (<TableRowdiff --git a/packages/dashboard/vitest.config.ts b/packages/dashboard/vitest.config.tsnew file mode 100644index 0000000000..dd7b09524c--- /dev/null+++ b/packages/dashboard/vitest.config.ts@@ -0,0 +1,16 @@+import path from 'node:path'+import { defineConfig } from 'vitest/config'++export default defineConfig({+ resolve: {+ alias: {+ '@': path.resolve(import.meta.dirname, 'src'),+ },+ },+ test: {+ globals: true,+ environment: 'node',+ include: ['src/**/*.{test,spec}.{ts,tsx}'],+ exclude: ['node_modules/**', 'e2e/**', 'dist/**'],+ },+})diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 3af6a76c6b..fcdf70bf85 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -285,6 +285,9 @@ importers:vite:specifier: ^8.0.11version: 8.0.11(@types/[email protected])([email protected])([email protected])([email protected])([email protected])+ vitest:+ specifier: ^4.1.5+ version: 4.1.5(@types/[email protected])(@vitest/[email protected])([email protected](@types/[email protected])([email protected]))([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))packages/dashboard-core:dependencies: