refactor: replace deprecated getPressureUnit and getTemperatureUnit functions with user model methods
Updated the GateDeviceInteraction and MeasurementDescriber components to utilize user.pressureUnit() instead of the deprecated getPressureUnit() function. Added deprecation comments in units.ts for clarity on the transition to User.tempUnit() and User.pressureUnit().
This commit is contained in:
parent
ccabbbbd17
commit
a2944d7a60
3 changed files with 10 additions and 9 deletions
|
|
@ -7,8 +7,6 @@ import moment from "moment";
|
|||
import { pond, quack } from "protobuf-ts/pond";
|
||||
import { useGlobalState, useInteractionsAPI, useSnackbar } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { getPressureUnit } from "utils";
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
close: (canceled: boolean) => void;
|
||||
|
|
@ -186,9 +184,9 @@ export default function GateDeviceInteraction(props: Props) {
|
|||
//need to make sure the redthreshold is in pascals
|
||||
let thresholdPascals = 0
|
||||
if(!isNaN(parseFloat(redThreshold))){
|
||||
if(getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS){
|
||||
if(user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS){
|
||||
thresholdPascals = parseFloat(redThreshold)*1000
|
||||
}else if (getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER){
|
||||
}else if (user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER){
|
||||
thresholdPascals = parseFloat(redThreshold)*249
|
||||
}
|
||||
}
|
||||
|
|
@ -346,8 +344,8 @@ export default function GateDeviceInteraction(props: Props) {
|
|||
when the difference between the pressures falls within this range and vice versa:
|
||||
</Typography>
|
||||
<br />
|
||||
<Typography>Upper Limit: {getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (highDelta/249.089).toFixed(2) + " iwg" : highDelta/1000 + " kPa"}</Typography>
|
||||
<Typography>Lower Limit: {getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (lowDelta/249.089).toFixed(2) + " iwg" : lowDelta/1000 + " kPa"}</Typography>
|
||||
<Typography>Upper Limit: {user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (highDelta/249.089).toFixed(2) + " iwg" : highDelta/1000 + " kPa"}</Typography>
|
||||
<Typography>Lower Limit: {user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? (lowDelta/249.089).toFixed(2) + " iwg" : lowDelta/1000 + " kPa"}</Typography>
|
||||
<br />
|
||||
|
||||
<Typography>If you would like to have the interactions set in such a way that if the average pressure falls below a given value set the use off condition and set the value to use</Typography>
|
||||
|
|
@ -372,7 +370,7 @@ export default function GateDeviceInteraction(props: Props) {
|
|||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
{getPressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? "iwg" : "kPa"}
|
||||
{user.pressureUnit() === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER ? "iwg" : "kPa"}
|
||||
</InputAdornment>
|
||||
)
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import { pond } from "protobuf-ts/pond";
|
|||
import { quack } from "protobuf-ts/quack";
|
||||
import { getTextSecondary } from "theme/text";
|
||||
// import { getTextSecondary } from "theme";
|
||||
import { getDistanceUnit, getPressureUnit, roundTo } from "utils";
|
||||
import { getDistanceUnit, roundTo } from "utils";
|
||||
import { extract } from "utils/types";
|
||||
|
||||
interface Enumeration {
|
||||
|
|
@ -235,7 +235,8 @@ export class MeasurementDescriber {
|
|||
}
|
||||
break;
|
||||
case quack.MeasurementType.MEASUREMENT_TYPE_PRESSURE:
|
||||
let pressureUnit = getPressureUnit();
|
||||
let pressureUnit =
|
||||
user?.pressureUnit() ?? pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER;
|
||||
let isIWG = pressureUnit === pond.PressureUnit.PRESSURE_UNIT_INCHES_OF_WATER;
|
||||
this.details.label = "Pressure";
|
||||
this.details.unit = isIWG ? "iwg" : "kPa";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { pond } from "protobuf-ts/pond";
|
||||
|
||||
//function is deprecated, use User.tempUnit() instead
|
||||
export function getTemperatureUnit(): pond.TemperatureUnit {
|
||||
return localStorage.getItem("temperature") === "f"
|
||||
? pond.TemperatureUnit.TEMPERATURE_UNIT_FAHRENHEIT
|
||||
|
|
@ -31,6 +32,7 @@ export const fahrenheitToCelsius = (fahrenheit: number) => {
|
|||
return (fahrenheit - 32) * (5 / 9);
|
||||
};
|
||||
|
||||
// function is deprecated, use User.pressureUnit() instead
|
||||
export function getPressureUnit(): pond.PressureUnit {
|
||||
return localStorage.getItem("pressure") === "kpa"
|
||||
? pond.PressureUnit.PRESSURE_UNIT_KILOPASCALS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue