diff --git a/web/src/editor/JournalPanel.tsx b/web/src/editor/JournalPanel.tsx index fba7d63..bba0447 100644 --- a/web/src/editor/JournalPanel.tsx +++ b/web/src/editor/JournalPanel.tsx @@ -37,6 +37,8 @@ export function JournalPanel({ objects, scopeObjectId, onScopeChange, + scopePlantingId, + onScopePlantingChange, }: { gardenId: number canEdit: boolean @@ -46,19 +48,30 @@ export function JournalPanel({ /** Which bed the panel is filtered to, if any. */ scopeObjectId: number | null onScopeChange: (id: number | null) => void + /** Which single plop the panel is filtered to, if any (#85). The store keeps + * this mutually exclusive with scopeObjectId. Required like its bed twin. */ + scopePlantingId: number | null + onScopePlantingChange: (id: number | null) => void }) { // Date-range narrowing (#85): the backend and JournalFilter already supported // from/to; they just had no UI. Empty inputs don't filter. const [from, setFrom] = useState('') const [to, setTo] = useState('') + const scopedObject = objects.find((o) => o.id === scopeObjectId) ?? null + // One source of scope priority — plop over bed — for both the filter and the + // composer's label, so they can't drift. + const scopeLabel = scopePlantingId != null ? 'this planting' : scopedObject ? objectDisplayName(scopedObject) : null const filter = { - ...(scopeObjectId != null ? { objectId: scopeObjectId } : {}), + ...(scopePlantingId != null + ? { plantingId: scopePlantingId } + : scopeObjectId != null + ? { objectId: scopeObjectId } + : {}), ...(from ? { from } : {}), ...(to ? { to } : {}), } const journal = useJournal(gardenId, filter) const entries = journal.data?.pages.flatMap((p) => p.entries) ?? [] - const scopedObject = objects.find((o) => o.id === scopeObjectId) ?? null return (
@@ -83,6 +96,19 @@ export function JournalPanel({ )}
+ {scopePlantingId != null && ( +
+ Notes about one planting + +
+ )} +