inventoryGrouping.ts 868 B

123456789101112131415161718192021222324
  1. import type { InventorySpool } from '../api/client';
  2. // Synthesize a spool-shaped object for a group's collapsed header row: the
  3. // quantity fields (label_weight, weight_used, core_weight) are summed across
  4. // members so the header shows group totals (#1368), while identity fields are
  5. // carried from the first member — all members share them, they are the group
  6. // key. The expanded per-spool rows keep using the real per-member spools.
  7. export function aggregateGroupSpool(spools: InventorySpool[]): InventorySpool {
  8. const base = spools[0];
  9. let labelWeight = 0;
  10. let weightUsed = 0;
  11. let coreWeight = 0;
  12. for (const s of spools) {
  13. labelWeight += s.label_weight;
  14. weightUsed += s.weight_used;
  15. coreWeight += s.core_weight;
  16. }
  17. return {
  18. ...base,
  19. label_weight: labelWeight,
  20. weight_used: weightUsed,
  21. core_weight: coreWeight,
  22. };
  23. }