farmcontrol-ui/src/components/Dashboard/utils/fetchAllObjectPages.js
Tom Butcher eea7e1f724
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
Add InfoActionButtons to Various Dashboard Components
- Integrated InfoActionButtons into multiple components across the Finance and Inventory sections, enhancing user interaction and providing contextual actions for invoices, payment policies, payments, tax records, and various inventory items.
- Updated the respective components to include the new buttons with appropriate object types and list mode settings, improving the overall functionality and user experience in the dashboard.
2026-09-14 23:33:03 +01:00

42 lines
768 B
JavaScript

export async function fetchAllObjectPages({
fetchObjects,
type,
filter = {},
sorter = {},
limit = 25
}) {
if (!type || typeof fetchObjects !== 'function') return []
const all = []
let page = 1
let totalPages = 1
do {
const result = await fetchObjects(type, {
page,
limit,
filter,
sorter
})
if (!result || Array.isArray(result)) {
break
}
const data = Array.isArray(result.data) ? result.data : []
all.push(...data)
if (Number.isFinite(result.totalPages) && result.totalPages > 0) {
totalPages = result.totalPages
} else if (result.hasMore) {
totalPages = page + 1
} else {
totalPages = page
}
page += 1
} while (page <= totalPages)
return all
}