This commit is contained in:
seb
2026-10-13 23:20:54 +02:00
parent e2bf08d340
commit f6cb3d3e35
3 changed files with 19 additions and 4 deletions

View File

@@ -69,6 +69,7 @@ export {
default as orderAutomat, default as orderAutomat,
selectOrders, selectOrders,
selectOrderTotal, selectOrderTotal,
selectOrderUnfilteredTotal,
selectOrderPagination, selectOrderPagination,
selectOnlyUnpaid, selectOnlyUnpaid,
selectOnlyUndelivered, selectOnlyUndelivered,

View File

@@ -65,6 +65,7 @@ const CHUNK_DEBOUNCE_MS = 130;
const initialState = { const initialState = {
items: null, items: null,
total: 0, total: 0,
unfilteredTotal: 0,
filter: '', filter: '',
onlyUnpaid: false, onlyUnpaid: false,
onlyUndelivered: false, onlyUndelivered: false,
@@ -181,6 +182,7 @@ function getOrCreateFilterCache(filterKey, filterState = automat?.state || initi
label: formatFilterLabel(params), label: formatFilterLabel(params),
params, params,
total: 0, total: 0,
unfilteredTotal: automat?.state?.unfilteredTotal || 0,
items: null, items: null,
loadedChunks: new Set(), loadedChunks: new Set(),
status: 'idle', status: 'idle',
@@ -508,7 +510,8 @@ async function fetchOrdersPageFor(filterParams, offset = 0, limit = CHUNK_SIZE)
const res = await orderApi.list(params); const res = await orderApi.list(params);
const orders = Array.isArray(res?.orders) ? res.orders : []; const orders = Array.isArray(res?.orders) ? res.orders : [];
const total = Number(res?.total ?? orders.length); const total = Number(res?.total ?? orders.length);
return { orders, total }; const unfilteredTotal = res?.unfilteredTotal != null ? Number(res.unfilteredTotal) : total;
return { orders, total, unfilteredTotal };
} }
function onFilterChange(immediate = false) { function onFilterChange(immediate = false) {
@@ -544,6 +547,7 @@ function applyFilterReload() {
automat.setState({ automat.setState({
items: cached.items, items: cached.items,
total: cached.total, total: cached.total,
unfilteredTotal: cached.unfilteredTotal ?? automat.state.unfilteredTotal ?? 0,
status: cached.status || 'ready', status: cached.status || 'ready',
error: cached.error || null, error: cached.error || null,
}); });
@@ -568,6 +572,7 @@ function applyFilterReload() {
automat.setState({ automat.setState({
items: null, items: null,
total: 0, total: 0,
unfilteredTotal: automat.state.unfilteredTotal ?? 0,
status: 'loading', status: 'loading',
error: null, error: null,
}); });
@@ -757,9 +762,10 @@ const actions = {
const filterParams = entry.params || getFilterParams(automat.state); const filterParams = entry.params || getFilterParams(automat.state);
const promise = fetchOrdersPageFor(filterParams, offset, limit) const promise = fetchOrdersPageFor(filterParams, offset, limit)
.then(({ orders, total }) => { .then(({ orders, total, unfilteredTotal }) => {
const currentTotal = total > 0 ? total : 0; const currentTotal = total > 0 ? total : 0;
entry.total = currentTotal; entry.total = currentTotal;
entry.unfilteredTotal = unfilteredTotal;
if (entry.items === null || entry.items.length !== currentTotal) { if (entry.items === null || entry.items.length !== currentTotal) {
entry.items = new Array(currentTotal).fill(null); entry.items = new Array(currentTotal).fill(null);
@@ -788,6 +794,7 @@ const actions = {
automat.setState({ automat.setState({
items: entry.items, items: entry.items,
total: currentTotal, total: currentTotal,
unfilteredTotal,
status: 'ready', status: 'ready',
error: null, error: null,
}); });
@@ -1157,6 +1164,11 @@ export function selectOrderTotal(state = automat.state) {
return state.total; return state.total;
} }
/** Selects unfiltered total count */
export function selectOrderUnfilteredTotal(state = automat.state) {
return state.unfilteredTotal ?? 0;
}
/** Selects unpaid filter */ /** Selects unpaid filter */
export function selectOnlyUnpaid(state = automat.state) { export function selectOnlyUnpaid(state = automat.state) {
return state.onlyUnpaid; return state.onlyUnpaid;

View File

@@ -474,6 +474,7 @@ export class OrderList extends PureComponent {
// getItems() returns current items or null and triggers loading of the first chunk // getItems() returns current items or null and triggers loading of the first chunk
this.state = { this.state = {
items: orderAutomat.getItems(), items: orderAutomat.getItems(),
unfilteredTotal: orderAutomat.state.unfilteredTotal ?? 0,
partiesById: {}, partiesById: {},
busyId: null, busyId: null,
}; };
@@ -490,9 +491,9 @@ export class OrderList extends PureComponent {
componentDidMount() { componentDidMount() {
this._cancelled = false; this._cancelled = false;
// Subscribe to items only
this.unsub = orderAutomat.subscribe(this, (state) => ({ this.unsub = orderAutomat.subscribe(this, (state) => ({
items: state.items, items: state.items,
unfilteredTotal: state.unfilteredTotal ?? 0,
})); }));
void this.loadParties(); void this.loadParties();
} }
@@ -582,7 +583,7 @@ export class OrderList extends PureComponent {
} }
render() { render() {
const { items, partiesById, busyId } = this.state; const { items, unfilteredTotal, partiesById, busyId } = this.state;
rowContext.partiesById = partiesById; rowContext.partiesById = partiesById;
rowContext.busyId = busyId; rowContext.busyId = busyId;
@@ -616,6 +617,7 @@ export class OrderList extends PureComponent {
minHeight={0} minHeight={0}
items={items || []} items={items || []}
totalCount={items ? items.length : 0} totalCount={items ? items.length : 0}
unfilteredTotal={unfilteredTotal}
renderItem={OrderRow} renderItem={OrderRow}
virtualScrollbar virtualScrollbar
header={ header={