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
Simplify BrandsListPage layout using ResourceTable's built-in toolbar (#14359)
Damian Legawiecf2e9eb0aee8c
diff --git a/packages/dashboard-plugin-example/src/client.ts b/packages/dashboard-plugin-example/src/client.tsindex 85d71c975b..d6b25db31c 100644--- a/packages/dashboard-plugin-example/src/client.ts+++ b/packages/dashboard-plugin-example/src/client.ts@@ -23,7 +23,10 @@ import type { Brand, BrandCreateParams, BrandUpdateParams } from './types'* In practice, callers pass the same `{ page, limit, sort, search, … }`* keys built-in resources accept.*/-type BrandsListParams = Record<string, string | number | boolean | (string | number)[] | undefined>+export type BrandsListParams = Record<+ string,+ string | number | boolean | (string | number)[] | undefined+>export const brandsClient = {list: (params?: BrandsListParams) =>diff --git a/packages/dashboard-plugin-example/src/locales/en.json b/packages/dashboard-plugin-example/src/locales/en.jsonindex 5512223fe5..68ebfeb36e 100644--- a/packages/dashboard-plugin-example/src/locales/en.json+++ b/packages/dashboard-plugin-example/src/locales/en.json@@ -3,8 +3,6 @@"brands_plugin": {"nav": "Brands","page": {- "title": "Brands",- "subtitle": "Manage product brands","new_cta": "New brand"},"table": {diff --git a/packages/dashboard-plugin-example/src/pages/brands-list.tsx b/packages/dashboard-plugin-example/src/pages/brands-list.tsxindex 95dd2f2b75..ec4d5f9d0c 100644--- a/packages/dashboard-plugin-example/src/pages/brands-list.tsx+++ b/packages/dashboard-plugin-example/src/pages/brands-list.tsx@@ -1,50 +1,43 @@+import { type ResourceSearch, ResourceTable } from '@spree/dashboard-core'+import { Button } from '@spree/dashboard-ui'+import { PlusIcon } from 'lucide-react'+import { useTranslation } from 'react-i18next'+import { type BrandsListParams, brandsClient } from '../client'+import type { Brand } from '../types'++interface BrandsListPageProps {+ /** URL-driven table state (page, sort, search, filters), validated by the route via `resourceSearchSchema`. */+ searchParams: ResourceSearch+}+/*** Brands index page, rendered by the `brands.index` file route. Uses the* dashboard's `<ResourceTable>` for filtering, sorting, pagination, and* bulk-action chrome — the same UX as core's Products/Customers/Orders pages.+ * Like those pages, the table is the whole page: the toolbar carries the+ * title (from the table definition) and the primary action.** The table's columns and filters are declared via `defineTable('brands', ...)`* in `../index.tsx` (alongside the plugin entry); ResourceTable reads from* that registry by tableKey.*/-import { PageHeader, type ResourceSearch, ResourceTable } from '@spree/dashboard-core'-import { Button, ResourceLayout } from '@spree/dashboard-ui'-import { PlusIcon } from 'lucide-react'-import { useTranslation } from 'react-i18next'-import { brandsClient } from '../client'-import type { Brand } from '../types'--interface BrandsListPageProps {- searchParams: ResourceSearch-}-export function BrandsListPage({ searchParams }: BrandsListPageProps) {const { t } = useTranslation()return (- <ResourceLayout- header={- <PageHeader- title={t('admin.brands_plugin.page.title')}- subtitle={t('admin.brands_plugin.page.subtitle')}- actions={- <Button size="sm">- <PlusIcon className="size-4" />- {t('admin.brands_plugin.page.new_cta')}- </Button>- }- />- }- main={- <ResourceTable<Brand>- tableKey="brands"- queryKey="brands"- // ResourceTable hands `params` to queryFn as `Record<string, unknown>`- // (its internal builder doesn't know what each table's API accepts).- // We narrow to our client's known param shape at the boundary.- queryFn={(params) => brandsClient.list(params as Record<string, never>)}- searchParams={searchParams}- />+ <ResourceTable<Brand>+ tableKey="brands"+ queryKey="brands"+ // ResourceTable hands `params` to queryFn as `Record<string, unknown>`+ // (its internal builder doesn't know what each table's API accepts).+ // We narrow to our client's accepted param shape at the boundary.+ queryFn={(params) => brandsClient.list(params as BrandsListParams)}+ searchParams={searchParams}+ actions={+ <Button size="sm" className="h-[2.125rem]">+ <PlusIcon className="size-4" />+ {t('admin.brands_plugin.page.new_cta')}+ </Button>}/>)