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

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