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:
parent
be8dc1d11f
commit
49aa08f232
1 changed files with 59 additions and 32 deletions
|
|
@ -125,17 +125,19 @@ export default function GrainTransaction(props: Props) {
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
//let sourceOps: Option[] = sourceOptions
|
//let sourceOps: Option[] = sourceOptions
|
||||||
let binOps: Option[] = [];
|
let binOps: Option[] = [];
|
||||||
resp.data.bins.forEach(bin => {
|
if(resp.data.bins){
|
||||||
let b = Bin.create(bin);
|
resp.data.bins.forEach(bin => {
|
||||||
if (mainObject.key() !== b.key()) {
|
let b = Bin.create(bin);
|
||||||
let op: Option = {
|
if (mainObject.key() !== b.key()) {
|
||||||
label: b.name(),
|
let op: Option = {
|
||||||
value: b,
|
label: b.name(),
|
||||||
group: "Bins"
|
value: b,
|
||||||
};
|
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,17 +153,19 @@ export default function GrainTransaction(props: Props) {
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
//let sourceOps: Option[] = sourceOptions
|
//let sourceOps: Option[] = sourceOptions
|
||||||
let bagOps: Option[] = [];
|
let bagOps: Option[] = [];
|
||||||
resp.data.grainBags.forEach(bag => {
|
if(resp.data.grainBags){
|
||||||
let b = GrainBag.create(bag);
|
resp.data.grainBags.forEach(bag => {
|
||||||
if (mainObject.key() !== b.key()) {
|
let b = GrainBag.create(bag);
|
||||||
let op: Option = {
|
if (mainObject.key() !== b.key()) {
|
||||||
label: b.name(),
|
let op: Option = {
|
||||||
value: b,
|
label: b.name(),
|
||||||
group: "Grain Bags"
|
value: b,
|
||||||
};
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue