OrderFilterBar
WCPOS v2's row of order filter pills, shown only for the filter fields the connector supports
Import
import { OrderFilterBar } from '@tallyui/components';
import { orderFiltersQuery, type OrderFilterValue } from '@tallyui/pos';Usage
The bar is presentational: the app holds the value, passes the connector's orderFilters as fields, and supplies every option list. orderFiltersQuery from @tallyui/pos turns the value into ListOrdersQuery filter fields.
const [filters, setFilters] = useState<OrderFilterValue>({});
<OrderFilterBar
value={filters}
onChange={setFilters}
fields={connector.orderFilters ?? []}
options={{
status: [{ value: 'completed', label: 'Completed' }, { value: 'refunded', label: 'Refunded' }],
paymentMethod: [
{ value: 'pos_cash', label: 'Cash', kind: 'cash' },
{ value: 'stripe', label: 'Stripe', kind: 'card' },
{ value: 'cheque', label: 'Cheque' },
],
customer: [{ value: '0', label: 'Guest' }, { value: '12', label: 'Jane Smith' }],
cashier: [{ value: '1', label: 'Ada' }],
register: [{ value: 'reg-1', label: 'Front till' }],
createdVia: [{ value: 'woocommerce-pos', label: 'POS' }, { value: 'checkout', label: 'Online Store' }],
}}
timezone="Australia/Sydney"
/>Then read the orders with the bar's filters, the date range as UTC instants in the store's zone:
const page = await connector.listOrders?.(context, orderFiltersQuery(filters, 'Australia/Sydney'));How it behaves
Pills, in WCPOS v2's order. Status, Payment Method, Customer, Cashier, Store / Created via, Register and Date range, in one horizontally scrolling row. With nothing picked, they read Status, Payment Method, Select Customer, Select Cashier, Created via, Select register and Date range.
When each pill shows. A pill shows only when its field is in fields, and some also need options:
| Pill | Shows when |
|---|---|
| Status | 'status' is in fields and options.status has at least one option |
| Payment Method | 'paymentMethod' is in fields. With no options its menu reads "No payment methods found" |
| Customer | 'customerId' is in fields and options.customer has an option or onCustomerSearch is given |
| Cashier | 'cashierId' is in fields and options.cashier has an option or onCashierSearch is given |
| Store / Created via | 'createdVia' is in fields with options.createdVia non-empty, or 'storeId' is in fields with options.store non-empty |
| Register | 'registerId' is in fields and options.register has at least one option |
| Date range | 'dateRange' is in fields |
'modifiedAfter' in fields has no pill.
Payment methods are grouped by kind. The menu lists cash, then card, stored_value, bank_transfer and other, with a separator between groups and empty groups left out. An option without a kind goes in other.
Store and Created via share one pill. Its menu has a Created via group and a Store group, each shown only when its field is supported and has options, with a separator when both show. Picking a store clears createdVia, and picking a Created via option clears storeId.
Customer and Cashier search. Each is a searchable combobox. With onCustomerSearch (or onCashierSearch) the pill calls it with the typed text and shows its options as given, so the host does the searching. Without it, the pill filters its options locally by label, ignoring case.
Date range. The pill opens a range calendar; Done sets the range, and closing without Done changes nothing. A set range reads Today or Yesterday when it is that store day in timezone, and otherwise the range itself.
A set pill. It is highlighted, shows the picked option's label (or the raw value when it is not in the options), and has a Remove button that clears its field. Remove on the store pill clears both storeId and createdVia.
Clear all. A Clear all link shows when at least two pills differ from initial; the store pill counts once. It calls onChange with a copy of initial.
What onChange gets. Every pick or Remove calls onChange with the whole value: the current value with that one field set, or set to undefined when cleared. The bar never filters orders itself.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | OrderFilterValue | required | The current filters |
onChange | (next: OrderFilterValue) => void | required | Called with the whole next value |
fields | readonly OrderFilterField[] | required | The connector's orderFilters. A pill shows only when its field is here |
initial | OrderFilterValue | {} | What Clear all resets to and counts against |
options | object, see below | {} | The option list for each pill |
onCustomerSearch | (text: string) => void | — | Search customers on the host instead of filtering options.customer locally |
onCashierSearch | (text: string) => void | — | Search cashiers on the host instead of filtering options.cashier locally |
timezone | string | required | IANA zone of the store, or 'device'. Used for the Today and Yesterday labels and the calendar's today |
now | () => Date | () => new Date() | The clock for the date pill |
testID | string | 'order-filter-bar' | testID of the bar's container |
options
interface OrderFilterBarOptions {
status?: OrderFilterOption[];
paymentMethod?: (OrderFilterOption & { kind?: PaymentKind })[];
customer?: OrderFilterOption[];
cashier?: OrderFilterOption[];
register?: OrderFilterOption[];
store?: OrderFilterOption[];
createdVia?: OrderFilterOption[];
}OrderFilterBarOptions is a name for this page only; the type is OrderFilterBarProps['options'].
OrderFilterValue
From @tallyui/pos. Each field holds an option's value.
interface OrderFilterValue {
status?: string;
customerId?: string;
cashierId?: string;
registerId?: string;
paymentMethod?: string;
storeId?: string;
createdVia?: string;
/** Store days, inclusive. */
dateRange?: DayRange;
}OrderFilterOption
type OrderFilterOption = { value: string; label: string };PaymentMethodKind
Deprecated: use PaymentKind from @tallyui/core. It is the same type.
type PaymentKind = 'cash' | 'card' | 'stored_value' | 'bank_transfer' | 'other';