Sort rooms by Newbook category order, numeric room name collation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-02 20:51:09 +00:00
parent 44653c51e4
commit d25e3421a8

View file

@ -167,22 +167,22 @@ export async function fetchGridData(startDate, days, settings, forceRefresh = fa
const dates = [] const dates = []
for (let i = 0; i < days; i++) dates.push(offsetDate(startDate, i)) for (let i = 0; i < days; i++) dates.push(offsetDate(startDate, i))
const grid = {} const grid = {}
const rooms = [] const rooms = []
const categoryOrder = []
for (const booking of resp.data) { for (const booking of resp.data) {
const siteId = booking.site_id || '' const siteId = booking.site_id || ''
const siteName = booking.site_name || '' const siteName = booking.site_name || ''
if (!siteId || !siteName) continue if (!siteId || !siteName) continue
const category = (booking.category_name || 'Uncategorized').trim()
if (!grid[siteId]) { if (!grid[siteId]) {
grid[siteId] = { grid[siteId] = { site_name: siteName, category, cells: {} }
site_name: siteName,
category: (booking.category_name || 'Uncategorized').trim(),
cells: {},
}
rooms.push(siteId) rooms.push(siteId)
} }
if (!categoryOrder.includes(category)) categoryOrder.push(category)
const checkin = (booking.booking_arrival || '').slice(0, 10) const checkin = (booking.booking_arrival || '').slice(0, 10)
const checkout = (booking.booking_departure || '').slice(0, 10) const checkout = (booking.booking_departure || '').slice(0, 10)
@ -207,11 +207,13 @@ export async function fetchGridData(startDate, days, settings, forceRefresh = fa
} }
} }
// Sort by category then room name // Sort by Newbook's natural category order, then room name numerically
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
rooms.sort((a, b) => { rooms.sort((a, b) => {
const ac = grid[a].category, bc = grid[b].category const ai = categoryOrder.indexOf(grid[a].category)
if (ac !== bc) return ac.localeCompare(bc) const bi = categoryOrder.indexOf(grid[b].category)
return grid[a].site_name.localeCompare(grid[b].site_name) if (ai !== bi) return ai - bi
return collator.compare(grid[a].site_name, grid[b].site_name)
}) })
const result = { dates, rooms, grid } const result = { dates, rooms, grid }