feat(client): let people actually type a bag weight limit

The column, the contract, the API route and its tests have all been there
since v2.9.0 — there was simply no field to enter a limit in, so the only
way to record one was to put it in the bag name, where nothing can act on
it. Both the desktop bag card and the mobile bag row now take a limit in
kilograms (how airlines state them) and store it in grams. Emptying the
field clears the limit instead of writing a zero.

While adding it: the fill-bar formula existed in three places, and the one
in the bag modal had been copied without the limit, so a limit set on a
window narrower than xl did nothing. It now lives once in
packingListPanel.helpers as bagFillPct, next to itemWeight.
This commit is contained in:
Maurice
2026-08-03 20:52:59 +02:00
committed by Maurice
parent 628f4e78cd
commit e25a1276dc
8 changed files with 215 additions and 12 deletions
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { katColor, itemWeight, parseCsvLine, parseImportLines } from './packingListPanel.helpers'
import { katColor, itemWeight, bagFillPct, parseCsvLine, parseImportLines } from './packingListPanel.helpers'
import { KAT_COLORS } from './packingListPanel.constants'
describe('packingListPanel.helpers', () => {
@@ -46,6 +46,27 @@ describe('packingListPanel.helpers', () => {
})
})
describe('bagFillPct', () => {
it('measures against the bag limit when there is one', () => {
expect(bagFillPct(5000, 20000, 99999)).toBe(25)
expect(bagFillPct(20000, 20000, 1)).toBe(100)
})
it('never reports more than full', () => {
expect(bagFillPct(30000, 20000, 1)).toBe(100)
})
it('falls back to the heaviest bag when no limit is set', () => {
expect(bagFillPct(2500, null, 5000)).toBe(50)
expect(bagFillPct(2500, undefined, 5000)).toBe(50)
expect(bagFillPct(0, 0, 5000)).toBe(0)
})
it('does not divide by zero on an empty trip', () => {
expect(bagFillPct(0, null, 0)).toBe(0)
})
})
describe('parseCsvLine', () => {
it('splits on comma, semicolon and tab and trims fields', () => {
expect(parseCsvLine('a, b ;c\td')).toEqual(['a', 'b', 'c', 'd'])