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
This commit is contained in:
parent
9966e90f7a
commit
f6e53aff1c
6 changed files with 23 additions and 27 deletions
|
|
@ -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<Field[]>([]);
|
||||
const [total, setTotal] = useState(0)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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<string>();
|
||||
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"}
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ export default function FieldPage() {
|
|||
</Grid2>
|
||||
<Grid2 size={8}>
|
||||
<Card raised>
|
||||
<HarvestPlanTable field={field}/>
|
||||
<HarvestPlanTable field={field} planSelected={(plan) => {setHPlan(plan)}}/>
|
||||
</Card>
|
||||
</Grid2>
|
||||
</Grid2>
|
||||
|
|
@ -276,7 +276,7 @@ export default function FieldPage() {
|
|||
</Card>
|
||||
</Grid2>
|
||||
<Grid2>
|
||||
<HarvestPlanTable field={field}/>
|
||||
<HarvestPlanTable field={field} planSelected={(plan) => {setHPlan(plan)}}/>
|
||||
</Grid2>
|
||||
</Grid2>
|
||||
</TabPanel>
|
||||
|
|
|
|||
|
|
@ -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<pond.Permission[]>([]);
|
||||
const [{ user }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
const userAPI = useUserAPI();
|
||||
const [menuAnchorEl, setMenuAnchorEl] = useState<Element | null>(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) {
|
|||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue