@burdenoff/microfe-healthybowl 2026.904.21 → 2026.904.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/dist/components/assistant/AssistantChatArea.js +7 -9
  2. package/dist/components/assistant/AssistantChatArea.js.map +1 -1
  3. package/dist/healthybowl/HealthyBowlRoot.js +56 -57
  4. package/dist/healthybowl/HealthyBowlRoot.js.map +1 -1
  5. package/dist/healthybowl/HealthyBowlRoutes.js +36 -48
  6. package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
  7. package/dist/healthybowl/components/CreateFarmTaskButton.js.map +1 -1
  8. package/dist/healthybowl/components/PageLayout.js +10 -11
  9. package/dist/healthybowl/components/PageLayout.js.map +1 -1
  10. package/dist/healthybowl/context/HealthyBowlContext.js +7 -7
  11. package/dist/healthybowl/context/HealthyBowlContext.js.map +1 -1
  12. package/dist/healthybowl/hooks/useHealthyBowlCompliance.js +141 -157
  13. package/dist/healthybowl/hooks/useHealthyBowlCompliance.js.map +1 -1
  14. package/dist/healthybowl/hooks/useHealthyBowlData.js +0 -18
  15. package/dist/healthybowl/hooks/useHealthyBowlData.js.map +1 -1
  16. package/dist/healthybowl/hooks/useHealthyBowlDistribution.js +37 -52
  17. package/dist/healthybowl/hooks/useHealthyBowlDistribution.js.map +1 -1
  18. package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js +78 -135
  19. package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js.map +1 -1
  20. package/dist/healthybowl/hooks/useIrrigationAutomation.js +1 -1
  21. package/dist/healthybowl/hooks/useIrrigationAutomation.js.map +1 -1
  22. package/dist/healthybowl/hooks/useSuccessionPlanning.js +1 -1
  23. package/dist/healthybowl/hooks/useSuccessionPlanning.js.map +1 -1
  24. package/dist/healthybowl/hooks/useWeatherIntelligence.js +1 -1
  25. package/dist/healthybowl/hooks/useWeatherIntelligence.js.map +1 -1
  26. package/dist/healthybowl/offline/OfflineStatusPill.js +21 -40
  27. package/dist/healthybowl/offline/OfflineStatusPill.js.map +1 -1
  28. package/dist/healthybowl/offline/OfflineSyncProvider.js +130 -153
  29. package/dist/healthybowl/offline/OfflineSyncProvider.js.map +1 -1
  30. package/dist/healthybowl/offline/graphql.js.map +1 -1
  31. package/dist/healthybowl/offline/store.js +1 -1
  32. package/dist/healthybowl/offline/syncEngine.js +1 -2
  33. package/dist/healthybowl/offline/syncEngine.js.map +1 -1
  34. package/dist/healthybowl/offline/types.js.map +1 -1
  35. package/dist/healthybowl/pages/GettingStartedPage.js +0 -1
  36. package/dist/healthybowl/pages/GettingStartedPage.js.map +1 -1
  37. package/dist/healthybowl/pages/analytics/InsightsPage.js +2 -2
  38. package/dist/healthybowl/pages/analytics/InsightsPage.js.map +1 -1
  39. package/dist/healthybowl/pages/analytics/ReportsPage.js +99 -136
  40. package/dist/healthybowl/pages/analytics/ReportsPage.js.map +1 -1
  41. package/dist/healthybowl/pages/compliance/ComplianceOverviewPage.js +162 -204
  42. package/dist/healthybowl/pages/compliance/ComplianceOverviewPage.js.map +1 -1
  43. package/dist/healthybowl/pages/compliance/IcsGroupDetailPage.js +178 -196
  44. package/dist/healthybowl/pages/compliance/IcsGroupDetailPage.js.map +1 -1
  45. package/dist/healthybowl/pages/compliance/IcsGrowerDetailPage.js +141 -142
  46. package/dist/healthybowl/pages/compliance/IcsGrowerDetailPage.js.map +1 -1
  47. package/dist/healthybowl/pages/crops/CropFieldsPage.js +0 -2
  48. package/dist/healthybowl/pages/crops/CropFieldsPage.js.map +1 -1
  49. package/dist/healthybowl/pages/crops/CropHarvestPage.js +272 -316
  50. package/dist/healthybowl/pages/crops/CropHarvestPage.js.map +1 -1
  51. package/dist/healthybowl/pages/crops/CropPlanningPage.js +0 -6
  52. package/dist/healthybowl/pages/crops/CropPlanningPage.js.map +1 -1
  53. package/dist/healthybowl/pages/crops/FieldDetailsPage.js +846 -871
  54. package/dist/healthybowl/pages/crops/FieldDetailsPage.js.map +1 -1
  55. package/dist/healthybowl/pages/crops/HarvestDetailsPage.js +334 -376
  56. package/dist/healthybowl/pages/crops/HarvestDetailsPage.js.map +1 -1
  57. package/dist/healthybowl/pages/distribution/CsaPlanDetailPage.js +188 -415
  58. package/dist/healthybowl/pages/distribution/CsaPlanDetailPage.js.map +1 -1
  59. package/dist/healthybowl/pages/distribution/labels.js +2 -10
  60. package/dist/healthybowl/pages/distribution/labels.js.map +1 -1
  61. package/dist/healthybowl/pages/farm/FarmProfilePage.js +0 -1
  62. package/dist/healthybowl/pages/farm/FarmProfilePage.js.map +1 -1
  63. package/dist/healthybowl/pages/field-capture/CaptureObservationForm.js +8 -8
  64. package/dist/healthybowl/pages/fields/FieldMapPage.js +0 -2
  65. package/dist/healthybowl/pages/fields/FieldMapPage.js.map +1 -1
  66. package/dist/healthybowl/pages/financial/FinancialReportsPage.js +107 -92
  67. package/dist/healthybowl/pages/financial/FinancialReportsPage.js.map +1 -1
  68. package/dist/healthybowl/pages/government-schemes/ApplicationTrackingPage.js +188 -228
  69. package/dist/healthybowl/pages/government-schemes/ApplicationTrackingPage.js.map +1 -1
  70. package/dist/healthybowl/pages/government-schemes/SchemeDetailsPage.js +191 -261
  71. package/dist/healthybowl/pages/government-schemes/SchemeDetailsPage.js.map +1 -1
  72. package/dist/healthybowl/pages/inputs-insurance/InputsInsuranceOverviewPage.js +14 -14
  73. package/dist/healthybowl/pages/inputs-insurance/InputsInsuranceOverviewPage.js.map +1 -1
  74. package/dist/healthybowl/pages/irrigation/IrrigationPage.js +307 -338
  75. package/dist/healthybowl/pages/irrigation/IrrigationPage.js.map +1 -1
  76. package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js +102 -126
  77. package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js.map +1 -1
  78. package/dist/healthybowl/pages/livestock/AnimalDepthPage.js +215 -257
  79. package/dist/healthybowl/pages/livestock/AnimalDepthPage.js.map +1 -1
  80. package/dist/healthybowl/pages/livestock/GrazingPage.js +0 -1
  81. package/dist/healthybowl/pages/livestock/GrazingPage.js.map +1 -1
  82. package/dist/healthybowl/pages/livestock/HerdDepthPage.js +0 -4
  83. package/dist/healthybowl/pages/livestock/HerdDepthPage.js.map +1 -1
  84. package/dist/healthybowl/pages/livestock/grazing/RecordGrazingMoveModal.js +9 -8
  85. package/dist/healthybowl/pages/livestock/grazing/RecordGrazingMoveModal.js.map +1 -1
  86. package/dist/healthybowl/pages/network/ExpertsPage.js +419 -520
  87. package/dist/healthybowl/pages/network/ExpertsPage.js.map +1 -1
  88. package/dist/healthybowl/pages/weather/WeatherAlertHistoryPage.js +130 -129
  89. package/dist/healthybowl/pages/weather/WeatherAlertHistoryPage.js.map +1 -1
  90. package/dist/healthybowl/pages/weather/WeatherSettingsPage.js +237 -285
  91. package/dist/healthybowl/pages/weather/WeatherSettingsPage.js.map +1 -1
  92. package/dist/healthybowl/utils/plantingCapacity.js +10 -10
  93. package/dist/healthybowl/utils/plantingCapacity.js.map +1 -1
  94. package/dist/node_modules/fast-equals/dist/es/index.js +86 -74
  95. package/dist/node_modules/fast-equals/dist/es/index.js.map +1 -1
  96. package/dist/services/assistantApi.js +30 -59
  97. package/dist/services/assistantApi.js.map +1 -1
  98. package/dist/utils/pageContext.js +1 -15
  99. package/dist/utils/pageContext.js.map +1 -1
  100. package/package.json +1 -1
  101. package/dist/healthybowl/hooks/useAgronomyDecisions.js +0 -79
  102. package/dist/healthybowl/hooks/useAgronomyDecisions.js.map +0 -1
  103. package/dist/healthybowl/hooks/useAnalyticsReports.js +0 -173
  104. package/dist/healthybowl/hooks/useAnalyticsReports.js.map +0 -1
  105. package/dist/healthybowl/hooks/useComplianceExports.js +0 -74
  106. package/dist/healthybowl/hooks/useComplianceExports.js.map +0 -1
  107. package/dist/healthybowl/hooks/useConsultationPayments.js +0 -59
  108. package/dist/healthybowl/hooks/useConsultationPayments.js.map +0 -1
  109. package/dist/healthybowl/hooks/usePlantingEstimate.js +0 -88
  110. package/dist/healthybowl/hooks/usePlantingEstimate.js.map +0 -1
  111. package/dist/healthybowl/offline/HeaderOfflinePill.js +0 -28
  112. package/dist/healthybowl/offline/HeaderOfflinePill.js.map +0 -1
  113. package/dist/healthybowl/offline/captureCache.js +0 -30
  114. package/dist/healthybowl/offline/captureCache.js.map +0 -1
  115. package/dist/healthybowl/offline/headerSlot.js +0 -24
  116. package/dist/healthybowl/offline/headerSlot.js.map +0 -1
  117. package/dist/healthybowl/pages/ai/AiDecisionsPage.js +0 -287
  118. package/dist/healthybowl/pages/ai/AiDecisionsPage.js.map +0 -1
  119. package/dist/healthybowl/pages/compliance/ResidueTestsPage.js +0 -291
  120. package/dist/healthybowl/pages/compliance/ResidueTestsPage.js.map +0 -1
  121. package/dist/healthybowl/pages/compliance/SubstanceRulesPage.js +0 -300
  122. package/dist/healthybowl/pages/compliance/SubstanceRulesPage.js.map +0 -1
  123. package/dist/healthybowl/pages/compliance/substanceRuleForm.js +0 -135
  124. package/dist/healthybowl/pages/compliance/substanceRuleForm.js.map +0 -1
  125. package/dist/healthybowl/pages/government-schemes/schemeApplicationTransitions.js +0 -49
  126. package/dist/healthybowl/pages/government-schemes/schemeApplicationTransitions.js.map +0 -1
  127. package/dist/healthybowl/pages/government-schemes/schemeDocumentSlots.js +0 -48
  128. package/dist/healthybowl/pages/government-schemes/schemeDocumentSlots.js.map +0 -1
  129. package/dist/healthybowl/pages/government-schemes/useSchemeApplicationTransition.js +0 -54
  130. package/dist/healthybowl/pages/government-schemes/useSchemeApplicationTransition.js.map +0 -1
  131. package/dist/healthybowl/pages/livestock/PedigreeTree.js +0 -154
  132. package/dist/healthybowl/pages/livestock/PedigreeTree.js.map +0 -1
  133. package/dist/healthybowl/pages/livestock/eidTagInput.js +0 -39
  134. package/dist/healthybowl/pages/livestock/eidTagInput.js.map +0 -1
  135. package/dist/healthybowl/pages/livestock/pedigreeLayout.js +0 -68
  136. package/dist/healthybowl/pages/livestock/pedigreeLayout.js.map +0 -1
  137. package/dist/healthybowl/pages/weather/alertDelivery.js +0 -105
  138. package/dist/healthybowl/pages/weather/alertDelivery.js.map +0 -1
  139. package/dist/healthybowl/utils/icsInspection.js +0 -18
  140. package/dist/healthybowl/utils/icsInspection.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"ResidueTestsPage.js","names":[],"sources":["../../../../src/healthybowl/pages/compliance/ResidueTestsPage.tsx"],"sourcesContent":["/**\n * Lab residue test results (BOFF-6020).\n *\n * The counterpart to `SubstanceRulesPage`: the rulebook says what is allowed, this records what a\n * lab actually measured. `createHealthyBowlResidueTest` screens the measurement against the\n * workspace rulebook **on write** and raises a CRITICAL finding straight away, so a breach reaches\n * the alerts inbox without anyone running a scan.\n *\n * The verdict column is display only — the server is the authority. It exists so a farmer reading\n * the list can see *why* a row is flagged without cross-referencing two pages, and so a\n * measurement against a substance nobody has written a rule for is visibly **unjudged** rather than\n * silently passing.\n */\nimport { useMemo, useState } from 'react';\nimport { FlaskConical, Plus, Trash2 } from 'lucide-react';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { Button, Input, Textarea } from '@burdenoff/fe-libs/ui';\nimport {\n PageLayout,\n DataTable,\n EmptyState,\n ErrorState,\n PageLoader,\n Modal,\n StatusBadge,\n useConfirm,\n} from '../../components';\nimport { ToastContainer } from '../../components/Toast';\nimport { useToast } from '../../hooks/useToast';\nimport { useHealthyBowlCompliance, type ResidueTest } from '../../hooks/useHealthyBowlCompliance';\nimport { formatDate, todayLocalDate } from '../../utils/helpers';\nimport {\n buildResidueTestInput,\n emptyResidueTestForm,\n residueVerdict,\n type ResidueFieldError,\n type ResidueTestFormValues,\n type ResidueVerdict,\n} from './substanceRuleForm';\n\nconst fieldLabel = 'mb-1 block text-sm font-medium text-text-primary';\n\nconst VERDICT_PRESENTATION: Record<\n ResidueVerdict,\n { variant: 'error' | 'success' | 'muted' | 'warning'; key: string; fallback: string }\n> = {\n BREACH: {\n variant: 'error',\n key: 'healthybowl.compliance.residueTests.verdict.breach',\n fallback: 'Over the limit',\n },\n PROHIBITED: {\n variant: 'error',\n key: 'healthybowl.compliance.residueTests.verdict.prohibited',\n fallback: 'Prohibited substance detected',\n },\n WITHIN_LIMIT: {\n variant: 'success',\n key: 'healthybowl.compliance.residueTests.verdict.within',\n fallback: 'Within limit',\n },\n // Deliberately not \"pass\": nobody has written a rule, so nothing has judged it.\n NO_RULE: {\n variant: 'muted',\n key: 'healthybowl.compliance.residueTests.verdict.noRule',\n fallback: 'No rule for this substance',\n },\n};\n\nexport const ResidueTestsPage = () => {\n const { t } = useI18n();\n const confirm = useConfirm();\n const { toast, toasts, dismiss } = useToast();\n const { residueTests, substanceRules, loading, errors, createResidueTest, deleteResidueTest } =\n useHealthyBowlCompliance();\n\n const [open, setOpen] = useState(false);\n const [values, setValues] = useState<ResidueTestFormValues>(() => emptyResidueTestForm(todayLocalDate()));\n const [fieldErrors, setFieldErrors] = useState<ResidueFieldError[]>([]);\n const [busy, setBusy] = useState(false);\n\n const errorFor = (field: keyof ResidueTestFormValues): ResidueFieldError | undefined =>\n fieldErrors.find((e) => e.field === field);\n\n const set = <K extends keyof ResidueTestFormValues>(key: K, value: ResidueTestFormValues[K]) =>\n setValues((prev) => ({ ...prev, [key]: value }));\n\n const rows = useMemo(\n () => residueTests.map((test) => ({ ...test, ...residueVerdict(test, substanceRules) })),\n [residueTests, substanceRules]\n );\n\n const startCreate = () => {\n setValues(emptyResidueTestForm(todayLocalDate()));\n setFieldErrors([]);\n setOpen(true);\n };\n\n const submit = async () => {\n const built = buildResidueTestInput(values);\n if (!built.ok) {\n setFieldErrors(built.errors);\n return;\n }\n setBusy(true);\n try {\n await createResidueTest(built.input);\n setOpen(false);\n toast({\n title: t('healthybowl.compliance.residueTests.toast.created', 'Residue test recorded'),\n description: t(\n 'healthybowl.compliance.residueTests.toast.createdDesc',\n 'It has been screened against the substance rulebook. Any breach appears in Compliance alerts.'\n ),\n variant: 'success',\n });\n } catch (err) {\n toast({\n title: t('healthybowl.compliance.residueTests.toast.failed', 'Could not record the test'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n } finally {\n setBusy(false);\n }\n };\n\n const remove = async (test: ResidueTest) => {\n const ok = await confirm({\n title: t('healthybowl.compliance.residueTests.confirm.title', 'Remove this test result?'),\n message: t(\n 'healthybowl.compliance.residueTests.confirm.description',\n 'Any compliance finding this result raised stays on record. Remove it only if the result was entered in error.'\n ),\n });\n if (!ok) return;\n try {\n await deleteResidueTest(test.id);\n toast({ title: t('healthybowl.compliance.residueTests.toast.removed', 'Test removed'), variant: 'success' });\n } catch (err) {\n toast({\n title: t('healthybowl.compliance.residueTests.toast.removeFailed', 'Could not remove the test'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n }\n };\n\n if (loading.residue && residueTests.length === 0) return <PageLoader />;\n if (errors.residue && residueTests.length === 0) return <ErrorState description={errors.residue.message} />;\n\n return (\n <PageLayout\n title={t('healthybowl.compliance.residueTests.title', 'Lab residue tests')}\n description={t(\n 'healthybowl.compliance.residueTests.description',\n 'Recorded laboratory measurements, screened against this workspace’s substance rules as they are entered.'\n )}\n purpose=\"Record what a laboratory measured on a batch or a crop. Each result is checked against the substance rulebook on save — a reading over a limit, or any detection of a prohibited substance, raises a critical compliance finding immediately.\"\n actions={\n <Button onClick={startCreate}>\n <Plus className=\"h-4 w-4\" />\n {t('healthybowl.compliance.residueTests.add', 'Record test')}\n </Button>\n }\n >\n {rows.length === 0 ? (\n <EmptyState\n icon={<FlaskConical className=\"h-6 w-6\" />}\n title={t('healthybowl.compliance.residueTests.emptyTitle', 'No residue tests recorded')}\n description={t(\n 'healthybowl.compliance.residueTests.emptyDescription',\n 'Record a laboratory result to have it screened against your substance rules.'\n )}\n action={<Button onClick={startCreate}>{t('healthybowl.compliance.residueTests.add', 'Record test')}</Button>}\n />\n ) : (\n <DataTable\n data={rows}\n keyField=\"id\"\n columns={[\n {\n key: 'substanceName',\n header: t('healthybowl.compliance.residueTests.col.substance', 'Substance'),\n render: (r: (typeof rows)[number]) => (\n <span className=\"font-medium text-text-primary\">{r.substanceName}</span>\n ),\n },\n {\n key: 'measuredMgPerKg',\n header: t('healthybowl.compliance.residueTests.col.measured', 'Measured'),\n render: (r: (typeof rows)[number]) => (\n <span className=\"tabular-nums text-text-primary\">\n {t('healthybowl.compliance.residueTests.mgPerKg', '{{n}} mg/kg', { n: r.measuredMgPerKg })}\n </span>\n ),\n },\n {\n key: 'verdict',\n header: t('healthybowl.compliance.residueTests.col.verdict', 'Against the rulebook'),\n render: (r: (typeof rows)[number]) => {\n const p = VERDICT_PRESENTATION[r.verdict];\n return (\n <span className=\"inline-flex items-center gap-2\">\n <StatusBadge variant={p.variant} label={t(p.key, p.fallback)} />\n {r.rule !== null && r.rule.mrlMgPerKg !== null ? (\n <span className=\"text-xs tabular-nums text-text-secondary\">\n {t('healthybowl.compliance.residueTests.limitIs', 'limit {{n}}', { n: r.rule.mrlMgPerKg })}\n </span>\n ) : null}\n </span>\n );\n },\n },\n {\n key: 'testedAt',\n header: t('healthybowl.compliance.residueTests.col.testedAt', 'Tested'),\n render: (r: (typeof rows)[number]) => formatDate(r.testedAt),\n },\n {\n key: 'laboratory',\n header: t('healthybowl.compliance.residueTests.col.lab', 'Laboratory'),\n render: (r: (typeof rows)[number]) => r.laboratory ?? '—',\n },\n {\n key: 'actions',\n header: '',\n render: (r: (typeof rows)[number]) => (\n <div className=\"flex justify-end\">\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => void remove(r)}\n aria-label={t('healthybowl.compliance.residueTests.remove', 'Remove test')}\n >\n <Trash2 className=\"h-3.5 w-3.5\" />\n </Button>\n </div>\n ),\n },\n ]}\n />\n )}\n\n <Modal\n open={open}\n onClose={() => setOpen(false)}\n title={t('healthybowl.compliance.residueTests.addTitle', 'Record a residue test')}\n footer={\n <div className=\"flex justify-end gap-2\">\n <Button variant=\"outline\" onClick={() => setOpen(false)} disabled={busy}>\n {t('common.cancel', 'Cancel')}\n </Button>\n <Button onClick={() => void submit()} disabled={busy}>\n {busy ? t('common.saving', 'Saving…') : t('common.save', 'Save')}\n </Button>\n </div>\n }\n >\n <div className=\"space-y-4\">\n <div>\n <label htmlFor=\"residue-substance\" className={fieldLabel}>\n {t('healthybowl.compliance.residueTests.field.substance', 'Substance name')}\n </label>\n <Input\n id=\"residue-substance\"\n value={values.substanceName}\n onChange={(e) => set('substanceName', e.target.value)}\n placeholder=\"Chlorpyrifos\"\n list=\"hb-substance-names\"\n />\n {/* Typing a name that matches a rule is what makes the screening fire, so offer the\n rulebook rather than leaving the operator to remember the exact spelling. */}\n <datalist id=\"hb-substance-names\">\n {substanceRules.map((r) => (\n <option key={r.id} value={r.substanceName} />\n ))}\n </datalist>\n {errorFor('substanceName') ? (\n <p className=\"mt-1 text-xs text-status-error-text\">\n {t(errorFor('substanceName')!.messageKey, errorFor('substanceName')!.messageFallback)}\n </p>\n ) : null}\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n <div>\n <label htmlFor=\"residue-measured\" className={fieldLabel}>\n {t('healthybowl.compliance.residueTests.field.measured', 'Measured residue (mg/kg)')}\n </label>\n <Input\n id=\"residue-measured\"\n inputMode=\"decimal\"\n value={values.measuredMgPerKg}\n onChange={(e) => set('measuredMgPerKg', e.target.value)}\n placeholder=\"0.005\"\n />\n {errorFor('measuredMgPerKg') ? (\n <p className=\"mt-1 text-xs text-status-error-text\">\n {t(errorFor('measuredMgPerKg')!.messageKey, errorFor('measuredMgPerKg')!.messageFallback)}\n </p>\n ) : null}\n </div>\n <div>\n <label htmlFor=\"residue-tested-at\" className={fieldLabel}>\n {t('healthybowl.compliance.residueTests.field.testedAt', 'Test date')}\n </label>\n <Input\n id=\"residue-tested-at\"\n type=\"date\"\n value={values.testedAt}\n onChange={(e) => set('testedAt', e.target.value)}\n />\n {errorFor('testedAt') ? (\n <p className=\"mt-1 text-xs text-status-error-text\">\n {t(errorFor('testedAt')!.messageKey, errorFor('testedAt')!.messageFallback)}\n </p>\n ) : null}\n </div>\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n <div>\n <label htmlFor=\"residue-lab\" className={fieldLabel}>\n {t('healthybowl.compliance.residueTests.field.lab', 'Laboratory (optional)')}\n </label>\n <Input id=\"residue-lab\" value={values.laboratory} onChange={(e) => set('laboratory', e.target.value)} />\n </div>\n <div>\n <label htmlFor=\"residue-batch\" className={fieldLabel}>\n {t('healthybowl.compliance.residueTests.field.batch', 'Trace batch id (optional)')}\n </label>\n <Input\n id=\"residue-batch\"\n value={values.traceBatchId}\n onChange={(e) => set('traceBatchId', e.target.value)}\n />\n </div>\n </div>\n\n <div>\n <label htmlFor=\"residue-notes\" className={fieldLabel}>\n {t('healthybowl.compliance.residueTests.field.notes', 'Notes (optional)')}\n </label>\n <Textarea id=\"residue-notes\" value={values.notes} onChange={(e) => set('notes', e.target.value)} />\n </div>\n </div>\n </Modal>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwCA,IAAM,IAAa,oDAEb,IAGF;CACF,QAAQ;EACN,SAAS;EACT,KAAK;EACL,UAAU;CACZ;CACA,YAAY;EACV,SAAS;EACT,KAAK;EACL,UAAU;CACZ;CACA,cAAc;EACZ,SAAS;EACT,KAAK;EACL,UAAU;CACZ;CAEA,SAAS;EACP,SAAS;EACT,KAAK;EACL,UAAU;CACZ;AACF,GAEa,UAAyB;CACpC,IAAM,EAAE,SAAM,EAAQ,GAChB,IAAU,EAAW,GACrB,EAAE,UAAO,WAAQ,eAAY,EAAS,GACtC,EAAE,iBAAc,mBAAgB,YAAS,WAAQ,sBAAmB,yBACxE,EAAyB,GAErB,CAAC,GAAM,KAAW,EAAS,EAAK,GAChC,CAAC,GAAQ,KAAa,QAAsC,EAAqB,EAAe,CAAC,CAAC,GAClG,CAAC,GAAa,KAAkB,EAA8B,CAAC,CAAC,GAChE,CAAC,GAAM,KAAW,EAAS,EAAK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ACtE,CAAA,GACP,kBAAC,GAAD;QAAO,IAAG;QAAc,OAAO,EAAO;QAAY,WAAW,MAAM,EAAI,cAAc,EAAE,OAAO,KAAK;OAAI,CAAA,CACpG,EAAA,CAAA,GACL,kBAAC,OAAD,EAAA,UAAA,CACE,kBAAC,SAAD;QAAO,SAAQ;QAAgB,WAAW;kBACvC,EAAE,mDAAmD,2BAA2B;OAC5E,CAAA,GACP,kBAAC,GAAD;QACE,IAAG;QACH,OAAO,EAAO;QACd,WAAW,MAAM,EAAI,gBAAgB,EAAE,OAAO,KAAK;OACpD,CAAA,CACE,EAAA,CAAA,CACF;;MAEL,kBAAC,OAAD,EAAA,UAAA,CACE,kBAAC,SAAD;OAAO,SAAQ;OAAgB,WAAW;iBACvC,EAAE,mDAAmD,kBAAkB;MACnE,CAAA,GACP,kBAAC,GAAD;OAAU,IAAG;OAAgB,OAAO,EAAO;OAAO,WAAW,MAAM,EAAI,SAAS,EAAE,OAAO,KAAK;MAAI,CAAA,CAC/F,EAAA,CAAA;KACF;;GACA,CAAA;GAEP,kBAAC,GAAD;IAAwB;IAAQ,WAAW;GAAU,CAAA;EAC3C;;AAEhB"}
@@ -1,300 +0,0 @@
1
- import { PageLayout as e } from "../../components/PageLayout.js";
2
- import { DataTable as t } from "../../components/DataTable.js";
3
- import { StatusBadge as n } from "../../components/StatusBadge.js";
4
- import { EmptyState as ee } from "../../components/EmptyState.js";
5
- import { ErrorState as te } from "../../components/ErrorState.js";
6
- import { ToastContainer as r } from "../../components/Toast.js";
7
- import { useConfirm as i } from "../../components/ConfirmDialog.js";
8
- import { PageLoader as a } from "../../components/PageLoader.js";
9
- import { Modal as o } from "../../components/Modal.js";
10
- import { useToast as s } from "../../hooks/useToast.js";
11
- import "../../components/index.js";
12
- import { useHealthyBowlCompliance as c } from "../../hooks/useHealthyBowlCompliance.js";
13
- import { buildSubstanceRuleInput as l, emptySubstanceRuleForm as u, hasNoNumericLimit as d, substanceRuleToForm as f } from "./substanceRuleForm.js";
14
- import { useMemo as ne, useState as p } from "react";
15
- import { useI18n as re } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
16
- import { AlertTriangle as ie, Ban as ae, FlaskConical as m, Gauge as h, Pencil as g, Plus as _, Trash2 as v } from "lucide-react";
17
- import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
18
- import { Button as S, Input as C, Select as w, SelectContent as T, SelectItem as E, SelectTrigger as D, SelectValue as O, Textarea as k } from "@burdenoff/fe-libs/ui";
19
- //#region src/healthybowl/pages/compliance/SubstanceRulesPage.tsx
20
- var A = "mb-1 block text-sm font-medium text-text-primary", j = () => {
21
- let { t: j } = re(), M = i(), { toast: N, toasts: P, dismiss: F } = s(), { substanceRules: I, loading: oe, errors: L, createSubstanceRule: R, updateSubstanceRule: z, deleteSubstanceRule: B } = c(), [V, H] = p(!1), [U, W] = p(null), [G, K] = p(u), [q, J] = p([]), [Y, X] = p(!1), Z = (e) => q.find((t) => t.field === e), Q = (e, t) => K((n) => ({
22
- ...n,
23
- [e]: t
24
- })), $ = () => {
25
- W(null), K(u), J([]), H(!0);
26
- }, se = (e) => {
27
- W(e), K(f(e)), J([]), H(!0);
28
- }, ce = async () => {
29
- let e = l(G);
30
- if (!e.ok) {
31
- J(e.errors);
32
- return;
33
- }
34
- X(!0);
35
- try {
36
- U ? await z({
37
- ...e.input,
38
- id: U.id
39
- }) : await R(e.input), H(!1), N({
40
- title: U ? j("healthybowl.compliance.substanceRules.toast.updated", "Rule updated") : j("healthybowl.compliance.substanceRules.toast.created", "Rule added"),
41
- variant: "success"
42
- });
43
- } catch (e) {
44
- N({
45
- title: j("healthybowl.compliance.substanceRules.toast.failed", "Could not save the rule"),
46
- description: e instanceof Error ? e.message : String(e),
47
- variant: "error"
48
- });
49
- } finally {
50
- X(!1);
51
- }
52
- }, le = async (e) => {
53
- if (await M({
54
- title: j("healthybowl.compliance.substanceRules.confirm.title", "Remove this rule?"),
55
- message: j("healthybowl.compliance.substanceRules.confirm.description", "Residue tests already recorded keep their findings. New tests will no longer be screened against this substance.")
56
- })) try {
57
- await B(e.id), N({
58
- title: j("healthybowl.compliance.substanceRules.toast.removed", "Rule removed"),
59
- variant: "success"
60
- });
61
- } catch (e) {
62
- N({
63
- title: j("healthybowl.compliance.substanceRules.toast.removeFailed", "Could not remove the rule"),
64
- description: e instanceof Error ? e.message : String(e),
65
- variant: "error"
66
- });
67
- }
68
- }, ue = ne(() => d(I), [I]);
69
- return oe.rules && I.length === 0 ? /* @__PURE__ */ b(a, {}) : L.rules && I.length === 0 ? /* @__PURE__ */ b(te, { description: L.rules.message }) : /* @__PURE__ */ x(e, {
70
- title: j("healthybowl.compliance.substanceRules.title", "Substance rules & residue limits"),
71
- description: j("healthybowl.compliance.substanceRules.description", "The rulebook every recorded residue test is screened against — prohibited substances, and maximum residue limits in mg/kg."),
72
- purpose: "Set what may not be used on this farm at all, and what may be used only below a numeric limit. A lab result recorded above a limit here raises a critical compliance finding straight away, without anyone running a scan.",
73
- actions: /* @__PURE__ */ x(S, {
74
- onClick: $,
75
- children: [/* @__PURE__ */ b(_, { className: "h-4 w-4" }), j("healthybowl.compliance.substanceRules.add", "Add rule")]
76
- }),
77
- children: [
78
- ue ? /* @__PURE__ */ x("div", {
79
- className: "mb-4 flex items-start gap-2 rounded-lg border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text",
80
- children: [/* @__PURE__ */ b(ie, { className: "mt-0.5 h-4 w-4 shrink-0" }), /* @__PURE__ */ b("span", { children: j("healthybowl.compliance.substanceRules.noLimits", "No rule in this workspace carries a numeric limit, so a residue test can never be found to exceed one. The built-in list covers outright bans only — add a limit rule for any substance your buyer or certifier caps rather than forbids.") })]
81
- }) : null,
82
- I.length === 0 ? /* @__PURE__ */ b(ee, {
83
- icon: /* @__PURE__ */ b(m, { className: "h-6 w-6" }),
84
- title: j("healthybowl.compliance.substanceRules.emptyTitle", "No substance rules yet"),
85
- description: j("healthybowl.compliance.substanceRules.emptyDescription", "Add the substances your certification prohibits, and the residue limits your buyers enforce."),
86
- action: /* @__PURE__ */ b(S, {
87
- onClick: $,
88
- children: j("healthybowl.compliance.substanceRules.add", "Add rule")
89
- })
90
- }) : /* @__PURE__ */ b(t, {
91
- data: I,
92
- keyField: "id",
93
- columns: [
94
- {
95
- key: "substanceName",
96
- header: j("healthybowl.compliance.substanceRules.col.substance", "Substance"),
97
- render: (e) => /* @__PURE__ */ x("div", { children: [/* @__PURE__ */ b("span", {
98
- className: "font-medium text-text-primary",
99
- children: e.substanceName
100
- }), e.activeIngredient ? /* @__PURE__ */ b("span", {
101
- className: "ms-2 text-xs text-text-secondary",
102
- children: e.activeIngredient
103
- }) : null] })
104
- },
105
- {
106
- key: "rule",
107
- header: j("healthybowl.compliance.substanceRules.col.rule", "Rule"),
108
- render: (e) => e.mrlMgPerKg === null ? /* @__PURE__ */ x("span", {
109
- className: "inline-flex items-center gap-1 text-sm text-text-primary",
110
- children: [/* @__PURE__ */ b(ae, { className: "h-3.5 w-3.5 text-status-error-text" }), j("healthybowl.compliance.substanceRules.prohibited", "Prohibited")]
111
- }) : /* @__PURE__ */ x("span", {
112
- className: "inline-flex items-center gap-1 text-sm tabular-nums text-text-primary",
113
- children: [/* @__PURE__ */ b(h, { className: "h-3.5 w-3.5 text-text-secondary" }), j("healthybowl.compliance.substanceRules.limitValue", "≤ {{n}} mg/kg", { n: e.mrlMgPerKg })]
114
- })
115
- },
116
- {
117
- key: "cropScope",
118
- header: j("healthybowl.compliance.substanceRules.col.scope", "Applies to"),
119
- render: (e) => e.cropScope ?? j("healthybowl.compliance.substanceRules.allCrops", "All crops")
120
- },
121
- {
122
- key: "source",
123
- header: j("healthybowl.compliance.substanceRules.col.source", "Source"),
124
- render: (e) => /* @__PURE__ */ x("span", {
125
- className: "inline-flex items-center gap-2",
126
- children: [/* @__PURE__ */ b("span", {
127
- className: "text-sm text-text-secondary",
128
- children: e.source
129
- }), e.builtin ? /* @__PURE__ */ b(n, {
130
- variant: "muted",
131
- label: j("healthybowl.compliance.substanceRules.builtin", "Built-in")
132
- }) : null]
133
- })
134
- },
135
- {
136
- key: "actions",
137
- header: "",
138
- render: (e) => /* @__PURE__ */ b("div", {
139
- className: "flex items-center justify-end gap-1",
140
- children: e.builtin ? /* @__PURE__ */ b("span", {
141
- className: "text-xs text-text-secondary",
142
- children: j("healthybowl.compliance.substanceRules.builtinHint", "Add your own rule to override")
143
- }) : /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ b(S, {
144
- variant: "ghost",
145
- size: "sm",
146
- onClick: () => se(e),
147
- "aria-label": j("healthybowl.compliance.substanceRules.edit", "Edit rule"),
148
- children: /* @__PURE__ */ b(g, { className: "h-3.5 w-3.5" })
149
- }), /* @__PURE__ */ b(S, {
150
- variant: "ghost",
151
- size: "sm",
152
- onClick: () => void le(e),
153
- "aria-label": j("healthybowl.compliance.substanceRules.remove", "Remove rule"),
154
- children: /* @__PURE__ */ b(v, { className: "h-3.5 w-3.5" })
155
- })] })
156
- })
157
- }
158
- ]
159
- }),
160
- /* @__PURE__ */ b(o, {
161
- open: V,
162
- onClose: () => H(!1),
163
- title: U ? j("healthybowl.compliance.substanceRules.editTitle", "Edit substance rule") : j("healthybowl.compliance.substanceRules.addTitle", "Add substance rule"),
164
- footer: /* @__PURE__ */ x("div", {
165
- className: "flex justify-end gap-2",
166
- children: [/* @__PURE__ */ b(S, {
167
- variant: "outline",
168
- onClick: () => H(!1),
169
- disabled: Y,
170
- children: j("common.cancel", "Cancel")
171
- }), /* @__PURE__ */ b(S, {
172
- onClick: () => void ce(),
173
- disabled: Y,
174
- children: Y ? j("common.saving", "Saving…") : j("common.save", "Save")
175
- })]
176
- }),
177
- children: /* @__PURE__ */ x("div", {
178
- className: "space-y-4",
179
- children: [
180
- /* @__PURE__ */ x("div", { children: [
181
- /* @__PURE__ */ b("label", {
182
- htmlFor: "substance-name",
183
- className: A,
184
- children: j("healthybowl.compliance.substanceRules.field.substance", "Substance name")
185
- }),
186
- /* @__PURE__ */ b(C, {
187
- id: "substance-name",
188
- value: G.substanceName,
189
- onChange: (e) => Q("substanceName", e.target.value),
190
- placeholder: "Chlorpyrifos"
191
- }),
192
- Z("substanceName") ? /* @__PURE__ */ b("p", {
193
- className: "mt-1 text-xs text-status-error-text",
194
- children: j(Z("substanceName").messageKey, Z("substanceName").messageFallback)
195
- }) : null
196
- ] }),
197
- /* @__PURE__ */ x("div", {
198
- className: "grid grid-cols-1 gap-4 sm:grid-cols-2",
199
- children: [/* @__PURE__ */ x("div", { children: [/* @__PURE__ */ b("label", {
200
- htmlFor: "substance-ingredient",
201
- className: A,
202
- children: j("healthybowl.compliance.substanceRules.field.ingredient", "Active ingredient (optional)")
203
- }), /* @__PURE__ */ b(C, {
204
- id: "substance-ingredient",
205
- value: G.activeIngredient,
206
- onChange: (e) => Q("activeIngredient", e.target.value)
207
- })] }), /* @__PURE__ */ x("div", { children: [/* @__PURE__ */ b("label", {
208
- htmlFor: "substance-cas",
209
- className: A,
210
- children: j("healthybowl.compliance.substanceRules.field.cas", "CAS number (optional)")
211
- }), /* @__PURE__ */ b(C, {
212
- id: "substance-cas",
213
- value: G.casNumber,
214
- onChange: (e) => Q("casNumber", e.target.value)
215
- })] })]
216
- }),
217
- /* @__PURE__ */ x("div", { children: [/* @__PURE__ */ b("span", {
218
- className: A,
219
- children: j("healthybowl.compliance.substanceRules.field.mode", "How is it constrained?")
220
- }), /* @__PURE__ */ x(w, {
221
- value: G.mode,
222
- onValueChange: (e) => Q("mode", e === "LIMIT" ? "LIMIT" : "PROHIBITED"),
223
- children: [/* @__PURE__ */ b(D, { children: /* @__PURE__ */ b(O, {}) }), /* @__PURE__ */ x(T, { children: [/* @__PURE__ */ b(E, {
224
- value: "PROHIBITED",
225
- children: j("healthybowl.compliance.substanceRules.mode.prohibited", "Prohibited — may not be used at all")
226
- }), /* @__PURE__ */ b(E, {
227
- value: "LIMIT",
228
- children: j("healthybowl.compliance.substanceRules.mode.limit", "Limit — allowed below a residue threshold")
229
- })] })]
230
- })] }),
231
- G.mode === "LIMIT" ? /* @__PURE__ */ x("div", { children: [
232
- /* @__PURE__ */ b("label", {
233
- htmlFor: "substance-mrl",
234
- className: A,
235
- children: j("healthybowl.compliance.substanceRules.field.mrl", "Maximum residue limit (mg/kg)")
236
- }),
237
- /* @__PURE__ */ b(C, {
238
- id: "substance-mrl",
239
- inputMode: "decimal",
240
- value: G.mrlMgPerKg,
241
- onChange: (e) => Q("mrlMgPerKg", e.target.value),
242
- placeholder: "0.01"
243
- }),
244
- Z("mrlMgPerKg") ? /* @__PURE__ */ b("p", {
245
- className: "mt-1 text-xs text-status-error-text",
246
- children: j(Z("mrlMgPerKg").messageKey, Z("mrlMgPerKg").messageFallback)
247
- }) : null
248
- ] }) : null,
249
- /* @__PURE__ */ x("div", {
250
- className: "grid grid-cols-1 gap-4 sm:grid-cols-2",
251
- children: [/* @__PURE__ */ x("div", { children: [
252
- /* @__PURE__ */ b("label", {
253
- htmlFor: "substance-scope",
254
- className: A,
255
- children: j("healthybowl.compliance.substanceRules.field.scope", "Crop scope (optional)")
256
- }),
257
- /* @__PURE__ */ b(C, {
258
- id: "substance-scope",
259
- value: G.cropScope,
260
- onChange: (e) => Q("cropScope", e.target.value),
261
- placeholder: j("healthybowl.compliance.substanceRules.allCrops", "All crops")
262
- }),
263
- G.cropScope.trim().length > 0 ? /* @__PURE__ */ b("p", {
264
- className: "mt-1 text-xs text-status-warning-text",
265
- children: j("healthybowl.compliance.substanceRules.cropScopeWarning", "A rule limited to one crop is not currently screened against lab results — residue tests are matched by substance only. Leave this blank for the rule to take effect.")
266
- }) : null
267
- ] }), /* @__PURE__ */ x("div", { children: [/* @__PURE__ */ b("label", {
268
- htmlFor: "substance-source",
269
- className: A,
270
- children: j("healthybowl.compliance.substanceRules.field.source", "Source (optional)")
271
- }), /* @__PURE__ */ b(C, {
272
- id: "substance-source",
273
- value: G.source,
274
- onChange: (e) => Q("source", e.target.value),
275
- placeholder: "FSSAI notification / buyer contract"
276
- })] })]
277
- }),
278
- /* @__PURE__ */ x("div", { children: [/* @__PURE__ */ b("label", {
279
- htmlFor: "substance-notes",
280
- className: A,
281
- children: j("healthybowl.compliance.substanceRules.field.notes", "Notes (optional)")
282
- }), /* @__PURE__ */ b(k, {
283
- id: "substance-notes",
284
- value: G.notes,
285
- onChange: (e) => Q("notes", e.target.value)
286
- })] })
287
- ]
288
- })
289
- }),
290
- /* @__PURE__ */ b(r, {
291
- toasts: P,
292
- onDismiss: F
293
- })
294
- ]
295
- });
296
- };
297
- //#endregion
298
- export { j as SubstanceRulesPage };
299
-
300
- //# sourceMappingURL=SubstanceRulesPage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SubstanceRulesPage.js","names":[],"sources":["../../../../src/healthybowl/pages/compliance/SubstanceRulesPage.tsx"],"sourcesContent":["/**\n * MRL / prohibited-substance rulebook (BOFF-6020).\n *\n * The backend has shipped a complete residue-screening engine since the compliance module landed —\n * a per-workspace substance rulebook, lab residue measurements, inline flag raising on write, and\n * an idempotent compliance scan. None of it was reachable from the app: `useHealthyBowlCompliance`\n * already fetched both lists and exposed create/delete, and no page destructured either.\n *\n * The consequence worth stating plainly: **no built-in rule carries a numeric MRL, and no user\n * could create one, so `MRL_EXCEEDED` could never fire.** For an organic-certification product a\n * check that silently always passes is false assurance, not a missing feature. This page is what\n * makes the check fireable, and it says so when the rulebook still cannot raise one.\n *\n * Every decision lives in `substanceRuleForm.ts`, which is unit-tested; this file is presentational.\n */\nimport { useMemo, useState } from 'react';\nimport { AlertTriangle, Ban, FlaskConical, Gauge, Pencil, Plus, Trash2 } from 'lucide-react';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport {\n Button,\n Input,\n Textarea,\n Select,\n SelectTrigger,\n SelectValue,\n SelectContent,\n SelectItem,\n} from '@burdenoff/fe-libs/ui';\nimport {\n PageLayout,\n DataTable,\n EmptyState,\n ErrorState,\n PageLoader,\n Modal,\n StatusBadge,\n useConfirm,\n} from '../../components';\nimport { ToastContainer } from '../../components/Toast';\nimport { useToast } from '../../hooks/useToast';\nimport { useHealthyBowlCompliance, type SubstanceRule } from '../../hooks/useHealthyBowlCompliance';\nimport {\n buildSubstanceRuleInput,\n emptySubstanceRuleForm,\n hasNoNumericLimit,\n substanceRuleToForm,\n type FieldError,\n type SubstanceRuleFormValues,\n} from './substanceRuleForm';\n\nconst fieldLabel = 'mb-1 block text-sm font-medium text-text-primary';\n\nexport const SubstanceRulesPage = () => {\n const { t } = useI18n();\n const confirm = useConfirm();\n const { toast, toasts, dismiss } = useToast();\n const { substanceRules, loading, errors, createSubstanceRule, updateSubstanceRule, deleteSubstanceRule } =\n useHealthyBowlCompliance();\n\n const [open, setOpen] = useState(false);\n const [editing, setEditing] = useState<SubstanceRule | null>(null);\n const [values, setValues] = useState<SubstanceRuleFormValues>(emptySubstanceRuleForm);\n const [fieldErrors, setFieldErrors] = useState<FieldError[]>([]);\n const [busy, setBusy] = useState(false);\n\n const errorFor = (field: keyof SubstanceRuleFormValues): FieldError | undefined =>\n fieldErrors.find((e) => e.field === field);\n\n const set = <K extends keyof SubstanceRuleFormValues>(key: K, value: SubstanceRuleFormValues[K]) =>\n setValues((prev) => ({ ...prev, [key]: value }));\n\n const startCreate = () => {\n setEditing(null);\n setValues(emptySubstanceRuleForm);\n setFieldErrors([]);\n setOpen(true);\n };\n\n const startEdit = (rule: SubstanceRule) => {\n setEditing(rule);\n setValues(substanceRuleToForm(rule));\n setFieldErrors([]);\n setOpen(true);\n };\n\n const submit = async () => {\n const built = buildSubstanceRuleInput(values);\n if (!built.ok) {\n setFieldErrors(built.errors);\n return;\n }\n setBusy(true);\n try {\n if (editing) await updateSubstanceRule({ ...built.input, id: editing.id });\n else await createSubstanceRule(built.input);\n setOpen(false);\n toast({\n title: editing\n ? t('healthybowl.compliance.substanceRules.toast.updated', 'Rule updated')\n : t('healthybowl.compliance.substanceRules.toast.created', 'Rule added'),\n variant: 'success',\n });\n } catch (err) {\n toast({\n title: t('healthybowl.compliance.substanceRules.toast.failed', 'Could not save the rule'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n } finally {\n setBusy(false);\n }\n };\n\n const remove = async (rule: SubstanceRule) => {\n const ok = await confirm({\n title: t('healthybowl.compliance.substanceRules.confirm.title', 'Remove this rule?'),\n message: t(\n 'healthybowl.compliance.substanceRules.confirm.description',\n 'Residue tests already recorded keep their findings. New tests will no longer be screened against this substance.'\n ),\n });\n if (!ok) return;\n try {\n await deleteSubstanceRule(rule.id);\n toast({ title: t('healthybowl.compliance.substanceRules.toast.removed', 'Rule removed'), variant: 'success' });\n } catch (err) {\n toast({\n title: t('healthybowl.compliance.substanceRules.toast.removeFailed', 'Could not remove the rule'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n }\n };\n\n const noLimits = useMemo(() => hasNoNumericLimit(substanceRules), [substanceRules]);\n\n if (loading.rules && substanceRules.length === 0) return <PageLoader />;\n if (errors.rules && substanceRules.length === 0) return <ErrorState description={errors.rules.message} />;\n\n return (\n <PageLayout\n title={t('healthybowl.compliance.substanceRules.title', 'Substance rules & residue limits')}\n description={t(\n 'healthybowl.compliance.substanceRules.description',\n 'The rulebook every recorded residue test is screened against — prohibited substances, and maximum residue limits in mg/kg.'\n )}\n purpose=\"Set what may not be used on this farm at all, and what may be used only below a numeric limit. A lab result recorded above a limit here raises a critical compliance finding straight away, without anyone running a scan.\"\n actions={\n <Button onClick={startCreate}>\n <Plus className=\"h-4 w-4\" />\n {t('healthybowl.compliance.substanceRules.add', 'Add rule')}\n </Button>\n }\n >\n {/* The silence looked like a pass; this is the whole point of the ticket. */}\n {noLimits ? (\n <div className=\"mb-4 flex items-start gap-2 rounded-lg border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text\">\n <AlertTriangle className=\"mt-0.5 h-4 w-4 shrink-0\" />\n <span>\n {t(\n 'healthybowl.compliance.substanceRules.noLimits',\n 'No rule in this workspace carries a numeric limit, so a residue test can never be found to exceed one. The built-in list covers outright bans only — add a limit rule for any substance your buyer or certifier caps rather than forbids.'\n )}\n </span>\n </div>\n ) : null}\n\n {substanceRules.length === 0 ? (\n <EmptyState\n icon={<FlaskConical className=\"h-6 w-6\" />}\n title={t('healthybowl.compliance.substanceRules.emptyTitle', 'No substance rules yet')}\n description={t(\n 'healthybowl.compliance.substanceRules.emptyDescription',\n 'Add the substances your certification prohibits, and the residue limits your buyers enforce.'\n )}\n action={<Button onClick={startCreate}>{t('healthybowl.compliance.substanceRules.add', 'Add rule')}</Button>}\n />\n ) : (\n <DataTable\n data={substanceRules}\n keyField=\"id\"\n columns={[\n {\n key: 'substanceName',\n header: t('healthybowl.compliance.substanceRules.col.substance', 'Substance'),\n render: (r: SubstanceRule) => (\n <div>\n <span className=\"font-medium text-text-primary\">{r.substanceName}</span>\n {r.activeIngredient ? (\n <span className=\"ms-2 text-xs text-text-secondary\">{r.activeIngredient}</span>\n ) : null}\n </div>\n ),\n },\n {\n key: 'rule',\n header: t('healthybowl.compliance.substanceRules.col.rule', 'Rule'),\n render: (r: SubstanceRule) =>\n r.mrlMgPerKg === null ? (\n <span className=\"inline-flex items-center gap-1 text-sm text-text-primary\">\n <Ban className=\"h-3.5 w-3.5 text-status-error-text\" />\n {t('healthybowl.compliance.substanceRules.prohibited', 'Prohibited')}\n </span>\n ) : (\n <span className=\"inline-flex items-center gap-1 text-sm tabular-nums text-text-primary\">\n <Gauge className=\"h-3.5 w-3.5 text-text-secondary\" />\n {t('healthybowl.compliance.substanceRules.limitValue', '≤ {{n}} mg/kg', { n: r.mrlMgPerKg })}\n </span>\n ),\n },\n {\n key: 'cropScope',\n header: t('healthybowl.compliance.substanceRules.col.scope', 'Applies to'),\n render: (r: SubstanceRule) =>\n r.cropScope ?? t('healthybowl.compliance.substanceRules.allCrops', 'All crops'),\n },\n {\n key: 'source',\n header: t('healthybowl.compliance.substanceRules.col.source', 'Source'),\n render: (r: SubstanceRule) => (\n <span className=\"inline-flex items-center gap-2\">\n <span className=\"text-sm text-text-secondary\">{r.source}</span>\n {r.builtin ? (\n <StatusBadge\n variant=\"muted\"\n label={t('healthybowl.compliance.substanceRules.builtin', 'Built-in')}\n />\n ) : null}\n </span>\n ),\n },\n {\n key: 'actions',\n header: '',\n render: (r: SubstanceRule) => (\n <div className=\"flex items-center justify-end gap-1\">\n {/* Built-in rules are the shipped catalogue; editing one would put a workspace's\n opinion behind a name that reads as the standard's. Copy it instead. */}\n {r.builtin ? (\n <span className=\"text-xs text-text-secondary\">\n {t('healthybowl.compliance.substanceRules.builtinHint', 'Add your own rule to override')}\n </span>\n ) : (\n <>\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => startEdit(r)}\n aria-label={t('healthybowl.compliance.substanceRules.edit', 'Edit rule')}\n >\n <Pencil className=\"h-3.5 w-3.5\" />\n </Button>\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => void remove(r)}\n aria-label={t('healthybowl.compliance.substanceRules.remove', 'Remove rule')}\n >\n <Trash2 className=\"h-3.5 w-3.5\" />\n </Button>\n </>\n )}\n </div>\n ),\n },\n ]}\n />\n )}\n\n <Modal\n open={open}\n onClose={() => setOpen(false)}\n title={\n editing\n ? t('healthybowl.compliance.substanceRules.editTitle', 'Edit substance rule')\n : t('healthybowl.compliance.substanceRules.addTitle', 'Add substance rule')\n }\n footer={\n <div className=\"flex justify-end gap-2\">\n <Button variant=\"outline\" onClick={() => setOpen(false)} disabled={busy}>\n {t('common.cancel', 'Cancel')}\n </Button>\n <Button onClick={() => void submit()} disabled={busy}>\n {busy ? t('common.saving', 'Saving…') : t('common.save', 'Save')}\n </Button>\n </div>\n }\n >\n <div className=\"space-y-4\">\n <div>\n <label htmlFor=\"substance-name\" className={fieldLabel}>\n {t('healthybowl.compliance.substanceRules.field.substance', 'Substance name')}\n </label>\n <Input\n id=\"substance-name\"\n value={values.substanceName}\n onChange={(e) => set('substanceName', e.target.value)}\n placeholder=\"Chlorpyrifos\"\n />\n {errorFor('substanceName') ? (\n <p className=\"mt-1 text-xs text-status-error-text\">\n {t(errorFor('substanceName')!.messageKey, errorFor('substanceName')!.messageFallback)}\n </p>\n ) : null}\n </div>\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n <div>\n <label htmlFor=\"substance-ingredient\" className={fieldLabel}>\n {t('healthybowl.compliance.substanceRules.field.ingredient', 'Active ingredient (optional)')}\n </label>\n <Input\n id=\"substance-ingredient\"\n value={values.activeIngredient}\n onChange={(e) => set('activeIngredient', e.target.value)}\n />\n </div>\n <div>\n <label htmlFor=\"substance-cas\" className={fieldLabel}>\n {t('healthybowl.compliance.substanceRules.field.cas', 'CAS number (optional)')}\n </label>\n <Input id=\"substance-cas\" value={values.casNumber} onChange={(e) => set('casNumber', e.target.value)} />\n </div>\n </div>\n\n <div>\n <span className={fieldLabel}>\n {t('healthybowl.compliance.substanceRules.field.mode', 'How is it constrained?')}\n </span>\n <Select value={values.mode} onValueChange={(v) => set('mode', v === 'LIMIT' ? 'LIMIT' : 'PROHIBITED')}>\n <SelectTrigger>\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value=\"PROHIBITED\">\n {t('healthybowl.compliance.substanceRules.mode.prohibited', 'Prohibited — may not be used at all')}\n </SelectItem>\n <SelectItem value=\"LIMIT\">\n {t('healthybowl.compliance.substanceRules.mode.limit', 'Limit — allowed below a residue threshold')}\n </SelectItem>\n </SelectContent>\n </Select>\n </div>\n\n {values.mode === 'LIMIT' ? (\n <div>\n <label htmlFor=\"substance-mrl\" className={fieldLabel}>\n {t('healthybowl.compliance.substanceRules.field.mrl', 'Maximum residue limit (mg/kg)')}\n </label>\n <Input\n id=\"substance-mrl\"\n inputMode=\"decimal\"\n value={values.mrlMgPerKg}\n onChange={(e) => set('mrlMgPerKg', e.target.value)}\n placeholder=\"0.01\"\n />\n {errorFor('mrlMgPerKg') ? (\n <p className=\"mt-1 text-xs text-status-error-text\">\n {t(errorFor('mrlMgPerKg')!.messageKey, errorFor('mrlMgPerKg')!.messageFallback)}\n </p>\n ) : null}\n </div>\n ) : null}\n\n <div className=\"grid grid-cols-1 gap-4 sm:grid-cols-2\">\n <div>\n <label htmlFor=\"substance-scope\" className={fieldLabel}>\n {t('healthybowl.compliance.substanceRules.field.scope', 'Crop scope (optional)')}\n </label>\n <Input\n id=\"substance-scope\"\n value={values.cropScope}\n onChange={(e) => set('cropScope', e.target.value)}\n placeholder={t('healthybowl.compliance.substanceRules.allCrops', 'All crops')}\n />\n {/* Verified against the service: `evaluateResidueTest` is called without a crop name\n from both call sites, and `ruleAppliesToCrop` returns false when a rule has a scope\n and the crop is unknown. A crop-scoped rule therefore never matches anything. Say\n so — shipping a rule that silently cannot fire is the exact false assurance this\n page exists to end. */}\n {values.cropScope.trim().length > 0 ? (\n <p className=\"mt-1 text-xs text-status-warning-text\">\n {t(\n 'healthybowl.compliance.substanceRules.cropScopeWarning',\n 'A rule limited to one crop is not currently screened against lab results — residue tests are matched by substance only. Leave this blank for the rule to take effect.'\n )}\n </p>\n ) : null}\n </div>\n <div>\n <label htmlFor=\"substance-source\" className={fieldLabel}>\n {t('healthybowl.compliance.substanceRules.field.source', 'Source (optional)')}\n </label>\n <Input\n id=\"substance-source\"\n value={values.source}\n onChange={(e) => set('source', e.target.value)}\n placeholder=\"FSSAI notification / buyer contract\"\n />\n </div>\n </div>\n\n <div>\n <label htmlFor=\"substance-notes\" className={fieldLabel}>\n {t('healthybowl.compliance.substanceRules.field.notes', 'Notes (optional)')}\n </label>\n <Textarea id=\"substance-notes\" value={values.notes} onChange={(e) => set('notes', e.target.value)} />\n </div>\n </div>\n </Modal>\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkDA,IAAM,IAAa,oDAEN,UAA2B;CACtC,IAAM,EAAE,SAAM,GAAQ,GAChB,IAAU,EAAW,GACrB,EAAE,UAAO,WAAQ,eAAY,EAAS,GACtC,EAAE,mBAAgB,aAAS,WAAQ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,IACH;MAEJ,kBAAC,OAAD;OAAK,WAAU;iBAAf,CACE,kBAAC,OAAD,EAAA,UAAA;QACE,kBAAC,SAAD;SAAO,SAAQ;SAAkB,WAAW;mBACzC,EAAE,qDAAqD,uBAAuB;QAC1E,CAAA;QACP,kBAAC,GAAD;SACE,IAAG;SACH,OAAO,EAAO;SACd,WAAW,MAAM,EAAI,aAAa,EAAE,OAAO,KAAK;SAChD,aAAa,EAAE,kDAAkD,WAAW;QAC7E,CAAA;QAMA,EAAO,UAAU,KAAK,EAAE,SAAS,IAChC,kBAAC,KAAD;SAAG,WAAU;mBACV,EACC,0DACA,uKACF;QACC,CAAA,IACD;OACD,EAAA,CAAA,GACL,kBAAC,OAAD,EAAA,UAAA,CACE,kBAAC,SAAD;QAAO,SAAQ;QAAmB,WAAW;kBAC1C,EAAE,sDAAsD,mBAAmB;OACvE,CAAA,GACP,kBAAC,GAAD;QACE,IAAG;QACH,OAAO,EAAO;QACd,WAAW,MAAM,EAAI,UAAU,EAAE,OAAO,KAAK;QAC7C,aAAY;OACb,CAAA,CACE,EAAA,CAAA,CACF;;MAEL,kBAAC,OAAD,EAAA,UAAA,CACE,kBAAC,SAAD;OAAO,SAAQ;OAAkB,WAAW;iBACzC,EAAE,qDAAqD,kBAAkB;MACrE,CAAA,GACP,kBAAC,GAAD;OAAU,IAAG;OAAkB,OAAO,EAAO;OAAO,WAAW,MAAM,EAAI,SAAS,EAAE,OAAO,KAAK;MAAI,CAAA,CACjG,EAAA,CAAA;KACF;;GACA,CAAA;GAEP,kBAAC,GAAD;IAAwB;IAAQ,WAAW;GAAU,CAAA;EAC3C;;AAEhB"}
@@ -1,135 +0,0 @@
1
- //#region src/healthybowl/pages/compliance/substanceRuleForm.ts
2
- var e = {
3
- substanceName: "",
4
- activeIngredient: "",
5
- casNumber: "",
6
- standardCode: "",
7
- mode: "PROHIBITED",
8
- mrlMgPerKg: "",
9
- cropScope: "",
10
- source: "",
11
- notes: ""
12
- };
13
- function t(e) {
14
- return {
15
- substanceName: e.substanceName,
16
- activeIngredient: e.activeIngredient ?? "",
17
- casNumber: e.casNumber ?? "",
18
- standardCode: e.standardCode ?? "",
19
- mode: e.mrlMgPerKg === null ? "PROHIBITED" : "LIMIT",
20
- mrlMgPerKg: e.mrlMgPerKg === null ? "" : String(e.mrlMgPerKg),
21
- cropScope: e.cropScope ?? "",
22
- source: e.source ?? "",
23
- notes: e.notes ?? ""
24
- };
25
- }
26
- var n = (e) => {
27
- let t = e.trim();
28
- return t.length > 0 ? t : null;
29
- };
30
- function r(e) {
31
- let t = [], r = e.substanceName.trim();
32
- r.length === 0 && t.push({
33
- field: "substanceName",
34
- messageKey: "healthybowl.compliance.substanceRules.error.nameRequired",
35
- messageFallback: "A substance name is required."
36
- });
37
- let i = null;
38
- if (e.mode === "LIMIT") {
39
- let n = e.mrlMgPerKg.trim();
40
- if (n.length === 0) t.push({
41
- field: "mrlMgPerKg",
42
- messageKey: "healthybowl.compliance.substanceRules.error.mrlRequired",
43
- messageFallback: "A maximum residue limit is required for a limit rule. Choose “Prohibited” instead to ban the substance outright."
44
- });
45
- else {
46
- let e = Number(n);
47
- !Number.isFinite(e) || e < 0 ? t.push({
48
- field: "mrlMgPerKg",
49
- messageKey: "healthybowl.compliance.substanceRules.error.mrlNumber",
50
- messageFallback: "The limit must be a number of milligrams per kilogram, and cannot be negative."
51
- }) : i = e;
52
- }
53
- }
54
- return t.length > 0 ? {
55
- ok: !1,
56
- errors: t
57
- } : {
58
- ok: !0,
59
- input: {
60
- substanceName: r,
61
- activeIngredient: n(e.activeIngredient),
62
- casNumber: n(e.casNumber),
63
- standardCode: n(e.standardCode),
64
- prohibited: e.mode === "PROHIBITED",
65
- mrlMgPerKg: e.mode === "LIMIT" ? i : null,
66
- cropScope: n(e.cropScope),
67
- source: n(e.source),
68
- notes: n(e.notes)
69
- }
70
- };
71
- }
72
- var i = (e) => ({
73
- substanceName: "",
74
- measuredMgPerKg: "",
75
- testedAt: e,
76
- laboratory: "",
77
- traceBatchId: "",
78
- cropId: "",
79
- notes: ""
80
- });
81
- function a(e) {
82
- let t = [], r = e.substanceName.trim();
83
- r.length === 0 && t.push({
84
- field: "substanceName",
85
- messageKey: "healthybowl.compliance.residueTests.error.nameRequired",
86
- messageFallback: "A substance name is required."
87
- });
88
- let i = e.measuredMgPerKg.trim(), a = Number(i);
89
- return (i.length === 0 || !Number.isFinite(a) || a < 0) && t.push({
90
- field: "measuredMgPerKg",
91
- messageKey: "healthybowl.compliance.residueTests.error.measured",
92
- messageFallback: "The measured residue must be a number of milligrams per kilogram, and cannot be negative."
93
- }), e.testedAt.trim().length === 0 && t.push({
94
- field: "testedAt",
95
- messageKey: "healthybowl.compliance.residueTests.error.testedAt",
96
- messageFallback: "A test date is required."
97
- }), t.length > 0 ? {
98
- ok: !1,
99
- errors: t
100
- } : {
101
- ok: !0,
102
- input: {
103
- substanceName: r,
104
- measuredMgPerKg: a,
105
- testedAt: e.testedAt,
106
- laboratory: n(e.laboratory),
107
- traceBatchId: n(e.traceBatchId),
108
- cropId: n(e.cropId),
109
- notes: n(e.notes)
110
- }
111
- };
112
- }
113
- function o(e, t) {
114
- let n = e.substanceName.trim().toLowerCase(), r = t.find((e) => e.substanceName.trim().toLowerCase() === n) ?? t.find((e) => (e.activeIngredient ?? "").trim().toLowerCase() === n && n.length > 0) ?? null;
115
- return r ? r.mrlMgPerKg === null ? r.prohibited ? {
116
- verdict: e.measuredMgPerKg > 0 ? "PROHIBITED" : "WITHIN_LIMIT",
117
- rule: r
118
- } : {
119
- verdict: "NO_RULE",
120
- rule: r
121
- } : {
122
- verdict: e.measuredMgPerKg > r.mrlMgPerKg ? "BREACH" : "WITHIN_LIMIT",
123
- rule: r
124
- } : {
125
- verdict: "NO_RULE",
126
- rule: null
127
- };
128
- }
129
- function s(e) {
130
- return e.every((e) => e.mrlMgPerKg === null);
131
- }
132
- //#endregion
133
- export { a as buildResidueTestInput, r as buildSubstanceRuleInput, i as emptyResidueTestForm, e as emptySubstanceRuleForm, s as hasNoNumericLimit, o as residueVerdict, t as substanceRuleToForm };
134
-
135
- //# sourceMappingURL=substanceRuleForm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"substanceRuleForm.js","names":[],"sources":["../../../../src/healthybowl/pages/compliance/substanceRuleForm.ts"],"sourcesContent":["/**\n * Substance-rule and residue-test form logic (BOFF-6020) — pure, so it is unit-testable.\n *\n * `microfe-healthybowl`'s vitest runs `environment: 'node'` with no jsdom and no testing-library, so\n * every decision lives here and the pages stay presentational. Established pattern:\n * `government-schemes/schemeAdminValidation.ts`.\n *\n * The rule this module exists to enforce: a rule is either a **ban** (prohibited, no numeric limit)\n * or a **limit** (an MRL in mg/kg). Shipping one that is neither means the compliance scan's\n * `MRL_EXCEEDED` check can never fire — which, for an organic-certification product, is false\n * assurance rather than a missing feature.\n *\n * @module healthybowl\n */\nimport type { ResidueTest, SubstanceRule } from '../../hooks/useHealthyBowlCompliance';\n\n/** How a rule constrains a substance. Mirrors the server's `prohibited` + `mrlMgPerKg` pair. */\nexport type RuleMode = 'PROHIBITED' | 'LIMIT';\n\nexport interface SubstanceRuleFormValues {\n substanceName: string;\n activeIngredient: string;\n casNumber: string;\n standardCode: string;\n mode: RuleMode;\n /** Free text while typing; parsed on submit. Only meaningful when `mode === 'LIMIT'`. */\n mrlMgPerKg: string;\n cropScope: string;\n source: string;\n notes: string;\n}\n\nexport const emptySubstanceRuleForm: SubstanceRuleFormValues = {\n substanceName: '',\n activeIngredient: '',\n casNumber: '',\n standardCode: '',\n mode: 'PROHIBITED',\n mrlMgPerKg: '',\n cropScope: '',\n source: '',\n notes: '',\n};\n\n/** Seed the form from an existing rule, for the edit path. */\nexport function substanceRuleToForm(rule: SubstanceRule): SubstanceRuleFormValues {\n return {\n substanceName: rule.substanceName,\n activeIngredient: rule.activeIngredient ?? '',\n casNumber: rule.casNumber ?? '',\n standardCode: rule.standardCode ?? '',\n mode: rule.mrlMgPerKg === null ? 'PROHIBITED' : 'LIMIT',\n mrlMgPerKg: rule.mrlMgPerKg === null ? '' : String(rule.mrlMgPerKg),\n cropScope: rule.cropScope ?? '',\n source: rule.source ?? '',\n notes: rule.notes ?? '',\n };\n}\n\nexport type FieldError = { field: keyof SubstanceRuleFormValues; messageKey: string; messageFallback: string };\n\n/** Trim, and collapse a blank to null so the column goes NULL rather than storing an empty string. */\nconst nullable = (value: string): string | null => {\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : null;\n};\n\n/**\n * Validate and shape a substance rule for the API.\n *\n * Returns the field errors rather than throwing, so the page can mark the offending input instead of\n * showing one banner for a form with several problems.\n */\nexport function buildSubstanceRuleInput(\n values: SubstanceRuleFormValues\n): { ok: true; input: Record<string, unknown> } | { ok: false; errors: FieldError[] } {\n const errors: FieldError[] = [];\n\n const substanceName = values.substanceName.trim();\n if (substanceName.length === 0) {\n errors.push({\n field: 'substanceName',\n messageKey: 'healthybowl.compliance.substanceRules.error.nameRequired',\n messageFallback: 'A substance name is required.',\n });\n }\n\n let mrl: number | null = null;\n if (values.mode === 'LIMIT') {\n const raw = values.mrlMgPerKg.trim();\n if (raw.length === 0) {\n errors.push({\n field: 'mrlMgPerKg',\n messageKey: 'healthybowl.compliance.substanceRules.error.mrlRequired',\n messageFallback:\n 'A maximum residue limit is required for a limit rule. Choose “Prohibited” instead to ban the substance outright.',\n });\n } else {\n const parsed = Number(raw);\n if (!Number.isFinite(parsed) || parsed < 0) {\n errors.push({\n field: 'mrlMgPerKg',\n messageKey: 'healthybowl.compliance.substanceRules.error.mrlNumber',\n messageFallback: 'The limit must be a number of milligrams per kilogram, and cannot be negative.',\n });\n } else {\n mrl = parsed;\n }\n }\n }\n\n if (errors.length > 0) return { ok: false, errors };\n\n return {\n ok: true,\n input: {\n substanceName,\n activeIngredient: nullable(values.activeIngredient),\n casNumber: nullable(values.casNumber),\n standardCode: nullable(values.standardCode),\n // A ban carries no number; a limit carries one and is not a ban. Sending both would leave the\n // scan unable to decide which rule it is enforcing.\n prohibited: values.mode === 'PROHIBITED',\n mrlMgPerKg: values.mode === 'LIMIT' ? mrl : null,\n cropScope: nullable(values.cropScope),\n source: nullable(values.source),\n notes: nullable(values.notes),\n },\n };\n}\n\nexport interface ResidueTestFormValues {\n substanceName: string;\n measuredMgPerKg: string;\n testedAt: string;\n laboratory: string;\n traceBatchId: string;\n cropId: string;\n notes: string;\n}\n\nexport const emptyResidueTestForm = (today: string): ResidueTestFormValues => ({\n substanceName: '',\n measuredMgPerKg: '',\n testedAt: today,\n laboratory: '',\n traceBatchId: '',\n cropId: '',\n notes: '',\n});\n\nexport type ResidueFieldError = {\n field: keyof ResidueTestFormValues;\n messageKey: string;\n messageFallback: string;\n};\n\nexport function buildResidueTestInput(\n values: ResidueTestFormValues\n): { ok: true; input: Record<string, unknown> } | { ok: false; errors: ResidueFieldError[] } {\n const errors: ResidueFieldError[] = [];\n\n const substanceName = values.substanceName.trim();\n if (substanceName.length === 0) {\n errors.push({\n field: 'substanceName',\n messageKey: 'healthybowl.compliance.residueTests.error.nameRequired',\n messageFallback: 'A substance name is required.',\n });\n }\n\n const raw = values.measuredMgPerKg.trim();\n const measured = Number(raw);\n if (raw.length === 0 || !Number.isFinite(measured) || measured < 0) {\n errors.push({\n field: 'measuredMgPerKg',\n messageKey: 'healthybowl.compliance.residueTests.error.measured',\n messageFallback: 'The measured residue must be a number of milligrams per kilogram, and cannot be negative.',\n });\n }\n\n if (values.testedAt.trim().length === 0) {\n errors.push({\n field: 'testedAt',\n messageKey: 'healthybowl.compliance.residueTests.error.testedAt',\n messageFallback: 'A test date is required.',\n });\n }\n\n if (errors.length > 0) return { ok: false, errors };\n\n return {\n ok: true,\n input: {\n substanceName,\n measuredMgPerKg: measured,\n testedAt: values.testedAt,\n laboratory: nullable(values.laboratory),\n traceBatchId: nullable(values.traceBatchId),\n cropId: nullable(values.cropId),\n notes: nullable(values.notes),\n },\n };\n}\n\n/** How a recorded measurement compares to the workspace rulebook. */\nexport type ResidueVerdict = 'BREACH' | 'PROHIBITED' | 'WITHIN_LIMIT' | 'NO_RULE';\n\n/**\n * Compare one measurement against the rulebook, for display only.\n *\n * **The server is the authority** — `createHealthyBowlResidueTest` raises the real\n * `MRL_EXCEEDED` flag on write. This exists so a farmer reading the list can see *why* a row is\n * flagged without cross-referencing two pages, and so a measurement against a substance nobody has\n * written a rule for is visibly unjudged rather than silently passing.\n *\n * Matching is case-insensitive on the substance name, because a lab report and a rulebook entry are\n * typed by different people on different days.\n */\nexport function residueVerdict(\n test: Pick<ResidueTest, 'substanceName' | 'measuredMgPerKg'>,\n rules: readonly SubstanceRule[]\n): { verdict: ResidueVerdict; rule: SubstanceRule | null } {\n const needle = test.substanceName.trim().toLowerCase();\n const rule =\n rules.find((r) => r.substanceName.trim().toLowerCase() === needle) ??\n rules.find((r) => (r.activeIngredient ?? '').trim().toLowerCase() === needle && needle.length > 0) ??\n null;\n\n if (!rule) return { verdict: 'NO_RULE', rule: null };\n if (rule.mrlMgPerKg !== null) {\n return { verdict: test.measuredMgPerKg > rule.mrlMgPerKg ? 'BREACH' : 'WITHIN_LIMIT', rule };\n }\n // A ban with any detectable residue is a breach; a ban with a zero reading is not.\n if (rule.prohibited) {\n return { verdict: test.measuredMgPerKg > 0 ? 'PROHIBITED' : 'WITHIN_LIMIT', rule };\n }\n return { verdict: 'NO_RULE', rule };\n}\n\n/**\n * True when the rulebook can never raise an MRL breach.\n *\n * The built-in catalogue is a list of outright bans with no numeric limits, so a workspace that has\n * added nothing of its own has an `MRL_EXCEEDED` check that cannot fire. Saying so is the whole\n * point of this ticket — the silence looked like a pass.\n */\nexport function hasNoNumericLimit(rules: readonly SubstanceRule[]): boolean {\n return rules.every((r) => r.mrlMgPerKg === null);\n}\n"],"mappings":";AAgCA,IAAa,IAAkD;CAC7D,eAAe;CACf,kBAAkB;CAClB,WAAW;CACX,cAAc;CACd,MAAM;CACN,YAAY;CACZ,WAAW;CACX,QAAQ;CACR,OAAO;AACT;AAGA,SAAgB,EAAoB,GAA8C;CAChF,OAAO;EACL,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CAAK,IANzB;EAAE,SAAS,EAAK,kBAAkB,EAAK,aAAa,WAAW;EAAgB;CAAK,IAF3E;EAAE,SAAS;EAAW,MAAM;CAAK;AASrD;AASA,SAAgB,EAAkB,GAA0C;CAC1E,OAAO,EAAM,OAAO,MAAM,EAAE,eAAe,IAAI;AACjD"}
@@ -1,49 +0,0 @@
1
- //#region src/healthybowl/pages/government-schemes/schemeApplicationTransitions.ts
2
- var e = {
3
- submitted: ["under_review", "rejected"],
4
- under_review: ["approved", "rejected"],
5
- approved: ["disbursed"],
6
- rejected: [],
7
- disbursed: []
8
- }, t = {
9
- submitted: {
10
- labelKey: "healthybowl.governmentSchemes.tracking.action.submitted",
11
- labelFallback: "Mark submitted",
12
- destructive: !1
13
- },
14
- under_review: {
15
- labelKey: "healthybowl.governmentSchemes.tracking.action.underReview",
16
- labelFallback: "Move to under review",
17
- destructive: !1
18
- },
19
- approved: {
20
- labelKey: "healthybowl.governmentSchemes.tracking.action.approved",
21
- labelFallback: "Approve",
22
- destructive: !1
23
- },
24
- rejected: {
25
- labelKey: "healthybowl.governmentSchemes.tracking.action.rejected",
26
- labelFallback: "Reject",
27
- destructive: !0
28
- },
29
- disbursed: {
30
- labelKey: "healthybowl.governmentSchemes.tracking.action.disbursed",
31
- labelFallback: "Mark disbursed",
32
- destructive: !1
33
- }
34
- };
35
- function n(n) {
36
- let r = e[n];
37
- return r ? r.map((e) => ({
38
- status: e,
39
- ...t[e]
40
- })) : [];
41
- }
42
- function r(t) {
43
- let n = e[t];
44
- return n !== void 0 && n.length === 0;
45
- }
46
- //#endregion
47
- export { r as isTerminalSchemeApplicationStatus, n as transitionActionsFor };
48
-
49
- //# sourceMappingURL=schemeApplicationTransitions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemeApplicationTransitions.js","names":[],"sources":["../../../../src/healthybowl/pages/government-schemes/schemeApplicationTransitions.ts"],"sourcesContent":["/**\n * Government scheme-application transitions (BOFF-6037) — pure, so it is unit-testable.\n *\n * Mirrors `SCHEME_APPLICATION_TRANSITIONS` in wspace-healthybowl-svc's\n * `HealthyBowlDomainProvider`. The server is the authority — it refuses an illegal edge with\n * `BAD_USER_INPUT` — and this exists so the page offers only the buttons that will work, rather\n * than showing four and letting three of them fail.\n *\n * Statuses arrive from the API **lower-cased** (`toLowerEnum`), which is what the tracking page\n * already renders, so this map is keyed the same way.\n *\n * @module healthybowl\n */\n\nexport type SchemeApplicationStatus = 'submitted' | 'under_review' | 'approved' | 'rejected' | 'disbursed';\n\n/**\n * Legal next states, by current state.\n *\n * No `submitted → disbursed` skip: money must not move without a recorded approval. `submitted →\n * rejected` is direct, because an ineligible applicant is refused on sight and forcing a review\n * cycle would be theatre. Terminal states offer nothing, and there are no self-edges — so a\n * double-clicked button cannot produce a duplicate audit row.\n */\nexport const SCHEME_APPLICATION_TRANSITIONS: Readonly<\n Record<SchemeApplicationStatus, readonly SchemeApplicationStatus[]>\n> = {\n submitted: ['under_review', 'rejected'],\n under_review: ['approved', 'rejected'],\n approved: ['disbursed'],\n rejected: [],\n disbursed: [],\n};\n\nexport interface TransitionAction {\n status: SchemeApplicationStatus;\n labelKey: string;\n labelFallback: string;\n /** A refusal is a heavier act than an advance, so it is styled apart. */\n destructive: boolean;\n}\n\nconst ACTION_COPY: Readonly<Record<SchemeApplicationStatus, Omit<TransitionAction, 'status'>>> = {\n submitted: {\n labelKey: 'healthybowl.governmentSchemes.tracking.action.submitted',\n labelFallback: 'Mark submitted',\n destructive: false,\n },\n under_review: {\n labelKey: 'healthybowl.governmentSchemes.tracking.action.underReview',\n labelFallback: 'Move to under review',\n destructive: false,\n },\n approved: {\n labelKey: 'healthybowl.governmentSchemes.tracking.action.approved',\n labelFallback: 'Approve',\n destructive: false,\n },\n rejected: {\n labelKey: 'healthybowl.governmentSchemes.tracking.action.rejected',\n labelFallback: 'Reject',\n destructive: true,\n },\n disbursed: {\n labelKey: 'healthybowl.governmentSchemes.tracking.action.disbursed',\n labelFallback: 'Mark disbursed',\n destructive: false,\n },\n};\n\n/**\n * The actions offered for an application in this state.\n *\n * An unrecognised status yields none rather than guessing: a state this client does not know about\n * is a state it has no business moving.\n */\nexport function transitionActionsFor(status: string): TransitionAction[] {\n const next = SCHEME_APPLICATION_TRANSITIONS[status as SchemeApplicationStatus];\n if (!next) return [];\n return next.map((target) => ({ status: target, ...ACTION_COPY[target] }));\n}\n\n/** True when the application has reached a state nothing can move it out of. */\nexport function isTerminalSchemeApplicationStatus(status: string): boolean {\n const next = SCHEME_APPLICATION_TRANSITIONS[status as SchemeApplicationStatus];\n return next !== undefined && next.length === 0;\n}\n"],"mappings":";AAwBA,IAAa,IAET;CACF,WAAW,CAAC,gBAAgB,UAAU;CACtC,cAAc,CAAC,YAAY,UAAU;CACrC,UAAU,CAAC,WAAW;CACtB,UAAU,CAAC;CACX,WAAW,CAAC;AACd,GAUM,IAA2F;CAC/F,WAAW;EACT,UAAU;EACV,eAAe;EACf,aAAa;CACf;CACA,cAAc;EACZ,UAAU;EACV,eAAe;EACf,aAAa;CACf;CACA,UAAU;EACR,UAAU;EACV,eAAe;EACf,aAAa;CACf;CACA,UAAU;EACR,UAAU;EACV,eAAe;EACf,aAAa;CACf;CACA,WAAW;EACT,UAAU;EACV,eAAe;EACf,aAAa;CACf;AACF;AAQA,SAAgB,EAAqB,GAAoC;CACvE,IAAM,IAAO,EAA+B;CAE5C,OADK,IACE,EAAK,KAAK,OAAY;EAAE,QAAQ;EAAQ,GAAG,EAAY;CAAQ,EAAE,IADtD,CAAC;AAErB;AAGA,SAAgB,EAAkC,GAAyB;CACzE,IAAM,IAAO,EAA+B;CAC5C,OAAO,MAAS,KAAA,KAAa,EAAK,WAAW;AAC/C"}