From 6301c6af3ef94ffe8f5b905a55c8b7f206d3d7a1 Mon Sep 17 00:00:00 2001 From: Manuel Santana Date: Wed, 3 Jul 2024 13:08:56 +0200 Subject: [PATCH 1/3] Add option to view speed in the sidebar --- src/common/attributes/useCommonUserAttributes.js | 4 ++++ src/main/DeviceRow.jsx | 6 ++++++ src/resources/l10n/en.json | 1 + src/resources/l10n/es.json | 1 + src/settings/PreferencesPage.jsx | 11 +++++++++++ 5 files changed, 23 insertions(+) diff --git a/src/common/attributes/useCommonUserAttributes.js b/src/common/attributes/useCommonUserAttributes.js index 43983fbc99..e0c8826c65 100644 --- a/src/common/attributes/useCommonUserAttributes.js +++ b/src/common/attributes/useCommonUserAttributes.js @@ -37,6 +37,10 @@ export default (t) => useMemo(() => ({ name: t('deviceSecondaryInfo'), type: 'string', }, + deviceShowSpeed: { + name: t('attributeShowSpeed'), + type: 'boolean', + }, soundEvents: { name: t('eventsSoundEvents'), type: 'string', diff --git a/src/main/DeviceRow.jsx b/src/main/DeviceRow.jsx index d9c1a18978..56d2fa6e5e 100644 --- a/src/main/DeviceRow.jsx +++ b/src/main/DeviceRow.jsx @@ -22,6 +22,7 @@ import { mapIconKey, mapIcons } from '../map/core/preloadImages'; import { useAdministrator } from '../common/util/permissions'; import EngineIcon from '../resources/images/data/engine.svg?react'; import { useAttributePreference } from '../common/util/preferences'; +import { speedFromKnots } from '../common/util/converter'; dayjs.extend(relativeTime); @@ -62,6 +63,10 @@ const DeviceRow = ({ data, index, style }) => { const devicePrimary = useAttributePreference('devicePrimary', 'name'); const deviceSecondary = useAttributePreference('deviceSecondary', ''); + const showSpeed = useAttributePreference('deviceShowSpeed', ''); + const speedUnit = useAttributePreference('speedUnit'); + + const deviceSpeed = position?.speed; const secondaryText = () => { let status; @@ -74,6 +79,7 @@ const DeviceRow = ({ data, index, style }) => { <> {deviceSecondary && item[deviceSecondary] && `${item[deviceSecondary]} • `} {status} + {showSpeed && deviceSpeed != null && {` • ${parseInt(speedFromKnots(deviceSpeed, speedUnit), 10)} ${speedUnit}`}} ); }; diff --git a/src/resources/l10n/en.json b/src/resources/l10n/en.json index f541b3a28e..dfdbb13785 100644 --- a/src/resources/l10n/en.json +++ b/src/resources/l10n/en.json @@ -121,6 +121,7 @@ "calendarFriday": "Friday", "calendarSaturday": "Saturday", "attributeShowGeofences": "Show Geofences", + "attributeShowSpeed": "Show Speed on SideBar", "attributeSpeedLimit": "Speed Limit", "attributeFuelDropThreshold": "Fuel Drop Threshold", "attributeFuelIncreaseThreshold": "Fuel Increase Threshold", diff --git a/src/resources/l10n/es.json b/src/resources/l10n/es.json index 8c9ce74947..7cb8d6c494 100644 --- a/src/resources/l10n/es.json +++ b/src/resources/l10n/es.json @@ -121,6 +121,7 @@ "calendarFriday": "Viernes", "calendarSaturday": "Sábado", "attributeShowGeofences": "Mostrar Geo-Zonas", + "attributeShowSpeed": "Mostrar Velocidad en la Barra Lateral", "attributeSpeedLimit": "Límite de velocidad", "attributeFuelDropThreshold": "Umbral de pérdida de combustible", "attributeFuelIncreaseThreshold": "Umbral del subida de combustible", diff --git a/src/settings/PreferencesPage.jsx b/src/settings/PreferencesPage.jsx index a8e3de884b..1d1e138d98 100644 --- a/src/settings/PreferencesPage.jsx +++ b/src/settings/PreferencesPage.jsx @@ -258,6 +258,17 @@ const PreferencesPage = () => { titleGetter={(it) => t(it.name)} label={t('deviceSecondaryInfo')} /> + + setAttributes({ ...attributes, deviceShowSpeed: e.target.checked })} + /> + )} + label={t('attributeShowSpeed')} + /> + From 0f08b889e777f6de777bc3c7b1a5972530fc3ace Mon Sep 17 00:00:00 2001 From: Manuel Santana Date: Thu, 4 Jul 2024 11:45:09 +0200 Subject: [PATCH 2/3] Add option to view one attribute in the sidebar --- .../attributes/useCommonUserAttributes.js | 6 ++-- src/main/DeviceRow.jsx | 18 +++++++---- src/resources/l10n/en.json | 2 +- src/resources/l10n/es.json | 2 +- src/settings/PreferencesPage.jsx | 30 ++++++++++++------- 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/common/attributes/useCommonUserAttributes.js b/src/common/attributes/useCommonUserAttributes.js index e0c8826c65..d321aa8a3d 100644 --- a/src/common/attributes/useCommonUserAttributes.js +++ b/src/common/attributes/useCommonUserAttributes.js @@ -37,9 +37,9 @@ export default (t) => useMemo(() => ({ name: t('deviceSecondaryInfo'), type: 'string', }, - deviceShowSpeed: { - name: t('attributeShowSpeed'), - type: 'boolean', + deviceAttribute: { + name: t('deviceShowAttribute'), + type: 'string', }, soundEvents: { name: t('eventsSoundEvents'), diff --git a/src/main/DeviceRow.jsx b/src/main/DeviceRow.jsx index 56d2fa6e5e..579ae85029 100644 --- a/src/main/DeviceRow.jsx +++ b/src/main/DeviceRow.jsx @@ -22,7 +22,7 @@ import { mapIconKey, mapIcons } from '../map/core/preloadImages'; import { useAdministrator } from '../common/util/permissions'; import EngineIcon from '../resources/images/data/engine.svg?react'; import { useAttributePreference } from '../common/util/preferences'; -import { speedFromKnots } from '../common/util/converter'; +import PositionValue from '../common/components/PositionValue'; dayjs.extend(relativeTime); @@ -63,10 +63,7 @@ const DeviceRow = ({ data, index, style }) => { const devicePrimary = useAttributePreference('devicePrimary', 'name'); const deviceSecondary = useAttributePreference('deviceSecondary', ''); - const showSpeed = useAttributePreference('deviceShowSpeed', ''); - const speedUnit = useAttributePreference('speedUnit'); - - const deviceSpeed = position?.speed; + const deviceAttributeToShow = useAttributePreference('deviceShowAttribute', ''); const secondaryText = () => { let status; @@ -79,7 +76,16 @@ const DeviceRow = ({ data, index, style }) => { <> {deviceSecondary && item[deviceSecondary] && `${item[deviceSecondary]} • `} {status} - {showSpeed && deviceSpeed != null && {` • ${parseInt(speedFromKnots(deviceSpeed, speedUnit), 10)} ${speedUnit}`}} + {position && position.hasOwnProperty(deviceAttributeToShow) && ( + <> + {' • '} + + + )} ); }; diff --git a/src/resources/l10n/en.json b/src/resources/l10n/en.json index dfdbb13785..4cc96a0184 100644 --- a/src/resources/l10n/en.json +++ b/src/resources/l10n/en.json @@ -121,7 +121,7 @@ "calendarFriday": "Friday", "calendarSaturday": "Saturday", "attributeShowGeofences": "Show Geofences", - "attributeShowSpeed": "Show Speed on SideBar", + "deviceShowAttribute": "Show Attribute on SideBar", "attributeSpeedLimit": "Speed Limit", "attributeFuelDropThreshold": "Fuel Drop Threshold", "attributeFuelIncreaseThreshold": "Fuel Increase Threshold", diff --git a/src/resources/l10n/es.json b/src/resources/l10n/es.json index 7cb8d6c494..8e11ee5332 100644 --- a/src/resources/l10n/es.json +++ b/src/resources/l10n/es.json @@ -121,7 +121,7 @@ "calendarFriday": "Viernes", "calendarSaturday": "Sábado", "attributeShowGeofences": "Mostrar Geo-Zonas", - "attributeShowSpeed": "Mostrar Velocidad en la Barra Lateral", + "deviceShowAttribute": "Mostrar atributo en la Barra Lateral", "attributeSpeedLimit": "Límite de velocidad", "attributeFuelDropThreshold": "Umbral de pérdida de combustible", "attributeFuelIncreaseThreshold": "Umbral del subida de combustible", diff --git a/src/settings/PreferencesPage.jsx b/src/settings/PreferencesPage.jsx index 1d1e138d98..d9fe5aa7fb 100644 --- a/src/settings/PreferencesPage.jsx +++ b/src/settings/PreferencesPage.jsx @@ -258,17 +258,25 @@ const PreferencesPage = () => { titleGetter={(it) => t(it.name)} label={t('deviceSecondaryInfo')} /> - - setAttributes({ ...attributes, deviceShowSpeed: e.target.checked })} - /> - )} - label={t('attributeShowSpeed')} - /> - + + {t('deviceShowAttribute')} + + From aba0ef909f5c19ffc1d94ce798e04a293d4d387e Mon Sep 17 00:00:00 2001 From: Manuel Santana Date: Fri, 5 Jul 2024 13:07:18 +0200 Subject: [PATCH 3/3] Unify variable naming, remove unnecessary Typography element and Es translation --- src/common/attributes/useCommonUserAttributes.js | 2 +- src/main/DeviceRow.jsx | 8 ++++---- src/resources/l10n/es.json | 1 - src/settings/PreferencesPage.jsx | 4 +--- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/common/attributes/useCommonUserAttributes.js b/src/common/attributes/useCommonUserAttributes.js index d321aa8a3d..f01f16f675 100644 --- a/src/common/attributes/useCommonUserAttributes.js +++ b/src/common/attributes/useCommonUserAttributes.js @@ -37,7 +37,7 @@ export default (t) => useMemo(() => ({ name: t('deviceSecondaryInfo'), type: 'string', }, - deviceAttribute: { + deviceShowAttribute: { name: t('deviceShowAttribute'), type: 'string', }, diff --git a/src/main/DeviceRow.jsx b/src/main/DeviceRow.jsx index 579ae85029..c90a8c35cc 100644 --- a/src/main/DeviceRow.jsx +++ b/src/main/DeviceRow.jsx @@ -63,7 +63,7 @@ const DeviceRow = ({ data, index, style }) => { const devicePrimary = useAttributePreference('devicePrimary', 'name'); const deviceSecondary = useAttributePreference('deviceSecondary', ''); - const deviceAttributeToShow = useAttributePreference('deviceShowAttribute', ''); + const deviceShowAttribute = useAttributePreference('deviceShowAttribute', ''); const secondaryText = () => { let status; @@ -76,13 +76,13 @@ const DeviceRow = ({ data, index, style }) => { <> {deviceSecondary && item[deviceSecondary] && `${item[deviceSecondary]} • `} {status} - {position && position.hasOwnProperty(deviceAttributeToShow) && ( + {position && position.hasOwnProperty(deviceShowAttribute) && ( <> {' • '} )} diff --git a/src/resources/l10n/es.json b/src/resources/l10n/es.json index 8e11ee5332..8c9ce74947 100644 --- a/src/resources/l10n/es.json +++ b/src/resources/l10n/es.json @@ -121,7 +121,6 @@ "calendarFriday": "Viernes", "calendarSaturday": "Sábado", "attributeShowGeofences": "Mostrar Geo-Zonas", - "deviceShowAttribute": "Mostrar atributo en la Barra Lateral", "attributeSpeedLimit": "Límite de velocidad", "attributeFuelDropThreshold": "Umbral de pérdida de combustible", "attributeFuelIncreaseThreshold": "Umbral del subida de combustible", diff --git a/src/settings/PreferencesPage.jsx b/src/settings/PreferencesPage.jsx index d9fe5aa7fb..50e3d6f65a 100644 --- a/src/settings/PreferencesPage.jsx +++ b/src/settings/PreferencesPage.jsx @@ -270,9 +270,7 @@ const PreferencesPage = () => { {'\u00a0'} {Object.keys(positionAttributes).map((option) => ( - - {positionAttributes[option]?.name || option} - + {positionAttributes[option]?.name || option} ))}