@burdenoff/microfe-healthybowl 2026.710.21 → 2026.711.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.
Files changed (29) hide show
  1. package/dist/healthybowl/HealthyBowlRoot.js +93 -85
  2. package/dist/healthybowl/HealthyBowlRoot.js.map +1 -1
  3. package/dist/healthybowl/HealthyBowlRoutes.js +98 -86
  4. package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
  5. package/dist/healthybowl/components/PlanExecutionPanel.js +535 -0
  6. package/dist/healthybowl/components/PlanExecutionPanel.js.map +1 -0
  7. package/dist/healthybowl/hooks/useHealthyBowlWithdrawal.js +237 -0
  8. package/dist/healthybowl/hooks/useHealthyBowlWithdrawal.js.map +1 -0
  9. package/dist/healthybowl/hooks/usePlanExecution.js +106 -0
  10. package/dist/healthybowl/hooks/usePlanExecution.js.map +1 -0
  11. package/dist/healthybowl/pages/crops/PlanningDetailsPage.js +246 -241
  12. package/dist/healthybowl/pages/crops/PlanningDetailsPage.js.map +1 -1
  13. package/dist/healthybowl/pages/livestock/AnimalDetailsPage.js +532 -527
  14. package/dist/healthybowl/pages/livestock/AnimalDetailsPage.js.map +1 -1
  15. package/dist/healthybowl/pages/livestock/MedicationLibraryPage.js +387 -0
  16. package/dist/healthybowl/pages/livestock/MedicationLibraryPage.js.map +1 -0
  17. package/dist/healthybowl/pages/livestock/WithdrawalAlertsPage.js +286 -0
  18. package/dist/healthybowl/pages/livestock/WithdrawalAlertsPage.js.map +1 -0
  19. package/dist/healthybowl/pages/livestock/WithdrawalCalendarPage.js +182 -0
  20. package/dist/healthybowl/pages/livestock/WithdrawalCalendarPage.js.map +1 -0
  21. package/dist/healthybowl/pages/livestock/withdrawal/AnimalWithdrawalCard.js +166 -0
  22. package/dist/healthybowl/pages/livestock/withdrawal/AnimalWithdrawalCard.js.map +1 -0
  23. package/dist/healthybowl/pages/livestock/withdrawal/LogTreatmentModal.js +274 -0
  24. package/dist/healthybowl/pages/livestock/withdrawal/LogTreatmentModal.js.map +1 -0
  25. package/dist/healthybowl/pages/livestock/withdrawal/WithdrawalNav.js +40 -0
  26. package/dist/healthybowl/pages/livestock/withdrawal/WithdrawalNav.js.map +1 -0
  27. package/dist/healthybowl/pages/livestock/withdrawal/status.js +53 -0
  28. package/dist/healthybowl/pages/livestock/withdrawal/status.js.map +1 -0
  29. package/package.json +1 -1
@@ -0,0 +1,237 @@
1
+ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
+ import { useCallback as t, useMemo as n } from "react";
3
+ import { gql as r } from "@apollo/client";
4
+ import { useMutation as i, useQuery as a } from "@apollo/client/react";
5
+ //#region src/healthybowl/hooks/useHealthyBowlWithdrawal.ts
6
+ var o = "00000000-0000-0000-0000-000000000001", s = "\n produceType\n withdrawalDays\n clearDate\n status\n blocked\n daysLeft\n", c = `
7
+ id
8
+ animalId
9
+ animalTag
10
+ animalName
11
+ animalType
12
+ healthRecordId
13
+ medicationLibraryItemId
14
+ medicationName
15
+ className
16
+ dose
17
+ route
18
+ treatmentDate
19
+ administeredBy
20
+ notes
21
+ milkWithdrawalDays
22
+ meatWithdrawalDays
23
+ eggsWithdrawalDays
24
+ milkClearDate
25
+ meatClearDate
26
+ eggsClearDate
27
+ produceStatuses { ${s} }
28
+ overallStatus
29
+ daysLeft
30
+ createdAt
31
+ `, l = "\n id\n name\n className\n route\n milkWithdrawalDays\n meatWithdrawalDays\n eggsWithdrawalDays\n species\n source\n builtin\n", u = r`
32
+ query GetHealthyBowlMedicationLibrary($context: ContextInput!, $search: String, $species: String, $source: String) {
33
+ getHealthyBowlMedicationLibrary(context: $context, search: $search, species: $species, source: $source) { ${l} }
34
+ }
35
+ `, d = r`
36
+ query GetHealthyBowlActiveWithdrawals($context: ContextInput!, $status: String) {
37
+ getHealthyBowlActiveWithdrawals(context: $context, status: $status) { ${c} }
38
+ }
39
+ `, f = r`
40
+ query GetHealthyBowlWithdrawalSummary($context: ContextInput!) {
41
+ getHealthyBowlWithdrawalSummary(context: $context) {
42
+ animalsUnderWithdrawal
43
+ productsBlocked
44
+ clearsNext48h
45
+ clearedThisWeek
46
+ }
47
+ }
48
+ `, p = r`
49
+ query GetHealthyBowlAnimalWithdrawalStatus($context: ContextInput!, $animalId: ID!) {
50
+ getHealthyBowlAnimalWithdrawalStatus(context: $context, animalId: $animalId) {
51
+ animalId
52
+ tagNumber
53
+ name
54
+ type
55
+ breed
56
+ location
57
+ overallStatus
58
+ blocked
59
+ produceStatuses { ${s} }
60
+ treatments { ${c} }
61
+ }
62
+ }
63
+ `, m = r`
64
+ query GetHealthyBowlWithdrawalCalendar($context: ContextInput!, $from: String, $to: String) {
65
+ getHealthyBowlWithdrawalCalendar(context: $context, from: $from, to: $to) {
66
+ date
67
+ treatmentId
68
+ animalId
69
+ tagNumber
70
+ produceType
71
+ status
72
+ medicationName
73
+ }
74
+ }
75
+ `, h = r`
76
+ mutation LogHealthyBowlMedicationTreatment($input: LogMedicationTreatmentInput!) {
77
+ logHealthyBowlMedicationTreatment(input: $input) { ${c} }
78
+ }
79
+ `, g = r`
80
+ mutation UpdateHealthyBowlMedicationTreatment($input: UpdateMedicationTreatmentInput!) {
81
+ updateHealthyBowlMedicationTreatment(input: $input) { ${c} }
82
+ }
83
+ `, _ = r`
84
+ mutation DeleteHealthyBowlMedicationTreatment($id: ID!, $context: ContextInput!) {
85
+ deleteHealthyBowlMedicationTreatment(id: $id, context: $context)
86
+ }
87
+ `, v = r`
88
+ mutation CreateHealthyBowlMedicationLibraryItem($input: CreateMedicationLibraryItemInput!) {
89
+ createHealthyBowlMedicationLibraryItem(input: $input) { ${l} }
90
+ }
91
+ `, y = r`
92
+ mutation UpdateHealthyBowlMedicationLibraryItem($input: UpdateMedicationLibraryItemInput!) {
93
+ updateHealthyBowlMedicationLibraryItem(input: $input) { ${l} }
94
+ }
95
+ `, b = r`
96
+ mutation DeleteHealthyBowlMedicationLibraryItem($id: ID!, $context: ContextInput!) {
97
+ deleteHealthyBowlMedicationLibraryItem(id: $id, context: $context)
98
+ }
99
+ `, x = r`
100
+ mutation RunHealthyBowlWithdrawalScan($context: ContextInput!) {
101
+ runHealthyBowlWithdrawalScan(context: $context) {
102
+ scannedAt
103
+ cleared
104
+ notificationsSent
105
+ }
106
+ }
107
+ `;
108
+ function S(r = {}) {
109
+ let { workspaceId: s } = e(), c = s || o, l = n(() => ({ workspaceId: c }), [c]), S = a(d, {
110
+ variables: { context: l },
111
+ fetchPolicy: "cache-and-network"
112
+ }), C = a(f, {
113
+ variables: { context: l },
114
+ fetchPolicy: "cache-and-network"
115
+ }), w = a(u, {
116
+ variables: { context: l },
117
+ fetchPolicy: "cache-and-network",
118
+ skip: r.skipLibrary === !0
119
+ }), T = S.refetch, E = C.refetch, D = w.refetch, O = t(async (...e) => {
120
+ await Promise.all(e.map((e) => e().catch(() => void 0)));
121
+ }, []), [k] = i(h), [A] = i(g), [j] = i(_), [M] = i(v), [N] = i(y), [P] = i(b), [F] = i(x), I = t((e) => ({
122
+ ...e,
123
+ context: l
124
+ }), [l]);
125
+ return {
126
+ activeWithdrawals: S.data?.getHealthyBowlActiveWithdrawals ?? [],
127
+ summary: C.data?.getHealthyBowlWithdrawalSummary ?? null,
128
+ library: w.data?.getHealthyBowlMedicationLibrary ?? [],
129
+ loading: {
130
+ active: S.loading,
131
+ summary: C.loading,
132
+ library: w.loading
133
+ },
134
+ errors: {
135
+ active: S.error,
136
+ summary: C.error,
137
+ library: w.error
138
+ },
139
+ refetchAll: t(() => O(T, E, D), [
140
+ O,
141
+ T,
142
+ E,
143
+ D
144
+ ]),
145
+ refetchLibrary: D,
146
+ logTreatment: t(async (e) => {
147
+ let t = await k({ variables: { input: I(e) } });
148
+ if (t.error) throw t.error;
149
+ return await O(T, E), t.data?.logHealthyBowlMedicationTreatment ?? null;
150
+ }, [
151
+ k,
152
+ I,
153
+ O,
154
+ T,
155
+ E
156
+ ]),
157
+ updateTreatment: t(async (e) => {
158
+ let t = await A({ variables: { input: I(e) } });
159
+ if (t.error) throw t.error;
160
+ return await O(T, E), t.data;
161
+ }, [
162
+ A,
163
+ I,
164
+ O,
165
+ T,
166
+ E
167
+ ]),
168
+ deleteTreatment: t(async (e) => {
169
+ let t = await j({ variables: {
170
+ id: e,
171
+ context: l
172
+ } });
173
+ if (t.error) throw t.error;
174
+ await O(T, E);
175
+ }, [
176
+ j,
177
+ l,
178
+ O,
179
+ T,
180
+ E
181
+ ]),
182
+ createMedication: t(async (e) => {
183
+ let t = await M({ variables: { input: I(e) } });
184
+ if (t.error) throw t.error;
185
+ return await O(D), t.data?.createHealthyBowlMedicationLibraryItem ?? null;
186
+ }, [
187
+ M,
188
+ I,
189
+ O,
190
+ D
191
+ ]),
192
+ updateMedication: t(async (e) => {
193
+ let t = await N({ variables: { input: I(e) } });
194
+ if (t.error) throw t.error;
195
+ return await O(D), t.data?.updateHealthyBowlMedicationLibraryItem ?? null;
196
+ }, [
197
+ N,
198
+ I,
199
+ O,
200
+ D
201
+ ]),
202
+ deleteMedication: t(async (e) => {
203
+ let t = await P({ variables: {
204
+ id: e,
205
+ context: l
206
+ } });
207
+ if (t.error) throw t.error;
208
+ await O(D);
209
+ }, [
210
+ P,
211
+ l,
212
+ O,
213
+ D
214
+ ]),
215
+ runScan: t(async () => {
216
+ let e = await F({ variables: { context: l } });
217
+ if (e.error) throw e.error;
218
+ return await O(T, E), e.data?.runHealthyBowlWithdrawalScan ?? null;
219
+ }, [
220
+ F,
221
+ l,
222
+ O,
223
+ T,
224
+ E
225
+ ]),
226
+ documents: {
227
+ GET_ANIMAL_STATUS: p,
228
+ GET_CALENDAR: m,
229
+ GET_LIBRARY: u
230
+ },
231
+ context: l
232
+ };
233
+ }
234
+ //#endregion
235
+ export { p as GET_ANIMAL_STATUS, m as GET_CALENDAR, S as useHealthyBowlWithdrawal };
236
+
237
+ //# sourceMappingURL=useHealthyBowlWithdrawal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHealthyBowlWithdrawal.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlWithdrawal.ts"],"sourcesContent":["/**\n * Livestock Medication Withdrawal Alerts — data hook.\n * Roadmap 13 · BOFF-2885 · gap L-2.\n *\n * Documents are declared inline with `gql` (not as `src/operations/wspace/*.graphql`) because\n * codegen validates operations against the committed `graphql/wspace.graphql` snapshot, which\n * can't know about these fields until the subgraph is live in the supergraph — the same escape\n * hatch `useHealthyBowlCompliance` uses. Types mirror\n * `wspace-healthybowl-svc/src/modules/healthybowl/schema/withdrawal.gql`.\n *\n * Reads use `cache-and-network`; every write refetches the reads it invalidates.\n */\n\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\nconst FALLBACK_WORKSPACE_ID = '00000000-0000-0000-0000-000000000001';\n\n// ── types (mirror withdrawal.gql) ────────────────────────────────────────────\n\nexport type ProduceType = 'MILK' | 'MEAT' | 'EGGS';\nexport type WithdrawalStatus = 'NOT_APPLICABLE' | 'CLEARED' | 'UNDER_WITHDRAWAL' | 'BLOCKED';\nexport type MedicationSource = 'STANDARD' | 'CUSTOM';\n\nexport interface MedicationLibraryItem {\n id: string;\n name: string;\n className: string;\n route: string;\n milkWithdrawalDays: number | null;\n meatWithdrawalDays: number | null;\n eggsWithdrawalDays: number | null;\n species: string[];\n source: MedicationSource;\n builtin: boolean;\n}\n\nexport interface ProduceWithdrawalStatus {\n produceType: ProduceType;\n withdrawalDays: number | null;\n clearDate: string | null;\n status: WithdrawalStatus;\n blocked: boolean;\n daysLeft: number;\n}\n\nexport interface MedicationTreatment {\n id: string;\n animalId: string;\n animalTag: string;\n animalName: string;\n animalType: string;\n healthRecordId: string | null;\n medicationLibraryItemId: string | null;\n medicationName: string;\n className: string | null;\n dose: string | null;\n route: string | null;\n treatmentDate: string;\n administeredBy: string | null;\n notes: string | null;\n milkWithdrawalDays: number | null;\n meatWithdrawalDays: number | null;\n eggsWithdrawalDays: number | null;\n milkClearDate: string | null;\n meatClearDate: string | null;\n eggsClearDate: string | null;\n produceStatuses: ProduceWithdrawalStatus[];\n overallStatus: WithdrawalStatus;\n daysLeft: number;\n createdAt: string;\n}\n\nexport interface AnimalWithdrawalStatus {\n animalId: string;\n tagNumber: string;\n name: string;\n type: string;\n breed: string | null;\n location: string | null;\n overallStatus: WithdrawalStatus;\n blocked: boolean;\n produceStatuses: ProduceWithdrawalStatus[];\n treatments: MedicationTreatment[];\n}\n\nexport interface WithdrawalSummary {\n animalsUnderWithdrawal: number;\n productsBlocked: number;\n clearsNext48h: number;\n clearedThisWeek: number;\n}\n\nexport interface WithdrawalCalendarEntry {\n date: string;\n treatmentId: string;\n animalId: string;\n tagNumber: string;\n produceType: ProduceType;\n status: WithdrawalStatus;\n medicationName: string;\n}\n\nexport interface ProduceWithdrawalCheck {\n animalId: string;\n produceType: string;\n blocked: boolean;\n clearDate: string | null;\n daysLeft: number;\n reason: string | null;\n}\n\nexport interface WithdrawalScanResult {\n scannedAt: string;\n cleared: number;\n notificationsSent: number;\n}\n\ninterface HbContext {\n workspaceId: string;\n}\n\n// ── field fragments ───────────────────────────────────────────────────────────\n\nconst PRODUCE_STATUS_FIELDS = `\n produceType\n withdrawalDays\n clearDate\n status\n blocked\n daysLeft\n`;\n\nconst TREATMENT_FIELDS = `\n id\n animalId\n animalTag\n animalName\n animalType\n healthRecordId\n medicationLibraryItemId\n medicationName\n className\n dose\n route\n treatmentDate\n administeredBy\n notes\n milkWithdrawalDays\n meatWithdrawalDays\n eggsWithdrawalDays\n milkClearDate\n meatClearDate\n eggsClearDate\n produceStatuses { ${PRODUCE_STATUS_FIELDS} }\n overallStatus\n daysLeft\n createdAt\n`;\n\nconst LIBRARY_FIELDS = `\n id\n name\n className\n route\n milkWithdrawalDays\n meatWithdrawalDays\n eggsWithdrawalDays\n species\n source\n builtin\n`;\n\n// ── documents ───────────────────────────────────────────────────────────────\n\nconst GET_LIBRARY = gql`\n query GetHealthyBowlMedicationLibrary($context: ContextInput!, $search: String, $species: String, $source: String) {\n getHealthyBowlMedicationLibrary(context: $context, search: $search, species: $species, source: $source) { ${LIBRARY_FIELDS} }\n }\n`;\n\nconst GET_ACTIVE = gql`\n query GetHealthyBowlActiveWithdrawals($context: ContextInput!, $status: String) {\n getHealthyBowlActiveWithdrawals(context: $context, status: $status) { ${TREATMENT_FIELDS} }\n }\n`;\n\nconst GET_SUMMARY = gql`\n query GetHealthyBowlWithdrawalSummary($context: ContextInput!) {\n getHealthyBowlWithdrawalSummary(context: $context) {\n animalsUnderWithdrawal\n productsBlocked\n clearsNext48h\n clearedThisWeek\n }\n }\n`;\n\nconst GET_ANIMAL_STATUS = gql`\n query GetHealthyBowlAnimalWithdrawalStatus($context: ContextInput!, $animalId: ID!) {\n getHealthyBowlAnimalWithdrawalStatus(context: $context, animalId: $animalId) {\n animalId\n tagNumber\n name\n type\n breed\n location\n overallStatus\n blocked\n produceStatuses { ${PRODUCE_STATUS_FIELDS} }\n treatments { ${TREATMENT_FIELDS} }\n }\n }\n`;\n\nconst GET_CALENDAR = gql`\n query GetHealthyBowlWithdrawalCalendar($context: ContextInput!, $from: String, $to: String) {\n getHealthyBowlWithdrawalCalendar(context: $context, from: $from, to: $to) {\n date\n treatmentId\n animalId\n tagNumber\n produceType\n status\n medicationName\n }\n }\n`;\n\nconst LOG_TREATMENT = gql`\n mutation LogHealthyBowlMedicationTreatment($input: LogMedicationTreatmentInput!) {\n logHealthyBowlMedicationTreatment(input: $input) { ${TREATMENT_FIELDS} }\n }\n`;\nconst UPDATE_TREATMENT = gql`\n mutation UpdateHealthyBowlMedicationTreatment($input: UpdateMedicationTreatmentInput!) {\n updateHealthyBowlMedicationTreatment(input: $input) { ${TREATMENT_FIELDS} }\n }\n`;\nconst DELETE_TREATMENT = gql`\n mutation DeleteHealthyBowlMedicationTreatment($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlMedicationTreatment(id: $id, context: $context)\n }\n`;\nconst CREATE_LIB = gql`\n mutation CreateHealthyBowlMedicationLibraryItem($input: CreateMedicationLibraryItemInput!) {\n createHealthyBowlMedicationLibraryItem(input: $input) { ${LIBRARY_FIELDS} }\n }\n`;\nconst UPDATE_LIB = gql`\n mutation UpdateHealthyBowlMedicationLibraryItem($input: UpdateMedicationLibraryItemInput!) {\n updateHealthyBowlMedicationLibraryItem(input: $input) { ${LIBRARY_FIELDS} }\n }\n`;\nconst DELETE_LIB = gql`\n mutation DeleteHealthyBowlMedicationLibraryItem($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlMedicationLibraryItem(id: $id, context: $context)\n }\n`;\nconst RUN_SCAN = gql`\n mutation RunHealthyBowlWithdrawalScan($context: ContextInput!) {\n runHealthyBowlWithdrawalScan(context: $context) {\n scannedAt\n cleared\n notificationsSent\n }\n }\n`;\n\n// ── hook ───────────────────────────────────────────────────────────────────\n\nexport interface UseWithdrawalOptions {\n /** Skip the medication-library read on pages that only need the dashboard. */\n skipLibrary?: boolean;\n}\n\nexport function useHealthyBowlWithdrawal(options: UseWithdrawalOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n\n const activeQuery = useQuery<\n { getHealthyBowlActiveWithdrawals: MedicationTreatment[] },\n { context: HbContext; status?: string | null }\n >(GET_ACTIVE, { variables: { context: ctx }, fetchPolicy: 'cache-and-network' });\n\n const summaryQuery = useQuery<{ getHealthyBowlWithdrawalSummary: WithdrawalSummary }, { context: HbContext }>(\n GET_SUMMARY,\n {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n }\n );\n\n const libraryQuery = useQuery<{ getHealthyBowlMedicationLibrary: MedicationLibraryItem[] }, { context: HbContext }>(\n GET_LIBRARY,\n {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n skip: options.skipLibrary === true,\n }\n );\n\n const refetchActive = activeQuery.refetch;\n const refetchSummary = summaryQuery.refetch;\n const refetchLibrary = libraryQuery.refetch;\n\n const reconcile = useCallback(async (...refetchers: Array<() => Promise<unknown>>) => {\n await Promise.all(refetchers.map((run) => run().catch(() => undefined)));\n }, []);\n\n const [logTreatmentMutation] = useMutation<\n { logHealthyBowlMedicationTreatment: MedicationTreatment },\n { input: Record<string, unknown> }\n >(LOG_TREATMENT);\n const [updateTreatmentMutation] = useMutation(UPDATE_TREATMENT);\n const [deleteTreatmentMutation] = useMutation(DELETE_TREATMENT);\n const [createLibMutation] = useMutation<\n { createHealthyBowlMedicationLibraryItem: MedicationLibraryItem },\n { input: Record<string, unknown> }\n >(CREATE_LIB);\n const [updateLibMutation] = useMutation<\n { updateHealthyBowlMedicationLibraryItem: MedicationLibraryItem },\n { input: Record<string, unknown> }\n >(UPDATE_LIB);\n const [deleteLibMutation] = useMutation(DELETE_LIB);\n const [runScanMutation] = useMutation<{ runHealthyBowlWithdrawalScan: WithdrawalScanResult }, { context: HbContext }>(\n RUN_SCAN\n );\n\n const withCtx = useCallback((input: Record<string, unknown>) => ({ ...input, context: ctx }), [ctx]);\n\n return {\n activeWithdrawals: activeQuery.data?.getHealthyBowlActiveWithdrawals ?? [],\n summary: summaryQuery.data?.getHealthyBowlWithdrawalSummary ?? null,\n library: libraryQuery.data?.getHealthyBowlMedicationLibrary ?? [],\n\n loading: {\n active: activeQuery.loading,\n summary: summaryQuery.loading,\n library: libraryQuery.loading,\n },\n errors: {\n active: activeQuery.error,\n summary: summaryQuery.error,\n library: libraryQuery.error,\n },\n\n refetchAll: useCallback(\n () => reconcile(refetchActive, refetchSummary, refetchLibrary),\n [reconcile, refetchActive, refetchSummary, refetchLibrary]\n ),\n refetchLibrary,\n\n logTreatment: useCallback(\n async (input: Record<string, unknown>): Promise<MedicationTreatment | null> => {\n const res = await logTreatmentMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchActive, refetchSummary);\n return res.data?.logHealthyBowlMedicationTreatment ?? null;\n },\n [logTreatmentMutation, withCtx, reconcile, refetchActive, refetchSummary]\n ),\n updateTreatment: useCallback(\n async (input: Record<string, unknown>) => {\n const res = await updateTreatmentMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchActive, refetchSummary);\n return res.data;\n },\n [updateTreatmentMutation, withCtx, reconcile, refetchActive, refetchSummary]\n ),\n deleteTreatment: useCallback(\n async (id: string) => {\n const res = await deleteTreatmentMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchActive, refetchSummary);\n },\n [deleteTreatmentMutation, ctx, reconcile, refetchActive, refetchSummary]\n ),\n\n createMedication: useCallback(\n async (input: Record<string, unknown>): Promise<MedicationLibraryItem | null> => {\n const res = await createLibMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchLibrary);\n return res.data?.createHealthyBowlMedicationLibraryItem ?? null;\n },\n [createLibMutation, withCtx, reconcile, refetchLibrary]\n ),\n updateMedication: useCallback(\n async (input: Record<string, unknown>): Promise<MedicationLibraryItem | null> => {\n const res = await updateLibMutation({ variables: { input: withCtx(input) } });\n if (res.error) throw res.error;\n await reconcile(refetchLibrary);\n return res.data?.updateHealthyBowlMedicationLibraryItem ?? null;\n },\n [updateLibMutation, withCtx, reconcile, refetchLibrary]\n ),\n deleteMedication: useCallback(\n async (id: string) => {\n const res = await deleteLibMutation({ variables: { id, context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchLibrary);\n },\n [deleteLibMutation, ctx, reconcile, refetchLibrary]\n ),\n\n runScan: useCallback(async (): Promise<WithdrawalScanResult | null> => {\n const res = await runScanMutation({ variables: { context: ctx } });\n if (res.error) throw res.error;\n await reconcile(refetchActive, refetchSummary);\n return res.data?.runHealthyBowlWithdrawalScan ?? null;\n }, [runScanMutation, ctx, reconcile, refetchActive, refetchSummary]),\n\n documents: { GET_ANIMAL_STATUS, GET_CALENDAR, GET_LIBRARY },\n context: ctx,\n };\n}\n\nexport { GET_ANIMAL_STATUS, GET_CALENDAR };\n\nexport interface AnimalWithdrawalStatusData {\n getHealthyBowlAnimalWithdrawalStatus: AnimalWithdrawalStatus;\n}\nexport interface WithdrawalCalendarData {\n getHealthyBowlWithdrawalCalendar: WithdrawalCalendarEntry[];\n}\n"],"mappings":";;;;;AAkBA,IAAM,IAAwB,wCA4GxB,IAAwB,qFASxB,IAAmB;;;;;;;;;;;;;;;;;;;;;sBAqBH,EAAsB;;;;GAMtC,IAAiB,4IAejB,IAAc,CAAG;;gHAEyF,EAAe;;GAIzH,IAAa,CAAG;;4EAEsD,EAAiB;;GAIvF,IAAc,CAAG;;;;;;;;;GAWjB,IAAoB,CAAG;;;;;;;;;;;0BAWH,EAAsB;qBAC3B,EAAiB;;;GAKhC,IAAe,CAAG;;;;;;;;;;;;GAclB,IAAgB,CAAG;;yDAEgC,EAAiB;;GAGpE,IAAmB,CAAG;;4DAEgC,EAAiB;;GAGvE,IAAmB,CAAG;;;;GAKtB,IAAa,CAAG;;8DAEwC,EAAe;;GAGvE,IAAa,CAAG;;8DAEwC,EAAe;;GAGvE,IAAa,CAAG;;;;GAKhB,IAAW,CAAG;;;;;;;;;AAiBpB,SAAgB,EAAyB,IAAgC,EAAE,EAAE;CAC3E,IAAM,EAAE,mBAAgB,GAAgB,EAClC,IAAuB,KAAe,GACtC,IAAM,SAA0B,EAAE,aAAa,GAAsB,GAAG,CAAC,EAAqB,CAAC,EAE/F,IAAc,EAGlB,GAAY;EAAE,WAAW,EAAE,SAAS,GAAK;EAAE,aAAa;EAAqB,CAAC,EAE1E,IAAe,EACnB,GACA;EACE,WAAW,EAAE,SAAS,GAAK;EAC3B,aAAa;EACd,CACF,EAEK,IAAe,EACnB,GACA;EACE,WAAW,EAAE,SAAS,GAAK;EAC3B,aAAa;EACb,MAAM,EAAQ,gBAAgB;EAC/B,CACF,EAEK,IAAgB,EAAY,SAC5B,IAAiB,EAAa,SAC9B,IAAiB,EAAa,SAE9B,IAAY,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gCAAgC;KAChD;GAAC;GAAiB;GAAK;GAAW;GAAe;GAAe,CAAC;EAEpE,WAAW;GAAE;GAAmB;GAAc;GAAa;EAC3D,SAAS;EACV"}
@@ -0,0 +1,106 @@
1
+ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
+ import { useCallback as t } from "react";
3
+ import { gql as n } from "@apollo/client";
4
+ import { useMutation as r, useQuery as i } from "@apollo/client/react";
5
+ //#region src/healthybowl/hooks/usePlanExecution.ts
6
+ var a = n`
7
+ query HealthyBowlPlanExecution($context: ContextInput!, $plantingPlanId: ID!) {
8
+ healthyBowlPlantingPlanExecution(context: $context, plantingPlanId: $plantingPlanId) {
9
+ ${"\n plantingPlanId\n cropName\n fieldName\n status\n sowDate\n transplantDate\n plannedYield\n actualYield\n yieldVariancePct\n harvestCount\n harvests {\n id\n cropName\n harvestDate\n quantity\n unit\n qualityGrade\n status\n productId\n }\n activities {\n id\n type\n activityDate\n quantity\n unit\n laborHours\n notes\n }\n"}
10
+ }
11
+ }
12
+ `, o = n`
13
+ mutation HealthyBowlSetTransplantDate($input: UpdatePlantingPlanInput!) {
14
+ updateHealthyBowlPlantingPlan(input: $input) {
15
+ id
16
+ transplantDate
17
+ }
18
+ }
19
+ `, s = n`
20
+ mutation HealthyBowlCreatePlantingActivity($input: CreateHealthyBowlPlantingActivityInput!) {
21
+ createHealthyBowlPlantingActivity(input: $input) {
22
+ id
23
+ type
24
+ activityDate
25
+ }
26
+ }
27
+ `, c = n`
28
+ mutation HealthyBowlDeletePlantingActivity($id: ID!, $context: ContextInput!) {
29
+ deleteHealthyBowlPlantingActivity(id: $id, context: $context)
30
+ }
31
+ `, l = n`
32
+ mutation HealthyBowlCreateLinkedHarvest($input: CreateHarvestRecordInput!) {
33
+ createHealthyBowlHarvestRecord(input: $input) {
34
+ id
35
+ productId
36
+ plantingPlanId
37
+ }
38
+ }
39
+ `;
40
+ function u(n) {
41
+ let { workspaceId: u } = e(), d = { workspaceId: u }, { data: f, loading: p, error: m, refetch: h } = i(a, {
42
+ variables: {
43
+ context: d,
44
+ plantingPlanId: n ?? ""
45
+ },
46
+ skip: !u || !n,
47
+ fetchPolicy: "cache-and-network",
48
+ notifyOnNetworkStatusChange: !0
49
+ }), [g] = r(o), [_] = r(s), [v] = r(c), [y] = r(l), b = t(async (e) => {
50
+ n && (await g({ variables: { input: {
51
+ id: n,
52
+ transplantDate: e,
53
+ context: d
54
+ } } }), await h());
55
+ }, [
56
+ g,
57
+ h,
58
+ n,
59
+ u
60
+ ]), x = t(async (e) => {
61
+ n && (await _({ variables: { input: {
62
+ ...e,
63
+ plantingPlanId: n,
64
+ context: d
65
+ } } }), await h());
66
+ }, [
67
+ _,
68
+ h,
69
+ n,
70
+ u
71
+ ]), S = t(async (e) => {
72
+ await v({ variables: {
73
+ id: e,
74
+ context: d
75
+ } }), await h();
76
+ }, [
77
+ v,
78
+ h,
79
+ u
80
+ ]), C = t(async (e) => {
81
+ n && (await y({ variables: { input: {
82
+ ...e,
83
+ plantingPlanId: n,
84
+ context: d
85
+ } } }), await h());
86
+ }, [
87
+ y,
88
+ h,
89
+ n,
90
+ u
91
+ ]);
92
+ return {
93
+ execution: f?.healthyBowlPlantingPlanExecution,
94
+ loading: p,
95
+ error: m,
96
+ refetch: h,
97
+ setTransplantDate: b,
98
+ addActivity: x,
99
+ deleteActivity: S,
100
+ recordHarvest: C
101
+ };
102
+ }
103
+ //#endregion
104
+ export { u as usePlanExecution };
105
+
106
+ //# sourceMappingURL=usePlanExecution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlanExecution.js","names":[],"sources":["../../../src/healthybowl/hooks/usePlanExecution.ts"],"sourcesContent":["/**\n * Plan-execution data hook (roadmap I-7 + I-8).\n *\n * Wires the \"does the plan actually happen\" layer of crop planning:\n * • I-7 — transplant date + a watering/tilling/etc. activity log against a plan.\n * • I-8 — record a harvest linked back to this plan, optionally pushing the\n * harvested quantity into inventory, and read a planned-vs-actual rollup.\n *\n * Mirrors the raw-`gql` pattern used by {@link useSuccessionPlanning} — the\n * offline codegen doesn't type these operations, so they're hand-written\n * documents executed directly against the live gateway.\n * @module healthybowl\n */\nimport { useCallback } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\nexport interface PlanActivity {\n id: string;\n type: string;\n activityDate: string;\n quantity?: number | null;\n unit?: string | null;\n laborHours?: number | null;\n notes?: string | null;\n}\n\nexport interface PlanHarvest {\n id: string;\n cropName: string;\n harvestDate: string;\n quantity: number;\n unit: string;\n qualityGrade: string;\n status: string;\n productId?: string | null;\n}\n\nexport interface PlanExecution {\n plantingPlanId: string;\n cropName: string;\n fieldName: string;\n status: string;\n sowDate?: string | null;\n transplantDate?: string | null;\n plannedYield: number;\n actualYield: number;\n yieldVariancePct?: number | null;\n harvestCount: number;\n harvests: PlanHarvest[];\n activities: PlanActivity[];\n}\n\nexport interface ActivityInput {\n type: string;\n activityDate: string;\n quantity?: number | null;\n unit?: string | null;\n laborHours?: number | null;\n notes?: string | null;\n}\n\nexport interface HarvestInput {\n cropId: string;\n fieldId: string;\n quantity: number;\n unit?: string | null;\n quality: string;\n harvestDate: string;\n pricePerUnit?: number | null;\n addToInventory: boolean;\n}\n\nconst EXECUTION_FIELDS = `\n plantingPlanId\n cropName\n fieldName\n status\n sowDate\n transplantDate\n plannedYield\n actualYield\n yieldVariancePct\n harvestCount\n harvests {\n id\n cropName\n harvestDate\n quantity\n unit\n qualityGrade\n status\n productId\n }\n activities {\n id\n type\n activityDate\n quantity\n unit\n laborHours\n notes\n }\n`;\n\nconst EXECUTION_QUERY = gql`\n query HealthyBowlPlanExecution($context: ContextInput!, $plantingPlanId: ID!) {\n healthyBowlPlantingPlanExecution(context: $context, plantingPlanId: $plantingPlanId) {\n ${EXECUTION_FIELDS}\n }\n }\n`;\n\nconst SET_TRANSPLANT = gql`\n mutation HealthyBowlSetTransplantDate($input: UpdatePlantingPlanInput!) {\n updateHealthyBowlPlantingPlan(input: $input) {\n id\n transplantDate\n }\n }\n`;\n\nconst CREATE_ACTIVITY = gql`\n mutation HealthyBowlCreatePlantingActivity($input: CreateHealthyBowlPlantingActivityInput!) {\n createHealthyBowlPlantingActivity(input: $input) {\n id\n type\n activityDate\n }\n }\n`;\n\nconst DELETE_ACTIVITY = gql`\n mutation HealthyBowlDeletePlantingActivity($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPlantingActivity(id: $id, context: $context)\n }\n`;\n\nconst CREATE_HARVEST = gql`\n mutation HealthyBowlCreateLinkedHarvest($input: CreateHarvestRecordInput!) {\n createHealthyBowlHarvestRecord(input: $input) {\n id\n productId\n plantingPlanId\n }\n }\n`;\n\ninterface ExecutionQueryData {\n healthyBowlPlantingPlanExecution: PlanExecution;\n}\n\n/**\n * Loads the execution rollup for one plan and exposes helpers to log activities,\n * set the transplant date, and record a linked (optionally inventoried) harvest.\n * Every mutation refetches the rollup so planned-vs-actual stays live.\n */\nexport function usePlanExecution(plantingPlanId: string | undefined) {\n const { workspaceId } = useHealthyBowl();\n const context = { workspaceId };\n\n const { data, loading, error, refetch } = useQuery<ExecutionQueryData>(EXECUTION_QUERY, {\n variables: { context, plantingPlanId: plantingPlanId ?? '' },\n skip: !workspaceId || !plantingPlanId,\n fetchPolicy: 'cache-and-network',\n notifyOnNetworkStatusChange: true,\n });\n\n const [setTransplantMutation] = useMutation(SET_TRANSPLANT);\n const [createActivityMutation] = useMutation(CREATE_ACTIVITY);\n const [deleteActivityMutation] = useMutation(DELETE_ACTIVITY);\n const [createHarvestMutation] = useMutation(CREATE_HARVEST);\n\n const setTransplantDate = useCallback(\n async (transplantDate: string) => {\n if (!plantingPlanId) return;\n await setTransplantMutation({ variables: { input: { id: plantingPlanId, transplantDate, context } } });\n await refetch();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [setTransplantMutation, refetch, plantingPlanId, workspaceId]\n );\n\n const addActivity = useCallback(\n async (input: ActivityInput) => {\n if (!plantingPlanId) return;\n await createActivityMutation({ variables: { input: { ...input, plantingPlanId, context } } });\n await refetch();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [createActivityMutation, refetch, plantingPlanId, workspaceId]\n );\n\n const deleteActivity = useCallback(\n async (id: string) => {\n await deleteActivityMutation({ variables: { id, context } });\n await refetch();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [deleteActivityMutation, refetch, workspaceId]\n );\n\n const recordHarvest = useCallback(\n async (input: HarvestInput) => {\n if (!plantingPlanId) return;\n await createHarvestMutation({ variables: { input: { ...input, plantingPlanId, context } } });\n await refetch();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [createHarvestMutation, refetch, plantingPlanId, workspaceId]\n );\n\n return {\n execution: data?.healthyBowlPlantingPlanExecution,\n loading,\n error,\n refetch,\n setTransplantDate,\n addActivity,\n deleteActivity,\n recordHarvest,\n };\n}\n"],"mappings":";;;;;AA0GA,IAAM,IAAkB,CAAG;;;QAhCF,qYAmCA;;;GAKnB,IAAiB,CAAG;;;;;;;GASpB,IAAkB,CAAG;;;;;;;;GAUrB,IAAkB,CAAG;;;;GAMrB,IAAiB,CAAG;;;;;;;;;AAmB1B,SAAgB,EAAiB,GAAoC;CACnE,IAAM,EAAE,mBAAgB,GAAgB,EAClC,IAAU,EAAE,gBAAa,EAEzB,EAAE,SAAM,YAAS,UAAO,eAAY,EAA6B,GAAiB;EACtF,WAAW;GAAE;GAAS,gBAAgB,KAAkB;GAAI;EAC5D,MAAM,CAAC,KAAe,CAAC;EACvB,aAAa;EACb,6BAA6B;EAC9B,CAAC,EAEI,CAAC,KAAyB,EAAY,EAAe,EACrD,CAAC,KAA0B,EAAY,EAAgB,EACvD,CAAC,KAA0B,EAAY,EAAgB,EACvD,CAAC,KAAyB,EAAY,EAAe,EAErD,IAAoB,EACxB,OAAO,MAA2B;AAC3B,QACL,MAAM,EAAsB,EAAE,WAAW,EAAE,OAAO;GAAE,IAAI;GAAgB;GAAgB;GA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