@burdenoff/microfe-healthybowl 2026.813.21 → 2026.813.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ import { capacityModelFor as e } from "../utils/growLocationType.js";
2
+ import { jsx as t, jsxs as n } from "react/jsx-runtime";
3
+ //#region src/healthybowl/components/GrowGeometryInputs.tsx
4
+ var r = [
5
+ {
6
+ key: "benchCount",
7
+ labelKey: "healthybowl.growGeometry.benchCount",
8
+ labelDefault: "Number of benches",
9
+ integer: !0
10
+ },
11
+ {
12
+ key: "benchLengthM",
13
+ labelKey: "healthybowl.growGeometry.benchLengthM",
14
+ labelDefault: "Bench length (m)"
15
+ },
16
+ {
17
+ key: "benchWidthM",
18
+ labelKey: "healthybowl.growGeometry.benchWidthM",
19
+ labelDefault: "Bench width (m)"
20
+ },
21
+ {
22
+ key: "aisleWidthM",
23
+ labelKey: "healthybowl.growGeometry.aisleWidthM",
24
+ labelDefault: "Aisle width (m)"
25
+ }
26
+ ], i = [{
27
+ key: "treeSpacingM",
28
+ labelKey: "healthybowl.growGeometry.treeSpacingM",
29
+ labelDefault: "Tree spacing (m)"
30
+ }, {
31
+ key: "rowWidthM",
32
+ labelKey: "healthybowl.growGeometry.rowWidthM",
33
+ labelDefault: "Row width (m)"
34
+ }], a = [
35
+ {
36
+ key: "rackCount",
37
+ labelKey: "healthybowl.growGeometry.rackCount",
38
+ labelDefault: "Number of racks",
39
+ integer: !0
40
+ },
41
+ {
42
+ key: "tiers",
43
+ labelKey: "healthybowl.growGeometry.tiers",
44
+ labelDefault: "Tiers per rack",
45
+ integer: !0
46
+ },
47
+ {
48
+ key: "trayLengthM",
49
+ labelKey: "healthybowl.growGeometry.trayLengthM",
50
+ labelDefault: "Tray length (m)"
51
+ },
52
+ {
53
+ key: "trayWidthM",
54
+ labelKey: "healthybowl.growGeometry.trayWidthM",
55
+ labelDefault: "Tray width (m)"
56
+ }
57
+ ], o = (t) => {
58
+ switch (e(t)) {
59
+ case "BENCH": return r;
60
+ case "TREE": return i;
61
+ case "RACK": return a;
62
+ default: return [];
63
+ }
64
+ }, s = (e, t) => {
65
+ let n = o(e);
66
+ if (n.length === 0) return null;
67
+ let r = {}, i = !1;
68
+ for (let e of n) {
69
+ let n = t[e.key];
70
+ typeof n == "number" && Number.isFinite(n) && n > 0 && (r[e.key] = n, i = !0);
71
+ }
72
+ return i ? r : null;
73
+ }, c = ({ type: r, value: i, onChange: a, t: s, testIdPrefix: c = "grow-geometry" }) => {
74
+ let l = o(r);
75
+ return l.length === 0 ? null : /* @__PURE__ */ t("div", {
76
+ className: "grid grid-cols-2 gap-3",
77
+ "data-testid": c,
78
+ "data-capacity-model": e(r),
79
+ children: l.map((e) => /* @__PURE__ */ n("div", {
80
+ className: "space-y-1",
81
+ children: [/* @__PURE__ */ t("label", {
82
+ htmlFor: `${c}-${e.key}`,
83
+ className: "text-xs font-medium text-text-secondary",
84
+ children: s(e.labelKey, e.labelDefault)
85
+ }), /* @__PURE__ */ t("input", {
86
+ id: `${c}-${e.key}`,
87
+ "data-testid": `${c}-${e.key}`,
88
+ type: "number",
89
+ min: e.integer ? 1 : .1,
90
+ step: e.integer ? 1 : .1,
91
+ className: "w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]",
92
+ value: i[e.key] ?? "",
93
+ onChange: (t) => {
94
+ let n = t.target.value, r = { ...i };
95
+ if (n === "") delete r[e.key];
96
+ else {
97
+ let t = Number(n);
98
+ Number.isFinite(t) && (r[e.key] = e.integer ? Math.floor(t) : t);
99
+ }
100
+ a(r);
101
+ }
102
+ })]
103
+ }, e.key))
104
+ });
105
+ };
106
+ //#endregion
107
+ export { c as GrowGeometryInputs, s as geometryForType };
108
+
109
+ //# sourceMappingURL=GrowGeometryInputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GrowGeometryInputs.js","names":[],"sources":["../../../src/healthybowl/components/GrowGeometryInputs.tsx"],"sourcesContent":["/**\n * Per-type growing-geometry inputs for a field (BOFF-6040).\n *\n * BOFF-5977 let a farmer say \"this is a greenhouse\" and then had nothing to ask next,\n * so the planting estimates simply stopped. These are the missing questions: the\n * dimensions each grow-location type is actually described by, swapped by type so a\n * grower is never asked for a bench width for an open field.\n *\n * ## Why one component instead of three inline blocks\n *\n * Three separate forms create or edit a field (`CropFieldsPage`, `FieldDetailsPage`,\n * `FieldMapPage`), and all three feed the same `Field.growGeometry` JSON column. Split\n * across three files these would drift — one would gain a field the others lack, and a\n * greenhouse created on the map would silently estimate differently from one created in\n * the list. The shapes must agree exactly, so they live once.\n *\n * ## The shape is not free-form\n *\n * `estimateGrowCapacity` reads specific keys, and the service's `normalizeGrowGeometry`\n * drops anything it does not recognise per type. So the key names here are a contract\n * with both sides, not a local choice — see `plantingCapacity.ts` and the provider's\n * `KEYS_BY_TYPE`.\n *\n * @module healthybowl\n */\nimport type { GrowGeometry } from '../utils/plantingCapacity';\nimport { capacityModelFor, type TranslateFn } from '../utils/growLocationType';\n\nimport type React from 'react';\n\n/** One numeric input: which key it writes, its label, and its unit suffix. */\ninterface GeometryFieldSpec {\n key: keyof GrowGeometry;\n labelKey: string;\n labelDefault: string;\n /** Whole benches/racks/tiers cannot be fractional; metre dimensions can. */\n integer?: boolean;\n}\n\nconst BENCH_FIELDS: readonly GeometryFieldSpec[] = [\n {\n key: 'benchCount',\n labelKey: 'healthybowl.growGeometry.benchCount',\n labelDefault: 'Number of benches',\n integer: true,\n },\n { key: 'benchLengthM', labelKey: 'healthybowl.growGeometry.benchLengthM', labelDefault: 'Bench length (m)' },\n { key: 'benchWidthM', labelKey: 'healthybowl.growGeometry.benchWidthM', labelDefault: 'Bench width (m)' },\n // Aisle width is collected but never multiplied in: it describes the space BETWEEN\n // benches, which is exactly the part that is not plantable. It is here because a\n // farmer laying out a house needs to record it, and because the next thing anyone\n // will want is a footprint check against `Field.area`.\n { key: 'aisleWidthM', labelKey: 'healthybowl.growGeometry.aisleWidthM', labelDefault: 'Aisle width (m)' },\n];\n\nconst TREE_FIELDS: readonly GeometryFieldSpec[] = [\n { key: 'treeSpacingM', labelKey: 'healthybowl.growGeometry.treeSpacingM', labelDefault: 'Tree spacing (m)' },\n { key: 'rowWidthM', labelKey: 'healthybowl.growGeometry.rowWidthM', labelDefault: 'Row width (m)' },\n];\n\nconst RACK_FIELDS: readonly GeometryFieldSpec[] = [\n { key: 'rackCount', labelKey: 'healthybowl.growGeometry.rackCount', labelDefault: 'Number of racks', integer: true },\n { key: 'tiers', labelKey: 'healthybowl.growGeometry.tiers', labelDefault: 'Tiers per rack', integer: true },\n { key: 'trayLengthM', labelKey: 'healthybowl.growGeometry.trayLengthM', labelDefault: 'Tray length (m)' },\n { key: 'trayWidthM', labelKey: 'healthybowl.growGeometry.trayWidthM', labelDefault: 'Tray width (m)' },\n];\n\n/** The inputs a type asks for, or none for BED/PASTURE. */\nexport const geometryFieldsFor = (type: unknown): readonly GeometryFieldSpec[] => {\n switch (capacityModelFor(type)) {\n case 'BENCH':\n return BENCH_FIELDS;\n case 'TREE':\n return TREE_FIELDS;\n case 'RACK':\n return RACK_FIELDS;\n default:\n return [];\n }\n};\n\n/**\n * Strip a geometry down to the keys the given type actually uses.\n *\n * Called before save so that switching a field from greenhouse to orchard does not\n * post orphaned bench dimensions. The service drops them anyway, but sending them\n * would make the optimistic UI and the reloaded row disagree for one render.\n */\nexport const geometryForType = (type: unknown, geometry: GrowGeometry): GrowGeometry | null => {\n const specs = geometryFieldsFor(type);\n if (specs.length === 0) return null;\n const out: GrowGeometry = {};\n let any = false;\n for (const spec of specs) {\n const value = geometry[spec.key];\n if (typeof value === 'number' && Number.isFinite(value) && value > 0) {\n out[spec.key] = value;\n any = true;\n }\n }\n // All-blank is `null`, not `{}` — an empty object reads as \"geometry recorded, and\n // it is empty\", which would make the capacity panel show a prompt forever with no\n // way to tell it apart from never having been asked.\n return any ? out : null;\n};\n\ninterface GrowGeometryInputsProps {\n type: unknown;\n value: GrowGeometry;\n onChange: (next: GrowGeometry) => void;\n t: TranslateFn;\n /** Prefix for `data-testid`, so three forms on three pages stay addressable. */\n testIdPrefix?: string;\n}\n\nexport const GrowGeometryInputs = ({\n type,\n value,\n onChange,\n t,\n testIdPrefix = 'grow-geometry',\n}: GrowGeometryInputsProps) => {\n const specs = geometryFieldsFor(type);\n if (specs.length === 0) return null;\n\n return (\n <div className=\"grid grid-cols-2 gap-3\" data-testid={testIdPrefix} data-capacity-model={capacityModelFor(type)}>\n {specs.map((spec) => (\n <div key={spec.key} className=\"space-y-1\">\n <label htmlFor={`${testIdPrefix}-${spec.key}`} className=\"text-xs font-medium text-text-secondary\">\n {t(spec.labelKey, spec.labelDefault)}\n </label>\n <input\n id={`${testIdPrefix}-${spec.key}`}\n data-testid={`${testIdPrefix}-${spec.key}`}\n type=\"number\"\n min={spec.integer ? 1 : 0.1}\n step={spec.integer ? 1 : 0.1}\n className=\"w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]\"\n value={value[spec.key] ?? ''}\n onChange={(event: React.ChangeEvent<HTMLInputElement>) => {\n const raw = event.target.value;\n // An empty box clears the key rather than writing 0. Zero is a real number\n // the service would reject, and it would also read as \"recorded\" here.\n const next = { ...value };\n if (raw === '') delete next[spec.key];\n else {\n const parsed = Number(raw);\n if (Number.isFinite(parsed)) next[spec.key] = spec.integer ? Math.floor(parsed) : parsed;\n }\n onChange(next);\n }}\n />\n </div>\n ))}\n </div>\n );\n};\n"],"mappings":";;;AAuCA,IAAM,IAA6C;CACjD;EACE,KAAK;EACL,UAAU;EACV,cAAc;EACd,SAAS;EACV;CACD;EAAE,KAAK;EAAgB,UAAU;EAAyC,cAAc;EAAoB;CAC5G;EAAE,KAAK;EAAe,UAAU;EAAwC,cAAc;EAAmB;CAKzG;EAAE,KAAK;EAAe,UAAU;EAAwC,cAAc;EA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