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.

Added a search filter to every list with a search box

Damian Legawiec3664c3abe3a2
diff --git a/packages/dashboard-core/src/tables/package-types.tsx b/packages/dashboard-core/src/tables/package-types.tsx
index e0b3426200..d5c3d37de2 100644
--- a/packages/dashboard-core/src/tables/package-types.tsx
+++ b/packages/dashboard-core/src/tables/package-types.tsx
@@ -8,7 +8,7 @@ defineTable<PanelPackageType>('package-types', {
docsPath: 'settings/package-types',
description: i18n.t('admin.package_types.description'),
title: i18n.t('admin.package_types.table_title'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.package_types.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <PackageIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard-core/src/tables/stock-locations.tsx b/packages/dashboard-core/src/tables/stock-locations.tsx
index c2911bf7fb..d37c550a77 100644
--- a/packages/dashboard-core/src/tables/stock-locations.tsx
+++ b/packages/dashboard-core/src/tables/stock-locations.tsx
@@ -8,7 +8,7 @@ defineTable<PanelStockLocation>('stock-locations', {
docsPath: 'settings/locations',
description: i18n.t('admin.stock_locations.description'),
title: i18n.t('admin.settings_nav.items.stock_locations'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.stock_locations.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <WarehouseIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/hooks/use-categories.ts b/packages/dashboard/src/hooks/use-categories.ts
index 3479bc4ff6..5afd5545a1 100644
--- a/packages/dashboard/src/hooks/use-categories.ts
+++ b/packages/dashboard/src/hooks/use-categories.ts
@@ -27,8 +27,7 @@ export function useCategorySearch(query: string) {
const trimmed = query.trim()
return useQuery({
queryKey: useResourceKey('categories', 'search', trimmed),
- queryFn: () =>
- adminClient.categories.list({ name_cont: trimmed, limit: 50, sort: 'pretty_name' }),
+ queryFn: () => adminClient.categories.list({ search: trimmed, limit: 50, sort: 'pretty_name' }),
enabled: trimmed.length > 0,
staleTime: 1000 * 60,
})
@@ -176,7 +175,7 @@ export function categoryAutocompleteProps(queryKey: string) {
queryKey,
search: (q: string) =>
adminClient.categories.list({
- pretty_name_cont: q,
+ search: q,
limit: 100,
sort: 'pretty_name',
fields: ['pretty_name', 'name'],
diff --git a/packages/dashboard/src/hooks/use-channels.ts b/packages/dashboard/src/hooks/use-channels.ts
index 2ba39548cc..71c99994c0 100644
--- a/packages/dashboard/src/hooks/use-channels.ts
+++ b/packages/dashboard/src/hooks/use-channels.ts
@@ -68,7 +68,7 @@ export function channelAutocompleteProps(queryKey: string) {
queryKey,
search: (q: string) =>
adminClient.channels.list({
- name_cont: q,
+ search: q,
limit: 100,
sort: 'name',
fields: ['name', 'code'],
diff --git a/packages/dashboard/src/hooks/use-collections.ts b/packages/dashboard/src/hooks/use-collections.ts
index 5613ad3fcd..3963d7ec83 100644
--- a/packages/dashboard/src/hooks/use-collections.ts
+++ b/packages/dashboard/src/hooks/use-collections.ts
@@ -181,7 +181,7 @@ export function collectionAutocompleteProps(queryKey: string) {
queryKey,
search: (q: string) =>
adminClient.collections.list({
- name_cont: q,
+ search: q,
automatic_eq: false,
limit: 100,
sort: 'name',
diff --git a/packages/dashboard/src/hooks/use-companies.ts b/packages/dashboard/src/hooks/use-companies.ts
index 75fd58f7e2..885ac5c6fb 100644
--- a/packages/dashboard/src/hooks/use-companies.ts
+++ b/packages/dashboard/src/hooks/use-companies.ts
@@ -36,7 +36,7 @@ export function useCompany(id: string | undefined) {
export function companyAutocompleteProps(queryKey: string) {
return {
queryKey,
- search: (q: string) => adminClient.companies.list({ name_cont: q, limit: 100, sort: 'name' }),
+ search: (q: string) => adminClient.companies.list({ search: q, limit: 100, sort: 'name' }),
hydrate: (ids: string[]) => adminClient.companies.list({ id_in: ids, limit: ids.length }),
getOptionLabel: (company: Company) => company.name ?? company.id,
placeholder: i18n.t('admin.companies.autocomplete.placeholder'),
diff --git a/packages/dashboard/src/hooks/use-customer-groups.ts b/packages/dashboard/src/hooks/use-customer-groups.ts
index b2a4ffc469..c39c6cba40 100644
--- a/packages/dashboard/src/hooks/use-customer-groups.ts
+++ b/packages/dashboard/src/hooks/use-customer-groups.ts
@@ -29,7 +29,7 @@ export function customerGroupAutocompleteProps(queryKey: string) {
return {
queryKey,
search: (q: string) =>
- adminClient.customerGroups.list({ name_cont: q, limit: 100, sort: 'name', fields: ['name'] }),
+ adminClient.customerGroups.list({ search: q, limit: 100, sort: 'name', fields: ['name'] }),
hydrate: (ids: string[]) => adminClient.customerGroups.list({ id_in: ids, limit: ids.length }),
getOptionLabel: (g: CustomerGroup) => g.name ?? g.id,
placeholder: i18n.t('admin.customer_groups.autocomplete.placeholder'),
diff --git a/packages/dashboard/src/hooks/use-option-types.ts b/packages/dashboard/src/hooks/use-option-types.ts
index 70c63df2e0..52c160b464 100644
--- a/packages/dashboard/src/hooks/use-option-types.ts
+++ b/packages/dashboard/src/hooks/use-option-types.ts
@@ -44,7 +44,7 @@ export function optionTypeAutocompleteProps(queryKey: string) {
queryKey,
search: (q: string) =>
adminClient.optionTypes.list({
- name_cont: q,
+ search: q,
limit: 100,
sort: 'name',
fields: ['name', 'label'],
diff --git a/packages/dashboard/src/hooks/use-product-types.ts b/packages/dashboard/src/hooks/use-product-types.ts
index cf06d31690..2b5886deb3 100644
--- a/packages/dashboard/src/hooks/use-product-types.ts
+++ b/packages/dashboard/src/hooks/use-product-types.ts
@@ -33,7 +33,7 @@ export function productTypeAutocompleteProps(queryKey: string) {
return {
queryKey,
search: (q: string) =>
- adminClient.productTypes.list({ name_cont: q, limit: 100, sort: 'name', fields: ['name'] }),
+ adminClient.productTypes.list({ search: q, limit: 100, sort: 'name', fields: ['name'] }),
hydrate: (ids: string[]) => adminClient.productTypes.list({ id_in: ids, limit: ids.length }),
getOptionLabel: (productType: ProductType) => productType.name ?? productType.id,
placeholder: i18n.t('admin.product_types.search_placeholder'),
diff --git a/packages/dashboard/src/hooks/use-products.ts b/packages/dashboard/src/hooks/use-products.ts
index eda8a28a97..b2c29dd372 100644
--- a/packages/dashboard/src/hooks/use-products.ts
+++ b/packages/dashboard/src/hooks/use-products.ts
@@ -27,7 +27,7 @@ export function productAutocompleteProps(queryKey: string) {
return {
queryKey,
search: (q: string) =>
- adminClient.products.list({ name_cont: q, limit: 100, sort: 'name', fields: ['name'] }),
+ adminClient.products.list({ search: q, limit: 100, sort: 'name', fields: ['name'] }),
hydrate: (ids: string[]) => adminClient.products.list({ id_in: ids, limit: ids.length }),
getOptionLabel: (product: Product) => product.name ?? product.id,
placeholder: i18n.t('admin.products.autocomplete.placeholder'),
@@ -48,7 +48,7 @@ export function useProducts({
const params: Record<string, unknown> = { page, limit, sort }
if (search) {
- params.name_cont = search
+ params.search = search
}
// Convert FilterRule[] to Ransack params
diff --git a/packages/dashboard/src/hooks/use-sellers.ts b/packages/dashboard/src/hooks/use-sellers.ts
index e77d9ac3fd..f68d42a94e 100644
--- a/packages/dashboard/src/hooks/use-sellers.ts
+++ b/packages/dashboard/src/hooks/use-sellers.ts
@@ -37,7 +37,7 @@ export function sellerAutocompleteProps(queryKey: string) {
return {
queryKey,
search: (q: string) =>
- adminClient.sellers.list({ name_cont: q, limit: 100, sort: 'name', fields: ['name'] }),
+ adminClient.sellers.list({ search: q, limit: 100, sort: 'name', fields: ['name'] }),
hydrate: (ids: string[]) => adminClient.sellers.list({ id_in: ids, limit: ids.length }),
getOptionLabel: (seller: Seller) => seller.name ?? seller.id,
placeholder: i18n.t('admin.sellers.autocomplete.placeholder'),
diff --git a/packages/dashboard/src/hooks/use-stock-levels.ts b/packages/dashboard/src/hooks/use-stock-levels.ts
index 7028ac4f1c..1ad40ea7bb 100644
--- a/packages/dashboard/src/hooks/use-stock-levels.ts
+++ b/packages/dashboard/src/hooks/use-stock-levels.ts
@@ -100,7 +100,7 @@ export function stockLocationAutocompleteProps(queryKey: string) {
return {
queryKey,
search: (query: string) =>
- adminClient.stockLocations.list({ name_cont: query, limit: 100, sort: 'name' }),
+ adminClient.stockLocations.list({ search: query, limit: 100, sort: 'name' }),
hydrate: (ids: string[]) => adminClient.stockLocations.list({ id_in: ids, limit: ids.length }),
// Every warehouse, so the filter opens as a list rather than a search
// box: a store has a handful, and the API caps the page at 100 anyway.
diff --git a/packages/dashboard/src/tables/allowed-origins.tsx b/packages/dashboard/src/tables/allowed-origins.tsx
index 2215f17d54..c2bed81ca9 100644
--- a/packages/dashboard/src/tables/allowed-origins.tsx
+++ b/packages/dashboard/src/tables/allowed-origins.tsx
@@ -8,7 +8,7 @@ defineTable<AllowedOrigin>('allowed-origins', {
title: i18n.t('admin.allowed_origins.table_title'),
docsPath: 'settings/allowed-origins',
description: i18n.t('admin.table_descriptions.allowed_origins'),
- searchParam: 'origin_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.allowed_origins.search_placeholder'),
defaultSort: { field: 'origin', direction: 'asc' },
emptyIcon: <GlobeLockIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/catalogs.tsx b/packages/dashboard/src/tables/catalogs.tsx
index e052602668..6ea13fefa4 100644
--- a/packages/dashboard/src/tables/catalogs.tsx
+++ b/packages/dashboard/src/tables/catalogs.tsx
@@ -8,7 +8,7 @@ defineTable<Catalog>('catalogs', {
title: i18n.t('admin.nav.catalogs'),
description: i18n.t('admin.table_descriptions.catalogs'),
docsPath: 'catalogs/catalogs',
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.catalogs.search_placeholder'),
defaultSort: { field: 'position', direction: 'asc' },
emptyIcon: <BookOpenIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/channels.tsx b/packages/dashboard/src/tables/channels.tsx
index c00671aa41..8f00dfaf7d 100644
--- a/packages/dashboard/src/tables/channels.tsx
+++ b/packages/dashboard/src/tables/channels.tsx
@@ -8,7 +8,7 @@ defineTable<Channel>('channels', {
title: i18n.t('admin.pages.channels.title'),
docsPath: 'settings/sales-channels',
description: i18n.t('admin.table_descriptions.channels'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.common.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <RadioTowerIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/collections.tsx b/packages/dashboard/src/tables/collections.tsx
index 4e43cc237c..81fc2d7655 100644
--- a/packages/dashboard/src/tables/collections.tsx
+++ b/packages/dashboard/src/tables/collections.tsx
@@ -9,7 +9,7 @@ defineTable<Collection>('collections', {
title: i18n.t('admin.collections.title'),
description: i18n.t('admin.table_descriptions.collections'),
docsPath: 'products/collections',
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.collections.search_placeholder'),
defaultSort: { field: 'position', direction: 'asc' },
emptyIcon: <LayersIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/commission-rates.tsx b/packages/dashboard/src/tables/commission-rates.tsx
index 5e761bb5d3..e6cf136a6a 100644
--- a/packages/dashboard/src/tables/commission-rates.tsx
+++ b/packages/dashboard/src/tables/commission-rates.tsx
@@ -9,7 +9,7 @@ defineTable<CommissionRate>('commission-rates', {
title: i18n.t('admin.settings_nav.items.commission_rates'),
docsPath: 'sellers/commission-rates',
description: i18n.t('admin.table_descriptions.commission_rates'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.commission_rates.search_placeholder'),
// The list IS the resolution order, walked top-down, so the table has to
// show it in that order and nothing else. Sorting by another column would
diff --git a/packages/dashboard/src/tables/companies.tsx b/packages/dashboard/src/tables/companies.tsx
index 46277cf8ae..75d4984b36 100644
--- a/packages/dashboard/src/tables/companies.tsx
+++ b/packages/dashboard/src/tables/companies.tsx
@@ -9,7 +9,7 @@ defineTable<Company>('companies', {
docsPath: 'customers/companies',
title: i18n.t('admin.nav.companies'),
description: i18n.t('admin.table_descriptions.companies'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.companies.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <Building2Icon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/customer-groups.tsx b/packages/dashboard/src/tables/customer-groups.tsx
index c9eb686013..30c729fbb2 100644
--- a/packages/dashboard/src/tables/customer-groups.tsx
+++ b/packages/dashboard/src/tables/customer-groups.tsx
@@ -8,7 +8,7 @@ defineTable<CustomerGroup>('customer-groups', {
title: i18n.t('admin.customers.groups.table.title'),
description: i18n.t('admin.table_descriptions.customer_groups'),
docsPath: 'customers/customer-groups',
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.customers.groups.table.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <UsersRoundIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/delivery-profiles.tsx b/packages/dashboard/src/tables/delivery-profiles.tsx
index 312f7e65dd..5bdc365219 100644
--- a/packages/dashboard/src/tables/delivery-profiles.tsx
+++ b/packages/dashboard/src/tables/delivery-profiles.tsx
@@ -8,7 +8,7 @@ defineTable<DeliveryProfile>('delivery-profiles', {
title: i18n.t('admin.settings_nav.items.delivery_profiles'),
description: i18n.t('admin.table_descriptions.delivery_profiles'),
docsPath: 'settings/shipping-methods',
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.delivery_profiles.search_placeholder'),
defaultSort: { field: 'position', direction: 'asc' },
emptyIcon: <TruckIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/gift-cards.tsx b/packages/dashboard/src/tables/gift-cards.tsx
index 7cc1a4da1d..f3b31fef09 100644
--- a/packages/dashboard/src/tables/gift-cards.tsx
+++ b/packages/dashboard/src/tables/gift-cards.tsx
@@ -28,7 +28,7 @@ defineTable<GiftCard>('gift-cards', {
title: i18n.t('admin.nav.gift_cards'),
docsPath: 'loyalty/gift-cards',
description: i18n.t('admin.table_descriptions.gift_cards'),
- searchParam: 'code_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.gift_cards.table.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <GiftIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/imports.tsx b/packages/dashboard/src/tables/imports.tsx
index 5f40e46266..9e4f77ef72 100644
--- a/packages/dashboard/src/tables/imports.tsx
+++ b/packages/dashboard/src/tables/imports.tsx
@@ -18,7 +18,7 @@ defineTable<Import>('imports', {
title: i18n.t('admin.pages.settings.imports.title'),
docsPath: 'manage-products/import-products',
description: i18n.t('admin.table_descriptions.imports'),
- searchParam: 'number_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.pages.settings.imports.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <UploadIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/markets.tsx b/packages/dashboard/src/tables/markets.tsx
index 37d6a2ace7..75c44183ae 100644
--- a/packages/dashboard/src/tables/markets.tsx
+++ b/packages/dashboard/src/tables/markets.tsx
@@ -8,7 +8,7 @@ defineTable<Market>('markets', {
title: i18n.t('admin.settings_nav.items.markets'),
docsPath: 'settings/markets',
description: i18n.t('admin.table_descriptions.markets'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.markets.search_placeholder'),
defaultSort: { field: 'position', direction: 'asc' },
emptyIcon: <GlobeIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/option-types.tsx b/packages/dashboard/src/tables/option-types.tsx
index baf242a8eb..aecaca5220 100644
--- a/packages/dashboard/src/tables/option-types.tsx
+++ b/packages/dashboard/src/tables/option-types.tsx
@@ -14,7 +14,7 @@ defineTable<OptionType>('option-types', {
title: i18n.t('admin.nav.options'),
description: i18n.t('admin.table_descriptions.options'),
docsPath: 'manage-products/product-options',
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.option_types.table.search_placeholder'),
defaultSort: { field: 'position', direction: 'asc' },
emptyIcon: <ListChecksIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/payment-methods.tsx b/packages/dashboard/src/tables/payment-methods.tsx
index 5f9c64187f..16bf96e3b7 100644
--- a/packages/dashboard/src/tables/payment-methods.tsx
+++ b/packages/dashboard/src/tables/payment-methods.tsx
@@ -8,7 +8,7 @@ defineTable<PaymentMethod>('payment-methods', {
docsPath: 'settings/payments',
description: i18n.t('admin.table_descriptions.payment_methods'),
title: i18n.t('admin.payment_methods.title'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.payment_methods.search_placeholder'),
defaultSort: { field: 'position', direction: 'asc' },
emptyIcon: <CreditCardIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/policies.tsx b/packages/dashboard/src/tables/policies.tsx
index 5aca728281..c14e8f6471 100644
--- a/packages/dashboard/src/tables/policies.tsx
+++ b/packages/dashboard/src/tables/policies.tsx
@@ -8,7 +8,7 @@ defineTable<Policy>('policies', {
docsPath: 'settings/policies',
description: i18n.t('admin.table_descriptions.policies'),
title: i18n.t('admin.settings_nav.items.policies'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.policies.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <ScrollTextIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/post-sale.tsx b/packages/dashboard/src/tables/post-sale.tsx
index ae4141d0fe..0bb1da8316 100644
--- a/packages/dashboard/src/tables/post-sale.tsx
+++ b/packages/dashboard/src/tables/post-sale.tsx
@@ -67,7 +67,7 @@ defineTable<Return>('returns', {
title: i18n.t('admin.nav.returns'),
description: i18n.t('admin.table_descriptions.returns'),
docsPath: 'orders/returns',
- searchParam: 'number_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.post_sale.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <RotateCcwIcon className="size-8 text-muted-foreground" />,
@@ -98,7 +98,7 @@ defineTable<Exchange>('exchanges', {
title: i18n.t('admin.nav.exchanges'),
description: i18n.t('admin.table_descriptions.exchanges'),
docsPath: 'orders/exchanges',
- searchParam: 'number_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.post_sale.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <RepeatIcon className="size-8 text-muted-foreground" />,
@@ -129,7 +129,7 @@ defineTable<Claim>('claims', {
title: i18n.t('admin.nav.claims'),
description: i18n.t('admin.table_descriptions.claims'),
docsPath: 'orders/claims',
- searchParam: 'number_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.post_sale.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <ShieldAlertIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/price-lists.tsx b/packages/dashboard/src/tables/price-lists.tsx
index 4b9951399f..957eb34287 100644
--- a/packages/dashboard/src/tables/price-lists.tsx
+++ b/packages/dashboard/src/tables/price-lists.tsx
@@ -9,7 +9,7 @@ defineTable<PriceList>('price-lists', {
title: i18n.t('admin.nav.price_lists'),
description: i18n.t('admin.table_descriptions.price_lists'),
docsPath: 'pricing/price-lists',
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.common.search_placeholder'),
defaultSort: { field: 'position', direction: 'asc' },
emptyIcon: <TagsIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/product-types.tsx b/packages/dashboard/src/tables/product-types.tsx
index 7d97ea8ba7..a0c14da2c8 100644
--- a/packages/dashboard/src/tables/product-types.tsx
+++ b/packages/dashboard/src/tables/product-types.tsx
@@ -8,7 +8,7 @@ defineTable<ProductType>('product-types', {
docsPath: 'settings/product-types',
title: i18n.t('admin.settings_nav.items.product_types'),
description: i18n.t('admin.table_descriptions.product_types'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.product_types.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <ShapesIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/promotions.tsx b/packages/dashboard/src/tables/promotions.tsx
index 2819772161..f60afa2716 100644
--- a/packages/dashboard/src/tables/promotions.tsx
+++ b/packages/dashboard/src/tables/promotions.tsx
@@ -8,7 +8,7 @@ defineTable<Promotion>('promotions', {
docsPath: 'promotions/create-a-promotion',
description: i18n.t('admin.table_descriptions.promotions'),
title: i18n.t('admin.nav.promotions'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.promotions.table.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <TagIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/purchase-orders.tsx b/packages/dashboard/src/tables/purchase-orders.tsx
index 415b00b820..ba79246db9 100644
--- a/packages/dashboard/src/tables/purchase-orders.tsx
+++ b/packages/dashboard/src/tables/purchase-orders.tsx
@@ -20,7 +20,7 @@ defineTable<PurchaseOrder>('purchase-orders', {
docsPath: 'inventory/purchase-orders',
title: i18n.t('admin.purchase_orders.title'),
description: i18n.t('admin.table_descriptions.purchase_orders'),
- searchParam: 'number_or_reference_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.purchase_orders.table.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <TruckIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/saved-reports.tsx b/packages/dashboard/src/tables/saved-reports.tsx
index 32f081c7f3..90a2b8d05d 100644
--- a/packages/dashboard/src/tables/saved-reports.tsx
+++ b/packages/dashboard/src/tables/saved-reports.tsx
@@ -9,7 +9,7 @@ defineTable<SavedReport>('saved-reports', {
docsPath: 'reports/reports',
title: i18n.t('admin.reports.title'),
description: i18n.t('admin.reports.subtitle'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.reports.table.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <ChartColumnIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/seller-requirements.tsx b/packages/dashboard/src/tables/seller-requirements.tsx
index 4707be2d1d..fd31b22619 100644
--- a/packages/dashboard/src/tables/seller-requirements.tsx
+++ b/packages/dashboard/src/tables/seller-requirements.tsx
@@ -9,7 +9,7 @@ defineTable<SellerRequirement>('seller-requirements', {
docsPath: 'sellers/onboarding',
description: i18n.t('admin.table_descriptions.seller_requirements'),
title: i18n.t('admin.seller_requirements.title'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.seller_requirements.search_placeholder'),
defaultSort: { field: 'position', direction: 'asc' },
emptyIcon: <ClipboardCheckIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/sellers.tsx b/packages/dashboard/src/tables/sellers.tsx
index 5773c7c06e..b9ca5d2ade 100644
--- a/packages/dashboard/src/tables/sellers.tsx
+++ b/packages/dashboard/src/tables/sellers.tsx
@@ -10,7 +10,7 @@ defineTable<Seller>('sellers', {
docsPath: 'sellers/managing-sellers',
description: i18n.t('admin.table_descriptions.sellers'),
title: i18n.t('admin.nav.sellers'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.sellers.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <StoreIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/stock-levels.tsx b/packages/dashboard/src/tables/stock-levels.tsx
index f8be97424d..92fbdcf906 100644
--- a/packages/dashboard/src/tables/stock-levels.tsx
+++ b/packages/dashboard/src/tables/stock-levels.tsx
@@ -28,7 +28,7 @@ defineTable<StockLevel>('stock-levels', {
title: i18n.t('admin.stock_levels.title'),
description: i18n.t('admin.table_descriptions.stock_levels'),
docsPath: 'inventory/stock-levels',
- searchParam: 'variant_sku_or_variant_product_name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.stock_levels.table.search_placeholder'),
// A shelf list has to hold still. Without this the table falls back to
// `updated_at desc`, and correcting a count — which touches `updated_at` —
diff --git a/packages/dashboard/src/tables/stock-transfers.tsx b/packages/dashboard/src/tables/stock-transfers.tsx
index 5ea6928fd0..22271d0479 100644
--- a/packages/dashboard/src/tables/stock-transfers.tsx
+++ b/packages/dashboard/src/tables/stock-transfers.tsx
@@ -13,7 +13,7 @@ defineTable<StockTransfer>('stock-transfers', {
title: i18n.t('admin.stock_transfers.title'),
description: i18n.t('admin.table_descriptions.stock_transfers'),
docsPath: 'inventory/stock-transfers',
- searchParam: 'number_or_reference_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.stock_transfers.table.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <ArrowLeftRightIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/store-credits.tsx b/packages/dashboard/src/tables/store-credits.tsx
index 746a95f45f..0b09d86d68 100644
--- a/packages/dashboard/src/tables/store-credits.tsx
+++ b/packages/dashboard/src/tables/store-credits.tsx
@@ -27,7 +27,7 @@ defineTable<StoreCredit>('store-credits', {
docsPath: 'loyalty/store-credits-list',
description: i18n.t('admin.table_descriptions.store_credits'),
title: i18n.t('admin.nav.store_credits'),
- searchParam: 'memo_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.store_credits.table.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <BanknoteIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/suppliers.tsx b/packages/dashboard/src/tables/suppliers.tsx
index 15e0b9f7fe..3b7034e456 100644
--- a/packages/dashboard/src/tables/suppliers.tsx
+++ b/packages/dashboard/src/tables/suppliers.tsx
@@ -8,7 +8,7 @@ defineTable<Supplier>('suppliers', {
docsPath: 'inventory/suppliers',
title: i18n.t('admin.suppliers.title'),
description: i18n.t('admin.table_descriptions.suppliers'),
- searchParam: 'name_or_contact_name_or_email_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.suppliers.table.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <Building2Icon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/tax-categories.tsx b/packages/dashboard/src/tables/tax-categories.tsx
index 23a7a0da8b..f39d42df2f 100644
--- a/packages/dashboard/src/tables/tax-categories.tsx
+++ b/packages/dashboard/src/tables/tax-categories.tsx
@@ -8,7 +8,7 @@ defineTable<TaxCategory>('tax-categories', {
docsPath: 'settings/tax',
description: i18n.t('admin.table_descriptions.tax_categories'),
title: i18n.t('admin.settings_nav.items.tax_categories'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.tax_categories.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <PercentIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/tax-rates.tsx b/packages/dashboard/src/tables/tax-rates.tsx
index aead6b989d..daa2880333 100644
--- a/packages/dashboard/src/tables/tax-rates.tsx
+++ b/packages/dashboard/src/tables/tax-rates.tsx
@@ -10,7 +10,7 @@ defineTable<TaxRate>('tax-rates', {
docsPath: 'settings/tax',
description: i18n.t('admin.table_descriptions.tax_rates'),
title: i18n.t('admin.settings_nav.items.tax_rates'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.tax_rates.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <ReceiptTextIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/dashboard/src/tables/webhook-deliveries.tsx b/packages/dashboard/src/tables/webhook-deliveries.tsx
index 3038b9502e..76c0af3d31 100644
--- a/packages/dashboard/src/tables/webhook-deliveries.tsx
+++ b/packages/dashboard/src/tables/webhook-deliveries.tsx
@@ -17,7 +17,7 @@ defineTable<WebhookDelivery>('webhook-deliveries', {
docsPath: 'settings/webhooks',
description: i18n.t('admin.table_descriptions.webhook_deliveries'),
title: i18n.t('admin.pages.settings.webhooks.deliveries_sheet_title'),
- searchParam: 'event_name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.pages.settings.webhooks.deliveries.search_placeholder'),
// `created_at` (not `delivered_at`) so freshly-queued rows whose
// `delivered_at` is still null sort to the top. Matches the model's
diff --git a/packages/dashboard/src/tables/webhook-endpoints.tsx b/packages/dashboard/src/tables/webhook-endpoints.tsx
index 6e6479ce84..95fe4f0f5c 100644
--- a/packages/dashboard/src/tables/webhook-endpoints.tsx
+++ b/packages/dashboard/src/tables/webhook-endpoints.tsx
@@ -16,7 +16,7 @@ defineTable<WebhookEndpoint>('webhook-endpoints', {
docsPath: 'settings/webhooks',
description: i18n.t('admin.table_descriptions.webhook_endpoints'),
title: i18n.t('admin.pages.settings.webhooks.title'),
- searchParam: 'url_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('admin.pages.settings.webhooks.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <WebhookIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/seller-dashboard/src/tables/delivery-methods.tsx b/packages/seller-dashboard/src/tables/delivery-methods.tsx
index 404157129b..bfc7b46286 100644
--- a/packages/seller-dashboard/src/tables/delivery-methods.tsx
+++ b/packages/seller-dashboard/src/tables/delivery-methods.tsx
@@ -6,7 +6,7 @@ import i18n from 'i18next'
defineTable<DeliveryMethod>('seller-delivery-methods', {
title: i18n.t('delivery_methods.title'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('delivery_methods.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <TruckIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/seller-dashboard/src/tables/payouts.tsx b/packages/seller-dashboard/src/tables/payouts.tsx
index 6923a8ac8c..4cacc87ab7 100644
--- a/packages/seller-dashboard/src/tables/payouts.tsx
+++ b/packages/seller-dashboard/src/tables/payouts.tsx
@@ -22,7 +22,7 @@ const STATUSES = ['pending', 'processing', 'completed', 'failed', 'unresolved']
defineTable<Payout>('seller-payouts', {
title: i18n.t('payouts.title'),
- searchParam: 'reference_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('payouts.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <HandCoinsIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/seller-dashboard/src/tables/policies.tsx b/packages/seller-dashboard/src/tables/policies.tsx
index 9f02e3f4d3..67ae6ade47 100644
--- a/packages/seller-dashboard/src/tables/policies.tsx
+++ b/packages/seller-dashboard/src/tables/policies.tsx
@@ -6,7 +6,7 @@ import i18n from 'i18next'
defineTable<Policy>('seller-policies', {
title: i18n.t('policies.title'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('policies.search_placeholder'),
defaultSort: { field: 'name', direction: 'asc' },
emptyIcon: <ScrollTextIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/seller-dashboard/src/tables/products.tsx b/packages/seller-dashboard/src/tables/products.tsx
index 9742093461..c60d8e5c43 100644
--- a/packages/seller-dashboard/src/tables/products.tsx
+++ b/packages/seller-dashboard/src/tables/products.tsx
@@ -9,7 +9,7 @@ const PRODUCT_STATUSES = ['active', 'draft', 'proposed', 'rejected', 'archived']
defineTable<Product>('seller-products', {
title: i18n.t('products.title'),
- searchParam: 'name_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('products.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <PackageIcon className="size-8 text-muted-foreground" />,
diff --git a/packages/seller-dashboard/src/tables/transfers.tsx b/packages/seller-dashboard/src/tables/transfers.tsx
index cb9163e3d3..c0d6f8e15c 100644
--- a/packages/seller-dashboard/src/tables/transfers.tsx
+++ b/packages/seller-dashboard/src/tables/transfers.tsx
@@ -51,7 +51,7 @@ defineTable<Transfer>('seller-transfers', {
// Without this the toolbar sends `name_cont`, which the ledger does not
// whitelist — Ransack drops an unknown condition, so the box would look
// like it worked and return everything.
- searchParam: 'reference_cont',
+ searchParam: 'search',
searchPlaceholder: i18n.t('earnings.search_placeholder'),
defaultSort: { field: 'created_at', direction: 'desc' },
emptyIcon: <BanknoteIcon className="size-8 text-muted-foreground" />,
diff --git a/spree/core/app/models/concerns/spree/ransackable_attributes.rb b/spree/core/app/models/concerns/spree/ransackable_attributes.rb
index 7da79fdc27..f8a38ced51 100644
--- a/spree/core/app/models/concerns/spree/ransackable_attributes.rb
+++ b/spree/core/app/models/concerns/spree/ransackable_attributes.rb
@@ -27,6 +27,9 @@ module Spree::RansackableAttributes
class_attribute :private_ransackable_attributes, default: {}
class_attribute :private_ransackable_scopes, default: {}
+ # Attributes the `search` filter matches, set with {.search_by}.
+ class_attribute :search_attributes, default: [], instance_accessor: false
+
class_attribute :default_ransackable_attributes
# `position` is included so any `acts_as_list` model is sortable by it
# without each subclass having to opt in. Ransack ignores attributes
@@ -54,10 +57,47 @@ module Spree::RansackableAttributes
def self.ransackable_scopes(auth_object = nil)
base = (whitelisted_ransackable_scopes || []).map(&:to_s)
base |= Spree.ransack.custom_scopes_for(self).map(&:to_s)
+ base |= %w[search] if search_attributes.any? && search_attributes.all? { |path| ransackable_path?(path, auth_object) }
return base unless Spree::RansackableAttributes.restricted_audience?(auth_object)
base - Array(private_ransackable_scopes[auth_object.to_sym])
end
+
+ # Declares the `search` filter (`q[search]=term`): a case-insensitive
+ # partial match on any of the given attributes, which may reach through
+ # associations (`variant_sku`). It runs as Ransack's `_cont` on those
+ # attributes, so translated names match in the current locale. An
+ # audience that may not filter on every one of them does not get it.
+ #
+ # search_by :name, :code
+ #
+ # @param attributes [Array<Symbol, String>]
+ def self.search_by(*attributes)
+ self.search_attributes = attributes.map(&:to_s).freeze
+ scope :search, ->(query) {
+ query.blank? ? all : ransack("#{search_attributes.join('_or_')}_cont" => query.to_s.strip).result
+ }
+ end
+
+ # Whether an attribute, or one reached through associations
+ # (`variant_product_name`), is filterable by this audience.
+ #
+ # @param path [String]
+ # @param auth_object [Symbol, nil]
+ # @return [Boolean]
+ def self.ransackable_path?(path, auth_object = nil, depth = 0)
+ return true if ransackable_attributes(auth_object).include?(path)
+ return false if depth >= 2
+
+ ransackable_associations(auth_object).any? do |name|
+ next false unless path.start_with?("#{name}_")
+
+ reflection = reflect_on_association(name.to_sym)
+ next false if reflection.nil? || reflection.polymorphic? || !reflection.klass.respond_to?(:ransackable_path?)
+
+ reflection.klass.ransackable_path?(path.delete_prefix("#{name}_"), auth_object, depth + 1)
+ end
+ end
end
# @param auth_object [Symbol, nil] the Ransack auth object a search ran with
diff --git a/spree/core/app/models/spree/allowed_origin.rb b/spree/core/app/models/spree/allowed_origin.rb
index 55eec27ab8..4916f3d932 100644
--- a/spree/core/app/models/spree/allowed_origin.rb
+++ b/spree/core/app/models/spree/allowed_origin.rb
@@ -11,6 +11,7 @@ module Spree
include Spree::SingleStoreResource
self.whitelisted_ransackable_attributes = %w[origin]
+ search_by :origin
validates :origin, presence: true
diff --git a/spree/core/app/models/spree/catalog.rb b/spree/core/app/models/spree/catalog.rb
index 092c58c14a..1b7bd4ea4f 100644
--- a/spree/core/app/models/spree/catalog.rb
+++ b/spree/core/app/models/spree/catalog.rb
@@ -86,6 +86,7 @@ module Spree
scope :by_position, -> { ordered }
self.whitelisted_ransackable_attributes = %w[name active]
+ search_by :name
# The catalogs that apply to a purchase node, nearest node first: the
# node's own assignments before its parent's, catalog position breaking
diff --git a/spree/core/app/models/spree/category.rb b/spree/core/app/models/spree/category.rb
index ca049dda8d..da00d94a7a 100644
--- a/spree/core/app/models/spree/category.rb
+++ b/spree/core/app/models/spree/category.rb
@@ -135,6 +135,7 @@ module Spree
self.whitelisted_ransackable_associations = %w[parent]
self.whitelisted_ransackable_attributes = %w[name permalink automatic depth children_count
products_count pretty_name parent_id]
+ search_by :name, :pretty_name
#
# Translations
diff --git a/spree/core/app/models/spree/channel.rb b/spree/core/app/models/spree/channel.rb
index 27cf52b72c..1fde2a6072 100644
--- a/spree/core/app/models/spree/channel.rb
+++ b/spree/core/app/models/spree/channel.rb
@@ -60,6 +60,7 @@ module Spree
scope :default, -> { where(default: true) }
self.whitelisted_ransackable_attributes = %w[name code active default store_id]
+ search_by :name
# Publishes the given products on this channel by creating/upserting ProductPublications.
# Optionally sets the publication window; if not given, the products will be published immediately
diff --git a/spree/core/app/models/spree/claim.rb b/spree/core/app/models/spree/claim.rb
index bbcccda9c7..c2ea42810b 100644
--- a/spree/core/app/models/spree/claim.rb
+++ b/spree/core/app/models/spree/claim.rb
@@ -44,6 +44,7 @@ module Spree
delegate :currency, to: :order
self.whitelisted_ransackable_attributes = %w[number status created_at]
+ search_by :number
self.whitelisted_ransackable_associations = %w[order reason]
def refund_total
diff --git a/spree/core/app/models/spree/collection.rb b/spree/core/app/models/spree/collection.rb
index 9942dc9c8c..0056256461 100644
--- a/spree/core/app/models/spree/collection.rb
+++ b/spree/core/app/models/spree/collection.rb
@@ -101,6 +101,7 @@ module Spree
# Ransack
#
self.whitelisted_ransackable_attributes = %w[permalink automatic sort_order products_count]
+ search_by :name
#
# Automatic (rule-based) membership
diff --git a/spree/core/app/models/spree/commission_rate.rb b/spree/core/app/models/spree/commission_rate.rb
index e500c1c9aa..249126fac9 100644
--- a/spree/core/app/models/spree/commission_rate.rb
+++ b/spree/core/app/models/spree/commission_rate.rb
@@ -106,6 +106,7 @@ module Spree
self.whitelisted_ransackable_attributes = %w[name code kind enabled position value
tax_inclusive include_shipping]
+ search_by :name
self.whitelisted_ransackable_associations = %w[commission_rules]
# @return [Boolean]
diff --git a/spree/core/app/models/spree/company.rb b/spree/core/app/models/spree/company.rb
index 7773b045a9..5fd83d6800 100644
--- a/spree/core/app/models/spree/company.rb
+++ b/spree/core/app/models/spree/company.rb
@@ -101,6 +101,7 @@ module Spree
}
self.whitelisted_ransackable_attributes = %w[name kind parent_id po_number_required]
+ search_by :name
self.whitelisted_ransackable_associations = %w[parent children memberships external_references]
# The node a buyer browses and buys as when they name none: the single
diff --git a/spree/core/app/models/spree/custom_field_definition.rb b/spree/core/app/models/spree/custom_field_definition.rb
index 16120dee6b..00cd1ff703 100644
--- a/spree/core/app/models/spree/custom_field_definition.rb
+++ b/spree/core/app/models/spree/custom_field_definition.rb
@@ -25,16 +25,6 @@ module Spree
scope :for_resource_type, ->(resource_type) { where(resource_type: resource_type) }
scope :storefront_visible, -> { where(storefront_visible: true) }
scope :admin_only, -> { where(storefront_visible: false) }
- scope :search, ->(query) do
- return all if query.blank?
-
- search_term = "%#{query.downcase}%"
- namespace_condition = arel_table[:namespace].lower.matches(search_term)
- key_condition = arel_table[:key].lower.matches(search_term)
- label_condition = arel_table[:label].lower.matches(search_term)
-
- where(namespace_condition.or(key_condition).or(label_condition))
- end
#
# Callbacks
@@ -62,7 +52,7 @@ module Spree
else super
end
end
- self.whitelisted_ransackable_scopes = %w[search]
+ search_by :namespace, :key, :label
# API-facing token for the STI subclass name stored in the `field_type`
# column. Reader returns the registered token (`short_text`); writer
diff --git a/spree/core/app/models/spree/customer_group.rb b/spree/core/app/models/spree/customer_group.rb
index 0bfbbbd33c..d9f4b2057b 100644
--- a/spree/core/app/models/spree/customer_group.rb
+++ b/spree/core/app/models/spree/customer_group.rb
@@ -5,6 +5,7 @@ module Spree
acts_as_paranoid
include Spree::SingleStoreResource
+ search_by :name
#
# Associations
diff --git a/spree/core/app/models/spree/delivery_method.rb b/spree/core/app/models/spree/delivery_method.rb
index 29a5a21099..c23f675fd4 100644
--- a/spree/core/app/models/spree/delivery_method.rb
+++ b/spree/core/app/models/spree/delivery_method.rb
@@ -122,6 +122,7 @@ module Spree
# needed. `seller_id` is what the operator's list filters by to see one
# seller's methods, or (blank) the marketplace's own.
self.whitelisted_ransackable_attributes = %w[storefront_visible available_to_sellers seller_id]
+ search_by :name
self.whitelisted_ransackable_associations = %w[seller]
validates :name, presence: true
diff --git a/spree/core/app/models/spree/delivery_profile.rb b/spree/core/app/models/spree/delivery_profile.rb
index 6b57aca102..d782c13d5f 100644
--- a/spree/core/app/models/spree/delivery_profile.rb
+++ b/spree/core/app/models/spree/delivery_profile.rb
@@ -13,6 +13,7 @@ module Spree
include Spree::HasListPosition
has_prefix_id :fp
+ search_by :name
acts_as_list scope: :store
diff --git a/spree/core/app/models/spree/exchange.rb b/spree/core/app/models/spree/exchange.rb
index 66a3688981..903ac9c5a7 100644
--- a/spree/core/app/models/spree/exchange.rb
+++ b/spree/core/app/models/spree/exchange.rb
@@ -42,6 +42,7 @@ module Spree
delegate :currency, to: :order
self.whitelisted_ransackable_attributes = %w[number status created_at]
+ search_by :number
self.whitelisted_ransackable_associations = %w[order reason]
# Positive when the replacements cost more than what came back (the
diff --git a/spree/core/app/models/spree/gift_card.rb b/spree/core/app/models/spree/gift_card.rb
index af134eca5d..ecfc26c798 100644
--- a/spree/core/app/models/spree/gift_card.rb
+++ b/spree/core/app/models/spree/gift_card.rb
@@ -66,6 +66,7 @@ module Spree
#
ransack_alias :state, :status # @deprecated filter alias — removed in 6.1
self.whitelisted_ransackable_attributes = %w[code customer_id status state gift_card_batch_id created_by_id currency expires_at]
+ search_by :code
# `users` is the pre-6.0 name for `customers` — removed in 6.1.
self.whitelisted_ransackable_associations = %w[customers users orders batch]
self.whitelisted_ransackable_scopes = %w[active expired redeemed partially_redeemed]
diff --git a/spree/core/app/models/spree/import.rb b/spree/core/app/models/spree/import.rb
index c258a8e254..592525a130 100644
--- a/spree/core/app/models/spree/import.rb
+++ b/spree/core/app/models/spree/import.rb
@@ -55,6 +55,7 @@ module Spree
# Ransack configuration
#
self.whitelisted_ransackable_attributes = %w[number type status seller_id]
+ search_by :number
# Lets an operator filter their list by who ran the job — the seller's
# name, not an id they would have to look up first.
self.whitelisted_ransackable_associations = %w[seller]
diff --git a/spree/core/app/models/spree/market.rb b/spree/core/app/models/spree/market.rb
index 966206dc76..bc0e90884a 100644
--- a/spree/core/app/models/spree/market.rb
+++ b/spree/core/app/models/spree/market.rb
@@ -9,6 +9,7 @@ module Spree
acts_as_list scope: :store_id
self.whitelisted_ransackable_attributes = %w[currency default_locale]
+ search_by :name
#
# Associations
diff --git a/spree/core/app/models/spree/option_type.rb b/spree/core/app/models/spree/option_type.rb
index 5a25a38453..93467779fb 100644
--- a/spree/core/app/models/spree/option_type.rb
+++ b/spree/core/app/models/spree/option_type.rb
@@ -25,6 +25,7 @@ module Spree
# `label` is what admin surfaces display, so it has to be filterable —
# matching Spree::OptionValue, which already allows it.
self.whitelisted_ransackable_attributes = %w[label name kind]
+ search_by :name, :label
normalizes :name, with: ->(value) { value&.to_s&.squish&.presence }
diff --git a/spree/core/app/models/spree/package_type.rb b/spree/core/app/models/spree/package_type.rb
index 3b835d5a47..c9a5f345a0 100644
--- a/spree/core/app/models/spree/package_type.rb
+++ b/spree/core/app/models/spree/package_type.rb
@@ -94,6 +94,7 @@ module Spree
# `seller_id` is what the operator's list filters by to see one seller's
# packaging, or (blank) the marketplace's own.
self.whitelisted_ransackable_attributes = %w[name kind default seller_id]
+ search_by :name
self.whitelisted_ransackable_associations = %w[seller]
# The unit the geometry is expressed in, falling back to what the store's
diff --git a/spree/core/app/models/spree/payment_method.rb b/spree/core/app/models/spree/payment_method.rb
index d871ed4800..52675ee880 100644
--- a/spree/core/app/models/spree/payment_method.rb
+++ b/spree/core/app/models/spree/payment_method.rb
@@ -57,6 +57,7 @@ module Spree
# Real columns, so admin clients filter them directly — no ransacker needed.
self.whitelisted_ransackable_attributes = %w[storefront_visible active type]
+ search_by :name
after_initialize :set_name, if: :new_record?
diff --git a/spree/core/app/models/spree/policy.rb b/spree/core/app/models/spree/policy.rb
index 24fc229a00..14f517f0ce 100644
--- a/spree/core/app/models/spree/policy.rb
+++ b/spree/core/app/models/spree/policy.rb
@@ -62,6 +62,7 @@ module Spree
# Ransack
#
self.whitelisted_ransackable_attributes = %w[name owner_type owner_id]
+ search_by :name
before_destroy :really_destroy_slugs!
diff --git a/spree/core/app/models/spree/price_list.rb b/spree/core/app/models/spree/price_list.rb
index f673ca8f77..9a52dadb47 100644
--- a/spree/core/app/models/spree/price_list.rb
+++ b/spree/core/app/models/spree/price_list.rb
@@ -97,6 +97,7 @@ module Spree
# `catalog_id` is queryable so a picker can offer the lists that are
# actually available — unowned, plus the one the catalog already holds.
self.whitelisted_ransackable_attributes = %w[status match_policy starts_at ends_at catalog_id]
+ search_by :name
scope :by_position, -> { ordered }
scope :for_store, ->(store) { where(store: store) }
diff --git a/spree/core/app/models/spree/product_type.rb b/spree/core/app/models/spree/product_type.rb
index cedcc835a1..9f37805a65 100644
--- a/spree/core/app/models/spree/product_type.rb
+++ b/spree/core/app/models/spree/product_type.rb
@@ -37,6 +37,7 @@ module Spree
validates :store, presence: true
self.whitelisted_ransackable_attributes = %w[name]
+ search_by :name
self.whitelisted_ransackable_associations = %w[option_types]
# Replace-set writer for the flat API payload. Each entry is
diff --git a/spree/core/app/models/spree/promotion.rb b/spree/core/app/models/spree/promotion.rb
index cc79532568..f886904bf4 100644
--- a/spree/core/app/models/spree/promotion.rb
+++ b/spree/core/app/models/spree/promotion.rb
@@ -87,6 +87,7 @@ module Spree
# `name` is whitelisted so the admin global search / command palette can
# filter via the `name_or_code_cont` predicate without a dedicated scope.
self.whitelisted_ransackable_attributes = ['name', 'path', 'promotion_category_id', 'code', 'kind', 'starts_at', 'expires_at']
+ search_by :name, :code
self.whitelisted_ransackable_associations = %w[coupon_codes]
def self.with_coupon_code(coupon_code)
diff --git a/spree/core/app/models/spree/purchase_order.rb b/spree/core/app/models/spree/purchase_order.rb
index cfa961720b..65798559ba 100644
--- a/spree/core/app/models/spree/purchase_order.rb
+++ b/spree/core/app/models/spree/purchase_order.rb
@@ -58,6 +58,7 @@ module Spree
self.whitelisted_ransackable_attributes = %w[number status currency reference expected_at
cancel_by ordered_at received_at closed_short_at
supplier_id destination_location_id created_at]
+ search_by :number, :reference
self.whitelisted_ransackable_scopes = %w[open closed overdue past_cancel_by]
self.ransackable_scope_types = %w[open closed overdue past_cancel_by].index_with('boolean')
self.whitelisted_ransackable_associations = %w[supplier destination_location items]
diff --git a/spree/core/app/models/spree/return.rb b/spree/core/app/models/spree/return.rb
index 73b96a5e6f..95c5987e4a 100644
--- a/spree/core/app/models/spree/return.rb
+++ b/spree/core/app/models/spree/return.rb
@@ -52,6 +52,7 @@ module Spree
delegate :currency, to: :order
self.whitelisted_ransackable_attributes = %w[number status created_at]
+ search_by :number
self.whitelisted_ransackable_associations = %w[order reason]
# The label that currently binds the inbound parcel — bought or uploaded,
diff --git a/spree/core/app/models/spree/saved_report.rb b/spree/core/app/models/spree/saved_report.rb
index f00a153f5c..9c475c6723 100644
--- a/spree/core/app/models/spree/saved_report.rb
+++ b/spree/core/app/models/spree/saved_report.rb
@@ -23,6 +23,7 @@ module Spree
scope :seeded, -> { where(seeded: true) }
self.whitelisted_ransackable_attributes = %w[name seeded created_at updated_at]
+ search_by :name
def event_serializer_class
'Spree::Api::V3::SavedReportEventSerializer'.safe_constantize
diff --git a/spree/core/app/models/spree/seller.rb b/spree/core/app/models/spree/seller.rb
index 0476d59f2d..dbcb4078bc 100644
--- a/spree/core/app/models/spree/seller.rb
+++ b/spree/core/app/models/spree/seller.rb
@@ -44,6 +44,7 @@ module Spree
# The storefront lists approved sellers only, and a seller's contact
# address is back-office data.
self.whitelisted_ransackable_attributes = %w[status contact_email]
+ search_by :name
self.private_ransackable_attributes = { store: %w[status contact_email], seller: %w[status contact_email] }
# Who remits consumer tax on this seller's sales. `seller` means they are
diff --git a/spree/core/app/models/spree/seller_payout.rb b/spree/core/app/models/spree/seller_payout.rb
index 81c659d534..028d8abb55 100644
--- a/spree/core/app/models/spree/seller_payout.rb
+++ b/spree/core/app/models/spree/seller_payout.rb
@@ -60,6 +60,7 @@ module Spree
scope :owed, -> { where(status: %w[pending processing]) }
self.whitelisted_ransackable_attributes = %w[amount currency status provider reference period_start period_end created_at seller_id]
+ search_by :reference
# Filtered by the provider's API shorthand (`system`); the column holds
# its class name.
ransacker :provider, formatter: ->(value) { Spree::ApiTyped.class_name_for(Spree.payout_providers, value) } do |parent|
diff --git a/spree/core/app/models/spree/seller_requirement.rb b/spree/core/app/models/spree/seller_requirement.rb
index 778200386e..1dd848c20e 100644
--- a/spree/core/app/models/spree/seller_requirement.rb
+++ b/spree/core/app/models/spree/seller_requirement.rb
@@ -21,6 +21,7 @@ module Spree
self.type_labels_scope = 'spree.seller_requirement_types'
has_prefix_id :selreq
+ search_by :name
acts_as_list scope: :store
diff --git a/spree/core/app/models/spree/seller_transfer.rb b/spree/core/app/models/spree/seller_transfer.rb
index 2976670538..e510c5ba6f 100644
--- a/spree/core/app/models/spree/seller_transfer.rb
+++ b/spree/core/app/models/spree/seller_transfer.rb
@@ -112,6 +112,7 @@ module Spree
end
self.whitelisted_ransackable_attributes = %w[amount currency kind status provider reference created_at seller_id order_id payout_id]
+ search_by :reference
# Filtered by the provider's API shorthand (`system`); the column holds
# its class name.
ransacker :provider, formatter: ->(value) { Spree::ApiTyped.class_name_for(Spree.payout_providers, value) } do |parent|
diff --git a/spree/core/app/models/spree/stock_level.rb b/spree/core/app/models/spree/stock_level.rb
index 364ea4dc65..056c5f4bb6 100644
--- a/spree/core/app/models/spree/stock_level.rb
+++ b/spree/core/app/models/spree/stock_level.rb
@@ -38,6 +38,7 @@ module Spree
self.whitelisted_ransackable_attributes = %w[count_on_hand allocated_count reserved_count incoming_count
stock_location_id variant_id]
+ search_by :variant_sku, :variant_product_name
self.whitelisted_ransackable_scopes = %w[with_stock_status]
self.ransackable_scope_types = { 'with_stock_status' => { list: 'text' } }
self.whitelisted_ransackable_associations = %w[variant stock_location]
diff --git a/spree/core/app/models/spree/stock_location.rb b/spree/core/app/models/spree/stock_location.rb
index 76221e3adf..706f969da6 100644
--- a/spree/core/app/models/spree/stock_location.rb
+++ b/spree/core/app/models/spree/stock_location.rb
@@ -50,6 +50,7 @@ module Spree
country_code state_code created_at updated_at
seller_id
]
+ search_by :name
self.whitelisted_ransackable_associations = %w[seller]
scope :active, -> { where(active: true) }
diff --git a/spree/core/app/models/spree/stock_transfer.rb b/spree/core/app/models/spree/stock_transfer.rb
index 9dff48e57b..8fe160abd2 100644
--- a/spree/core/app/models/spree/stock_transfer.rb
+++ b/spree/core/app/models/spree/stock_transfer.rb
@@ -66,6 +66,7 @@ module Spree
self.whitelisted_ransackable_attributes = %w[number status reference source_location_id
destination_location_id shipped_at received_at
closed_short_at created_at]
+ search_by :number, :reference
self.whitelisted_ransackable_scopes = %w[open closed]
self.ransackable_scope_types = %w[open closed].index_with('boolean')
self.whitelisted_ransackable_associations = %w[source_location destination_location items]
diff --git a/spree/core/app/models/spree/store_credit.rb b/spree/core/app/models/spree/store_credit.rb
index dff8eb056e..6a4f10a0bc 100644
--- a/spree/core/app/models/spree/store_credit.rb
+++ b/spree/core/app/models/spree/store_credit.rb
@@ -109,6 +109,7 @@ module Spree
money_methods :amount, :amount_used, :amount_remaining, :amount_authorized
self.whitelisted_ransackable_attributes = %w[customer_id created_by_id amount currency memo]
+ search_by :memo
self.whitelisted_ransackable_associations = %w[customer created_by]
self.whitelisted_ransackable_scopes = %w[outstanding from_gift_card]
self.ransackable_scope_types = %w[outstanding from_gift_card].index_with('boolean')
diff --git a/spree/core/app/models/spree/supplier.rb b/spree/core/app/models/spree/supplier.rb
index 3d52e51ff4..2a6b88a312 100644
--- a/spree/core/app/models/spree/supplier.rb
+++ b/spree/core/app/models/spree/supplier.rb
@@ -32,6 +32,7 @@ module Spree
normalizes :name, :contact_name, :phone, with: ->(value) { value.strip }
self.whitelisted_ransackable_attributes = %w[name contact_name email phone city country_code created_at]
+ search_by :name, :contact_name, :email
# The postal address, built from this row's own columns the way
# {Spree::StockLocation#address} does. Unsaved, and blank when nothing has
diff --git a/spree/core/app/models/spree/tax_category.rb b/spree/core/app/models/spree/tax_category.rb
index bf93fd126d..ab416333bf 100644
--- a/spree/core/app/models/spree/tax_category.rb
+++ b/spree/core/app/models/spree/tax_category.rb
@@ -16,6 +16,7 @@ module Spree
before_save :set_default_category
self.whitelisted_ransackable_attributes = %w[name is_default tax_code]
+ search_by :name
# The category applied to taxable records that carry none of their own.
#
diff --git a/spree/core/app/models/spree/tax_rate.rb b/spree/core/app/models/spree/tax_rate.rb
index b489ed6251..ae12dba400 100644
--- a/spree/core/app/models/spree/tax_rate.rb
+++ b/spree/core/app/models/spree/tax_rate.rb
@@ -62,6 +62,7 @@ module Spree
self.whitelisted_ransackable_attributes = %w[amount rate country_code state_code tax_category_id included_in_price name]
ransack_alias :rate, :amount
+ search_by :name
# The rate as a fraction (0.23); the column is +amount+.
alias_attribute :rate, :amount
diff --git a/spree/core/app/models/spree/webhook_delivery.rb b/spree/core/app/models/spree/webhook_delivery.rb
index f3c21e388d..f56d79544d 100644
--- a/spree/core/app/models/spree/webhook_delivery.rb
+++ b/spree/core/app/models/spree/webhook_delivery.rb
@@ -25,6 +25,7 @@ module Spree
# Ransack configuration
self.whitelisted_ransackable_attributes = %w[event_name response_code execution_time success delivered_at created_at]
+ search_by :event_name
# Event subjects whose permission is not found by class name alone.
PAYLOAD_SUBJECT_CLASSES = {
diff --git a/spree/core/app/models/spree/webhook_endpoint.rb b/spree/core/app/models/spree/webhook_endpoint.rb
index d9e568f7e9..41cd78f267 100644
--- a/spree/core/app/models/spree/webhook_endpoint.rb
+++ b/spree/core/app/models/spree/webhook_endpoint.rb
@@ -30,6 +30,7 @@ module Spree
before_save :clear_disabled_state_when_reactivated
self.whitelisted_ransackable_attributes = %w[name url active]
+ search_by :url
scope :active, -> { where(active: true) }
scope :inactive, -> { where(active: false) }
diff --git a/spree/core/spec/models/concerns/spree/ransackable_attributes_spec.rb b/spree/core/spec/models/concerns/spree/ransackable_attributes_spec.rb
index 6d3c64571d..f79cdeffd7 100644
--- a/spree/core/spec/models/concerns/spree/ransackable_attributes_spec.rb
+++ b/spree/core/spec/models/concerns/spree/ransackable_attributes_spec.rb
@@ -34,4 +34,30 @@ RSpec.describe Spree::RansackableAttributes do
expect(Spree::Order.ransackable_scopes(:seller)).not_to include('search')
end
end
+
+ describe '.search_by' do
+ let(:store) { @default_store }
+
+ it 'matches any declared attribute, partially and case-insensitively' do
+ supplier = create(:supplier, store: store, name: 'Acme Supplies', contact_name: 'Jane Roe', email: '[email protected]')
+ other = create(:supplier, store: store, name: 'Globex', contact_name: 'John Doe', email: '[email protected]')
+
+ expect(Spree::Supplier.search('acme')).to contain_exactly(supplier)
+ expect(Spree::Supplier.search('JANE')).to contain_exactly(supplier)
+ expect(Spree::Supplier.search('')).to include(supplier, other)
+ end
+
+ it 'reaches through associations' do
+ variant = create(:variant, sku: 'SEARCH-SKU-1')
+
+ expect(Spree::StockLevel.search('search-sku')).to include(*variant.stock_levels)
+ end
+
+ it 'is offered to an audience only when it may filter on every searched attribute' do
+ expect(Spree::StoreCredit.ransackable_scopes).to include('search')
+ expect(Spree::StoreCredit.ransackable_scopes(:store)).not_to include('search')
+ expect(Spree::StockLevel.ransackable_scopes(:store)).not_to include('search')
+ expect(Spree::Collection.ransackable_scopes(:store)).to include('search')
+ end
+ end
end