modified th api's for bin, contract and task to have as passed in as a prop and not get it ffrom the global state directly in the api
This commit is contained in:
parent
4bcac4e346
commit
e2f5eb0557
31 changed files with 155 additions and 507 deletions
|
|
@ -129,7 +129,7 @@ export default function BinComponentTypes(props: Props) {
|
|||
const [selectedComponentKey, setSelectedComponentKey] = useState("");
|
||||
const [selectedComponentSubtype, setSelectedComponentSubtype] = useState(0);
|
||||
const [selectedComponentTopNode, setSelectedComponentTopNode] = useState(0);
|
||||
const [{ user }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
|
||||
useEffect(() => {
|
||||
if (user.settings.temperatureUnit) {
|
||||
|
|
@ -152,7 +152,7 @@ export default function BinComponentTypes(props: Props) {
|
|||
p.type = type;
|
||||
p.node = topNode ?? 0;
|
||||
binAPI
|
||||
.updateComponentPreferences(bin, component, p)
|
||||
.updateComponentPreferences(bin, component, p, as)
|
||||
.then(() => {
|
||||
snackbar.success("Component preferences updated");
|
||||
preferences.set(component, p!);
|
||||
|
|
@ -163,7 +163,7 @@ export default function BinComponentTypes(props: Props) {
|
|||
});
|
||||
}
|
||||
},
|
||||
[bin, binAPI, preferences, setPreferences, snackbar]
|
||||
[bin, binAPI, preferences, setPreferences, snackbar, as]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import { Component, Device } from "models";
|
|||
import { pond } from "protobuf-ts/pond";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
import { useComponentAPI, useDeviceAPI, useSnackbar } from "hooks";
|
||||
import { useBinAPI } from "providers";
|
||||
import { useBinAPI, useGlobalState } from "providers";
|
||||
import { GetComponentIcon } from "pbHelpers/ComponentType";
|
||||
import { CheckBox as CheckBoxIcon, CheckBoxOutlineBlank, Remove } from "@mui/icons-material";
|
||||
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||
|
|
@ -85,6 +85,7 @@ interface Option {
|
|||
|
||||
export default function BinComponents(props: Props) {
|
||||
const { components, bin, setComponents, updateBinStatus, binGrain } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const classes = useStyles();
|
||||
const binAPI = useBinAPI();
|
||||
const theme = useTheme();
|
||||
|
|
@ -208,7 +209,7 @@ export default function BinComponents(props: Props) {
|
|||
// }, [selectedDevice, componentAPI, deviceComponents, snackbar]);
|
||||
|
||||
const removeComponent = (component: string) => {
|
||||
binAPI.removeComponent(bin, component).then(() => {
|
||||
binAPI.removeComponent(bin, component, as).then(() => {
|
||||
if (components && setComponents) {
|
||||
if (components.delete(component)) {
|
||||
let newComponents = new Map(components);
|
||||
|
|
@ -312,7 +313,7 @@ export default function BinComponents(props: Props) {
|
|||
type: preset,
|
||||
node: component.settings.grainFilledTo ?? 0
|
||||
});
|
||||
binAPI.addComponent(bin, device, component.key(), preferences).then(resp => {
|
||||
binAPI.addComponent(bin, device, component.key(), preferences, as).then(resp => {
|
||||
if (components && setComponents) {
|
||||
if (components.set(component.key(), component)) {
|
||||
let newComponents = new Map(components);
|
||||
|
|
@ -337,7 +338,7 @@ export default function BinComponents(props: Props) {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
binAPI.removeComponent(bin, component.key()).then(resp => {
|
||||
binAPI.removeComponent(bin, component.key(), as).then(resp => {
|
||||
if (components && setComponents) {
|
||||
if (components.delete(component.key())) {
|
||||
let newComponents = new Map(components);
|
||||
|
|
@ -350,7 +351,7 @@ export default function BinComponents(props: Props) {
|
|||
};
|
||||
|
||||
const removeAll = () => {
|
||||
binAPI.removeAllComponents(bin).then(resp => {
|
||||
binAPI.removeAllComponents(bin, as).then(resp => {
|
||||
if (setComponents) {
|
||||
setComponents(new Map());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ export default function BinsFansStatusTable(props: Props) {
|
|||
let bin = selectedBinRow.bin;
|
||||
bin.settings.fanId = newFanID;
|
||||
binAPI
|
||||
.updateBin(bin.key(), bin.settings)
|
||||
.updateBin(bin.key(), bin.settings, as)
|
||||
.then(resp => {
|
||||
//when an update succeeds update the table with the fan information
|
||||
//let dataMap = tableDataMap
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { createStyles, makeStyles } from "@mui/styles";
|
|||
//import { MatchParams } from "navigation/Routes";
|
||||
import DiffHistory, { ListResult, Record } from "common/DiffHistory";
|
||||
import { useSnackbar, useMobile } from "hooks";
|
||||
import { useBinAPI } from "providers";
|
||||
import { useBinAPI, useGlobalState } from "providers";
|
||||
import { Bin } from "models";
|
||||
import { TranslateKey, TranslateValue } from "pbHelpers/Bin";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
|
|
@ -37,6 +37,7 @@ export default function BinHistory(props: Props) {
|
|||
//const params = useParams<MatchParams>();
|
||||
const {binID, drawer} = props
|
||||
const classes = useStyles();
|
||||
const [{as}] = useGlobalState();
|
||||
const { openSnack } = useSnackbar();
|
||||
const binAPI = useBinAPI();
|
||||
//const binID = props.binID ?? params.binID;
|
||||
|
|
@ -46,14 +47,14 @@ export default function BinHistory(props: Props) {
|
|||
|
||||
useEffect(() => {
|
||||
binAPI
|
||||
.getBin(binID)
|
||||
.getBin(binID, as)
|
||||
.then((response: any) => {
|
||||
setBin(Bin.any(response.data));
|
||||
})
|
||||
.catch(err => {
|
||||
openSnack("There was a problem loading your bin");
|
||||
});
|
||||
}, [binAPI, binID, openSnack]);
|
||||
}, [binAPI, binID, openSnack, as]);
|
||||
|
||||
let list = (limit: number, offset: number): Promise<ListResult> => {
|
||||
return new Promise(resolve => {
|
||||
|
|
|
|||
|
|
@ -408,7 +408,7 @@ export default function BinSettings(props: Props) {
|
|||
if (form.inventory) form.inventory.inventoryControl = inventoryControl;
|
||||
|
||||
binAPI
|
||||
.addBin(form)
|
||||
.addBin(form, as)
|
||||
.then(resp => {
|
||||
openSnack("Successfully created bin");
|
||||
if (!coords) {
|
||||
|
|
@ -451,7 +451,7 @@ export default function BinSettings(props: Props) {
|
|||
form.autoGrainNode = autoTopNode;
|
||||
if (form.inventory) form.inventory.inventoryControl = inventoryControl;
|
||||
binAPI
|
||||
.updateBin(bin.key(), form)
|
||||
.updateBin(bin.key(), form, as)
|
||||
.then(response => {
|
||||
openSnack("Updated " + bin.name());
|
||||
close(true);
|
||||
|
|
@ -491,7 +491,7 @@ export default function BinSettings(props: Props) {
|
|||
const removeBin = () => {
|
||||
if (bin && bin.key()) {
|
||||
binAPI
|
||||
.removeBin(bin.key())
|
||||
.removeBin(bin.key(), as)
|
||||
.then(response => {
|
||||
openSnack(bin.name() + " was removed");
|
||||
navigate("/bins");
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import { GrainCable } from "models/GrainCable";
|
|||
import { UnitMeasurement } from "models/UnitMeasurement";
|
||||
import Co2Icon from "products/CommonIcons/co2Icon";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useBinAPI, useSnackbar } from "providers";
|
||||
import { useBinAPI, useGlobalState, useSnackbar } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { avg, getTemperatureUnit } from "utils";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
|
|
@ -133,6 +133,7 @@ export default function BinStorageConditions(props: Props) {
|
|||
const binAPI = useBinAPI();
|
||||
const { openSnack } = useSnackbar();
|
||||
const { bin, headspaceCO2, cables } = props;
|
||||
const [{as}] = useGlobalState()
|
||||
const [sliderTemps, setSliderTemps] = useState<number[]>([-40, 40]);
|
||||
//boolean that if a cable is missing its filled to display an icon or something to let the user know not all of the cables have their fill set
|
||||
const [missingTopNodeWarning, setMissingTopNodeWarning] = useState(false);
|
||||
|
|
@ -309,7 +310,7 @@ export default function BinStorageConditions(props: Props) {
|
|||
}
|
||||
|
||||
binAPI
|
||||
.updateBin(bin.key(), settings)
|
||||
.updateBin(bin.key(), settings, as)
|
||||
.then(_resp => {
|
||||
openSnack("Updated bin thresholds");
|
||||
})
|
||||
|
|
|
|||
|
|
@ -228,6 +228,7 @@ export default function BinVisualizer(props: Props) {
|
|||
binPresets
|
||||
} = props;
|
||||
const binAPI = useBinAPI();
|
||||
const [{as}] = useGlobalState()
|
||||
const isMobile = useMobile();
|
||||
const classes = useStyles();
|
||||
const theme = useTheme();
|
||||
|
|
@ -1814,7 +1815,7 @@ export default function BinVisualizer(props: Props) {
|
|||
setModeTime(moment(newTimestamp));
|
||||
status.lastModeChange = newTimestamp;
|
||||
binAPI
|
||||
.updateBinStatus(bin.key(), status)
|
||||
.updateBinStatus(bin.key(), status, as)
|
||||
.then(resp => {
|
||||
openSnack("Reset the storage time");
|
||||
})
|
||||
|
|
@ -2066,7 +2067,7 @@ export default function BinVisualizer(props: Props) {
|
|||
b.settings.outdoorHumidity = Number(outdoorHumidityInput);
|
||||
b.settings.mode = newPreset;
|
||||
|
||||
binAPI.updateBin(bin.key(), b.settings).then(resp => {
|
||||
binAPI.updateBin(bin.key(), b.settings, as).then(resp => {
|
||||
refresh();
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ export default function BinyardDisplay(props: Props) {
|
|||
}, []);
|
||||
|
||||
const duplicateBin = (bin: Bin) => {
|
||||
binAPI.addBin(bin.settings).then(resp => {
|
||||
binAPI.addBin(bin.settings, as).then(resp => {
|
||||
loadBins();
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { Button, Card, Grid2 as Grid, Slider } from "@mui/material";
|
|||
import { useMobile } from "hooks";
|
||||
import { GrainCable } from "models/GrainCable";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useBinAPI } from "providers";
|
||||
import { useBinAPI, useGlobalState } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
interface Props {
|
||||
|
|
@ -21,6 +21,7 @@ interface CableNodeInfo {
|
|||
|
||||
export default function CableTopNodeSummary(props: Props) {
|
||||
const { binKey, cables, componentDevMap } = props;
|
||||
const [{as}] = useGlobalState()
|
||||
const [cableNodes, setCableNodes] = useState<CableNodeInfo[]>([]);
|
||||
const isMobile = useMobile();
|
||||
const binAPI = useBinAPI();
|
||||
|
|
@ -53,7 +54,7 @@ export default function CableTopNodeSummary(props: Props) {
|
|||
);
|
||||
});
|
||||
binAPI
|
||||
.updateTopNodes(binKey, newTopNodes)
|
||||
.updateTopNodes(binKey, newTopNodes, as)
|
||||
.then(resp => {
|
||||
console.log("Set Top Nodes for cables, components and interactions have been updated");
|
||||
})
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export default function GrainNodeInteractions(props: Props) {
|
|||
const [nodeTemp, setNodeTemp] = useState<number>();
|
||||
const [nodeHum, setNodeHum] = useState<number>();
|
||||
const [nodeMoist, setNodeMoist] = useState<number | undefined>();
|
||||
const [{ user }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
const tempDescriber = describeMeasurement(quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE);
|
||||
const humDescriber = describeMeasurement(quack.MeasurementType.MEASUREMENT_TYPE_PERCENT);
|
||||
const moistureDescriber = describeMeasurement(quack.MeasurementType.MEASUREMENT_TYPE_GRAIN_EMC);
|
||||
|
|
@ -195,7 +195,7 @@ export default function GrainNodeInteractions(props: Props) {
|
|||
});
|
||||
//update the bins preferences to have the new top node for the cable
|
||||
binAPI
|
||||
.updateComponentPreferences(binKey, cable.key(), pref)
|
||||
.updateComponentPreferences(binKey, cable.key(), pref, as)
|
||||
.then(resp => {
|
||||
openSnack("Updated cables top node");
|
||||
updateComponentCallback(cable.key());
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ export default function BinGraphs(props: Props) {
|
|||
const [recentPlenumTrend, setRecentPlenumTrend] = useState<TrendPoint | undefined>();
|
||||
const [recentCableTrend, setRecentCableTrend] = useState<DataPoint | undefined>();
|
||||
const [recentWaterContent, setRecentWaterContent] = useState<WaterPoint | undefined>();
|
||||
const [{ user }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
const [measurementsLoading, setMeasurementsLoading] = useState(false);
|
||||
const isMobile = useMobile();
|
||||
const [{ showErrors }, dispatch] = useGlobalState();
|
||||
|
|
@ -142,7 +142,8 @@ export default function BinGraphs(props: Props) {
|
|||
bin.key(),
|
||||
startDate.toISOString(),
|
||||
endDate.toISOString(),
|
||||
showErrors
|
||||
showErrors,
|
||||
as
|
||||
)
|
||||
.then(resp => {
|
||||
resp.data.measurements.forEach((um: any) => {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import BarGraph, { BarData, RefArea } from "charts/BarGraph";
|
|||
import { Bin } from "models";
|
||||
import moment, { Moment } from "moment";
|
||||
import { pond, quack } from "protobuf-ts/pond";
|
||||
import { useBinAPI } from "providers";
|
||||
import { useBinAPI, useGlobalState } from "providers";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Legend } from "recharts";
|
||||
import { getGrainUnit } from "utils";
|
||||
|
|
@ -30,6 +30,7 @@ interface Props {
|
|||
export default function BinLevelOverTime(props: Props) {
|
||||
const { bin, fertilizerBin, colour, startDate, endDate, customHeight } = props;
|
||||
const binAPI = useBinAPI();
|
||||
const [{as}] = useGlobalState();
|
||||
const [showCable, setShowCable] = useState(false);
|
||||
const [manualData, setManualData] = useState<BarData[]>([]);
|
||||
const [cableData, setCableData] = useState<BarData[]>([]);
|
||||
|
|
@ -157,7 +158,7 @@ export default function BinLevelOverTime(props: Props) {
|
|||
if (cableDataLoading || bin.key() === "") return;
|
||||
setCableDataLoading(true);
|
||||
binAPI
|
||||
.listBinMeasurements(bin.key(), startDate, endDate, 500, 0, "asc")
|
||||
.listBinMeasurements(bin.key(), startDate, endDate, 500, 0, "asc", undefined, undefined, undefined, undefined, as)
|
||||
.then(resp => {
|
||||
resp.data.measurements.forEach(objMeasurement => {
|
||||
//set the bushel cable measurements
|
||||
|
|
@ -186,7 +187,7 @@ export default function BinLevelOverTime(props: Props) {
|
|||
.finally(() => {
|
||||
setCableDataLoading(false);
|
||||
});
|
||||
}, [binAPI, bin, startDate, endDate, fertilizerBin]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
}, [binAPI, bin, startDate, endDate, fertilizerBin, as]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const legend = () => {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export default function BinWaterLevel(props: Props) {
|
|||
bin.settings.inventory?.targetMoisture.toString() ?? ""
|
||||
);
|
||||
const [reference, setReference] = useState(0);
|
||||
// const [{ newStructure }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -70,7 +70,8 @@ export default function BinWaterLevel(props: Props) {
|
|||
plenumKey,
|
||||
cableKey,
|
||||
pressureKey,
|
||||
fanKey
|
||||
fanKey,
|
||||
as
|
||||
)
|
||||
.then(resp => {
|
||||
let lastData: DataPoint | undefined;
|
||||
|
|
@ -93,7 +94,7 @@ export default function BinWaterLevel(props: Props) {
|
|||
});
|
||||
}
|
||||
}
|
||||
}, [binAPI, range, bin, grainMoisture, plenumKey, cableKey, pressureKey]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
}, [binAPI, range, bin, grainMoisture, plenumKey, cableKey, pressureKey, as]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue