modified the matching check and confirmation dialog for when grain types dont match or at least one (destination or source) is using custom

This commit is contained in:
csawatzky 2025-12-18 13:24:20 -06:00
parent be8dc1d11f
commit 49aa08f232

View file

@ -125,6 +125,7 @@ export default function GrainTransaction(props: Props) {
.then(resp => { .then(resp => {
//let sourceOps: Option[] = sourceOptions //let sourceOps: Option[] = sourceOptions
let binOps: Option[] = []; let binOps: Option[] = [];
if(resp.data.bins){
resp.data.bins.forEach(bin => { resp.data.bins.forEach(bin => {
let b = Bin.create(bin); let b = Bin.create(bin);
if (mainObject.key() !== b.key()) { if (mainObject.key() !== b.key()) {
@ -133,9 +134,10 @@ export default function GrainTransaction(props: Props) {
value: b, value: b,
group: "Bins" group: "Bins"
}; };
(!restrictMatching || grainTypesMatch(op.value, mainObject)) && binOps.push(op); (!restrictMatching || grainTypesMatch(op.value, mainObject) || op.value.grainName() === mainObject.grainName()) && binOps.push(op);
} }
}); });
}
setBinOptions([...binOps]); setBinOptions([...binOps]);
}) })
.finally(() => { .finally(() => {
@ -151,6 +153,7 @@ export default function GrainTransaction(props: Props) {
.then(resp => { .then(resp => {
//let sourceOps: Option[] = sourceOptions //let sourceOps: Option[] = sourceOptions
let bagOps: Option[] = []; let bagOps: Option[] = [];
if(resp.data.grainBags){
resp.data.grainBags.forEach(bag => { resp.data.grainBags.forEach(bag => {
let b = GrainBag.create(bag); let b = GrainBag.create(bag);
if (mainObject.key() !== b.key()) { if (mainObject.key() !== b.key()) {
@ -159,9 +162,10 @@ export default function GrainTransaction(props: Props) {
value: b, value: b,
group: "Grain Bags" group: "Grain Bags"
}; };
(!restrictMatching || grainTypesMatch(op.value, mainObject)) && bagOps.push(op); (!restrictMatching || grainTypesMatch(op.value, mainObject) || op.value.grainName() === mainObject.grainName()) && bagOps.push(op);
} }
}); });
}
setBagOptions([...bagOps]); setBagOptions([...bagOps]);
}) })
.finally(() => { .finally(() => {
@ -184,7 +188,7 @@ export default function GrainTransaction(props: Props) {
value: f, value: f,
group: "Fields" group: "Fields"
}; };
(!restrictMatching || grainTypesMatch(op.value, mainObject)) && fieldOps.push(op); (!restrictMatching || grainTypesMatch(op.value, mainObject) || op.value.grainName() === mainObject.grainName()) && fieldOps.push(op);
}); });
setFieldOptions([...fieldOps]); setFieldOptions([...fieldOps]);
}) })
@ -356,13 +360,6 @@ export default function GrainTransaction(props: Props) {
if (source.grain() === destination.grain()) { if (source.grain() === destination.grain()) {
matching = true; matching = true;
} }
} else if (source.storage() === pond.BinStorage.BIN_STORAGE_UNSUPPORTED_GRAIN) {
if (
source.customType().toLowerCase() === destination.customType().toLowerCase() &&
source.bushelsPerTonne() === destination.bushelsPerTonne()
) {
matching = true;
}
} }
} }
return matching; return matching;
@ -373,7 +370,7 @@ export default function GrainTransaction(props: Props) {
if (grainTypesMatch(selectedSource.value, selectedDestination.value)) { if (grainTypesMatch(selectedSource.value, selectedDestination.value)) {
updateInventory(); updateInventory();
} else { } else {
//open dialog saying that the destinations grain type will change from this action //open dialog saying that the grain types do not match or because it is a custom type
setGrainChangeDialog(true); setGrainChangeDialog(true);
} }
} else { } else {
@ -381,6 +378,36 @@ export default function GrainTransaction(props: Props) {
} }
}; };
/**
* the function is used to determine what text to display to the user when the grain types dont match
* or when it sees any of the objects involved as having a custom grain type
* @param source the source of the grain
* @param destination the destination of the grain
* @returns the text describing the situation
*/
const confirmationText = () => {
if(selectedSource && selectedDestination){
let source = selectedSource?.value
let destination = selectedDestination?.value
//both are custom
if(source.storage() === pond.BinStorage.BIN_STORAGE_UNSUPPORTED_GRAIN && destination.storage() === pond.BinStorage.BIN_STORAGE_UNSUPPORTED_GRAIN){
return "Both source and destination are using custom grain types, they may not match. Would you like to continue with the transaction?"
}
//source is custom destination is not
if(source.storage() === pond.BinStorage.BIN_STORAGE_UNSUPPORTED_GRAIN){
return "The source is using a custom grain type and may not match the destination. Would you like to continue with the transaction?"
}
//destination is custom source is not
if(destination.storage() === pond.BinStorage.BIN_STORAGE_UNSUPPORTED_GRAIN){
return "The destination is using a custom grain type and may not match the source. Would you like to continue with the transaction?"
}
}
//neither are custom
return "The Grain types do not match. Are you sure you would like to perform this transaction?"
}
const grainChange = () => { const grainChange = () => {
return ( return (
<ResponsiveDialog <ResponsiveDialog
@ -389,7 +416,7 @@ export default function GrainTransaction(props: Props) {
setGrainChangeDialog(false); setGrainChangeDialog(false);
}}> }}>
<DialogContent> <DialogContent>
The grain type of the destination may change as a result of this action. {confirmationText()}
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button <Button