had cursor replace uses of getDistanceUnit with using the distance unit in the users settings so that it no longer relies on local storage
This commit is contained in:
parent
c6bb7aa24a
commit
dc54f99abd
20 changed files with 273 additions and 199 deletions
|
|
@ -7,8 +7,6 @@ import { Bin, BinYard, Field, User } from "models";
|
|||
import { GrainBag } from "models/GrainBag";
|
||||
//import { ObjectHeater } from "models/ObjectHeater";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { getDistanceUnit } from "utils";
|
||||
|
||||
interface Sort {
|
||||
order: string; //what to send to the backend list to sort by
|
||||
numerical: boolean; //whether to use a numerical or text sort
|
||||
|
|
@ -62,7 +60,10 @@ const binColumns = (user?: User): Column<any>[] => {
|
|||
render: row => {
|
||||
let d = row.settings.specs?.heightCm;
|
||||
if (d) {
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
if (
|
||||
(user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET) ===
|
||||
pond.DistanceUnit.DISTANCE_UNIT_METERS
|
||||
) {
|
||||
return (d / 100).toFixed(2) + " m";
|
||||
} else {
|
||||
return (d / 30.48).toFixed(2) + " ft";
|
||||
|
|
@ -76,7 +77,10 @@ const binColumns = (user?: User): Column<any>[] => {
|
|||
render: row => {
|
||||
let d = row.settings.specs?.diameterCm;
|
||||
if (d) {
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
if (
|
||||
(user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET) ===
|
||||
pond.DistanceUnit.DISTANCE_UNIT_METERS
|
||||
) {
|
||||
return (d / 100).toFixed(2) + " m";
|
||||
} else {
|
||||
return (d / 30.48).toFixed(2) + " ft";
|
||||
|
|
@ -141,6 +145,89 @@ const binColumns = (user?: User): Column<any>[] => {
|
|||
] as Column<Bin>[];
|
||||
};
|
||||
|
||||
const grainBagColumns = (user?: User): Column<GrainBag>[] => {
|
||||
const distanceUnit =
|
||||
user?.distanceUnit() ?? pond.DistanceUnit.DISTANCE_UNIT_FEET;
|
||||
return [
|
||||
{
|
||||
title: "Name",
|
||||
render: row => {
|
||||
if (row.title) {
|
||||
return (<div>{row.title.toString()}</div>);
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Length",
|
||||
render: row => {
|
||||
if (row.settings.length) {
|
||||
if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
return row.settings.length.toFixed(2) + " m";
|
||||
} else {
|
||||
return (row.settings.length * 3.281).toFixed(2) + " ft";
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Diameter",
|
||||
render: row => {
|
||||
if (row.settings.diameter) {
|
||||
if (distanceUnit === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
return row.settings.diameter.toFixed(2) + " m";
|
||||
} else {
|
||||
return (row.settings.diameter * 3.281).toFixed(2) + " ft";
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Grain",
|
||||
render: row => {
|
||||
if (row.settings.supportedGrain) {
|
||||
return GrainDescriber(row.settings.supportedGrain).name;
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Custom Grain",
|
||||
render: row => {
|
||||
return row.settings.customGrain;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Grain Variant",
|
||||
render: row => {
|
||||
return row.settings.grainSubtype;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Capacity",
|
||||
render: row => {
|
||||
return row.settings.bushelCapacity + " bu";
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Bushels",
|
||||
render: row => {
|
||||
return row.settings.currentBushels + " bu";
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Fill Date",
|
||||
render: row => {
|
||||
return row.settings.fillDate;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Initial Moisture",
|
||||
render: row => {
|
||||
return row.settings.initialMoisture + "%";
|
||||
}
|
||||
}
|
||||
] as Column<GrainBag>[];
|
||||
};
|
||||
|
||||
export const ObjectExtensions: Map<pond.ObjectType, ObjectExtension> = new Map([
|
||||
[pond.ObjectType.OBJECT_TYPE_UNKNOWN, defaultObject],
|
||||
[
|
||||
|
|
@ -403,84 +490,8 @@ export const ObjectExtensions: Map<pond.ObjectType, ObjectExtension> = new Map([
|
|||
name: "Grainbag",
|
||||
inventoryGroup: "grain",
|
||||
isTransactionObject: true,
|
||||
tableColumns: [
|
||||
{
|
||||
title: "Name",
|
||||
render: row => {
|
||||
if (row.title) {
|
||||
return (<div>{row.title.toString()}</div>);
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Length",
|
||||
render: row => {
|
||||
if (row.settings.length) {
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
return row.settings.length.toFixed(2) + " m";
|
||||
} else {
|
||||
return (row.settings.length * 3.281).toFixed(2) + " ft";
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Diameter",
|
||||
render: row => {
|
||||
if (row.settings.diameter) {
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
return row.settings.diameter.toFixed(2) + " m";
|
||||
} else {
|
||||
return (row.settings.diameter * 3.281).toFixed(2) + " ft";
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Grain",
|
||||
render: row => {
|
||||
if (row.settings.supportedGrain) {
|
||||
return GrainDescriber(row.settings.supportedGrain).name;
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Custom Grain",
|
||||
render: row => {
|
||||
return row.settings.customGrain;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Grain Variant",
|
||||
render: row => {
|
||||
return row.settings.grainSubtype;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Capacity",
|
||||
render: row => {
|
||||
return row.settings.bushelCapacity + " bu";
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Bushels",
|
||||
render: row => {
|
||||
return row.settings.currentBushels + " bu";
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Fill Date",
|
||||
render: row => {
|
||||
return row.settings.fillDate;
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Initial Moisture",
|
||||
render: row => {
|
||||
return row.settings.initialMoisture + "%";
|
||||
}
|
||||
}
|
||||
] as Column<GrainBag>[],
|
||||
tableColumns: grainBagColumns(),
|
||||
getTableColumns: (user?: User) => grainBagColumns(user),
|
||||
tableSort: new Map([
|
||||
["Name", { order: "name", numerical: false }],
|
||||
["Length", { order: "length", numerical: true }],
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { GrainOptions } from "grain";
|
|||
import { pond } from "protobuf-ts/pond";
|
||||
import { useBinAPI, useGlobalState, useSnackbar } from "providers";
|
||||
import React, { useState } from "react";
|
||||
import { fahrenheitToCelsius, getDistanceUnit } from "utils";
|
||||
import { fahrenheitToCelsius } from "utils";
|
||||
|
||||
interface Props {
|
||||
selectedBins: pond.Bin[];
|
||||
|
|
@ -32,10 +32,10 @@ export default function BulkBinSettings(props: Props) {
|
|||
const [lowTemp, setLowTemp] = useState<number | undefined>();
|
||||
|
||||
const convertedDistance = (enteredDistance: number) => {
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_METERS) {
|
||||
return enteredDistance * 100;
|
||||
}
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
|
||||
if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
|
||||
return enteredDistance * 30.48;
|
||||
}
|
||||
return enteredDistance;
|
||||
|
|
@ -168,7 +168,7 @@ export default function BulkBinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
|
||||
{user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
|
||||
</InputAdornment>
|
||||
)
|
||||
}}
|
||||
|
|
@ -186,7 +186,7 @@ export default function BulkBinSettings(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getDistanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
|
||||
{user.distanceUnit() !== pond.DistanceUnit.DISTANCE_UNIT_FEET ? "m" : "ft"}
|
||||
</InputAdornment>
|
||||
)
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import { GrainBag } from "models/GrainBag";
|
|||
import { pond } from "protobuf-ts/pond";
|
||||
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
|
||||
import React, { useState } from "react";
|
||||
import { getDistanceUnit } from "utils";
|
||||
|
||||
interface Props {
|
||||
selectedBags: GrainBag[];
|
||||
|
|
@ -28,10 +27,10 @@ export default function BulkGrainBagSettings(props: Props) {
|
|||
const [bushels, setBushels] = useState<number | undefined>();
|
||||
const [fillDate, setFillDate] = useState<string | undefined>();
|
||||
const [initialMoisture, setInitialMoisture] = useState<number | undefined>();
|
||||
const [{as}] = useGlobalState();
|
||||
const [{ as, user }] = useGlobalState();
|
||||
|
||||
const convertedDistance = (enteredDistance: number) => {
|
||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
|
||||
if (user.distanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
|
||||
return enteredDistance / 3.281;
|
||||
}
|
||||
return enteredDistance;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue