Skip to content

Commit

Permalink
#401 show last measured value under alert sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
io53 committed Mar 24, 2024
1 parent 96488cd commit f50037d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/components/AlertItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, ListItem } from "@chakra-ui/layout";
import { Switch } from "@chakra-ui/switch";
import React, { Component, Suspense } from "react";
import { withTranslation } from 'react-i18next';
import { getAlertRange, getUnitHelper, localeNumber, round } from "../UnitHelper";
import { getAlertRange, getDisplayValue, getUnitHelper, localeNumber, round } from "../UnitHelper";
import EditableText from "./EditableText";
import InputDialog from "./InputDialog";
import RangeInputDialog from "./RangeInputDialog";
Expand Down Expand Up @@ -148,6 +148,9 @@ class AlertItem extends Component {
</span>
</div>
</>
const getUnit = () => {
return type !== "movement" && type !== "signal" && type !== "offline" ? ` ${type === "humidity" ? "%" : uh.unit}` : ""
}

return (
<ListItem key={type}>
Expand Down Expand Up @@ -176,9 +179,16 @@ class AlertItem extends Component {
}>
<AlertSlider type={type} value={alert || { ...getAlertRange(this.props.type) }} onChange={(v, final) => this.setAlert({ ...alert, min: v[0], max: v[1] }, type, alert ? alert.enabled : false, !final)} />
</Suspense>
{this.props.latestValue !== undefined &&
<div style={{ ...editItemMargins, display: "flex", justifyContent: "flex-end" }}>
<span style={{ ...this.props.detailedSubText, opacity: 0.5 }}>
{t("latest_measured_value").replace(/{(.*?)}/, getDisplayValue(this.props.type.toLowerCase(), this.props.latestValue))} {getUnit()}
</span>
</div>
}
</Box>
}
{this.props.showDelay && type !== "offline" &&
{this.props.showDelay && type !== "offline" &&
<Box mt={5}>
<ScreenSizeWrapper>
{delaySetting()}
Expand Down
6 changes: 4 additions & 2 deletions src/states/Sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,13 @@ class Sensor extends Component {
</Box>}
{["temperature", "humidity", "pressure", "signal", "movement", ...[["Free", "Basic"].includes(sensorSubscription) ? null : "offline"]].map(x => {
if (!x) return null
let dataKey = x === "movement" ? "movementCounter" : "signal" ? "rssi" : x;
if (this.getLatestReading()[dataKey] === undefined) return null;
let dataKey = x === "movement" ? "movementCounter" : x === "signal" ? "rssi" : x;
let latestValue = this.getLatestReading()[dataKey]
if (latestValue === undefined) return null;
var alert = this.getAlert(x)
let key = alert ? alert.min + "" + alert.max + "" + alert.enabled.toString() + "" + alert.description : x
return <AlertItem key={key} alerts={this.props.sensor.alerts} alert={alert} sensor={this.props.sensor}
latestValue={latestValue}
showDelay={sensorSubscription === "Business Starter"}
detailedTitle={detailedTitle}
detailedText={detailedText} detailedSubText={detailedSubText}
Expand Down

0 comments on commit f50037d

Please sign in to comment.