some updates to the form so that it uses the passed in grain to initialize it but not change when it changes
This commit is contained in:
parent
fb1434f817
commit
42110f8821
2 changed files with 36 additions and 29 deletions
|
|
@ -16,38 +16,45 @@ export default function CustomGrainForm(props: Props) {
|
|||
const {grainSettings, onGrainSettingsChange} = props
|
||||
const grainAPI = useGrainAPI()
|
||||
const [{as}] = useGlobalState()
|
||||
const [name, setName] = useState("")
|
||||
const [group, setGroup] = useState("")
|
||||
const [equation, setEquation] = useState<pond.MoistureEquation>(pond.MoistureEquation.MOISTURE_EQUATION_NONE)
|
||||
const [constantA, setConstantA] = useState("0")
|
||||
const [constantB, setConstantB] = useState("0")
|
||||
const [constantC, setConstantC] = useState("0")
|
||||
const [kgPerBushel, setKgPerBushel] = useState("0")
|
||||
const [bushelsPerTonne, setBushelsPerTonne] = useState("0")
|
||||
const [newGrainSettings, setNewGrainSettings] = useState(pond.GrainSettings.create())
|
||||
const [grainMap, setGrainMap] = useState<Map<string, pond.GrainObject>>(new Map())
|
||||
const [grainOptions, setGrainOptions] = useState<Option[]>([])
|
||||
const [name, setName] = useState(grainSettings ? grainSettings.name : "")
|
||||
const [group, setGroup] = useState(grainSettings ? grainSettings.group : "")
|
||||
const [equation, setEquation] = useState<pond.MoistureEquation>(grainSettings ? grainSettings.equation : pond.MoistureEquation.MOISTURE_EQUATION_NONE)
|
||||
const [constantA, setConstantA] = useState(grainSettings ? grainSettings.a.toString() : "0")
|
||||
const [constantB, setConstantB] = useState(grainSettings ? grainSettings.b.toString() : "0")
|
||||
const [constantC, setConstantC] = useState(grainSettings ? grainSettings.c.toString() : "0")
|
||||
const [kgPerBushel, setKgPerBushel] = useState(grainSettings ? grainSettings.kgPerBushel.toString() : "0")
|
||||
const [bushelsPerTonne, setBushelsPerTonne] = useState(grainSettings ? grainSettings.bushelsPerTonne.toString() : "0")
|
||||
const [newGrainSettings, setNewGrainSettings] = useState(grainSettings ?? pond.GrainSettings.create())
|
||||
const [grainMap, setGrainMap] = useState<Map<string, pond.GrainObject>>(
|
||||
grainSettings ?
|
||||
new Map([
|
||||
["Active", pond.GrainObject.create({key: "Active", name: grainSettings.name, settings: grainSettings})]
|
||||
])
|
||||
:
|
||||
new Map())
|
||||
const [grainOptions, setGrainOptions] = useState<Option[]>(
|
||||
grainSettings ?
|
||||
[
|
||||
{
|
||||
label: grainSettings.name,
|
||||
value: "Active",
|
||||
group: "Active"
|
||||
}
|
||||
]
|
||||
:
|
||||
[]
|
||||
)
|
||||
const [isNew, setIsNew] = useState(false)
|
||||
const [selectedOption, setSelectedOption] = useState<Option | null>(null)
|
||||
|
||||
useEffect(()=>{
|
||||
if(grainSettings){
|
||||
setNewGrainSettings(grainSettings)
|
||||
setName(grainSettings.name)
|
||||
setGroup(grainSettings.group)
|
||||
setEquation(grainSettings.equation)
|
||||
setConstantA(grainSettings.a.toString())
|
||||
setConstantB(grainSettings.b.toString())
|
||||
setConstantC(grainSettings.c.toString())
|
||||
setKgPerBushel(grainSettings.kgPerBushel.toString())
|
||||
setBushelsPerTonne(grainSettings.bushelsPerTonne.toString())
|
||||
}
|
||||
},[grainSettings])
|
||||
const [selectedOption, setSelectedOption] = useState<Option | null>(grainSettings ? {
|
||||
label: grainSettings.name,
|
||||
value: "Active",
|
||||
group: "Active"
|
||||
} : null)
|
||||
|
||||
useEffect(()=>{
|
||||
grainAPI.listGrains(0, 0, "asc", "name", undefined, undefined, undefined, as).then(resp => {
|
||||
let options: Option[] = []
|
||||
let map: Map<string, pond.GrainObject> = new Map()
|
||||
let options: Option[] = grainOptions
|
||||
let map: Map<string, pond.GrainObject> = grainMap
|
||||
if (resp.data.grains){
|
||||
resp.data.grains.forEach(grain => {
|
||||
map.set(grain.key, grain)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue