Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Leave products staged for removal out of the price spreadsheet

Damian Legawiece1f1ed20fc4a
diff --git a/docs/plans/6.0-catalog-agreement-rework.md b/docs/plans/6.0-catalog-agreement-rework.md
index 700f2fc180..0e03342862 100644
--- a/docs/plans/6.0-catalog-agreement-rework.md
+++ b/docs/plans/6.0-catalog-agreement-rework.md
@@ -165,6 +165,12 @@ catalog page this rework establishes.
an owned list by another path: the two memberships are separate tables,
and a catalog whose list missed the sync shows an empty price
spreadsheet while plainly having products.
+- **The price spreadsheet reflects staged membership, not just saved
+ membership** — a products card stages its edits until Save, so a grid
+ opened beside one excludes products staged for removal
+ (`variant_product_id_not_in`) rather than inviting prices that Save
+ discards. Staged *additions* have no rows to show until Save, so the
+ surface says so instead.
## Open Questions
diff --git a/packages/dashboard/e2e/catalogs.spec.ts b/packages/dashboard/e2e/catalogs.spec.ts
index ba0704f226..10f9574fc1 100644
--- a/packages/dashboard/e2e/catalogs.spec.ts
+++ b/packages/dashboard/e2e/catalogs.spec.ts
@@ -112,6 +112,54 @@ test.describe('catalogs', () => {
})
})
+ // An owned price list prices the catalog's assortment and nothing else, so
+ // the spreadsheet has to open on the products the catalog actually holds —
+ // and drop the ones on their way out.
+ test('prices the assortment, and omits a product staged for removal', async ({ page }) => {
+ const creds = await login(page)
+ await gotoIndex(page, CATALOGS_PATH(creds.store_id), CTA)
+
+ const name = `E2E Catalog Prices ${Date.now()}`
+ await createCatalog(page, name)
+
+ // Products first, then pricing — the order a merchant works in.
+ await page.getByRole('button', { name: /add products/i }).click()
+ const picker = page.getByRole('dialog')
+ await expect(picker.getByRole('heading', { name: /add products to catalog/i })).toBeVisible()
+ await picker.getByRole('searchbox').fill(FIXTURE_PROMO_PRODUCT)
+ const option = picker
+ .getByRole('button', { name: new RegExp(FIXTURE_PROMO_PRODUCT, 'i') })
+ .first()
+ await expect(option).toBeVisible({ timeout: 15_000 })
+ await option.click()
+ await picker.getByRole('button', { name: /^add 1$/i }).click()
+ await expect(picker).toBeHidden({ timeout: 15_000 })
+
+ await page.locator('#catalog-pricing-mode').click()
+ await page.getByRole('option', { name: /prices i enter for this catalog/i }).click()
+ await saveCatalog(page)
+
+ // The list is created by Save and seeded from the assortment, so the
+ // spreadsheet opens on a priceable row rather than empty.
+ const openPrices = page.getByRole('button', { name: /^enter prices$/i })
+ await expect(openPrices).toBeVisible({ timeout: 15_000 })
+ await openPrices.click()
+ const grid = page.getByRole('dialog')
+ await expect(grid.getByLabel(/^price for/i).first()).toBeVisible({ timeout: 15_000 })
+ await grid.getByRole('button', { name: /^close$/i }).click()
+ await expect(grid).toBeHidden({ timeout: 15_000 })
+
+ // Staging the product for removal takes it out of the grid: its prices
+ // survive until Save, but pricing something on its way out is wasted work.
+ const productRow = page.getByRole('row', { name: new RegExp(FIXTURE_PROMO_PRODUCT, 'i') })
+ await productRow.getByRole('button', { name: /remove from catalog/i }).click()
+ await expect(productRow.getByRole('button', { name: /restore/i })).toBeVisible()
+
+ await openPrices.click()
+ const emptyGrid = page.getByRole('dialog')
+ await expect(emptyGrid.getByLabel(/^price for/i)).toHaveCount(0, { timeout: 15_000 })
+ })
+
test('renames a catalog from the header Save', async ({ page }) => {
const creds = await login(page)
await gotoIndex(page, CATALOGS_PATH(creds.store_id), CTA)
diff --git a/packages/dashboard/src/components/spree/bulk-price-editor/bulk-price-editor-dialog.tsx b/packages/dashboard/src/components/spree/bulk-price-editor/bulk-price-editor-dialog.tsx
index 28d4e0870d..7079ef1c60 100644
--- a/packages/dashboard/src/components/spree/bulk-price-editor/bulk-price-editor-dialog.tsx
+++ b/packages/dashboard/src/components/spree/bulk-price-editor/bulk-price-editor-dialog.tsx
@@ -15,7 +15,7 @@ import {
useConfirm,
} from '@spree/dashboard-ui'
import { XIcon } from 'lucide-react'
-import { useCallback, useEffect, useState } from 'react'
+import { useCallback, useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { BulkPriceEditor, type BulkPriceEditorState } from './bulk-price-editor'
@@ -23,6 +23,12 @@ interface BulkPriceEditorDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
priceList: PriceList
+ /**
+ * Products staged for removal on the surrounding page. Their prices are
+ * still on the list until Save, but pricing something on its way out is
+ * wasted work, so they are left out of the grid.
+ */
+ excludeProductIds?: string[]
}
/**
@@ -42,6 +48,7 @@ export function BulkPriceEditorDialog({
open,
onOpenChange,
priceList,
+ excludeProductIds,
}: BulkPriceEditorDialogProps) {
const { t } = useTranslation()
const { currencies, defaultCurrency } = useStore()
@@ -58,6 +65,17 @@ export function BulkPriceEditorDialog({
setEditorState(next)
}, [])
+ // Keyed on contents rather than array identity: callers derive this from
+ // form state and hand over a fresh array on every render, which as a raw
+ // dependency would refetch the grid and drop in-progress edits.
+ const excludeKey = (excludeProductIds ?? []).join(',')
+ const filter = useMemo(
+ () => (excludeKey ? { variant_product_id_not_in: excludeKey.split(',') } : undefined),
+ // Depends on the joined key, not the array: callers derive this from form
+ // state and hand over a fresh array on every render.
+ [excludeKey],
+ )
+
// Reset currency to the store default whenever the dialog reopens. Stale
// currency state from a prior open would otherwise survive the
// remount-less close+reopen.
@@ -185,6 +203,7 @@ export function BulkPriceEditorDialog({
<BulkPriceEditor
priceListId={priceList.id}
currency={currency}
+ filter={filter}
onStateChange={onStateChange}
/>
</DialogBody>
diff --git a/packages/dashboard/src/components/spree/bulk-price-editor/bulk-price-editor.tsx b/packages/dashboard/src/components/spree/bulk-price-editor/bulk-price-editor.tsx
index bbbffae8e1..e7b52eac2e 100644
--- a/packages/dashboard/src/components/spree/bulk-price-editor/bulk-price-editor.tsx
+++ b/packages/dashboard/src/components/spree/bulk-price-editor/bulk-price-editor.tsx
@@ -44,7 +44,7 @@ interface BaselineRow extends BulkPriceRow {
variantId?: string
}
-type FilterShape = Record<string, string | number | boolean | null | undefined>
+type FilterShape = Record<string, string | number | boolean | string[] | null | undefined>
// Strip predicates the editor owns + drop empty values, then serialize
// in a key-sorted form so reference churn from the parent doesn't
@@ -55,6 +55,9 @@ function sanitizeFilter(filter: FilterShape | undefined): FilterShape {
for (const [k, v] of Object.entries(filter)) {
if (k.startsWith('price_list_id')) continue
if (v === undefined || v === null || v === '') continue
+ // An empty list is not a filter — Ransack reads `field_in: []` as
+ // "match nothing" and would blank the grid.
+ if (Array.isArray(v) && v.length === 0) continue
out[k] = v
}
return out
@@ -74,7 +77,7 @@ export interface BulkPriceEditorProps {
* Keys starting with `price_list_id` are stripped (the editor owns
* that predicate via `priceListId`). Memoize in the parent to avoid
* refetch + edits-reset churn on every render. */
- filter?: Record<string, string | number | boolean | null | undefined>
+ filter?: FilterShape
/** Notifies the parent of dirty count + save handle so the route can
* render a sticky footer bar and a router-leave guard. */
onStateChange?: (state: BulkPriceEditorState) => void
diff --git a/packages/dashboard/src/components/spree/catalog-pricing-fields.tsx b/packages/dashboard/src/components/spree/catalog-pricing-fields.tsx
index 6404ea8099..68c03a2293 100644
--- a/packages/dashboard/src/components/spree/catalog-pricing-fields.tsx
+++ b/packages/dashboard/src/components/spree/catalog-pricing-fields.tsx
@@ -39,6 +39,8 @@ export function CatalogPricingFields({
canEdit,
priceList,
savedMode,
+ excludeProductIds,
+ hasStagedProducts,
}: {
form: UseFormReturn<CatalogFormValues>
canEdit: boolean
@@ -50,6 +52,18 @@ export function CatalogPricingFields({
priceList?: PriceList | null
/** The mode as last saved, so a switch can be warned about before Save. */
savedMode?: CatalogPricingMode
+ /**
+ * Products staged for removal from the assortment. Their prices survive
+ * until Save, but they are on their way out, so the spreadsheet leaves
+ * them out rather than inviting work that Save discards.
+ */
+ excludeProductIds?: string[]
+ /**
+ * True while any membership edit is staged. A staged addition has no
+ * price rows until Save, so the grid cannot show it yet — the help text
+ * says so rather than leaving the merchant hunting for it.
+ */
+ hasStagedProducts?: boolean
}) {
const { t } = useTranslation()
const { errors } = form.formState
@@ -205,11 +219,18 @@ export function CatalogPricingFields({
<TableIcon className="size-4" />
{t('admin.catalogs.edit_prices_cta')}
</Button>
- <FieldDescription>{t('admin.catalogs.edit_prices_help')}</FieldDescription>
+ <FieldDescription>
+ {t(
+ hasStagedProducts
+ ? 'admin.catalogs.edit_prices_pending_save'
+ : 'admin.catalogs.edit_prices_help',
+ )}
+ </FieldDescription>
<BulkPriceEditorDialog
open={priceEditorOpen}
onOpenChange={setPriceEditorOpen}
priceList={priceList}
+ excludeProductIds={excludeProductIds}
/>
</div>
) : (
diff --git a/packages/dashboard/src/components/spree/price-list-editors/price-list-form.tsx b/packages/dashboard/src/components/spree/price-list-editors/price-list-form.tsx
index d6434e56b1..323d84b305 100644
--- a/packages/dashboard/src/components/spree/price-list-editors/price-list-form.tsx
+++ b/packages/dashboard/src/components/spree/price-list-editors/price-list-form.tsx
@@ -29,6 +29,7 @@ import { DeferredProductMembershipCard } from '../deferred-product-membership-ca
import {
flushProductMembership,
ProductMembershipStagingProvider,
+ useProductMembershipStaging,
} from '../product-membership-staging'
import { PriceListStatusBadge } from './status-badge'
// Side-effect import — registers per-rule editors (customer, customer
@@ -915,6 +916,9 @@ function DefaultRuleEditor({ draft, onSave, onClose }: PriceRuleEditorContext) {
function EditPricesButton({ priceList }: { priceList: PriceList }) {
const { t } = useTranslation()
const [editorOpen, setEditorOpen] = useState(false)
+ // Products staged for removal keep their prices until Save, so leave them
+ // out of the grid rather than inviting edits that Save discards.
+ const { removes } = useProductMembershipStaging()
return (
<>
@@ -922,7 +926,12 @@ function EditPricesButton({ priceList }: { priceList: PriceList }) {
<TableIcon className="size-4" />
{t('admin.pages.products.price_lists.edit_prices_cta')}
</Button>
- <BulkPriceEditorDialog open={editorOpen} onOpenChange={setEditorOpen} priceList={priceList} />
+ <BulkPriceEditorDialog
+ open={editorOpen}
+ onOpenChange={setEditorOpen}
+ priceList={priceList}
+ excludeProductIds={removes}
+ />
</>
)
}
diff --git a/packages/dashboard/src/locales/ar.json b/packages/dashboard/src/locales/ar.json
index bbaad82ded..92901719ad 100644
--- a/packages/dashboard/src/locales/ar.json
+++ b/packages/dashboard/src/locales/ar.json
@@ -127,6 +127,7 @@
"edit_prices_after_save": "احفظ الكتالوج، ثم أدخل أسعار هذا الجمهور.",
"edit_prices_cta": "إدخال الأسعار",
"edit_prices_help": "حدّد سعر كل منتج لهذا الجمهور.",
+ "edit_prices_pending_save": "حدّد سعر كل منتج لهذا الجمهور. احفظ أولاً لتسعير المنتجات التي غيّرتها للتو.",
"empty": "لا توجد كتالوجات بعد",
"messages": {
"assigned": "تم تعيين الكتالوج",
diff --git a/packages/dashboard/src/locales/de.json b/packages/dashboard/src/locales/de.json
index a96ec692d5..7f7235e193 100644
--- a/packages/dashboard/src/locales/de.json
+++ b/packages/dashboard/src/locales/de.json
@@ -127,6 +127,7 @@
"edit_prices_after_save": "Katalog speichern, dann die Preise für diese Zielgruppe eingeben.",
"edit_prices_cta": "Preise eingeben",
"edit_prices_help": "Legen Sie fest, was jedes Produkt diese Zielgruppe kostet.",
+ "edit_prices_pending_save": "Legen Sie fest, was jedes Produkt diese Zielgruppe kostet. Speichern Sie zuerst, um die soeben geänderten Produkte zu bepreisen.",
"empty": "Noch keine Kataloge",
"messages": {
"assigned": "Katalog zugewiesen",
diff --git a/packages/dashboard/src/locales/en.json b/packages/dashboard/src/locales/en.json
index ae7ff837a7..5a2d94f716 100644
--- a/packages/dashboard/src/locales/en.json
+++ b/packages/dashboard/src/locales/en.json
@@ -127,6 +127,7 @@
"edit_prices_after_save": "Save the catalog, then enter the prices for this audience.",
"edit_prices_cta": "Enter prices",
"edit_prices_help": "Set the price each product costs this audience.",
+ "edit_prices_pending_save": "Set the price each product costs this audience. Save first to price the products you just changed.",
"empty": "No catalogs yet",
"messages": {
"assigned": "Catalog assigned",
diff --git a/packages/dashboard/src/locales/fr.json b/packages/dashboard/src/locales/fr.json
index aafdf23202..c9c2c6ff7c 100644
--- a/packages/dashboard/src/locales/fr.json
+++ b/packages/dashboard/src/locales/fr.json
@@ -127,6 +127,7 @@
"edit_prices_after_save": "Enregistrez le catalogue, puis saisissez les prix de cette audience.",
"edit_prices_cta": "Saisir les prix",
"edit_prices_help": "Définissez le prix de chaque produit pour cette audience.",
+ "edit_prices_pending_save": "Définissez le prix de chaque produit pour cette audience. Enregistrez d'abord pour fixer le prix des produits que vous venez de modifier.",
"empty": "Aucun catalogue pour le moment",
"messages": {
"assigned": "Catalogue affecté",
diff --git a/packages/dashboard/src/locales/pl.json b/packages/dashboard/src/locales/pl.json
index f444e2f71e..cbd17609c5 100644
--- a/packages/dashboard/src/locales/pl.json
+++ b/packages/dashboard/src/locales/pl.json
@@ -129,6 +129,7 @@
"edit_prices_after_save": "Zapisz katalog, a następnie wprowadź ceny dla tej grupy odbiorców.",
"edit_prices_cta": "Wprowadź ceny",
"edit_prices_help": "Ustal, ile każdy produkt kosztuje tę grupę odbiorców.",
+ "edit_prices_pending_save": "Ustal, ile każdy produkt kosztuje tę grupę odbiorców. Zapisz najpierw, aby wycenić dopiero co zmienione produkty.",
"empty": "Brak katalogów",
"messages": {
"assigned": "Katalog przypisany",
diff --git a/packages/dashboard/src/locales/zh-CN.json b/packages/dashboard/src/locales/zh-CN.json
index a48926c01d..eaf336af97 100644
--- a/packages/dashboard/src/locales/zh-CN.json
+++ b/packages/dashboard/src/locales/zh-CN.json
@@ -127,6 +127,7 @@
"edit_prices_after_save": "保存目录后,再为此受众输入价格。",
"edit_prices_cta": "输入价格",
"edit_prices_help": "设置每件商品对此受众的价格。",
+ "edit_prices_pending_save": "设置每件商品对此受众的价格。请先保存,才能为刚刚更改的商品定价。",
"empty": "暂无目录",
"messages": {
"assigned": "目录已分配",
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId.tsx
index a90ee6928c..594c7ad09b 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/catalogs/$catalogId.tsx
@@ -47,7 +47,10 @@ import { Controller, type UseFormReturn, useForm } from 'react-hook-form'
import { useTranslation } from 'react-i18next'
import { CatalogPricingFields } from '../../../../../components/spree/catalog-pricing-fields'
import { DeferredProductMembershipCard } from '../../../../../components/spree/deferred-product-membership-card'
-import { ProductMembershipStagingProvider } from '../../../../../components/spree/product-membership-staging'
+import {
+ ProductMembershipStagingProvider,
+ useProductMembershipStaging,
+} from '../../../../../components/spree/product-membership-staging'
import { ResourceDetailSkeleton } from '../../../../../components/spree/route-pending'
import {
useAssignCatalog,
@@ -234,6 +237,9 @@ function CatalogPricingCard({
canEdit: boolean
}) {
const { t } = useTranslation()
+ // A product staged for removal still has its prices on the list until
+ // Save, so the spreadsheet would invite pricing something on its way out.
+ const { removes, dirty: stagedProducts } = useProductMembershipStaging()
return (
<Card>
@@ -247,6 +253,8 @@ function CatalogPricingCard({
canEdit={canEdit}
priceList={catalog.price_list}
savedMode={catalogPricingValues(catalog.price_list).pricing_mode}
+ excludeProductIds={removes}
+ hasStagedProducts={stagedProducts}
/>
</FieldGroup>
</CardContent>