- Upgrading from {currentFirmware()} to {latestFirmware()}
+ Upgrading {device.platformName()} from {currentFirmware()} to {latestFirmware()}
It is recommended that the device be plugged in during the upgrade as it will take
diff --git a/src/field/FieldList.tsx b/src/field/FieldList.tsx
index 6243ce3..b22e23b 100644
--- a/src/field/FieldList.tsx
+++ b/src/field/FieldList.tsx
@@ -1,7 +1,13 @@
import {
+ Accordion,
+ AccordionDetails,
+ AccordionSummary,
Box,
Button,
+ Grid2,
+ IconButton,
Paper,
+ Stack,
Tab,
Table,
TableBody,
@@ -9,16 +15,26 @@ import {
TableContainer,
TableHead,
TableRow,
- Tabs
+ Tabs,
+ Typography
} from "@mui/material";
import React, { useCallback, useEffect, useState } from "react";
-import { useMobile, useSnackbar } from "hooks";
-import { useGlobalState, useFieldAPI } from "providers";
+import { useMobile, useSnackbar, useUserAPI } from "hooks";
+import { useGlobalState, useFieldAPI, useJohnDeereProxyAPI, useCNHiProxyAPI } from "providers";
//import HarvestTable from "harvestPlan/HarvestTable";
-import { Field } from "models";
+import { Field, fieldScope, teamScope } 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";
+import FieldSettings from "./FieldSettings";
+import { ArrowForward, ExpandMore, Settings } from "@mui/icons-material";
+import { cloneDeep } from "lodash";
+import ShareAllFields from "./ShareAllFields";
+import EventBlocker from "common/EventBlocker";
+import { useNavigate } from "react-router-dom";
interface TabPanelProps {
children?: React.ReactNode;
@@ -26,128 +42,244 @@ interface TabPanelProps {
value: any;
}
-function TabPanelMine(props: TabPanelProps) {
- const { children, value, index, ...other } = props;
-
- return (
-
- {value === index && {children}}
-
- );
-}
-
export default function FieldList() {
const [{ as }] = useGlobalState();
const isMobile = useMobile();
const fieldAPI = useFieldAPI();
+ const jdAPI = useJohnDeereProxyAPI();
+ const cnhAPI = useCNHiProxyAPI();
const { openSnack } = useSnackbar();
- const [fields, setFields] = useState([]);
- const [value, setValue] = React.useState(0);
+ const [tabValue, setTabValue] = React.useState(0);
const [openHarvestSettings, setOpenHarvestSettings] = useState(false);
- const [fieldForPlan, setFieldForPlan] = useState(Field.create());
+ // const [fieldForPlan, setFieldForPlan] = useState(Field.create());
+ const [fields, setFields] = useState([]);
+ const [total, setTotal] = useState(0)
+ const [rowsPerPage, setRowsPerPage] = useState(5)
+ const [page, setPage] = useState(0)
+ const [selectedField, setSelectedField] = useState()
+ const [openFieldSettings, setOpenFieldSettings] = useState(false)
+ const [shareOpen, setShareOpen] = useState(false)
+ const navigate = useNavigate();
const handleChange = (event: React.ChangeEvent<{}>, newValue: number) => {
- setValue(newValue);
+ setTabValue(newValue);
+ setPage(0)
};
- const loadFields = useCallback(() => {
+ const loadAdaptiveFields = useCallback(() => {
fieldAPI
- .listFields(500, 0, "asc", "fieldName", undefined, as)
+ .listFields(rowsPerPage, page*rowsPerPage, "asc", "fieldName", undefined, as)
.then(resp => {
- setFields(resp.data.fields.map(f => Field.any(f)));
- // resp.data.fields.forEach(f => {
- // if (f.settings) {
- // fieldAPI.updateField(f.settings.key, f.settings);
- // }
- // });
+ setFields(resp.data.fields.map(f => Field.create(f)));
+ setTotal(resp.data.total)
})
.catch(err => {
- openSnack("Failed to load Field Mapping");
+ openSnack("Failed to load Fields");
});
- }, [fieldAPI, as, openSnack]);
+ }, [fieldAPI, as, openSnack, page, rowsPerPage]);
+
+ const loadJDFields = useCallback(() => {
+ jdAPI.listFields(rowsPerPage, page*rowsPerPage, as)
+ .then(resp => {
+ resp.data.fields ? setFields(resp.data.fields.map(f => Field.create(f))) : setFields([])
+ }).catch(err => {
+ openSnack("Failed to load John Deere Fields");
+ })
+ },[jdAPI, as, openSnack, page, rowsPerPage])
+
+ const loadCNHFields = useCallback(() => {
+ cnhAPI.listFields(rowsPerPage, page*rowsPerPage, as)
+ .then(resp => {
+ resp.data.fields ? setFields(resp.data.fields.map(f => Field.create(f))) : setFields([])
+ }).catch(err => {
+ openSnack("Failed to load John Deere Fields");
+ })
+ },[cnhAPI, as, openSnack, page, rowsPerPage])
useEffect(() => {
- loadFields();
- }, [loadFields]);
+ //based on the current tab load the correct fields
+ switch(tabValue){
+ case 0:
+ loadAdaptiveFields();
+ break;
+ case 1:
+ loadJDFields();
+ break;
+ case 2:
+ loadCNHFields();
+ break;
+ }
+ }, [loadAdaptiveFields, loadJDFields, loadCNHFields, tabValue]);
- const calcTotalAcres = () => {
- let totalAcres = 0;
- fields.forEach(field => {
- totalAcres += field.acres();
- });
- totalAcres = Math.round(totalAcres);
- return totalAcres;
- };
+ const goTo = (field: Field) => {
+ let path = field.key();
+ navigate(path, { state: {field: field, permissions: field.permissions} });
+ }
- const listFieldsInfo = fields.map((field, index) => (
-
- {field.fieldName()}
- {field.landLoc()}
-
- {field.crop() === pond.Grain.GRAIN_CUSTOM
- ? field.customType()
- : GrainDescriber(field.crop()).name}
-
- {field.calculateAcres()}
-
- {field.permissions.includes(pond.Permission.PERMISSION_WRITE) && (
-
- )}
-
-
- ));
+ const fieldActions = (field: Field) => {
+ return (
+
+ {
+ setSelectedField(field)
+ setOpenFieldSettings(true)
+ }}>
+ {}}/>
+ {isMobile && {goTo(field)}}>}
+
+ )
+ }
+
+const columns: Column[] = [
+ {
+ title: "View",
+ render: row => {
+ return (
+
+
+
+ )
+ }
+ },
+ {
+ title: "Field Name",
+ render: row => {
+ return {row.name()}
+ }
+ },
+ {
+ title: "Current Crop",
+ render: row => {
+ return {GrainDescriber(row.crop()).name}
+ }
+ },
+ {
+ title: "Acres",
+ render: row => {
+ return {row.acres()}
+ }
+ },
+ {
+ title: "Actions",
+ hidden: tabValue > 0,
+ render: row => fieldActions(row)
+ }
+]
+
+ const fieldTable = (fields: Field[]) => {
+ return (
+
+ columns={columns}
+ rows={fields}
+ onRowClick={(row) => {
+ !isMobile && goTo(row)
+ }}
+ setPage={(newPage)=>{
+ setPage(newPage)
+ }}
+ handleRowsPerPageChange={(e)=>{setRowsPerPage(e.target.value)}}
+ page={page}
+ pageSize={rowsPerPage}
+ total={total}
+ resizeable
+ loadMore={() => {
+ let currentFields = cloneDeep(fields)
+ switch(tabValue){
+ case 0:
+ fieldAPI.listFields(rowsPerPage, currentFields.length, "asc", "fieldName", undefined, as).then(resp => {
+ setFields(currentFields.concat(resp.data.fields.map(f => Field.create(f))))
+ }).catch(err => {
+ openSnack("Failed to load more fields")
+ })
+ break;
+ case 1:
+ jdAPI.listFields(rowsPerPage, currentFields.length, as).then(resp => {
+ resp.data.fields ? setFields(currentFields.concat(resp.data.fields.map(f => Field.create(f)))) : setFields([])
+ }).catch(err => {
+ openSnack("Failed to load more fields")
+ })
+ break;
+ case 2:
+ cnhAPI.listFields(rowsPerPage, currentFields.length, as).then(resp => {
+ resp.data.fields ? setFields(currentFields.concat(resp.data.fields.map(f => Field.create(f)))) : setFields([])
+ }).catch(err => {
+ openSnack("Failed to load more fields")
+ })
+ break;
+ }
+ }}
+ renderMobile={(row, index) => {
+ return (
+
+ }>
+
+
+
+ {row.name()}
+
+
+
+ {fieldActions(row)}
+
+
+
+
+
+
+
+
+
+
+
+
+ {row.grainName()}
+ {row.acres()} Acres
+
+
+
+
+
+
+ )
+ }}
+ />
+ )
+ }
return (
+
-
- {/* {!isMobile && }
- {!isMobile && } */}
+
+
+
-
-
-
-
-
- Field Name
- Land Location
- Main Crop Type
- Acres ({calcTotalAcres()} Total)
- Create New Plan
-
-
- {listFieldsInfo}
-
-
-
- {/* need to re-factor the harvest table file before restoring these functions */}
- {/*
-
-
-
-
- */}
- setOpenHarvestSettings(false)}
field={fieldForPlan}
+ /> */}
+ {
+ //will need to re-load the fields after one is deleted
+ loadAdaptiveFields()
+ }}
+ open={openFieldSettings}
+ onClose={() => {
+ setOpenFieldSettings(false);
+ }}
/>
+ {setShareOpen(false)}}/>
);
}
\ No newline at end of file
diff --git a/src/field/FieldSettings.tsx b/src/field/FieldSettings.tsx
index ca865a0..33f0c5d 100644
--- a/src/field/FieldSettings.tsx
+++ b/src/field/FieldSettings.tsx
@@ -152,9 +152,7 @@ export default function FieldSettings(props: Props) {
const fieldInformation = () => {
return (
-
-
- Field Information
+
setFeatColor(color)} />
-
+
+ );
+ };
+
+ return (
+
+ Field Information
+ {fieldInformation()}
@@ -282,13 +287,6 @@ export default function FieldSettings(props: Props) {
-