mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-06 22:21:29 +02:00
With "Group similar" enabled, the collapsed group row showed a single member's values — a group of five 1 kg spools displayed 1000 g instead of 5 kg (#1368). The group header now aggregates across all members: the table view's Label / Net / Gross / Used / Remaining columns and the grid card's weight figure show group totals. Identity columns (Material, Brand, Colour) and the Cost/kg rate stay per-spool-correct since they are the group key; per-spool-only fields with no meaningful total (dates, location, note, tag ID) keep the representative member's value. The expanded per-spool rows are unchanged. New aggregateGroupSpool helper with 4 unit tests; the table group component's header prop is renamed representative -> headerSpool. Frontend-only — all data was already in the spool list.
25 lines
868 B
TypeScript
25 lines
868 B
TypeScript
import type { InventorySpool } from '../api/client';
|
|
|
|
// Synthesize a spool-shaped object for a group's collapsed header row: the
|
|
// quantity fields (label_weight, weight_used, core_weight) are summed across
|
|
// members so the header shows group totals (#1368), while identity fields are
|
|
// carried from the first member — all members share them, they are the group
|
|
// key. The expanded per-spool rows keep using the real per-member spools.
|
|
export function aggregateGroupSpool(spools: InventorySpool[]): InventorySpool {
|
|
const base = spools[0];
|
|
let labelWeight = 0;
|
|
let weightUsed = 0;
|
|
let coreWeight = 0;
|
|
for (const s of spools) {
|
|
labelWeight += s.label_weight;
|
|
weightUsed += s.weight_used;
|
|
coreWeight += s.core_weight;
|
|
}
|
|
return {
|
|
...base,
|
|
label_weight: labelWeight,
|
|
weight_used: weightUsed,
|
|
core_weight: coreWeight,
|
|
};
|
|
}
|