From f6e53aff1c618d1175495848570d90cbd3ef6355 Mon Sep 17 00:00:00 2001 From: csawatzky Date: Thu, 12 Feb 2026 14:55:43 -0600 Subject: [PATCH] added some minor functionality to the field page so clicking a harvest plan from the table updated the overview with it, also fixed a bug that came up regarding that with the settings using the plan permissions when they should be using the permissions passed in --- src/field/FieldList.tsx | 20 ++------------------ src/harvestPlan/HarvestPlanActions.tsx | 1 + src/harvestPlan/HarvestPlanTable.tsx | 6 +++++- src/harvestPlan/HarvestSettings.tsx | 9 ++++++--- src/pages/Field.tsx | 4 ++-- src/tasks/TaskCard.tsx | 10 +++++++--- 6 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/field/FieldList.tsx b/src/field/FieldList.tsx index b437840..f8ad8ef 100644 --- a/src/field/FieldList.tsx +++ b/src/field/FieldList.tsx @@ -6,26 +6,17 @@ import { Button, Grid2, IconButton, - Paper, Stack, Tab, - Table, - TableBody, - TableCell, - TableContainer, - TableHead, - TableRow, Tabs, Typography } from "@mui/material"; import React, { useCallback, useEffect, useState } from "react"; -import { useMobile, useSnackbar, useUserAPI } from "hooks"; +import { useMobile, useSnackbar } from "hooks"; import { useGlobalState, useFieldAPI, useJohnDeereProxyAPI, useCNHiProxyAPI } from "providers"; //import HarvestTable from "harvestPlan/HarvestTable"; -import { Field, fieldScope, teamScope } from "models"; +import { Field } from "models"; import GrainDescriber from "grain/GrainDescriber"; -import { pond } from "protobuf-ts/pond"; -import HarvestSettings from "harvestPlan/HarvestSettings"; import ResponsiveTable, { Column } from "common/ResponsiveTable"; import FieldMinimap from "./Fieldminimap"; import FieldActions from "./FieldActions"; @@ -36,12 +27,6 @@ import ShareAllFields from "./ShareAllFields"; import EventBlocker from "common/EventBlocker"; import { useNavigate } from "react-router-dom"; -interface TabPanelProps { - children?: React.ReactNode; - index: any; - value: any; -} - export default function FieldList() { const [{ as }] = useGlobalState(); const isMobile = useMobile(); @@ -50,7 +35,6 @@ export default function FieldList() { const cnhAPI = useCNHiProxyAPI(); const { openSnack } = useSnackbar(); const [tabValue, setTabValue] = React.useState(0); - const [openHarvestSettings, setOpenHarvestSettings] = useState(false); // const [fieldForPlan, setFieldForPlan] = useState(Field.create()); const [fields, setFields] = useState([]); const [total, setTotal] = useState(0) diff --git a/src/harvestPlan/HarvestPlanActions.tsx b/src/harvestPlan/HarvestPlanActions.tsx index f29c1e4..a3de850 100644 --- a/src/harvestPlan/HarvestPlanActions.tsx +++ b/src/harvestPlan/HarvestPlanActions.tsx @@ -161,6 +161,7 @@ export default function HarvestPlanActions(props: Props) { update={updatePlan} open={openState.settings} plan={plan.key() !== "" ? plan : undefined} + permissions={permissions} close={(refresh, updatedPlan) => { setOpenState({ ...openState, settings: false }); if (refresh) { diff --git a/src/harvestPlan/HarvestPlanTable.tsx b/src/harvestPlan/HarvestPlanTable.tsx index a4f48c1..645b804 100644 --- a/src/harvestPlan/HarvestPlanTable.tsx +++ b/src/harvestPlan/HarvestPlanTable.tsx @@ -11,6 +11,7 @@ import { getThemeType } from "theme" interface Props { field: Field + planSelected: (plan: HarvestPlan) => void } const useStyles = makeStyles((theme: Theme) => ({ @@ -25,7 +26,7 @@ const useStyles = makeStyles((theme: Theme) => ({ })); export default function HarvestPlanTable(props: Props){ - const {field} = props + const {field, planSelected} = props const harvestAPI = useHarvestPlanAPI() const [page, setPage] = useState(0) const [pageSize, setPageSize] = useState(10) @@ -114,6 +115,9 @@ export default function HarvestPlanTable(props: Props){ title={"Harvest Plans"} resizeable page={page} + onRowClick={(row) => { + planSelected(row) + }} pageSize={pageSize} rows={loadedPlans} total={total} diff --git a/src/harvestPlan/HarvestSettings.tsx b/src/harvestPlan/HarvestSettings.tsx index a33e0eb..966c528 100644 --- a/src/harvestPlan/HarvestSettings.tsx +++ b/src/harvestPlan/HarvestSettings.tsx @@ -35,6 +35,7 @@ interface Props { field: Field; update?: boolean; plan?: HarvestPlan; + permissions?: pond.Permission[] } const cropOptions = [ @@ -160,7 +161,7 @@ const useStyles = makeStyles((theme: Theme) => ({ const steps = ["Pre-Seeding", "Seeding", "Post-Seeding", "Harvest", "Fall"]; export default function HarvestSettings(props: Props) { - const { open, plan, close, field, update } = props; + const { open, plan, close, field, update, permissions } = props; const [{as}] = useGlobalState() const [planKey, setPlanKey] = useState(); const [newPlan, setNewPlan] = useState(HarvestPlan.create()); @@ -184,6 +185,8 @@ export default function HarvestSettings(props: Props) { const { openSnack } = useSnackbar(); const [deleteOpen, setDeleteOpen] = useState(false); + + const loadTasks = useCallback(() => { if (planKey) { taskAPI.getMultiTasks([planKey], as).then(resp => { @@ -201,7 +204,7 @@ export default function HarvestSettings(props: Props) { }, [loadTasks]); useEffect(() => { - if (!plan || (plan && plan.permissions.includes(pond.Permission.PERMISSION_WRITE))) { + if (!plan || (permissions && permissions.includes(pond.Permission.PERMISSION_WRITE))) { setActiveStep(0); } else { setActiveStep(1); @@ -415,7 +418,7 @@ export default function HarvestSettings(props: Props) { key={0} classes={{ root: classes.tab }} disabled={ - !planKey || !(plan && plan.permissions.includes(pond.Permission.PERMISSION_WRITE)) + !planKey || !(permissions && permissions.includes(pond.Permission.PERMISSION_WRITE)) } label={"General"} aria-label={"general"} diff --git a/src/pages/Field.tsx b/src/pages/Field.tsx index 19472ae..15c29db 100644 --- a/src/pages/Field.tsx +++ b/src/pages/Field.tsx @@ -227,7 +227,7 @@ export default function FieldPage() { - + {setHPlan(plan)}}/> @@ -276,7 +276,7 @@ export default function FieldPage() { - + {setHPlan(plan)}}/> diff --git a/src/tasks/TaskCard.tsx b/src/tasks/TaskCard.tsx index 6151b01..bac70e0 100644 --- a/src/tasks/TaskCard.tsx +++ b/src/tasks/TaskCard.tsx @@ -20,7 +20,7 @@ import Edit from "@mui/icons-material/Edit"; import DeleteIcon from "@mui/icons-material/Delete"; import { red } from "@mui/material/colors"; import { pond } from "protobuf-ts/pond"; -import { taskScope } from "models/Scope"; +import { taskScope, teamScope } from "models/Scope"; import EventBlocker from "common/EventBlocker"; interface Props { @@ -58,19 +58,22 @@ export default function TaskCard(props: Props) { const [day, setDay] = useState(0); const classes = useStyles(); const [permissions, setPermissions] = useState([]); - const [{ user }] = useGlobalState(); + const [{ user, as }] = useGlobalState(); const userAPI = useUserAPI(); const [menuAnchorEl, setMenuAnchorEl] = useState(null); const loadPermissions = useCallback(() => { let scope = taskScope(props.task.key); + if(as){//if viewing as a team use the permissions to the team, and not the task itself + scope = teamScope(as) + } userAPI .getUser(user.id(), scope) .then(resp => { setPermissions(resp.permissions); }) .catch(err => {}); - }, [props.task, userAPI, user]); + }, [props.task, userAPI, user, as]); useEffect(() => { loadPermissions(); @@ -176,3 +179,4 @@ export default function TaskCard(props: Props) { ); } +