Skip to content

Commit

Permalink
hide current selected unit from full sensor unit list #452
Browse files Browse the repository at this point in the history
  • Loading branch information
io53 committed Nov 12, 2024
1 parent a5cc7b7 commit e16c7da
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/UnitHelper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ const unitHelper = {

export const allUnits = unitHelper;

export function getUnitSettingFor(key) {
let map = { 'temperature': 'UNIT_TEMPERATURE', 'humidity': 'UNIT_HUMIDITY', 'pressure': 'UNIT_PRESSURE' }
const defaults = {
UNIT_HUMIDITY: "0",
UNIT_TEMPERATURE: "C",
UNIT_PRESSURE: "1",
}
let settings = localStorage.getItem("settings");
if (settings) {
settings = JSON.parse(settings)
if (settings[map[key]]) return settings[map[key]]
}
if (defaults[map[key]]) return defaults[map[key]]
return null
}

export function getUnitFor(key, setting) {
switch (key) {
case "temperature":
Expand Down
5 changes: 4 additions & 1 deletion src/components/SensorTypePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "@chakra-ui/react"
import { MdArrowDropDown } from "react-icons/md"
import { useTranslation } from 'react-i18next';
import { allUnits, getUnitHelper } from "../UnitHelper";
import { allUnits, getUnitHelper, getUnitSettingFor } from "../UnitHelper";

const types = ["temperature", "humidity", "pressure", "movementCounter", "battery", "accelerationX", "accelerationY", "accelerationZ", "rssi", "measurementSequenceNumber"]

Expand All @@ -36,6 +36,7 @@ export default function SensorTypePicker(props) {
}
}


let opts = Object.keys(allUnits).map(x => allUnits[x].graphable ? { "sensorType": x, unit: null } : null).filter(x => x !== null)
if (props.sensors) {
let sensorTypes = []
Expand All @@ -59,8 +60,10 @@ export default function SensorTypePicker(props) {
if (props.allUnits) {
for (let i = 0; i < opts.length; i++) {
let unitOpts = allUnits[opts[i]?.sensorType]?.units
let setting = getUnitSettingFor(opts[i]?.sensorType)
if (unitOpts) {
for (let j = 0; j < unitOpts.length; j++) {
if (setting === unitOpts[j].cloudStoreKey) continue
opts.splice(i + 1, 0, { "sensorType": opts[i].sensorType, "unit": unitOpts[j] });
i++;
}
Expand Down
24 changes: 21 additions & 3 deletions src/states/SensorCompare.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ExportMenu from "../components/ExportMenu";
import { uppercaseFirst } from "../TextHelper";
import { exportMuliSensorCSV, exportMuliSensorXLSX } from "../utils/export";
import ScreenSizeWrapper from "../components/ScreenSizeWrapper";
import { getUnitHelper } from "../UnitHelper";
import { getUnitHelper, getUnitSettingFor } from "../UnitHelper";

let data = {};
const descriptionStyle = { fontFamily: "mulish", fontSize: "14px", fontWeight: 400, maxWidth: "800px" }
Expand Down Expand Up @@ -47,11 +47,23 @@ function SensorCompare(props) {

const graphTitle = (mobile) => {
if (dataKey === "measurementSequenceNumber") return "";
let unit = getUnitHelper(dataKey).unit
let unit = ""
let label = "";
if (typeof(dataKey) === "object") {
label = dataKey.sensorType
if (dataKey.unit) {
unit = t(dataKey.unit.translationKey)
} else {
unit = getUnitHelper(label).unit
}
} else {
label = getUnitHelper(dataKey).label
unit = getUnitHelper(dataKey).unit
}

return <div style={{ marginLeft: 30 }}>
<span className="graphLengthText" style={{ fontSize: mobile ? "20px" : "24px" }}>
{t(getUnitHelper(dataKey).label)}
{t(label)}
</span>
{!mobile && <br />}
<span className="graphInfo" style={{ marginLeft: mobile ? 6 : undefined }}>
Expand All @@ -60,6 +72,12 @@ function SensorCompare(props) {
</div>
}
const graphCtrl = (isMobile) => {
let key = ""
if (typeof(dataKey) === "object") {
key = dataKey.sensorType
} else {
key = dataKey
}
return <>
<ZoomInfo />
<ExportMenu buttonText={uppercaseFirst(t("export"))} noPdf onClick={val => {
Expand Down

0 comments on commit e16c7da

Please sign in to comment.