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>
2026-06-19 11:00:01 -06:00
|
|
|
import React, {useMemo, useState} from "react";
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
import {Dropdown, Input, Select} from "semantic-ui-react";
|
|
|
|
|
import {Button, Confirm, Header, Icon, Loader, Menu, Modal, Segment} from "../Theme";
|
|
|
|
|
import {PageContainer, useTitle} from "../Common";
|
|
|
|
|
import {collectLocations, useCatalog, useInventories} from "../../hooks/customHooks";
|
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>
2026-06-19 11:00:01 -06:00
|
|
|
import {filterItems, InventoryTable} from "./InventoryTable";
|
2026-06-18 13:56:53 -06:00
|
|
|
import {InventoryItemsMobile} from "./InventoryItemsMobile";
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
import {InventorySummary} from "./InventorySummary";
|
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>
2026-06-19 11:00:01 -06:00
|
|
|
import {InventoryExportPanel} from "./InventoryExportPanel";
|
|
|
|
|
import {InventoryPrint} from "./InventoryPrint";
|
|
|
|
|
import {defaultGroupKey, defaultSumKey} from "./summarize";
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
import {FieldSchemaEditor} from "./FieldSchemaEditor";
|
|
|
|
|
import {CatalogEditor} from "./CatalogEditor";
|
2026-06-18 13:56:53 -06:00
|
|
|
import {Media} from "../../contexts/contexts";
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
|
|
|
|
|
const INVENTORY_TYPES = [
|
|
|
|
|
{key: 'food', value: 'food', text: 'Food Storage'},
|
|
|
|
|
{key: 'fuel', value: 'fuel', text: 'Fuel'},
|
|
|
|
|
{key: 'tool', value: 'tool', text: 'Tools'},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function NewInventoryModal({open, onClose, onCreate}) {
|
|
|
|
|
const [name, setName] = useState('');
|
|
|
|
|
const [type, setType] = useState('food');
|
|
|
|
|
|
|
|
|
|
const create = async () => {
|
|
|
|
|
const inventory = await onCreate(name, type);
|
|
|
|
|
if (inventory) {
|
|
|
|
|
setName('');
|
|
|
|
|
setType('food');
|
|
|
|
|
onClose();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return <Modal open={open} onClose={onClose} closeIcon>
|
|
|
|
|
<Modal.Header>New Inventory</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
|
|
|
|
<Input fluid label='Name' value={name} onChange={e => setName(e.target.value)}
|
|
|
|
|
placeholder='Food Storage' style={{marginBottom: '1em'}}/>
|
|
|
|
|
<div>
|
|
|
|
|
Type:{' '}
|
|
|
|
|
<Select options={INVENTORY_TYPES} value={type} onChange={(e, data) => setType(data.value)}/>
|
|
|
|
|
<p style={{fontSize: '0.85em', opacity: 0.7, marginTop: '0.5em'}}>
|
|
|
|
|
The type seeds a starting set of fields — you can customize them afterward.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
|
|
|
|
<Button onClick={onClose}>Cancel</Button>
|
|
|
|
|
<Button primary onClick={create} disabled={!name.trim()}>Create</Button>
|
|
|
|
|
</Modal.Actions>
|
|
|
|
|
</Modal>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function InventoryRoute() {
|
|
|
|
|
useTitle('Inventory');
|
|
|
|
|
const {inventories, persistInventory, addInventory, removeInventory} = useInventories();
|
|
|
|
|
const {catalog, persistCatalog} = useCatalog();
|
|
|
|
|
const [slug, setSlug] = useState(null);
|
|
|
|
|
|
|
|
|
|
const [tab, setTab] = useState('items');
|
|
|
|
|
const [newOpen, setNewOpen] = useState(false);
|
|
|
|
|
const [catalogOpen, setCatalogOpen] = useState(false);
|
|
|
|
|
const [editFieldsOpen, setEditFieldsOpen] = useState(false);
|
|
|
|
|
const [renaming, setRenaming] = useState(false);
|
|
|
|
|
const [renameValue, setRenameValue] = useState('');
|
|
|
|
|
const [confirmDelete, setConfirmDelete] = useState(false);
|
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>
2026-06-19 11:00:01 -06:00
|
|
|
// Grouping for the PDF export's summary table (chosen in the Export tab, rendered by the always-mounted print
|
|
|
|
|
// view). null until seeded from the current inventory's schema.
|
|
|
|
|
const [exportGroupKey, setExportGroupKey] = useState(null);
|
|
|
|
|
const [exportSumKey, setExportSumKey] = useState(null);
|
|
|
|
|
// Free-text filter applied to the active inventory's items across every column.
|
|
|
|
|
const [search, setSearch] = useState('');
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
|
|
|
|
|
// Default to the first inventory once loaded.
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (slug == null && inventories && inventories.length > 0) {
|
|
|
|
|
setSlug(inventories[0].slug);
|
|
|
|
|
}
|
|
|
|
|
}, [inventories, slug]);
|
|
|
|
|
|
|
|
|
|
const current = inventories?.find(i => i.slug === slug);
|
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>
2026-06-19 11:00:01 -06:00
|
|
|
const fields = useMemo(() => (current ? current.fields : []), [current]);
|
|
|
|
|
const items = useMemo(() => (current ? current.items : []), [current]);
|
|
|
|
|
|
|
|
|
|
// Re-seed the export grouping when the selected inventory (or its schema) changes.
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
setExportGroupKey(defaultGroupKey(fields));
|
|
|
|
|
setExportSumKey(defaultSumKey(fields));
|
|
|
|
|
}, [fields]);
|
|
|
|
|
// Clear the search when switching inventories.
|
|
|
|
|
React.useEffect(() => setSearch(''), [slug]);
|
|
|
|
|
|
|
|
|
|
// The search narrows the whole inventory view (Items display, Summary, Export); edits/adds in InventoryTable
|
|
|
|
|
// still operate on the full `items`, so filtering never drops data.
|
|
|
|
|
const filteredItems = useMemo(() => filterItems(items, fields, search), [items, fields, search]);
|
|
|
|
|
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
// Location suggestions are pooled across every inventory.
|
|
|
|
|
const locations = collectLocations(inventories);
|
|
|
|
|
|
|
|
|
|
const onCreate = async (name, type) => {
|
|
|
|
|
const inventory = await addInventory(name, type);
|
|
|
|
|
if (inventory) {
|
|
|
|
|
setSlug(inventory.slug);
|
|
|
|
|
}
|
|
|
|
|
return inventory;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const doRename = async () => {
|
|
|
|
|
await persistInventory(slug, {name: renameValue});
|
|
|
|
|
setRenaming(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const doDelete = async () => {
|
|
|
|
|
await removeInventory(slug);
|
|
|
|
|
setConfirmDelete(false);
|
|
|
|
|
setSlug(null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (inventories === null) {
|
|
|
|
|
return <PageContainer><Loader active inline='centered'/></PageContainer>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const inventoryOptions = inventories.map(i => ({key: i.slug, value: i.slug, text: i.name}));
|
|
|
|
|
|
|
|
|
|
return <PageContainer>
|
|
|
|
|
<Header as='h1'>Inventory</Header>
|
|
|
|
|
|
|
|
|
|
<Segment>
|
|
|
|
|
<div style={{display: 'flex', gap: '0.5em', alignItems: 'center', flexWrap: 'wrap'}}>
|
|
|
|
|
<Dropdown
|
|
|
|
|
selection
|
|
|
|
|
placeholder='Select an inventory'
|
|
|
|
|
options={inventoryOptions}
|
|
|
|
|
value={slug || ''}
|
|
|
|
|
onChange={(e, data) => setSlug(data.value)}
|
|
|
|
|
style={{minWidth: '14em'}}
|
|
|
|
|
/>
|
|
|
|
|
<Button primary icon onClick={() => setNewOpen(true)} aria-label='New inventory'>
|
|
|
|
|
<Icon name='plus'/>
|
|
|
|
|
</Button>
|
|
|
|
|
<Button icon onClick={() => setCatalogOpen(true)} aria-label='Food catalog'>
|
|
|
|
|
<Icon name='book'/> Catalog
|
|
|
|
|
</Button>
|
|
|
|
|
{current && <>
|
|
|
|
|
<Button icon onClick={() => {
|
|
|
|
|
setRenameValue(current.name);
|
|
|
|
|
setRenaming(true);
|
|
|
|
|
}} aria-label='Rename inventory'><Icon name='edit'/></Button>
|
|
|
|
|
<Button icon onClick={() => setEditFieldsOpen(true)} aria-label='Customize fields'>
|
|
|
|
|
<Icon name='columns'/> Fields
|
|
|
|
|
</Button>
|
|
|
|
|
<Button color='red' icon onClick={() => setConfirmDelete(true)} aria-label='Delete inventory'>
|
|
|
|
|
<Icon name='trash'/>
|
|
|
|
|
</Button>
|
|
|
|
|
</>}
|
|
|
|
|
</div>
|
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>
2026-06-19 11:00:01 -06:00
|
|
|
{current &&
|
|
|
|
|
<Input fluid icon='search' iconPosition='left' placeholder='Search items…' value={search}
|
|
|
|
|
aria-label='Search items' clearable style={{marginTop: '0.75em'}}
|
|
|
|
|
onChange={(e, data) => setSearch(data.value)}/>}
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
</Segment>
|
|
|
|
|
|
|
|
|
|
{current ? <>
|
|
|
|
|
<Menu pointing secondary>
|
|
|
|
|
<Menu.Item name='Items' active={tab === 'items'} onClick={() => setTab('items')}/>
|
|
|
|
|
<Menu.Item name='Summary' active={tab === 'summary'} onClick={() => setTab('summary')}/>
|
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>
2026-06-19 11:00:01 -06:00
|
|
|
<Menu.Item name='Export' active={tab === 'export'} onClick={() => setTab('export')}/>
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
</Menu>
|
|
|
|
|
|
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>
2026-06-19 11:00:01 -06:00
|
|
|
{tab === 'items' && <>
|
|
|
|
|
{/* Portrait mobile: condensed, read-only. Rotate to landscape (tablet+) for the full editor. */}
|
|
|
|
|
<Media at='mobile'>
|
|
|
|
|
<InventoryItemsMobile fields={fields} items={filteredItems}/>
|
|
|
|
|
</Media>
|
|
|
|
|
<Media greaterThanOrEqual='tablet'>
|
|
|
|
|
{/* The table gets the FULL items (so edits/adds don't drop filtered-out rows) plus the search,
|
|
|
|
|
which it applies to its displayed rows only. */}
|
|
|
|
|
<InventoryTable slug={slug} fields={fields} items={items} locations={locations}
|
|
|
|
|
catalog={catalog} search={search}
|
|
|
|
|
onChange={newItems => persistInventory(slug, {items: newItems})}/>
|
|
|
|
|
</Media>
|
|
|
|
|
</>}
|
|
|
|
|
{tab === 'summary' && <InventorySummary fields={fields} items={filteredItems}/>}
|
|
|
|
|
{tab === 'export' &&
|
|
|
|
|
<InventoryExportPanel name={current.name} fields={fields} items={filteredItems}
|
|
|
|
|
groupKey={exportGroupKey} sumKey={exportSumKey}
|
|
|
|
|
onGroupKey={setExportGroupKey} onSumKey={setExportSumKey}/>}
|
|
|
|
|
|
|
|
|
|
{/* Always mounted (hidden on screen) so the browser print dialog has the full table + summary to render. */}
|
|
|
|
|
<InventoryPrint name={current.name} fields={fields} items={filteredItems}
|
|
|
|
|
groupKey={exportGroupKey} sumKey={exportSumKey}/>
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
|
|
|
|
|
<FieldSchemaEditor fields={fields} open={editFieldsOpen}
|
|
|
|
|
onClose={() => setEditFieldsOpen(false)}
|
|
|
|
|
onSave={newFields => persistInventory(slug, {fields: newFields})}/>
|
|
|
|
|
</> : <p>Create an inventory to get started.</p>}
|
|
|
|
|
|
|
|
|
|
<NewInventoryModal open={newOpen} onClose={() => setNewOpen(false)} onCreate={onCreate}/>
|
|
|
|
|
|
|
|
|
|
<CatalogEditor catalog={catalog || []} open={catalogOpen} onClose={() => setCatalogOpen(false)}
|
|
|
|
|
onSave={persistCatalog}/>
|
|
|
|
|
|
|
|
|
|
<Modal open={renaming} onClose={() => setRenaming(false)} closeIcon size='tiny'>
|
|
|
|
|
<Modal.Header>Rename Inventory</Modal.Header>
|
|
|
|
|
<Modal.Content>
|
|
|
|
|
<Input fluid value={renameValue} onChange={e => setRenameValue(e.target.value)}/>
|
|
|
|
|
</Modal.Content>
|
|
|
|
|
<Modal.Actions>
|
|
|
|
|
<Button onClick={() => setRenaming(false)}>Cancel</Button>
|
|
|
|
|
<Button primary onClick={doRename} disabled={!renameValue.trim()}>Save</Button>
|
|
|
|
|
</Modal.Actions>
|
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
|
|
<Confirm
|
|
|
|
|
open={confirmDelete}
|
|
|
|
|
header='Delete Inventory'
|
|
|
|
|
content={`Delete "${current?.name}" and all its items? This cannot be undone.`}
|
|
|
|
|
confirmButton='Delete'
|
|
|
|
|
onCancel={() => setConfirmDelete(false)}
|
|
|
|
|
onConfirm={doDelete}
|
|
|
|
|
/>
|
|
|
|
|
</PageContainer>;
|
|
|
|
|
}
|