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
Add a bulk shipping spreadsheet to the product page
Damian Legawiec96135c4a49f6
diff --git a/packages/dashboard-ui/src/index.ts b/packages/dashboard-ui/src/index.tsindex 1ebcc01bf4..5939ff275f 100644--- a/packages/dashboard-ui/src/index.ts+++ b/packages/dashboard-ui/src/index.ts@@ -27,6 +27,7 @@ export * from './spree/address-block'export * from './spree/back-button'export * from './spree/bulk-dialog'export * from './spree/bulk-price-table'+export * from './spree/bulk-shipping-table'export * from './spree/calculator-summary'export * from './spree/color-picker'export * from './spree/confirm-dialog'diff --git a/packages/dashboard-ui/src/spree/bulk-shipping-table.tsx b/packages/dashboard-ui/src/spree/bulk-shipping-table.tsxnew file mode 100644index 0000000000..7370e1c5c4--- /dev/null+++ b/packages/dashboard-ui/src/spree/bulk-shipping-table.tsx@@ -0,0 +1,111 @@+import type { ColumnDef } from '@tanstack/react-table'+import { useMemo } from 'react'+import { DataGrid, DecimalCell, ReadOnlyCell } from './data-grid'++export interface BulkShippingRow {+ id: string+ variantLabel?: string | null+ sku?: string | null+ // Display strings — decimal weight/dimension values, or null for unset.+ weight?: string | null+ height?: string | null+ width?: string | null+ depth?: string | null+}++export type BulkShippingField = 'weight' | 'height' | 'width' | 'depth'++export interface BulkShippingTableLabels {+ /** Column header for the variant label column. */+ variant: string+ /** Column header for the SKU column. */+ sku: string+ /** Column headers for the editable measurement columns. */+ weight: string+ height: string+ width: string+ depth: string+ /** Placeholder for a variant row with no options text (e.g. "Default"). */+ variantDefault: string+ /** Shown when rows.length === 0. */+ emptyMessage?: string+ /** Aria label on the DataGrid for screen readers. */+ gridAriaLabel?: string+}++export interface BulkShippingTableProps {+ rows: BulkShippingRow[]+ /** Localized strings — the caller owns translations. */+ labels: BulkShippingTableLabels+ /** Called when the user commits a value to a cell. The id is the row id. */+ onChange: (rowId: string, field: BulkShippingField, value: string | null) => void+}++// Editable columns in grid order; the +2 offset skips the two read-only+// leading columns when assigning keyboard-navigation coordinates.+const FIELDS: BulkShippingField[] = ['weight', 'height', 'width', 'depth']++/**+ * Presentational primitive for a "spreadsheet of variant shipping fields" UI.+ * Owns the DataGrid columns and decimal-cell wiring; selection, copy/paste,+ * and drag-fill come from the DataGrid. Owns NO data fetching, edit tracking,+ * or save logic — the caller projects its rows into BulkShippingRow shape and+ * writes edits back through `onChange`.+ */+export function BulkShippingTable({ rows, labels, onChange }: BulkShippingTableProps) {+ const columns = useMemo<ColumnDef<BulkShippingRow>[]>(+ () => [+ {+ id: 'variant',+ header: labels.variant,+ cell: ({ row }) => (+ <ReadOnlyCell className="text-muted-foreground">+ {row.original.variantLabel ?? labels.variantDefault}+ </ReadOnlyCell>+ ),+ },+ {+ id: 'sku',+ header: labels.sku,+ cell: ({ row }) => (+ <ReadOnlyCell className="font-mono text-xs text-muted-foreground">+ {row.original.sku ?? '—'}+ </ReadOnlyCell>+ ),+ },+ ...FIELDS.map<ColumnDef<BulkShippingRow>>((field, fieldIndex) => ({+ id: field,+ header: () => <span className="block text-right">{labels[field]}</span>,+ cell: ({ row }) => {+ const r = row.original+ // No section-header rows in this grid, so the table row index IS+ // the keyboard-navigation row coordinate.+ const coords = { row: row.index, col: fieldIndex + 2 }+ const label = r.variantLabel ?? labels.variantDefault+ return (+ <DecimalCell+ coords={coords}+ value={r[field] ?? null}+ onChange={(next) => onChange(r.id, field, next)}+ ariaLabel={`${labels[field]} — ${label}`}+ />+ )+ },+ })),+ ],+ [onChange, labels],+ )++ if (rows.length === 0) {+ return <p className="text-sm text-muted-foreground">{labels.emptyMessage ?? ''}</p>+ }++ return (+ <DataGrid<BulkShippingRow>+ rows={rows}+ columns={columns}+ getRowId={(row) => row.id}+ aria-label={labels.gridAriaLabel}+ />+ )+}diff --git a/packages/dashboard-ui/src/spree/data-grid/cells.tsx b/packages/dashboard-ui/src/spree/data-grid/cells.tsxindex d8f146379e..bcf38b7351 100644--- a/packages/dashboard-ui/src/spree/data-grid/cells.tsx+++ b/packages/dashboard-ui/src/spree/data-grid/cells.tsx@@ -140,8 +140,9 @@ interface MoneyCellProps extends BaseCellProps {* `"12,50"` are fine, the backend's `Spree::LocalizedNumber` does the* parsing. `null` only when the user explicitly blanks the field. */onChange: (next: string | null) => void- /** Currency symbol rendered as a non-editable prefix (`$`, `€`, `kr`, …). */- symbol: string+ /** Currency symbol rendered as a non-editable prefix (`$`, `€`, `kr`, …).+ * Omit for a plain decimal cell with no prefix. */+ symbol?: string/*** Locale decimal separator used only for display (canonical `.` →* locale char). Whatever the user types is shipped as-is; the@@ -252,12 +253,14 @@ export function MoneyCell({isEditing && 'bg-card ring-2 ring-blue-500 ring-inset',)}>- <span- className="pl-3 text-muted-foreground pointer-events-none select-none tabular-nums"- aria-hidden- >- {symbol}- </span>+ {symbol != null && (+ <span+ className="pl-3 text-muted-foreground pointer-events-none select-none tabular-nums"+ aria-hidden+ >+ {symbol}+ </span>+ )}<inputref={inputRef}type="text"@@ -279,7 +282,8 @@ export function MoneyCell({}}aria-label={ariaLabel}className={cn(- 'block h-9 w-full cursor-cell border-0 bg-transparent pl-1 pr-3 text-right tabular-nums outline-none',+ 'block h-9 w-full cursor-cell border-0 bg-transparent pr-3 text-right tabular-nums outline-none',+ symbol != null ? 'pl-1' : 'pl-3',isEditing && 'cursor-text',)}/>@@ -287,6 +291,13 @@ export function MoneyCell({)}+/** Editable decimal cell — `MoneyCell` without the currency prefix. Keeps+ * decimals (unlike `NumberCell`, which truncates to integers); for+ * measurements like weight and dimensions. */+export function DecimalCell(props: Omit<MoneyCellProps, 'symbol'>) {+ return <MoneyCell {...props} />+}+interface SwitchCellProps extends BaseCellProps {value: booleanonChange: (next: boolean) => voiddiff --git a/packages/dashboard-ui/src/spree/data-grid/index.ts b/packages/dashboard-ui/src/spree/data-grid/index.tsindex 6037b2ef7e..6c219c02df 100644--- a/packages/dashboard-ui/src/spree/data-grid/index.ts+++ b/packages/dashboard-ui/src/spree/data-grid/index.ts@@ -1,4 +1,4 @@-export { MoneyCell, NumberCell, ReadOnlyCell, SelectCell, SwitchCell } from './cells'+export { DecimalCell, MoneyCell, NumberCell, ReadOnlyCell, SelectCell, SwitchCell } from './cells'export { useDataGridContext } from './context'export { DataGrid } from './data-grid'export { editableRowIndex } from './helpers'diff --git a/packages/dashboard/src/components/spree/products/product-bulk-shipping-editor.tsx b/packages/dashboard/src/components/spree/products/product-bulk-shipping-editor.tsxnew file mode 100644index 0000000000..bb4f385c57--- /dev/null+++ b/packages/dashboard/src/components/spree/products/product-bulk-shipping-editor.tsx@@ -0,0 +1,85 @@+import {+ type BulkShippingField,+ type BulkShippingRow,+ BulkShippingTable,+} from '@spree/dashboard-ui'+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 type { ProductFormValues } from '../../../schemas/product'+import { composeOptionsText } from './variants-matrix'++interface Props {+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ form: UseFormReturn<ProductFormValues, any, any>+}++/**+ * Form-backed shipping spreadsheet for ONE product's variants: weight,+ * height, width, depth. Reads from and writes to the parent product form's+ * `variants[]` array — works equally for persisted and unsaved variants —+ * so edits ride the product form's Save like the prices grid. Units are+ * deliberately not columns here: they rarely vary per variant and stay+ * editable in the variant edit sheet.+ */+export function ProductBulkShippingEditor({ form }: Props) {+ const { t } = useTranslation()+ const variants = useWatch({ control: form.control, name: 'variants' }) ?? []+ const { data: optionTypesData } = useOptionTypes({ limit: 100 })+ const optionTypes = useMemo(() => optionTypesData?.data ?? [], [optionTypesData])++ // Row id is the variant's array index so onChange can write back+ // unambiguously, even for variants without a persisted id.+ const rows = useMemo<BulkShippingRow[]>(+ () =>+ variants.map((v, idx) => ({+ id: `variant:${idx}`,+ variantLabel: v.options.length > 0 ? composeOptionsText(v.options, optionTypes) : null,+ sku: v.sku ?? null,+ weight: v.weight != null ? String(v.weight) : null,+ height: v.height != null ? String(v.height) : null,+ width: v.width != null ? String(v.width) : null,+ depth: v.depth != null ? String(v.depth) : null,+ })),+ [variants, optionTypes],+ )++ const handleChange = useCallback(+ (rowId: string, field: BulkShippingField, next: string | null) => {+ if (!rowId.startsWith('variant:')) return+ const idx = Number.parseInt(rowId.slice('variant:'.length), 10)+ if (Number.isNaN(idx)) return++ const path = `variants.${idx}.${field}` as const+ if (next == null || next.trim() === '') {+ form.setValue(path, null, { shouldDirty: true })+ return+ }+ // Accept a comma decimal (the cell ships raw input); ignore anything+ // that doesn't parse to a non-negative number rather than mangling it.+ const parsed = Number(next.trim().replace(',', '.'))+ if (!Number.isFinite(parsed) || parsed < 0) return+ form.setValue(path, parsed, { shouldDirty: true })+ },+ [form],+ )++ return (+ <BulkShippingTable+ rows={rows}+ onChange={handleChange}+ labels={{+ variant: t('admin.pages.products.price_lists.edit_prices.columns.variant'),+ sku: t('admin.fields.variant.sku.label'),+ weight: t('admin.fields.variant.weight.label'),+ height: t('admin.fields.variant.height.label'),+ width: t('admin.fields.variant.width.label'),+ depth: t('admin.fields.variant.depth.label'),+ variantDefault: t('admin.pages.products.price_lists.edit_prices.variant_default'),+ emptyMessage: t('admin.pages.products.edit.bulk_shipping.no_variants'),+ gridAriaLabel: t('admin.pages.products.edit.bulk_shipping.grid_aria'),+ }}+ />+ )+}diff --git a/packages/dashboard/src/components/spree/products/product-form-cards.tsx b/packages/dashboard/src/components/spree/products/product-form-cards.tsxindex 9612626bf0..ae25a40ec4 100644--- a/packages/dashboard/src/components/spree/products/product-form-cards.tsx+++ b/packages/dashboard/src/components/spree/products/product-form-cards.tsx@@ -54,6 +54,7 @@ import type { ProductFormValues } from '../../../schemas/product'import { ProductBulkPriceEditor } from '../bulk-price-editor/product-bulk-price-editor'import { InventorySection } from './inventory-section'import { MediaEditSheet } from './media-edit-sheet'+import { ProductBulkShippingEditor } from './product-bulk-shipping-editor'import { VariantsSection } from './variants-section'// eslint-disable-next-line @typescript-eslint/no-explicit-any@@ -152,6 +153,27 @@ export function PricesCard({ form, productName }: FormCardProps & { productName:)}+// ---------------------------------------------------------------------------+// Shipping — inline form-backed spreadsheet of per-variant weight and+// dimensions. Same model as PricesCard: edits ride the parent product+// form's Save.+// ---------------------------------------------------------------------------++export function ShippingCard({ form }: FormCardProps) {+ const { t } = useTranslation()++ return (+ <Card>+ <CardHeader>+ <CardTitle>{t('admin.fields.shipping.label')}</CardTitle>+ </CardHeader>+ <CardContent>+ <ProductBulkShippingEditor form={form} />+ </CardContent>+ </Card>+ )+}+// ---------------------------------------------------------------------------// Media — edit-only. On create, render a "save first" empty state so the// merchant sees where uploads will go but can't trigger them.diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.jsonindex ad633d66be..506c724445 100644--- a/packages/dashboard/src/locales/ar.json+++ b/packages/dashboard/src/locales/ar.json@@ -2029,6 +2029,10 @@"edit": {"bulk_prices": {"no_variants": "أضف متغيرًا واحدًا على الأقل لبدء تعديل الأسعار."+ },+ "bulk_shipping": {+ "no_variants": "أضف متغيرًا واحدًا على الأقل لبدء تعديل بيانات الشحن.",+ "grid_aria": "جدول شحن المتغيرات"}},"inventory": {diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.jsonindex 4c827ede98..73ea620a68 100644--- a/packages/dashboard/src/locales/de.json+++ b/packages/dashboard/src/locales/de.json@@ -2029,6 +2029,10 @@"edit": {"bulk_prices": {"no_variants": "Fügen Sie mindestens eine Variante hinzu, um die Preisbearbeitung zu starten."+ },+ "bulk_shipping": {+ "no_variants": "Füge mindestens eine Variante hinzu, um Versanddaten zu bearbeiten.",+ "grid_aria": "Versandtabelle der Varianten"}},"inventory": {diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.jsonindex 798d27d1ac..3bb6b68c71 100644--- a/packages/dashboard/src/locales/en.json+++ b/packages/dashboard/src/locales/en.json@@ -2029,6 +2029,10 @@"edit": {"bulk_prices": {"no_variants": "Add at least one variant to start editing prices."+ },+ "bulk_shipping": {+ "no_variants": "Add at least one variant to start editing shipping.",+ "grid_aria": "Variant shipping spreadsheet"}},"inventory": {diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.jsonindex d4c919a557..76c4d4538d 100644--- a/packages/dashboard/src/locales/fr.json+++ b/packages/dashboard/src/locales/fr.json@@ -2029,6 +2029,10 @@"edit": {"bulk_prices": {"no_variants": "Ajoutez au moins une variante pour commencer à modifier les prix."+ },+ "bulk_shipping": {+ "no_variants": "Ajoutez au moins une variante pour modifier les données d'expédition.",+ "grid_aria": "Tableau d'expédition des variantes"}},"inventory": {diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.jsonindex e33960c09e..91755596be 100644--- a/packages/dashboard/src/locales/pl.json+++ b/packages/dashboard/src/locales/pl.json@@ -2041,6 +2041,10 @@"edit": {"bulk_prices": {"no_variants": "Dodaj co najmniej jeden wariant, aby rozpocząć edycję cen."+ },+ "bulk_shipping": {+ "no_variants": "Dodaj co najmniej jeden wariant, aby edytować dane wysyłki.",+ "grid_aria": "Arkusz wysyłki wariantów"}},"inventory": {diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.jsonindex be5f31ca82..1202cb3336 100644--- a/packages/dashboard/src/locales/zh-CN.json+++ b/packages/dashboard/src/locales/zh-CN.json@@ -2029,6 +2029,10 @@"edit": {"bulk_prices": {"no_variants": "至少添加一个变体以开始编辑价格。"+ },+ "bulk_shipping": {+ "no_variants": "请至少添加一个变体以编辑运输信息。",+ "grid_aria": "变体运输表格"}},"inventory": {diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsxindex 6002019645..1391fb90e9 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx@@ -33,6 +33,7 @@ import {MediaCard,PricesCard,SEOCard,+ ShippingCard,StatusCard,TaxCard,VariantsCard,@@ -443,6 +444,7 @@ function ProductForm({ product }: { product: Product }) {<VariantsCard form={form} /><MediaCard productId={productId} variants={assignableVariants} form={form} /><PricesCard form={form} productName={product.name} />+ <ShippingCard form={form} /><InventoryCard form={form} storeId={storeId} /><ProductCustomFieldsProvider form={form} productTypeId={selectedProductTypeId}><CustomFieldsInlineCard />diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsxindex fdbc263bb3..e96a22e09b 100644--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/new.tsx@@ -20,6 +20,7 @@ import {MediaCard,PricesCard,SEOCard,+ ShippingCard,StatusCard,TaxCard,VariantsCard,@@ -184,6 +185,7 @@ function NewProductPage() {form={form}productName={form.watch('name') || t('admin.pages.products.new.title')}/>+ <ShippingCard form={form} /><InventoryCard form={form} storeId={storeId} /><ProductCustomFieldsProviderform={form}