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 list filters to checkboxes with an Only shortcut (#15007)

Damian Legawiec27bbcfa8938e
diff --git a/.changeset/dashboard-filter-checkboxes.md b/.changeset/dashboard-filter-checkboxes.md
new file mode 100644
index 0000000000..d3383ce90e
--- /dev/null
+++ b/.changeset/dashboard-filter-checkboxes.md
@@ -0,0 +1,7 @@
+---
+"@spree/dashboard": patch
+"@spree/dashboard-core": patch
+"@spree/dashboard-ui": patch
+---
+
+List filters in the admin dashboard are quicker to narrow. Dropdown menus show checkboxes instead of trailing checkmarks, and every multi-select row offers "Only" on hover to keep just that value, or "Select all" to widen back. Quick filters show the colours of the statuses they let through and a count when narrowed. The Add filter panel lists values as checkboxes under an "Any …" row that clears the field, statuses can be picked several at once, and clicking a filter chip reopens the panel on that field. The Add filter button is now an icon with a tooltip.
diff --git a/packages/dashboard-core/src/components/table-toolbar.tsx b/packages/dashboard-core/src/components/table-toolbar.tsx
index a049e15845..5a9b5bf5ce 100644
--- a/packages/dashboard-core/src/components/table-toolbar.tsx
+++ b/packages/dashboard-core/src/components/table-toolbar.tsx
@@ -37,7 +37,7 @@ import {
XIcon,
} from '@spree/dashboard-ui/icons'
import { useQuery } from '@tanstack/react-query'
-import { Fragment, useCallback, useDeferredValue, useMemo, useState } from 'react'
+import { Fragment, type ReactNode, useCallback, useDeferredValue, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { getApiClient } from '../api-client'
import { useAuth } from '../hooks/use-auth'
@@ -184,6 +184,8 @@ export function TableToolbar({
}: TableToolbarProps) {
const { t } = useTranslation()
const [filterOpen, setFilterOpen] = useState(false)
+ // The rule the panel opens on when its chip is clicked; null opens the field list.
+ const [panelRule, setPanelRule] = useState<FilterRule | null>(null)
const allCols = allColumns ?? columns
// Memoize so `FilterPanel`'s `useMemo` deps stay stable across parent
@@ -226,6 +228,7 @@ export function TableToolbar({
() => filterableColumns.filter((c) => !quickFilterKeys.has(c.key)),
[filterableColumns, quickFilterKeys],
)
+ const panelKeys = useMemo(() => new Set(panelColumns.map((c) => c.key)), [panelColumns])
const chipFilters = useMemo(() => {
const covered = new Set(
quickFilterColumns.flatMap((c) =>
@@ -294,24 +297,43 @@ export function TableToolbar({
className="hidden h-[2.125rem] w-[240px] bg-card text-sm lg:flex"
/>
- {/* Reads as a verb rather than an icon: it is the way *in* to
- everything the quick controls beside it don't cover, so it has to
- look like an action and not a toggle. */}
+ {/* Icon only, like sort and columns: the quick controls beside it
+ already carry the row's words, and the tooltip names it. */}
{/* Hidden when every filterable field already has a quick control:
the button would open onto an empty list. */}
{panelColumns.length > 0 && (
- <Popover open={filterOpen} onOpenChange={setFilterOpen}>
- <PopoverTrigger asChild>
- <Button variant="outline" size="sm" className="h-11 gap-1.5 lg:h-[2.125rem]">
- <ListFilter className="size-3.5" />
- {t('admin.components.table_toolbar.add_filter')}
- </Button>
- </PopoverTrigger>
+ <Popover
+ open={filterOpen}
+ onOpenChange={(next) => {
+ setFilterOpen(next)
+ // Cleared on opening too: Apply closes the panel through
+ // `open`, which does not call this, so the trigger is the
+ // first chance to forget the chip that opened it last.
+ setPanelRule(null)
+ }}
+ >
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <PopoverTrigger asChild>
+ <Button
+ variant="outline"
+ size="sm"
+ className="h-11 lg:h-[2.125rem]"
+ aria-label={t('admin.components.table_toolbar.add_filter')}
+ >
+ <ListFilter className="size-4" />
+ </Button>
+ </PopoverTrigger>
+ </TooltipTrigger>
+ <TooltipContent>{t('admin.components.table_toolbar.add_filter')}</TooltipContent>
+ </Tooltip>
{/* `min(480px, …)` rather than a flat 480px: the panel is wider
than a phone, so a fixed width runs its right edge and the
Apply button off the screen. */}
<PopoverContent align="start" className="w-[min(480px,calc(100vw-1rem))] p-0">
<FilterPanel
+ key={panelRule?.id ?? ''}
+ initialRule={panelRule}
columns={panelColumns}
filters={filters}
onApply={(f) => {
@@ -374,6 +396,14 @@ export function TableToolbar({
key={entry.key}
rules={entry.rules}
col={allCols.find((c) => c.key === entry.rules[0].field)}
+ onEdit={
+ panelKeys.has(entry.rules[0].field)
+ ? () => {
+ setPanelRule(entry.rules[0])
+ setFilterOpen(true)
+ }
+ : undefined
+ }
onRemove={() => {
const removing = new Set(entry.rules.map((r) => r.id))
onFiltersChange(filters.filter((f) => !removing.has(f.id)))
@@ -430,11 +460,14 @@ export function TableToolbar({
function FilterChip({
rules,
col,
+ onEdit,
onRemove,
}: {
/** Usually one rule; a bounded date range is two, shown as one chip. */
rules: FilterRule[]
col: ColumnDef | undefined
+ /** Reopens the filter panel on this field. Absent when the panel cannot edit it. */
+ onEdit?: () => void
onRemove: () => void
}) {
const { t, i18n } = useTranslation()
@@ -465,6 +498,50 @@ function FilterChip({
const opLabelKey = getOperatorLabelKey(col?.filterType ?? 'string', first.operator)
const opLabel = opLabelKey ? t(opLabelKey) : first.operator
const showValue = !noValueOperators.includes(first.operator)
+ // "Status Ready, Error" reads better than "Status is any of Ready, Error";
+ // every other operator, `not_in` included, still says what it does.
+ const showOperator = first.operator !== 'in'
+ const listedIds = ['in', 'not_in'].includes(first.operator) ? parseFilterIds(first.value) : []
+
+ const body = isRange ? (
+ // "1 Aug – 29 Aug 2026" rather than two chips of ISO bounds: the range
+ // is what was asked for, and it is read far more often than it is
+ // edited.
+ <span>
+ {formatDate(from)} – {formatDate(to)}
+ </span>
+ ) : (
+ <>
+ {showOperator && <span className="text-muted-foreground">{opLabel}</span>}
+ {showValue &&
+ (listedIds.length > 2 ? (
+ <span>{t('admin.components.table_toolbar.n_selected', { count: listedIds.length })}</span>
+ ) : col?.filterType === 'date' ? (
+ <span>{formatDate(first.value)}</span>
+ ) : col?.filterType === 'resource' && col.filterResource ? (
+ <ResourceFilterValue value={first.value} config={col.filterResource} />
+ ) : col?.filterType === 'tags' ? (
+ <span>{listedIds.join(', ')}</span>
+ ) : col?.filterType === 'locale' ? (
+ <span>
+ {listedIds.map((code, index) => (
+ <Fragment key={code}>
+ {index > 0 && ', '}
+ <LocaleLabel code={code} />
+ </Fragment>
+ ))}
+ </span>
+ ) : col?.filterType === 'enum' && col.filterOptions ? (
+ <span>
+ {parseFilterIds(first.value)
+ .map((v) => col.filterOptions?.find((o) => o.value === v)?.label ?? v)
+ .join(', ')}
+ </span>
+ ) : (
+ <span>{first.value}</span>
+ ))}
+ </>
+ )
return (
// Deliberately shaped like the quick-filter buttons beside it rather than
@@ -477,44 +554,21 @@ function FilterChip({
// outlined controls reads as a different kind of object, when the only
// real difference is that this one is set and they are not: the solid
// border already says that, against the dashed one an unused control wears.
- <span className="inline-flex h-11 shrink-0 items-center gap-1.5 rounded-md border border-border bg-card py-1 pr-1 pl-2.5 text-sm shadow-xs lg:h-[2.125rem]">
- <span className="text-muted-foreground">{label}</span>
- {isRange ? (
- // "1 Aug – 29 Aug 2026" rather than two chips of ISO bounds: the range
- // is what was asked for, and it is read far more often than it is
- // edited.
- <span>
- {formatDate(from)} – {formatDate(to)}
- </span>
+ <span className="inline-flex h-11 shrink-0 items-center gap-0.5 rounded-md border border-border bg-card pr-1 text-sm shadow-xs lg:h-[2.125rem]">
+ {onEdit ? (
+ <button
+ type="button"
+ className="inline-flex h-full items-center gap-1.5 rounded-l-md pl-2.5 pr-1 transition-colors hover:bg-accent/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
+ onClick={onEdit}
+ >
+ <span className="text-muted-foreground">{label}</span>
+ {body}
+ </button>
) : (
- <>
- <span className="text-muted-foreground">{opLabel}</span>
- {showValue &&
- (col?.filterType === 'date' ? (
- <span>{formatDate(first.value)}</span>
- ) : col?.filterType === 'resource' && col.filterResource ? (
- <ResourceFilterValue value={first.value} config={col.filterResource} />
- ) : col?.filterType === 'tags' ? (
- <span>{parseFilterIds(first.value).join(', ')}</span>
- ) : col?.filterType === 'locale' ? (
- <span>
- {parseFilterIds(first.value).map((code, index) => (
- <Fragment key={code}>
- {index > 0 && ', '}
- <LocaleLabel code={code} />
- </Fragment>
- ))}
- </span>
- ) : col?.filterType === 'enum' && col.filterOptions ? (
- <span>
- {parseFilterIds(first.value)
- .map((v) => col.filterOptions?.find((o) => o.value === v)?.label ?? v)
- .join(', ')}
- </span>
- ) : (
- <span>{first.value}</span>
- ))}
- </>
+ <span className="inline-flex items-center gap-1.5 pl-2.5 pr-1">
+ <span className="text-muted-foreground">{label}</span>
+ {body}
+ </span>
)}
{/* 20px box around a 12px glyph: the chip's own height caps how large
this can be, and the chips are spaced by `gap-2`, which is what the
@@ -678,6 +732,85 @@ function quickFilterTriggerClass(unset: boolean) {
return cn('h-11 gap-1.5 lg:h-[2.125rem]', unset && 'border-dashed')
}
+/** "6/7" on a quick filter that narrows the list. */
+function SelectedCount({ selected, total }: { selected: number; total: number }) {
+ return (
+ <span className="rounded-full bg-muted px-1.5 py-px text-xs font-medium tabular-nums">
+ {selected}/{total}
+ </span>
+ )
+}
+
+/**
+ * Hover shortcut on a multi-select row: "Only" narrows to that value alone,
+ * and on the row that already is the only one, "Select all" widens back.
+ *
+ * Pointer-only and hidden from assistive technology: the row itself stays the
+ * control, and ticking or unticking the others reaches the same state.
+ */
+function RowAction({ label, onSelect }: { label: string; onSelect: () => void }) {
+ return (
+ <span
+ aria-hidden
+ data-slot="filter-row-action"
+ className="ml-auto shrink-0 cursor-pointer pl-3 text-xs text-muted-foreground opacity-0 transition-opacity hover:text-foreground group-hover/row:opacity-100 group-data-[highlighted]/checkbox-item:opacity-100"
+ // Stopped here so the row underneath does not also toggle.
+ onMouseUp={(event) => event.stopPropagation()}
+ onClick={(event) => {
+ event.preventDefault()
+ event.stopPropagation()
+ onSelect()
+ }}
+ >
+ {label}
+ </span>
+ )
+}
+
+/**
+ * The menu rows shared by the enum and resource quick filters. `selected` is
+ * what the list currently shows, which is every value when nothing is set.
+ */
+function QuickFilterItems({
+ options,
+ selected,
+ dots,
+ onChange,
+}: {
+ options: { value: string; label: string }[]
+ selected: string[]
+ dots: boolean
+ onChange: (values: string[]) => void
+}) {
+ const { t } = useTranslation()
+ return options.map((option) => {
+ const checked = selected.includes(option.value)
+ const sole = checked && selected.length === 1
+ return (
+ <DropdownMenuCheckboxItem
+ key={option.value}
+ checked={checked}
+ onCheckedChange={(next) =>
+ onChange(next ? [...selected, option.value] : selected.filter((v) => v !== option.value))
+ }
+ >
+ {dots && <StatusDot status={option.value} />}
+ <span className="truncate">{option.label}</span>
+ {options.length > 1 && (
+ <RowAction
+ label={t(
+ sole
+ ? 'admin.components.table_toolbar.select_all'
+ : 'admin.components.table_toolbar.only',
+ )}
+ onSelect={() => onChange(sole ? options.map((o) => o.value) : [option.value])}
+ />
+ )}
+ </DropdownMenuCheckboxItem>
+ )
+ })
+}
+
/**
* Always-visible control for one heavily-used filter.
*
@@ -746,28 +879,27 @@ function QuickEnumFilter({
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="sm" className={quickFilterTriggerClass(allSelected)}>
- <span className="text-muted-foreground">{column.label}</span>
- <span className="tabular-nums">
- {allSelected ? t('admin.common.all') : `${selected.length}/${options.length}`}
+ {/* The colours of what is let through, so a narrowed status reads
+ at a glance without opening the menu. */}
+ <span aria-hidden className="flex -space-x-1">
+ {options
+ .filter((o) => selected.includes(o.value))
+ .slice(0, 4)
+ .map((o) => (
+ <StatusDot key={o.value} status={o.value} className="size-2.5 ring-2 ring-card" />
+ ))}
</span>
+ <span className="text-muted-foreground">{column.label}</span>
+ {allSelected ? (
+ <span>{t('admin.common.all')}</span>
+ ) : (
+ <SelectedCount selected={selected.length} total={options.length} />
+ )}
<ChevronDownIcon className="size-3.5 text-muted-foreground" />
</Button>
</DropdownMenuTrigger>
- <DropdownMenuContent align="start" className="min-w-52">
- {options.map((option) => (
- <DropdownMenuCheckboxItem
- key={option.value}
- checked={selected.includes(option.value)}
- onCheckedChange={(checked) =>
- apply(
- checked ? [...selected, option.value] : selected.filter((v) => v !== option.value),
- )
- }
- >
- <StatusDot status={option.value} />
- {option.label}
- </DropdownMenuCheckboxItem>
- ))}
+ <DropdownMenuContent align="start" className="min-w-56">
+ <QuickFilterItems options={options} selected={selected} dots onChange={apply} />
</DropdownMenuContent>
</DropdownMenu>
)
@@ -837,11 +969,15 @@ function QuickResourceFilter({
// No rule means no constraint, which is every option — not none.
const active = selected.length > 0 ? selected : options.map((o) => o.value)
const summary =
- selected.length === 0
- ? t('admin.common.all')
- : selected.length === 1
- ? (options.find((o) => o.value === selected[0])?.label ?? '1')
- : `${selected.length}/${options.length}`
+ selected.length === 0 ? (
+ <span>{t('admin.common.all')}</span>
+ ) : selected.length === 1 ? (
+ <span className="max-w-40 truncate">
+ {options.find((o) => o.value === selected[0])?.label ?? '1'}
+ </span>
+ ) : (
+ <SelectedCount selected={selected.length} total={options.length} />
+ )
return (
<DropdownMenu>
@@ -852,22 +988,12 @@ function QuickResourceFilter({
className={quickFilterTriggerClass(selected.length === 0)}
>
<span className="text-muted-foreground">{column.label}</span>
- <span className="max-w-40 truncate">{summary}</span>
+ {summary}
<ChevronDownIcon className="size-3.5 text-muted-foreground" />
</Button>
</DropdownMenuTrigger>
- <DropdownMenuContent align="start" className="min-w-52">
- {options.map((option) => (
- <DropdownMenuCheckboxItem
- key={option.value}
- checked={active.includes(option.value)}
- onCheckedChange={(checked) =>
- apply(checked ? [...active, option.value] : active.filter((v) => v !== option.value))
- }
- >
- {option.label}
- </DropdownMenuCheckboxItem>
- ))}
+ <DropdownMenuContent align="start" className="min-w-56">
+ <QuickFilterItems options={options} selected={active} dots={false} onChange={apply} />
</DropdownMenuContent>
</DropdownMenu>
)
@@ -1104,6 +1230,63 @@ function ColumnSelector({
// ============================================================================
// Filter Drawer
// ============================================================================
+
+const panelRowClass =
+ 'group/row flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50'
+
+/** One value in a multi-select list of the filter panel. */
+function CheckRow({
+ checked,
+ sole,
+ onToggle,
+ onOnly,
+ children,
+}: {
+ checked: boolean
+ /** The only value ticked — its "Only" would do nothing, so it offers none. */
+ sole: boolean
+ onToggle: () => void
+ onOnly: () => void
+ children: ReactNode
+}) {
+ const { t } = useTranslation()
+ return (
+ <button
+ type="button"
+ data-slot="filter-panel-item"
+ aria-pressed={checked}
+ className={panelRowClass}
+ onClick={onToggle}
+ >
+ <Checkbox checked={checked} tabIndex={-1} className="pointer-events-none" />
+ {children}
+ {!sole && <RowAction label={t('admin.components.table_toolbar.only')} onSelect={onOnly} />}
+ </button>
+ )
+}
+
+/** "Any Status": the row that clears this field, ticked while nothing is set. */
+function AnyRow({
+ label,
+ active,
+ onSelect,
+}: {
+ label: string
+ active: boolean
+ onSelect: () => void
+}) {
+ return (
+ <button
+ type="button"
+ data-slot="filter-panel-item"
+ className={cn(panelRowClass, 'justify-between')}
+ onClick={onSelect}
+ >
+ {label}
+ {active && <CheckIcon className="size-4 shrink-0" />}
+ </button>
+ )
+}
/**
* Inline, searchable, multi-select list of a filter's candidate values.
*
@@ -1121,12 +1304,14 @@ function InlineValueList({
query,
selected,
onToggle,
+ onOnly,
}: {
column: ColumnDef
tenantId: string | undefined
query: string
selected: string[]
onToggle: (value: string) => void
+ onOnly: (value: string) => void
}) {
const { t } = useTranslation()
const { isAuthenticated } = useAuth()
@@ -1269,15 +1454,15 @@ function InlineValueList({
return (
<>
{ordered.map((option) => (
- <button
+ <CheckRow
key={option.value}
- type="button"
- className="flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
- onClick={() => onToggle(option.value)}
+ checked={selected.includes(option.value)}
+ sole={selected.length === 1 && selected[0] === option.value}
+ onToggle={() => onToggle(option.value)}
+ onOnly={() => onOnly(option.value)}
>
- <Checkbox checked={selected.includes(option.value)} className="pointer-events-none" />
<span className="truncate">{option.label}</span>
- </button>
+ </CheckRow>
))}
</>
)
@@ -1295,11 +1480,14 @@ function InlineValueList({
* duplicated that list in a second place, in a different notation.
*/
function FilterPanel({
+ initialRule = null,
columns,
filters,
onApply,
onChange,
}: {
+ /** Open straight on this rule's field and value, as when its chip is clicked. */
+ initialRule?: FilterRule | null
/** The fields with no quick control of their own. A field that has one is
* filtered there alone — its checkbox list already says "is" and "is not",
* so offering it here too only listed the same field twice. */
@@ -1314,10 +1502,39 @@ function FilterPanel({
const tenantId = useTenantId()
const store = useOptionalStore()
const timezone = store?.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone ?? 'UTC'
+ /**
+ * What picking a field starts from: the rule already set on it, so reopening
+ * a filter shows the values it is filtering by. Without this a list reads as
+ * empty, and the next tick would replace the existing set rather than extend
+ * it.
+ */
+ function seedFor(key: string | null, rule?: FilterRule | null) {
+ const col = columns.find((c) => c.key === key)
+ if (!col) return { operator: '', value: '', editing: null }
+ const ops = getOperators(col.filterType ?? 'string')
+ const editable = (f: FilterRule) =>
+ f.field === key && col.filterType !== 'date' && ops.some((o) => o.value === f.operator)
+ // The clicked chip's own rule first: a field can carry two typed rules,
+ // and editing "equals b" must not open on "contains a".
+ const applied =
+ (rule && editable(rule) ? rule : undefined) ??
+ filters.find((f) => f.field === key && f.operator === 'in') ??
+ filters.find(editable)
+ return {
+ operator: applied && applied.operator !== 'in' ? applied.operator : ops[0].value,
+ value: applied?.value ?? '',
+ // The typed rule being edited, replaced on Apply even if its operator
+ // changes — otherwise "contains a" edited to "equals b" keeps both.
+ editing: applied && applied.operator !== 'in' ? applied.id : null,
+ }
+ }
+ const [initial] = useState(() => seedFor(initialRule?.field ?? null, initialRule))
+
// The field being built, or null while the field list is showing.
- const [field, setField] = useState<string | null>(null)
- const [operator, setOperator] = useState('')
- const [value, setValue] = useState('')
+ const [field, setField] = useState<string | null>(initialRule?.field ?? null)
+ const [operator, setOperator] = useState(initial.operator)
+ const [value, setValue] = useState(initial.value)
+ const [editing, setEditing] = useState<string | null>(initial.editing)
const [query, setQuery] = useState('')
// Set once the user picks "custom" from the date presets, revealing the two
// date fields. Kept separate from `value` so backing out of custom does not
@@ -1338,6 +1555,11 @@ function FilterPanel({
// accumulate a set and need an explicit Apply; the single ones commit on the
// click that picks them.
const multi = type === 'tags' || type === 'resource' || type === 'currency' || type === 'locale'
+ // An enum is ticked like the others and sent as `in`. Not one backed by a
+ // Ransack scope: a scope takes the value as its argument, and most of them
+ // answer a yes-or-no question that a list of values would not fit.
+ const enumMulti = type === 'enum' && !column?.ransackScope
+ const checked = parseFilterIds(value)
// Dates are their own shape: a list of relative presets, with the calendar
// behind "custom". Same presets the quick filter offers, so a range means
// the same thing wherever it was set.
@@ -1367,15 +1589,11 @@ function FilterPanel({
}, [columns, query])
function chooseField(key: string) {
- const col = columns.find((c) => c.key === key)
- const firstOperator = getOperators(col?.filterType ?? 'string')[0].value
+ const seed = seedFor(key)
setField(key)
- setOperator(firstOperator)
- // Seed from what is already applied, so reopening a multi-select shows the
- // values it is filtering by. Without this the list reads as empty and the
- // next tick would replace the existing set rather than extend it.
- const applied = filters.find((f) => f.field === key && f.operator === 'in')
- setValue(applied?.value ?? '')
+ setOperator(seed.operator)
+ setValue(seed.value)
+ setEditing(seed.editing)
setQuery('')
setCustomRange(null)
}
@@ -1387,6 +1605,7 @@ function FilterPanel({
setField(null)
setOperator('')
setValue('')
+ setEditing(null)
setQuery('')
setCustomRange(null)
}
@@ -1404,7 +1623,9 @@ function FilterPanel({
function commit(nextValue: string, nextOperator = operator) {
if (!field) return
if (!noValueOperators.includes(nextOperator) && nextValue.trim() === '') return
- const others = filters.filter((f) => !(f.field === field && f.operator === nextOperator))
+ const others = filters.filter(
+ (f) => !(f.field === field && f.operator === nextOperator) && f.id !== editing,
+ )
onApply([
...others,
{ id: crypto.randomUUID(), field, operator: nextOperator, value: nextValue },
@@ -1436,15 +1657,18 @@ function FilterPanel({
* unticking the last one removes it, rather than leaving an empty rule that
* would match nothing.
*/
- function toggleValue(option: string) {
+ function setValues(next: string[]) {
if (!field) return
- const current = parseFilterIds(value)
- const next = current.includes(option)
- ? current.filter((v) => v !== option)
- : [...current, option]
setValue(next.join(','))
+ // A reopened `status is active` is shown ticked, so the set that replaces
+ // it must replace that rule too, or the old `eq` keeps narrowing the list.
+ // Only for enums: a `not_in` tag rule is a separate constraint.
+ const replaced = enumMulti ? editing : null
+ setEditing(null)
- const others = filters.filter((f) => !(f.field === field && f.operator === 'in'))
+ const others = filters.filter(
+ (f) => !(f.field === field && f.operator === 'in') && f.id !== replaced,
+ )
onChange(
next.length === 0
? others
@@ -1452,6 +1676,17 @@ function FilterPanel({
)
}
+ /** "Any …": no constraint on this field at all, `is not` rules included. */
+ function clearValues() {
+ setValue('')
+ setEditing(null)
+ onChange(filters.filter((f) => f.field !== field))
+ }
+
+ function toggleValue(option: string) {
+ setValues(checked.includes(option) ? checked.filter((v) => v !== option) : [...checked, option])
+ }
+
return (
// `rounded-xl` to match the popover, and `overflow-hidden` to enforce it:
// the panel is mounted with `p-0`, so the header meets the popover's edge
@@ -1469,19 +1704,12 @@ function FilterPanel({
size when it departs from it. */}
<div className="flex items-stretch border-b text-base">
{field ? (
- // The field name is the way back, not a second picker. It used to
- // open a dropdown over the value list underneath — a menu on top of
- // the menu it was covering, offering the same fields the screen
- // behind it was already showing. Clicking it now simply returns to
- // that list, which is where changing subject was always going to
- // end up.
+ // The field name is the way back to the field list.
<button
type="button"
className="flex shrink-0 cursor-pointer items-center gap-1.5 rounded-none border-r px-3 py-2 font-medium transition-colors hover:bg-accent focus-visible:bg-accent focus-visible:outline-none"
onClick={clearField}
>
- {/* Leads the label rather than trailing it: a back arrow points at
- what it returns to, and after the word it pointed at nothing. */}
<ChevronLeftIcon className="size-4 shrink-0 text-muted-foreground" />
{column?.label ?? field}
</button>
@@ -1544,13 +1772,39 @@ function FilterPanel({
</button>
))}
- {/* Stage two, list-shaped types: the values themselves, one click to
- apply. No operator control — "is" is the only thing a list of
- values can mean, and offering "is not" here would double the list's
- length for a case the panel's other branch already covers. */}
+ {/* Stage two, list-shaped types: the values themselves, ticked and
+ applied as they go. No operator control — "is any of" is the only
+ thing a list of values can mean, and "is not" lives in the typed
+ branch below. */}
+ {field && (multi || enumMulti) && column && (
+ <AnyRow
+ label={t('admin.components.table_toolbar.any_field', { field: column.label })}
+ active={!filters.some((f) => f.field === field)}
+ onSelect={clearValues}
+ />
+ )}
+
+ {field &&
+ enumMulti &&
+ listOptions.map((option) => (
+ <CheckRow
+ key={option.value}
+ checked={checked.includes(option.value)}
+ sole={checked.length === 1 && checked[0] === option.value}
+ onToggle={() => toggleValue(option.value)}
+ onOnly={() => setValues([option.value])}
+ >
+ <StatusDot status={option.value} />
+ <span className="truncate">{option.label}</span>
+ </CheckRow>
+ ))}
+
+ {/* Booleans and scope-backed enums answer one question, so one click
+ picks the answer and closes. */}
{field &&
listed &&
!multi &&
+ !enumMulti &&
listOptions.map((option) => (
<button
key={option.value}
@@ -1576,8 +1830,9 @@ function FilterPanel({
column={column}
tenantId={tenantId}
query={query}
- selected={parseFilterIds(value)}
+ selected={checked}
onToggle={toggleValue}
+ onOnly={(option) => setValues([option])}
/>
)}
@@ -1602,7 +1857,14 @@ function FilterPanel({
type="button"
data-slot="filter-panel-item"
className="flex w-full items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
- onClick={() => setCustomRange({ from: '', to: '' })}
+ // Seeded with the bounds applied, so editing one end keeps the other.
+ onClick={() =>
+ setCustomRange({
+ from:
+ filters.find((f) => f.field === field && f.operator === 'gteq')?.value ?? '',
+ to: filters.find((f) => f.field === field && f.operator === 'lteq')?.value ?? '',
+ })
+ }
>
{t('admin.components.table_toolbar.date_presets.custom')}
<ChevronRightIcon className="size-3.5 shrink-0 text-muted-foreground" />
diff --git a/packages/dashboard-core/src/locales/ar.json b/packages/dashboard-core/src/locales/ar.json
index 8f05a8e190..1f44ddd6c4 100644
--- a/packages/dashboard-core/src/locales/ar.json
+++ b/packages/dashboard-core/src/locales/ar.json
@@ -424,6 +424,7 @@
},
"table_toolbar": {
"add_filter": "إضافة فلتر",
+ "any_field": "{{field}}: الكل",
"ascending": "تصاعدي",
"clear_all": "مسح الكل",
"columns_tooltip": "الأعمدة",
@@ -444,6 +445,8 @@
"filter_select_placeholder": "اختر…",
"filter_text_placeholder": "تصفية…",
"filter_to_placeholder": "التصفية إلى…",
+ "n_selected": "{{count}} محدد",
+ "only": "فقط",
"operators": {
"after": "بعد",
"before": "قبل",
@@ -469,6 +472,7 @@
"remove_filter": "إزالة الفلتر",
"reset_to_default": "إعادة إلى الافتراضي",
"search_placeholder": "بحث…",
+ "select_all": "تحديد الكل",
"sort_by": "ترتيب حسب",
"sort_tooltip": "ترتيب",
"visible_columns": "الأعمدة المرئية"
diff --git a/packages/dashboard-core/src/locales/de.json b/packages/dashboard-core/src/locales/de.json
index 68f236789a..7fa3d4d708 100644
--- a/packages/dashboard-core/src/locales/de.json
+++ b/packages/dashboard-core/src/locales/de.json
@@ -424,6 +424,7 @@
},
"table_toolbar": {
"add_filter": "Filter hinzufügen",
+ "any_field": "Beliebig: {{field}}",
"ascending": "Aufsteigend",
"clear_all": "Alle löschen",
"columns_tooltip": "Spalten",
@@ -444,6 +445,8 @@
"filter_select_placeholder": "Auswählen…",
"filter_text_placeholder": "Filtern…",
"filter_to_placeholder": "Filtern auf…",
+ "n_selected": "{{count}} ausgewählt",
+ "only": "Nur",
"operators": {
"after": "nach",
"before": "vor",
@@ -469,6 +472,7 @@
"remove_filter": "Filter entfernen",
"reset_to_default": "Auf Standard zurücksetzen",
"search_placeholder": "Suchen…",
+ "select_all": "Alle auswählen",
"sort_by": "Sortieren nach",
"sort_tooltip": "Sortieren",
"visible_columns": "Sichtbare Spalten"
diff --git a/packages/dashboard-core/src/locales/en.json b/packages/dashboard-core/src/locales/en.json
index 84da7d4869..97d91f2165 100644
--- a/packages/dashboard-core/src/locales/en.json
+++ b/packages/dashboard-core/src/locales/en.json
@@ -426,6 +426,7 @@
},
"table_toolbar": {
"add_filter": "Add filter",
+ "any_field": "Any {{field}}",
"ascending": "Ascending",
"clear_all": "Clear all",
"columns_tooltip": "Columns",
@@ -446,6 +447,8 @@
"filter_select_placeholder": "Select…",
"filter_text_placeholder": "Filter…",
"filter_to_placeholder": "Filter to…",
+ "n_selected": "{{count}} selected",
+ "only": "Only",
"operators": {
"after": "after",
"before": "before",
@@ -471,6 +474,7 @@
"remove_filter": "Remove filter",
"reset_to_default": "Reset to default",
"search_placeholder": "Search…",
+ "select_all": "Select all",
"sort_by": "Sort by",
"sort_tooltip": "Sort",
"visible_columns": "Visible columns"
diff --git a/packages/dashboard-core/src/locales/es.json b/packages/dashboard-core/src/locales/es.json
index 93b76d0283..293daa87ff 100644
--- a/packages/dashboard-core/src/locales/es.json
+++ b/packages/dashboard-core/src/locales/es.json
@@ -237,6 +237,7 @@
},
"table_toolbar": {
"add_filter": "Agregar filtro",
+ "any_field": "Cualquier {{field}}",
"ascending": "Ascendente",
"clear_all": "Borrar todo",
"columns_tooltip": "Columnas",
@@ -257,6 +258,8 @@
"filter_select_placeholder": "Seleccionar…",
"filter_text_placeholder": "Filtrar…",
"filter_to_placeholder": "Filtrar hasta…",
+ "n_selected": "{{count}} seleccionados",
+ "only": "Solo",
"operators": {
"after": "después de",
"before": "antes de",
@@ -282,6 +285,7 @@
"remove_filter": "Quitar filtro",
"reset_to_default": "Restablecer a la configuración predeterminada",
"search_placeholder": "Buscar…",
+ "select_all": "Seleccionar todo",
"sort_by": "Ordenar por",
"sort_tooltip": "Ordenar",
"visible_columns": "Columnas visibles"
diff --git a/packages/dashboard-core/src/locales/fr.json b/packages/dashboard-core/src/locales/fr.json
index 42e9a64b50..9a224bb5ef 100644
--- a/packages/dashboard-core/src/locales/fr.json
+++ b/packages/dashboard-core/src/locales/fr.json
@@ -424,6 +424,7 @@
},
"table_toolbar": {
"add_filter": "Ajouter un filtre",
+ "any_field": "{{field}} : tous",
"ascending": "Croissant",
"clear_all": "Tout effacer",
"columns_tooltip": "Colonnes",
@@ -444,6 +445,8 @@
"filter_select_placeholder": "Sélectionner…",
"filter_text_placeholder": "Filtrer…",
"filter_to_placeholder": "Filtrer sur…",
+ "n_selected": "{{count}} sélectionnés",
+ "only": "Uniquement",
"operators": {
"after": "après",
"before": "avant",
@@ -469,6 +472,7 @@
"remove_filter": "Supprimer le filtre",
"reset_to_default": "Réinitialiser",
"search_placeholder": "Rechercher…",
+ "select_all": "Tout sélectionner",
"sort_by": "Trier par",
"sort_tooltip": "Trier",
"visible_columns": "Colonnes visibles"
diff --git a/packages/dashboard-core/src/locales/pl.json b/packages/dashboard-core/src/locales/pl.json
index 43dcf408c9..819e645f74 100644
--- a/packages/dashboard-core/src/locales/pl.json
+++ b/packages/dashboard-core/src/locales/pl.json
@@ -425,6 +425,7 @@
},
"table_toolbar": {
"add_filter": "Dodaj filtr",
+ "any_field": "{{field}}: dowolne",
"ascending": "Rosnąco",
"clear_all": "Wyczyść wszystko",
"columns_tooltip": "Kolumny",
@@ -445,6 +446,8 @@
"filter_select_placeholder": "Wybierz…",
"filter_text_placeholder": "Filtruj…",
"filter_to_placeholder": "Filtruj do…",
+ "n_selected": "Wybrano: {{count}}",
+ "only": "Tylko",
"operators": {
"after": "po",
"before": "przed",
@@ -470,6 +473,7 @@
"remove_filter": "Usuń filtr",
"reset_to_default": "Przywróć domyślne",
"search_placeholder": "Szukaj…",
+ "select_all": "Zaznacz wszystko",
"sort_by": "Sortuj według",
"sort_tooltip": "Sortuj",
"visible_columns": "Widoczne kolumny"
diff --git a/packages/dashboard-core/src/locales/zh-CN.json b/packages/dashboard-core/src/locales/zh-CN.json
index be5f8ddaab..4343e1134c 100644
--- a/packages/dashboard-core/src/locales/zh-CN.json
+++ b/packages/dashboard-core/src/locales/zh-CN.json
@@ -424,6 +424,7 @@
},
"table_toolbar": {
"add_filter": "添加筛选条件",
+ "any_field": "任意{{field}}",
"ascending": "升序",
"clear_all": "全部清除",
"columns_tooltip": "列",
@@ -444,6 +445,8 @@
"filter_select_placeholder": "选择…",
"filter_text_placeholder": "筛选…",
"filter_to_placeholder": "筛选至…",
+ "n_selected": "已选 {{count}} 项",
+ "only": "仅此项",
"operators": {
"after": "晚于",
"before": "早于",
@@ -469,6 +472,7 @@
"remove_filter": "移除筛选",
"reset_to_default": "重置为默认值",
"search_placeholder": "搜索…",
+ "select_all": "全选",
"sort_by": "排序方式",
"sort_tooltip": "排序",
"visible_columns": "可见列"
diff --git a/packages/dashboard-ui/src/ui/dropdown-menu.tsx b/packages/dashboard-ui/src/ui/dropdown-menu.tsx
index ff27015fc8..2f437b7227 100644
--- a/packages/dashboard-ui/src/ui/dropdown-menu.tsx
+++ b/packages/dashboard-ui/src/ui/dropdown-menu.tsx
@@ -160,19 +160,23 @@ function DropdownMenuCheckboxItem({
data-slot="dropdown-menu-checkbox-item"
data-inset={inset}
className={cn(
- "relative flex cursor-pointer items-center gap-3 rounded-lg py-1.5 pr-8 pl-2.5 text-sm outline-hidden select-none transition-colors duration-75 focus:bg-accent focus:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
+ "group/checkbox-item relative flex cursor-pointer items-center gap-2.5 rounded-lg py-1.5 pr-2.5 pl-2.5 text-sm outline-hidden select-none transition-colors duration-75 focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className,
)}
checked={checked}
onCheckedChange={onCheckedChange ? (checked) => onCheckedChange(checked) : undefined}
{...props}
>
+ {/* Drawn rather than a <Checkbox>: the item is already the checkbox to
+ assistive technology, and a second control inside it would be read
+ twice. Styled to match <Checkbox> so a menu and a table agree. */}
<span
- className="pointer-events-none absolute right-2 flex items-center justify-center"
+ aria-hidden
data-slot="dropdown-menu-checkbox-item-indicator"
+ className="pointer-events-none flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-border bg-card text-white shadow-xs transition-colors duration-100 group-data-[checked]/checkbox-item:border-blue-500 group-data-[checked]/checkbox-item:bg-blue-500"
>
<MenuPrimitive.CheckboxItemIndicator keepMounted={false}>
- <CheckIcon />
+ <CheckIcon className="size-3.5" />
</MenuPrimitive.CheckboxItemIndicator>
</span>
{children}
diff --git a/packages/dashboard/e2e/helpers.ts b/packages/dashboard/e2e/helpers.ts
index 1e30c5d71c..ca6f704cfd 100644
--- a/packages/dashboard/e2e/helpers.ts
+++ b/packages/dashboard/e2e/helpers.ts
@@ -756,12 +756,17 @@ export async function addTextFilter(page: Page, field: RegExp, operator: RegExp,
await expect(controls).toBeHidden()
}
-/** Adds a filter whose values are listed (a status, yes or no) by picking one. */
+/**
+ * Adds a filter whose values are listed (a status, yes or no) by picking one.
+ * A yes-or-no closes the panel on its own; a status list stays open to tick
+ * more, so Escape closes it.
+ */
export async function addListFilter(page: Page, field: RegExp, value: RegExp) {
await page.getByRole('button', { name: /add filter/i }).click()
const items = page.locator('[data-slot="filter-panel-item"]')
await items.getByText(field).click()
await items.getByText(value).click()
+ await page.keyboard.press('Escape')
}
/** Adds a filter on related records (categories, tags) by searching for one and ticking it. */
@@ -773,20 +778,13 @@ export async function addRecordFilter(page: Page, field: RegExp, value: string)
await page.keyboard.press('Escape')
}
-/**
- * Narrows a quick filter in the toolbar to one value. Every value starts
- * ticked, so narrowing means unticking the rest.
- */
+/** Narrows a quick filter in the toolbar to one value, through that row's "Only". */
export async function narrowQuickFilter(page: Page, trigger: RegExp, keep: RegExp) {
await page.getByRole('button', { name: trigger }).click()
- const items = page.getByRole('menuitemcheckbox')
- await expect(items.first()).toBeVisible()
- for (const item of await items.all()) {
- const name = (await item.textContent()) ?? ''
- if (!keep.test(name.trim()) && (await item.getAttribute('aria-checked')) === 'true') {
- await item.click()
- }
- }
+ const item = page.getByRole('menuitemcheckbox', { name: keep })
+ await item.hover()
+ await item.getByText(/^only$/i).click()
+ await expect(page.getByRole('menuitemcheckbox', { checked: true })).toHaveCount(1)
await page.keyboard.press('Escape')
}
diff --git a/packages/dashboard/e2e/list-filters.spec.ts b/packages/dashboard/e2e/list-filters.spec.ts
index e8d14eea01..76c027073b 100644
--- a/packages/dashboard/e2e/list-filters.spec.ts
+++ b/packages/dashboard/e2e/list-filters.spec.ts
@@ -107,6 +107,15 @@ test.describe('list filters', () => {
await expect(row(page, swatch)).toBeVisible({ timeout: 15_000 })
await expect(row(page, buttons)).toBeHidden()
+
+ // On the only value left, the row's shortcut widens back to every kind.
+ await page.getByRole('button', { name: /^kind/i }).click()
+ const kept = page.getByRole('menuitemcheckbox', { name: /^color swatch$/i })
+ await kept.hover()
+ await kept.getByText(/^select all$/i).click()
+ await page.keyboard.press('Escape')
+
+ await expect(row(page, buttons)).toBeVisible({ timeout: 15_000 })
})
test('filters custom field definitions by type', async ({ page }) => {
@@ -136,4 +145,52 @@ test.describe('list filters', () => {
await expect(row(page, number)).toBeVisible({ timeout: 15_000 })
await expect(row(page, text)).toBeHidden()
})
+
+ // Statuses tick like tags: several at once, and the chip they leave reopens
+ // the panel on the same field with the same values ticked.
+ test('ticks several custom field types and edits them from the chip', async ({ page }) => {
+ const session = await login(page)
+ const id = stamp()
+ const number = `width_${id}`
+ const text = `colour_${id}`
+ const flag = `featured_${id}`
+ for (const [key, fieldType] of [
+ [number, 'number'],
+ [text, 'short_text'],
+ [flag, 'boolean'],
+ ]) {
+ await seedRecord(page, session, '/custom_field_definitions', {
+ namespace: 'e2e',
+ key,
+ field_type: fieldType,
+ resource_type: 'product',
+ })
+ }
+
+ const search = /search by label, namespace, or key/i
+ await openList(page, `/${session.store_id}/settings/custom-field-definitions`, search)
+ await searchList(page, search, id)
+ await expect(row(page, flag)).toBeVisible({ timeout: 15_000 })
+
+ await page.getByRole('button', { name: /add filter/i }).click()
+ const items = page.locator('[data-slot="filter-panel-item"]')
+ await items.getByText(/^type$/i).click()
+ await items.getByText(/^number$/i).click()
+ await items.getByText(/^short text$/i).click()
+ await page.keyboard.press('Escape')
+
+ await expect(row(page, number)).toBeVisible({ timeout: 15_000 })
+ await expect(row(page, text)).toBeVisible()
+ await expect(row(page, flag)).toBeHidden()
+
+ await page.getByRole('button', { name: /^type number, short text$/i }).click()
+ await expect(page.getByRole('button', { name: /^number$/i, pressed: true })).toBeVisible()
+ const shortText = page.getByRole('button', { name: /^short text$/i, pressed: true })
+ await shortText.hover()
+ await shortText.getByText(/^only$/i).click()
+ await page.keyboard.press('Escape')
+
+ await expect(row(page, number)).toBeHidden({ timeout: 15_000 })
+ await expect(row(page, text)).toBeVisible()
+ })
})