diff --git a/src/app/dashboard/plant/equipment/page.tsx b/src/app/dashboard/plant/equipment/page.tsx index 84a4f78..9246219 100644 --- a/src/app/dashboard/plant/equipment/page.tsx +++ b/src/app/dashboard/plant/equipment/page.tsx @@ -1,4 +1,5 @@ import { pbAdmin } from "@/lib/pb"; +import { composeFilter, filterOpt, getSiteScope, siteFilter, type SearchParams } from "@/lib/site-scope"; import { PlantView, type PlantRow, @@ -9,7 +10,13 @@ import type { PlantSiteOption } from "@/components/add-plant-button"; export const dynamic = "force-dynamic"; -export default async function PlantPage() { +export default async function PlantPage({ + searchParams, +}: { + searchParams: Promise; +}) { + const scope = await getSiteScope(await searchParams); + const siteF = siteFilter(scope); const pb = await pbAdmin(); // Plant bucket includes legacy empty-unit-type rows. The fuel page @@ -18,16 +25,17 @@ export default async function PlantPage() { const [allVehicles, allFuelLogs, allSites] = await Promise.all([ pb.collection("vehicles").getFullList({ sort: "description", - perPage: 5000, - filter: `unit_type="plant" || unit_type="" || unit_type=null`, + filter: composeFilter(siteF, `unit_type="plant" || unit_type="" || unit_type=null`), }), pb.collection("fuel_logs").getFullList({ sort: "-date_logged", - perPage: 5000, + ...filterOpt(siteF), }), + // Sites is a lookup table for project_code display, not a data + // read — left unfiltered so the Add-plant dialog can still show + // every site even when this page is scoped. pb.collection("sites").getFullList({ sort: "project_code", - perPage: 5000, fields: "id,project_code,name", }), ]); @@ -145,7 +153,7 @@ export default async function PlantPage() { }; }); - const projectCodes = Array.from(new Set(rows.map((r) => r.projectCode))).sort(); + const projectCodes: string[] = []; // Project column visibility is controlled by showSiteColumn; the list is now derived server-side. const sites: PlantSiteOption[] = allSites.map((s) => ({ id: s.id, @@ -179,6 +187,7 @@ export default async function PlantPage() { logs={logs} projectCodes={projectCodes} sites={sites} + showSiteColumn={scope.mode === "all"} kpis={kpis} vehicleBasePath="/dashboard/plant/equipment" title="Equipment (L/h)" diff --git a/src/app/dashboard/plant/equipment/plant-view.tsx b/src/app/dashboard/plant/equipment/plant-view.tsx index 47c4cc3..7981567 100644 --- a/src/app/dashboard/plant/equipment/plant-view.tsx +++ b/src/app/dashboard/plant/equipment/plant-view.tsx @@ -135,6 +135,7 @@ export function PlantView({ logs, projectCodes, sites, + showSiteColumn, kpis, vehicleBasePath, title, @@ -144,13 +145,13 @@ export function PlantView({ logs: PlantLogRow[]; projectCodes: string[]; sites: PlantSiteOption[]; + showSiteColumn: boolean; kpis: PlantKpis; vehicleBasePath: string; title: string; subtitle?: string; }) { const router = useRouter(); - const [projectFilter, setProjectFilter] = React.useState("all"); const [search, setSearch] = React.useState(""); const [page, setPage] = React.useState(1); // Independent pagination for the bottom "Plant log entries" table. @@ -184,15 +185,14 @@ export function PlantView({ const q = search.trim().toLowerCase(); return rows.filter((r) => { if (removedIds.has(r.id)) return false; - if (projectFilter !== "all" && r.projectCode !== projectFilter) return false; if (q && !r.description.toLowerCase().includes(q)) return false; return true; }); - }, [rows, projectFilter, search, removedIds]); + }, [rows, search, removedIds]); React.useEffect(() => { setPage(1); - }, [projectFilter, search]); + }, [search]); const pageCount = Math.max(1, Math.ceil(filtered.length / PAGE_SIZE)); const pageRows = React.useMemo( @@ -249,7 +249,7 @@ export function PlantView({ } } - const filtersActive = projectFilter !== "all" || search !== ""; + const filtersActive = search !== ""; // Inline-edit hook for the description column. The page-level toggle // controls this state via the EditModeToggle rendered in the Topbar. @@ -392,31 +392,11 @@ export function PlantView({ /> -
- - Project - - -
- {filtersActive && (