@burdenoff/microfe-healthybowl 2026.902.37 → 2026.903.2
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/hooks/useAnalyticsReports.js +16 -9
- package/dist/healthybowl/hooks/useAnalyticsReports.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js +134 -78
- package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js.map +1 -1
- package/dist/healthybowl/pages/analytics/ReportsPage.js +31 -27
- package/dist/healthybowl/pages/analytics/ReportsPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/FinancialReportsPage.js +30 -26
- package/dist/healthybowl/pages/financial/FinancialReportsPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js +11 -7
- package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js.map +1 -1
- package/dist/healthybowl/pages/livestock/AnimalDepthPage.js +257 -215
- package/dist/healthybowl/pages/livestock/AnimalDepthPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/PedigreeTree.js +154 -0
- package/dist/healthybowl/pages/livestock/PedigreeTree.js.map +1 -0
- package/dist/healthybowl/pages/livestock/pedigreeLayout.js +68 -0
- package/dist/healthybowl/pages/livestock/pedigreeLayout.js.map +1 -0
- package/package.json +2 -1
|
@@ -103,10 +103,14 @@ function m(e) {
|
|
|
103
103
|
];
|
|
104
104
|
}
|
|
105
105
|
function h() {
|
|
106
|
-
let { workspaceId: i } = e(), l = i || "00000000-0000-0000-0000-000000000001", u = a(), [f] = o(s), [m, h] = r(
|
|
106
|
+
let { workspaceId: i } = e(), l = i || "00000000-0000-0000-0000-000000000001", u = a(), [f] = o(s), [m, h] = r(() => /* @__PURE__ */ new Set()), g = n(!1), _ = n(/* @__PURE__ */ new Set());
|
|
107
107
|
return {
|
|
108
108
|
generate: t(async (e) => {
|
|
109
|
-
|
|
109
|
+
if (g.current) return {
|
|
110
|
+
ok: !0,
|
|
111
|
+
started: !1
|
|
112
|
+
};
|
|
113
|
+
g.current = !0;
|
|
110
114
|
try {
|
|
111
115
|
let t = p(/* @__PURE__ */ new Date());
|
|
112
116
|
return await f({ variables: {
|
|
@@ -115,22 +119,26 @@ function h() {
|
|
|
115
119
|
type: e.type,
|
|
116
120
|
startDate: e.startDate ?? t.startDate,
|
|
117
121
|
endDate: e.endDate ?? t.endDate
|
|
118
|
-
} }), {
|
|
122
|
+
} }), {
|
|
123
|
+
ok: !0,
|
|
124
|
+
started: !0
|
|
125
|
+
};
|
|
119
126
|
} catch (e) {
|
|
120
127
|
return {
|
|
121
128
|
ok: !1,
|
|
129
|
+
started: !0,
|
|
122
130
|
message: d(e, "The report could not be generated.")
|
|
123
131
|
};
|
|
124
132
|
} finally {
|
|
125
|
-
|
|
133
|
+
g.current = !1;
|
|
126
134
|
}
|
|
127
135
|
}, [f, l]),
|
|
128
136
|
download: t(async (e) => {
|
|
129
|
-
if (
|
|
137
|
+
if (_.current.has(e)) return {
|
|
130
138
|
ok: !1,
|
|
131
139
|
message: "This report is already being prepared."
|
|
132
140
|
};
|
|
133
|
-
|
|
141
|
+
_.current.add(e), h(new Set(_.current));
|
|
134
142
|
try {
|
|
135
143
|
let { data: t } = await u.query({
|
|
136
144
|
query: c,
|
|
@@ -153,11 +161,10 @@ function h() {
|
|
|
153
161
|
message: d(e, "The report could not be downloaded.")
|
|
154
162
|
};
|
|
155
163
|
} finally {
|
|
156
|
-
|
|
164
|
+
_.current.delete(e), h(new Set(_.current));
|
|
157
165
|
}
|
|
158
166
|
}, [u, l]),
|
|
159
|
-
|
|
160
|
-
downloadingIds: g
|
|
167
|
+
downloadingIds: m
|
|
161
168
|
};
|
|
162
169
|
}
|
|
163
170
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAnalyticsReports.js","names":[],"sources":["../../../src/healthybowl/hooks/useAnalyticsReports.ts"],"sourcesContent":["/**\n * Generate and download analytics reports (BOFF-6022).\n *\n * Declared as inline `gql` documents rather than entries under `src/operations/`: these ops are\n * newer than the committed `graphql/wspace.graphql` snapshot that codegen validates against, and\n * this is the escape hatch the repo uses for exactly that case.\n *\n * @module healthybowl\n */\nimport { useCallback, useRef, useState } from 'react';\nimport { gql } from '@apollo/client';\nimport { useApolloClient, useMutation } from '@apollo/client/react';\nimport { HEALTHYBOWL_FALLBACK_WORKSPACE_ID, useHealthyBowl } from '../context/HealthyBowlContext';\n\nconst GENERATE_ANALYTICS_REPORT = gql`\n mutation GenerateHealthyBowlAnalyticsReport(\n $context: ContextInput!\n $title: String\n $type: String!\n $startDate: String!\n $endDate: String!\n ) {\n generateHealthyBowlAnalyticsReport(\n context: $context\n title: $title\n type: $type\n startDate: $startDate\n endDate: $endDate\n ) {\n id\n title\n type\n status\n period\n createdAt\n }\n }\n`;\n\nconst ANALYTICS_REPORT_EXPORT = gql`\n query GetHealthyBowlAnalyticsReportExport($context: ContextInput!, $reportId: ID!) {\n getHealthyBowlAnalyticsReportExport(context: $context, reportId: $reportId) {\n format\n filename\n mimeType\n contentBase64\n }\n }\n`;\n\n/** The report types the server can actually build today. */\nexport const GENERATABLE_REPORT_TYPES = [\n { value: 'FINANCIAL', labelKey: 'healthybowl.analytics.reports.type.financial', labelFallback: 'Financial' },\n { value: 'CROP', labelKey: 'healthybowl.analytics.reports.type.crop', labelFallback: 'Crop' },\n] as const;\n\nexport type GeneratableReportType = (typeof GENERATABLE_REPORT_TYPES)[number]['value'];\n\nexport function isGeneratableReportType(value: string): value is GeneratableReportType {\n return GENERATABLE_REPORT_TYPES.some((type) => type.value === value);\n}\n\n/**\n * Read the operator-facing message off a rejected operation.\n *\n * Apollo Client v4 rejects with `CombinedGraphQLErrors`, which has no v3 `graphQLErrors` property,\n * and the server puts the readable text in `extensions.userMessage` — for these ops that is the\n * sentence naming which report types CAN be generated. `err.message` alone would render Apollo's\n * aggregate wording and throw that away.\n */\nexport function readOperationError(err: unknown, fallback: string): string {\n if (err !== null && typeof err === 'object') {\n const shaped = err as { errors?: unknown; message?: unknown };\n if (Array.isArray(shaped.errors) && shaped.errors.length > 0) {\n const first = shaped.errors[0] as { message?: unknown; extensions?: { userMessage?: unknown } | null };\n const userMessage = first?.extensions?.userMessage;\n if (typeof userMessage === 'string' && userMessage.length > 0) return userMessage;\n if (typeof first?.message === 'string' && first.message.length > 0) return first.message;\n }\n if (typeof shaped.message === 'string' && shaped.message.length > 0) return shaped.message;\n }\n return fallback;\n}\n\n/**\n * `YYYY-MM-DD` in the farmer's OWN timezone.\n *\n * `toISOString().slice(0, 10)` would convert to UTC. For a farm in IST (UTC+5:30), any time between\n * midnight and 05:30 local yields the PREVIOUS day — so a report generated before dawn, which is\n * exactly when farm work happens, would silently end a day early. On 1 January it would compute\n * last year's 1 January as the start.\n */\nexport function toLocalDateString(date: Date): string {\n const pad = (n: number) => String(n).padStart(2, '0');\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n}\n\n/**\n * A sensible default period for a newly requested report.\n *\n * Year to date rather than \"this month\": a farmer generating a report usually wants the season so\n * far, and an empty January report would be the first thing a new user sees.\n */\nexport function defaultReportPeriod(now: Date): { startDate: string; endDate: string } {\n return { startDate: toLocalDateString(new Date(now.getFullYear(), 0, 1)), endDate: toLocalDateString(now) };\n}\n\n/**\n * Real period choices, computed from today rather than hard-coded.\n *\n * The financial page shipped a picker offering \"Q1 2025\" / \"Q4 2024\" — fixed strings that were\n * already stale and would only get staler. Generating a \"Q1 2025\" report in 2026 is worse than\n * defaulting to year-to-date, so the options are derived.\n */\nexport interface ReportPeriodOption {\n value: string;\n labelKey: string;\n labelFallback: string;\n startDate: string;\n endDate: string;\n}\n\nexport function reportPeriodOptions(now: Date): ReportPeriodOption[] {\n const year = now.getFullYear();\n const quarter = Math.floor(now.getMonth() / 3);\n const quarterStart = new Date(year, quarter * 3, 1);\n const prevQuarterStart = new Date(year, (quarter - 1) * 3, 1);\n // Day 0 of the following month is the last day of this one — no month-length table, no leap-year\n // special case.\n const prevQuarterEnd = new Date(year, quarter * 3, 0);\n\n return [\n {\n value: 'ytd',\n labelKey: 'healthybowl.financial.reports.generate.periods.ytd',\n labelFallback: 'Year to date',\n startDate: toLocalDateString(new Date(year, 0, 1)),\n endDate: toLocalDateString(now),\n },\n {\n value: 'this-quarter',\n labelKey: 'healthybowl.financial.reports.generate.periods.thisQuarter',\n labelFallback: 'This quarter',\n startDate: toLocalDateString(quarterStart),\n endDate: toLocalDateString(now),\n },\n {\n value: 'last-quarter',\n labelKey: 'healthybowl.financial.reports.generate.periods.lastQuarter',\n labelFallback: 'Last quarter',\n startDate: toLocalDateString(prevQuarterStart),\n endDate: toLocalDateString(prevQuarterEnd),\n },\n {\n value: 'last-year',\n labelKey: 'healthybowl.financial.reports.generate.periods.lastYear',\n labelFallback: 'Last year',\n startDate: toLocalDateString(new Date(year - 1, 0, 1)),\n endDate: toLocalDateString(new Date(year - 1, 11, 31)),\n },\n ];\n}\n\ninterface GenerateInput {\n title: string;\n type: GeneratableReportType;\n startDate?: string;\n endDate?: string;\n}\n\nexport interface ExportPayload {\n format: string;\n filename: string;\n mimeType: string;\n contentBase64: string;\n}\n\nexport type GenerateResult = { ok: true } | { ok: false; message: string };\nexport type DownloadResult = { ok: true; payload: ExportPayload } | { ok: false; message: string };\n\nexport function useAnalyticsReports(): {\n generate: (input: GenerateInput) => Promise<GenerateResult>;\n download: (reportId: string) => Promise<DownloadResult>;\n generating: boolean;\n downloadingIds: ReadonlySet<string>;\n} {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || HEALTHYBOWL_FALLBACK_WORKSPACE_ID;\n const client = useApolloClient();\n const [mutate] = useMutation(GENERATE_ANALYTICS_REPORT);\n const [generating, setGenerating] = useState(false);\n const [downloadingIds, setDownloadingIds] = useState<ReadonlySet<string>>(() => new Set());\n // State updates render the pending status; the ref also rejects two same-tick clicks before React\n // has rendered that disabled state.\n const downloadingIdsRef = useRef(new Set<string>());\n\n const generate = useCallback(\n async (input: GenerateInput) => {\n setGenerating(true);\n try {\n const period = defaultReportPeriod(new Date());\n await mutate({\n variables: {\n context: { workspaceId: effectiveWorkspaceId },\n title: input.title,\n type: input.type,\n startDate: input.startDate ?? period.startDate,\n endDate: input.endDate ?? period.endDate,\n },\n });\n return { ok: true } as const;\n } catch (err) {\n return { ok: false, message: readOperationError(err, 'The report could not be generated.') } as const;\n } finally {\n setGenerating(false);\n }\n },\n [mutate, effectiveWorkspaceId]\n );\n\n const download = useCallback(\n async (reportId: string) => {\n if (downloadingIdsRef.current.has(reportId)) {\n return { ok: false, message: 'This report is already being prepared.' } as const;\n }\n downloadingIdsRef.current.add(reportId);\n setDownloadingIds(new Set(downloadingIdsRef.current));\n try {\n const { data } = await client.query({\n query: ANALYTICS_REPORT_EXPORT,\n variables: { context: { workspaceId: effectiveWorkspaceId }, reportId },\n // Always refetched: a cached copy would hand back the previous report's bytes when the\n // farmer downloads a second one in the same session.\n fetchPolicy: 'network-only',\n });\n const payload = (data as { getHealthyBowlAnalyticsReportExport?: ExportPayload } | null)\n ?.getHealthyBowlAnalyticsReportExport;\n if (!payload?.contentBase64) {\n return { ok: false, message: 'The report file could not be produced.' } as const;\n }\n return { ok: true, payload } as const;\n } catch (err) {\n return { ok: false, message: readOperationError(err, 'The report could not be downloaded.') } as const;\n } finally {\n downloadingIdsRef.current.delete(reportId);\n setDownloadingIds(new Set(downloadingIdsRef.current));\n }\n },\n [client, effectiveWorkspaceId]\n );\n\n return { generate, download, generating, downloadingIds };\n}\n"],"mappings":";;;;;AAcA,IAAM,IAA4B,CAAG;;;;;;;;;;;;;;;;;;;;;;;GAyB/B,IAA0B,CAAG;;;;;;;;;GAYtB,IAA2B,CACtC;CAAE,OAAO;CAAa,UAAU;CAAgD,eAAe;AAAY,GAC3G;CAAE,OAAO;CAAQ,UAAU;CAA2C,eAAe;AAAO,CAC9F;AAIA,SAAgB,EAAwB,GAA+C;CACrF,OAAO,EAAyB,MAAM,MAAS,EAAK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ACtC,EAAkB,IAAI,IAAI,EAAkB,OAAO,CAAC;GACpD,IAAI;IACF,IAAM,EAAE,YAAS,MAAM,EAAO,MAAM;KAClC,OAAO;KACP,WAAW;MAAE,SAAS,EAAE,aAAa,EAAqB;MAAG;KAAS;KAGtE,aAAa;IACf,CAAC,GACK,IAAW,GACb;IAIJ,OAHK,GAAS,gBAGP;KAAE,IAAI;KAAM;IAAQ,IAFlB;KAAE,IAAI;KAAO,SAAS;IAAyC;GAG1E,SAAS,GAAK;IACZ,OAAO;KAAE,IAAI;KAAO,SAAS,EAAmB,GAAK,qCAAqC;IAAE;GAC9F,UAAU;IAER,AADA,EAAkB,QAAQ,OAAO,CAAQ,GACzC,EAAkB,IAAI,IAAI,EAAkB,OAAO,CAAC;GACtD;EACF,GACA,CAAC,GAAQ,CAAoB,CAGZ;EAAU;EAAY;CAAe;AAC1D"}
|
|
1
|
+
{"version":3,"file":"useAnalyticsReports.js","names":[],"sources":["../../../src/healthybowl/hooks/useAnalyticsReports.ts"],"sourcesContent":["/**\n * Generate and download analytics reports (BOFF-6022).\n *\n * Declared as inline `gql` documents rather than entries under `src/operations/`: these ops are\n * newer than the committed `graphql/wspace.graphql` snapshot that codegen validates against, and\n * this is the escape hatch the repo uses for exactly that case.\n *\n * @module healthybowl\n */\nimport { useCallback, useRef, useState } from 'react';\nimport { gql } from '@apollo/client';\nimport { useApolloClient, useMutation } from '@apollo/client/react';\nimport { HEALTHYBOWL_FALLBACK_WORKSPACE_ID, useHealthyBowl } from '../context/HealthyBowlContext';\n\nconst GENERATE_ANALYTICS_REPORT = gql`\n mutation GenerateHealthyBowlAnalyticsReport(\n $context: ContextInput!\n $title: String\n $type: String!\n $startDate: String!\n $endDate: String!\n ) {\n generateHealthyBowlAnalyticsReport(\n context: $context\n title: $title\n type: $type\n startDate: $startDate\n endDate: $endDate\n ) {\n id\n title\n type\n status\n period\n createdAt\n }\n }\n`;\n\nconst ANALYTICS_REPORT_EXPORT = gql`\n query GetHealthyBowlAnalyticsReportExport($context: ContextInput!, $reportId: ID!) {\n getHealthyBowlAnalyticsReportExport(context: $context, reportId: $reportId) {\n format\n filename\n mimeType\n contentBase64\n }\n }\n`;\n\n/** The report types the server can actually build today. */\nexport const GENERATABLE_REPORT_TYPES = [\n { value: 'FINANCIAL', labelKey: 'healthybowl.analytics.reports.type.financial', labelFallback: 'Financial' },\n { value: 'CROP', labelKey: 'healthybowl.analytics.reports.type.crop', labelFallback: 'Crop' },\n] as const;\n\nexport type GeneratableReportType = (typeof GENERATABLE_REPORT_TYPES)[number]['value'];\n\nexport function isGeneratableReportType(value: string): value is GeneratableReportType {\n return GENERATABLE_REPORT_TYPES.some((type) => type.value === value);\n}\n\n/**\n * Read the operator-facing message off a rejected operation.\n *\n * Apollo Client v4 rejects with `CombinedGraphQLErrors`, which has no v3 `graphQLErrors` property,\n * and the server puts the readable text in `extensions.userMessage` — for these ops that is the\n * sentence naming which report types CAN be generated. `err.message` alone would render Apollo's\n * aggregate wording and throw that away.\n */\nexport function readOperationError(err: unknown, fallback: string): string {\n if (err !== null && typeof err === 'object') {\n const shaped = err as { errors?: unknown; message?: unknown };\n if (Array.isArray(shaped.errors) && shaped.errors.length > 0) {\n const first = shaped.errors[0] as { message?: unknown; extensions?: { userMessage?: unknown } | null };\n const userMessage = first?.extensions?.userMessage;\n if (typeof userMessage === 'string' && userMessage.length > 0) return userMessage;\n if (typeof first?.message === 'string' && first.message.length > 0) return first.message;\n }\n if (typeof shaped.message === 'string' && shaped.message.length > 0) return shaped.message;\n }\n return fallback;\n}\n\n/**\n * `YYYY-MM-DD` in the farmer's OWN timezone.\n *\n * `toISOString().slice(0, 10)` would convert to UTC. For a farm in IST (UTC+5:30), any time between\n * midnight and 05:30 local yields the PREVIOUS day — so a report generated before dawn, which is\n * exactly when farm work happens, would silently end a day early. On 1 January it would compute\n * last year's 1 January as the start.\n */\nexport function toLocalDateString(date: Date): string {\n const pad = (n: number) => String(n).padStart(2, '0');\n return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;\n}\n\n/**\n * A sensible default period for a newly requested report.\n *\n * Year to date rather than \"this month\": a farmer generating a report usually wants the season so\n * far, and an empty January report would be the first thing a new user sees.\n */\nexport function defaultReportPeriod(now: Date): { startDate: string; endDate: string } {\n return { startDate: toLocalDateString(new Date(now.getFullYear(), 0, 1)), endDate: toLocalDateString(now) };\n}\n\n/**\n * Real period choices, computed from today rather than hard-coded.\n *\n * The financial page shipped a picker offering \"Q1 2025\" / \"Q4 2024\" — fixed strings that were\n * already stale and would only get staler. Generating a \"Q1 2025\" report in 2026 is worse than\n * defaulting to year-to-date, so the options are derived.\n */\nexport interface ReportPeriodOption {\n value: string;\n labelKey: string;\n labelFallback: string;\n startDate: string;\n endDate: string;\n}\n\nexport function reportPeriodOptions(now: Date): ReportPeriodOption[] {\n const year = now.getFullYear();\n const quarter = Math.floor(now.getMonth() / 3);\n const quarterStart = new Date(year, quarter * 3, 1);\n const prevQuarterStart = new Date(year, (quarter - 1) * 3, 1);\n // Day 0 of the following month is the last day of this one — no month-length table, no leap-year\n // special case.\n const prevQuarterEnd = new Date(year, quarter * 3, 0);\n\n return [\n {\n value: 'ytd',\n labelKey: 'healthybowl.financial.reports.generate.periods.ytd',\n labelFallback: 'Year to date',\n startDate: toLocalDateString(new Date(year, 0, 1)),\n endDate: toLocalDateString(now),\n },\n {\n value: 'this-quarter',\n labelKey: 'healthybowl.financial.reports.generate.periods.thisQuarter',\n labelFallback: 'This quarter',\n startDate: toLocalDateString(quarterStart),\n endDate: toLocalDateString(now),\n },\n {\n value: 'last-quarter',\n labelKey: 'healthybowl.financial.reports.generate.periods.lastQuarter',\n labelFallback: 'Last quarter',\n startDate: toLocalDateString(prevQuarterStart),\n endDate: toLocalDateString(prevQuarterEnd),\n },\n {\n value: 'last-year',\n labelKey: 'healthybowl.financial.reports.generate.periods.lastYear',\n labelFallback: 'Last year',\n startDate: toLocalDateString(new Date(year - 1, 0, 1)),\n endDate: toLocalDateString(new Date(year - 1, 11, 31)),\n },\n ];\n}\n\ninterface GenerateInput {\n title: string;\n type: GeneratableReportType;\n startDate?: string;\n endDate?: string;\n}\n\nexport interface ExportPayload {\n format: string;\n filename: string;\n mimeType: string;\n contentBase64: string;\n}\n\nexport type GenerateResult =\n { ok: true; started: true } | { ok: true; started: false } | { ok: false; started: true; message: string };\nexport type DownloadResult = { ok: true; payload: ExportPayload } | { ok: false; message: string };\n\nexport function useAnalyticsReports(): {\n generate: (input: GenerateInput) => Promise<GenerateResult>;\n download: (reportId: string) => Promise<DownloadResult>;\n downloadingIds: ReadonlySet<string>;\n} {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || HEALTHYBOWL_FALLBACK_WORKSPACE_ID;\n const client = useApolloClient();\n const [mutate] = useMutation(GENERATE_ANALYTICS_REPORT);\n const [downloadingIds, setDownloadingIds] = useState<ReadonlySet<string>>(() => new Set());\n // Both operations use refs to reject duplicate same-tick clicks before React has rendered the\n // consuming page's disabled button state.\n const generatingRef = useRef(false);\n const downloadingIdsRef = useRef(new Set<string>());\n\n const generate = useCallback(\n async (input: GenerateInput) => {\n if (generatingRef.current) return { ok: true, started: false } as const;\n generatingRef.current = true;\n try {\n const period = defaultReportPeriod(new Date());\n await mutate({\n variables: {\n context: { workspaceId: effectiveWorkspaceId },\n title: input.title,\n type: input.type,\n startDate: input.startDate ?? period.startDate,\n endDate: input.endDate ?? period.endDate,\n },\n });\n return { ok: true, started: true } as const;\n } catch (err) {\n return {\n ok: false,\n started: true,\n message: readOperationError(err, 'The report could not be generated.'),\n } as const;\n } finally {\n generatingRef.current = false;\n }\n },\n [mutate, effectiveWorkspaceId]\n );\n\n const download = useCallback(\n async (reportId: string) => {\n if (downloadingIdsRef.current.has(reportId)) {\n return { ok: false, message: 'This report is already being prepared.' } as const;\n }\n downloadingIdsRef.current.add(reportId);\n setDownloadingIds(new Set(downloadingIdsRef.current));\n try {\n const { data } = await client.query({\n query: ANALYTICS_REPORT_EXPORT,\n variables: { context: { workspaceId: effectiveWorkspaceId }, reportId },\n // Always refetched: a cached copy would hand back the previous report's bytes when the\n // farmer downloads a second one in the same session.\n fetchPolicy: 'network-only',\n });\n const payload = (data as { getHealthyBowlAnalyticsReportExport?: ExportPayload } | null)\n ?.getHealthyBowlAnalyticsReportExport;\n if (!payload?.contentBase64) {\n return { ok: false, message: 'The report file could not be produced.' } as const;\n }\n return { ok: true, payload } as const;\n } catch (err) {\n return { ok: false, message: readOperationError(err, 'The report could not be downloaded.') } as const;\n } finally {\n downloadingIdsRef.current.delete(reportId);\n setDownloadingIds(new Set(downloadingIdsRef.current));\n }\n },\n [client, effectiveWorkspaceId]\n );\n\n return { generate, download, downloadingIds };\n}\n"],"mappings":";;;;;AAcA,IAAM,IAA4B,CAAG;;;;;;;;;;;;;;;;;;;;;;;GAyB/B,IAA0B,CAAG;;;;;;;;;GAYtB,IAA2B,CACtC;CAAE,OAAO;CAAa,UAAU;CAAgD,eAAe;AAAY,GAC3G;CAAE,OAAO;CAAQ,UAAU;CAA2C,eAAe;AAAO,CAC9F;AAIA,SAAgB,EAAwB,GAA+C;CACrF,OAAO,EAAyB,MAAM,MAAS,EAAK,UAAU,CAAK;AACrE;AAUA,SAAgB,EAAmB,GAAc,GAA0B;CACzE,IAAoB,OAAO,KAAQ,YAA/B,GAAyC;EAC3C,IAAM,IAAS;EACf,IAAI,MAAM,QAAQ,EAAO,MAAM,KAAK,EAAO,OAAO,SAAS,GAAG;GAC5D,IAAM,IAAQ,EAAO,OAAO,IACtB,IAAc,GAAO,YAAY;GACvC,IAAI,OAAO,KAAgB,YAAY,EAAY,SAAS,GAAG,OAAO;GACtE,IAAI,OAAO,GAAO,WAAY,YAAY,EAAM,QAAQ,SAAS,GAAG,OAAO,EAAM;EACnF;EACA,IAAI,OAAO,EAAO,WAAY,YAAY,EAAO,QAAQ,SAAS,GAAG,OAAO,EAAO;CACrF;CACA,OAAO;AACT;AAUA,SAAgB,EAAkB,GAAoB;CACpD,IAAM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AkB,IAAI,IAAI,EAAkB,OAAO,CAAC;GACtD;EACF,GACA,CAAC,GAAQ,CAAoB,CAGZ;EAAU;CAAe;AAC9C"}
|
|
@@ -16,7 +16,10 @@ var o = "00000000-0000-0000-0000-000000000001", s = "\n status\n blocked\n en
|
|
|
16
16
|
latestWeightKg
|
|
17
17
|
latestWeightAt
|
|
18
18
|
withdrawal { ${s} }
|
|
19
|
-
`, u =
|
|
19
|
+
`, u = `
|
|
20
|
+
${l}
|
|
21
|
+
archived
|
|
22
|
+
`, d = "\n id\n animalId\n weightKg\n measuredAt\n method\n notes\n createdAt\n", f = `
|
|
20
23
|
animalId
|
|
21
24
|
tagNumber
|
|
22
25
|
eidTag
|
|
@@ -29,17 +32,19 @@ var o = "00000000-0000-0000-0000-000000000001", s = "\n status\n blocked\n en
|
|
|
29
32
|
bodyConditionScore
|
|
30
33
|
damId
|
|
31
34
|
damTag
|
|
35
|
+
damArchived
|
|
32
36
|
sireId
|
|
33
37
|
sireTag
|
|
38
|
+
sireArchived
|
|
34
39
|
grazingPaddock
|
|
35
40
|
rotationDate
|
|
36
41
|
grazingNotes
|
|
37
42
|
adgKgPerDay
|
|
38
43
|
latestWeightKg
|
|
39
44
|
latestWeightAt
|
|
40
|
-
weightHistory { ${
|
|
45
|
+
weightHistory { ${d} }
|
|
41
46
|
withdrawal { ${s} }
|
|
42
|
-
`,
|
|
47
|
+
`, p = r`
|
|
43
48
|
query HealthyBowlHerdDepth($context: ContextInput!, $groupId: ID, $search: String) {
|
|
44
49
|
healthyBowlHerdDepth(context: $context, groupId: $groupId, search: $search) {
|
|
45
50
|
truncated
|
|
@@ -48,154 +53,205 @@ var o = "00000000-0000-0000-0000-000000000001", s = "\n status\n blocked\n en
|
|
|
48
53
|
groups { ${c} }
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
|
-
`,
|
|
56
|
+
`, m = r`
|
|
57
|
+
query HealthyBowlHerdDepthWithArchived(
|
|
58
|
+
$context: ContextInput!
|
|
59
|
+
$groupId: ID
|
|
60
|
+
$search: String
|
|
61
|
+
$includeArchived: Boolean
|
|
62
|
+
) {
|
|
63
|
+
healthyBowlHerdDepth(context: $context, groupId: $groupId, search: $search, includeArchived: $includeArchived) {
|
|
64
|
+
truncated
|
|
65
|
+
rows { ${u} }
|
|
66
|
+
summary { totalAnimals animalsInWithdrawal animalsClear complianceMessage }
|
|
67
|
+
groups { ${c} }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
`, h = "\n animalId tagNumber name type breed gender dateOfBirth generation relation archived childAnimalId\n", g = r`
|
|
71
|
+
query HealthyBowlAnimalPedigree($context: ContextInput!, $animalId: ID!, $ancestorDepth: Int, $offspringDepth: Int) {
|
|
72
|
+
healthyBowlAnimalPedigree(
|
|
73
|
+
context: $context
|
|
74
|
+
animalId: $animalId
|
|
75
|
+
ancestorDepth: $ancestorDepth
|
|
76
|
+
offspringDepth: $offspringDepth
|
|
77
|
+
) {
|
|
78
|
+
root { ${h} }
|
|
79
|
+
ancestors { ${h} }
|
|
80
|
+
offspring { ${"\n animalId tagNumber name type gender dateOfBirth generation viaParent archived parentAnimalId parentAnimalIds\n"} }
|
|
81
|
+
truncated
|
|
82
|
+
cycleDetected
|
|
83
|
+
ancestorDepth
|
|
84
|
+
offspringDepth
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
`, _ = r`
|
|
52
88
|
query HealthyBowlAnimalDepth($context: ContextInput!, $animalId: ID!) {
|
|
53
|
-
healthyBowlAnimalDepth(context: $context, animalId: $animalId) { ${
|
|
89
|
+
healthyBowlAnimalDepth(context: $context, animalId: $animalId) { ${f} }
|
|
54
90
|
}
|
|
55
|
-
`,
|
|
91
|
+
`, v = r`
|
|
56
92
|
query HealthyBowlAnimalGroups($context: ContextInput!) {
|
|
57
93
|
healthyBowlAnimalGroups(context: $context) { ${c} }
|
|
58
94
|
}
|
|
59
|
-
`,
|
|
95
|
+
`, y = r`
|
|
60
96
|
mutation UpdateHealthyBowlAnimalDepth($input: UpdateHealthyBowlAnimalDepthInput!) {
|
|
61
|
-
updateHealthyBowlAnimalDepth(input: $input) { ${
|
|
97
|
+
updateHealthyBowlAnimalDepth(input: $input) { ${f} }
|
|
62
98
|
}
|
|
63
|
-
`,
|
|
99
|
+
`, b = r`
|
|
64
100
|
mutation CreateHealthyBowlAnimalGroup($input: CreateHealthyBowlAnimalGroupInput!) {
|
|
65
101
|
createHealthyBowlAnimalGroup(input: $input) { ${c} }
|
|
66
102
|
}
|
|
67
|
-
`,
|
|
103
|
+
`, x = r`
|
|
68
104
|
mutation UpdateHealthyBowlAnimalGroup($input: UpdateHealthyBowlAnimalGroupInput!) {
|
|
69
105
|
updateHealthyBowlAnimalGroup(input: $input) { ${c} }
|
|
70
106
|
}
|
|
71
|
-
`,
|
|
107
|
+
`, S = r`
|
|
72
108
|
mutation DeleteHealthyBowlAnimalGroup($id: ID!, $context: ContextInput!) {
|
|
73
109
|
deleteHealthyBowlAnimalGroup(id: $id, context: $context)
|
|
74
110
|
}
|
|
75
|
-
`,
|
|
111
|
+
`, C = r`
|
|
76
112
|
mutation RecordHealthyBowlAnimalWeight($input: RecordHealthyBowlAnimalWeightInput!) {
|
|
77
|
-
recordHealthyBowlAnimalWeight(input: $input) { ${
|
|
113
|
+
recordHealthyBowlAnimalWeight(input: $input) { ${d} }
|
|
78
114
|
}
|
|
79
|
-
`,
|
|
115
|
+
`, w = r`
|
|
80
116
|
mutation DeleteHealthyBowlAnimalWeight($id: ID!, $context: ContextInput!) {
|
|
81
117
|
deleteHealthyBowlAnimalWeight(id: $id, context: $context)
|
|
82
118
|
}
|
|
83
119
|
`;
|
|
84
|
-
function
|
|
85
|
-
let { workspaceId: s } = e(), c = s || o, l = n(() => ({ workspaceId: c }), [c]), u = r.herd === !0, d = r.groups === !0,
|
|
86
|
-
variables: {
|
|
120
|
+
function T(r = {}) {
|
|
121
|
+
let { workspaceId: s } = e(), c = s || o, l = n(() => ({ workspaceId: c }), [c]), u = r.herd === !0, d = r.groups === !0, f = r.animalId ?? null, h = r.herdGroupId ?? null, T = r.herdSearch ?? null, E = r.herdIncludeArchived ?? !1, D = a(E ? m : p, {
|
|
122
|
+
variables: E ? {
|
|
87
123
|
context: l,
|
|
88
|
-
groupId:
|
|
89
|
-
search:
|
|
124
|
+
groupId: h,
|
|
125
|
+
search: T,
|
|
126
|
+
includeArchived: !0
|
|
127
|
+
} : {
|
|
128
|
+
context: l,
|
|
129
|
+
groupId: h,
|
|
130
|
+
search: T
|
|
90
131
|
},
|
|
91
132
|
fetchPolicy: "cache-and-network",
|
|
92
133
|
skip: !u
|
|
93
|
-
}),
|
|
134
|
+
}), O = a(v, {
|
|
94
135
|
variables: { context: l },
|
|
95
136
|
fetchPolicy: "cache-and-network",
|
|
96
137
|
skip: !d
|
|
97
|
-
}),
|
|
138
|
+
}), k = a(_, {
|
|
98
139
|
variables: {
|
|
99
140
|
context: l,
|
|
100
|
-
animalId:
|
|
141
|
+
animalId: f ?? ""
|
|
101
142
|
},
|
|
102
143
|
fetchPolicy: "cache-and-network",
|
|
103
|
-
skip: !
|
|
104
|
-
}),
|
|
144
|
+
skip: !f
|
|
145
|
+
}), A = a(g, {
|
|
146
|
+
variables: {
|
|
147
|
+
context: l,
|
|
148
|
+
animalId: f ?? "",
|
|
149
|
+
ancestorDepth: r.pedigreeAncestorDepth ?? null,
|
|
150
|
+
offspringDepth: null
|
|
151
|
+
},
|
|
152
|
+
fetchPolicy: "cache-and-network",
|
|
153
|
+
skip: !f || r.pedigree !== !0
|
|
154
|
+
}), [j] = i(y), [M] = i(b), [N] = i(x), [P] = i(S), [F] = i(C), [I] = i(w), L = t(() => D.refetch(), [D]), R = t(() => O.refetch(), [O]), z = t(() => k.refetch(), [k]), B = t(() => A.refetch(), [A]), V = r.pedigree === !0, H = t(async () => {
|
|
105
155
|
let e = [];
|
|
106
|
-
u && e.push(
|
|
156
|
+
u && e.push(L().catch(() => void 0)), d && e.push(R().catch(() => void 0)), f && e.push(z().catch(() => void 0)), f && V && e.push(B().catch(() => void 0)), await Promise.all(e);
|
|
107
157
|
}, [
|
|
108
158
|
u,
|
|
109
159
|
d,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
160
|
+
f,
|
|
161
|
+
V,
|
|
162
|
+
L,
|
|
163
|
+
R,
|
|
164
|
+
z,
|
|
165
|
+
B
|
|
166
|
+
]), U = t(async (e) => {
|
|
167
|
+
let t = await j({ variables: { input: {
|
|
116
168
|
...e,
|
|
117
169
|
context: l
|
|
118
170
|
} } });
|
|
119
|
-
return await
|
|
171
|
+
return await H(), t.data?.updateHealthyBowlAnimalDepth;
|
|
120
172
|
}, [
|
|
121
|
-
|
|
173
|
+
j,
|
|
122
174
|
l,
|
|
123
|
-
|
|
124
|
-
]),
|
|
125
|
-
let t = await
|
|
175
|
+
H
|
|
176
|
+
]), W = t(async (e) => {
|
|
177
|
+
let t = await M({ variables: { input: {
|
|
126
178
|
...e,
|
|
127
179
|
context: l
|
|
128
180
|
} } });
|
|
129
|
-
return await
|
|
181
|
+
return await H(), t.data?.createHealthyBowlAnimalGroup;
|
|
130
182
|
}, [
|
|
131
|
-
|
|
183
|
+
M,
|
|
132
184
|
l,
|
|
133
|
-
|
|
134
|
-
]),
|
|
135
|
-
let t = await
|
|
185
|
+
H
|
|
186
|
+
]), G = t(async (e) => {
|
|
187
|
+
let t = await N({ variables: { input: {
|
|
136
188
|
...e,
|
|
137
189
|
context: l
|
|
138
190
|
} } });
|
|
139
|
-
return await
|
|
191
|
+
return await H(), t.data?.updateHealthyBowlAnimalGroup;
|
|
140
192
|
}, [
|
|
141
|
-
|
|
193
|
+
N,
|
|
142
194
|
l,
|
|
143
|
-
|
|
144
|
-
]),
|
|
145
|
-
await
|
|
195
|
+
H
|
|
196
|
+
]), K = t(async (e) => {
|
|
197
|
+
await P({ variables: {
|
|
146
198
|
id: e,
|
|
147
199
|
context: l
|
|
148
|
-
} }), await
|
|
200
|
+
} }), await H();
|
|
149
201
|
}, [
|
|
150
|
-
|
|
202
|
+
P,
|
|
151
203
|
l,
|
|
152
|
-
|
|
153
|
-
]),
|
|
154
|
-
let t = await
|
|
204
|
+
H
|
|
205
|
+
]), q = t(async (e) => {
|
|
206
|
+
let t = await F({ variables: { input: {
|
|
155
207
|
...e,
|
|
156
208
|
context: l
|
|
157
209
|
} } });
|
|
158
|
-
return await
|
|
210
|
+
return await H(), t.data?.recordHealthyBowlAnimalWeight;
|
|
159
211
|
}, [
|
|
160
|
-
|
|
212
|
+
F,
|
|
161
213
|
l,
|
|
162
|
-
|
|
163
|
-
]),
|
|
164
|
-
await
|
|
214
|
+
H
|
|
215
|
+
]), J = t(async (e) => {
|
|
216
|
+
await I({ variables: {
|
|
165
217
|
id: e,
|
|
166
218
|
context: l
|
|
167
|
-
} }), await
|
|
219
|
+
} }), await H();
|
|
168
220
|
}, [
|
|
169
|
-
|
|
221
|
+
I,
|
|
170
222
|
l,
|
|
171
|
-
|
|
223
|
+
H
|
|
172
224
|
]);
|
|
173
225
|
return {
|
|
174
|
-
herd:
|
|
175
|
-
groups:
|
|
176
|
-
animalDepth:
|
|
226
|
+
herd: D.data?.healthyBowlHerdDepth ?? null,
|
|
227
|
+
groups: O.data?.healthyBowlAnimalGroups ?? D.data?.healthyBowlHerdDepth?.groups ?? [],
|
|
228
|
+
animalDepth: k.data?.healthyBowlAnimalDepth ?? null,
|
|
229
|
+
pedigree: A.data?.healthyBowlAnimalPedigree ?? null,
|
|
177
230
|
loading: {
|
|
178
|
-
herd:
|
|
179
|
-
groups:
|
|
180
|
-
animal:
|
|
231
|
+
herd: D.loading,
|
|
232
|
+
groups: O.loading,
|
|
233
|
+
animal: k.loading,
|
|
234
|
+
pedigree: A.loading
|
|
181
235
|
},
|
|
182
236
|
errors: {
|
|
183
|
-
herd:
|
|
184
|
-
groups:
|
|
185
|
-
animal:
|
|
237
|
+
herd: D.error ?? null,
|
|
238
|
+
groups: O.error ?? null,
|
|
239
|
+
animal: k.error ?? null,
|
|
240
|
+
pedigree: A.error ?? null
|
|
186
241
|
},
|
|
187
|
-
refetchHerd:
|
|
188
|
-
refetchGroups:
|
|
189
|
-
refetchAnimal:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
242
|
+
refetchHerd: L,
|
|
243
|
+
refetchGroups: R,
|
|
244
|
+
refetchAnimal: z,
|
|
245
|
+
refetchPedigree: B,
|
|
246
|
+
updateAnimalDepth: U,
|
|
247
|
+
createGroup: W,
|
|
248
|
+
updateGroup: G,
|
|
249
|
+
deleteGroup: K,
|
|
250
|
+
recordWeight: q,
|
|
251
|
+
deleteWeight: J
|
|
196
252
|
};
|
|
197
253
|
}
|
|
198
254
|
//#endregion
|
|
199
|
-
export {
|
|
255
|
+
export { T as useHealthyBowlLivestockDepth };
|
|
200
256
|
|
|
201
257
|
//# sourceMappingURL=useHealthyBowlLivestockDepth.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useHealthyBowlLivestockDepth.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlLivestockDepth.ts"],"sourcesContent":["/**\n * Deep livestock records — data hook.\n * Roadmap 18 · BOFF-2890 · gap L-1.\n *\n * Broadens the animal record with EID/RFID, body-condition score, manual/smart groups, dam/sire\n * genealogy, grazing/rotation, and a weight history that yields ADG. The medication-withdrawal\n * end-date + \"do not sell\" compliance flag are REUSED from the shipped withdrawal sub-domain\n * (BOFF-2885) and surfaced here on the deep herd view. Documents are declared inline with `gql`\n * (the same escape hatch `useHealthyBowlWithdrawal`/`useHealthyBowlDistribution` use) because\n * codegen validates against the committed `graphql/wspace.graphql` snapshot. Types mirror\n * `wspace-healthybowl-svc/src/modules/healthybowl/schema/livestock-depth.gql`.\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 livestock-depth.gql) ─────────────────────────────────────────\n\nexport interface AnimalWithdrawalBadge {\n status: string;\n blocked: boolean;\n endDate: string | null;\n daysLeft: number;\n milkClearDate: string | null;\n meatClearDate: string | null;\n eggsClearDate: string | null;\n}\n\nexport interface HerdDepthRow {\n animalId: string;\n tagNumber: string;\n eidTag: string | null;\n name: string;\n type: string;\n groupId: string | null;\n groupName: string | null;\n bodyConditionScore: number | null;\n adgKgPerDay: number | null;\n latestWeightKg: number | null;\n latestWeightAt: string | null;\n withdrawal: AnimalWithdrawalBadge;\n}\n\nexport interface AnimalGroup {\n id: string;\n name: string;\n description: string | null;\n kind: string;\n smartRule: Record<string, unknown> | null;\n color: string | null;\n animalCount: number;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface HerdComplianceSummary {\n totalAnimals: number;\n animalsInWithdrawal: number;\n animalsClear: number;\n complianceMessage: string;\n}\n\nexport interface HerdDepthView {\n rows: HerdDepthRow[];\n summary: HerdComplianceSummary;\n groups: AnimalGroup[];\n /**\n * True when the server hit a row cap, so `rows` is a page of the herd rather than the herd\n * (BOFF-6012). `summary.totalAnimals` counts the rows returned; `groups[].animalCount` still\n * counts the whole herd.\n */\n truncated: boolean;\n}\n\nexport interface WeightRecord {\n id: string;\n animalId: string;\n weightKg: number;\n measuredAt: string;\n method: string | null;\n notes: string | null;\n createdAt: string;\n}\n\nexport interface AnimalDepthRecord {\n animalId: string;\n tagNumber: string;\n eidTag: string | null;\n name: string;\n type: string;\n breed: string | null;\n status: string;\n groupId: string | null;\n groupName: string | null;\n bodyConditionScore: number | null;\n damId: string | null;\n damTag: string | null;\n sireId: string | null;\n sireTag: string | null;\n grazingPaddock: string | null;\n rotationDate: string | null;\n grazingNotes: string | null;\n adgKgPerDay: number | null;\n latestWeightKg: number | null;\n latestWeightAt: string | null;\n weightHistory: WeightRecord[];\n withdrawal: AnimalWithdrawalBadge;\n}\n\ninterface HbContext {\n workspaceId: string;\n}\n\n// ── field fragments ─────────────────────────────────────────────────────────\n\nconst WITHDRAWAL_FIELDS = `\n status\n blocked\n endDate\n daysLeft\n milkClearDate\n meatClearDate\n eggsClearDate\n`;\n\nconst GROUP_FIELDS = `\n id\n name\n description\n kind\n smartRule\n color\n animalCount\n createdAt\n updatedAt\n`;\n\nconst HERD_ROW_FIELDS = `\n animalId\n tagNumber\n eidTag\n name\n type\n groupId\n groupName\n bodyConditionScore\n adgKgPerDay\n latestWeightKg\n latestWeightAt\n withdrawal { ${WITHDRAWAL_FIELDS} }\n`;\n\nconst WEIGHT_FIELDS = `\n id\n animalId\n weightKg\n measuredAt\n method\n notes\n createdAt\n`;\n\nconst ANIMAL_DEPTH_FIELDS = `\n animalId\n tagNumber\n eidTag\n name\n type\n breed\n status\n groupId\n groupName\n bodyConditionScore\n damId\n damTag\n sireId\n sireTag\n grazingPaddock\n rotationDate\n grazingNotes\n adgKgPerDay\n latestWeightKg\n latestWeightAt\n weightHistory { ${WEIGHT_FIELDS} }\n withdrawal { ${WITHDRAWAL_FIELDS} }\n`;\n\n// ── documents ─────────────────────────────────────────────────────────────\n\nconst GET_HERD_DEPTH = gql`\n query HealthyBowlHerdDepth($context: ContextInput!, $groupId: ID, $search: String) {\n healthyBowlHerdDepth(context: $context, groupId: $groupId, search: $search) {\n truncated\n rows { ${HERD_ROW_FIELDS} }\n summary { totalAnimals animalsInWithdrawal animalsClear complianceMessage }\n groups { ${GROUP_FIELDS} }\n }\n }\n`;\n\nconst GET_ANIMAL_DEPTH = gql`\n query HealthyBowlAnimalDepth($context: ContextInput!, $animalId: ID!) {\n healthyBowlAnimalDepth(context: $context, animalId: $animalId) { ${ANIMAL_DEPTH_FIELDS} }\n }\n`;\n\nconst GET_GROUPS = gql`\n query HealthyBowlAnimalGroups($context: ContextInput!) {\n healthyBowlAnimalGroups(context: $context) { ${GROUP_FIELDS} }\n }\n`;\n\nconst UPDATE_ANIMAL_DEPTH = gql`\n mutation UpdateHealthyBowlAnimalDepth($input: UpdateHealthyBowlAnimalDepthInput!) {\n updateHealthyBowlAnimalDepth(input: $input) { ${ANIMAL_DEPTH_FIELDS} }\n }\n`;\n\nconst CREATE_GROUP = gql`\n mutation CreateHealthyBowlAnimalGroup($input: CreateHealthyBowlAnimalGroupInput!) {\n createHealthyBowlAnimalGroup(input: $input) { ${GROUP_FIELDS} }\n }\n`;\n\nconst UPDATE_GROUP = gql`\n mutation UpdateHealthyBowlAnimalGroup($input: UpdateHealthyBowlAnimalGroupInput!) {\n updateHealthyBowlAnimalGroup(input: $input) { ${GROUP_FIELDS} }\n }\n`;\n\nconst DELETE_GROUP = gql`\n mutation DeleteHealthyBowlAnimalGroup($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlAnimalGroup(id: $id, context: $context)\n }\n`;\n\nconst RECORD_WEIGHT = gql`\n mutation RecordHealthyBowlAnimalWeight($input: RecordHealthyBowlAnimalWeightInput!) {\n recordHealthyBowlAnimalWeight(input: $input) { ${WEIGHT_FIELDS} }\n }\n`;\n\nconst DELETE_WEIGHT = gql`\n mutation DeleteHealthyBowlAnimalWeight($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlAnimalWeight(id: $id, context: $context)\n }\n`;\n\n// ── hook ─────────────────────────────────────────────────────────────────────\n\nexport interface UseLivestockDepthOptions {\n /** Fetch the deep herd view (rows + compliance summary + groups). */\n herd?: boolean;\n /** Optional group filter for the herd view. */\n herdGroupId?: string | null;\n /** Optional free-text search (tag / name / EID) for the herd view. */\n herdSearch?: string | null;\n /** Fetch the animal groups list. */\n groups?: boolean;\n /** Fetch a single animal's deep record. */\n animalId?: string | null;\n}\n\nexport function useHealthyBowlLivestockDepth(options: UseLivestockDepthOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n\n const enableHerd = options.herd === true;\n const enableGroups = options.groups === true;\n const animalId = options.animalId ?? null;\n const herdGroupId = options.herdGroupId ?? null;\n const herdSearch = options.herdSearch ?? null;\n\n const herdQuery = useQuery<\n { healthyBowlHerdDepth: HerdDepthView },\n { context: HbContext; groupId: string | null; search: string | null }\n >(GET_HERD_DEPTH, {\n variables: { context: ctx, groupId: herdGroupId, search: herdSearch },\n fetchPolicy: 'cache-and-network',\n skip: !enableHerd,\n });\n\n const groupsQuery = useQuery<{ healthyBowlAnimalGroups: AnimalGroup[] }, { context: HbContext }>(GET_GROUPS, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n skip: !enableGroups,\n });\n\n const animalQuery = useQuery<{ healthyBowlAnimalDepth: AnimalDepthRecord }, { context: HbContext; animalId: string }>(\n GET_ANIMAL_DEPTH,\n { variables: { context: ctx, animalId: animalId ?? '' }, fetchPolicy: 'cache-and-network', skip: !animalId }\n );\n\n const [updateAnimalDepthMutation] = useMutation(UPDATE_ANIMAL_DEPTH);\n const [createGroupMutation] = useMutation(CREATE_GROUP);\n const [updateGroupMutation] = useMutation(UPDATE_GROUP);\n const [deleteGroupMutation] = useMutation(DELETE_GROUP);\n const [recordWeightMutation] = useMutation(RECORD_WEIGHT);\n const [deleteWeightMutation] = useMutation(DELETE_WEIGHT);\n\n const refetchHerd = useCallback(() => herdQuery.refetch(), [herdQuery]);\n const refetchGroups = useCallback(() => groupsQuery.refetch(), [groupsQuery]);\n const refetchAnimal = useCallback(() => animalQuery.refetch(), [animalQuery]);\n\n const reconcile = useCallback(async () => {\n const runners: Array<Promise<unknown>> = [];\n if (enableHerd) runners.push(refetchHerd().catch(() => undefined));\n if (enableGroups) runners.push(refetchGroups().catch(() => undefined));\n if (animalId) runners.push(refetchAnimal().catch(() => undefined));\n await Promise.all(runners);\n }, [enableHerd, enableGroups, animalId, refetchHerd, refetchGroups, refetchAnimal]);\n\n const updateAnimalDepth = useCallback(\n async (input: Record<string, unknown>): Promise<AnimalDepthRecord | undefined> => {\n const res = await updateAnimalDepthMutation({ variables: { input: { ...input, context: ctx } } });\n await reconcile();\n return (res.data as { updateHealthyBowlAnimalDepth?: AnimalDepthRecord } | null)?.updateHealthyBowlAnimalDepth;\n },\n [updateAnimalDepthMutation, ctx, reconcile]\n );\n\n const createGroup = useCallback(\n async (input: Record<string, unknown>): Promise<AnimalGroup | undefined> => {\n const res = await createGroupMutation({ variables: { input: { ...input, context: ctx } } });\n await reconcile();\n return (res.data as { createHealthyBowlAnimalGroup?: AnimalGroup } | null)?.createHealthyBowlAnimalGroup;\n },\n [createGroupMutation, ctx, reconcile]\n );\n\n const updateGroup = useCallback(\n async (input: Record<string, unknown>): Promise<AnimalGroup | undefined> => {\n const res = await updateGroupMutation({ variables: { input: { ...input, context: ctx } } });\n await reconcile();\n return (res.data as { updateHealthyBowlAnimalGroup?: AnimalGroup } | null)?.updateHealthyBowlAnimalGroup;\n },\n [updateGroupMutation, ctx, reconcile]\n );\n\n const deleteGroup = useCallback(\n async (id: string): Promise<void> => {\n await deleteGroupMutation({ variables: { id, context: ctx } });\n await reconcile();\n },\n [deleteGroupMutation, ctx, reconcile]\n );\n\n const recordWeight = useCallback(\n async (input: Record<string, unknown>): Promise<WeightRecord | undefined> => {\n const res = await recordWeightMutation({ variables: { input: { ...input, context: ctx } } });\n await reconcile();\n return (res.data as { recordHealthyBowlAnimalWeight?: WeightRecord } | null)?.recordHealthyBowlAnimalWeight;\n },\n [recordWeightMutation, ctx, reconcile]\n );\n\n const deleteWeight = useCallback(\n async (id: string): Promise<void> => {\n await deleteWeightMutation({ variables: { id, context: ctx } });\n await reconcile();\n },\n [deleteWeightMutation, ctx, reconcile]\n );\n\n return {\n herd: herdQuery.data?.healthyBowlHerdDepth ?? null,\n groups: groupsQuery.data?.healthyBowlAnimalGroups ?? herdQuery.data?.healthyBowlHerdDepth?.groups ?? [],\n animalDepth: animalQuery.data?.healthyBowlAnimalDepth ?? null,\n loading: {\n herd: herdQuery.loading,\n groups: groupsQuery.loading,\n animal: animalQuery.loading,\n },\n errors: {\n herd: herdQuery.error ?? null,\n groups: groupsQuery.error ?? null,\n animal: animalQuery.error ?? null,\n },\n refetchHerd,\n refetchGroups,\n refetchAnimal,\n updateAnimalDepth,\n createGroup,\n updateGroup,\n deleteGroup,\n recordWeight,\n deleteWeight,\n };\n}\n"],"mappings":";;;;;AAkBA,IAAM,IAAwB,wCAqGxB,IAAoB,qGAUpB,IAAe,0GAYf,IAAkB;;;;;;;;;;;;iBAYP,EAAkB;GAG7B,IAAgB,kFAUhB,IAAsB;;;;;;;;;;;;;;;;;;;;;oBAqBR,EAAc;iBACjB,EAAkB;GAK7B,IAAiB,CAAG;;;;eAIX,EAAgB;;iBAEd,EAAa;;;GAKxB,IAAmB,CAAG;;uEAE2C,EAAoB;;GAIrF,IAAa,CAAG;;mDAE6B,EAAa;;GAI1D,IAAsB,CAAG;;oDAEqB,EAAoB;;GAIlE,IAAe,CAAG;;oDAE4B,EAAa;;GAI3D,IAAe,CAAG;;oDAE4B,EAAa;;GAI3D,IAAe,CAAG;;;;GAMlB,IAAgB,CAAG;;qDAE4B,EAAc;;GAI7D,IAAgB,CAAG;;;;;AAqBzB,SAAgB,EAA6B,IAAoC,CAAC,GAAG;CACnF,IAAM,EAAE,mBAAgB,EAAe,GACjC,IAAuB,KAAe,GACtC,IAAM,SAA0B,EAAE,aAAa,EAAqB,IAAI,CAAC,CAAoB,CAAC,GAE9F,IAAa,EAAQ,SAAS,IAC9B,IAAe,EAAQ,WAAW,IAClC,IAAW,EAAQ,YAAY,MAI/B,IAAY,EAGhB,GAAgB;EAChB,WAAW;GAAE,SAAS;GAAK,SAPT,EAAQ,eAAe;GAOQ,QANhC,EAAQ,cAAc;EAM6B;EACpE,aAAa;EACb,MAAM,CAAC;CACT,CAAC,GAEK,IAAc,EAA6E,GAAY;EAC3G,WAAW,EAAE,SAAS,EAAI;EAC1B,aAAa;EACb,MAAM,CAAC;CACT,CAAC,GAEK,IAAc,EAClB,GACA;EAAE,WAA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AAc,EAClB,OAAO,MAAqE;EAC1E,IAAM,IAAM,MAAM,EAAoB,EAAE,WAAW,EAAE,OAAO;GAAE,GAAG;GAAO,SAAS;EAAI,EAAE,EAAE,CAAC;EAE1F,OADA,MAAM,EAAU,GACR,EAAI,MAAgE;CAC9E,GACA;EAAC;EAAqB;EAAK;CAAS,CACtC,GAEM,IAAc,EAClB,OAAO,MAA8B;EAEnC,AADA,MAAM,EAAoB,EAAE,WAAW;GAAE;GAAI,SAAS;EAAI,EAAE,CAAC,GAC7D,MAAM,EAAU;CAClB,GACA;EAAC;EAAqB;EAAK;CAAS,CACtC,GAEM,IAAe,EACnB,OAAO,MAAsE;EAC3E,IAAM,IAAM,MAAM,EAAqB,EAAE,WAAW,EAAE,OAAO;GAAE,GAAG;GAAO,SAAS;EAAI,EAAE,EAAE,CAAC;EAE3F,OADA,MAAM,EAAU,GACR,EAAI,MAAkE;CAChF,GACA;EAAC;EAAsB;EAAK;CAAS,CACvC,GAEM,IAAe,EACnB,OAAO,MAA8B;EAEnC,AADA,MAAM,EAAqB,EAAE,WAAW;GAAE;GAAI,SAAS;EAAI,EAAE,CAAC,GAC9D,MAAM,EAAU;CAClB,GACA;EAAC;EAAsB;EAAK;CAAS,CACvC;CAEA,OAAO;EACL,MAAM,EAAU,MAAM,wBAAwB;EAC9C,QAAQ,EAAY,MAAM,2BAA2B,EAAU,MAAM,sBAAsB,UAAU,CAAC;EACtG,aAAa,EAAY,MAAM,0BAA0B;EACzD,SAAS;GACP,MAAM,EAAU;GAChB,QAAQ,EAAY;GACpB,QAAQ,EAAY;EACtB;EACA,QAAQ;GACN,MAAM,EAAU,SAAS;GACzB,QAAQ,EAAY,SAAS;GAC7B,QAAQ,EAAY,SAAS;EAC/B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useHealthyBowlLivestockDepth.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlLivestockDepth.ts"],"sourcesContent":["/**\n * Deep livestock records — data hook.\n * Roadmap 18 · BOFF-2890 · gap L-1.\n *\n * Broadens the animal record with EID/RFID, body-condition score, manual/smart groups, dam/sire\n * genealogy, grazing/rotation, and a weight history that yields ADG. The medication-withdrawal\n * end-date + \"do not sell\" compliance flag are REUSED from the shipped withdrawal sub-domain\n * (BOFF-2885) and surfaced here on the deep herd view. Documents are declared inline with `gql`\n * (the same escape hatch `useHealthyBowlWithdrawal`/`useHealthyBowlDistribution` use) because\n * codegen validates against the committed `graphql/wspace.graphql` snapshot. Types mirror\n * `wspace-healthybowl-svc/src/modules/healthybowl/schema/livestock-depth.gql`.\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 livestock-depth.gql) ─────────────────────────────────────────\n\nexport interface AnimalWithdrawalBadge {\n status: string;\n blocked: boolean;\n endDate: string | null;\n daysLeft: number;\n milkClearDate: string | null;\n meatClearDate: string | null;\n eggsClearDate: string | null;\n}\n\nexport interface HerdDepthRow {\n animalId: string;\n tagNumber: string;\n eidTag: string | null;\n name: string;\n type: string;\n groupId: string | null;\n groupName: string | null;\n bodyConditionScore: number | null;\n adgKgPerDay: number | null;\n latestWeightKg: number | null;\n latestWeightAt: string | null;\n /**\n * True when the animal has left the herd. Only present at all when `herdIncludeArchived` was set —\n * the default document does not select it, so it is `undefined` on every other caller's rows.\n */\n archived?: boolean;\n withdrawal: AnimalWithdrawalBadge;\n}\n\nexport interface AnimalGroup {\n id: string;\n name: string;\n description: string | null;\n kind: string;\n smartRule: Record<string, unknown> | null;\n color: string | null;\n animalCount: number;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface HerdComplianceSummary {\n totalAnimals: number;\n animalsInWithdrawal: number;\n animalsClear: number;\n complianceMessage: string;\n}\n\nexport interface HerdDepthView {\n rows: HerdDepthRow[];\n summary: HerdComplianceSummary;\n groups: AnimalGroup[];\n /**\n * True when the server hit a row cap, so `rows` is a page of the herd rather than the herd\n * (BOFF-6012). `summary.totalAnimals` counts the rows returned; `groups[].animalCount` still\n * counts the whole herd.\n */\n truncated: boolean;\n}\n\nexport interface WeightRecord {\n id: string;\n animalId: string;\n weightKg: number;\n measuredAt: string;\n method: string | null;\n notes: string | null;\n createdAt: string;\n}\n\nexport interface AnimalDepthRecord {\n animalId: string;\n tagNumber: string;\n eidTag: string | null;\n name: string;\n type: string;\n breed: string | null;\n status: string;\n groupId: string | null;\n groupName: string | null;\n bodyConditionScore: number | null;\n damId: string | null;\n damTag: string | null;\n /** True when the dam has left the herd (BOFF-6011). Drives the \"(archived)\" suffix. */\n damArchived: boolean;\n sireId: string | null;\n sireTag: string | null;\n /** True when the sire has left the herd. See `damArchived`. */\n sireArchived: boolean;\n grazingPaddock: string | null;\n rotationDate: string | null;\n grazingNotes: string | null;\n adgKgPerDay: number | null;\n latestWeightKg: number | null;\n latestWeightAt: string | null;\n weightHistory: WeightRecord[];\n withdrawal: AnimalWithdrawalBadge;\n}\n\ninterface HbContext {\n workspaceId: string;\n}\n\n// ── field fragments ─────────────────────────────────────────────────────────\n\nconst WITHDRAWAL_FIELDS = `\n status\n blocked\n endDate\n daysLeft\n milkClearDate\n meatClearDate\n eggsClearDate\n`;\n\nconst GROUP_FIELDS = `\n id\n name\n description\n kind\n smartRule\n color\n animalCount\n createdAt\n updatedAt\n`;\n\nconst HERD_ROW_FIELDS = `\n animalId\n tagNumber\n eidTag\n name\n type\n groupId\n groupName\n bodyConditionScore\n adgKgPerDay\n latestWeightKg\n latestWeightAt\n withdrawal { ${WITHDRAWAL_FIELDS} }\n`;\n\n/** The herd row plus the archived marker. Only the genealogy picker asks for this — see the note\n * above `GET_HERD_DEPTH_WITH_ARCHIVED`. */\nconst HERD_ROW_FIELDS_WITH_ARCHIVED = `\n ${HERD_ROW_FIELDS}\n archived\n`;\n\nconst WEIGHT_FIELDS = `\n id\n animalId\n weightKg\n measuredAt\n method\n notes\n createdAt\n`;\n\nconst ANIMAL_DEPTH_FIELDS = `\n animalId\n tagNumber\n eidTag\n name\n type\n breed\n status\n groupId\n groupName\n bodyConditionScore\n damId\n damTag\n damArchived\n sireId\n sireTag\n sireArchived\n grazingPaddock\n rotationDate\n grazingNotes\n adgKgPerDay\n latestWeightKg\n latestWeightAt\n weightHistory { ${WEIGHT_FIELDS} }\n withdrawal { ${WITHDRAWAL_FIELDS} }\n`;\n\n// ── documents ─────────────────────────────────────────────────────────────\n\nconst GET_HERD_DEPTH = gql`\n query HealthyBowlHerdDepth($context: ContextInput!, $groupId: ID, $search: String) {\n healthyBowlHerdDepth(context: $context, groupId: $groupId, search: $search) {\n truncated\n rows { ${HERD_ROW_FIELDS} }\n summary { totalAnimals animalsInWithdrawal animalsClear complianceMessage }\n groups { ${GROUP_FIELDS} }\n }\n }\n`;\n\n/**\n * The archived-aware variant, used ONLY when a caller sets `herdIncludeArchived` (BOFF-6195).\n *\n * Deliberately a second document rather than one document with an optional argument. The herd list\n * and the grazing move modal do not want archived rows and have no reason to carry the risk: a\n * single shared document would send `includeArchived` and select `archived` on every read, so a\n * supergraph that has not yet composed those — a stale prod Hive CDN edge lasts ~30–40 min after a\n * publish — would fail validation on `/livestock/records` and `/livestock/grazing` too, not just on\n * the one page that needs the feature. The blast radius is now exactly the caller that opted in.\n *\n * The operation name differs so Apollo treats it as a distinct operation.\n */\nconst GET_HERD_DEPTH_WITH_ARCHIVED = gql`\n query HealthyBowlHerdDepthWithArchived(\n $context: ContextInput!\n $groupId: ID\n $search: String\n $includeArchived: Boolean\n ) {\n healthyBowlHerdDepth(context: $context, groupId: $groupId, search: $search, includeArchived: $includeArchived) {\n truncated\n rows { ${HERD_ROW_FIELDS_WITH_ARCHIVED} }\n summary { totalAnimals animalsInWithdrawal animalsClear complianceMessage }\n groups { ${GROUP_FIELDS} }\n }\n }\n`;\n\nexport interface PedigreeNode {\n animalId: string;\n tagNumber: string;\n name: string;\n type: string;\n breed: string | null;\n gender: string;\n dateOfBirth: string | null;\n generation: number;\n /** DAM | SIRE — which side of this node's own child it sits on. SELF on the root. */\n relation: string;\n archived: boolean;\n /** ONE of the animals a generation closer to the root that this node parents. */\n childAnimalId: string | null;\n}\n\nexport interface OffspringNode {\n animalId: string;\n tagNumber: string;\n name: string;\n type: string;\n gender: string;\n dateOfBirth: string | null;\n generation: number;\n /** DAM | SIRE | BOTH — the parent link followed from the preceding node in the pedigree walk. */\n viaParent: string;\n archived: boolean;\n /** One matching preceding parent for compatibility; parentAnimalIds retains every matching edge. */\n parentAnimalId: string | null;\n /** All immediately preceding parents matched in the walk; empty for direct offspring. */\n parentAnimalIds: string[];\n}\n\nexport interface AnimalPedigree {\n root: PedigreeNode;\n ancestors: PedigreeNode[];\n offspring: OffspringNode[];\n /** A depth or node cap stopped the walk, so the tree shown is incomplete. */\n truncated: boolean;\n /** The walk re-entered an animal it had already visited — reachable on undated rows. */\n cycleDetected: boolean;\n ancestorDepth: number;\n offspringDepth: number;\n}\n\nconst PEDIGREE_NODE_FIELDS = `\n animalId tagNumber name type breed gender dateOfBirth generation relation archived childAnimalId\n`;\nconst OFFSPRING_NODE_FIELDS = `\n animalId tagNumber name type gender dateOfBirth generation viaParent archived parentAnimalId parentAnimalIds\n`;\n\nconst GET_PEDIGREE = gql`\n query HealthyBowlAnimalPedigree($context: ContextInput!, $animalId: ID!, $ancestorDepth: Int, $offspringDepth: Int) {\n healthyBowlAnimalPedigree(\n context: $context\n animalId: $animalId\n ancestorDepth: $ancestorDepth\n offspringDepth: $offspringDepth\n ) {\n root { ${PEDIGREE_NODE_FIELDS} }\n ancestors { ${PEDIGREE_NODE_FIELDS} }\n offspring { ${OFFSPRING_NODE_FIELDS} }\n truncated\n cycleDetected\n ancestorDepth\n offspringDepth\n }\n }\n`;\n\nconst GET_ANIMAL_DEPTH = gql`\n query HealthyBowlAnimalDepth($context: ContextInput!, $animalId: ID!) {\n healthyBowlAnimalDepth(context: $context, animalId: $animalId) { ${ANIMAL_DEPTH_FIELDS} }\n }\n`;\n\nconst GET_GROUPS = gql`\n query HealthyBowlAnimalGroups($context: ContextInput!) {\n healthyBowlAnimalGroups(context: $context) { ${GROUP_FIELDS} }\n }\n`;\n\nconst UPDATE_ANIMAL_DEPTH = gql`\n mutation UpdateHealthyBowlAnimalDepth($input: UpdateHealthyBowlAnimalDepthInput!) {\n updateHealthyBowlAnimalDepth(input: $input) { ${ANIMAL_DEPTH_FIELDS} }\n }\n`;\n\nconst CREATE_GROUP = gql`\n mutation CreateHealthyBowlAnimalGroup($input: CreateHealthyBowlAnimalGroupInput!) {\n createHealthyBowlAnimalGroup(input: $input) { ${GROUP_FIELDS} }\n }\n`;\n\nconst UPDATE_GROUP = gql`\n mutation UpdateHealthyBowlAnimalGroup($input: UpdateHealthyBowlAnimalGroupInput!) {\n updateHealthyBowlAnimalGroup(input: $input) { ${GROUP_FIELDS} }\n }\n`;\n\nconst DELETE_GROUP = gql`\n mutation DeleteHealthyBowlAnimalGroup($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlAnimalGroup(id: $id, context: $context)\n }\n`;\n\nconst RECORD_WEIGHT = gql`\n mutation RecordHealthyBowlAnimalWeight($input: RecordHealthyBowlAnimalWeightInput!) {\n recordHealthyBowlAnimalWeight(input: $input) { ${WEIGHT_FIELDS} }\n }\n`;\n\nconst DELETE_WEIGHT = gql`\n mutation DeleteHealthyBowlAnimalWeight($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlAnimalWeight(id: $id, context: $context)\n }\n`;\n\n// ── hook ─────────────────────────────────────────────────────────────────────\n\nexport interface UseLivestockDepthOptions {\n /** Fetch the deep herd view (rows + compliance summary + groups). */\n herd?: boolean;\n /** Optional group filter for the herd view. */\n herdGroupId?: string | null;\n /** Optional free-text search (tag / name / EID) for the herd view. */\n herdSearch?: string | null;\n /**\n * Include archived (soft-deleted) animals in the herd rows. Off by default — only the genealogy\n * picker wants them, and they must never appear in a herd LIST. `summary` and\n * `groups[].animalCount` stay live-only whatever this is set to (BOFF-6195).\n */\n herdIncludeArchived?: boolean;\n /** Fetch the animal groups list. */\n groups?: boolean;\n /** Fetch a single animal's deep record. */\n animalId?: string | null;\n /** Fetch the animal's pedigree (ancestors + offspring). Requires `animalId` (BOFF-6097). */\n pedigree?: boolean;\n /** Generations of ancestors to walk. The server clamps to 1..8; default 4. */\n pedigreeAncestorDepth?: number | null;\n}\n\nexport function useHealthyBowlLivestockDepth(options: UseLivestockDepthOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n const effectiveWorkspaceId = workspaceId || FALLBACK_WORKSPACE_ID;\n const ctx = useMemo<HbContext>(() => ({ workspaceId: effectiveWorkspaceId }), [effectiveWorkspaceId]);\n\n const enableHerd = options.herd === true;\n const enableGroups = options.groups === true;\n const animalId = options.animalId ?? null;\n const herdGroupId = options.herdGroupId ?? null;\n const herdSearch = options.herdSearch ?? null;\n const herdIncludeArchived = options.herdIncludeArchived ?? false;\n\n const herdQuery = useQuery<\n { healthyBowlHerdDepth: HerdDepthView },\n { context: HbContext; groupId: string | null; search: string | null; includeArchived?: boolean }\n >(herdIncludeArchived ? GET_HERD_DEPTH_WITH_ARCHIVED : GET_HERD_DEPTH, {\n variables: herdIncludeArchived\n ? { context: ctx, groupId: herdGroupId, search: herdSearch, includeArchived: true }\n : { context: ctx, groupId: herdGroupId, search: herdSearch },\n fetchPolicy: 'cache-and-network',\n skip: !enableHerd,\n });\n\n const groupsQuery = useQuery<{ healthyBowlAnimalGroups: AnimalGroup[] }, { context: HbContext }>(GET_GROUPS, {\n variables: { context: ctx },\n fetchPolicy: 'cache-and-network',\n skip: !enableGroups,\n });\n\n const animalQuery = useQuery<{ healthyBowlAnimalDepth: AnimalDepthRecord }, { context: HbContext; animalId: string }>(\n GET_ANIMAL_DEPTH,\n { variables: { context: ctx, animalId: animalId ?? '' }, fetchPolicy: 'cache-and-network', skip: !animalId }\n );\n\n const pedigreeQuery = useQuery<\n { healthyBowlAnimalPedigree: AnimalPedigree },\n { context: HbContext; animalId: string; ancestorDepth: number | null; offspringDepth: number | null }\n >(GET_PEDIGREE, {\n variables: {\n context: ctx,\n animalId: animalId ?? '',\n ancestorDepth: options.pedigreeAncestorDepth ?? null,\n offspringDepth: null,\n },\n fetchPolicy: 'cache-and-network',\n skip: !animalId || options.pedigree !== true,\n });\n\n const [updateAnimalDepthMutation] = useMutation(UPDATE_ANIMAL_DEPTH);\n const [createGroupMutation] = useMutation(CREATE_GROUP);\n const [updateGroupMutation] = useMutation(UPDATE_GROUP);\n const [deleteGroupMutation] = useMutation(DELETE_GROUP);\n const [recordWeightMutation] = useMutation(RECORD_WEIGHT);\n const [deleteWeightMutation] = useMutation(DELETE_WEIGHT);\n\n const refetchHerd = useCallback(() => herdQuery.refetch(), [herdQuery]);\n const refetchGroups = useCallback(() => groupsQuery.refetch(), [groupsQuery]);\n const refetchAnimal = useCallback(() => animalQuery.refetch(), [animalQuery]);\n const refetchPedigree = useCallback(() => pedigreeQuery.refetch(), [pedigreeQuery]);\n const enablePedigree = options.pedigree === true;\n\n const reconcile = useCallback(async () => {\n const runners: Array<Promise<unknown>> = [];\n if (enableHerd) runners.push(refetchHerd().catch(() => undefined));\n if (enableGroups) runners.push(refetchGroups().catch(() => undefined));\n if (animalId) runners.push(refetchAnimal().catch(() => undefined));\n // An edit that changes dam/sire changes the tree — without this the panel keeps showing the\n // pre-edit ancestry until a hard reload (BOFF-6097).\n if (animalId && enablePedigree) runners.push(refetchPedigree().catch(() => undefined));\n await Promise.all(runners);\n }, [enableHerd, enableGroups, animalId, enablePedigree, refetchHerd, refetchGroups, refetchAnimal, refetchPedigree]);\n\n const updateAnimalDepth = useCallback(\n async (input: Record<string, unknown>): Promise<AnimalDepthRecord | undefined> => {\n const res = await updateAnimalDepthMutation({ variables: { input: { ...input, context: ctx } } });\n await reconcile();\n return (res.data as { updateHealthyBowlAnimalDepth?: AnimalDepthRecord } | null)?.updateHealthyBowlAnimalDepth;\n },\n [updateAnimalDepthMutation, ctx, reconcile]\n );\n\n const createGroup = useCallback(\n async (input: Record<string, unknown>): Promise<AnimalGroup | undefined> => {\n const res = await createGroupMutation({ variables: { input: { ...input, context: ctx } } });\n await reconcile();\n return (res.data as { createHealthyBowlAnimalGroup?: AnimalGroup } | null)?.createHealthyBowlAnimalGroup;\n },\n [createGroupMutation, ctx, reconcile]\n );\n\n const updateGroup = useCallback(\n async (input: Record<string, unknown>): Promise<AnimalGroup | undefined> => {\n const res = await updateGroupMutation({ variables: { input: { ...input, context: ctx } } });\n await reconcile();\n return (res.data as { updateHealthyBowlAnimalGroup?: AnimalGroup } | null)?.updateHealthyBowlAnimalGroup;\n },\n [updateGroupMutation, ctx, reconcile]\n );\n\n const deleteGroup = useCallback(\n async (id: string): Promise<void> => {\n await deleteGroupMutation({ variables: { id, context: ctx } });\n await reconcile();\n },\n [deleteGroupMutation, ctx, reconcile]\n );\n\n const recordWeight = useCallback(\n async (input: Record<string, unknown>): Promise<WeightRecord | undefined> => {\n const res = await recordWeightMutation({ variables: { input: { ...input, context: ctx } } });\n await reconcile();\n return (res.data as { recordHealthyBowlAnimalWeight?: WeightRecord } | null)?.recordHealthyBowlAnimalWeight;\n },\n [recordWeightMutation, ctx, reconcile]\n );\n\n const deleteWeight = useCallback(\n async (id: string): Promise<void> => {\n await deleteWeightMutation({ variables: { id, context: ctx } });\n await reconcile();\n },\n [deleteWeightMutation, ctx, reconcile]\n );\n\n return {\n herd: herdQuery.data?.healthyBowlHerdDepth ?? null,\n groups: groupsQuery.data?.healthyBowlAnimalGroups ?? herdQuery.data?.healthyBowlHerdDepth?.groups ?? [],\n animalDepth: animalQuery.data?.healthyBowlAnimalDepth ?? null,\n pedigree: pedigreeQuery.data?.healthyBowlAnimalPedigree ?? null,\n loading: {\n herd: herdQuery.loading,\n groups: groupsQuery.loading,\n animal: animalQuery.loading,\n pedigree: pedigreeQuery.loading,\n },\n errors: {\n herd: herdQuery.error ?? null,\n groups: groupsQuery.error ?? null,\n animal: animalQuery.error ?? null,\n pedigree: pedigreeQuery.error ?? null,\n },\n refetchHerd,\n refetchGroups,\n refetchAnimal,\n refetchPedigree,\n updateAnimalDepth,\n createGroup,\n updateGroup,\n deleteGroup,\n recordWeight,\n deleteWeight,\n };\n}\n"],"mappings":";;;;;AAkBA,IAAM,IAAwB,wCA8GxB,IAAoB,qGAUpB,IAAe,0GAYf,IAAkB;;;;;;;;;;;;iBAYP,EAAkB;GAK7B,IAAgC;IAClC,EAAgB;;GAId,IAAgB,kFAUhB,IAAsB;;;;;;;;;;;;;;;;;;;;;;;oBAuBR,EAAc;iBACjB,EAAkB;GAK7B,IAAiB,CAAG;;;;eAIX,EAAgB;;iBAEd,EAAa;;;GAiBxB,IAA+B,CAAG;;;;;;;;;eASzB,EAA8B;;iBAE5B,EAAa;;;GAkDxB,IAAuB,0GAOvB,IAAe,CAAG;;;;;;;;eAQT,EAAqB;oBAChB,EAAqB;oBACrB,qHAAsB;;;;;;;GASpC,IAAmB,CAAG;;uEAE2C,EAAoB;;GAIrF,IAAa,CAAG;;mDAE6B,EAAa;;GAI1D,IAAsB,CAAG;;oDAEqB,EAAoB;;GAIlE,IAAe,CAAG;;oDAE4B,EAAa;;GAI3D,IAAe,CAAG;;oDAE4B,EAAa;;GAI3D,IAAe,CAAG;;;;GAMlB,IAAgB,CAAG;;qDAE4B,EAAc;;GAI7D,IAAgB,CAAG;;;;;AA+BzB,SAAgB,EAA6B,IAAoC,CAAC,GAAG;CACnF,IAAM,EAAE,mBAAgB,EAAe,GACjC,IAAuB,KAAe,GACtC,IAAM,SAA0B,EAAE,aAAa,EAAqB,IAAI,CAAC,CAAoB,CAAC,GAE9F,IAAa,EAAQ,SAAS,IAC9B,IAAe,EAAQ,WAAW,IAClC,IAAW,EAAQ,YAAY,MAC/B,IAAc,EAAQ,eAAe,MACrC,IAAa,EAAQ,cAAc,MACnC,IAAsB,EAAQ,uBAAuB,IAErD,IAAY,EAGhB,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;EAAsB;EAAK;CAAS,CACvC,GAEM,IAAe,EACnB,OAAO,MAA8B;EAEnC,AADA,MAAM,EAAqB,EAAE,WAAW;GAAE;GAAI,SAAS;EAAI,EAAE,CAAC,GAC9D,MAAM,EAAU;CAClB,GACA;EAAC;EAAsB;EAAK;CAAS,CACvC;CAEA,OAAO;EACL,MAAM,EAAU,MAAM,wBAAwB;EAC9C,QAAQ,EAAY,MAAM,2BAA2B,EAAU,MAAM,sBAAsB,UAAU,CAAC;EACtG,aAAa,EAAY,MAAM,0BAA0B;EACzD,UAAU,EAAc,MAAM,6BAA6B;EAC3D,SAAS;GACP,MAAM,EAAU;GAChB,QAAQ,EAAY;GACpB,QAAQ,EAAY;GACpB,UAAU,EAAc;EAC1B;EACA,QAAQ;GACN,MAAM,EAAU,SAAS;GACzB,QAAQ,EAAY,SAAS;GAC7B,QAAQ,EAAY,SAAS;GAC7B,UAAU,EAAc,SAAS;EACnC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -34,37 +34,41 @@ function M() {
|
|
|
34
34
|
let { t: M } = _(), { analyticsReports: N, loading: P, errors: F, refetch: I } = d(), { generate: L, download: ee, downloadingIds: R } = m(), [z, B] = g(!1), [V, H] = g(""), [U, W] = g(!1), [G, K] = g(""), [q, J] = g("FINANCIAL"), { toasts: Y, toast: X, dismiss: Z } = u(), Q = (e) => {
|
|
35
35
|
p(e) && J(e);
|
|
36
36
|
}, $ = async () => {
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
if (z) return;
|
|
38
|
+
if (!G.trim()) {
|
|
39
|
+
X({
|
|
40
|
+
title: M("healthybowl.analytics.reports.toast.missingTitle.title", "Missing Title"),
|
|
41
|
+
description: M("healthybowl.analytics.reports.toast.missingTitle.description", "Please enter a report title"),
|
|
42
|
+
variant: "warning"
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
B(!0);
|
|
47
|
+
let e = !0;
|
|
48
|
+
try {
|
|
49
|
+
let t = await L({
|
|
50
|
+
title: G.trim(),
|
|
51
|
+
type: q
|
|
52
|
+
});
|
|
53
|
+
if (!t.started) {
|
|
54
|
+
e = !1;
|
|
44
55
|
return;
|
|
45
56
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
if (!t.ok) {
|
|
58
|
+
X({
|
|
59
|
+
title: M("healthybowl.analytics.reports.toast.failed.title", "Could not generate the report"),
|
|
60
|
+
description: t.message,
|
|
61
|
+
variant: "error"
|
|
51
62
|
});
|
|
52
|
-
|
|
53
|
-
X({
|
|
54
|
-
title: M("healthybowl.analytics.reports.toast.failed.title", "Could not generate the report"),
|
|
55
|
-
description: e.message,
|
|
56
|
-
variant: "error"
|
|
57
|
-
});
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
await I().catch(() => void 0), X({
|
|
61
|
-
title: M("healthybowl.analytics.reports.toast.generated.title", "Report ready"),
|
|
62
|
-
description: M("healthybowl.analytics.reports.toast.generated.description", "\"{{title}}\" is ready to download.", { title: G.trim() }),
|
|
63
|
-
variant: "success"
|
|
64
|
-
}), W(!1), K(""), J("FINANCIAL");
|
|
65
|
-
} finally {
|
|
66
|
-
B(!1);
|
|
63
|
+
return;
|
|
67
64
|
}
|
|
65
|
+
await I().catch(() => void 0), X({
|
|
66
|
+
title: M("healthybowl.analytics.reports.toast.generated.title", "Report ready"),
|
|
67
|
+
description: M("healthybowl.analytics.reports.toast.generated.description", "\"{{title}}\" is ready to download.", { title: G.trim() }),
|
|
68
|
+
variant: "success"
|
|
69
|
+
}), W(!1), K(""), J("FINANCIAL");
|
|
70
|
+
} finally {
|
|
71
|
+
e && B(!1);
|
|
68
72
|
}
|
|
69
73
|
}, te = async (e, t) => {
|
|
70
74
|
let n = await ee(e);
|