Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to view one attribute in the sidebar #1254

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/common/attributes/useCommonUserAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default (t) => useMemo(() => ({
name: t('deviceSecondaryInfo'),
type: 'string',
},
deviceShowAttribute: {
name: t('deviceShowAttribute'),
type: 'string',
},
soundEvents: {
name: t('eventsSoundEvents'),
type: 'string',
Expand Down
12 changes: 12 additions & 0 deletions src/main/DeviceRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 PositionValue from '../common/components/PositionValue';

dayjs.extend(relativeTime);

Expand Down Expand Up @@ -62,6 +63,7 @@ const DeviceRow = ({ data, index, style }) => {

const devicePrimary = useAttributePreference('devicePrimary', 'name');
const deviceSecondary = useAttributePreference('deviceSecondary', '');
const deviceShowAttribute = useAttributePreference('deviceShowAttribute', '');

const secondaryText = () => {
let status;
Expand All @@ -74,6 +76,16 @@ const DeviceRow = ({ data, index, style }) => {
<>
{deviceSecondary && item[deviceSecondary] && `${item[deviceSecondary]} • `}
<span className={classes[getStatusColor(item.status)]}>{status}</span>
{position && position.hasOwnProperty(deviceShowAttribute) && (
<>
<span>{' • '}</span>
<PositionValue
position={position}
property={position.hasOwnProperty(deviceShowAttribute) ? deviceShowAttribute : null}
attribute={position.hasOwnProperty(deviceShowAttribute) ? null : deviceShowAttribute}
/>
</>
)}
</>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/resources/l10n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"calendarFriday": "Friday",
"calendarSaturday": "Saturday",
"attributeShowGeofences": "Show Geofences",
"deviceShowAttribute": "Show Attribute on SideBar",
"attributeSpeedLimit": "Speed Limit",
"attributeFuelDropThreshold": "Fuel Drop Threshold",
"attributeFuelIncreaseThreshold": "Fuel Increase Threshold",
Expand Down
17 changes: 17 additions & 0 deletions src/settings/PreferencesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,23 @@ const PreferencesPage = () => {
titleGetter={(it) => t(it.name)}
label={t('deviceSecondaryInfo')}
/>
<FormControl>
<InputLabel>{t('deviceShowAttribute')}</InputLabel>
<Select
label={t('deviceShowAttribute')}
value={attributes.deviceShowAttribute || ''}
onChange={(e) => {
setAttributes({ ...attributes, deviceShowAttribute: e.target.value });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easy way to clear this attribute when empty value is selected?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the existing code of the page, attributes are normally not removed when they are set with empty values; they are kept with an empty string or a default value. To maintain consistency, I manage empty values in a similar way:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think it's ok to keep as is. It's a bit different though because most of the other attributes are basically expected to have something. This one is basically optional.

}}
>
<MenuItem value="">{'\u00a0'}</MenuItem>
{Object.keys(positionAttributes).map((option) => (
<MenuItem key={option} value={option}>
{positionAttributes[option]?.name || option}
</MenuItem>
))}
</Select>
</FormControl>
</AccordionDetails>
</Accordion>
<Accordion>
Expand Down