@burdenoff/microfe-healthybowl 2026.1005.2 → 2026.1007.1
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.
- package/dist/healthybowl/components/BedLayoutGrid.js +128 -115
- package/dist/healthybowl/components/BedLayoutGrid.js.map +1 -1
- package/dist/healthybowl/components/CropPicker.js +37 -0
- package/dist/healthybowl/components/CropPicker.js.map +1 -0
- package/dist/healthybowl/components/DataTable.js +125 -108
- package/dist/healthybowl/components/DataTable.js.map +1 -1
- package/dist/healthybowl/components/FilterBar.js +9 -6
- package/dist/healthybowl/components/FilterBar.js.map +1 -1
- package/dist/healthybowl/components/PlantCatalogPicker.js +32 -0
- package/dist/healthybowl/components/PlantCatalogPicker.js.map +1 -0
- package/dist/healthybowl/components/WorkspaceRecordPicker.js +164 -0
- package/dist/healthybowl/components/WorkspaceRecordPicker.js.map +1 -0
- package/dist/healthybowl/components/index.js +3 -1
- package/dist/healthybowl/hooks/useCropPage.js +71 -0
- package/dist/healthybowl/hooks/useCropPage.js.map +1 -0
- package/dist/healthybowl/hooks/usePlantCatalog.js +133 -44
- package/dist/healthybowl/hooks/usePlantCatalog.js.map +1 -1
- package/dist/healthybowl/hooks/usePlantingEstimate.js +6 -6
- package/dist/healthybowl/hooks/usePlantingEstimate.js.map +1 -1
- package/dist/healthybowl/hooks/useWorkspaceRead.js +46 -0
- package/dist/healthybowl/hooks/useWorkspaceRead.js.map +1 -0
- package/dist/healthybowl/pages/analytics/ReportsPage.js +8 -8
- package/dist/healthybowl/pages/catalog/PlantCatalogPage.js +266 -192
- package/dist/healthybowl/pages/catalog/PlantCatalogPage.js.map +1 -1
- package/dist/healthybowl/pages/catalog/WorkspaceBrowseFilters.js +58 -0
- package/dist/healthybowl/pages/catalog/WorkspaceBrowseFilters.js.map +1 -0
- package/dist/healthybowl/pages/catalog/browsePagination.js +24 -0
- package/dist/healthybowl/pages/catalog/browsePagination.js.map +1 -0
- package/dist/healthybowl/pages/compliance/ComplianceDocumentsPage.js +6 -6
- package/dist/healthybowl/pages/crops/CropDetailsPage.js +340 -348
- package/dist/healthybowl/pages/crops/CropDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/CropPlanningPage.js +468 -434
- package/dist/healthybowl/pages/crops/CropPlanningPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/CropsPage.js +633 -542
- package/dist/healthybowl/pages/crops/CropsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js +875 -800
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/PlanningDetailsPage.js +459 -448
- package/dist/healthybowl/pages/crops/PlanningDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/SuccessionCropLabel.js +21 -0
- package/dist/healthybowl/pages/crops/SuccessionCropLabel.js.map +1 -0
- package/dist/healthybowl/pages/crops/planningEdit.js +30 -0
- package/dist/healthybowl/pages/crops/planningEdit.js.map +1 -0
- package/dist/healthybowl/pages/fields/FieldMapPage.js +989 -941
- package/dist/healthybowl/pages/fields/FieldMapPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/GeneralLedgerPage.js +6 -6
- package/dist/healthybowl/pages/financial/InvoiceManagementPage.js +7 -7
- package/dist/healthybowl/pages/financial/InvoiceManagementPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/TransactionsPage.js +541 -541
- package/dist/healthybowl/pages/financial/TransactionsPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/ApplicationTrackingPage.js +10 -10
- package/dist/healthybowl/pages/government-schemes/CommunicationPage.js +207 -207
- package/dist/healthybowl/pages/government-schemes/CommunicationPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/SchemeAdminPage.js +38 -38
- package/dist/healthybowl/pages/government-schemes/SchemeAdminPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/TrainingProgramsPage.js +15 -15
- package/dist/healthybowl/pages/government-schemes/TrainingProgramsPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/AnimalRegistryPage.js +4 -4
- package/dist/healthybowl/pages/livestock/BreedingManagementPage.js +4 -4
- package/dist/healthybowl/pages/livestock/FeedManagementPage.js +4 -4
- package/dist/healthybowl/pages/livestock/HealthRecordsPage.js +16 -16
- package/dist/healthybowl/pages/livestock/HealthRecordsPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/ProductionTrackingPage.js +4 -4
- package/dist/healthybowl/pages/livestock/VaccinationSchedulePage.js +4 -4
- package/dist/healthybowl/pages/market/MarketPricesPage.js +305 -305
- package/dist/healthybowl/pages/market/MarketPricesPage.js.map +1 -1
- package/dist/healthybowl/pages/network/CohortsPage.js +107 -107
- package/dist/healthybowl/pages/network/CohortsPage.js.map +1 -1
- package/dist/healthybowl/pages/network/CommunityPage.js +247 -247
- package/dist/healthybowl/pages/network/CommunityPage.js.map +1 -1
- package/dist/healthybowl/pages/network/EventsPage.js +16 -16
- package/dist/healthybowl/pages/network/EventsPage.js.map +1 -1
- package/dist/healthybowl/pages/network/ExpertsPage.js +470 -470
- package/dist/healthybowl/pages/network/ExpertsPage.js.map +1 -1
- package/dist/healthybowl/pages/network/MentorsPage.js +6 -6
- package/dist/healthybowl/pages/pest-management/PestIssuesPage.js +8 -8
- package/dist/healthybowl/pages/pest-management/TreatmentLibraryPage.js +7 -7
- package/dist/healthybowl/pages/pest-management/TreatmentLibraryPage.js.map +1 -1
- package/dist/healthybowl/pages/production/ProductionBatchesPage.js +7 -7
- package/dist/healthybowl/pages/production/RecipeManagementPage.js +5 -5
- package/dist/healthybowl/pages/production/ValueAddedProductsPage.js +7 -7
- package/dist/healthybowl/pages/soil/SoilTestsPage.js +6 -6
- package/dist/healthybowl/pages/soil/SoilTestsPage.js.map +1 -1
- package/dist/healthybowl/pages/suppliers/SuppliersPage.js +10 -10
- package/dist/healthybowl/pages/sustainability/CarbonCreditLedgerPage.js +6 -6
- package/dist/healthybowl/pages/terrace/PlantingFormModal.js +151 -131
- package/dist/healthybowl/pages/terrace/PlantingFormModal.js.map +1 -1
- package/dist/healthybowl/pages/traceability/BatchTrackingPage.js +6 -6
- package/dist/healthybowl/utils/cropComparison.js +1 -1
- package/dist/healthybowl/utils/cropComparison.js.map +1 -1
- package/dist/healthybowl/utils/cropPicker.js +35 -0
- package/dist/healthybowl/utils/cropPicker.js.map +1 -0
- package/dist/healthybowl/utils/plantingCapacity.js +2 -2
- package/dist/healthybowl/utils/plantingCapacity.js.map +1 -1
- package/dist/healthybowl/utils/seedRate.js +1 -8
- package/dist/healthybowl/utils/seedRate.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,156 +1,173 @@
|
|
|
1
1
|
import { cn as e } from "../utils/helpers.js";
|
|
2
|
-
import { useCallback as t,
|
|
3
|
-
import { ChevronDown as
|
|
4
|
-
import { jsx as
|
|
5
|
-
import { ResponsiveTable as d } from "@burdenoff/fe-libs/ui";
|
|
2
|
+
import { useCallback as t, useEffect as n, useMemo as r, useState as i } from "react";
|
|
3
|
+
import { ChevronDown as a, ChevronUp as o, ChevronsUpDown as s } from "lucide-react";
|
|
4
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
5
|
+
import { Pagination as u, ResponsiveTable as d } from "@burdenoff/fe-libs/ui";
|
|
6
6
|
//#region src/healthybowl/components/DataTable.tsx
|
|
7
7
|
var f = new Set(["actions", "action"]), p = new Set([
|
|
8
8
|
"expand",
|
|
9
9
|
"select",
|
|
10
10
|
"selection"
|
|
11
11
|
]), m = new Set([...f, ...p]);
|
|
12
|
-
function h(
|
|
13
|
-
let
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
function h(e, t, n) {
|
|
13
|
+
let r = Number.isFinite(t) && t > 0 ? Math.max(1, Math.floor(t)) : 10, i = Math.max(1, Math.ceil(e / r)), a = Math.max(0, Math.min(i - 1, Math.floor(n)));
|
|
14
|
+
return {
|
|
15
|
+
limit: r,
|
|
16
|
+
page: a,
|
|
17
|
+
totalPages: i,
|
|
18
|
+
offset: a * r
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function g(e, t) {
|
|
22
|
+
return Reflect.get(e, t);
|
|
23
|
+
}
|
|
24
|
+
function _({ columns: _, data: v, keyField: y, onRowClick: b, emptyMessage: x = "No data available", className: S, pageSize: C = 10, pagination: w, paginationResetKey: T, selectable: E = !1, selectedKeys: D, onSelectionChange: O }) {
|
|
25
|
+
let [k, A] = i(null), [j, M] = i(null), [N, P] = i({
|
|
26
|
+
page: 0,
|
|
27
|
+
resetKey: T
|
|
28
|
+
}), F = t((e) => P({
|
|
29
|
+
page: e,
|
|
30
|
+
resetKey: T
|
|
31
|
+
}), [T]), I = t((e) => {
|
|
32
|
+
k === e ? j === "asc" ? M("desc") : j === "desc" ? (A(null), M(null)) : M("asc") : (A(e), M("asc")), F(0);
|
|
33
|
+
}, [
|
|
34
|
+
k,
|
|
35
|
+
j,
|
|
36
|
+
F
|
|
37
|
+
]), L = r(() => !k || !j ? v : [...v].sort((e, t) => {
|
|
38
|
+
let n = g(e, k), r = g(t, k);
|
|
17
39
|
if (n == null && r == null) return 0;
|
|
18
40
|
if (n == null) return 1;
|
|
19
41
|
if (r == null) return -1;
|
|
20
42
|
let i = typeof n == "number" && typeof r == "number" ? n - r : String(n).localeCompare(String(r));
|
|
21
|
-
return
|
|
43
|
+
return j === "asc" ? i : -i;
|
|
22
44
|
}), [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
]),
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
v,
|
|
46
|
+
k,
|
|
47
|
+
j
|
|
48
|
+
]), R = h(L.length, C, N.resetKey === T ? N.page : 0), z = w !== void 0, B = R.page;
|
|
49
|
+
n(() => {
|
|
50
|
+
z || P((e) => e.page === B && e.resetKey === T ? e : {
|
|
51
|
+
page: B,
|
|
52
|
+
resetKey: T
|
|
53
|
+
});
|
|
30
54
|
}, [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
n.has(t) ? n.delete(t) : n.add(t), w(n);
|
|
55
|
+
z,
|
|
56
|
+
B,
|
|
57
|
+
T
|
|
58
|
+
]);
|
|
59
|
+
let V = w?.limit ?? R.limit, H = w?.offset ?? R.offset, U = w?.total ?? L.length, W = w ? L : L.slice(H, H + V), G = t((e) => String(g(e, y)), [y]), K = E && D ? W.length > 0 && W.every((e) => D.has(G(e))) : !1, q = t(() => {
|
|
60
|
+
if (!O || !D) return;
|
|
61
|
+
let e = new Set(D);
|
|
62
|
+
K ? W.forEach((t) => e.delete(G(t))) : W.forEach((t) => e.add(G(t))), O(e);
|
|
40
63
|
}, [
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
64
|
+
K,
|
|
65
|
+
O,
|
|
66
|
+
W,
|
|
67
|
+
G,
|
|
68
|
+
D
|
|
69
|
+
]), J = t((e) => {
|
|
70
|
+
if (!O || !D) return;
|
|
71
|
+
let t = G(e), n = new Set(D);
|
|
72
|
+
n.has(t) ? n.delete(t) : n.add(t), O(n);
|
|
73
|
+
}, [
|
|
74
|
+
O,
|
|
75
|
+
G,
|
|
76
|
+
D
|
|
77
|
+
]), Y = r(() => _.find((e) => !m.has(e.key) && e.header.trim() !== "")?.key, [_]), X = t((e) => e.key === Y ? "primary" : f.has(e.key) ? "secondary" : p.has(e.key) || e.header.trim() === "" ? "hidden-on-mobile" : "secondary", [Y]), Z = r(() => {
|
|
78
|
+
let t = _.map((t) => {
|
|
79
|
+
let n = t.sortable !== !1, r = k === t.key;
|
|
47
80
|
return {
|
|
48
81
|
key: t.key,
|
|
49
|
-
priority:
|
|
82
|
+
priority: X(t),
|
|
50
83
|
headerClassName: t.className,
|
|
51
84
|
cellClassName: t.className,
|
|
52
85
|
mobileLabel: t.header,
|
|
53
|
-
header: /* @__PURE__ */
|
|
86
|
+
header: /* @__PURE__ */ l("button", {
|
|
87
|
+
type: "button",
|
|
88
|
+
disabled: !n,
|
|
89
|
+
"aria-label": n ? `Sort ${t.header}${z ? " on this page" : ""}` : void 0,
|
|
54
90
|
className: e("inline-flex items-center gap-1 text-xs font-medium uppercase tracking-wider text-text-secondary", n && "cursor-pointer select-none hover:text-text-primary"),
|
|
55
|
-
onClick: n ? () =>
|
|
56
|
-
children: [t.header, n && (r ?
|
|
91
|
+
onClick: n ? () => I(t.key) : void 0,
|
|
92
|
+
children: [t.header, n && (r ? c(j === "asc" ? o : a, { className: "h-3 w-3" }) : /* @__PURE__ */ c(s, { className: "h-3 w-3 opacity-30" }))]
|
|
57
93
|
}),
|
|
58
|
-
cell: (e) => t.render ? t.render(e) : String(e
|
|
94
|
+
cell: (e) => t.render ? t.render(e) : String(g(e, t.key) ?? "")
|
|
59
95
|
};
|
|
60
96
|
});
|
|
61
|
-
return
|
|
97
|
+
return E ? [{
|
|
62
98
|
key: "__select__",
|
|
63
99
|
priority: "hidden-on-mobile",
|
|
64
100
|
headerClassName: "w-10",
|
|
65
101
|
cellClassName: "w-10",
|
|
66
|
-
header: /* @__PURE__ */
|
|
102
|
+
header: /* @__PURE__ */ c("input", {
|
|
67
103
|
type: "checkbox",
|
|
68
|
-
checked:
|
|
69
|
-
onChange:
|
|
104
|
+
checked: K,
|
|
105
|
+
onChange: q,
|
|
70
106
|
className: "h-4 w-4 rounded border-border-subtle",
|
|
71
107
|
"aria-label": "Select all rows on this page"
|
|
72
108
|
}),
|
|
73
|
-
cell: (e) => /* @__PURE__ */
|
|
109
|
+
cell: (e) => /* @__PURE__ */ c("span", {
|
|
74
110
|
onClick: (e) => e.stopPropagation(),
|
|
75
|
-
children: /* @__PURE__ */
|
|
111
|
+
children: /* @__PURE__ */ c("input", {
|
|
76
112
|
type: "checkbox",
|
|
77
|
-
checked:
|
|
78
|
-
onChange: () =>
|
|
113
|
+
checked: D?.has(G(e)) ?? !1,
|
|
114
|
+
onChange: () => J(e),
|
|
79
115
|
className: "h-4 w-4 rounded border-border-subtle",
|
|
80
116
|
"aria-label": "Select row"
|
|
81
117
|
})
|
|
82
118
|
})
|
|
83
119
|
}, ...t] : t;
|
|
84
120
|
}, [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
121
|
+
_,
|
|
122
|
+
z,
|
|
123
|
+
X,
|
|
124
|
+
k,
|
|
89
125
|
j,
|
|
90
|
-
S,
|
|
91
126
|
I,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
127
|
+
E,
|
|
128
|
+
K,
|
|
129
|
+
q,
|
|
130
|
+
D,
|
|
131
|
+
G,
|
|
132
|
+
J
|
|
96
133
|
]);
|
|
97
|
-
return
|
|
98
|
-
className: "
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
134
|
+
return /* @__PURE__ */ l("div", {
|
|
135
|
+
className: e("space-y-3", S),
|
|
136
|
+
"aria-busy": w?.loading || void 0,
|
|
137
|
+
children: [
|
|
138
|
+
w && _.some((e) => e.sortable !== !1) && /* @__PURE__ */ c("p", {
|
|
139
|
+
className: "text-xs text-text-secondary",
|
|
140
|
+
children: "Sorting applies to this page only."
|
|
141
|
+
}),
|
|
142
|
+
W.length === 0 ? /* @__PURE__ */ c("div", {
|
|
143
|
+
className: "flex items-center justify-center rounded-xl border border-border-seam bg-gloss-card p-12",
|
|
144
|
+
children: /* @__PURE__ */ c("p", {
|
|
145
|
+
className: "text-sm text-text-secondary",
|
|
146
|
+
children: w?.loading ? "Loading rows…" : x
|
|
147
|
+
})
|
|
148
|
+
}) : /* @__PURE__ */ c("div", {
|
|
149
|
+
className: "overflow-hidden rounded-xl border border-border-seam bg-gloss-card shadow-pop",
|
|
150
|
+
children: /* @__PURE__ */ c(d, {
|
|
151
|
+
columns: Z,
|
|
152
|
+
data: W,
|
|
153
|
+
rowKey: G,
|
|
154
|
+
onRowClick: b
|
|
155
|
+
})
|
|
156
|
+
}),
|
|
157
|
+
(w || U > V) && /* @__PURE__ */ c(u, {
|
|
158
|
+
page: Math.floor(H / V) + 1,
|
|
159
|
+
pageSize: V,
|
|
160
|
+
totalItems: H < U || U === 0 ? U : void 0,
|
|
161
|
+
totalPages: Math.max(1, Math.ceil(U / V)),
|
|
162
|
+
hasPreviousPage: H > 0,
|
|
163
|
+
hasNextPage: H + V < U,
|
|
164
|
+
loading: w?.loading,
|
|
165
|
+
onPageChange: (e) => w ? w.onOffsetChange(Math.max(0, (e - 1) * V)) : F(e - 1)
|
|
112
166
|
})
|
|
113
|
-
|
|
114
|
-
className: "flex items-center justify-between text-sm",
|
|
115
|
-
children: [/* @__PURE__ */ u("span", {
|
|
116
|
-
className: "text-text-secondary",
|
|
117
|
-
children: [
|
|
118
|
-
"Showing ",
|
|
119
|
-
k * x + 1,
|
|
120
|
-
"-",
|
|
121
|
-
Math.min((k + 1) * x, M.length),
|
|
122
|
-
" of ",
|
|
123
|
-
M.length
|
|
124
|
-
]
|
|
125
|
-
}), /* @__PURE__ */ u("div", {
|
|
126
|
-
className: "flex items-center gap-1",
|
|
127
|
-
children: [
|
|
128
|
-
/* @__PURE__ */ l("button", {
|
|
129
|
-
onClick: () => A((e) => Math.max(0, e - 1)),
|
|
130
|
-
disabled: k === 0,
|
|
131
|
-
className: "rounded-md border border-border-subtle p-1.5 text-text-secondary transition-colors hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-40",
|
|
132
|
-
"aria-label": "Previous page",
|
|
133
|
-
children: /* @__PURE__ */ l(a, { className: "h-4 w-4" })
|
|
134
|
-
}),
|
|
135
|
-
Array.from({ length: N }).map((t, n) => /* @__PURE__ */ l("button", {
|
|
136
|
-
onClick: () => A(n),
|
|
137
|
-
"aria-current": n === k ? "page" : void 0,
|
|
138
|
-
className: e("h-8 w-8 rounded-md text-xs font-medium transition-colors", n === k ? "bg-foreground text-background" : "text-text-secondary hover:bg-bg-sunken"),
|
|
139
|
-
children: n + 1
|
|
140
|
-
}, n)),
|
|
141
|
-
/* @__PURE__ */ l("button", {
|
|
142
|
-
onClick: () => A((e) => Math.min(N - 1, e + 1)),
|
|
143
|
-
disabled: k >= N - 1,
|
|
144
|
-
className: "rounded-md border border-border-subtle p-1.5 text-text-secondary transition-colors hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-40",
|
|
145
|
-
"aria-label": "Next page",
|
|
146
|
-
children: /* @__PURE__ */ l(o, { className: "h-4 w-4" })
|
|
147
|
-
})
|
|
148
|
-
]
|
|
149
|
-
})]
|
|
150
|
-
})]
|
|
167
|
+
]
|
|
151
168
|
});
|
|
152
169
|
}
|
|
153
170
|
//#endregion
|
|
154
|
-
export {
|
|
171
|
+
export { _ as DataTable };
|
|
155
172
|
|
|
156
173
|
//# sourceMappingURL=DataTable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTable.js","names":[],"sources":["../../../src/healthybowl/components/DataTable.tsx"],"sourcesContent":["import { useState, useMemo, useCallback, type ReactNode } from 'react';\nimport { ChevronUp, ChevronDown, ChevronsUpDown, ChevronLeft, ChevronRight } from 'lucide-react';\nimport { ResponsiveTable, type ResponsiveTableColumn, type ResponsiveTableColumnPriority } from '@burdenoff/fe-libs/ui';\nimport { cn } from '../utils/helpers';\n\nexport interface Column<T> {\n key: string;\n header: string;\n render?: (item: T) => ReactNode;\n className?: string;\n sortable?: boolean;\n}\n\ntype SortDirection = 'asc' | 'desc' | null;\n\ninterface DataTableProps<T> {\n columns: Column<T>[];\n data: T[];\n keyField: string;\n onRowClick?: (item: T) => void;\n emptyMessage?: string;\n className?: string;\n pageSize?: number;\n selectable?: boolean;\n selectedKeys?: Set<string>;\n onSelectionChange?: (keys: Set<string>) => void;\n}\n\n/** Row-action columns (edit / delete / adjust). Shown on the desktop table AND\n * kept on the mobile card (as a secondary field) so row operations stay\n * reachable below 767px — the old horizontally-scrollable table exposed them. */\nconst ACTION_COLUMN_KEYS = new Set(['actions', 'action']);\n/** Pure-control columns (row-select / expand) — dropped from the mobile card. */\nconst CONTROL_COLUMN_KEYS = new Set(['expand', 'select', 'selection']);\n/** All non-content keys, used only to skip them when picking the card heading. */\nconst UTIL_COLUMN_KEYS = new Set([...ACTION_COLUMN_KEYS, ...CONTROL_COLUMN_KEYS]);\n\n/**\n * Tabular list wrapping the Boff `ResponsiveTable` (real <table> at md+, a stack\n * of cards below 767px). The bespoke client-side sorting, pagination and row\n * selection are retained here because the primitive does not provide them — only\n * the current page slice is handed to `ResponsiveTable`. The public prop +\n * `Column` API is unchanged so existing call sites compile as-is.\n */\nexport function DataTable<T extends object>({\n columns,\n data,\n keyField,\n onRowClick,\n emptyMessage = 'No data available',\n className,\n pageSize = 10,\n selectable = false,\n selectedKeys,\n onSelectionChange,\n}: DataTableProps<T>) {\n const [sortKey, setSortKey] = useState<string | null>(null);\n const [sortDir, setSortDir] = useState<SortDirection>(null);\n const [page, setPage] = useState(0);\n\n const handleSort = useCallback(\n (key: string) => {\n if (sortKey === key) {\n if (sortDir === 'asc') setSortDir('desc');\n else if (sortDir === 'desc') {\n setSortKey(null);\n setSortDir(null);\n } else setSortDir('asc');\n } else {\n setSortKey(key);\n setSortDir('asc');\n }\n setPage(0);\n },\n [sortKey, sortDir]\n );\n\n const sorted = useMemo(() => {\n if (!sortKey || !sortDir) return data;\n return [...data].sort((a, b) => {\n const av = (a as Record<string, unknown>)[sortKey];\n const bv = (b as Record<string, unknown>)[sortKey];\n if (av == null && bv == null) return 0;\n if (av == null) return 1;\n if (bv == null) return -1;\n const cmp = typeof av === 'number' && typeof bv === 'number' ? av - bv : String(av).localeCompare(String(bv));\n return sortDir === 'asc' ? cmp : -cmp;\n });\n }, [data, sortKey, sortDir]);\n\n const totalPages = Math.max(1, Math.ceil(sorted.length / pageSize));\n const paged = sorted.slice(page * pageSize, (page + 1) * pageSize);\n\n const rowKeyFor = useCallback((item: T) => String((item as Record<string, unknown>)[keyField]), [keyField]);\n\n const allPageKeysSelected =\n selectable && selectedKeys ? paged.length > 0 && paged.every((item) => selectedKeys.has(rowKeyFor(item))) : false;\n\n const handleSelectAll = useCallback(() => {\n if (!onSelectionChange || !selectedKeys) return;\n const keys = new Set(selectedKeys);\n if (allPageKeysSelected) {\n paged.forEach((item) => keys.delete(rowKeyFor(item)));\n } else {\n paged.forEach((item) => keys.add(rowKeyFor(item)));\n }\n onSelectionChange(keys);\n }, [allPageKeysSelected, onSelectionChange, paged, rowKeyFor, selectedKeys]);\n\n const handleSelectRow = useCallback(\n (item: T) => {\n if (!onSelectionChange || !selectedKeys) return;\n const key = rowKeyFor(item);\n const keys = new Set(selectedKeys);\n if (keys.has(key)) keys.delete(key);\n else keys.add(key);\n onSelectionChange(keys);\n },\n [onSelectionChange, rowKeyFor, selectedKeys]\n );\n\n // Derive a mobile-card priority for each column: the first content column is\n // the card heading; util columns (actions/expand/select) are hidden on mobile;\n // everything else is a labelled secondary field. Desktop renders every column\n // regardless, so this never changes the md+ table.\n const firstContentKey = useMemo(() => {\n const content = columns.find((c) => !UTIL_COLUMN_KEYS.has(c.key) && c.header.trim() !== '');\n return content?.key;\n }, [columns]);\n\n const priorityFor = useCallback(\n (col: Column<T>): ResponsiveTableColumnPriority => {\n if (col.key === firstContentKey) return 'primary';\n // Edit/delete actions stay on the mobile card so rows remain operable.\n if (ACTION_COLUMN_KEYS.has(col.key)) return 'secondary';\n // Pure controls + unlabelled columns drop off the mobile card.\n if (CONTROL_COLUMN_KEYS.has(col.key) || col.header.trim() === '') return 'hidden-on-mobile';\n return 'secondary';\n },\n [firstContentKey]\n );\n\n const responsiveColumns = useMemo<ResponsiveTableColumn<T>[]>(() => {\n const mapped = columns.map((col): ResponsiveTableColumn<T> => {\n const isSortable = col.sortable !== false;\n const isActive = sortKey === col.key;\n return {\n key: col.key,\n priority: priorityFor(col),\n headerClassName: col.className,\n cellClassName: col.className,\n mobileLabel: col.header,\n header: (\n <span\n className={cn(\n 'inline-flex items-center gap-1 text-xs font-medium uppercase tracking-wider text-text-secondary',\n isSortable && 'cursor-pointer select-none hover:text-text-primary'\n )}\n onClick={isSortable ? () => handleSort(col.key) : undefined}\n >\n {col.header}\n {isSortable &&\n (isActive ? (\n sortDir === 'asc' ? (\n <ChevronUp className=\"h-3 w-3\" />\n ) : (\n <ChevronDown className=\"h-3 w-3\" />\n )\n ) : (\n <ChevronsUpDown className=\"h-3 w-3 opacity-30\" />\n ))}\n </span>\n ),\n cell: (item: T) => (col.render ? col.render(item) : String((item as Record<string, unknown>)[col.key] ?? '')),\n };\n });\n\n if (!selectable) return mapped;\n\n const selectColumn: ResponsiveTableColumn<T> = {\n key: '__select__',\n priority: 'hidden-on-mobile',\n headerClassName: 'w-10',\n cellClassName: 'w-10',\n header: (\n <input\n type=\"checkbox\"\n checked={allPageKeysSelected}\n onChange={handleSelectAll}\n className=\"h-4 w-4 rounded border-border-subtle\"\n aria-label=\"Select all rows on this page\"\n />\n ),\n cell: (item: T) => (\n <span onClick={(e) => e.stopPropagation()}>\n <input\n type=\"checkbox\"\n checked={selectedKeys?.has(rowKeyFor(item)) ?? false}\n onChange={() => handleSelectRow(item)}\n className=\"h-4 w-4 rounded border-border-subtle\"\n aria-label=\"Select row\"\n />\n </span>\n ),\n };\n return [selectColumn, ...mapped];\n }, [\n columns,\n priorityFor,\n sortKey,\n sortDir,\n handleSort,\n selectable,\n allPageKeysSelected,\n handleSelectAll,\n selectedKeys,\n rowKeyFor,\n handleSelectRow,\n ]);\n\n if (data.length === 0) {\n return (\n <div className=\"flex items-center justify-center rounded-xl border border-border-seam bg-gloss-card p-12\">\n <p className=\"text-sm text-text-secondary\">{emptyMessage}</p>\n </div>\n );\n }\n\n return (\n <div className={cn('space-y-3', className)}>\n <div className=\"overflow-hidden rounded-xl border border-border-seam bg-gloss-card shadow-pop\">\n <ResponsiveTable<T> columns={responsiveColumns} data={paged} rowKey={rowKeyFor} onRowClick={onRowClick} />\n </div>\n\n {/* Pagination */}\n {sorted.length > pageSize && (\n <div className=\"flex items-center justify-between text-sm\">\n <span className=\"text-text-secondary\">\n Showing {page * pageSize + 1}-{Math.min((page + 1) * pageSize, sorted.length)} of {sorted.length}\n </span>\n <div className=\"flex items-center gap-1\">\n <button\n onClick={() => setPage((p) => Math.max(0, p - 1))}\n disabled={page === 0}\n className=\"rounded-md border border-border-subtle p-1.5 text-text-secondary transition-colors hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-40\"\n aria-label=\"Previous page\"\n >\n <ChevronLeft className=\"h-4 w-4\" />\n </button>\n {Array.from({ length: totalPages }).map((_, i) => (\n <button\n key={i}\n onClick={() => setPage(i)}\n aria-current={i === page ? 'page' : undefined}\n className={cn(\n 'h-8 w-8 rounded-md text-xs font-medium transition-colors',\n i === page ? 'bg-foreground text-background' : 'text-text-secondary hover:bg-bg-sunken'\n )}\n >\n {i + 1}\n </button>\n ))}\n <button\n onClick={() => setPage((p) => Math.min(totalPages - 1, p + 1))}\n disabled={page >= totalPages - 1}\n className=\"rounded-md border border-border-subtle p-1.5 text-text-secondary transition-colors hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-40\"\n aria-label=\"Next page\"\n >\n <ChevronRight className=\"h-4 w-4\" />\n </button>\n </div>\n </div>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;AA+BA,IAAM,IAAqB,IAAI,IAAI,CAAC,WAAW,QAAQ,CAAC,GAElD,IAAsB,IAAI,IAAI;CAAC;CAAU;CAAU;AAAW,CAAC,GAE/D,IAAmB,IAAI,IAAI,CAAC,GAAG,GAAoB,GAAG,CAAmB,CAAC;AAShF,SAAgB,EAA4B,EAC1C,YACA,SACA,aACA,eACA,kBAAe,qBACf,cACA,cAAW,IACX,gBAAa,IACb,iBACA,wBACoB;CACpB,IAAM,CAAC,GAAS,KAAc,EAAwB,IAAI,GACpD,CAAC,GAAS,KAAc,EAAwB,IAAI,GACpD,CAAC,GAAM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C1C,kBAAC,UAAD;MAEE,eAAe,EAAQ,CAAC;MACxB,gBAAc,MAAM,IAAO,SAAS,KAAA;MACpC,WAAW,EACT,4DACA,MAAM,IAAO,kCAAkC,wCACjD;gBAEC,IAAI;KACC,GATD,CASC,CACT;KACD,kBAAC,UAAD;MACE,eAAe,GAAS,MAAM,KAAK,IAAI,IAAa,GAAG,IAAI,CAAC,CAAC;MAC7D,UAAU,KAAQ,IAAa;MAC/B,WAAU;MACV,cAAW;gBAEX,kBAAC,GAAD,EAAc,WAAU,UAAW,CAAA;KAC7B,CAAA;IACL;KACF;IAEJ;;AAET"}
|
|
1
|
+
{"version":3,"file":"DataTable.js","names":[],"sources":["../../../src/healthybowl/components/DataTable.tsx"],"sourcesContent":["import { useState, useMemo, useCallback, useEffect, type ReactNode } from 'react';\nimport { ChevronUp, ChevronDown, ChevronsUpDown } from 'lucide-react';\nimport {\n Pagination,\n ResponsiveTable,\n type ResponsiveTableColumn,\n type ResponsiveTableColumnPriority,\n} from '@burdenoff/fe-libs/ui';\nimport { cn } from '../utils/helpers';\n\nexport interface Column<T> {\n key: string;\n header: string;\n render?: (item: T) => ReactNode;\n className?: string;\n sortable?: boolean;\n}\n\ntype SortDirection = 'asc' | 'desc' | null;\n\nexport interface DataTablePagination {\n total: number;\n limit: number;\n offset: number;\n onOffsetChange: (offset: number) => void;\n loading?: boolean;\n}\n\nexport interface DataTableProps<T> {\n columns: Column<T>[];\n data: T[];\n keyField: string;\n onRowClick?: (item: T) => void;\n emptyMessage?: string;\n className?: string;\n pageSize?: number;\n /** Already-paged server data is never sliced a second time. Callers reset offset for changed filters. */\n pagination?: DataTablePagination;\n /** Changing a local search/filter key returns legacy local paging to its first page. */\n paginationResetKey?: string | number;\n selectable?: boolean;\n selectedKeys?: Set<string>;\n onSelectionChange?: (keys: Set<string>) => void;\n}\n\n/** Row-action columns (edit / delete / adjust). Shown on the desktop table AND\n * kept on the mobile card (as a secondary field) so row operations stay\n * reachable below 767px — the old horizontally-scrollable table exposed them. */\nconst ACTION_COLUMN_KEYS = new Set(['actions', 'action']);\n/** Pure-control columns (row-select / expand) — dropped from the mobile card. */\nconst CONTROL_COLUMN_KEYS = new Set(['expand', 'select', 'selection']);\n/** All non-content keys, used only to skip them when picking the card heading. */\nconst UTIL_COLUMN_KEYS = new Set([...ACTION_COLUMN_KEYS, ...CONTROL_COLUMN_KEYS]);\n\nexport function localTablePagination(rowCount: number, pageSize: number, requestedPage: number) {\n const limit = Number.isFinite(pageSize) && pageSize > 0 ? Math.max(1, Math.floor(pageSize)) : 10;\n const totalPages = Math.max(1, Math.ceil(rowCount / limit));\n const page = Math.max(0, Math.min(totalPages - 1, Math.floor(requestedPage)));\n return { limit, page, totalPages, offset: page * limit };\n}\n\nfunction columnValue(item: object, key: string): unknown {\n return Reflect.get(item, key);\n}\n\n/**\n * Tabular list wrapping the Boff `ResponsiveTable` (real <table> at md+, a stack\n * of cards below 767px). Legacy sorting, local paging and selection remain;\n * controlled server paging renders exactly the supplied page. Sorting a server\n * page is explicitly page-local rather than a claim about the entire dataset.\n */\nexport function DataTable<T extends object>({\n columns,\n data,\n keyField,\n onRowClick,\n emptyMessage = 'No data available',\n className,\n pageSize = 10,\n pagination,\n paginationResetKey,\n selectable = false,\n selectedKeys,\n onSelectionChange,\n}: DataTableProps<T>) {\n const [sortKey, setSortKey] = useState<string | null>(null);\n const [sortDir, setSortDir] = useState<SortDirection>(null);\n const [pageState, setPageState] = useState({ page: 0, resetKey: paginationResetKey });\n const setPage = useCallback(\n (page: number) => setPageState({ page, resetKey: paginationResetKey }),\n [paginationResetKey]\n );\n\n const handleSort = useCallback(\n (key: string) => {\n if (sortKey === key) {\n if (sortDir === 'asc') setSortDir('desc');\n else if (sortDir === 'desc') {\n setSortKey(null);\n setSortDir(null);\n } else setSortDir('asc');\n } else {\n setSortKey(key);\n setSortDir('asc');\n }\n setPage(0);\n },\n [sortKey, sortDir, setPage]\n );\n\n const sorted = useMemo(() => {\n if (!sortKey || !sortDir) return data;\n return [...data].sort((a, b) => {\n const av = columnValue(a, sortKey);\n const bv = columnValue(b, sortKey);\n if (av == null && bv == null) return 0;\n if (av == null) return 1;\n if (bv == null) return -1;\n const cmp = typeof av === 'number' && typeof bv === 'number' ? av - bv : String(av).localeCompare(String(bv));\n return sortDir === 'asc' ? cmp : -cmp;\n });\n }, [data, sortKey, sortDir]);\n\n const local = localTablePagination(\n sorted.length,\n pageSize,\n pageState.resetKey === paginationResetKey ? pageState.page : 0\n );\n const controlled = pagination !== undefined;\n const localPage = local.page;\n // Clamp immediately for this render, then remember the clamped/reset page so\n // a later data expansion cannot unexpectedly jump back to a now-obsolete page.\n useEffect(() => {\n if (controlled) return;\n setPageState((previous) =>\n previous.page === localPage && previous.resetKey === paginationResetKey\n ? previous\n : { page: localPage, resetKey: paginationResetKey }\n );\n }, [controlled, localPage, paginationResetKey]);\n const limit = pagination?.limit ?? local.limit;\n const offset = pagination?.offset ?? local.offset;\n const total = pagination?.total ?? sorted.length;\n const paged = pagination ? sorted : sorted.slice(offset, offset + limit);\n\n const rowKeyFor = useCallback((item: T) => String(columnValue(item, keyField)), [keyField]);\n\n const allPageKeysSelected =\n selectable && selectedKeys ? paged.length > 0 && paged.every((item) => selectedKeys.has(rowKeyFor(item))) : false;\n\n const handleSelectAll = useCallback(() => {\n if (!onSelectionChange || !selectedKeys) return;\n const keys = new Set(selectedKeys);\n if (allPageKeysSelected) {\n paged.forEach((item) => keys.delete(rowKeyFor(item)));\n } else {\n paged.forEach((item) => keys.add(rowKeyFor(item)));\n }\n onSelectionChange(keys);\n }, [allPageKeysSelected, onSelectionChange, paged, rowKeyFor, selectedKeys]);\n\n const handleSelectRow = useCallback(\n (item: T) => {\n if (!onSelectionChange || !selectedKeys) return;\n const key = rowKeyFor(item);\n const keys = new Set(selectedKeys);\n if (keys.has(key)) keys.delete(key);\n else keys.add(key);\n onSelectionChange(keys);\n },\n [onSelectionChange, rowKeyFor, selectedKeys]\n );\n\n // Derive a mobile-card priority for each column: the first content column is\n // the card heading; util columns (actions/expand/select) are hidden on mobile;\n // everything else is a labelled secondary field. Desktop renders every column\n // regardless, so this never changes the md+ table.\n const firstContentKey = useMemo(() => {\n const content = columns.find((c) => !UTIL_COLUMN_KEYS.has(c.key) && c.header.trim() !== '');\n return content?.key;\n }, [columns]);\n\n const priorityFor = useCallback(\n (col: Column<T>): ResponsiveTableColumnPriority => {\n if (col.key === firstContentKey) return 'primary';\n // Edit/delete actions stay on the mobile card so rows remain operable.\n if (ACTION_COLUMN_KEYS.has(col.key)) return 'secondary';\n // Pure controls + unlabelled columns drop off the mobile card.\n if (CONTROL_COLUMN_KEYS.has(col.key) || col.header.trim() === '') return 'hidden-on-mobile';\n return 'secondary';\n },\n [firstContentKey]\n );\n\n const responsiveColumns = useMemo<ResponsiveTableColumn<T>[]>(() => {\n const mapped = columns.map((col): ResponsiveTableColumn<T> => {\n const isSortable = col.sortable !== false;\n const isActive = sortKey === col.key;\n return {\n key: col.key,\n priority: priorityFor(col),\n headerClassName: col.className,\n cellClassName: col.className,\n mobileLabel: col.header,\n header: (\n <button\n type=\"button\"\n disabled={!isSortable}\n aria-label={isSortable ? `Sort ${col.header}${controlled ? ' on this page' : ''}` : undefined}\n className={cn(\n 'inline-flex items-center gap-1 text-xs font-medium uppercase tracking-wider text-text-secondary',\n isSortable && 'cursor-pointer select-none hover:text-text-primary'\n )}\n onClick={isSortable ? () => handleSort(col.key) : undefined}\n >\n {col.header}\n {isSortable &&\n (isActive ? (\n sortDir === 'asc' ? (\n <ChevronUp className=\"h-3 w-3\" />\n ) : (\n <ChevronDown className=\"h-3 w-3\" />\n )\n ) : (\n <ChevronsUpDown className=\"h-3 w-3 opacity-30\" />\n ))}\n </button>\n ),\n cell: (item: T) => (col.render ? col.render(item) : String(columnValue(item, col.key) ?? '')),\n };\n });\n\n if (!selectable) return mapped;\n\n const selectColumn: ResponsiveTableColumn<T> = {\n key: '__select__',\n priority: 'hidden-on-mobile',\n headerClassName: 'w-10',\n cellClassName: 'w-10',\n header: (\n <input\n type=\"checkbox\"\n checked={allPageKeysSelected}\n onChange={handleSelectAll}\n className=\"h-4 w-4 rounded border-border-subtle\"\n aria-label=\"Select all rows on this page\"\n />\n ),\n cell: (item: T) => (\n <span onClick={(e) => e.stopPropagation()}>\n <input\n type=\"checkbox\"\n checked={selectedKeys?.has(rowKeyFor(item)) ?? false}\n onChange={() => handleSelectRow(item)}\n className=\"h-4 w-4 rounded border-border-subtle\"\n aria-label=\"Select row\"\n />\n </span>\n ),\n };\n return [selectColumn, ...mapped];\n }, [\n columns,\n controlled,\n priorityFor,\n sortKey,\n sortDir,\n handleSort,\n selectable,\n allPageKeysSelected,\n handleSelectAll,\n selectedKeys,\n rowKeyFor,\n handleSelectRow,\n ]);\n\n return (\n <div className={cn('space-y-3', className)} aria-busy={pagination?.loading || undefined}>\n {pagination && columns.some((column) => column.sortable !== false) && (\n <p className=\"text-xs text-text-secondary\">Sorting applies to this page only.</p>\n )}\n {paged.length === 0 ? (\n <div className=\"flex items-center justify-center rounded-xl border border-border-seam bg-gloss-card p-12\">\n <p className=\"text-sm text-text-secondary\">{pagination?.loading ? 'Loading rows…' : emptyMessage}</p>\n </div>\n ) : (\n <div className=\"overflow-hidden rounded-xl border border-border-seam bg-gloss-card shadow-pop\">\n <ResponsiveTable<T> columns={responsiveColumns} data={paged} rowKey={rowKeyFor} onRowClick={onRowClick} />\n </div>\n )}\n {(pagination || total > limit) && (\n <Pagination\n page={Math.floor(offset / limit) + 1}\n pageSize={limit}\n totalItems={offset < total || total === 0 ? total : undefined}\n totalPages={Math.max(1, Math.ceil(total / limit))}\n hasPreviousPage={offset > 0}\n hasNextPage={offset + limit < total}\n loading={pagination?.loading}\n onPageChange={(page) =>\n pagination ? pagination.onOffsetChange(Math.max(0, (page - 1) * limit)) : setPage(page - 1)\n }\n />\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;AAgDA,IAAM,IAAqB,IAAI,IAAI,CAAC,WAAW,QAAQ,CAAC,GAElD,IA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aAAa,IAAS,IAAQ;IAC9B,SAAS,GAAY;IACrB,eAAe,MACb,IAAa,EAAW,eAAe,KAAK,IAAI,IAAI,IAAO,KAAK,CAAK,CAAC,IAAI,EAAQ,IAAO,CAAC;GAE7F,CAAA;EAEA;;AAET"}
|
|
@@ -3,26 +3,29 @@ import { Search as t } from "lucide-react";
|
|
|
3
3
|
import { jsx as n, jsxs as r } from "react/jsx-runtime";
|
|
4
4
|
import { Input as i } from "@burdenoff/fe-libs/ui";
|
|
5
5
|
//#region src/healthybowl/components/FilterBar.tsx
|
|
6
|
-
var a = ({ searchValue: a, onSearchChange: o, searchPlaceholder: s = "Search...",
|
|
7
|
-
className: e("flex flex-wrap items-center gap-3",
|
|
6
|
+
var a = ({ searchValue: a, onSearchChange: o, searchPlaceholder: s = "Search...", searchId: c, searchLabel: l, disabled: u, filters: d, actions: f, className: p }) => /* @__PURE__ */ r("div", {
|
|
7
|
+
className: e("flex flex-wrap items-center gap-3", p),
|
|
8
8
|
children: [
|
|
9
9
|
/* @__PURE__ */ r("div", {
|
|
10
10
|
className: "relative min-w-[200px] flex-1",
|
|
11
11
|
children: [/* @__PURE__ */ n(t, { className: "pointer-events-none absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }), /* @__PURE__ */ n(i, {
|
|
12
12
|
type: "text",
|
|
13
|
+
id: c,
|
|
14
|
+
"aria-label": l,
|
|
15
|
+
disabled: u,
|
|
13
16
|
value: a,
|
|
14
17
|
onChange: (e) => o(e.target.value),
|
|
15
18
|
placeholder: s,
|
|
16
19
|
className: "h-9 ps-9"
|
|
17
20
|
})]
|
|
18
21
|
}),
|
|
19
|
-
|
|
22
|
+
d && /* @__PURE__ */ n("div", {
|
|
20
23
|
className: "flex items-center gap-2",
|
|
21
|
-
children:
|
|
24
|
+
children: d
|
|
22
25
|
}),
|
|
23
|
-
|
|
26
|
+
f && /* @__PURE__ */ n("div", {
|
|
24
27
|
className: "ms-auto flex items-center gap-2",
|
|
25
|
-
children:
|
|
28
|
+
children: f
|
|
26
29
|
})
|
|
27
30
|
]
|
|
28
31
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterBar.js","names":[],"sources":["../../../src/healthybowl/components/FilterBar.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\nimport { Search } from 'lucide-react';\nimport { Input } from '@burdenoff/fe-libs/ui';\nimport { cn } from '../utils/helpers';\n\ninterface FilterBarProps {\n searchValue: string;\n onSearchChange: (value: string) => void;\n searchPlaceholder?: string;\n filters?: ReactNode;\n actions?: ReactNode;\n className?: string;\n}\n\n/**\n * Filter/search toolbar. The search field wraps the Boff `Input` primitive\n * (theme-compliant border/background/focus-ring via semantic tokens) with a\n * leading search icon. The `filters` and `actions` slots remain caller-owned\n * ReactNode, so existing call sites pass their own controls unchanged.\n */\nexport const FilterBar: FC<FilterBarProps> = ({\n searchValue,\n onSearchChange,\n searchPlaceholder = 'Search...',\n filters,\n actions,\n className,\n}) => {\n return (\n <div className={cn('flex flex-wrap items-center gap-3', className)}>\n <div className=\"relative min-w-[200px] flex-1\">\n <Search className=\"pointer-events-none absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground\" />\n <Input\n type=\"text\"\n value={searchValue}\n onChange={(e) => onSearchChange(e.target.value)}\n placeholder={searchPlaceholder}\n className=\"h-9 ps-9\"\n />\n </div>\n {filters && <div className=\"flex items-center gap-2\">{filters}</div>}\n {actions && <div className=\"ms-auto flex items-center gap-2\">{actions}</div>}\n </div>\n );\n};\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"FilterBar.js","names":[],"sources":["../../../src/healthybowl/components/FilterBar.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\nimport { Search } from 'lucide-react';\nimport { Input } from '@burdenoff/fe-libs/ui';\nimport { cn } from '../utils/helpers';\n\ninterface FilterBarProps {\n searchValue: string;\n onSearchChange: (value: string) => void;\n searchPlaceholder?: string;\n searchId?: string;\n searchLabel?: string;\n disabled?: boolean;\n filters?: ReactNode;\n actions?: ReactNode;\n className?: string;\n}\n\n/**\n * Filter/search toolbar. The search field wraps the Boff `Input` primitive\n * (theme-compliant border/background/focus-ring via semantic tokens) with a\n * leading search icon. The `filters` and `actions` slots remain caller-owned\n * ReactNode, so existing call sites pass their own controls unchanged.\n */\nexport const FilterBar: FC<FilterBarProps> = ({\n searchValue,\n onSearchChange,\n searchPlaceholder = 'Search...',\n searchId,\n searchLabel,\n disabled,\n filters,\n actions,\n className,\n}) => {\n return (\n <div className={cn('flex flex-wrap items-center gap-3', className)}>\n <div className=\"relative min-w-[200px] flex-1\">\n <Search className=\"pointer-events-none absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground\" />\n <Input\n type=\"text\"\n id={searchId}\n aria-label={searchLabel}\n disabled={disabled}\n value={searchValue}\n onChange={(e) => onSearchChange(e.target.value)}\n placeholder={searchPlaceholder}\n className=\"h-9 ps-9\"\n />\n </div>\n {filters && <div className=\"flex items-center gap-2\">{filters}</div>}\n {actions && <div className=\"ms-auto flex items-center gap-2\">{actions}</div>}\n </div>\n );\n};\n"],"mappings":";;;;;AAuBA,IAAa,KAAiC,EAC5C,gBACA,mBACA,uBAAoB,aACpB,aACA,gBACA,aACA,YACA,YACA,mBAGE,kBAAC,OAAD;CAAK,WAAW,EAAG,qCAAqC,CAAS;WAAjE;EACE,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,GAAD,EAAQ,WAAU,8FAA+F,CAAA,GACjH,kBAAC,GAAD;IACE,MAAK;IACL,IAAI;IACJ,cAAY;IACF;IACV,OAAO;IACP,WAAW,MAAM,EAAe,EAAE,OAAO,KAAK;IAC9C,aAAa;IACb,WAAU;GACX,CAAA,CACE;;EACJ,KAAW,kBAAC,OAAD;GAAK,WAAU;aAA2B;EAAa,CAAA;EAClE,KAAW,kBAAC,OAAD;GAAK,WAAU;aAAmC;EAAa,CAAA;CACxE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
|
|
2
|
+
import { WorkspaceRecordPicker as t, usePickerBrowseState as n } from "./WorkspaceRecordPicker.js";
|
|
3
|
+
import { usePlantCatalogEntry as r, usePlantCatalogPage as i } from "../hooks/usePlantCatalog.js";
|
|
4
|
+
import { jsx as a } from "react/jsx-runtime";
|
|
5
|
+
//#region src/healthybowl/components/PlantCatalogPicker.tsx
|
|
6
|
+
function o(o) {
|
|
7
|
+
let { workspaceId: s } = e(), c = n(), l = o.skip || o.disabled || !s, u = i({
|
|
8
|
+
search: c.search || void 0,
|
|
9
|
+
category: c.category || void 0,
|
|
10
|
+
uncategorized: c.uncategorized || void 0,
|
|
11
|
+
limit: 50,
|
|
12
|
+
offset: c.offset,
|
|
13
|
+
skip: !!l
|
|
14
|
+
}), d = r(o.value, { skip: !!l || o.value === o.emptyOption?.value });
|
|
15
|
+
return /* @__PURE__ */ a(t, {
|
|
16
|
+
...o,
|
|
17
|
+
placeholder: o.placeholder ?? "Choose a catalog variety",
|
|
18
|
+
kind: "catalog entries",
|
|
19
|
+
workspaceId: s,
|
|
20
|
+
browse: c,
|
|
21
|
+
page: u,
|
|
22
|
+
selected: d
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function s(t) {
|
|
26
|
+
let { workspaceId: n } = e();
|
|
27
|
+
return /* @__PURE__ */ a(o, { ...t }, n);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { s as PlantCatalogPicker };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=PlantCatalogPicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlantCatalogPicker.js","names":[],"sources":["../../../src/healthybowl/components/PlantCatalogPicker.tsx"],"sourcesContent":["import { useHealthyBowl } from '../context/HealthyBowlContext';\nimport { usePlantCatalogEntry, usePlantCatalogPage, type PlantCatalogEntry } from '../hooks/usePlantCatalog';\nimport { WorkspaceRecordPicker, usePickerBrowseState, type WorkspaceRecordPickerProps } from './WorkspaceRecordPicker';\n\nexport type PlantCatalogPickerProps = WorkspaceRecordPickerProps<PlantCatalogEntry>;\n\nfunction WorkspacePlantCatalogPicker(props: PlantCatalogPickerProps) {\n const { workspaceId } = useHealthyBowl();\n const browse = usePickerBrowseState();\n const inactive = props.skip || props.disabled || !workspaceId;\n const page = usePlantCatalogPage({\n search: browse.search || undefined,\n category: browse.category || undefined,\n uncategorized: browse.uncategorized || undefined,\n limit: 50,\n offset: browse.offset,\n skip: Boolean(inactive),\n });\n const selected = usePlantCatalogEntry(props.value, {\n skip: Boolean(inactive) || props.value === props.emptyOption?.value,\n });\n return (\n <WorkspaceRecordPicker\n {...props}\n placeholder={props.placeholder ?? 'Choose a catalog variety'}\n kind=\"catalog entries\"\n workspaceId={workspaceId}\n browse={browse}\n page={page}\n selected={selected}\n />\n );\n}\n\n/** Catalog entry IDs only; a same-name operational Crop is not a catalog identity. */\nexport function PlantCatalogPicker(props: PlantCatalogPickerProps) {\n const { workspaceId } = useHealthyBowl();\n return <WorkspacePlantCatalogPicker key={workspaceId} {...props} />;\n}\n"],"mappings":";;;;;AAMA,SAAS,EAA4B,GAAgC;CACnE,IAAM,EAAE,mBAAgB,EAAe,GACjC,IAAS,EAAqB,GAC9B,IAAW,EAAM,QAAQ,EAAM,YAAY,CAAC,GAC5C,IAAO,EAAoB;EAC/B,QAAQ,EAAO,UAAU,KAAA;EACzB,UAAU,EAAO,YAAY,KAAA;EAC7B,eAAe,EAAO,iBAAiB,KAAA;EACvC,OAAO;EACP,QAAQ,EAAO;EACf,MAAM,EAAQ;CAChB,CAAC,GACK,IAAW,EAAqB,EAAM,OAAO,EACjD,MAAM,EAAQ,KAAa,EAAM,UAAU,EAAM,aAAa,MAChE,CAAC;CACD,OACE,kBAAC,GAAD;EACE,GAAI;EACJ,aAAa,EAAM,eAAe;EAClC,MAAK;EACQ;EACL;EACF;EACI;CACX,CAAA;AAEL;AAGA,SAAgB,EAAmB,GAAgC;CACjE,IAAM,EAAE,mBAAgB,EAAe;CACvC,OAAO,kBAAC,GAAD,EAA+C,GAAI,EAAQ,GAAzB,CAAyB;AACpE"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { cn as e } from "../utils/helpers.js";
|
|
2
|
+
import { groupPickerRecords as t, pickerRecordLabel as n, pickerVisibleRecords as r, retainedPickerRecords as i } from "../utils/cropPicker.js";
|
|
3
|
+
import { FilterBar as a } from "./FilterBar.js";
|
|
4
|
+
import { useCallback as o, useId as s, useState as c } from "react";
|
|
5
|
+
import { jsx as l, jsxs as u } from "react/jsx-runtime";
|
|
6
|
+
import { Button as d, Input as f, Pagination as p, Select as m, SelectContent as h, SelectGroup as g, SelectItem as _, SelectLabel as v, SelectTrigger as y, SelectValue as b } from "@burdenoff/fe-libs/ui";
|
|
7
|
+
//#region src/healthybowl/components/WorkspaceRecordPicker.tsx
|
|
8
|
+
function x() {
|
|
9
|
+
let [e, t] = c(""), [n, r] = c(""), [i, a] = c(!1), [s, l] = c(0);
|
|
10
|
+
return {
|
|
11
|
+
search: e,
|
|
12
|
+
category: n,
|
|
13
|
+
uncategorized: i,
|
|
14
|
+
offset: s,
|
|
15
|
+
setOffset: l,
|
|
16
|
+
onSearchChange: o((e) => {
|
|
17
|
+
t(e), l(0);
|
|
18
|
+
}, []),
|
|
19
|
+
onCategoryChange: o((e) => {
|
|
20
|
+
r(e), a(!1), l(0);
|
|
21
|
+
}, []),
|
|
22
|
+
onUncategorizedChange: o(() => {
|
|
23
|
+
a((e) => !e), r(""), l(0);
|
|
24
|
+
}, [])
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function S({ value: o, onValueChange: x, options: S = [], recordedLabel: C, placeholder: w, id: T, disabled: E, className: D, skip: O, emptyOption: k, kind: A, workspaceId: j, browse: M, page: N, selected: P }) {
|
|
28
|
+
let F = s(), I = `${F}-search`, L = `${F}-category`, R = `${F}-categories`, z = `${F}-status`, B = E || O || !j, [V, H] = c(null), U = i(j ? r(N.items, S, M) : [], j ? P.entry ?? S.find((e) => e.id === o) ?? (V?.id === o ? V : null) : null), W = t(U), G = t(N.items).flatMap((e) => e.category === null ? [] : [e.category]), K = k?.value ? k : void 0, q = o && o !== K?.value && !U.some((e) => e.id === o), J = `${C ?? `Recorded ${A === "crops" ? "crop" : "catalog entry"} (${o})`} (${P.loading ? "loading selected record…" : "recorded/unavailable"})`, Y = (e) => {
|
|
29
|
+
if (B) return;
|
|
30
|
+
if (e === K?.value) {
|
|
31
|
+
H(null), x(e, null);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
let t = U.find((t) => t.id === e);
|
|
35
|
+
t && (H(t), x(e, t));
|
|
36
|
+
}, X = (e) => {
|
|
37
|
+
e().catch(() => void 0);
|
|
38
|
+
};
|
|
39
|
+
return /* @__PURE__ */ u("div", {
|
|
40
|
+
className: e("space-y-2", D),
|
|
41
|
+
children: [
|
|
42
|
+
/* @__PURE__ */ l(a, {
|
|
43
|
+
searchValue: M.search,
|
|
44
|
+
onSearchChange: M.onSearchChange,
|
|
45
|
+
searchId: I,
|
|
46
|
+
searchLabel: `Search ${A} by name, variety or category`,
|
|
47
|
+
searchPlaceholder: `Search ${A}…`,
|
|
48
|
+
disabled: !!B,
|
|
49
|
+
filters: /* @__PURE__ */ u("div", {
|
|
50
|
+
className: "flex flex-wrap items-end gap-2",
|
|
51
|
+
children: [/* @__PURE__ */ u("div", { children: [
|
|
52
|
+
/* @__PURE__ */ l("label", {
|
|
53
|
+
htmlFor: L,
|
|
54
|
+
className: "mb-1 block text-xs text-text-secondary",
|
|
55
|
+
children: "Category (page suggestions)"
|
|
56
|
+
}),
|
|
57
|
+
/* @__PURE__ */ l(f, {
|
|
58
|
+
id: L,
|
|
59
|
+
list: R,
|
|
60
|
+
value: M.category,
|
|
61
|
+
onChange: (e) => M.onCategoryChange(e.target.value),
|
|
62
|
+
placeholder: "Any exact category",
|
|
63
|
+
className: "h-9 w-44",
|
|
64
|
+
disabled: !!B || M.uncategorized
|
|
65
|
+
}),
|
|
66
|
+
/* @__PURE__ */ l("datalist", {
|
|
67
|
+
id: R,
|
|
68
|
+
children: G.map((e) => /* @__PURE__ */ l("option", { value: e }, e))
|
|
69
|
+
})
|
|
70
|
+
] }), /* @__PURE__ */ l(d, {
|
|
71
|
+
type: "button",
|
|
72
|
+
size: "sm",
|
|
73
|
+
variant: "outline",
|
|
74
|
+
"aria-pressed": M.uncategorized,
|
|
75
|
+
disabled: !!B,
|
|
76
|
+
onClick: M.onUncategorizedChange,
|
|
77
|
+
children: "Uncategorized"
|
|
78
|
+
})]
|
|
79
|
+
})
|
|
80
|
+
}),
|
|
81
|
+
/* @__PURE__ */ u(m, {
|
|
82
|
+
value: o,
|
|
83
|
+
onValueChange: Y,
|
|
84
|
+
disabled: !!B,
|
|
85
|
+
children: [/* @__PURE__ */ l(y, {
|
|
86
|
+
id: T,
|
|
87
|
+
className: "w-full",
|
|
88
|
+
"aria-label": w,
|
|
89
|
+
"aria-describedby": z,
|
|
90
|
+
children: /* @__PURE__ */ l(b, { placeholder: w })
|
|
91
|
+
}), /* @__PURE__ */ u(h, { children: [
|
|
92
|
+
K && /* @__PURE__ */ l(_, {
|
|
93
|
+
value: K.value,
|
|
94
|
+
children: K.label
|
|
95
|
+
}),
|
|
96
|
+
q && /* @__PURE__ */ l(_, {
|
|
97
|
+
value: o,
|
|
98
|
+
disabled: !0,
|
|
99
|
+
children: J
|
|
100
|
+
}),
|
|
101
|
+
W.map((e) => /* @__PURE__ */ u(g, { children: [/* @__PURE__ */ l(v, { children: e.label }), e.items.map((e) => /* @__PURE__ */ l(_, {
|
|
102
|
+
value: e.id,
|
|
103
|
+
children: n(e)
|
|
104
|
+
}, e.id))] }, JSON.stringify(e.category))),
|
|
105
|
+
U.length === 0 && !K && !q && /* @__PURE__ */ l(g, { children: /* @__PURE__ */ l(v, { children: N.loading ? "Loading…" : N.error ? "Could not load options" : "No matching records" }) })
|
|
106
|
+
] })]
|
|
107
|
+
}),
|
|
108
|
+
/* @__PURE__ */ l("div", {
|
|
109
|
+
id: z,
|
|
110
|
+
"aria-live": "polite",
|
|
111
|
+
className: "text-xs text-text-secondary",
|
|
112
|
+
children: j ? O ? "Browsing is paused." : N.loading ? `Loading ${A}…` : !N.error && N.items.length === 0 ? "No matching records on this page." : N.error ? null : `${N.total} matching ${A} in this workspace.` : "Choose a workspace to browse."
|
|
113
|
+
}),
|
|
114
|
+
N.error && /* @__PURE__ */ u("div", {
|
|
115
|
+
role: "alert",
|
|
116
|
+
className: "flex items-center justify-between gap-2 text-sm text-error",
|
|
117
|
+
children: [/* @__PURE__ */ u("span", { children: [
|
|
118
|
+
"Could not load ",
|
|
119
|
+
A,
|
|
120
|
+
". Your selection has been kept."
|
|
121
|
+
] }), /* @__PURE__ */ l(d, {
|
|
122
|
+
type: "button",
|
|
123
|
+
size: "sm",
|
|
124
|
+
variant: "outline",
|
|
125
|
+
disabled: !!B || N.loading,
|
|
126
|
+
onClick: () => X(N.refetch),
|
|
127
|
+
children: "Retry"
|
|
128
|
+
})]
|
|
129
|
+
}),
|
|
130
|
+
P.error && q && /* @__PURE__ */ u("div", {
|
|
131
|
+
role: "alert",
|
|
132
|
+
className: "flex items-center justify-between gap-2 text-sm text-error",
|
|
133
|
+
children: [/* @__PURE__ */ l("span", { children: "Selected record details could not be loaded." }), /* @__PURE__ */ l(d, {
|
|
134
|
+
type: "button",
|
|
135
|
+
size: "sm",
|
|
136
|
+
variant: "outline",
|
|
137
|
+
disabled: !!B || P.loading,
|
|
138
|
+
onClick: () => X(P.refetch),
|
|
139
|
+
children: "Retry selected record"
|
|
140
|
+
})]
|
|
141
|
+
}),
|
|
142
|
+
S.length > 0 && !M.search.trim() && !M.category && !M.uncategorized && M.offset === 0 && /* @__PURE__ */ l("p", {
|
|
143
|
+
className: "text-xs text-text-secondary",
|
|
144
|
+
children: "Already-loaded choices are included; the total describes server matches."
|
|
145
|
+
}),
|
|
146
|
+
/* @__PURE__ */ l(p, {
|
|
147
|
+
page: Math.floor(N.offset / N.limit) + 1,
|
|
148
|
+
pageSize: N.limit,
|
|
149
|
+
totalItems: N.error || N.loading || N.offset >= N.total ? void 0 : N.total,
|
|
150
|
+
totalPages: !N.error && !N.loading ? Math.max(1, Math.ceil(N.total / N.limit)) : void 0,
|
|
151
|
+
hasNextPage: !B && !N.error && N.hasMore,
|
|
152
|
+
hasPreviousPage: !B && N.offset > 0,
|
|
153
|
+
loading: N.loading || !!B,
|
|
154
|
+
onPageChange: (e) => {
|
|
155
|
+
B || M.setOffset(Math.max(0, (e - 1) * N.limit));
|
|
156
|
+
}
|
|
157
|
+
})
|
|
158
|
+
]
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
export { S as WorkspaceRecordPicker, x as usePickerBrowseState };
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=WorkspaceRecordPicker.js.map
|