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.

Rename `status` to `enum` in table registry

Damian Legawiec11804e1bbd55
diff --git a/packages/admin/src/components/spree/table-toolbar.tsx b/packages/admin/src/components/spree/table-toolbar.tsx
index e3c9e4a178..9d47461b8c 100644
--- a/packages/admin/src/components/spree/table-toolbar.tsx
+++ b/packages/admin/src/components/spree/table-toolbar.tsx
@@ -68,7 +68,7 @@ const operatorsByType: Record<string, { value: string; label: string }[]> = {
{ value: 'present', label: 'is set' },
{ value: 'blank', label: 'is not set' },
],
- status: [
+ enum: [
{ value: 'eq', label: 'is' },
{ value: 'not_eq', label: 'is not' },
{ value: 'in', label: 'is any of' },
@@ -474,7 +474,7 @@ function FilterPanel({
</Select>
{!noValueOperators.includes(filter.operator) &&
- (col?.filterType === 'status' && col.filterOptions ? (
+ (col?.filterType === 'enum' && col.filterOptions ? (
<Select
items={col.filterOptions}
value={filter.value || undefined}
diff --git a/packages/admin/src/lib/table-registry.ts b/packages/admin/src/lib/table-registry.ts
index 6948bf53d8..b3fcd9c345 100644
--- a/packages/admin/src/lib/table-registry.ts
+++ b/packages/admin/src/lib/table-registry.ts
@@ -4,14 +4,13 @@ import type { ReactNode } from 'react'
// Types
// ============================================================================
-export interface ColumnDef<T = any> {
+/** Shared shape — every column has these regardless of filter type. */
+interface ColumnDefBase<T = any> {
key: string
label: string
sortable?: boolean
filterable?: boolean
default?: boolean
- filterType?: 'string' | 'status' | 'boolean' | 'number' | 'date'
- filterOptions?: { value: string; label: string }[]
/** Ransack attribute name if different from key (e.g., 'master_sku' for 'sku') */
ransackAttribute?: string
/** Custom cell renderer. If omitted, renders `row[key]` as text. */
@@ -22,6 +21,21 @@ export interface ColumnDef<T = any> {
displayable?: boolean
}
+/**
+ * Column definition. Discriminated union on `filterType`: when `filterType` is
+ * `'enum'`, `filterOptions` is **required**; for the other types it must be
+ * omitted (those filters render their own input widget).
+ */
+export type ColumnDef<T = any> =
+ | (ColumnDefBase<T> & {
+ filterType?: 'string' | 'boolean' | 'number' | 'date'
+ filterOptions?: never
+ })
+ | (ColumnDefBase<T> & {
+ filterType: 'enum'
+ filterOptions: { value: string; label: string }[]
+ })
+
export interface FilterRule {
id: string
field: string
diff --git a/packages/admin/src/tables/orders.tsx b/packages/admin/src/tables/orders.tsx
index 213b71b154..13aaf6d402 100644
--- a/packages/admin/src/tables/orders.tsx
+++ b/packages/admin/src/tables/orders.tsx
@@ -52,7 +52,7 @@ defineTable('orders', {
sortable: true,
filterable: true,
default: true,
- filterType: 'status',
+ filterType: 'enum',
filterOptions: [
{ value: 'balance_due', label: 'Balance due' },
{ value: 'credit_owed', label: 'Credit owed' },
@@ -69,7 +69,7 @@ defineTable('orders', {
sortable: true,
filterable: true,
default: true,
- filterType: 'status',
+ filterType: 'enum',
filterOptions: [
{ value: 'backorder', label: 'Backorder' },
{ value: 'canceled', label: 'Canceled' },
@@ -108,7 +108,7 @@ defineTable('orders', {
sortable: true,
filterable: true,
default: false,
- filterType: 'status',
+ filterType: 'enum',
filterOptions: [
{ value: 'draft', label: 'Draft' },
{ value: 'placed', label: 'Placed' },
diff --git a/packages/admin/src/tables/products.tsx b/packages/admin/src/tables/products.tsx
index b801206057..c735bcf3f1 100644
--- a/packages/admin/src/tables/products.tsx
+++ b/packages/admin/src/tables/products.tsx
@@ -48,7 +48,7 @@ defineTable('products', {
sortable: true,
filterable: true,
default: true,
- filterType: 'status',
+ filterType: 'enum',
filterOptions: [
{ value: 'draft', label: 'Draft' },
{ value: 'active', label: 'Active' },
diff --git a/packages/admin/src/tables/stock-locations.tsx b/packages/admin/src/tables/stock-locations.tsx
index fc6a0fa8b4..115ebf59bc 100644
--- a/packages/admin/src/tables/stock-locations.tsx
+++ b/packages/admin/src/tables/stock-locations.tsx
@@ -42,7 +42,7 @@ defineTable<StockLocation>('stock-locations', {
sortable: true,
filterable: true,
default: true,
- filterType: 'status',
+ filterType: 'enum',
filterOptions: [
{ value: 'warehouse', label: 'Warehouse' },
{ value: 'store', label: 'Store' },