making sure the bin uses the correct data when using libracart as an inventory control
This commit is contained in:
parent
e5300b19f4
commit
3e6185be8f
8 changed files with 115 additions and 69 deletions
|
|
@ -58,7 +58,7 @@ import { Bin } from "models";
|
|||
import moment from "moment";
|
||||
import { GetBinShapeDescribers } from "pbHelpers/Bin";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useBinAPI, useBinYardAPI, useGlobalState } from "providers";
|
||||
import { useBinAPI, useBinYardAPI, useGlobalState, useLibraCartProxyAPI } from "providers";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
// import { useHistory } from "react-router";
|
||||
import { getDistanceUnit, or, getTemperatureUnit, getGrainUnit } from "utils";
|
||||
|
|
@ -176,7 +176,7 @@ export default function BinSettings(props: Props) {
|
|||
const grainOptions = GrainOptions();
|
||||
const grainUseOptions = GetGrainUseOptions();
|
||||
const [inputCapacity, setInputCapacity] = useState<string>("");
|
||||
const [{ as }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
const [grainDiff, setGrainDiff] = useState(0);
|
||||
const [isCustomInventory, setIsCustomInventory] = useState<boolean>(false);
|
||||
const [grainUpdate, setGrainUpdate] = useState(false);
|
||||
|
|
@ -197,10 +197,13 @@ export default function BinSettings(props: Props) {
|
|||
const [inventoryControl, setInventoryControl] = useState<pond.BinInventoryControl>(
|
||||
pond.BinInventoryControl.BIN_INVENTORY_CONTROL_UNKNOWN
|
||||
);
|
||||
|
||||
const [storageType, setStorageType] = useState<pond.BinStorage>(
|
||||
pond.BinStorage.BIN_STORAGE_SUPPORTED_GRAIN
|
||||
);
|
||||
//libracart stuff
|
||||
const libracartAPI = useLibraCartProxyAPI()
|
||||
const [lcDestination, setlcDestination] = useState<Option | null>()
|
||||
const [lcDestinationOptions, setlcDestinationOptions] = useState<Option[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
|
|
@ -365,9 +368,34 @@ export default function BinSettings(props: Props) {
|
|||
}
|
||||
}, [binYardAPI, form.yardKey, userID, as, props.binYards]);
|
||||
|
||||
const loadLibraCartDestinations = useCallback(()=>{
|
||||
if(inventoryControl === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_LIBRACART){
|
||||
//load the destinations for the user/team they are viewing as
|
||||
let options: Option[] = []
|
||||
libracartAPI.listDestinations(0,0,undefined, as)
|
||||
.then(resp=>{
|
||||
console.log(resp)
|
||||
//set the options for the search select
|
||||
resp.data.destinations.forEach(d => {
|
||||
let newOp: Option = {
|
||||
label: d.name,
|
||||
value: d.id
|
||||
}
|
||||
options.push(newOp)
|
||||
//set the current option based on the key in the form
|
||||
if (d.id === form.libracartDestinationKey){
|
||||
setlcDestination(newOp)
|
||||
}
|
||||
})
|
||||
setlcDestinationOptions(options)
|
||||
}).catch(()=>{})
|
||||
}
|
||||
},[libracartAPI, inventoryControl, as, form.libracartDestinationKey])
|
||||
|
||||
useEffect(() => {
|
||||
loadBinYards();
|
||||
}, [loadBinYards]);
|
||||
loadLibraCartDestinations();
|
||||
}, [loadBinYards, loadLibraCartDestinations]);
|
||||
|
||||
useEffect(() => {
|
||||
if (bin?.settings.specs?.bushelCapacity) {
|
||||
|
|
@ -458,6 +486,7 @@ export default function BinSettings(props: Props) {
|
|||
form.inventory.inventoryControl = inventoryControl
|
||||
form.inventory.autoThreshold = autoFillThreshold
|
||||
}
|
||||
console.log(form)
|
||||
binAPI
|
||||
.updateBin(bin.key(), form, as)
|
||||
.then(response => {
|
||||
|
|
@ -713,6 +742,8 @@ export default function BinSettings(props: Props) {
|
|||
return "Auto (cable)"
|
||||
case pond.BinInventoryControl.BIN_INVENTORY_CONTROL_HYBRID_LIDAR:
|
||||
return "Hybrid (lidar)"
|
||||
case pond.BinInventoryControl.BIN_INVENTORY_CONTROL_LIBRACART:
|
||||
return "Auto (LibraCart)"
|
||||
default:
|
||||
return "Manual"
|
||||
}
|
||||
|
|
@ -860,7 +891,7 @@ export default function BinSettings(props: Props) {
|
|||
<FormControlLabel
|
||||
value={pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC}
|
||||
control={<Radio />}
|
||||
label={"Auto"}
|
||||
label={"Auto (Cable)"}
|
||||
/>
|
||||
<FormControlLabel
|
||||
value={pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC_LIDAR}
|
||||
|
|
@ -872,6 +903,13 @@ export default function BinSettings(props: Props) {
|
|||
control={<Radio />}
|
||||
label={"Hybrid (Lidar)"}
|
||||
/>
|
||||
{user.hasFeature("libra-cart") &&
|
||||
<FormControlLabel
|
||||
value={pond.BinInventoryControl.BIN_INVENTORY_CONTROL_LIBRACART}
|
||||
control={<Radio />}
|
||||
label={"Auto (LibraCart)"}
|
||||
/>
|
||||
}
|
||||
</RadioGroup>
|
||||
</AccordionDetails>
|
||||
{inventoryControl === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC &&
|
||||
|
|
@ -912,6 +950,25 @@ export default function BinSettings(props: Props) {
|
|||
/>
|
||||
</Box>
|
||||
}
|
||||
{inventoryControl === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_LIBRACART &&
|
||||
<Box width="100%" padding={2}>
|
||||
<SearchSelect
|
||||
label="LibraCart Destination"
|
||||
selected={lcDestination}
|
||||
changeSelection={option => {
|
||||
let newForm = form;
|
||||
newForm.libracartDestinationKey = option?.value;
|
||||
setForm(newForm);
|
||||
setlcDestination(option ? option : null);
|
||||
}}
|
||||
disabled={!canEdit}
|
||||
options={lcDestinationOptions}
|
||||
/>
|
||||
<Typography variant="caption">
|
||||
The linked bins inventory will be adjusted When the LibraCart Destination data is synced every 6 hours
|
||||
</Typography>
|
||||
</Box>
|
||||
}
|
||||
</Accordion>
|
||||
{empty ? (
|
||||
<Box marginTop={3} display="flex" flexDirection="column" alignItems="center">
|
||||
|
|
|
|||
|
|
@ -238,7 +238,8 @@ export default function BinLevelOverTime(props: Props) {
|
|||
let control = bin.inventoryControl()
|
||||
//for automatic lidar and cables get the data from measurements as an object measurement
|
||||
if(control === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC_LIDAR ||
|
||||
control === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC
|
||||
control === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC ||
|
||||
control === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_LIBRACART
|
||||
){
|
||||
//load the measurement data for the bar graph
|
||||
loadMeasurementData()
|
||||
|
|
@ -307,7 +308,8 @@ export default function BinLevelOverTime(props: Props) {
|
|||
{dataLoading ? <CircularProgress /> : inventoryChart()}
|
||||
{/* when using auto will need to make a new chart just for the bin modes since the auto inventory comes from another place */}
|
||||
{(bin.inventoryControl() === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC_LIDAR ||
|
||||
bin.inventoryControl() === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC) && autoBinModeChart()}
|
||||
bin.inventoryControl() === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_AUTOMATIC ||
|
||||
bin.inventoryControl() === pond.BinInventoryControl.BIN_INVENTORY_CONTROL_LIBRACART) && autoBinModeChart()}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue