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.

Changed custom fields to stay open on pages whose form saves them (#15008)

Damian Legawiecc0b62dc4ee13
diff --git a/.changeset/custom-fields-open-in-forms.md b/.changeset/custom-fields-open-in-forms.md
new file mode 100644
index 0000000000..793068e12f
--- /dev/null
+++ b/.changeset/custom-fields-open-in-forms.md
@@ -0,0 +1,5 @@
+---
+"@spree/dashboard": patch
+---
+
+Custom fields stay open on product, category, collection and promotion pages, where they are edited as part of the page's form and saved with it. Pages that edit custom fields behind their own Edit button, such as orders and customers, still fold the card.
diff --git a/packages/dashboard/e2e/custom-field-definitions.spec.ts b/packages/dashboard/e2e/custom-field-definitions.spec.ts
index 535ff3e3ac..7cb2581bdd 100644
--- a/packages/dashboard/e2e/custom-field-definitions.spec.ts
+++ b/packages/dashboard/e2e/custom-field-definitions.spec.ts
@@ -116,7 +116,6 @@ test.describe('custom field definitions', () => {
const customFields = page
.locator('[data-slot="card"]')
.filter({ has: page.locator('[data-slot="card-title"]', { hasText: /^custom fields$/i }) })
- await expandCustomFieldsCard(page)
const input = customFields.getByLabel(new RegExp(`^${label}$`, 'i'))
await expect(input).toBeVisible({ timeout: 15_000 })
await input.fill('Aisle 7')
@@ -124,7 +123,6 @@ test.describe('custom field definitions', () => {
await expect(page.getByRole('button', { name: /^save$/i })).toBeDisabled({ timeout: 15_000 })
await page.reload()
- await expandCustomFieldsCard(page)
await expect(customFields.getByLabel(new RegExp(`^${label}$`, 'i'))).toHaveValue('Aisle 7', {
timeout: 15_000,
})
diff --git a/packages/dashboard/e2e/helpers.ts b/packages/dashboard/e2e/helpers.ts
index ca6f704cfd..0a84664068 100644
--- a/packages/dashboard/e2e/helpers.ts
+++ b/packages/dashboard/e2e/helpers.ts
@@ -496,7 +496,7 @@ function customFieldsCardOn(page: Page) {
/**
* Unfolds the custom fields card where a detail page folds it. A no-op on
- * surfaces that always show it open, such as sheets and the new-product page.
+ * surfaces that always show it open: sheets, and pages whose form saves it.
*/
export async function expandCustomFieldsCard(page: Page) {
const card = customFieldsCardOn(page)
@@ -526,14 +526,12 @@ export async function saveCustomFieldOnCard(page: Page, label: string, value: st
* checks it survives a reload. A custom field alone must enable that Save.
*/
export async function saveCustomFieldWithPage(page: Page, label: string, value: string) {
- await expandCustomFieldsCard(page)
await page.getByLabel(label).fill(value)
const save = page.getByRole('button', { name: /^save$/i })
await save.click()
await expect(save).toBeDisabled({ timeout: 15_000 })
await page.reload()
- await expandCustomFieldsCard(page)
await expect(page.getByLabel(label)).toHaveValue(value, { timeout: 15_000 })
}
diff --git a/packages/dashboard/e2e/products-custom-fields.spec.ts b/packages/dashboard/e2e/products-custom-fields.spec.ts
index 4d77974cd2..7fb89a1a8d 100644
--- a/packages/dashboard/e2e/products-custom-fields.spec.ts
+++ b/packages/dashboard/e2e/products-custom-fields.spec.ts
@@ -1,5 +1,5 @@
import { expect, type Page, test } from '@playwright/test'
-import { expandCustomFieldsCard, gotoIndex, login } from './helpers'
+import { gotoIndex, login } from './helpers'
import { customFieldsCard, PRODUCTS_PATH } from './products-helpers'
const DEFINITIONS_PATH = (storeId: string) => `/${storeId}/settings/custom-field-definitions`
@@ -44,10 +44,9 @@ test.describe('product custom fields — new product', () => {
await expect(page).toHaveURL(new RegExp(`/${creds.store_id}/products/prod_[^/]+$`), {
timeout: 30_000,
})
- await expandCustomFieldsCard(page)
-
await expect(customFieldsCard(page).getByLabel(new RegExp(`^${fieldLabel}$`, 'i'))).toHaveValue(
'Cotton',
+ { timeout: 15_000 },
)
})
})
@@ -69,7 +68,6 @@ test.describe('product custom fields — existing product', () => {
timeout: 30_000,
})
- await expandCustomFieldsCard(page)
const cfCard = customFieldsCard(page)
const input = cfCard.getByLabel(new RegExp(`^${fieldLabel}$`, 'i'))
await expect(input).toBeVisible({ timeout: 15_000 })
@@ -83,10 +81,10 @@ test.describe('product custom fields — existing product', () => {
await expect(saveButton).toBeDisabled({ timeout: 30_000 })
await page.reload()
- await expandCustomFieldsCard(page)
await expect(customFieldsCard(page).getByLabel(new RegExp(`^${fieldLabel}$`, 'i'))).toHaveValue(
'Slim',
+ { timeout: 15_000 },
)
})
})
diff --git a/packages/dashboard/src/components/spree/categories/category-form.tsx b/packages/dashboard/src/components/spree/categories/category-form.tsx
index dfe14d6c87..17ab3179ca 100644
--- a/packages/dashboard/src/components/spree/categories/category-form.tsx
+++ b/packages/dashboard/src/components/spree/categories/category-form.tsx
@@ -94,7 +94,7 @@ export function CategoryMain({
persist on the page's Save.
*/}
<FormBackedCustomFieldsProvider form={form} resourceType="category">
- <CustomFieldsInlineCard collapsible />
+ <CustomFieldsInlineCard />
</FormBackedCustomFieldsProvider>
<RecordMetadataCard
metadata={category.metadata}
diff --git a/packages/dashboard/src/components/spree/collections/collection-form.tsx b/packages/dashboard/src/components/spree/collections/collection-form.tsx
index 07236141b5..2d43f604dc 100644
--- a/packages/dashboard/src/components/spree/collections/collection-form.tsx
+++ b/packages/dashboard/src/components/spree/collections/collection-form.tsx
@@ -95,7 +95,7 @@ export function CollectionMain({
<CollectionProductsCard collectionId={collection.id} automatic={automatic} />
<ResourceTranslationsCard resourceType="collection" resourceId={collection.id} />
<FormBackedCustomFieldsProvider form={form} resourceType="collection">
- <CustomFieldsInlineCard collapsible />
+ <CustomFieldsInlineCard />
</FormBackedCustomFieldsProvider>
<RecordMetadataCard metadata={collection.metadata} />
</>
diff --git a/packages/dashboard/src/components/spree/custom-fields/custom-fields-inline.tsx b/packages/dashboard/src/components/spree/custom-fields/custom-fields-inline.tsx
index 7c19c31d61..7711df35b3 100644
--- a/packages/dashboard/src/components/spree/custom-fields/custom-fields-inline.tsx
+++ b/packages/dashboard/src/components/spree/custom-fields/custom-fields-inline.tsx
@@ -606,15 +606,13 @@ export function ApiCustomFieldsCard({
export function DraftCustomFieldsCard({
draft,
hideWhenEmpty,
- collapsible,
}: {
draft: CustomFieldsDraft
hideWhenEmpty?: boolean
- collapsible?: boolean
}) {
return (
<DraftCustomFieldsProvider draft={draft}>
- <CustomFieldsInlineCard hideWhenEmpty={hideWhenEmpty} collapsible={collapsible} />
+ <CustomFieldsInlineCard hideWhenEmpty={hideWhenEmpty} />
</DraftCustomFieldsProvider>
)
}
@@ -630,7 +628,11 @@ interface CustomFieldsInlineCardProps {
* defined in Settings, which offers every resource with an edit surface.
*/
hideWhenEmpty?: boolean
- /** Folds the card to its header, with a count of filled fields. For the end of a detail page's main column. */
+ /**
+ * Folds the card to its header, with a count of filled fields. For a detail
+ * page that edits them behind the card's own Edit button; a page whose form
+ * saves them keeps them in view.
+ */
collapsible?: boolean
}
diff --git a/packages/dashboard/src/components/spree/promotion-editors/promotion-form.tsx b/packages/dashboard/src/components/spree/promotion-editors/promotion-form.tsx
index 94e9df7cf1..d6119e3cd5 100644
--- a/packages/dashboard/src/components/spree/promotion-editors/promotion-form.tsx
+++ b/packages/dashboard/src/components/spree/promotion-editors/promotion-form.tsx
@@ -357,7 +357,7 @@ export function PromotionForm({
matchPolicy={form.watch('match_policy')}
/>
<ActionsCard form={form} actionsArray={actionsArray} />
- {mode === 'edit' && <DraftCustomFieldsCard draft={customFields} collapsible />}
+ {mode === 'edit' && <DraftCustomFieldsCard draft={customFields} />}
{promotion && <RecordMetadataCard metadata={promotion.metadata} />}
</>
}
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
index dcf6cb4046..b70bdbf822 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/products/$productId.tsx
@@ -322,7 +322,7 @@ function ProductForm({ product }: { product: Product }) {
<DigitalAssetsCard productId={productId} variants={assignableVariants} />
<ResourceTranslationsCard resourceType="product" resourceId={productId} />
<ProductCustomFieldsProvider form={form} productTypeId={selectedProductTypeId}>
- <CustomFieldsInlineCard collapsible />
+ <CustomFieldsInlineCard />
</ProductCustomFieldsProvider>
<RecordMetadataCard
metadata={product.metadata}