added entries to the grain form for imperial fields, filling the imperial will calculate its metric counterpart
This commit is contained in:
parent
74e7371792
commit
3401cc7c15
4 changed files with 77 additions and 14 deletions
|
|
@ -18,7 +18,9 @@ export default function CustomGrainForm(props: Props) {
|
|||
const [constantB, setConstantB] = useState("0")
|
||||
const [constantC, setConstantC] = useState("0")
|
||||
const [kgPerBushel, setKgPerBushel] = useState("0")
|
||||
const [bushelsPerTonne, setBushelsPerTonne] = useState("0")
|
||||
const [bushelsPerTonne, setBushelsPerTonne] = useState("0")//this is metric
|
||||
const [lbPerBushel, setLbPerBushel] = useState("0")
|
||||
const [bushelsPerTon, setBushelsPerTon] = useState("0")//this is imperial
|
||||
const valid = useRef(false)
|
||||
|
||||
useEffect(()=>{
|
||||
|
|
@ -35,14 +37,25 @@ export default function CustomGrainForm(props: Props) {
|
|||
}
|
||||
},[grainSettings])
|
||||
|
||||
const validate = (name: string, group: string, constA: string, constB: string, constC: string, kgPerBushel: string, bushelsPerTonne: string) => {
|
||||
const validate = (
|
||||
name: string,
|
||||
group: string,
|
||||
constA: string,
|
||||
constB: string,
|
||||
constC: string,
|
||||
kgPerBushel: string,
|
||||
bushelsPerTonne: string,
|
||||
lbPerBushel: string,
|
||||
bushelsPerTon: string) => {
|
||||
if (name === "") return false
|
||||
if (group === "") return false
|
||||
if (isNaN(parseFloat(constA))) return false
|
||||
if (isNaN(parseFloat(constB))) return false
|
||||
if (isNaN(parseFloat(constC))) return false
|
||||
if (isNaN(parseFloat(kgPerBushel))) return false
|
||||
if (isNaN(parseFloat(lbPerBushel))) return false
|
||||
if (isNaN(parseFloat(bushelsPerTonne))) return false
|
||||
if (isNaN(parseFloat(bushelsPerTon))) return false
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +77,7 @@ export default function CustomGrainForm(props: Props) {
|
|||
setName(name)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
settings.name = name
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, bushelsPerTonne)
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, bushelsPerTonne, lbPerBushel, bushelsPerTon)
|
||||
settingsChanged(settings)
|
||||
}}/>
|
||||
<TextField
|
||||
|
|
@ -77,7 +90,7 @@ export default function CustomGrainForm(props: Props) {
|
|||
setGroup(group)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
settings.group = group
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, bushelsPerTonne)
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, bushelsPerTonne, lbPerBushel, bushelsPerTon)
|
||||
settingsChanged(settings)
|
||||
}}/>
|
||||
<TextField
|
||||
|
|
@ -91,7 +104,7 @@ export default function CustomGrainForm(props: Props) {
|
|||
setEquation(enumVal)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
settings.equation = enumVal
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, bushelsPerTonne)
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, bushelsPerTonne, lbPerBushel, bushelsPerTon)
|
||||
settingsChanged(settings)
|
||||
}}
|
||||
select>
|
||||
|
|
@ -121,7 +134,7 @@ export default function CustomGrainForm(props: Props) {
|
|||
onChange={(e) => {
|
||||
let val = e.target.value
|
||||
setConstantA(val)
|
||||
valid.current = validate(name, group, val, constantB, constantC, kgPerBushel, bushelsPerTonne)
|
||||
valid.current = validate(name, group, val, constantB, constantC, kgPerBushel, bushelsPerTonne, lbPerBushel, bushelsPerTon)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
if(!isNaN(parseFloat(val))){
|
||||
settings.a = parseFloat(val)
|
||||
|
|
@ -139,7 +152,7 @@ export default function CustomGrainForm(props: Props) {
|
|||
onChange={(e) => {
|
||||
let val = e.target.value
|
||||
setConstantB(val)
|
||||
valid.current = validate(name, group, constantA, val, constantC, kgPerBushel, bushelsPerTonne)
|
||||
valid.current = validate(name, group, constantA, val, constantC, kgPerBushel, bushelsPerTonne, lbPerBushel, bushelsPerTon)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
if(!isNaN(parseFloat(val))){
|
||||
settings.b = parseFloat(val)
|
||||
|
|
@ -157,7 +170,7 @@ export default function CustomGrainForm(props: Props) {
|
|||
onChange={(e) => {
|
||||
let val = e.target.value
|
||||
setConstantC(val)
|
||||
valid.current = validate(name, group, constantA, constantB, val, kgPerBushel, bushelsPerTonne)
|
||||
valid.current = validate(name, group, constantA, constantB, val, kgPerBushel, bushelsPerTonne, lbPerBushel, bushelsPerTon)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
if(!isNaN(parseFloat(val))){
|
||||
settings.c = parseFloat(val)
|
||||
|
|
@ -175,14 +188,40 @@ export default function CustomGrainForm(props: Props) {
|
|||
onChange={(e) => {
|
||||
let val = e.target.value
|
||||
setKgPerBushel(val)
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, val, bushelsPerTonne)
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, val, bushelsPerTonne, lbPerBushel, bushelsPerTon)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
if(!isNaN(parseFloat(val))){
|
||||
settings.kgPerBushel = parseFloat(val)
|
||||
//then calculate the kilograms to pounds and update it as well
|
||||
let newLb = Math.round((parseFloat(val)*2.205)*100)/100
|
||||
settings.poundsPerBushel = newLb
|
||||
setLbPerBushel(newLb.toString())
|
||||
}
|
||||
settingsChanged(settings)
|
||||
}}
|
||||
label="kg per Bushel"/>
|
||||
<TextField
|
||||
sx={{marginBottom: 2}}
|
||||
fullWidth
|
||||
type="number"
|
||||
value={lbPerBushel}
|
||||
error={isNaN(parseFloat(lbPerBushel))}
|
||||
helperText={isNaN(parseFloat(lbPerBushel)) ? "Must be a valid number" : ""}
|
||||
onChange={(e) => {
|
||||
let val = e.target.value
|
||||
setLbPerBushel(val)
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, bushelsPerTonne, val, bushelsPerTon)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
if(!isNaN(parseFloat(val))){
|
||||
settings.poundsPerBushel = parseFloat(val)
|
||||
//then calculate the pounds to kilograms and update it as well
|
||||
let newKg = Math.round((parseFloat(val)/2.205)*100)/100
|
||||
settings.kgPerBushel = newKg
|
||||
setKgPerBushel(newKg.toString())
|
||||
}
|
||||
settingsChanged(settings)
|
||||
}}
|
||||
label="lb per Bushel"/>
|
||||
<TextField
|
||||
sx={{marginBottom: 2}}
|
||||
fullWidth
|
||||
|
|
@ -193,14 +232,38 @@ export default function CustomGrainForm(props: Props) {
|
|||
onChange={(e) => {
|
||||
let val = e.target.value
|
||||
setBushelsPerTonne(val)
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, val)
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, val, lbPerBushel, bushelsPerTon)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
if(!isNaN(parseFloat(val))){
|
||||
settings.bushelsPerTonne = parseFloat(val)
|
||||
let newTon = Math.round((parseFloat(val)*1.102)*100)/100
|
||||
settings.bushelsPerTon = newTon
|
||||
setBushelsPerTon(newTon.toString())
|
||||
}
|
||||
settingsChanged(settings)
|
||||
}}
|
||||
label="Bushels per Tonne"/>
|
||||
<TextField
|
||||
sx={{marginBottom: 2}}
|
||||
fullWidth
|
||||
type="number"
|
||||
value={bushelsPerTon}
|
||||
error={isNaN(parseFloat(bushelsPerTon))}
|
||||
helperText={isNaN(parseFloat(bushelsPerTon)) ? "Must be a valid number" : ""}
|
||||
onChange={(e) => {
|
||||
let val = e.target.value
|
||||
setBushelsPerTon(val)
|
||||
valid.current = validate(name, group, constantA, constantB, constantC, kgPerBushel, bushelsPerTonne, lbPerBushel, val)
|
||||
let settings = cloneDeep(newGrainSettings)
|
||||
if(!isNaN(parseFloat(val))){
|
||||
settings.bushelsPerTon = parseFloat(val)
|
||||
let newTonne = Math.round((parseFloat(val)/1.102)*100)/100
|
||||
settings.bushelsPerTonne = newTonne
|
||||
setBushelsPerTonne(newTonne.toString())
|
||||
}
|
||||
settingsChanged(settings)
|
||||
}}
|
||||
label="Bushels per Ton"/>
|
||||
</React.Fragment>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ export function getWhitelabel(): WhiteLabel {
|
|||
return BXT_WHITE_LABEL;
|
||||
}
|
||||
if (window.location.origin.includes("localhost")) {
|
||||
return STAGING_WHITELABEL;
|
||||
return STREAMLINE_WHITE_LABEL;
|
||||
}
|
||||
if (window.location.origin.includes("staging") || import.meta.env.VITE_LOCAL_STAGING=='true') {
|
||||
return STAGING_WHITELABEL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue