diff --git a/src/field/FieldList.tsx b/src/field/FieldList.tsx index 6243ce3..6f1a7e7 100644 --- a/src/field/FieldList.tsx +++ b/src/field/FieldList.tsx @@ -9,7 +9,8 @@ import { TableContainer, TableHead, TableRow, - Tabs + Tabs, + Typography } from "@mui/material"; import React, { useCallback, useEffect, useState } from "react"; import { useMobile, useSnackbar } from "hooks"; @@ -19,6 +20,8 @@ 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"; interface TabPanelProps { children?: React.ReactNode; @@ -46,10 +49,13 @@ export default function FieldList() { const isMobile = useMobile(); const fieldAPI = useFieldAPI(); const { openSnack } = useSnackbar(); - const [fields, setFields] = useState([]); const [value, setValue] = React.useState(0); const [openHarvestSettings, setOpenHarvestSettings] = useState(false); const [fieldForPlan, setFieldForPlan] = useState(Field.create()); + const [fields, setFields] = useState([]); //all fields + const [adaptiveFields, setAdaptiveFields] = useState([]) + const [jdFields, setJDFields] = useState([]) + const [cnhFields, setCNHFields] = useState([]) const handleChange = (event: React.ChangeEvent<{}>, newValue: number) => { setValue(newValue); @@ -59,7 +65,7 @@ export default function FieldList() { fieldAPI .listFields(500, 0, "asc", "fieldName", undefined, as) .then(resp => { - setFields(resp.data.fields.map(f => Field.any(f))); + setAdaptiveFields(resp.data.fields.map(f => Field.any(f))); // resp.data.fields.forEach(f => { // if (f.settings) { // fieldAPI.updateField(f.settings.key, f.settings); @@ -75,7 +81,11 @@ export default function FieldList() { loadFields(); }, [loadFields]); - const calcTotalAcres = () => { + useEffect(()=>{ + setFields(adaptiveFields.concat(jdFields, cnhFields)) + },[adaptiveFields,jdFields,cnhFields]) + + const calcTotalAcres = (fields: Field[]) => { let totalAcres = 0; fields.forEach(field => { totalAcres += field.acres(); @@ -84,31 +94,104 @@ export default function FieldList() { return totalAcres; }; - 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 fieldList = (fields: Field[]) => { + // return 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 fieldTable = (fields: Field[]) => { + // return ( + // + // + // + // + // Field Name + // Land Location + // Main Crop Type + // Acres ({calcTotalAcres(fields)} Total) + // Create New Plan + // + // + // {fieldList(fields)} + //
+ //
+ // ) + // } + +const columns: Column[] = [ + { + title: "View", + render: row => { + return ( + + + + ) + } + }, + { + title: "Field Name", + render: row => { + return {row.name()} + } + }, + { + title: "Current Crop", + render: row => { + return {row.crop()} + } + }, + { + title: "Acres", + render: row => { + return {row.acres()} + } + }, + { + title: "Actions", + render: row => { + return Field Actions Here + } + } +] + + const fieldTable = (fields: Field[]) => { + return ( + + columns={columns} + rows={fields} + setPage={()=>{}} + hidePagination + handleRowsPerPageChange={()=>{}} + page={0} + pageSize={10} + total={fields.length} + /> + ) + } return ( @@ -116,33 +199,23 @@ export default function FieldList() { value={value} onChange={handleChange} TabIndicatorProps={{ style: { background: "rgba(255,255,0,255)" } }}> - - {/* {!isMobile && } - {!isMobile && } */} + + + + - - - - - Field Name - Land Location - Main Crop Type - Acres ({calcTotalAcres()} Total) - Create New Plan - - - {listFieldsInfo} -
-
+ {fieldTable(fields)}
- {/* need to re-factor the harvest table file before restoring these functions */} - {/* - + + {fieldTable(adaptiveFields)} - - */} + {fieldTable(jdFields)} + + + {fieldTable(cnhFields)} + setOpenHarvestSettings(false)} diff --git a/src/field/Fieldminimap.tsx b/src/field/Fieldminimap.tsx new file mode 100644 index 0000000..489877b --- /dev/null +++ b/src/field/Fieldminimap.tsx @@ -0,0 +1,24 @@ +import { Box } from "@mui/material"; +import { Field } from "models"; +import { useRef } from "react"; +import Map, { MapRef } from "react-map-gl/mapbox"; +import 'mapbox-gl/dist/mapbox-gl.css'; + +interface Props { + field?: Field +} + +export default function FieldMinimap(props: Props) { + const { field } = props + const MAPBOX_TOKEN = import.meta.env.VITE_MAPBOX_ACCESS_TOKEN; + + + return ( + + + ) +} \ No newline at end of file