adding the harvest plan stuff to the field page

This commit is contained in:
csawatzky 2025-09-04 14:38:53 -06:00
parent 84885dc163
commit c69636482a
8 changed files with 146 additions and 36 deletions

View file

@ -7,16 +7,17 @@ import {
TextField
} from "@mui/material";
import ResponsiveDialog from "common/ResponsiveDialog";
import { Option } from "common/SearchSelect";
import { Field, HarvestPlan, Task } from "models";
import moment from "moment";
import { pond } from "protobuf-ts/pond";
import { useGlobalState, useHarvestPlanAPI, useTaskAPI } from "providers";
import { useFieldAPI, useGlobalState, useHarvestPlanAPI, useTaskAPI } from "providers";
import { useCallback, useEffect, useState } from "react";
interface Props {
open: boolean;
close: () => void;
fields: Field[];
fields?: Field[];
plan: HarvestPlan;
}
@ -29,6 +30,8 @@ export default function DuplicateHarvestPlan(props: Props) {
const harvestPlanAPI = useHarvestPlanAPI();
const taskAPI = useTaskAPI();
const [ready, setReady] = useState(false);
const [fieldOptions, setFieldOptions] = useState<Field[]>([])
const fieldAPI = useFieldAPI();
const loadTasks = useCallback(() => {
taskAPI.listTasks(50, 0, "asc", "start", plan.key(), undefined).then(resp => {
@ -41,9 +44,25 @@ export default function DuplicateHarvestPlan(props: Props) {
loadTasks();
}, [loadTasks]);
useEffect(()=>{
if(fields){
//if fields were passed in use those
setFieldOptions(fields)
}else{
//otherwise load them
fieldAPI.listFields(50, 0, "asc", "fieldName").then(resp => {
setFieldOptions(resp.data.fields.map(f => Field.create(f)))
}).catch(err => {
})
}
},[fields])
//this should load the fields here
const duplicate = () => {
let planSettings = HarvestPlan.clone(plan).settings;
planSettings.field = fields[newFieldIndex].key();
planSettings.field = fieldOptions[newFieldIndex].key();
planSettings.createDate = moment.now();
if (title !== "") {
planSettings.title = title;
@ -69,7 +88,7 @@ export default function DuplicateHarvestPlan(props: Props) {
value={newFieldIndex}
onChange={e => setNewFieldIndex(+e.target.value)}
color="primary">
{fields.map((option, i) => (
{fieldOptions.map((option, i) => (
<MenuItem key={option.key()} value={i}>
{option.fieldName()}
</MenuItem>
@ -98,8 +117,8 @@ export default function DuplicateHarvestPlan(props: Props) {
color="primary"
disabled={
!ready ||
(fields[newFieldIndex] &&
!fields[newFieldIndex].permissions.includes(pond.Permission.PERMISSION_WRITE))
(fieldOptions[newFieldIndex] &&
!fieldOptions[newFieldIndex].permissions.includes(pond.Permission.PERMISSION_WRITE))
}>
Duplicate
</Button>