diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2023-06-16 12:42:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-16 12:42:39 -0700 |
commit | ff518dfd78001c12ff0fc6641ac12594d2c0b6c1 (patch) | |
tree | 8fc85a02fc67ebd47bd63f4e7cfc3a76e7733fe1 /modern/src | |
parent | cd5b1513be814f27dcb6196779af772d9fdf656f (diff) | |
parent | 3abe32d568ec275d740d7656702a666879a16466 (diff) | |
download | trackermap-web-ff518dfd78001c12ff0fc6641ac12594d2c0b6c1.tar.gz trackermap-web-ff518dfd78001c12ff0fc6641ac12594d2c0b6c1.tar.bz2 trackermap-web-ff518dfd78001c12ff0fc6641ac12594d2c0b6c1.zip |
Merge pull request #1135 from jinzo/modern-formatter-improvements
Sync old Position Attribute formatters to Modern
Diffstat (limited to 'modern/src')
-rw-r--r-- | modern/src/common/components/PositionValue.js | 30 | ||||
-rw-r--r-- | modern/src/common/util/formatter.js | 4 |
2 files changed, 32 insertions, 2 deletions
diff --git a/modern/src/common/components/PositionValue.js b/modern/src/common/components/PositionValue.js index 132cd648..58841939 100644 --- a/modern/src/common/components/PositionValue.js +++ b/modern/src/common/components/PositionValue.js @@ -3,7 +3,21 @@ import { useSelector } from 'react-redux'; import { Link } from '@mui/material'; import { Link as RouterLink } from 'react-router-dom'; import { - formatAlarm, formatAltitude, formatBoolean, formatCoordinate, formatCourse, formatDistance, formatNumber, formatNumericHours, formatPercentage, formatSpeed, formatTime, formatTemperature, + formatAlarm, + formatAltitude, + formatBoolean, + formatCoordinate, + formatCourse, + formatDistance, + formatNumber, + formatNumericHours, + formatPercentage, + formatSpeed, + formatTime, + formatTemperature, + formatVoltage, + formatVolume, + formatConsumption, } from '../util/formatter'; import { useAttributePreference, usePreference } from '../util/preferences'; import { useTranslation } from './LocalizationProvider'; @@ -24,6 +38,7 @@ const PositionValue = ({ position, property, attribute }) => { const distanceUnit = useAttributePreference('distanceUnit'); const altitudeUnit = useAttributePreference('altitudeUnit'); const speedUnit = useAttributePreference('speedUnit'); + const volumeUnit = useAttributePreference('volumeUnit'); const coordinateFormat = usePreference('coordinateFormat'); const hours12 = usePreference('twelveHourFormat'); @@ -38,18 +53,29 @@ const PositionValue = ({ position, property, attribute }) => { case 'longitude': return formatCoordinate('longitude', value, coordinateFormat); case 'speed': - return formatSpeed(value, speedUnit, t); + case 'obdSpeed': + return value != null ? formatSpeed(value, speedUnit, t) : ''; case 'course': return formatCourse(value); case 'altitude': return formatAltitude(value, altitudeUnit, t); + case 'power': + case 'battery': + return formatVoltage(value, t); case 'batteryLevel': return value != null ? formatPercentage(value, t) : ''; + case 'volume': + return value != null ? formatVolume(value, volumeUnit, t) : ''; + case 'fuelConsumption': + return value != null ? formatConsumption(value, t) : ''; case 'coolantTemp': return formatTemperature(value); case 'alarm': return formatAlarm(value, t); case 'odometer': + case 'serviceOdometer': + case 'tripOdometer': + case 'obdOdometer': case 'distance': case 'totalDistance': return value != null ? formatDistance(value, distanceUnit, t) : ''; diff --git a/modern/src/common/util/formatter.js b/modern/src/common/util/formatter.js index 610b8dd0..0f7d2cc8 100644 --- a/modern/src/common/util/formatter.js +++ b/modern/src/common/util/formatter.js @@ -19,6 +19,10 @@ export const formatPercentage = (value) => `${value}%`; export const formatTemperature = (value) => `${value}°C`; +export const formatVoltage = (value, t) => `${value} ${t('sharedVoltAbbreviation')}`; + +export const formatConsumption = (value, t) => `${value} ${t('sharedLiterPerHourAbbreviation')}`; + export const formatTime = (value, format, hours12) => { if (value) { const m = moment(value); |