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
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -10953,7 +10953,7 @@
|
||||||
},
|
},
|
||||||
"node_modules/protobuf-ts": {
|
"node_modules/protobuf-ts": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#e926a3b73f9b6a1b4f9e6f520628a905f7f0fb25",
|
"resolved": "git+https://gitlab+deploy-token-50627:hv8mB4WkyvtjBpJKU1rN@gitlab.com/brandx/protobuf-ts.git#2aa771366c36285eac26e4e0143c1759380e2fc9",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"protobufjs": "^6.8.8"
|
"protobufjs": "^6.8.8"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,38 +16,45 @@ export default function CustomGrainForm(props: Props) {
|
||||||
const {grainSettings, onGrainSettingsChange} = props
|
const {grainSettings, onGrainSettingsChange} = props
|
||||||
const grainAPI = useGrainAPI()
|
const grainAPI = useGrainAPI()
|
||||||
const [{as}] = useGlobalState()
|
const [{as}] = useGlobalState()
|
||||||
const [name, setName] = useState("")
|
const [name, setName] = useState(grainSettings ? grainSettings.name : "")
|
||||||
const [group, setGroup] = useState("")
|
const [group, setGroup] = useState(grainSettings ? grainSettings.group : "")
|
||||||
const [equation, setEquation] = useState<pond.MoistureEquation>(pond.MoistureEquation.MOISTURE_EQUATION_NONE)
|
const [equation, setEquation] = useState<pond.MoistureEquation>(grainSettings ? grainSettings.equation : pond.MoistureEquation.MOISTURE_EQUATION_NONE)
|
||||||
const [constantA, setConstantA] = useState("0")
|
const [constantA, setConstantA] = useState(grainSettings ? grainSettings.a.toString() : "0")
|
||||||
const [constantB, setConstantB] = useState("0")
|
const [constantB, setConstantB] = useState(grainSettings ? grainSettings.b.toString() : "0")
|
||||||
const [constantC, setConstantC] = useState("0")
|
const [constantC, setConstantC] = useState(grainSettings ? grainSettings.c.toString() : "0")
|
||||||
const [kgPerBushel, setKgPerBushel] = useState("0")
|
const [kgPerBushel, setKgPerBushel] = useState(grainSettings ? grainSettings.kgPerBushel.toString() : "0")
|
||||||
const [bushelsPerTonne, setBushelsPerTonne] = useState("0")
|
const [bushelsPerTonne, setBushelsPerTonne] = useState(grainSettings ? grainSettings.bushelsPerTonne.toString() : "0")
|
||||||
const [newGrainSettings, setNewGrainSettings] = useState(pond.GrainSettings.create())
|
const [newGrainSettings, setNewGrainSettings] = useState(grainSettings ?? pond.GrainSettings.create())
|
||||||
const [grainMap, setGrainMap] = useState<Map<string, pond.GrainObject>>(new Map())
|
const [grainMap, setGrainMap] = useState<Map<string, pond.GrainObject>>(
|
||||||
const [grainOptions, setGrainOptions] = useState<Option[]>([])
|
grainSettings ?
|
||||||
const [isNew, setIsNew] = useState(false)
|
new Map([
|
||||||
const [selectedOption, setSelectedOption] = useState<Option | null>(null)
|
["Active", pond.GrainObject.create({key: "Active", name: grainSettings.name, settings: grainSettings})]
|
||||||
|
])
|
||||||
useEffect(()=>{
|
:
|
||||||
if(grainSettings){
|
new Map())
|
||||||
setNewGrainSettings(grainSettings)
|
const [grainOptions, setGrainOptions] = useState<Option[]>(
|
||||||
setName(grainSettings.name)
|
grainSettings ?
|
||||||
setGroup(grainSettings.group)
|
[
|
||||||
setEquation(grainSettings.equation)
|
{
|
||||||
setConstantA(grainSettings.a.toString())
|
label: grainSettings.name,
|
||||||
setConstantB(grainSettings.b.toString())
|
value: "Active",
|
||||||
setConstantC(grainSettings.c.toString())
|
group: "Active"
|
||||||
setKgPerBushel(grainSettings.kgPerBushel.toString())
|
|
||||||
setBushelsPerTonne(grainSettings.bushelsPerTonne.toString())
|
|
||||||
}
|
}
|
||||||
},[grainSettings])
|
]
|
||||||
|
:
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
const [isNew, setIsNew] = useState(false)
|
||||||
|
const [selectedOption, setSelectedOption] = useState<Option | null>(grainSettings ? {
|
||||||
|
label: grainSettings.name,
|
||||||
|
value: "Active",
|
||||||
|
group: "Active"
|
||||||
|
} : null)
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
grainAPI.listGrains(0, 0, "asc", "name", undefined, undefined, undefined, as).then(resp => {
|
grainAPI.listGrains(0, 0, "asc", "name", undefined, undefined, undefined, as).then(resp => {
|
||||||
let options: Option[] = []
|
let options: Option[] = grainOptions
|
||||||
let map: Map<string, pond.GrainObject> = new Map()
|
let map: Map<string, pond.GrainObject> = grainMap
|
||||||
if (resp.data.grains){
|
if (resp.data.grains){
|
||||||
resp.data.grains.forEach(grain => {
|
resp.data.grains.forEach(grain => {
|
||||||
map.set(grain.key, grain)
|
map.set(grain.key, grain)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue