mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 06:09:57 -05:00
Add CSV/PDF export and a search filter to Inventory
New Export tab with two client-side formats (no new dependencies):
- CSV: the raw items table (RFC-4180 quoting, UTF-8 BOM for Excel), generated
entirely in the browser. The download anchor is attached to the DOM and the
object URL is revoked on the next tick for cross-browser robustness.
- PDF: a printable full-inventory table followed by a group-by summary table,
via the browser's print dialog ("Save as PDF"). The summary's grouping is
chosen in the Export tab.
Search filter: a box on its own line under the inventory selector filters the
active inventory across every column's displayed value (case-insensitive;
whitespace-separated terms are AND-ed). It narrows the whole view — Items
table, Summary aggregation, and Export/PDF — while edits/adds in the table
still operate on the full inventory, so filtering never drops data.
Summary/export grouping:
- The group-by aggregation is extracted into a shared summarize.js (field-role
detection + count-aware totals via units.js + calories), now the single
source of truth for the Summary tab, the PDF summary, and the ration
calculator. findCaloriesKey/findCountKey moved here from RationCalculator
(re-exported for back-compat).
- The Sum selector now offers number and calories fields in addition to
quantity: number/calories are summed as a plain column total, while quantity
stays count-aware and unit-compacted and the dedicated Calories column stays
count-aware.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
cc5afe3fbc
commit
947ee01b25
13 changed files with 835 additions and 102 deletions
|
|
@ -4,6 +4,8 @@ import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
|||
import {Form, Header, Table} from "../Theme";
|
||||
import {InfoPopup, roundDigits, useLocalStorage} from "../Common";
|
||||
import {formatDuration} from "./WaterCalculator";
|
||||
// Field-role detection lives in inventory/summarize.js (single source of truth); re-exported here for back-compat.
|
||||
export {findCaloriesKey, findCountKey} from "../inventory/summarize";
|
||||
|
||||
// Pure calculation functions for the Ration (food storage) estimate.
|
||||
//
|
||||
|
|
@ -46,27 +48,6 @@ export function daysOfFood(total, dailyDemand) {
|
|||
return total / dailyDemand;
|
||||
}
|
||||
|
||||
// The calories field is detected by its dedicated `calories` type (falling back to a field literally keyed
|
||||
// "calories" for inventories created before the type existed).
|
||||
export function findCaloriesKey(fields) {
|
||||
const byType = (fields || []).find(f => f.type === 'calories');
|
||||
if (byType) {
|
||||
return byType.key;
|
||||
}
|
||||
const legacy = (fields || []).find(f => f.key === 'calories' && f.type === 'number');
|
||||
return legacy ? legacy.key : null;
|
||||
}
|
||||
|
||||
// The count multiplier: prefer a number field keyed "count", else the first number field, else none (treat as 1).
|
||||
export function findCountKey(fields) {
|
||||
const count = (fields || []).find(f => f.type === 'number' && f.key === 'count');
|
||||
if (count) {
|
||||
return count.key;
|
||||
}
|
||||
const firstNumber = (fields || []).find(f => f.type === 'number');
|
||||
return firstNumber ? firstNumber.key : null;
|
||||
}
|
||||
|
||||
// Per-person daily calorie needs, by activity level. Adult figures are representative working-age values
|
||||
// (ages 19-60) from the Dietary Guidelines for Americans 2020-2025, Appendix 2, Table A2-2 ("Estimated Calorie
|
||||
// Needs per Day, by Age, Sex, and Physical Activity Level"), corroborated by the Merck Manuals table. The single
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue