@burdenoff/microfe-healthybowl 2026.609.5 → 2026.609.6
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/pages/analytics/AnalyticsDashboardPage.js +77 -85
- package/dist/healthybowl/pages/analytics/AnalyticsDashboardPage.js.map +1 -1
- package/dist/healthybowl/pages/analytics/AnalyticsOverviewPage.js +77 -57
- package/dist/healthybowl/pages/analytics/AnalyticsOverviewPage.js.map +1 -1
- package/dist/healthybowl/pages/analytics/InsightsPage.js +43 -38
- package/dist/healthybowl/pages/analytics/InsightsPage.js.map +1 -1
- package/dist/healthybowl/pages/analytics/ReportsPage.js +69 -61
- package/dist/healthybowl/pages/analytics/ReportsPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/FinancialDashboardPage.js +248 -239
- package/dist/healthybowl/pages/financial/FinancialDashboardPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/FinancialReportsPage.js +140 -190
- package/dist/healthybowl/pages/financial/FinancialReportsPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/TransactionsPage.js +163 -158
- package/dist/healthybowl/pages/financial/TransactionsPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/GovernmentDashboardPage.js +117 -97
- package/dist/healthybowl/pages/government-schemes/GovernmentDashboardPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/LivestockDashboardPage.js +194 -178
- package/dist/healthybowl/pages/livestock/LivestockDashboardPage.js.map +1 -1
- package/dist/healthybowl/pages/pest-management/PestOverviewPage.js +78 -61
- package/dist/healthybowl/pages/pest-management/PestOverviewPage.js.map +1 -1
- package/dist/healthybowl/pages/soil/SoilDashboardPage.js +64 -55
- package/dist/healthybowl/pages/soil/SoilDashboardPage.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,84 +1,76 @@
|
|
|
1
1
|
import { cn as e, formatCurrency as t, formatNumber as n } from "../../utils/helpers.js";
|
|
2
2
|
import { PageLayout as r } from "../../components/PageLayout.js";
|
|
3
3
|
import { StatCard as i } from "../../components/StatCard.js";
|
|
4
|
-
import {
|
|
4
|
+
import { EmptyState as a } from "../../components/EmptyState.js";
|
|
5
|
+
import { ChartCard as o } from "../../components/ChartCard.js";
|
|
6
|
+
import { LoadingSkeleton as s } from "../../components/LoadingSkeleton.js";
|
|
5
7
|
import "../../components/index.js";
|
|
6
|
-
import { useHealthyBowlData as
|
|
7
|
-
import { Legend as
|
|
8
|
-
import { Tooltip as
|
|
9
|
-
import { ResponsiveContainer as
|
|
10
|
-
import { Bar as
|
|
11
|
-
import { CartesianGrid as
|
|
12
|
-
import { Line as
|
|
13
|
-
import { XAxis as
|
|
14
|
-
import { YAxis as
|
|
15
|
-
import { LineChart as
|
|
16
|
-
import { BarChart as
|
|
17
|
-
import { useMemo as
|
|
18
|
-
import { Activity as
|
|
19
|
-
import { jsx as
|
|
8
|
+
import { useHealthyBowlData as c } from "../../hooks/useHealthyBowlData.js";
|
|
9
|
+
import { Legend as l } from "../../../node_modules/recharts/es6/component/Legend.js";
|
|
10
|
+
import { Tooltip as u } from "../../../node_modules/recharts/es6/component/Tooltip.js";
|
|
11
|
+
import { ResponsiveContainer as d } from "../../../node_modules/recharts/es6/component/ResponsiveContainer.js";
|
|
12
|
+
import { Bar as f } from "../../../node_modules/recharts/es6/cartesian/Bar.js";
|
|
13
|
+
import { CartesianGrid as p } from "../../../node_modules/recharts/es6/cartesian/CartesianGrid.js";
|
|
14
|
+
import { Line as m } from "../../../node_modules/recharts/es6/cartesian/Line.js";
|
|
15
|
+
import { XAxis as h } from "../../../node_modules/recharts/es6/cartesian/XAxis.js";
|
|
16
|
+
import { YAxis as g } from "../../../node_modules/recharts/es6/cartesian/YAxis.js";
|
|
17
|
+
import { LineChart as _ } from "../../../node_modules/recharts/es6/chart/LineChart.js";
|
|
18
|
+
import { BarChart as v } from "../../../node_modules/recharts/es6/chart/BarChart.js";
|
|
19
|
+
import { useMemo as y, useState as b } from "react";
|
|
20
|
+
import { Activity as x, BarChart3 as S, TrendingUp as C } from "lucide-react";
|
|
21
|
+
import { Fragment as w, jsx as T, jsxs as E } from "react/jsx-runtime";
|
|
20
22
|
//#region src/healthybowl/pages/analytics/AnalyticsDashboardPage.tsx
|
|
21
|
-
var
|
|
23
|
+
var D = [
|
|
22
24
|
"Q1",
|
|
23
25
|
"Q2",
|
|
24
26
|
"Monthly"
|
|
25
27
|
];
|
|
26
|
-
function
|
|
27
|
-
let { analyticsKPIs:
|
|
28
|
-
let e =
|
|
29
|
-
return [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
label: "Yield Growth",
|
|
44
|
-
value: Math.round(o),
|
|
45
|
-
unit: "%",
|
|
46
|
-
icon: /* @__PURE__ */ C(S, { className: "h-4 w-4" })
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
label: "Cost per Acre",
|
|
50
|
-
value: s,
|
|
51
|
-
unit: "",
|
|
52
|
-
icon: /* @__PURE__ */ C(b, { className: "h-4 w-4" }),
|
|
53
|
-
prefix: "$"
|
|
54
|
-
}
|
|
55
|
-
];
|
|
56
|
-
}, [E]), M = _(() => k === "Q1" ? D.slice(0, 3) : k === "Q2" ? D.slice(3, 6) : D, [D, k]);
|
|
57
|
-
return /* @__PURE__ */ w(r, {
|
|
28
|
+
function O() {
|
|
29
|
+
let { analyticsKPIs: O, revenueChartData: k, yieldTrendData: A, loading: j } = c(), [M, N] = b("Q1"), P = j && O.length === 0 && k.length === 0 && A.length === 0, F = y(() => {
|
|
30
|
+
let e = (e) => typeof e == "number" ? e : parseFloat(String(e)) || 0, t = O.find((e) => (e.label ?? "").toLowerCase().includes("revenue")), n = O.find((e) => (e.label ?? "").toLowerCase().includes("expense") || (e.label ?? "").toLowerCase().includes("cost")), r = O.find((e) => (e.label ?? "").toLowerCase().includes("yield")), i = t ? e(t.value) : 0;
|
|
31
|
+
return [t && n && i > 0 ? {
|
|
32
|
+
label: "Crop Efficiency",
|
|
33
|
+
value: Math.max(0, Math.min(100, Math.round((1 - e(n.value) / i) * 100))),
|
|
34
|
+
unit: "%",
|
|
35
|
+
icon: /* @__PURE__ */ T(x, { className: "h-4 w-4" })
|
|
36
|
+
} : null, r && typeof r.change == "number" ? {
|
|
37
|
+
label: "Yield Growth",
|
|
38
|
+
value: Math.round(r.change),
|
|
39
|
+
unit: "%",
|
|
40
|
+
icon: /* @__PURE__ */ T(C, { className: "h-4 w-4" })
|
|
41
|
+
} : null].filter((e) => e !== null);
|
|
42
|
+
}, [O]), I = y(() => M === "Q1" ? k.slice(0, 3) : M === "Q2" ? k.slice(3, 6) : k, [k, M]);
|
|
43
|
+
return /* @__PURE__ */ T(r, {
|
|
58
44
|
title: "Analytics Dashboard",
|
|
59
45
|
description: "Detailed farm performance analytics",
|
|
60
|
-
actions: /* @__PURE__ */
|
|
46
|
+
actions: /* @__PURE__ */ T("div", {
|
|
61
47
|
className: "flex items-center gap-1 rounded-lg border border-border bg-muted p-0.5",
|
|
62
|
-
children:
|
|
63
|
-
onClick: () =>
|
|
64
|
-
className: e("rounded-md px-3 py-1 text-sm font-medium transition-colors",
|
|
48
|
+
children: D.map((t) => /* @__PURE__ */ T("button", {
|
|
49
|
+
onClick: () => N(t),
|
|
50
|
+
className: e("rounded-md px-3 py-1 text-sm font-medium transition-colors", M === t ? "bg-card text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"),
|
|
65
51
|
children: t
|
|
66
52
|
}, t))
|
|
67
53
|
}),
|
|
68
|
-
children:
|
|
69
|
-
|
|
54
|
+
children: P ? /* @__PURE__ */ T(s, {
|
|
55
|
+
variant: "card",
|
|
56
|
+
count: 4
|
|
57
|
+
}) : /* @__PURE__ */ E(w, { children: [
|
|
58
|
+
F.length > 0 && /* @__PURE__ */ T("div", {
|
|
70
59
|
className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4",
|
|
71
|
-
children:
|
|
60
|
+
children: F.map((e) => /* @__PURE__ */ T(i, {
|
|
72
61
|
label: e.label,
|
|
73
62
|
value: e.value,
|
|
74
63
|
unit: e.unit,
|
|
75
|
-
prefix: e.prefix,
|
|
76
64
|
icon: e.icon
|
|
77
65
|
}, e.label))
|
|
78
66
|
}),
|
|
79
|
-
/* @__PURE__ */
|
|
67
|
+
O.length === 0 ? /* @__PURE__ */ T(a, {
|
|
68
|
+
icon: /* @__PURE__ */ T(S, { className: "h-6 w-6" }),
|
|
69
|
+
title: "No analytics yet",
|
|
70
|
+
description: "Key performance indicators will appear here once farm data has been recorded."
|
|
71
|
+
}) : /* @__PURE__ */ T("div", {
|
|
80
72
|
className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
81
|
-
children:
|
|
73
|
+
children: O.slice(0, 3).map((e) => /* @__PURE__ */ T(i, {
|
|
82
74
|
label: e.label,
|
|
83
75
|
value: e.value,
|
|
84
76
|
previousValue: e.previousValue,
|
|
@@ -88,14 +80,14 @@ function E() {
|
|
|
88
80
|
change: e.change
|
|
89
81
|
}, e.id))
|
|
90
82
|
}),
|
|
91
|
-
/* @__PURE__ */
|
|
83
|
+
/* @__PURE__ */ T(o, {
|
|
92
84
|
title: "Revenue vs Expenses",
|
|
93
|
-
description: `Period: ${
|
|
94
|
-
children: /* @__PURE__ */
|
|
85
|
+
description: `Period: ${M}`,
|
|
86
|
+
children: /* @__PURE__ */ T(d, {
|
|
95
87
|
width: "100%",
|
|
96
88
|
height: 280,
|
|
97
|
-
children: /* @__PURE__ */
|
|
98
|
-
data:
|
|
89
|
+
children: /* @__PURE__ */ E(v, {
|
|
90
|
+
data: I,
|
|
99
91
|
margin: {
|
|
100
92
|
top: 5,
|
|
101
93
|
right: 20,
|
|
@@ -103,21 +95,21 @@ function E() {
|
|
|
103
95
|
bottom: 5
|
|
104
96
|
},
|
|
105
97
|
children: [
|
|
106
|
-
/* @__PURE__ */
|
|
98
|
+
/* @__PURE__ */ T(p, {
|
|
107
99
|
strokeDasharray: "3 3",
|
|
108
100
|
className: "stroke-border"
|
|
109
101
|
}),
|
|
110
|
-
/* @__PURE__ */
|
|
102
|
+
/* @__PURE__ */ T(h, {
|
|
111
103
|
dataKey: "month",
|
|
112
104
|
className: "text-xs",
|
|
113
105
|
tick: { fill: "currentColor" }
|
|
114
106
|
}),
|
|
115
|
-
/* @__PURE__ */
|
|
107
|
+
/* @__PURE__ */ T(g, {
|
|
116
108
|
className: "text-xs",
|
|
117
109
|
tick: { fill: "currentColor" },
|
|
118
110
|
tickFormatter: (e) => `$${(e / 1e3).toFixed(0)}k`
|
|
119
111
|
}),
|
|
120
|
-
/* @__PURE__ */
|
|
112
|
+
/* @__PURE__ */ T(u, {
|
|
121
113
|
formatter: (e) => t(e),
|
|
122
114
|
contentStyle: {
|
|
123
115
|
backgroundColor: "var(--color-card)",
|
|
@@ -126,8 +118,8 @@ function E() {
|
|
|
126
118
|
},
|
|
127
119
|
labelStyle: { color: "var(--color-foreground)" }
|
|
128
120
|
}),
|
|
129
|
-
/* @__PURE__ */
|
|
130
|
-
/* @__PURE__ */
|
|
121
|
+
/* @__PURE__ */ T(l, {}),
|
|
122
|
+
/* @__PURE__ */ T(f, {
|
|
131
123
|
dataKey: "revenue",
|
|
132
124
|
name: "Revenue",
|
|
133
125
|
fill: "var(--color-success)",
|
|
@@ -138,7 +130,7 @@ function E() {
|
|
|
138
130
|
0
|
|
139
131
|
]
|
|
140
132
|
}),
|
|
141
|
-
/* @__PURE__ */
|
|
133
|
+
/* @__PURE__ */ T(f, {
|
|
142
134
|
dataKey: "expenses",
|
|
143
135
|
name: "Expenses",
|
|
144
136
|
fill: "var(--color-destructive)",
|
|
@@ -153,14 +145,14 @@ function E() {
|
|
|
153
145
|
})
|
|
154
146
|
})
|
|
155
147
|
}),
|
|
156
|
-
/* @__PURE__ */
|
|
148
|
+
/* @__PURE__ */ T(o, {
|
|
157
149
|
title: "Yield Trend by Crop",
|
|
158
150
|
description: "Monthly yield in kg",
|
|
159
|
-
children: /* @__PURE__ */
|
|
151
|
+
children: /* @__PURE__ */ T(d, {
|
|
160
152
|
width: "100%",
|
|
161
153
|
height: 280,
|
|
162
|
-
children: /* @__PURE__ */
|
|
163
|
-
data:
|
|
154
|
+
children: /* @__PURE__ */ E(_, {
|
|
155
|
+
data: A,
|
|
164
156
|
margin: {
|
|
165
157
|
top: 5,
|
|
166
158
|
right: 20,
|
|
@@ -168,21 +160,21 @@ function E() {
|
|
|
168
160
|
bottom: 5
|
|
169
161
|
},
|
|
170
162
|
children: [
|
|
171
|
-
/* @__PURE__ */
|
|
163
|
+
/* @__PURE__ */ T(p, {
|
|
172
164
|
strokeDasharray: "3 3",
|
|
173
165
|
className: "stroke-border"
|
|
174
166
|
}),
|
|
175
|
-
/* @__PURE__ */
|
|
167
|
+
/* @__PURE__ */ T(h, {
|
|
176
168
|
dataKey: "month",
|
|
177
169
|
className: "text-xs",
|
|
178
170
|
tick: { fill: "currentColor" }
|
|
179
171
|
}),
|
|
180
|
-
/* @__PURE__ */
|
|
172
|
+
/* @__PURE__ */ T(g, {
|
|
181
173
|
className: "text-xs",
|
|
182
174
|
tick: { fill: "currentColor" },
|
|
183
175
|
tickFormatter: (e) => `${e} kg`
|
|
184
176
|
}),
|
|
185
|
-
/* @__PURE__ */
|
|
177
|
+
/* @__PURE__ */ T(u, {
|
|
186
178
|
formatter: (e) => `${n(e)} kg`,
|
|
187
179
|
contentStyle: {
|
|
188
180
|
backgroundColor: "var(--color-card)",
|
|
@@ -191,8 +183,8 @@ function E() {
|
|
|
191
183
|
},
|
|
192
184
|
labelStyle: { color: "var(--color-foreground)" }
|
|
193
185
|
}),
|
|
194
|
-
/* @__PURE__ */
|
|
195
|
-
/* @__PURE__ */
|
|
186
|
+
/* @__PURE__ */ T(l, {}),
|
|
187
|
+
/* @__PURE__ */ T(m, {
|
|
196
188
|
type: "monotone",
|
|
197
189
|
dataKey: "tomatoes",
|
|
198
190
|
name: "Tomatoes",
|
|
@@ -200,7 +192,7 @@ function E() {
|
|
|
200
192
|
strokeWidth: 2,
|
|
201
193
|
dot: { r: 3 }
|
|
202
194
|
}),
|
|
203
|
-
/* @__PURE__ */
|
|
195
|
+
/* @__PURE__ */ T(m, {
|
|
204
196
|
type: "monotone",
|
|
205
197
|
dataKey: "peppers",
|
|
206
198
|
name: "Peppers",
|
|
@@ -208,7 +200,7 @@ function E() {
|
|
|
208
200
|
strokeWidth: 2,
|
|
209
201
|
dot: { r: 3 }
|
|
210
202
|
}),
|
|
211
|
-
/* @__PURE__ */
|
|
203
|
+
/* @__PURE__ */ T(m, {
|
|
212
204
|
type: "monotone",
|
|
213
205
|
dataKey: "lettuce",
|
|
214
206
|
name: "Lettuce",
|
|
@@ -216,7 +208,7 @@ function E() {
|
|
|
216
208
|
strokeWidth: 2,
|
|
217
209
|
dot: { r: 3 }
|
|
218
210
|
}),
|
|
219
|
-
/* @__PURE__ */
|
|
211
|
+
/* @__PURE__ */ T(m, {
|
|
220
212
|
type: "monotone",
|
|
221
213
|
dataKey: "basil",
|
|
222
214
|
name: "Basil",
|
|
@@ -228,10 +220,10 @@ function E() {
|
|
|
228
220
|
})
|
|
229
221
|
})
|
|
230
222
|
})
|
|
231
|
-
]
|
|
223
|
+
] })
|
|
232
224
|
});
|
|
233
225
|
}
|
|
234
226
|
//#endregion
|
|
235
|
-
export {
|
|
227
|
+
export { O as AnalyticsDashboardPage };
|
|
236
228
|
|
|
237
229
|
//# sourceMappingURL=AnalyticsDashboardPage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsDashboardPage.js","names":[],"sources":["../../../../src/healthybowl/pages/analytics/AnalyticsDashboardPage.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { BarChart3, Activity, TrendingUp, Layers } from 'lucide-react';\nimport {\n BarChart,\n Bar,\n XAxis,\n YAxis,\n CartesianGrid,\n Tooltip,\n Legend,\n ResponsiveContainer,\n LineChart,\n Line,\n} from 'recharts';\nimport { PageLayout, StatCard, ChartCard } from '../../components';\nimport { useHealthyBowlData } from '../../hooks/useHealthyBowlData';\nimport { cn, formatCurrency, formatNumber } from '../../utils/helpers';\n\nconst periods = ['Q1', 'Q2', 'Monthly'] as const;\n\nexport function AnalyticsDashboardPage() {\n const { analyticsKPIs, revenueChartData, yieldTrendData } = useHealthyBowlData();\n\n const [selectedPeriod, setSelectedPeriod] = useState<string>('Q1');\n\n // Derive performance metrics from actual KPI data\n const performanceMetrics = useMemo(() => {\n const revenueKpi = analyticsKPIs.find((k) => (k.label ?? '').toLowerCase().includes('revenue'));\n const expenseKpi = analyticsKPIs.find(\n (k) => (k.label ?? '').toLowerCase().includes('expense') || (k.label ?? '').toLowerCase().includes('cost')\n );\n const yieldKpi = analyticsKPIs.find((k) => (k.label ?? '').toLowerCase().includes('yield'));\n\n const totalRevenue = revenueKpi\n ? typeof revenueKpi.value === 'number'\n ? revenueKpi.value\n : parseFloat(String(revenueKpi.value)) || 0\n : 0;\n const totalExpenses = expenseKpi\n ? typeof expenseKpi.value === 'number'\n ? expenseKpi.value\n : parseFloat(String(expenseKpi.value)) || 0\n : 0;\n const efficiency = totalRevenue > 0 ? Math.round((1 - totalExpenses / totalRevenue) * 100) : 87;\n const yieldGrowth = yieldKpi?.change ?? 15;\n const costPerAcre = totalExpenses > 0 ? Math.round(totalExpenses / Math.max(analyticsKPIs.length, 1)) : 300;\n\n return [\n {\n label: 'Crop Efficiency',\n value: Math.max(0, Math.min(100, efficiency)),\n unit: '%',\n icon: <Activity className=\"h-4 w-4\" />,\n },\n {\n label: 'Resource Utilization',\n value: Math.max(0, Math.min(100, efficiency + 5)),\n unit: '%',\n icon: <Layers className=\"h-4 w-4\" />,\n },\n { label: 'Yield Growth', value: Math.round(yieldGrowth), unit: '%', icon: <TrendingUp className=\"h-4 w-4\" /> },\n {\n label: 'Cost per Acre',\n value: costPerAcre,\n unit: '',\n icon: <BarChart3 className=\"h-4 w-4\" />,\n prefix: '$' as const,\n },\n ];\n }, [analyticsKPIs]);\n\n // Filter chart data by period\n const filteredRevenueData = useMemo(() => {\n if (selectedPeriod === 'Q1') return revenueChartData.slice(0, 3);\n if (selectedPeriod === 'Q2') return revenueChartData.slice(3, 6);\n return revenueChartData; // Monthly = all\n }, [revenueChartData, selectedPeriod]);\n\n return (\n <PageLayout\n title=\"Analytics Dashboard\"\n description=\"Detailed farm performance analytics\"\n actions={\n <div className=\"flex items-center gap-1 rounded-lg border border-border bg-muted p-0.5\">\n {periods.map((p) => (\n <button\n key={p}\n onClick={() => setSelectedPeriod(p)}\n className={cn(\n 'rounded-md px-3 py-1 text-sm font-medium transition-colors',\n selectedPeriod === p\n ? 'bg-card text-foreground shadow-sm'\n : 'text-muted-foreground hover:text-foreground'\n )}\n >\n {p}\n </button>\n ))}\n </div>\n }\n >\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4\">\n {performanceMetrics.map((m) => (\n <StatCard key={m.label} label={m.label} value={m.value} unit={m.unit} prefix={m.prefix} icon={m.icon} />\n ))}\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3\">\n {analyticsKPIs.slice(0, 3).map((kpi) => (\n <StatCard\n key={kpi.id}\n label={kpi.label}\n value={kpi.value}\n previousValue={kpi.previousValue}\n prefix={kpi.unit === '$' ? '$' : undefined}\n unit={kpi.unit !== '$' ? kpi.unit : undefined}\n trend={kpi.trend}\n change={kpi.change}\n />\n ))}\n </div>\n\n <ChartCard title=\"Revenue vs Expenses\" description={`Period: ${selectedPeriod}`}>\n <ResponsiveContainer width=\"100%\" height={280}>\n <BarChart data={filteredRevenueData} margin={{ top: 5, right: 20, left: 0, bottom: 5 }}>\n <CartesianGrid strokeDasharray=\"3 3\" className=\"stroke-border\" />\n <XAxis dataKey=\"month\" className=\"text-xs\" tick={{ fill: 'currentColor' }} />\n <YAxis\n className=\"text-xs\"\n tick={{ fill: 'currentColor' }}\n tickFormatter={(v) => `$${(v / 1000).toFixed(0)}k`}\n />\n <Tooltip\n formatter={(value: number) => formatCurrency(value)}\n contentStyle={{\n backgroundColor: 'var(--color-card)',\n border: '1px solid var(--color-border)',\n borderRadius: '8px',\n }}\n labelStyle={{ color: 'var(--color-foreground)' }}\n />\n <Legend />\n <Bar dataKey=\"revenue\" name=\"Revenue\" fill=\"var(--color-success)\" radius={[4, 4, 0, 0]} />\n <Bar dataKey=\"expenses\" name=\"Expenses\" fill=\"var(--color-destructive)\" radius={[4, 4, 0, 0]} />\n </BarChart>\n </ResponsiveContainer>\n </ChartCard>\n\n <ChartCard title=\"Yield Trend by Crop\" description=\"Monthly yield in kg\">\n <ResponsiveContainer width=\"100%\" height={280}>\n <LineChart data={yieldTrendData} margin={{ top: 5, right: 20, left: 0, bottom: 5 }}>\n <CartesianGrid strokeDasharray=\"3 3\" className=\"stroke-border\" />\n <XAxis dataKey=\"month\" className=\"text-xs\" tick={{ fill: 'currentColor' }} />\n <YAxis className=\"text-xs\" tick={{ fill: 'currentColor' }} tickFormatter={(v) => `${v} kg`} />\n <Tooltip\n formatter={(value: number) => `${formatNumber(value)} kg`}\n contentStyle={{\n backgroundColor: 'var(--color-card)',\n border: '1px solid var(--color-border)',\n borderRadius: '8px',\n }}\n labelStyle={{ color: 'var(--color-foreground)' }}\n />\n <Legend />\n <Line\n type=\"monotone\"\n dataKey=\"tomatoes\"\n name=\"Tomatoes\"\n stroke=\"var(--color-destructive)\"\n strokeWidth={2}\n dot={{ r: 3 }}\n />\n <Line\n type=\"monotone\"\n dataKey=\"peppers\"\n name=\"Peppers\"\n stroke=\"var(--color-success)\"\n strokeWidth={2}\n dot={{ r: 3 }}\n />\n <Line\n type=\"monotone\"\n dataKey=\"lettuce\"\n name=\"Lettuce\"\n stroke=\"var(--color-info)\"\n strokeWidth={2}\n dot={{ r: 3 }}\n />\n <Line\n type=\"monotone\"\n dataKey=\"basil\"\n name=\"Basil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gB;QAAI,CAAA;OAC7E,kBAAC,GAAD;QAAO,WAAU;QAAU,MAAM,EAAE,MAAM,gBAAgB;QAAE,gBAAgB,MAAM,GAAG,EAAE;QAAQ,CAAA;OAC9F,kBAAC,GAAD;QACE,YAAY,MAAkB,GAAG,EAAa,EAAM,CAAC;QACrD,cAAc;SACZ,iBAAiB;SACjB,QAAQ;SACR,cAAc;SACf;QACD,YAAY,EAAE,OAAO,2BAA2B;QAChD,CAAA;OACF,kBAAC,GAAD,EAAU,CAAA;OACV,kBAAC,GAAD;QACE,MAAK;QACL,SAAQ;QACR,MAAK;QACL,QAAO;QACP,aAAa;QACb,KAAK,EAAE,GAAG,GAAG;QACb,CAAA;OACF,kBAAC,GAAD;QACE,MAAK;QACL,SAAQ;QACR,MAAK;QACL,QAAO;QACP,aAAa;QACb,KAAK,EAAE,GAAG,GAAG;QACb,CAAA;OACF,kBAAC,GAAD;QACE,MAAK;QACL,SAAQ;QACR,MAAK;QACL,QAAO;QACP,aAAa;QACb,KAAK,EAAE,GAAG,GAAG;QACb,CAAA;OACF,kBAAC,GAAD;QACE,MAAK;QACL,SAAQ;QACR,MAAK;QACL,QAAO;QACP,aAAa;QACb,KAAK,EAAE,GAAG,GAAG;QACb,CAAA;OACQ;;KACQ,CAAA;IACZ,CAAA;GACD"}
|
|
1
|
+
{"version":3,"file":"AnalyticsDashboardPage.js","names":[],"sources":["../../../../src/healthybowl/pages/analytics/AnalyticsDashboardPage.tsx"],"sourcesContent":["import { useMemo, useState } from 'react';\nimport { Activity, BarChart3, TrendingUp } from 'lucide-react';\nimport {\n BarChart,\n Bar,\n XAxis,\n YAxis,\n CartesianGrid,\n Tooltip,\n Legend,\n ResponsiveContainer,\n LineChart,\n Line,\n} from 'recharts';\nimport { PageLayout, StatCard, ChartCard, LoadingSkeleton, EmptyState } from '../../components';\nimport { useHealthyBowlData } from '../../hooks/useHealthyBowlData';\nimport { cn, formatCurrency, formatNumber } from '../../utils/helpers';\n\nconst periods = ['Q1', 'Q2', 'Monthly'] as const;\n\nexport function AnalyticsDashboardPage() {\n const { analyticsKPIs, revenueChartData, yieldTrendData, loading } = useHealthyBowlData();\n\n const [selectedPeriod, setSelectedPeriod] = useState<string>('Q1');\n\n // True while data is loading and nothing has arrived yet — avoids flashing 0/NaN/blank sections.\n const isInitialLoading =\n loading && analyticsKPIs.length === 0 && revenueChartData.length === 0 && yieldTrendData.length === 0;\n\n // Derive performance metrics from REAL KPI data only. A metric appears only when its source KPI\n // exists — no fabricated fallbacks (was 87/15/300) and no invented metrics (the old \"Resource\n // Utilization\" = efficiency+5 and \"Cost per Acre\" = expenses/KPI-count had no real data basis).\n const performanceMetrics = useMemo(() => {\n const toNum = (v: unknown) => (typeof v === 'number' ? v : parseFloat(String(v)) || 0);\n const revenueKpi = analyticsKPIs.find((k) => (k.label ?? '').toLowerCase().includes('revenue'));\n const expenseKpi = analyticsKPIs.find(\n (k) => (k.label ?? '').toLowerCase().includes('expense') || (k.label ?? '').toLowerCase().includes('cost')\n );\n const yieldKpi = analyticsKPIs.find((k) => (k.label ?? '').toLowerCase().includes('yield'));\n\n const totalRevenue = revenueKpi ? toNum(revenueKpi.value) : 0;\n const cropEfficiency =\n revenueKpi && expenseKpi && totalRevenue > 0\n ? {\n label: 'Crop Efficiency',\n value: Math.max(0, Math.min(100, Math.round((1 - toNum(expenseKpi.value) / totalRevenue) * 100))),\n unit: '%',\n icon: <Activity className=\"h-4 w-4\" />,\n }\n : null;\n const yieldGrowth =\n yieldKpi && typeof yieldKpi.change === 'number'\n ? {\n label: 'Yield Growth',\n value: Math.round(yieldKpi.change),\n unit: '%',\n icon: <TrendingUp className=\"h-4 w-4\" />,\n }\n : null;\n\n return [cropEfficiency, yieldGrowth].filter((m): m is NonNullable<typeof m> => m !== null);\n }, [analyticsKPIs]);\n\n // Filter chart data by period\n const filteredRevenueData = useMemo(() => {\n if (selectedPeriod === 'Q1') return revenueChartData.slice(0, 3);\n if (selectedPeriod === 'Q2') return revenueChartData.slice(3, 6);\n return revenueChartData; // Monthly = all\n }, [revenueChartData, selectedPeriod]);\n\n return (\n <PageLayout\n title=\"Analytics Dashboard\"\n description=\"Detailed farm performance analytics\"\n actions={\n <div className=\"flex items-center gap-1 rounded-lg border border-border bg-muted p-0.5\">\n {periods.map((p) => (\n <button\n key={p}\n onClick={() => setSelectedPeriod(p)}\n className={cn(\n 'rounded-md px-3 py-1 text-sm font-medium transition-colors',\n selectedPeriod === p\n ? 'bg-card text-foreground shadow-sm'\n : 'text-muted-foreground hover:text-foreground'\n )}\n >\n {p}\n </button>\n ))}\n </div>\n }\n >\n {isInitialLoading ? (\n <LoadingSkeleton variant=\"card\" count={4} />\n ) : (\n <>\n {performanceMetrics.length > 0 && (\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4\">\n {performanceMetrics.map((m) => (\n <StatCard key={m.label} label={m.label} value={m.value} unit={m.unit} icon={m.icon} />\n ))}\n </div>\n )}\n\n {analyticsKPIs.length === 0 ? (\n <EmptyState\n icon={<BarChart3 className=\"h-6 w-6\" />}\n title=\"No analytics yet\"\n description=\"Key performance indicators will appear here once farm data has been recorded.\"\n />\n ) : (\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3\">\n {analyticsKPIs.slice(0, 3).map((kpi) => (\n <StatCard\n key={kpi.id}\n label={kpi.label}\n value={kpi.value}\n previousValue={kpi.previousValue}\n prefix={kpi.unit === '$' ? '$' : undefined}\n unit={kpi.unit !== '$' ? kpi.unit : undefined}\n trend={kpi.trend}\n change={kpi.change}\n />\n ))}\n </div>\n )}\n\n <ChartCard title=\"Revenue vs Expenses\" description={`Period: ${selectedPeriod}`}>\n <ResponsiveContainer width=\"100%\" height={280}>\n <BarChart data={filteredRevenueData} margin={{ top: 5, right: 20, left: 0, bottom: 5 }}>\n <CartesianGrid strokeDasharray=\"3 3\" className=\"stroke-border\" />\n <XAxis dataKey=\"month\" className=\"text-xs\" tick={{ fill: 'currentColor' }} />\n <YAxis\n className=\"text-xs\"\n tick={{ fill: 'currentColor' }}\n tickFormatter={(v) => `$${(v / 1000).toFixed(0)}k`}\n />\n <Tooltip\n formatter={(value: number) => formatCurrency(value)}\n contentStyle={{\n backgroundColor: 'var(--color-card)',\n border: '1px solid var(--color-border)',\n borderRadius: '8px',\n }}\n labelStyle={{ color: 'var(--color-foreground)' }}\n />\n <Legend />\n <Bar dataKey=\"revenue\" name=\"Revenue\" fill=\"var(--color-success)\" radius={[4, 4, 0, 0]} />\n <Bar dataKey=\"expenses\" name=\"Expenses\" fill=\"var(--color-destructive)\" radius={[4, 4, 0, 0]} />\n </BarChart>\n </ResponsiveContainer>\n </ChartCard>\n\n <ChartCard title=\"Yield Trend by Crop\" description=\"Monthly yield in kg\">\n <ResponsiveContainer width=\"100%\" height={280}>\n <LineChart data={yieldTrendData} margin={{ top: 5, right: 20, left: 0, bottom: 5 }}>\n <CartesianGrid strokeDasharray=\"3 3\" className=\"stroke-border\" />\n <XAxis dataKey=\"month\" className=\"text-xs\" tick={{ fill: 'currentColor' }} />\n <YAxis className=\"text-xs\" tick={{ fill: 'currentColor' }} tickFormatter={(v) => `${v} kg`} />\n <Tooltip\n formatter={(value: number) => `${formatNumber(value)} kg`}\n contentStyle={{\n backgroundColor: 'var(--color-card)',\n border: '1px solid var(--color-border)',\n borderRadius: '8px',\n }}\n labelStyle={{ color: 'var(--color-foreground)' }}\n />\n <Legend />\n <Line\n type=\"monotone\"\n dataKey=\"tomatoes\"\n name=\"Tomatoes\"\n stroke=\"var(--color-destructive)\"\n strokeWidth={2}\n dot={{ r: 3 }}\n />\n <Line\n type=\"monotone\"\n dataKey=\"peppers\"\n name=\"Peppers\"\n stroke=\"var(--color-success)\"\n strokeWidth={2}\n dot={{ r: 3 }}\n />\n <Line\n type=\"monotone\"\n dataKey=\"lettuce\"\n name=\"Lettuce\"\n stroke=\"var(--color-info)\"\n strokeWidth={2}\n dot={{ r: 3 }}\n />\n <Line\n type=\"monotone\"\n dataKey=\"basil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AAU;QAAU,MAAM,EAAE,MAAM,gBAAgB;QAAE,gBAAgB,MAAM,GAAG,EAAE;QAAQ,CAAA;OAC9F,kBAAC,GAAD;QACE,YAAY,MAAkB,GAAG,EAAa,EAAM,CAAC;QACrD,cAAc;SACZ,iBAAiB;SACjB,QAAQ;SACR,cAAc;SACf;QACD,YAAY,EAAE,OAAO,2BAA2B;QAChD,CAAA;OACF,kBAAC,GAAD,EAAU,CAAA;OACV,kBAAC,GAAD;QACE,MAAK;QACL,SAAQ;QACR,MAAK;QACL,QAAO;QACP,aAAa;QACb,KAAK,EAAE,GAAG,GAAG;QACb,CAAA;OACF,kBAAC,GAAD;QACE,MAAK;QACL,SAAQ;QACR,MAAK;QACL,QAAO;QACP,aAAa;QACb,KAAK,EAAE,GAAG,GAAG;QACb,CAAA;OACF,kBAAC,GAAD;QACE,MAAK;QACL,SAAQ;QACR,MAAK;QACL,QAAO;QACP,aAAa;QACb,KAAK,EAAE,GAAG,GAAG;QACb,CAAA;OACF,kBAAC,GAAD;QACE,MAAK;QACL,SAAQ;QACR,MAAK;QACL,QAAO;QACP,aAAa;QACb,KAAK,EAAE,GAAG,GAAG;QACb,CAAA;OACQ;;KACQ,CAAA;IACZ,CAAA;GACX,EAAA,CAAA;EAEM,CAAA"}
|
|
@@ -2,55 +2,68 @@ import { useBasePath as e } from "../../hooks/useBasePath.js";
|
|
|
2
2
|
import { formatCurrency as t } from "../../utils/helpers.js";
|
|
3
3
|
import { PageLayout as n } from "../../components/PageLayout.js";
|
|
4
4
|
import { StatCard as r } from "../../components/StatCard.js";
|
|
5
|
-
import {
|
|
5
|
+
import { EmptyState as i } from "../../components/EmptyState.js";
|
|
6
|
+
import { ChartCard as a } from "../../components/ChartCard.js";
|
|
7
|
+
import { LoadingSkeleton as o } from "../../components/LoadingSkeleton.js";
|
|
6
8
|
import "../../components/index.js";
|
|
7
|
-
import { useHealthyBowlData as
|
|
8
|
-
import { useState as
|
|
9
|
-
import { ArrowRight as
|
|
10
|
-
import { useNavigate as
|
|
11
|
-
import { jsx as
|
|
9
|
+
import { useHealthyBowlData as s } from "../../hooks/useHealthyBowlData.js";
|
|
10
|
+
import { useState as c } from "react";
|
|
11
|
+
import { ArrowRight as l, BarChart3 as u, DollarSign as d, FileText as f, PieChart as p, ShieldCheck as m, ShoppingCart as h, TrendingDown as g, TrendingUp as _, Wheat as v } from "lucide-react";
|
|
12
|
+
import { useNavigate as y } from "react-router-dom";
|
|
13
|
+
import { jsx as b, jsxs as x } from "react/jsx-runtime";
|
|
12
14
|
//#region src/healthybowl/pages/analytics/AnalyticsOverviewPage.tsx
|
|
13
|
-
var
|
|
14
|
-
/* @__PURE__ */
|
|
15
|
-
/* @__PURE__ */ g
|
|
16
|
-
/* @__PURE__ */
|
|
17
|
-
/* @__PURE__ */
|
|
18
|
-
/* @__PURE__ */
|
|
19
|
-
/* @__PURE__ */
|
|
15
|
+
var S = [
|
|
16
|
+
/* @__PURE__ */ b(d, { className: "h-4 w-4" }),
|
|
17
|
+
/* @__PURE__ */ b(g, { className: "h-4 w-4" }),
|
|
18
|
+
/* @__PURE__ */ b(_, { className: "h-4 w-4" }),
|
|
19
|
+
/* @__PURE__ */ b(v, { className: "h-4 w-4" }),
|
|
20
|
+
/* @__PURE__ */ b(m, { className: "h-4 w-4" }),
|
|
21
|
+
/* @__PURE__ */ b(h, { className: "h-4 w-4" })
|
|
20
22
|
];
|
|
21
|
-
function
|
|
22
|
-
let { analyticsKPIs:
|
|
23
|
-
return /* @__PURE__ */
|
|
23
|
+
function C() {
|
|
24
|
+
let { analyticsKPIs: d, revenueChartData: m, cropDistributionData: h, loading: g } = s(), _ = y(), { buildPath: v } = e(), [C, w] = c("6m"), T = m.length ? Math.max(...m.flatMap((e) => [e.revenue, e.expenses])) : 0;
|
|
25
|
+
return g && d.length === 0 && m.length === 0 && h.length === 0 ? /* @__PURE__ */ b(n, {
|
|
26
|
+
title: "Analytics Overview",
|
|
27
|
+
description: "Key performance metrics for your farm",
|
|
28
|
+
children: /* @__PURE__ */ b(o, {
|
|
29
|
+
variant: "card",
|
|
30
|
+
count: 4
|
|
31
|
+
})
|
|
32
|
+
}) : /* @__PURE__ */ x(n, {
|
|
24
33
|
title: "Analytics Overview",
|
|
25
34
|
description: "Key performance metrics for your farm",
|
|
26
35
|
children: [
|
|
27
|
-
/* @__PURE__ */
|
|
36
|
+
/* @__PURE__ */ b("div", {
|
|
28
37
|
className: "flex flex-wrap gap-3",
|
|
29
38
|
children: [{
|
|
30
39
|
label: "Reports",
|
|
31
|
-
icon:
|
|
32
|
-
path:
|
|
40
|
+
icon: f,
|
|
41
|
+
path: v("analytics/reports"),
|
|
33
42
|
desc: "Generate and export reports"
|
|
34
|
-
}].map((e) => /* @__PURE__ */
|
|
43
|
+
}].map((e) => /* @__PURE__ */ x("button", {
|
|
35
44
|
type: "button",
|
|
36
|
-
onClick: () =>
|
|
45
|
+
onClick: () => _(e.path),
|
|
37
46
|
className: "flex items-center gap-3 rounded-lg border border-border bg-card px-4 py-3 text-left shadow-sm transition-colors hover:border-primary/30 hover:bg-accent",
|
|
38
47
|
children: [
|
|
39
|
-
/* @__PURE__ */
|
|
40
|
-
/* @__PURE__ */
|
|
48
|
+
/* @__PURE__ */ b(e.icon, { className: "h-5 w-5 text-muted-foreground" }),
|
|
49
|
+
/* @__PURE__ */ x("div", { children: [/* @__PURE__ */ b("p", {
|
|
41
50
|
className: "text-sm font-medium text-foreground",
|
|
42
51
|
children: e.label
|
|
43
|
-
}), /* @__PURE__ */
|
|
52
|
+
}), /* @__PURE__ */ b("p", {
|
|
44
53
|
className: "text-xs text-muted-foreground",
|
|
45
54
|
children: e.desc
|
|
46
55
|
})] }),
|
|
47
|
-
/* @__PURE__ */
|
|
56
|
+
/* @__PURE__ */ b(l, { className: "ml-2 h-4 w-4 text-muted-foreground" })
|
|
48
57
|
]
|
|
49
58
|
}, e.label))
|
|
50
59
|
}),
|
|
51
|
-
/* @__PURE__ */
|
|
60
|
+
d.length === 0 ? /* @__PURE__ */ b(i, {
|
|
61
|
+
icon: /* @__PURE__ */ b(u, { className: "h-6 w-6" }),
|
|
62
|
+
title: "No metrics yet",
|
|
63
|
+
description: "Key performance metrics will appear here once your farm has activity to report."
|
|
64
|
+
}) : /* @__PURE__ */ b("div", {
|
|
52
65
|
className: "grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3",
|
|
53
|
-
children:
|
|
66
|
+
children: d.map((e, t) => /* @__PURE__ */ b(r, {
|
|
54
67
|
label: e.label,
|
|
55
68
|
value: e.value,
|
|
56
69
|
previousValue: e.previousValue,
|
|
@@ -58,76 +71,83 @@ function y() {
|
|
|
58
71
|
unit: e.unit === "$" ? void 0 : e.unit,
|
|
59
72
|
trend: e.trend,
|
|
60
73
|
change: e.change,
|
|
61
|
-
icon:
|
|
74
|
+
icon: S[t]
|
|
62
75
|
}, e.id))
|
|
63
76
|
}),
|
|
64
|
-
/* @__PURE__ */
|
|
77
|
+
/* @__PURE__ */ b("div", {
|
|
65
78
|
className: "flex gap-2",
|
|
66
79
|
children: [
|
|
67
80
|
"3m",
|
|
68
81
|
"6m",
|
|
69
82
|
"1y"
|
|
70
|
-
].map((e) => /* @__PURE__ */
|
|
71
|
-
onClick: () =>
|
|
72
|
-
className: `rounded-md px-3 py-1.5 text-sm font-medium ${
|
|
83
|
+
].map((e) => /* @__PURE__ */ b("button", {
|
|
84
|
+
onClick: () => w(e),
|
|
85
|
+
className: `rounded-md px-3 py-1.5 text-sm font-medium ${C === e ? "bg-primary text-primary-foreground" : "border border-border text-foreground hover:bg-muted/50"}`,
|
|
73
86
|
children: e === "3m" ? "3 Months" : e === "6m" ? "6 Months" : "1 Year"
|
|
74
87
|
}, e))
|
|
75
88
|
}),
|
|
76
|
-
/* @__PURE__ */
|
|
89
|
+
/* @__PURE__ */ x("div", {
|
|
77
90
|
className: "grid grid-cols-1 gap-4 lg:grid-cols-2",
|
|
78
|
-
children: [/* @__PURE__ */
|
|
91
|
+
children: [/* @__PURE__ */ x(a, {
|
|
79
92
|
title: "Revenue Trend",
|
|
80
|
-
description: `Last ${
|
|
81
|
-
children: [/* @__PURE__ */
|
|
93
|
+
description: `Last ${C}`,
|
|
94
|
+
children: [m.length === 0 ? /* @__PURE__ */ b("div", {
|
|
95
|
+
className: "flex h-48 items-center justify-center text-sm text-muted-foreground",
|
|
96
|
+
children: "No revenue data yet."
|
|
97
|
+
}) : /* @__PURE__ */ b("div", {
|
|
82
98
|
className: "flex items-end gap-2 h-48",
|
|
83
|
-
children:
|
|
99
|
+
children: m.map((e) => /* @__PURE__ */ x("div", {
|
|
84
100
|
className: "flex flex-1 flex-col items-center gap-1",
|
|
85
|
-
children: [/* @__PURE__ */
|
|
101
|
+
children: [/* @__PURE__ */ x("div", {
|
|
86
102
|
className: "flex w-full gap-0.5 items-end",
|
|
87
103
|
style: { height: "160px" },
|
|
88
|
-
children: [/* @__PURE__ */
|
|
104
|
+
children: [/* @__PURE__ */ b("div", {
|
|
89
105
|
className: "flex-1 rounded-t bg-success/80",
|
|
90
|
-
style: { height: `${e.revenue /
|
|
106
|
+
style: { height: `${T > 0 ? e.revenue / T * 100 : 0}%` },
|
|
91
107
|
title: `Revenue: ${t(e.revenue)}`
|
|
92
|
-
}), /* @__PURE__ */
|
|
108
|
+
}), /* @__PURE__ */ b("div", {
|
|
93
109
|
className: "flex-1 rounded-t bg-destructive/60",
|
|
94
|
-
style: { height: `${e.expenses /
|
|
110
|
+
style: { height: `${T > 0 ? e.expenses / T * 100 : 0}%` },
|
|
95
111
|
title: `Expenses: ${t(e.expenses)}`
|
|
96
112
|
})]
|
|
97
|
-
}), /* @__PURE__ */
|
|
113
|
+
}), /* @__PURE__ */ b("span", {
|
|
98
114
|
className: "text-xs text-muted-foreground",
|
|
99
115
|
children: e.month
|
|
100
116
|
})]
|
|
101
117
|
}, e.month))
|
|
102
|
-
}), /* @__PURE__ */
|
|
118
|
+
}), /* @__PURE__ */ x("div", {
|
|
103
119
|
className: "mt-3 flex items-center gap-4 text-xs text-muted-foreground",
|
|
104
|
-
children: [/* @__PURE__ */
|
|
120
|
+
children: [/* @__PURE__ */ x("span", {
|
|
105
121
|
className: "flex items-center gap-1.5",
|
|
106
|
-
children: [/* @__PURE__ */
|
|
107
|
-
}), /* @__PURE__ */
|
|
122
|
+
children: [/* @__PURE__ */ b("span", { className: "h-2.5 w-2.5 rounded-sm bg-success/80" }), " Revenue"]
|
|
123
|
+
}), /* @__PURE__ */ x("span", {
|
|
108
124
|
className: "flex items-center gap-1.5",
|
|
109
|
-
children: [/* @__PURE__ */
|
|
125
|
+
children: [/* @__PURE__ */ b("span", { className: "h-2.5 w-2.5 rounded-sm bg-destructive/60" }), " Expenses"]
|
|
110
126
|
})]
|
|
111
127
|
})]
|
|
112
|
-
}), /* @__PURE__ */
|
|
128
|
+
}), /* @__PURE__ */ b(a, {
|
|
113
129
|
title: "Crop Distribution",
|
|
114
130
|
description: "By category",
|
|
115
|
-
children: /* @__PURE__ */
|
|
131
|
+
children: h.length === 0 ? /* @__PURE__ */ b(i, {
|
|
132
|
+
icon: /* @__PURE__ */ b(p, { className: "h-6 w-6" }),
|
|
133
|
+
title: "No crop data yet",
|
|
134
|
+
description: "Crop distribution will appear here once crops are added."
|
|
135
|
+
}) : /* @__PURE__ */ b("div", {
|
|
116
136
|
className: "space-y-3 py-2",
|
|
117
|
-
children:
|
|
137
|
+
children: h.map((e) => /* @__PURE__ */ x("div", {
|
|
118
138
|
className: "space-y-1",
|
|
119
|
-
children: [/* @__PURE__ */
|
|
139
|
+
children: [/* @__PURE__ */ x("div", {
|
|
120
140
|
className: "flex items-center justify-between text-sm",
|
|
121
|
-
children: [/* @__PURE__ */
|
|
141
|
+
children: [/* @__PURE__ */ b("span", {
|
|
122
142
|
className: "text-foreground",
|
|
123
143
|
children: e.name
|
|
124
|
-
}), /* @__PURE__ */
|
|
144
|
+
}), /* @__PURE__ */ x("span", {
|
|
125
145
|
className: "text-muted-foreground",
|
|
126
146
|
children: [e.value, "%"]
|
|
127
147
|
})]
|
|
128
|
-
}), /* @__PURE__ */
|
|
148
|
+
}), /* @__PURE__ */ b("div", {
|
|
129
149
|
className: "h-2 w-full rounded-full bg-muted",
|
|
130
|
-
children: /* @__PURE__ */
|
|
150
|
+
children: /* @__PURE__ */ b("div", {
|
|
131
151
|
className: "h-2 rounded-full",
|
|
132
152
|
style: {
|
|
133
153
|
width: `${e.value}%`,
|
|
@@ -143,6 +163,6 @@ function y() {
|
|
|
143
163
|
});
|
|
144
164
|
}
|
|
145
165
|
//#endregion
|
|
146
|
-
export {
|
|
166
|
+
export { C as AnalyticsOverviewPage };
|
|
147
167
|
|
|
148
168
|
//# sourceMappingURL=AnalyticsOverviewPage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsOverviewPage.js","names":[],"sources":["../../../../src/healthybowl/pages/analytics/AnalyticsOverviewPage.tsx"],"sourcesContent":["import { useState } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport {\n DollarSign,\n TrendingDown,\n TrendingUp,\n Wheat,\n ShieldCheck,\n ShoppingCart,\n FileText,\n ArrowRight,\n} from 'lucide-react';\nimport { PageLayout, StatCard, ChartCard } from '../../components';\nimport { useHealthyBowlData } from '../../hooks/useHealthyBowlData';\nimport { formatCurrency } from '../../utils/helpers';\n\nconst kpiIcons = [\n <DollarSign className=\"h-4 w-4\" />,\n <TrendingDown className=\"h-4 w-4\" />,\n <TrendingUp className=\"h-4 w-4\" />,\n <Wheat className=\"h-4 w-4\" />,\n <ShieldCheck className=\"h-4 w-4\" />,\n <ShoppingCart className=\"h-4 w-4\" />,\n];\n\nexport function AnalyticsOverviewPage() {\n const { analyticsKPIs, revenueChartData, cropDistributionData } = useHealthyBowlData();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n\n const [period, setPeriod] = useState('6m');\n\n const maxRevenue = Math.max(...revenueChartData.map((d) => d.revenue));\n\n return (\n <PageLayout title=\"Analytics Overview\" description=\"Key performance metrics for your farm\">\n {/* Quick Navigation */}\n <div className=\"flex flex-wrap gap-3\">\n {[\n {\n label: 'Reports',\n icon: FileText,\n path: buildPath('analytics/reports'),\n desc: 'Generate and export reports',\n },\n ].map((item) => (\n <button\n key={item.label}\n type=\"button\"\n onClick={() => navigate(item.path)}\n className=\"flex items-center gap-3 rounded-lg border border-border bg-card px-4 py-3 text-left shadow-sm transition-colors hover:border-primary/30 hover:bg-accent\"\n >\n <item.icon className=\"h-5 w-5 text-muted-foreground\" />\n <div>\n <p className=\"text-sm font-medium text-foreground\">{item.label}</p>\n <p className=\"text-xs text-muted-foreground\">{item.desc}</p>\n </div>\n <ArrowRight className=\"ml-2 h-4 w-4 text-muted-foreground\" />\n </button>\n ))}\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3\">\n {analyticsKPIs.map((kpi, i) => (\n <StatCard\n key={kpi.id}\n label={kpi.label}\n value={kpi.value}\n previousValue={kpi.previousValue}\n prefix={kpi.unit === '$' ? '$' : undefined}\n unit={kpi.unit !== '$' ? kpi.unit : undefined}\n trend={kpi.trend}\n change={kpi.change}\n icon={kpiIcons[i]}\n />\n ))}\n </div>\n\n <div className=\"flex gap-2\">\n {(['3m', '6m', '1y'] as const).map((p) => (\n <button\n key={p}\n onClick={() => setPeriod(p)}\n className={`rounded-md px-3 py-1.5 text-sm font-medium ${\n period === p\n ? 'bg-primary text-primary-foreground'\n : 'border border-border text-foreground hover:bg-muted/50'\n }`}\n >\n {p === '3m' ? '3 Months' : p === '6m' ? '6 Months' : '1 Year'}\n </button>\n ))}\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 lg:grid-cols-2\">\n <ChartCard title=\"Revenue Trend\" description={`Last ${period}`}>\n <div className=\"flex items-end gap-2 h-48\">\n {revenueChartData.map((d) => (\n <div key={d.month} className=\"flex flex-1 flex-col items-center gap-1\">\n <div className=\"flex w-full gap-0.5 items-end\" style={{ height: '160px' }}>\n <div\n className=\"flex-1 rounded-t bg-success/80\"\n style={{ height: `${(d.revenue / maxRevenue) * 100}%` }}\n title={`Revenue: ${formatCurrency(d.revenue)}`}\n />\n <div\n className=\"flex-1 rounded-t bg-destructive/60\"\n style={{ height: `${(d.expenses / maxRevenue) * 100}%` }}\n title={`Expenses: ${formatCurrency(d.expenses)}`}\n />\n </div>\n <span className=\"text-xs text-muted-foreground\">{d.month}</span>\n </div>\n ))}\n </div>\n <div className=\"mt-3 flex items-center gap-4 text-xs text-muted-foreground\">\n <span className=\"flex items-center gap-1.5\">\n <span className=\"h-2.5 w-2.5 rounded-sm bg-success/80\" /> Revenue\n </span>\n <span className=\"flex items-center gap-1.5\">\n <span className=\"h-2.5 w-2.5 rounded-sm bg-destructive/60\" /> Expenses\n </span>\n </div>\n </ChartCard>\n\n <ChartCard title=\"Crop Distribution\" description=\"By category\">\n <div className=\"space-y-3 py-2\">\n {cropDistributionData.map((d) => (\n <div key={d.name} className=\"space-y-1\">\n <div className=\"flex items-center justify-between text-sm\">\n <span className=\"text-foreground\">{d.name}</span>\n <span className=\"text-muted-foreground\">{d.value}%</span>\n </div>\n <div className=\"h-2 w-full rounded-full bg-muted\">\n <div className=\"h-2 rounded-full\" style={{ width: `${d.value}%`, backgroundColor: d.color }} />\n </div>\n </div>\n ))}\n </div>\n </ChartCard>\n </div>\n </PageLayout>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,IAAM,IAAW;CACf,kBAAC,GAAD,EAAY,WAAU,WAAY,CAAA;CAClC,kBAAC,GAAD,EAAc,WAAU,WAAY,CAAA;CACpC,kBAAC,GAAD,EAAY,WAAU,WAAY,CAAA;CAClC,kBAAC,GAAD,EAAO,WAAU,WAAY,CAAA;CAC7B,kBAAC,GAAD,EAAa,WAAU,WAAY,CAAA;CACnC,kBAAC,GAAD,EAAc,WAAU,WAAY,CAAA;CACrC;AAED,SAAgB,IAAwB;CACtC,IAAM,EAAE,kBAAe,qBAAkB,4BAAyB,GAAoB,EAChF,IAAW,GAAa,E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AU;SAAmB,OAAO;UAAE,OAAO,GAAG,EAAE,MAAM;UAAI,iBAAiB,EAAE;UAAO;SAAI,CAAA;QAC3F,CAAA,CACF;SARI,EAAE,KAQN,CACN;MACE,CAAA;KACI,CAAA,CACR;;GACK"}
|
|
1
|
+
{"version":3,"file":"AnalyticsOverviewPage.js","names":[],"sources":["../../../../src/healthybowl/pages/analytics/AnalyticsOverviewPage.tsx"],"sourcesContent":["import { useState } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport {\n DollarSign,\n TrendingDown,\n TrendingUp,\n Wheat,\n ShieldCheck,\n ShoppingCart,\n FileText,\n ArrowRight,\n BarChart3,\n PieChart,\n} from 'lucide-react';\nimport { PageLayout, StatCard, ChartCard, LoadingSkeleton, EmptyState } from '../../components';\nimport { useHealthyBowlData } from '../../hooks/useHealthyBowlData';\nimport { formatCurrency } from '../../utils/helpers';\n\nconst kpiIcons = [\n <DollarSign className=\"h-4 w-4\" />,\n <TrendingDown className=\"h-4 w-4\" />,\n <TrendingUp className=\"h-4 w-4\" />,\n <Wheat className=\"h-4 w-4\" />,\n <ShieldCheck className=\"h-4 w-4\" />,\n <ShoppingCart className=\"h-4 w-4\" />,\n];\n\nexport function AnalyticsOverviewPage() {\n const { analyticsKPIs, revenueChartData, cropDistributionData, loading } = useHealthyBowlData();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n\n const [period, setPeriod] = useState('6m');\n\n // Scale bars off the largest revenue OR expense; guard the empty case (Math.max() of [] is\n // -Infinity, which would render NaN% bar heights).\n const maxRevenue = revenueChartData.length\n ? Math.max(...revenueChartData.flatMap((d) => [d.revenue, d.expenses]))\n : 0;\n\n // While the first load is still in flight and nothing has arrived yet, show skeletons in place\n // of the stat/chart body so the page never flashes zeros/blank/NaN sections.\n if (loading && analyticsKPIs.length === 0 && revenueChartData.length === 0 && cropDistributionData.length === 0) {\n return (\n <PageLayout title=\"Analytics Overview\" description=\"Key performance metrics for your farm\">\n <LoadingSkeleton variant=\"card\" count={4} />\n </PageLayout>\n );\n }\n\n return (\n <PageLayout title=\"Analytics Overview\" description=\"Key performance metrics for your farm\">\n {/* Quick Navigation */}\n <div className=\"flex flex-wrap gap-3\">\n {[\n {\n label: 'Reports',\n icon: FileText,\n path: buildPath('analytics/reports'),\n desc: 'Generate and export reports',\n },\n ].map((item) => (\n <button\n key={item.label}\n type=\"button\"\n onClick={() => navigate(item.path)}\n className=\"flex items-center gap-3 rounded-lg border border-border bg-card px-4 py-3 text-left shadow-sm transition-colors hover:border-primary/30 hover:bg-accent\"\n >\n <item.icon className=\"h-5 w-5 text-muted-foreground\" />\n <div>\n <p className=\"text-sm font-medium text-foreground\">{item.label}</p>\n <p className=\"text-xs text-muted-foreground\">{item.desc}</p>\n </div>\n <ArrowRight className=\"ml-2 h-4 w-4 text-muted-foreground\" />\n </button>\n ))}\n </div>\n\n {analyticsKPIs.length === 0 ? (\n <EmptyState\n icon={<BarChart3 className=\"h-6 w-6\" />}\n title=\"No metrics yet\"\n description=\"Key performance metrics will appear here once your farm has activity to report.\"\n />\n ) : (\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3\">\n {analyticsKPIs.map((kpi, i) => (\n <StatCard\n key={kpi.id}\n label={kpi.label}\n value={kpi.value}\n previousValue={kpi.previousValue}\n prefix={kpi.unit === '$' ? '$' : undefined}\n unit={kpi.unit !== '$' ? kpi.unit : undefined}\n trend={kpi.trend}\n change={kpi.change}\n icon={kpiIcons[i]}\n />\n ))}\n </div>\n )}\n\n <div className=\"flex gap-2\">\n {(['3m', '6m', '1y'] as const).map((p) => (\n <button\n key={p}\n onClick={() => setPeriod(p)}\n className={`rounded-md px-3 py-1.5 text-sm font-medium ${\n period === p\n ? 'bg-primary text-primary-foreground'\n : 'border border-border text-foreground hover:bg-muted/50'\n }`}\n >\n {p === '3m' ? '3 Months' : p === '6m' ? '6 Months' : '1 Year'}\n </button>\n ))}\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 lg:grid-cols-2\">\n <ChartCard title=\"Revenue Trend\" description={`Last ${period}`}>\n {revenueChartData.length === 0 ? (\n <div className=\"flex h-48 items-center justify-center text-sm text-muted-foreground\">\n No revenue data yet.\n </div>\n ) : (\n <div className=\"flex items-end gap-2 h-48\">\n {revenueChartData.map((d) => (\n <div key={d.month} className=\"flex flex-1 flex-col items-center gap-1\">\n <div className=\"flex w-full gap-0.5 items-end\" style={{ height: '160px' }}>\n <div\n className=\"flex-1 rounded-t bg-success/80\"\n style={{ height: `${maxRevenue > 0 ? (d.revenue / maxRevenue) * 100 : 0}%` }}\n title={`Revenue: ${formatCurrency(d.revenue)}`}\n />\n <div\n className=\"flex-1 rounded-t bg-destructive/60\"\n style={{ height: `${maxRevenue > 0 ? (d.expenses / maxRevenue) * 100 : 0}%` }}\n title={`Expenses: ${formatCurrency(d.expenses)}`}\n />\n </div>\n <span className=\"text-xs text-muted-foreground\">{d.month}</span>\n </div>\n ))}\n </div>\n )}\n <div className=\"mt-3 flex items-center gap-4 text-xs text-muted-foreground\">\n <span className=\"flex items-center gap-1.5\">\n <span className=\"h-2.5 w-2.5 rounded-sm bg-success/80\" /> Revenue\n </span>\n <span className=\"flex items-center gap-1.5\">\n <span className=\"h-2.5 w-2.5 rounded-sm bg-destructive/60\" /> Expenses\n </span>\n </div>\n </ChartCard>\n\n <ChartCard title=\"Crop Distribution\" description=\"By category\">\n {cropDistributionData.length === 0 ? (\n <EmptyState\n icon={<PieChart className=\"h-6 w-6\" />}\n title=\"No crop data yet\"\n description=\"Crop distribution will appear here once crops are added.\"\n />\n ) : (\n <div className=\"space-y-3 py-2\">\n {cropDistributionData.map((d) => (\n <div key={d.name} className=\"space-y-1\">\n <div className=\"flex items-center justify-between text-sm\">\n <span className=\"text-foreground\">{d.name}</span>\n <span className=\"text-muted-foreground\">{d.value}%</span>\n </div>\n <div className=\"h-2 w-full rounded-full bg-muted\">\n <div className=\"h-2 rounded-full\" style={{ width: `${d.value}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