@burdenoff/microfe-healthybowl 2026.1005.2 → 2026.1007.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/components/BedLayoutGrid.js +128 -115
- package/dist/healthybowl/components/BedLayoutGrid.js.map +1 -1
- package/dist/healthybowl/components/CropPicker.js +37 -0
- package/dist/healthybowl/components/CropPicker.js.map +1 -0
- package/dist/healthybowl/components/DataTable.js +125 -108
- package/dist/healthybowl/components/DataTable.js.map +1 -1
- package/dist/healthybowl/components/FilterBar.js +9 -6
- package/dist/healthybowl/components/FilterBar.js.map +1 -1
- package/dist/healthybowl/components/PlantCatalogPicker.js +32 -0
- package/dist/healthybowl/components/PlantCatalogPicker.js.map +1 -0
- package/dist/healthybowl/components/WorkspaceRecordPicker.js +164 -0
- package/dist/healthybowl/components/WorkspaceRecordPicker.js.map +1 -0
- package/dist/healthybowl/components/index.js +3 -1
- package/dist/healthybowl/hooks/useCropPage.js +71 -0
- package/dist/healthybowl/hooks/useCropPage.js.map +1 -0
- package/dist/healthybowl/hooks/usePlantCatalog.js +133 -44
- package/dist/healthybowl/hooks/usePlantCatalog.js.map +1 -1
- package/dist/healthybowl/hooks/usePlantingEstimate.js +6 -6
- package/dist/healthybowl/hooks/usePlantingEstimate.js.map +1 -1
- package/dist/healthybowl/hooks/useWorkspaceRead.js +46 -0
- package/dist/healthybowl/hooks/useWorkspaceRead.js.map +1 -0
- package/dist/healthybowl/pages/HomePage.js +143 -142
- package/dist/healthybowl/pages/HomePage.js.map +1 -1
- package/dist/healthybowl/pages/analytics/ReportsPage.js +8 -8
- package/dist/healthybowl/pages/catalog/PlantCatalogPage.js +266 -192
- package/dist/healthybowl/pages/catalog/PlantCatalogPage.js.map +1 -1
- package/dist/healthybowl/pages/catalog/WorkspaceBrowseFilters.js +58 -0
- package/dist/healthybowl/pages/catalog/WorkspaceBrowseFilters.js.map +1 -0
- package/dist/healthybowl/pages/catalog/browsePagination.js +24 -0
- package/dist/healthybowl/pages/catalog/browsePagination.js.map +1 -0
- package/dist/healthybowl/pages/compliance/ComplianceDocumentsPage.js +6 -6
- package/dist/healthybowl/pages/crops/CropDetailsPage.js +340 -348
- package/dist/healthybowl/pages/crops/CropDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/CropPlanningPage.js +468 -434
- package/dist/healthybowl/pages/crops/CropPlanningPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/CropsPage.js +633 -542
- package/dist/healthybowl/pages/crops/CropsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js +875 -800
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/PlanningDetailsPage.js +459 -448
- package/dist/healthybowl/pages/crops/PlanningDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/SuccessionCropLabel.js +21 -0
- package/dist/healthybowl/pages/crops/SuccessionCropLabel.js.map +1 -0
- package/dist/healthybowl/pages/crops/planningEdit.js +30 -0
- package/dist/healthybowl/pages/crops/planningEdit.js.map +1 -0
- package/dist/healthybowl/pages/fields/FieldMapPage.js +989 -941
- package/dist/healthybowl/pages/fields/FieldMapPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/GeneralLedgerPage.js +6 -6
- package/dist/healthybowl/pages/financial/InvoiceManagementPage.js +7 -7
- package/dist/healthybowl/pages/financial/InvoiceManagementPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/TransactionsPage.js +541 -541
- package/dist/healthybowl/pages/financial/TransactionsPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/ApplicationTrackingPage.js +10 -10
- package/dist/healthybowl/pages/government-schemes/CommunicationPage.js +207 -207
- package/dist/healthybowl/pages/government-schemes/CommunicationPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/SchemeAdminPage.js +38 -38
- package/dist/healthybowl/pages/government-schemes/SchemeAdminPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/TrainingProgramsPage.js +15 -15
- package/dist/healthybowl/pages/government-schemes/TrainingProgramsPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/AnimalRegistryPage.js +4 -4
- package/dist/healthybowl/pages/livestock/BreedingManagementPage.js +4 -4
- package/dist/healthybowl/pages/livestock/FeedManagementPage.js +4 -4
- package/dist/healthybowl/pages/livestock/HealthRecordsPage.js +16 -16
- package/dist/healthybowl/pages/livestock/HealthRecordsPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/ProductionTrackingPage.js +4 -4
- package/dist/healthybowl/pages/livestock/VaccinationSchedulePage.js +4 -4
- package/dist/healthybowl/pages/market/MarketPricesPage.js +305 -305
- package/dist/healthybowl/pages/market/MarketPricesPage.js.map +1 -1
- package/dist/healthybowl/pages/network/CohortsPage.js +107 -107
- package/dist/healthybowl/pages/network/CohortsPage.js.map +1 -1
- package/dist/healthybowl/pages/network/CommunityPage.js +247 -247
- package/dist/healthybowl/pages/network/CommunityPage.js.map +1 -1
- package/dist/healthybowl/pages/network/EventsPage.js +16 -16
- package/dist/healthybowl/pages/network/EventsPage.js.map +1 -1
- package/dist/healthybowl/pages/network/ExpertsPage.js +470 -470
- package/dist/healthybowl/pages/network/ExpertsPage.js.map +1 -1
- package/dist/healthybowl/pages/network/MentorsPage.js +6 -6
- package/dist/healthybowl/pages/pest-management/PestIssuesPage.js +8 -8
- package/dist/healthybowl/pages/pest-management/TreatmentLibraryPage.js +7 -7
- package/dist/healthybowl/pages/pest-management/TreatmentLibraryPage.js.map +1 -1
- package/dist/healthybowl/pages/production/ProductionBatchesPage.js +7 -7
- package/dist/healthybowl/pages/production/RecipeManagementPage.js +5 -5
- package/dist/healthybowl/pages/production/ValueAddedProductsPage.js +7 -7
- package/dist/healthybowl/pages/soil/SoilTestsPage.js +6 -6
- package/dist/healthybowl/pages/soil/SoilTestsPage.js.map +1 -1
- package/dist/healthybowl/pages/suppliers/SuppliersPage.js +10 -10
- package/dist/healthybowl/pages/sustainability/CarbonCreditLedgerPage.js +6 -6
- package/dist/healthybowl/pages/terrace/PlantingFormModal.js +151 -131
- package/dist/healthybowl/pages/terrace/PlantingFormModal.js.map +1 -1
- package/dist/healthybowl/pages/traceability/BatchTrackingPage.js +6 -6
- package/dist/healthybowl/utils/cropComparison.js +1 -1
- package/dist/healthybowl/utils/cropComparison.js.map +1 -1
- package/dist/healthybowl/utils/cropPicker.js +35 -0
- package/dist/healthybowl/utils/cropPicker.js.map +1 -0
- package/dist/healthybowl/utils/plantingCapacity.js +2 -2
- package/dist/healthybowl/utils/plantingCapacity.js.map +1 -1
- package/dist/healthybowl/utils/quotaLabels.js +8 -0
- package/dist/healthybowl/utils/quotaLabels.js.map +1 -0
- package/dist/healthybowl/utils/seedRate.js +1 -8
- package/dist/healthybowl/utils/seedRate.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkspaceRecordPicker.js","names":[],"sources":["../../../src/healthybowl/components/WorkspaceRecordPicker.tsx"],"sourcesContent":["import { useCallback, useId, useState } from 'react';\nimport {\n Button,\n Input,\n Pagination,\n Select,\n SelectContent,\n SelectGroup,\n SelectItem,\n SelectLabel,\n SelectTrigger,\n SelectValue,\n} from '@burdenoff/fe-libs/ui';\nimport type { OffsetPage, ReadState } from '../hooks/useWorkspaceRead';\nimport {\n groupPickerRecords,\n pickerRecordLabel,\n pickerVisibleRecords,\n retainedPickerRecords,\n type PickerRecord,\n} from '../utils/cropPicker';\nimport { cn } from '../utils/helpers';\nimport { FilterBar } from './FilterBar';\n\nexport interface WorkspaceRecordPickerProps<T extends PickerRecord> {\n value: string;\n onValueChange: (id: string, entry: T | null) => void;\n options?: readonly T[];\n recordedLabel?: string;\n placeholder?: string;\n id?: string;\n disabled?: boolean;\n className?: string;\n skip?: boolean;\n /** Radix item values must be non-empty; existing manual/none sentinels stay caller-owned. */\n emptyOption?: { value: string; label: string };\n}\n\nexport function usePickerBrowseState() {\n const [search, setSearch] = useState('');\n const [category, setCategory] = useState('');\n const [uncategorized, setUncategorized] = useState(false);\n const [offset, setOffset] = useState(0);\n const onSearchChange = useCallback((value: string) => {\n setSearch(value);\n setOffset(0);\n }, []);\n const onCategoryChange = useCallback((value: string) => {\n setCategory(value);\n setUncategorized(false);\n setOffset(0);\n }, []);\n const onUncategorizedChange = useCallback(() => {\n setUncategorized((value) => !value);\n setCategory('');\n setOffset(0);\n }, []);\n return {\n search,\n category,\n uncategorized,\n offset,\n setOffset,\n onSearchChange,\n onCategoryChange,\n onUncategorizedChange,\n };\n}\n\ninterface PickerViewProps<T extends PickerRecord> extends WorkspaceRecordPickerProps<T> {\n kind: 'crops' | 'catalog entries';\n workspaceId: string;\n browse: ReturnType<typeof usePickerBrowseState>;\n page: OffsetPage<T> & ReadState;\n selected: ReadState & { entry: T | null };\n}\n\n/** Props-only view: browsing/refetch never invokes the caller's selection/reset callback. */\nexport function WorkspaceRecordPicker<T extends PickerRecord>({\n value,\n onValueChange,\n options = [],\n recordedLabel,\n placeholder,\n id,\n disabled,\n className,\n skip,\n emptyOption,\n kind,\n workspaceId,\n browse,\n page,\n selected,\n}: PickerViewProps<T>) {\n const controlId = useId();\n const searchId = `${controlId}-search`;\n const categoryId = `${controlId}-category`;\n const suggestionsId = `${controlId}-categories`;\n const statusId = `${controlId}-status`;\n const inactive = disabled || skip || !workspaceId;\n const [pickedEntry, setPickedEntry] = useState<T | null>(null);\n const visible = workspaceId ? pickerVisibleRecords(page.items, options, browse) : [];\n const selectedEntry = workspaceId\n ? (selected.entry ??\n options.find((entry) => entry.id === value) ??\n (pickedEntry?.id === value ? pickedEntry : null))\n : null;\n const records = retainedPickerRecords(visible, selectedEntry);\n const groups = groupPickerRecords(records);\n // These are suggestions from THIS SERVER PAGE, not exhaustive workspace facets.\n const categories = groupPickerRecords(page.items).flatMap((group) =>\n group.category === null ? [] : [group.category]\n );\n const validEmptyOption = emptyOption?.value ? emptyOption : undefined;\n const missingSelected = value && value !== validEmptyOption?.value && !records.some((entry) => entry.id === value);\n const missingLabel = `${recordedLabel ?? `Recorded ${kind === 'crops' ? 'crop' : 'catalog entry'} (${value})`} (${selected.loading ? 'loading selected record…' : 'recorded/unavailable'})`;\n\n const selectRecord = (nextId: string) => {\n if (inactive) return;\n if (nextId === validEmptyOption?.value) {\n setPickedEntry(null);\n onValueChange(nextId, null);\n return;\n }\n const entry = records.find((record) => record.id === nextId);\n if (!entry) return; // An unavailable recorded option is not another same-name record.\n setPickedEntry(entry);\n onValueChange(nextId, entry);\n };\n\n const retry = (refetch: ReadState['refetch']) => {\n // Apollo exposes the retry error in the actionable alert below as well as rejecting the promise.\n void refetch().catch(() => undefined);\n };\n\n return (\n <div className={cn('space-y-2', className)}>\n <FilterBar\n searchValue={browse.search}\n onSearchChange={browse.onSearchChange}\n searchId={searchId}\n searchLabel={`Search ${kind} by name, variety or category`}\n searchPlaceholder={`Search ${kind}…`}\n disabled={Boolean(inactive)}\n filters={\n <div className=\"flex flex-wrap items-end gap-2\">\n <div>\n <label htmlFor={categoryId} className=\"mb-1 block text-xs text-text-secondary\">\n Category (page suggestions)\n </label>\n <Input\n id={categoryId}\n list={suggestionsId}\n value={browse.category}\n onChange={(event) => browse.onCategoryChange(event.target.value)}\n placeholder=\"Any exact category\"\n className=\"h-9 w-44\"\n disabled={Boolean(inactive) || browse.uncategorized}\n />\n <datalist id={suggestionsId}>\n {categories.map((category) => (\n <option key={category} value={category} />\n ))}\n </datalist>\n </div>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n aria-pressed={browse.uncategorized}\n disabled={Boolean(inactive)}\n onClick={browse.onUncategorizedChange}\n >\n Uncategorized\n </Button>\n </div>\n }\n />\n <Select value={value} onValueChange={selectRecord} disabled={Boolean(inactive)}>\n <SelectTrigger id={id} className=\"w-full\" aria-label={placeholder} aria-describedby={statusId}>\n <SelectValue placeholder={placeholder} />\n </SelectTrigger>\n <SelectContent>\n {validEmptyOption && <SelectItem value={validEmptyOption.value}>{validEmptyOption.label}</SelectItem>}\n {missingSelected && (\n <SelectItem value={value} disabled>\n {missingLabel}\n </SelectItem>\n )}\n {groups.map((group) => (\n <SelectGroup key={JSON.stringify(group.category)}>\n <SelectLabel>{group.label}</SelectLabel>\n {group.items.map((entry) => (\n <SelectItem key={entry.id} value={entry.id}>\n {pickerRecordLabel(entry)}\n </SelectItem>\n ))}\n </SelectGroup>\n ))}\n {records.length === 0 && !validEmptyOption && !missingSelected && (\n <SelectGroup>\n <SelectLabel>\n {page.loading ? 'Loading…' : page.error ? 'Could not load options' : 'No matching records'}\n </SelectLabel>\n </SelectGroup>\n )}\n </SelectContent>\n </Select>\n <div id={statusId} aria-live=\"polite\" className=\"text-xs text-text-secondary\">\n {!workspaceId\n ? 'Choose a workspace to browse.'\n : skip\n ? 'Browsing is paused.'\n : page.loading\n ? `Loading ${kind}…`\n : !page.error && page.items.length === 0\n ? 'No matching records on this page.'\n : !page.error\n ? `${page.total} matching ${kind} in this workspace.`\n : null}\n </div>\n {page.error && (\n <div role=\"alert\" className=\"flex items-center justify-between gap-2 text-sm text-error\">\n <span>Could not load {kind}. Your selection has been kept.</span>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n disabled={Boolean(inactive) || page.loading}\n onClick={() => retry(page.refetch)}\n >\n Retry\n </Button>\n </div>\n )}\n {selected.error && missingSelected && (\n <div role=\"alert\" className=\"flex items-center justify-between gap-2 text-sm text-error\">\n <span>Selected record details could not be loaded.</span>\n <Button\n type=\"button\"\n size=\"sm\"\n variant=\"outline\"\n disabled={Boolean(inactive) || selected.loading}\n onClick={() => retry(selected.refetch)}\n >\n Retry selected record\n </Button>\n </div>\n )}\n {options.length > 0 &&\n !browse.search.trim() &&\n !browse.category &&\n !browse.uncategorized &&\n browse.offset === 0 && (\n <p className=\"text-xs text-text-secondary\">\n Already-loaded choices are included; the total describes server matches.\n </p>\n )}\n <Pagination\n page={Math.floor(page.offset / page.limit) + 1}\n pageSize={page.limit}\n totalItems={page.error || page.loading || page.offset >= page.total ? undefined : page.total}\n totalPages={!page.error && !page.loading ? Math.max(1, Math.ceil(page.total / page.limit)) : undefined}\n hasNextPage={!inactive && !page.error && page.hasMore}\n hasPreviousPage={!inactive && page.offset > 0}\n loading={page.loading || Boolean(inactive)}\n onPageChange={(nextPage) => {\n if (!inactive) browse.setOffset(Math.max(0, (nextPage - 1) * page.limit));\n }}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;AAsCA,SAAgB,IAAuB;CACrC,IAAM,CAAC,GAAQ,KAAa,EAAS,EAAE,GACjC,CAAC,GAAU,KAAe,EAAS,EAAE,GACrC,CAAC,GAAe,KAAoB,EAAS,EAAK,GAClD,CAAC,GAAQ,KAAa,EAAS,CAAC;CAetC,OAAO;EACL;EACA;EACA;EACA;EACA;EACA,gBApBqB,GAAa,MAAkB;GAEpD,AADA,EAAU,CAAK,GACf,EAAU,CAAC;EACb,GAAG,CAAC,CAiBF;EACA,kBAjBuB,GAAa,MAAkB;GAGtD,AAFA,EAAY,CAAK,GACjB,EAAiB,EAAK,GACtB,EAAU,CAAC;EACb,GAAG,CAAC,CAaF;EACA,uBAb4B,QAAkB;GAG9C,AAFA,GAAkB,MAAU,CAAC,CAAK,GAClC,EAAY,EAAE,GACd,EAAU,CAAC;EACb,GAAG,CAAC,CASF;CACF;AACF;AAWA,SAAgB,EAA8C,EAC5D,UACA,kBACA,aAAU,CAAC,GACX,kBACA,gBACA,OACA,aACA,cACA,SACA,gBACA,SACA,gBACA,WACA,SACA,eACqB;CACrB,IAAM,IAAY,EAAM,GAClB,IAAW,GAAG,EAAU,UACxB,IAAa,GAAG,EAAU,YAC1B,IAAgB,GAAG,EAAU,cAC7B,IAAW,GAAG,EAAU,UACxB,IAAW,KAAY,KAAQ,CAAC,GAChC,CAAC,GAAa,KAAkB,EAAmB,IAAI,GAOvD,IAAU,EANA,IAAc,EAAqB,EAAK,OAAO,GAAS,CAAM,IAAI,CAAC,GAC7D,IACjB,EAAS,SACV,EAAQ,MAAM,MAAU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AAK,CAAC;IAC1E;GACD,CAAA;EACE;;AAET"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import "./PageLayout.js";
|
|
2
2
|
import "./StatCard.js";
|
|
3
3
|
import "./DataTable.js";
|
|
4
|
+
import "./FilterBar.js";
|
|
5
|
+
import "./CropPicker.js";
|
|
6
|
+
import "./PlantCatalogPicker.js";
|
|
4
7
|
import "./StatusBadge.js";
|
|
5
8
|
import "./EmptyState.js";
|
|
6
9
|
import "./ErrorState.js";
|
|
7
10
|
import "./ComingSoon.js";
|
|
8
11
|
import "./ChartCard.js";
|
|
9
12
|
import "./AnalyticsControls.js";
|
|
10
|
-
import "./FilterBar.js";
|
|
11
13
|
import "./Toast.js";
|
|
12
14
|
import "./ErrorBoundary.js";
|
|
13
15
|
import "./ConfirmDialog.js";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
|
|
2
|
+
import { emptyOffsetPage as t, normalizeReadPagination as n, useWorkspaceRead as r } from "./useWorkspaceRead.js";
|
|
3
|
+
import { useMemo as i } from "react";
|
|
4
|
+
import { gql as a } from "@apollo/client";
|
|
5
|
+
//#region src/healthybowl/hooks/useCropPage.ts
|
|
6
|
+
var o = "\n id name variety category season plantingDate expectedHarvestDate field fieldName\n status growthStage healthStatus yieldEstimate yieldUnit yieldEstimateSource yieldEstimateAt\n healthScore healthScoreSource healthScoreAt organicCertified daysToHarvest progress imageIds\n entityTags { id key label color vocabularyKey }\n", s = a`
|
|
7
|
+
query GetHealthyBowlCropsPage(
|
|
8
|
+
$context: ContextInput!, $search: String, $category: String, $uncategorized: Boolean,
|
|
9
|
+
$fieldId: ID, $status: String, $growthStage: String, $limit: Int, $offset: Int
|
|
10
|
+
) {
|
|
11
|
+
getHealthyBowlCropsPage(
|
|
12
|
+
context: $context, search: $search, category: $category, uncategorized: $uncategorized,
|
|
13
|
+
fieldId: $fieldId, status: $status, growthStage: $growthStage, limit: $limit, offset: $offset
|
|
14
|
+
) {
|
|
15
|
+
items { ${o} }
|
|
16
|
+
total limit offset hasMore nextOffset
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`, c = a`
|
|
20
|
+
query GetHealthyBowlCrop($context: ContextInput!, $id: ID!) {
|
|
21
|
+
getHealthyBowlCrop(context: $context, id: $id) { ${o} }
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
function l(a = {}) {
|
|
25
|
+
let { workspaceId: o } = e(), { search: c, category: l, uncategorized: u, fieldId: d, status: f, growthStage: p, skip: m } = a, { limit: h, offset: g } = n(a), { data: _, loading: v, error: y, refetch: b } = r(s, i(() => ({
|
|
26
|
+
context: { workspaceId: o },
|
|
27
|
+
search: c,
|
|
28
|
+
category: l,
|
|
29
|
+
uncategorized: u,
|
|
30
|
+
fieldId: d,
|
|
31
|
+
status: f,
|
|
32
|
+
growthStage: p,
|
|
33
|
+
limit: h,
|
|
34
|
+
offset: g
|
|
35
|
+
}), [
|
|
36
|
+
o,
|
|
37
|
+
c,
|
|
38
|
+
l,
|
|
39
|
+
u,
|
|
40
|
+
d,
|
|
41
|
+
f,
|
|
42
|
+
p,
|
|
43
|
+
h,
|
|
44
|
+
g
|
|
45
|
+
]), m);
|
|
46
|
+
return {
|
|
47
|
+
..._?.getHealthyBowlCropsPage ?? t({
|
|
48
|
+
limit: h,
|
|
49
|
+
offset: g
|
|
50
|
+
}),
|
|
51
|
+
loading: v,
|
|
52
|
+
error: y,
|
|
53
|
+
refetch: b
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function u(t, n = {}) {
|
|
57
|
+
let { workspaceId: a } = e(), { data: o, loading: s, error: l, refetch: u } = r(c, i(() => ({
|
|
58
|
+
context: { workspaceId: a },
|
|
59
|
+
id: t ?? ""
|
|
60
|
+
}), [a, t]), n.skip || !t), d = o?.getHealthyBowlCrop;
|
|
61
|
+
return {
|
|
62
|
+
crop: d && d.id === t ? d : null,
|
|
63
|
+
loading: s,
|
|
64
|
+
error: l,
|
|
65
|
+
refetch: u
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { u as useCropDetail, l as useCropPage };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=useCropPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCropPage.js","names":[],"sources":["../../../src/healthybowl/hooks/useCropPage.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport { gql, type TypedDocumentNode } from '@apollo/client';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport type { Crop } from '../types';\nimport {\n emptyOffsetPage,\n normalizeReadPagination,\n useWorkspaceRead,\n type OffsetPage,\n type PageReadOptions,\n type ReadState,\n type WorkspaceReadContext,\n} from './useWorkspaceRead';\n\nexport interface CropPageOptions extends PageReadOptions {\n fieldId?: string;\n status?: string;\n growthStage?: string;\n}\n\ninterface CropPageVariables {\n context: WorkspaceReadContext;\n search?: string;\n category?: string;\n uncategorized?: boolean;\n fieldId?: string;\n status?: string;\n growthStage?: string;\n limit: number;\n offset: number;\n}\n\ninterface CropPageData {\n getHealthyBowlCropsPage: OffsetPage<Crop>;\n}\n\ninterface CropDetailVariables {\n context: WorkspaceReadContext;\n id: string;\n}\n\ninterface CropDetailData {\n getHealthyBowlCrop: Crop | null;\n}\n\n// The new companion reads are deliberately handwritten until the released Hive\n// supergraph reaches the sanctioned offline SDL pull. Item fields match the existing Crop read.\nconst CROP_FIELDS = `\n id name variety category season plantingDate expectedHarvestDate field fieldName\n status growthStage healthStatus yieldEstimate yieldUnit yieldEstimateSource yieldEstimateAt\n healthScore healthScoreSource healthScoreAt organicCertified daysToHarvest progress imageIds\n entityTags { id key label color vocabularyKey }\n`;\n\nexport const CROP_PAGE_QUERY: TypedDocumentNode<CropPageData, CropPageVariables> = gql`\n query GetHealthyBowlCropsPage(\n $context: ContextInput!, $search: String, $category: String, $uncategorized: Boolean,\n $fieldId: ID, $status: String, $growthStage: String, $limit: Int, $offset: Int\n ) {\n getHealthyBowlCropsPage(\n context: $context, search: $search, category: $category, uncategorized: $uncategorized,\n fieldId: $fieldId, status: $status, growthStage: $growthStage, limit: $limit, offset: $offset\n ) {\n items { ${CROP_FIELDS} }\n total limit offset hasMore nextOffset\n }\n }\n`;\n\nexport const CROP_DETAIL_QUERY: TypedDocumentNode<CropDetailData, CropDetailVariables> = gql`\n query GetHealthyBowlCrop($context: ContextInput!, $id: ID!) {\n getHealthyBowlCrop(context: $context, id: $id) { ${CROP_FIELDS} }\n }\n`;\n\nexport function useCropPage(options: CropPageOptions = {}): OffsetPage<Crop> & ReadState {\n const { workspaceId } = useHealthyBowl();\n const { search, category, uncategorized, fieldId, status, growthStage, skip } = options;\n const { limit, offset } = normalizeReadPagination(options);\n const variables = useMemo<CropPageVariables>(\n () => ({ context: { workspaceId }, search, category, uncategorized, fieldId, status, growthStage, limit, offset }),\n [workspaceId, search, category, uncategorized, fieldId, status, growthStage, limit, offset]\n );\n const { data, loading, error, refetch } = useWorkspaceRead(CROP_PAGE_QUERY, variables, skip);\n return { ...(data?.getHealthyBowlCropsPage ?? emptyOffsetPage<Crop>({ limit, offset })), loading, error, refetch };\n}\n\n/** A recorded ID is never resolved by name, even if it is missing from the current page. */\nexport function useCropDetail(\n id: string | null | undefined,\n options: { skip?: boolean } = {}\n): ReadState & {\n crop: Crop | null;\n} {\n const { workspaceId } = useHealthyBowl();\n const variables = useMemo<CropDetailVariables>(() => ({ context: { workspaceId }, id: id ?? '' }), [workspaceId, id]);\n const { data, loading, error, refetch } = useWorkspaceRead(CROP_DETAIL_QUERY, variables, options.skip || !id);\n const crop = data?.getHealthyBowlCrop;\n return { crop: crop && crop.id === id ? crop : null, loading, error, refetch };\n}\n"],"mappings":";;;;;AA+CA,IAAM,IAAc,4UAOP,IAAsE,CAAG;;;;;;;;;gBAStE,EAAY;;;;GAMf,IAA4E,CAAG;;uDAErC,EAAY;;;AAInE,SAAgB,EAAY,IAA2B,CAAC,GAAiC;CACvF,IAAM,EAAE,mBAAgB,EAAe,GACjC,EAAE,WAAQ,aAAU,kBAAe,YAAS,WAAQ,gBAAa,YAAS,GAC1E,EAAE,UAAO,cAAW,EAAwB,CAAO,GAKnD,EAAE,SAAM,YAAS,UAAO,eAAY,EAAiB,GAJzC,SACT;EAAE,SAAS,EAAE,eAAY;EAAG;EAAQ;EAAU;EAAe;EAAS;EAAQ;EAAa;EAAO;CAAO,IAChH;EAAC;EAAa;EAAQ;EAAU;EAAe;EAAS;EAAQ;EAAa;EAAO;CAAM,CAEhB,GAAW,CAAI;CAC3F,OAAO;EAAE,GAAI,GAAM,2BAA2B,EAAsB;GAAE;GAAO;EAAO,CAAC;EAAI;EAAS;EAAO;CAAQ;AACnH;AAGA,SAAgB,EACd,GACA,IAA8B,CAAC,GAG/B;CACA,IAAM,EAAE,mBAAgB,EAAe,GAEjC,EAAE,SAAM,YAAS,UAAO,eAAY,EAAiB,GADzC,SAAoC;EAAE,SAAS,EAAE,eAAY;EAAG,IAAI,KAAM;CAAG,IAAI,CAAC,GAAa,CAAE,CACrC,GAAW,EAAQ,QAAQ,CAAC,CAAE,GACtG,IAAO,GAAM;CACnB,OAAO;EAAE,MAAM,KAAQ,EAAK,OAAO,IAAK,IAAO;EAAM;EAAS;EAAO;CAAQ;AAC/E"}
|
|
@@ -1,77 +1,166 @@
|
|
|
1
1
|
import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { emptyOffsetPage as t, normalizeReadPagination as n, useWorkspaceRead as r } from "./useWorkspaceRead.js";
|
|
3
|
+
import { useCallback as i, useMemo as a } from "react";
|
|
4
|
+
import { gql as o } from "@apollo/client";
|
|
5
|
+
import { useMutation as s } from "@apollo/client/react";
|
|
5
6
|
//#region src/healthybowl/hooks/usePlantCatalog.ts
|
|
6
|
-
var
|
|
7
|
+
var c = "\n id\n name\n category\n variety\n plantSpacingCm\n rowSpacingCm\n daysToMaturity\n seedsPerGram\n germinationRate\n seedsPerCell\n organicSuitable\n notes\n", l = o`
|
|
7
8
|
query HealthyBowlPlantCatalog($context: ContextInput!) {
|
|
8
9
|
healthyBowlPlantCatalog(context: $context) {
|
|
9
|
-
${
|
|
10
|
+
${c}
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
|
-
`,
|
|
13
|
+
`, u = o`
|
|
13
14
|
mutation CreateHealthyBowlPlantCatalogEntry($input: CreateHealthyBowlPlantCatalogInput!) {
|
|
14
15
|
createHealthyBowlPlantCatalogEntry(input: $input) {
|
|
15
|
-
${
|
|
16
|
+
${c}
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
|
-
`,
|
|
19
|
+
`, d = o`
|
|
19
20
|
mutation UpdateHealthyBowlPlantCatalogEntry($input: UpdateHealthyBowlPlantCatalogInput!) {
|
|
20
21
|
updateHealthyBowlPlantCatalogEntry(input: $input) {
|
|
21
|
-
${
|
|
22
|
+
${c}
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
`,
|
|
25
|
+
`, f = o`
|
|
25
26
|
mutation DeleteHealthyBowlPlantCatalogEntry($id: ID!, $context: ContextInput!) {
|
|
26
27
|
deleteHealthyBowlPlantCatalogEntry(id: $id, context: $context)
|
|
27
28
|
}
|
|
29
|
+
`, p = o`
|
|
30
|
+
query HealthyBowlPlantCatalogPage(
|
|
31
|
+
$context: ContextInput!, $search: String, $category: String, $uncategorized: Boolean,
|
|
32
|
+
$id: ID, $name: String, $variety: String, $limit: Int, $offset: Int
|
|
33
|
+
) {
|
|
34
|
+
healthyBowlPlantCatalogPage(
|
|
35
|
+
context: $context, search: $search, category: $category, uncategorized: $uncategorized,
|
|
36
|
+
id: $id, name: $name, variety: $variety, limit: $limit, offset: $offset
|
|
37
|
+
) {
|
|
38
|
+
items { ${c} }
|
|
39
|
+
total limit offset hasMore nextOffset
|
|
40
|
+
}
|
|
41
|
+
}
|
|
28
42
|
`;
|
|
29
|
-
function
|
|
30
|
-
let { workspaceId:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
function m(i) {
|
|
44
|
+
let { workspaceId: o } = e(), { search: s, category: c, uncategorized: l, id: u, name: d, variety: f, skip: m } = i, { limit: h, offset: g } = n(i), { data: _, loading: v, error: y, refetch: b, settled: x } = r(p, a(() => ({
|
|
45
|
+
context: { workspaceId: o },
|
|
46
|
+
search: s,
|
|
47
|
+
category: c,
|
|
48
|
+
uncategorized: l,
|
|
49
|
+
id: u,
|
|
50
|
+
name: d,
|
|
51
|
+
variety: f,
|
|
52
|
+
limit: h,
|
|
53
|
+
offset: g
|
|
54
|
+
}), [
|
|
55
|
+
o,
|
|
56
|
+
s,
|
|
57
|
+
c,
|
|
58
|
+
l,
|
|
59
|
+
u,
|
|
60
|
+
d,
|
|
61
|
+
f,
|
|
62
|
+
h,
|
|
63
|
+
g
|
|
64
|
+
]), m);
|
|
65
|
+
return {
|
|
66
|
+
..._?.healthyBowlPlantCatalogPage ?? t({
|
|
67
|
+
limit: h,
|
|
68
|
+
offset: g
|
|
69
|
+
}),
|
|
70
|
+
loading: v,
|
|
71
|
+
error: y,
|
|
72
|
+
refetch: b,
|
|
73
|
+
settled: x
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function h(e = {}) {
|
|
77
|
+
let { items: t, total: n, limit: r, offset: i, hasMore: a, nextOffset: o, loading: s, error: c, refetch: l } = m(e);
|
|
78
|
+
return {
|
|
79
|
+
items: t,
|
|
80
|
+
total: n,
|
|
81
|
+
limit: r,
|
|
82
|
+
offset: i,
|
|
83
|
+
hasMore: a,
|
|
84
|
+
nextOffset: o,
|
|
85
|
+
loading: s,
|
|
86
|
+
error: c,
|
|
87
|
+
refetch: l
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function g(e, t = {}) {
|
|
91
|
+
let n = m({
|
|
92
|
+
id: e ?? void 0,
|
|
93
|
+
limit: 1,
|
|
94
|
+
offset: 0,
|
|
95
|
+
skip: t.skip || !e
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
entry: n.items.find((t) => t.id === e) ?? null,
|
|
99
|
+
loading: n.loading,
|
|
100
|
+
error: n.error,
|
|
101
|
+
refetch: n.refetch
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function _(t, n = {}) {
|
|
105
|
+
let { workspaceId: r } = e(), i = (t?.name ?? "").trim().toLowerCase(), a = (t?.variety ?? "").trim().toLowerCase(), o = !r || n.skip === !0 || !i, s = m({
|
|
106
|
+
name: i,
|
|
107
|
+
variety: a,
|
|
108
|
+
limit: 1,
|
|
109
|
+
offset: 0,
|
|
110
|
+
skip: o
|
|
111
|
+
}), c = s.settled ? s.items[0] : void 0, l = m({
|
|
112
|
+
name: i,
|
|
113
|
+
limit: 1,
|
|
114
|
+
offset: 0,
|
|
115
|
+
skip: o || !s.settled || !!c
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
entry: o ? null : c ?? (l.settled ? l.items[0] : void 0) ?? null,
|
|
119
|
+
loading: !o && (s.loading || l.loading),
|
|
120
|
+
error: o ? void 0 : s.error ?? l.error
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function v(t) {
|
|
124
|
+
let { workspaceId: n } = e(), o = a(() => ({ workspaceId: n }), [n]), { data: c, loading: p, error: m, refetch: h } = r(l, a(() => ({ context: o }), [o]), t?.skip), [g] = s(u), [_] = s(d), [v] = s(f), y = i(async (e) => {
|
|
125
|
+
await g({ variables: { input: {
|
|
37
126
|
...e,
|
|
38
|
-
context:
|
|
39
|
-
} } }), await
|
|
127
|
+
context: o
|
|
128
|
+
} } }), await h();
|
|
40
129
|
}, [
|
|
130
|
+
g,
|
|
41
131
|
h,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
await g({ variables: { input: {
|
|
132
|
+
o
|
|
133
|
+
]), b = i(async (e, t) => {
|
|
134
|
+
await _({ variables: { input: {
|
|
46
135
|
id: e,
|
|
47
136
|
...t,
|
|
48
|
-
context:
|
|
49
|
-
} } }), await
|
|
137
|
+
context: o
|
|
138
|
+
} } }), await h();
|
|
50
139
|
}, [
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
]),
|
|
55
|
-
await
|
|
140
|
+
_,
|
|
141
|
+
h,
|
|
142
|
+
o
|
|
143
|
+
]), x = i(async (e) => {
|
|
144
|
+
await v({ variables: {
|
|
56
145
|
id: e,
|
|
57
|
-
context:
|
|
58
|
-
} }), await
|
|
146
|
+
context: o
|
|
147
|
+
} }), await h();
|
|
59
148
|
}, [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
149
|
+
v,
|
|
150
|
+
h,
|
|
151
|
+
o
|
|
63
152
|
]);
|
|
64
153
|
return {
|
|
65
|
-
entries:
|
|
66
|
-
loading:
|
|
67
|
-
error:
|
|
68
|
-
refetch:
|
|
69
|
-
createEntry:
|
|
70
|
-
updateEntry:
|
|
71
|
-
deleteEntry:
|
|
154
|
+
entries: c?.healthyBowlPlantCatalog ?? [],
|
|
155
|
+
loading: p,
|
|
156
|
+
error: m,
|
|
157
|
+
refetch: h,
|
|
158
|
+
createEntry: y,
|
|
159
|
+
updateEntry: b,
|
|
160
|
+
deleteEntry: x
|
|
72
161
|
};
|
|
73
162
|
}
|
|
74
163
|
//#endregion
|
|
75
|
-
export {
|
|
164
|
+
export { p as PLANT_CATALOG_PAGE_QUERY, _ as useMatchedPlantCatalogEntry, v as usePlantCatalog, g as usePlantCatalogEntry, h as usePlantCatalogPage };
|
|
76
165
|
|
|
77
166
|
//# sourceMappingURL=usePlantCatalog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePlantCatalog.js","names":[],"sources":["../../../src/healthybowl/hooks/usePlantCatalog.ts"],"sourcesContent":["/**\n * Master Plant List (variety catalog) data hook.\n *\n * The offline codegen doesn't type the PlantCatalog operations, so — mirroring\n * the raw-gql pattern used for `updateHealthyBowlField` in `FieldMap.tsx` — these\n * are hand-written `gql` documents executed directly against the live gateway.\n * @module healthybowl\n */\nimport { useCallback } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\n/** A single entry in the Master Plant List (editable variety catalog with spacing). */\nexport interface PlantCatalogEntry {\n id: string;\n name: string;\n category?: string | null;\n variety?: string | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n daysToMaturity?: number | null;\n /** Approximate seed count per gram (seed-rate input). */\n seedsPerGram?: number | null;\n /** Germination rate as a fraction in [0, 1] (e.g. 0.85 = 85%). */\n germinationRate?: number | null;\n /** Seeds sown per nursery cell/plug when raising transplants. */\n seedsPerCell?: number | null;\n /** Whether the variety is suitable for organic production. */\n organicSuitable?: boolean | null;\n notes?: string | null;\n}\n\n/** Editable fields for create/update (context is attached from the hook). */\nexport interface PlantCatalogInput {\n name: string;\n category?: string | null;\n variety?: string | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n daysToMaturity?: number | null;\n seedsPerGram?: number | null;\n germinationRate?: number | null;\n seedsPerCell?: number | null;\n organicSuitable?: boolean | null;\n notes?: string | null;\n}\n\nconst CATALOG_FIELDS = `\n id\n name\n category\n variety\n plantSpacingCm\n rowSpacingCm\n daysToMaturity\n seedsPerGram\n germinationRate\n seedsPerCell\n organicSuitable\n notes\n`;\n\nconst PLANT_CATALOG_QUERY = gql`\n query HealthyBowlPlantCatalog($context: ContextInput!) {\n healthyBowlPlantCatalog(context: $context) {\n ${CATALOG_FIELDS}\n }\n }\n`;\n\nconst CREATE_PLANT_CATALOG = gql`\n mutation CreateHealthyBowlPlantCatalogEntry($input: CreateHealthyBowlPlantCatalogInput!) {\n createHealthyBowlPlantCatalogEntry(input: $input) {\n ${CATALOG_FIELDS}\n }\n }\n`;\n\nconst UPDATE_PLANT_CATALOG = gql`\n mutation UpdateHealthyBowlPlantCatalogEntry($input: UpdateHealthyBowlPlantCatalogInput!) {\n updateHealthyBowlPlantCatalogEntry(input: $input) {\n ${CATALOG_FIELDS}\n }\n }\n`;\n\nconst DELETE_PLANT_CATALOG = gql`\n mutation DeleteHealthyBowlPlantCatalogEntry($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPlantCatalogEntry(id: $id, context: $context)\n }\n`;\n\ninterface CatalogQueryData {\n healthyBowlPlantCatalog: PlantCatalogEntry[];\n}\n\n/**\n * Loads the Master Plant List for the active workspace and exposes create /\n * update / delete helpers. Mutations refetch the list so the caller's view stays\n * in sync without hand-managing the cache.\n *\n * @param options.skip suppress the query entirely (e.g. a closed modal).\n */\nexport function usePlantCatalog(options?: { skip?: boolean }) {\n const { workspaceId } = useHealthyBowl();\n const context = { workspaceId };\n\n const { data, loading, error, refetch } = useQuery<CatalogQueryData>(PLANT_CATALOG_QUERY, {\n variables: { context },\n // `skip` lets a caller that only needs the catalogue sometimes — the planting\n // form, which needs it when its modal is open — avoid the query the rest of\n // the time (BOFF-6362).\n skip: !workspaceId || options?.skip === true,\n fetchPolicy: 'cache-and-network',\n notifyOnNetworkStatusChange: true,\n });\n\n const [createMutation] = useMutation(CREATE_PLANT_CATALOG);\n const [updateMutation] = useMutation(UPDATE_PLANT_CATALOG);\n const [deleteMutation] = useMutation(DELETE_PLANT_CATALOG);\n\n const createEntry = useCallback(\n async (input: PlantCatalogInput) => {\n await createMutation({ variables: { input: { ...input, context } } });\n await refetch();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [createMutation, refetch, workspaceId]\n );\n\n const updateEntry = useCallback(\n async (id: string, input: PlantCatalogInput) => {\n await updateMutation({ variables: { input: { id, ...input, context } } });\n await refetch();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [updateMutation, refetch, workspaceId]\n );\n\n const deleteEntry = useCallback(\n async (id: string) => {\n await deleteMutation({ variables: { id, context } });\n await refetch();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [deleteMutation, refetch, workspaceId]\n );\n\n return {\n entries: data?.healthyBowlPlantCatalog ?? [],\n loading,\n error,\n refetch,\n createEntry,\n updateEntry,\n deleteEntry,\n };\n}\n"],"mappings":";;;;;AAgDA,IAAM,IAAiB,8KAejB,IAAsB,CAAG;;;QAGvB,EAAe;;;GAKjB,IAAuB,CAAG;;;QAGxB,EAAe;;;GAKjB,IAAuB,CAAG;;;QAGxB,EAAe;;;GAKjB,IAAuB,CAAG;;;;;AAiBhC,SAAgB,EAAgB,GAA8B;CAC5D,IAAM,EAAE,mBAAgB,EAAe,GACjC,IAAU,EAAE,eAAY,GAExB,EAAE,SAAM,YAAS,UAAO,eAAY,EAA2B,GAAqB;EACxF,WAAW,EAAE,WAAQ;EAIrB,MAAM,CAAC,KAAe,GAAS,SAAS;EACxC,aAAa;EACb,6BAA6B;CAC/B,CAAC,GAEK,CAAC,KAAkB,EAAY,CAAoB,GACnD,CAAC,KAAkB,EAAY,CAAoB,GACnD,CAAC,KAAkB,EAAY,CAAoB,GAEnD,IAAc,EAClB,OAAO,MAA6B;EAElC,AADA,MAAM,EAAe,EAAE,WAAW,EAAE,OAAO;GAAE,GAAG;GAAO;EAAQ,EAAE,EAAE,CAAC,GACpE,MAAM,EAAQ;CAChB,GAEA;EAAC;EAAgB;EAAS;CAAW,CACvC,GAEM,IAAc,EAClB,OAAO,GAAY,MAA6B;EAE9C,AADA,MAAM,EAAe,EAAE,WAAW,EAAE,OAAO;GAAE;GAAI,GAAG;GAAO;EAAQ,EAAE,EAAE,CAAC,GACxE,MAAM,EAAQ;CAChB,GAEA;EAAC;EAAgB;EAAS;CAAW,CACvC,GAEM,IAAc,EAClB,OAAO,MAAe;EAEpB,AADA,MAAM,EAAe,EAAE,WAAW;GAAE;GAAI;EAAQ,EAAE,CAAC,GACnD,MAAM,EAAQ;CAChB,GAEA;EAAC;EAAgB;EAAS;CAAW,CACvC;CAEA,OAAO;EACL,SAAS,GAAM,2BAA2B,CAAC;EAC3C;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"usePlantCatalog.js","names":[],"sources":["../../../src/healthybowl/hooks/usePlantCatalog.ts"],"sourcesContent":["/**\n * Master Plant List (variety catalog) data hook.\n *\n * The offline codegen doesn't type the PlantCatalog operations, so — mirroring\n * the raw-gql pattern used for `updateHealthyBowlField` in `FieldMap.tsx` — these\n * are hand-written `gql` documents executed directly against the live gateway.\n * @module healthybowl\n */\nimport { useCallback, useMemo } from 'react';\nimport { gql, type ErrorLike, type TypedDocumentNode } from '@apollo/client';\nimport { useMutation } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport type { Crop } from '../types';\nimport {\n emptyOffsetPage,\n normalizeReadPagination,\n useWorkspaceRead,\n type OffsetPage,\n type PageReadOptions,\n type ReadState,\n type WorkspaceReadContext,\n} from './useWorkspaceRead';\n\n/** A single entry in the Master Plant List (editable variety catalog with spacing). */\nexport interface PlantCatalogEntry {\n id: string;\n name: string;\n category?: string | null;\n variety?: string | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n daysToMaturity?: number | null;\n /** Approximate seed count per gram (seed-rate input). */\n seedsPerGram?: number | null;\n /** Germination rate as a fraction in [0, 1] (e.g. 0.85 = 85%). */\n germinationRate?: number | null;\n /** Seeds sown per nursery cell/plug when raising transplants. */\n seedsPerCell?: number | null;\n /** Whether the variety is suitable for organic production. */\n organicSuitable?: boolean | null;\n notes?: string | null;\n}\n\n/** Editable fields for create/update (context is attached from the hook). */\nexport interface PlantCatalogInput {\n name: string;\n category?: string | null;\n variety?: string | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n daysToMaturity?: number | null;\n seedsPerGram?: number | null;\n germinationRate?: number | null;\n seedsPerCell?: number | null;\n organicSuitable?: boolean | null;\n notes?: string | null;\n}\n\nconst CATALOG_FIELDS = `\n id\n name\n category\n variety\n plantSpacingCm\n rowSpacingCm\n daysToMaturity\n seedsPerGram\n germinationRate\n seedsPerCell\n organicSuitable\n notes\n`;\n\nconst PLANT_CATALOG_QUERY = gql`\n query HealthyBowlPlantCatalog($context: ContextInput!) {\n healthyBowlPlantCatalog(context: $context) {\n ${CATALOG_FIELDS}\n }\n }\n`;\n\nconst CREATE_PLANT_CATALOG = gql`\n mutation CreateHealthyBowlPlantCatalogEntry($input: CreateHealthyBowlPlantCatalogInput!) {\n createHealthyBowlPlantCatalogEntry(input: $input) {\n ${CATALOG_FIELDS}\n }\n }\n`;\n\nconst UPDATE_PLANT_CATALOG = gql`\n mutation UpdateHealthyBowlPlantCatalogEntry($input: UpdateHealthyBowlPlantCatalogInput!) {\n updateHealthyBowlPlantCatalogEntry(input: $input) {\n ${CATALOG_FIELDS}\n }\n }\n`;\n\nconst DELETE_PLANT_CATALOG = gql`\n mutation DeleteHealthyBowlPlantCatalogEntry($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPlantCatalogEntry(id: $id, context: $context)\n }\n`;\n\ninterface CatalogQueryData {\n healthyBowlPlantCatalog: PlantCatalogEntry[];\n}\n\ninterface CatalogQueryVariables {\n context: WorkspaceReadContext;\n}\n\ninterface CreateCatalogData {\n createHealthyBowlPlantCatalogEntry: PlantCatalogEntry;\n}\n\ninterface UpdateCatalogData {\n updateHealthyBowlPlantCatalogEntry: PlantCatalogEntry;\n}\n\ninterface DeleteCatalogData {\n deleteHealthyBowlPlantCatalogEntry: boolean;\n}\n\ninterface CreateCatalogVariables {\n input: PlantCatalogInput & { context: WorkspaceReadContext };\n}\n\ninterface UpdateCatalogVariables {\n input: PlantCatalogInput & { id: string; context: WorkspaceReadContext };\n}\n\ninterface DeleteCatalogVariables extends CatalogQueryVariables {\n id: string;\n}\n\nexport interface PlantCatalogPageOptions extends PageReadOptions {\n id?: string;\n name?: string;\n /** An empty string explicitly matches the existing null/blank variety semantics. */\n variety?: string;\n}\n\ninterface CatalogPageVariables extends CatalogQueryVariables {\n search?: string;\n category?: string;\n uncategorized?: boolean;\n id?: string;\n name?: string;\n variety?: string;\n limit: number;\n offset: number;\n}\n\ninterface CatalogPageData {\n healthyBowlPlantCatalogPage: OffsetPage<PlantCatalogEntry>;\n}\n\nexport const PLANT_CATALOG_PAGE_QUERY: TypedDocumentNode<CatalogPageData, CatalogPageVariables> = gql`\n query HealthyBowlPlantCatalogPage(\n $context: ContextInput!, $search: String, $category: String, $uncategorized: Boolean,\n $id: ID, $name: String, $variety: String, $limit: Int, $offset: Int\n ) {\n healthyBowlPlantCatalogPage(\n context: $context, search: $search, category: $category, uncategorized: $uncategorized,\n id: $id, name: $name, variety: $variety, limit: $limit, offset: $offset\n ) {\n items { ${CATALOG_FIELDS} }\n total limit offset hasMore nextOffset\n }\n }\n`;\n\nfunction useCatalogPageRead(options: PlantCatalogPageOptions) {\n const { workspaceId } = useHealthyBowl();\n const { search, category, uncategorized, id, name, variety, skip } = options;\n const { limit, offset } = normalizeReadPagination(options);\n const variables = useMemo<CatalogPageVariables>(\n () => ({ context: { workspaceId }, search, category, uncategorized, id, name, variety, limit, offset }),\n [workspaceId, search, category, uncategorized, id, name, variety, limit, offset]\n );\n const { data, loading, error, refetch, settled } = useWorkspaceRead(PLANT_CATALOG_PAGE_QUERY, variables, skip);\n return {\n ...(data?.healthyBowlPlantCatalogPage ?? emptyOffsetPage<PlantCatalogEntry>({ limit, offset })),\n loading,\n error,\n refetch,\n settled,\n };\n}\n\nexport function usePlantCatalogPage(options: PlantCatalogPageOptions = {}): OffsetPage<PlantCatalogEntry> & ReadState {\n const { items, total, limit, offset, hasMore, nextOffset, loading, error, refetch } = useCatalogPageRead(options);\n return { items, total, limit, offset, hasMore, nextOffset, loading, error, refetch };\n}\n\n/** Independent of the search/category/page the user is currently browsing. */\nexport function usePlantCatalogEntry(\n id: string | null | undefined,\n options: { skip?: boolean } = {}\n): ReadState & { entry: PlantCatalogEntry | null } {\n const page = useCatalogPageRead({ id: id ?? undefined, limit: 1, offset: 0, skip: options.skip || !id });\n return {\n entry: page.items.find((entry) => entry.id === id) ?? null,\n loading: page.loading,\n error: page.error,\n refetch: page.refetch,\n };\n}\n\n/**\n * Preserve the legacy normalized name + variety match, then the first same-name\n * row. Absence is authoritative only after the exact query completes: a partial\n * cached result must never make a different variety look like the selected one.\n */\nexport function useMatchedPlantCatalogEntry(\n crop: Pick<Crop, 'name' | 'variety'> | null | undefined,\n options: { skip?: boolean } = {}\n): { entry: PlantCatalogEntry | null; loading: boolean; error: ErrorLike | undefined } {\n const { workspaceId } = useHealthyBowl();\n const name = (crop?.name ?? '').trim().toLowerCase();\n const variety = (crop?.variety ?? '').trim().toLowerCase();\n const skip = !workspaceId || options.skip === true || !name;\n const exact = useCatalogPageRead({ name, variety, limit: 1, offset: 0, skip });\n const exactEntry = exact.settled ? exact.items[0] : undefined;\n const fallback = useCatalogPageRead({\n name,\n limit: 1,\n offset: 0,\n skip: skip || !exact.settled || Boolean(exactEntry),\n });\n\n return {\n entry: skip ? null : (exactEntry ?? (fallback.settled ? fallback.items[0] : undefined) ?? null),\n loading: !skip && (exact.loading || fallback.loading),\n error: skip ? undefined : (exact.error ?? fallback.error),\n };\n}\n\n/**\n * Loads the Master Plant List for the active workspace and exposes create /\n * update / delete helpers. Mutations refetch the list so the caller's view stays\n * in sync without hand-managing the cache.\n *\n * @param options.skip suppress the query entirely (e.g. a closed modal).\n */\nexport function usePlantCatalog(options?: { skip?: boolean }) {\n const { workspaceId } = useHealthyBowl();\n const context = useMemo<WorkspaceReadContext>(() => ({ workspaceId }), [workspaceId]);\n const variables = useMemo<CatalogQueryVariables>(() => ({ context }), [context]);\n const legacyQuery: TypedDocumentNode<CatalogQueryData, CatalogQueryVariables> = PLANT_CATALOG_QUERY;\n const { data, loading, error, refetch } = useWorkspaceRead(legacyQuery, variables, options?.skip);\n\n const [createMutation] = useMutation<CreateCatalogData, CreateCatalogVariables>(CREATE_PLANT_CATALOG);\n const [updateMutation] = useMutation<UpdateCatalogData, UpdateCatalogVariables>(UPDATE_PLANT_CATALOG);\n const [deleteMutation] = useMutation<DeleteCatalogData, DeleteCatalogVariables>(DELETE_PLANT_CATALOG);\n\n const createEntry = useCallback(\n async (input: PlantCatalogInput) => {\n await createMutation({ variables: { input: { ...input, context } } });\n await refetch();\n },\n [createMutation, refetch, context]\n );\n\n const updateEntry = useCallback(\n async (id: string, input: PlantCatalogInput) => {\n await updateMutation({ variables: { input: { id, ...input, context } } });\n await refetch();\n },\n [updateMutation, refetch, context]\n );\n\n const deleteEntry = useCallback(\n async (id: string) => {\n await deleteMutation({ variables: { id, context } });\n await refetch();\n },\n [deleteMutation, refetch, context]\n );\n\n return {\n entries: data?.healthyBowlPlantCatalog ?? [],\n loading,\n error,\n refetch,\n createEntry,\n updateEntry,\n deleteEntry,\n };\n}\n"],"mappings":";;;;;;AA0DA,IAAM,IAAiB,8KAejB,IAAsB,CAAG;;;QAGvB,EAAe;;;GAKjB,IAAuB,CAAG;;;QAGxB,EAAe;;;GAKjB,IAAuB,CAAG;;;QAGxB,EAAe;;;GAKjB,IAAuB,CAAG;;;;GA4DnB,IAAqF,CAAG;;;;;;;;;gBASrF,EAAe;;;;;AAM/B,SAAS,EAAmB,GAAkC;CAC5D,IAAM,EAAE,mBAAgB,EAAe,GACjC,EAAE,WAAQ,aAAU,kBAAe,OAAI,SAAM,YAAS,YAAS,GAC/D,EAAE,UAAO,cAAW,EAAwB,CAAO,GAKnD,EAAE,SAAM,YAAS,UAAO,YAAS,eAAY,EAAiB,GAJlD,SACT;EAAE,SAAS,EAAE,eAAY;EAAG;EAAQ;EAAU;EAAe;EAAI;EAAM;EAAS;EAAO;CAAO,IACrG;EAAC;EAAa;EAAQ;EAAU;EAAe;EAAI;EAAM;EAAS;EAAO;CAAM,CAEa,GAAW,CAAI;CAC7G,OAAO;EACL,GAAI,GAAM,+BAA+B,EAAmC;GAAE;GAAO;EAAO,CAAC;EAC7F;EACA;EACA;EACA;CACF;AACF;AAEA,SAAgB,EAAoB,IAAmC,CAAC,GAA8C;CACpH,IAAM,EAAE,UAAO,UAAO,UAAO,WAAQ,Y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C,EAAE,WAAQ,IAAI,CAAC,CAAO,CAEN,GAAW,GAAS,IAAI,GAE1F,CAAC,KAAkB,EAAuD,CAAoB,GAC9F,CAAC,KAAkB,EAAuD,CAAoB,GAC9F,CAAC,KAAkB,EAAuD,CAAoB,GAE9F,IAAc,EAClB,OAAO,MAA6B;EAElC,AADA,MAAM,EAAe,EAAE,WAAW,EAAE,OAAO;GAAE,GAAG;GAAO;EAAQ,EAAE,EAAE,CAAC,GACpE,MAAM,EAAQ;CAChB,GACA;EAAC;EAAgB;EAAS;CAAO,CACnC,GAEM,IAAc,EAClB,OAAO,GAAY,MAA6B;EAE9C,AADA,MAAM,EAAe,EAAE,WAAW,EAAE,OAAO;GAAE;GAAI,GAAG;GAAO;EAAQ,EAAE,EAAE,CAAC,GACxE,MAAM,EAAQ;CAChB,GACA;EAAC;EAAgB;EAAS;CAAO,CACnC,GAEM,IAAc,EAClB,OAAO,MAAe;EAEpB,AADA,MAAM,EAAe,EAAE,WAAW;GAAE;GAAI;EAAQ,EAAE,CAAC,GACnD,MAAM,EAAQ;CAChB,GACA;EAAC;EAAgB;EAAS;CAAO,CACnC;CAEA,OAAO;EACL,SAAS,GAAM,2BAA2B,CAAC;EAC3C;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -64,19 +64,19 @@ function l(t) {
|
|
|
64
64
|
t.rowSpacingCm,
|
|
65
65
|
t.bedWidthM,
|
|
66
66
|
t.pathWidthM
|
|
67
|
-
]), u = c(l, 250), d = JSON.stringify(l), f = JSON.stringify(u), { data:
|
|
67
|
+
]), u = c(l, 250), d = JSON.stringify(l), f = JSON.stringify(u), p = !r || !t.fieldId, { data: m, loading: h, error: g, dataState: _ } = a(o, {
|
|
68
68
|
variables: {
|
|
69
69
|
context: i,
|
|
70
70
|
input: u
|
|
71
71
|
},
|
|
72
|
-
skip:
|
|
72
|
+
skip: p,
|
|
73
73
|
fetchPolicy: "network-only"
|
|
74
74
|
});
|
|
75
75
|
return {
|
|
76
|
-
estimate:
|
|
77
|
-
loading:
|
|
78
|
-
error:
|
|
79
|
-
ready: d === f && !
|
|
76
|
+
estimate: m?.healthyBowlPlantingEstimate ?? null,
|
|
77
|
+
loading: h,
|
|
78
|
+
error: g,
|
|
79
|
+
ready: !p && d === f && !h && !g && _ === "complete" && m?.healthyBowlPlantingEstimate !== void 0
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
function u(e, t, n) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePlantingEstimate.js","names":[],"sources":["../../../src/healthybowl/hooks/usePlantingEstimate.ts"],"sourcesContent":["/**\n * Server-derived planting capacity and seed rate (BOFF-6100).\n *\n * ### Why the client still computes this too\n *\n * `plantingCapacity.ts` and `seedRate.ts` are not going away. A farmer dragging a bed-width or\n * spacing input expects the numbers to move as they type, and a round trip per keystroke would make\n * the panel feel broken. So the client's maths stays as the **instant preview**, and this hook\n * supplies the **authoritative** figures — the same ones `createPlantingPlan` will persist.\n *\n * `preferServer` below is the whole contract: show the server's numbers the moment they arrive, and\n * the local estimate only until then. If the two ever disagree, the farmer sees the number that\n * will actually be written, which is the disagreement spec 02 §3.8 exists to end.\n *\n * Inline `gql` rather than an entry under `src/operations/`: this op is newer than the committed\n * `graphql/wspace.graphql` snapshot codegen validates against — the escape hatch documented in\n * `useSuccessionPlanning.ts`.\n *\n * @module healthybowl\n */\nimport { useEffect, useMemo, useState } from 'react';\nimport { gql } from '@apollo/client';\nimport { useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\nexport interface PlantingCapacityFigures {\n areaSqm: number;\n cultivableAreaSqm: number;\n bedCount: number;\n bedLengthM: number;\n rowsPerBed: number;\n plantsPerRow: number;\n plantsPerBed: number;\n totalPlants: number;\n seedlingTarget: number;\n plantSpacingCm: number;\n rowSpacingCm: number;\n bedWidthM: number;\n pathWidthM: number;\n densityPlantsPerSqm: number;\n}\n\nexport interface SeedRateFigures {\n seedlingsToRaise: number;\n seedsNeeded: number;\n seedGrams: number | null;\n trays: number | null;\n}\n\nexport interface PlantingEstimate {\n appliesToBedGeometry: boolean;\n notApplicableReason: string | null;\n capacity: PlantingCapacityFigures | null;\n seedRate: SeedRateFigures | null;\n spacingPresetLabel: string;\n}\n\nconst PLANTING_ESTIMATE_QUERY = gql`\n query GetHealthyBowlPlantingEstimate($context: ContextInput!, $input: HealthyBowlPlantingEstimateInput!) {\n healthyBowlPlantingEstimate(context: $context, input: $input) {\n appliesToBedGeometry\n notApplicableReason\n spacingPresetLabel\n capacity {\n areaSqm\n cultivableAreaSqm\n bedCount\n bedLengthM\n rowsPerBed\n plantsPerRow\n plantsPerBed\n totalPlants\n seedlingTarget\n plantSpacingCm\n rowSpacingCm\n bedWidthM\n pathWidthM\n densityPlantsPerSqm\n }\n seedRate {\n seedlingsToRaise\n seedsNeeded\n seedGrams\n trays\n }\n }\n }\n`;\n\nexport interface PlantingEstimateArgs {\n fieldId?: string | null;\n plantCatalogId?: string | null;\n cropId?: string | null;\n /** Positive unsaved boundary area in the field unit; used only for the estimate read. */\n areaOverride?: number | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n bedWidthM?: number | null;\n pathWidthM?: number | null;\n}\n\n/** Drop nulls so an unset control does not override a catalog value with an explicit null. */\nfunction buildInput(args: PlantingEstimateArgs): Record<string, unknown> {\n const input: Record<string, unknown> = { fieldId: args.fieldId };\n const optional: [keyof PlantingEstimateArgs, unknown][] = [\n ['plantCatalogId', args.plantCatalogId],\n ['cropId', args.cropId],\n ['areaOverride', args.areaOverride],\n ['plantSpacingCm', args.plantSpacingCm],\n ['rowSpacingCm', args.rowSpacingCm],\n ['bedWidthM', args.bedWidthM],\n ['pathWidthM', args.pathWidthM],\n ];\n for (const [key, value] of optional) {\n if (value !== null && value !== undefined) input[key] = value;\n }\n return input;\n}\n\nfunction useDebouncedValue<T>(value: T, delayMs: number): T {\n const [debounced, setDebounced] = useState(value);\n\n useEffect(() => {\n const timer = window.setTimeout(() => setDebounced(value), delayMs);\n return () => window.clearTimeout(timer);\n }, [value, delayMs]);\n\n return debounced;\n}\n\nexport function usePlantingEstimate(args: PlantingEstimateArgs): {\n estimate: PlantingEstimate | null;\n loading: boolean;\n /** Network/GraphQL error. Caller can surface it without pretending a local preview was authoritative. */\n error: Error | undefined;\n /** True
|
|
1
|
+
{"version":3,"file":"usePlantingEstimate.js","names":[],"sources":["../../../src/healthybowl/hooks/usePlantingEstimate.ts"],"sourcesContent":["/**\n * Server-derived planting capacity and seed rate (BOFF-6100).\n *\n * ### Why the client still computes this too\n *\n * `plantingCapacity.ts` and `seedRate.ts` are not going away. A farmer dragging a bed-width or\n * spacing input expects the numbers to move as they type, and a round trip per keystroke would make\n * the panel feel broken. So the client's maths stays as the **instant preview**, and this hook\n * supplies the **authoritative** figures — the same ones `createPlantingPlan` will persist.\n *\n * `preferServer` below is the whole contract: show the server's numbers the moment they arrive, and\n * the local estimate only until then. If the two ever disagree, the farmer sees the number that\n * will actually be written, which is the disagreement spec 02 §3.8 exists to end.\n *\n * Inline `gql` rather than an entry under `src/operations/`: this op is newer than the committed\n * `graphql/wspace.graphql` snapshot codegen validates against — the escape hatch documented in\n * `useSuccessionPlanning.ts`.\n *\n * @module healthybowl\n */\nimport { useEffect, useMemo, useState } from 'react';\nimport { gql } from '@apollo/client';\nimport { useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\nexport interface PlantingCapacityFigures {\n areaSqm: number;\n cultivableAreaSqm: number;\n bedCount: number;\n bedLengthM: number;\n rowsPerBed: number;\n plantsPerRow: number;\n plantsPerBed: number;\n totalPlants: number;\n seedlingTarget: number;\n plantSpacingCm: number;\n rowSpacingCm: number;\n bedWidthM: number;\n pathWidthM: number;\n densityPlantsPerSqm: number;\n}\n\nexport interface SeedRateFigures {\n seedlingsToRaise: number;\n seedsNeeded: number;\n seedGrams: number | null;\n trays: number | null;\n}\n\nexport interface PlantingEstimate {\n appliesToBedGeometry: boolean;\n notApplicableReason: string | null;\n capacity: PlantingCapacityFigures | null;\n seedRate: SeedRateFigures | null;\n spacingPresetLabel: string;\n}\n\nconst PLANTING_ESTIMATE_QUERY = gql`\n query GetHealthyBowlPlantingEstimate($context: ContextInput!, $input: HealthyBowlPlantingEstimateInput!) {\n healthyBowlPlantingEstimate(context: $context, input: $input) {\n appliesToBedGeometry\n notApplicableReason\n spacingPresetLabel\n capacity {\n areaSqm\n cultivableAreaSqm\n bedCount\n bedLengthM\n rowsPerBed\n plantsPerRow\n plantsPerBed\n totalPlants\n seedlingTarget\n plantSpacingCm\n rowSpacingCm\n bedWidthM\n pathWidthM\n densityPlantsPerSqm\n }\n seedRate {\n seedlingsToRaise\n seedsNeeded\n seedGrams\n trays\n }\n }\n }\n`;\n\nexport interface PlantingEstimateArgs {\n fieldId?: string | null;\n plantCatalogId?: string | null;\n cropId?: string | null;\n /** Positive unsaved boundary area in the field unit; used only for the estimate read. */\n areaOverride?: number | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n bedWidthM?: number | null;\n pathWidthM?: number | null;\n}\n\n/** Drop nulls so an unset control does not override a catalog value with an explicit null. */\nfunction buildInput(args: PlantingEstimateArgs): Record<string, unknown> {\n const input: Record<string, unknown> = { fieldId: args.fieldId };\n const optional: [keyof PlantingEstimateArgs, unknown][] = [\n ['plantCatalogId', args.plantCatalogId],\n ['cropId', args.cropId],\n ['areaOverride', args.areaOverride],\n ['plantSpacingCm', args.plantSpacingCm],\n ['rowSpacingCm', args.rowSpacingCm],\n ['bedWidthM', args.bedWidthM],\n ['pathWidthM', args.pathWidthM],\n ];\n for (const [key, value] of optional) {\n if (value !== null && value !== undefined) input[key] = value;\n }\n return input;\n}\n\nfunction useDebouncedValue<T>(value: T, delayMs: number): T {\n const [debounced, setDebounced] = useState(value);\n\n useEffect(() => {\n const timer = window.setTimeout(() => setDebounced(value), delayMs);\n return () => window.clearTimeout(timer);\n }, [value, delayMs]);\n\n return debounced;\n}\n\nexport function usePlantingEstimate(args: PlantingEstimateArgs): {\n estimate: PlantingEstimate | null;\n loading: boolean;\n /** Network/GraphQL error. Caller can surface it without pretending a local preview was authoritative. */\n error: Error | undefined;\n /** True for a complete successful current-input answer, including a nullable refusal. */\n ready: boolean;\n} {\n const { workspaceId } = useHealthyBowl();\n const context = useMemo(() => ({ workspaceId }), [workspaceId]);\n // Depends on the FIELDS, not on `args`: every caller passes an object literal, so a `[args]`\n // dependency compares a fresh reference each render and the memo never caches — which in turn\n // hands Apollo a new `variables` object every render.\n const input = useMemo(\n () => buildInput(args),\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the fields ARE the identity of `args`.\n [\n args.fieldId,\n args.plantCatalogId,\n args.cropId,\n args.areaOverride,\n args.plantSpacingCm,\n args.rowSpacingCm,\n args.bedWidthM,\n args.pathWidthM,\n ]\n );\n\n const debouncedInput = useDebouncedValue(input, 250);\n const inputKey = JSON.stringify(input);\n const debouncedInputKey = JSON.stringify(debouncedInput);\n\n const skip = !workspaceId || !args.fieldId;\n const { data, loading, error, dataState } = useQuery<{ healthyBowlPlantingEstimate: PlantingEstimate | null }>(\n PLANTING_ESTIMATE_QUERY,\n {\n variables: { context, input: debouncedInput },\n // Without a workspace/field there is nothing to estimate, and firing the query would only\n // produce an unscoped read or a NOT_FOUND the page would have to swallow.\n skip,\n fetchPolicy: 'network-only',\n }\n );\n\n const estimate = data?.healthyBowlPlantingEstimate ?? null;\n // A slider change must stay on the local optimistic preview until its debounced server request\n // comes back. Otherwise Apollo's old data would masquerade as the answer for the new geometry.\n // Failed/partial replies are not authoritative refusals. A successful nullable root IS, so\n // check the complete response's presence/error, not whether its estimate is non-null.\n const ready =\n !skip &&\n inputKey === debouncedInputKey &&\n !loading &&\n !error &&\n dataState === 'complete' &&\n data?.healthyBowlPlantingEstimate !== undefined;\n return { estimate, loading, error, ready };\n}\n\n/**\n * Pick which figures to show.\n *\n * The server wins **the moment it answers**, including when its answer is `null`.\n *\n * That distinction is the whole point and the first version got it wrong. `serverValue ?? local`\n * cannot tell \"the server has not replied yet\" from \"the server replied `null`\" — and `null` is\n * exactly what a greenhouse, orchard or pasture returns, because bed geometry does not describe\n * them. Falling back to the local estimate there would print bed and seed counts for a greenhouse:\n * the precise failure the refusal exists to prevent, and worse than never having built it, since\n * the numbers would look authoritative.\n *\n * So readiness is passed explicitly rather than inferred from the value.\n */\nexport function preferServer<T>(ready: boolean, serverValue: T | null | undefined, localValue: T): T | null {\n if (!ready) return localValue;\n return serverValue ?? null;\n}\n"],"mappings":";;;;;AAyDA,IAAM,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CnC,SAAS,EAAW,GAAqD;CACvE,IAAM,IAAiC,EAAE,SAAS,EAAK,QAAQ,GACzD,IAAoD;EACxD,CAAC,kBAAkB,EAAK,cAAc;EACtC,CAAC,UAAU,EAAK,MAAM;EACtB,CAAC,gBAAgB,EAAK,YAAY;EAClC,CAAC,kBAAkB,EAAK,cAAc;EACtC,CAAC,gBAAgB,EAAK,YAAY;EAClC,CAAC,aAAa,EAAK,SAAS;EAC5B,CAAC,cAAc,EAAK,UAAU;CAChC;CACA,KAAK,IAAM,CAAC,GAAK,MAAU,GACzB,AAAI,KAAU,SAA6B,EAAM,KAAO;CAE1D,OAAO;AACT;AAEA,SAAS,EAAqB,GAAU,GAAoB;CAC1D,IAAM,CAAC,GAAW,KAAgB,EAAS,CAAK;CAOhD,OALA,QAAgB;EACd,IAAM,IAAQ,OAAO,iBAAiB,EAAa,CAAK,GAAG,CAAO;EAClE,aAAa,OAAO,aAAa,CAAK;CACxC,GAAG,CAAC,GAAO,CAAO,CAAC,GAEZ;AACT;AAEA,SAAgB,EAAoB,GAOlC;CACA,IAAM,EAAE,mBAAgB,EAAe,GACjC,IAAU,SAAe,EAAE,eAAY,IAAI,CAAC,CAAW,CAAC,GAIxD,IAAQ,QACN,EAAW,CAAI,GAErB;EACE,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;CACP,CACF,GAEM,IAAiB,EAAkB,GAAO,GAAG,GAC7C,IAAW,KAAK,UAAU,CAAK,GAC/B,IAAoB,KAAK,UAAU,CAAc,GAEjD,IAAO,CAAC,KAAe,CAAC,EAAK,SAC7B,EAAE,SAAM,YAAS,UAAO,iBAAc,EAC1C,GACA;EACE,WAAW;GAAE;GAAS,OAAO;EAAe;EAG5C;EACA,aAAa;CACf,CACF;CAcA,OAAO;EAAE,UAZQ,GAAM,+BAA+B;EAYnC;EAAS;EAAO,OANjC,CAAC,KACD,MAAa,KACb,CAAC,KACD,CAAC,KACD,MAAc,cACd,GAAM,gCAAgC,KAAA;CACC;AAC3C;AAgBA,SAAgB,EAAgB,GAAgB,GAAmC,GAAyB;CAE1G,OADK,IACE,KAAe,OADH;AAErB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback as e } from "react";
|
|
2
|
+
import { NetworkStatus as t } from "@apollo/client";
|
|
3
|
+
import { useQuery as n } from "@apollo/client/react";
|
|
4
|
+
//#region src/healthybowl/hooks/useWorkspaceRead.ts
|
|
5
|
+
function r(e) {
|
|
6
|
+
let t = e.limit == null ? 50 : Number.isFinite(e.limit) ? Math.floor(e.limit) : 1, n = e.offset == null || !Number.isFinite(e.offset) ? 0 : Math.floor(e.offset);
|
|
7
|
+
return {
|
|
8
|
+
limit: Math.min(100, Math.max(1, t)),
|
|
9
|
+
offset: Math.min(2147483647, Math.max(0, n))
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function i(e) {
|
|
13
|
+
return {
|
|
14
|
+
items: [],
|
|
15
|
+
total: 0,
|
|
16
|
+
...e,
|
|
17
|
+
hasMore: !1,
|
|
18
|
+
nextOffset: null
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function a(r, i, a = !1) {
|
|
22
|
+
let o = !!i.context.workspaceId && !a, s = n(r, {
|
|
23
|
+
variables: i,
|
|
24
|
+
skip: !o,
|
|
25
|
+
fetchPolicy: "cache-and-network",
|
|
26
|
+
returnPartialData: !1,
|
|
27
|
+
notifyOnNetworkStatusChange: !0
|
|
28
|
+
}), c = o && JSON.stringify(s.variables) === JSON.stringify(i), l = c ? s.error : void 0, u = c && s.dataState === "complete" ? s.data : void 0, d = o && (!c || s.loading || !l && s.dataState !== "complete"), f = c && !d && !l && s.networkStatus === t.ready && u !== void 0, p = s.refetch;
|
|
29
|
+
return {
|
|
30
|
+
data: u,
|
|
31
|
+
loading: d,
|
|
32
|
+
error: l,
|
|
33
|
+
refetch: e(async () => {
|
|
34
|
+
o && await p(i);
|
|
35
|
+
}, [
|
|
36
|
+
o,
|
|
37
|
+
p,
|
|
38
|
+
i
|
|
39
|
+
]),
|
|
40
|
+
settled: f
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { i as emptyOffsetPage, r as normalizeReadPagination, a as useWorkspaceRead };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=useWorkspaceRead.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWorkspaceRead.js","names":[],"sources":["../../../src/healthybowl/hooks/useWorkspaceRead.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { NetworkStatus, type ErrorLike, type OperationVariables, type TypedDocumentNode } from '@apollo/client';\nimport { useQuery } from '@apollo/client/react';\n\nexport interface WorkspaceReadContext {\n workspaceId: string;\n}\n\nexport interface OffsetPage<T> {\n items: T[];\n total: number;\n limit: number;\n offset: number;\n hasMore: boolean;\n nextOffset: number | null;\n}\n\nexport interface ReadState {\n loading: boolean;\n error: ErrorLike | undefined;\n refetch: () => Promise<void>;\n}\n\nexport interface PageReadOptions {\n search?: string;\n category?: string;\n uncategorized?: boolean;\n limit?: number;\n offset?: number;\n skip?: boolean;\n}\n\n/** Keep invalid numeric variables out of GraphQL Int, without expanding the server cap. */\nexport function normalizeReadPagination(options: Pick<PageReadOptions, 'limit' | 'offset'>) {\n const limit = options.limit == null ? 50 : Number.isFinite(options.limit) ? Math.floor(options.limit) : 1;\n const offset = options.offset == null || !Number.isFinite(options.offset) ? 0 : Math.floor(options.offset);\n return { limit: Math.min(100, Math.max(1, limit)), offset: Math.min(2_147_483_647, Math.max(0, offset)) };\n}\n\nexport function emptyOffsetPage<T>(pagination: { limit: number; offset: number }): OffsetPage<T> {\n return { items: [], total: 0, ...pagination, hasMore: false, nextOffset: null };\n}\n\n/**\n * A skipped or superseded workspace read must never expose Apollo's retained data.\n * Partial cached results are not authoritative absence (in particular for variety fallback).\n */\nexport function useWorkspaceRead<TData, TVariables extends OperationVariables & { context: WorkspaceReadContext }>(\n document: TypedDocumentNode<TData, TVariables>,\n variables: TVariables,\n skip = false\n) {\n const enabled = Boolean(variables.context.workspaceId) && !skip;\n const query = useQuery(document, {\n variables,\n skip: !enabled,\n fetchPolicy: 'cache-and-network',\n returnPartialData: false,\n notifyOnNetworkStatusChange: true,\n });\n const current = enabled && JSON.stringify(query.variables) === JSON.stringify(variables);\n const error = current ? query.error : undefined;\n const data = current && query.dataState === 'complete' ? query.data : undefined;\n const loading = enabled && (!current || query.loading || (!error && query.dataState !== 'complete'));\n const settled = current && !loading && !error && query.networkStatus === NetworkStatus.ready && data !== undefined;\n const queryRefetch = query.refetch;\n const refetch = useCallback(async (): Promise<void> => {\n if (!enabled) return;\n await queryRefetch(variables);\n }, [enabled, queryRefetch, variables]);\n\n return { data, loading, error, refetch, settled };\n}\n"],"mappings":";;;;AAiCA,SAAgB,EAAwB,GAAoD;CAC1F,IAAM,IAAQ,EAAQ,SAAS,OAAO,KAAK,OAAO,SAAS,EAAQ,KAAK,IAAI,KAAK,MAAM,EAAQ,KAAK,IAAI,GAClG,IAAS,EAAQ,UAAU,QAAQ,CAAC,OAAO,SAAS,EAAQ,MAAM,IAAI,IAAI,KAAK,MAAM,EAAQ,MAAM;CACzG,OAAO;EAAE,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,CAAK,CAAC;EAA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