import React, {useState} from 'react'; import ChipToggle from './ChipToggle'; const SHOWN = 10; // A dropdown of {id, name} choices with an "all" option on top, as a number // (or null for all) in and out. Nothing is rendered when there is no choice to // make. function Filter({choices, allLabel, value, onChange}) { if (choices.length < 2) return null; return ( ); } // What the member has growing, or just what is ready to pick, as a table. The // chips and the filters narrow it without reloading. `rows` is everything // growing, already worded by Rails, each with the `plant_id` of the crop it is // a kind of (a tomato variety has its tomato's) and its `garden_id`; `plants` // and `gardens` are what can be filtered on, and `gardens` is empty when // there is only the one. export default function GrowingTable({rows, plants, gardens, initial, labels}) { const [shown, setShown] = useState(initial); const [plantId, setPlantId] = useState(null); const [gardenId, setGardenId] = useState(null); const matching = rows.filter((row) => ( (plantId === null || row.plant_id === plantId) && (gardenId === null || row.garden_id === gardenId) )); const readyRows = matching.filter((row) => row.ready); const options = [ {key: 'growing', label: `${labels.chip_growing} (${matching.length})`, href: '/'}, {key: 'ready', label: `${labels.chip_ready} (${readyRows.length})`, href: '/?show=ready'} ]; const visible = (shown === 'ready' ? readyRows : matching).slice(0, SHOWN); return ( <>
{visible.length === 0 && ( )} {visible.map((row) => ( ))}
{labels.col_plant} {labels.col_bed} {labels.col_planted} {labels.col_maturity} {labels.col_progress}
{labels.nothing_to_show}
{row.name} {row.garden} {row.planted} {row.maturity}
); }