Skip to content
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
8 changes: 8 additions & 0 deletions modern/src/common/attributes/useServerAttributes .js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useMemo } from 'react';

export default (t) => useMemo(() => ({
disableMapLayers: {
name: t('attributeUiDisableMapLayers'),
type: 'string',
},
}), [t]);
13 changes: 11 additions & 2 deletions modern/src/map/core/useMapStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export default () => {
const hereKey = useAttributePreference('hereKey');
const mapboxAccessToken = useAttributePreference('mapboxAccessToken');
const customMapUrl = useSelector((state) => state.session.server?.mapUrl);
const disabledStyles = new Set((useSelector((state) => state.session.server.attributes?.disableMapLayers) || '').split(',') || []);
Copy link
Member

Choose a reason for hiding this comment

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

I would split it into two. First get disableMapLayers using selector and then a separate line to convert it into a set.

Also I think || [] should be unnecessary.

const activeStyles = [];

return [
const Styles = [
Copy link
Member

Choose a reason for hiding this comment

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

variables shouldn't start with a capital letter. it should be lower case

{
id: 'locationIqStreets',
title: t('mapLocationIqStreets'),
Expand Down Expand Up @@ -170,7 +172,7 @@ export default () => {
attribute: 'mapboxAccessToken',
},
{
id: 'mapboxSatelliteStreet',
id: 'mapboxSatellite',
title: t('mapMapboxSatellite'),
style: styleCustom(
[`https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=${mapboxAccessToken}`],
Expand All @@ -185,4 +187,11 @@ export default () => {
available: !!customMapUrl,
},
];

for (let i = 0; i < Styles.length; i += 1) {
if (!disabledStyles.has(Styles[i].id)) {
activeStyles.push(Styles[i]);
}
}
return activeStyles;
Comment on lines +191 to +196
Copy link
Member

Choose a reason for hiding this comment

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

Just use styles.filter(...) instead of doing this loop. And no need for a separate variable in that case.

};
4 changes: 3 additions & 1 deletion modern/src/settings/ServerPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import PageLayout from '../common/components/PageLayout';
import SettingsMenu from './components/SettingsMenu';
import useCommonDeviceAttributes from '../common/attributes/useCommonDeviceAttributes';
import useCommonUserAttributes from '../common/attributes/useCommonUserAttributes';
import useServerAttributes from '../common/attributes/useServerAttributes ';
import { useCatch } from '../reactHelper';

const useStyles = makeStyles((theme) => ({
Expand Down Expand Up @@ -58,6 +59,7 @@ const ServerPage = () => {
const t = useTranslation();

const commonUserAttributes = useCommonUserAttributes(t);
const commonServerAttributes = useServerAttributes(t);
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to rename the variable.

const commonDeviceAttributes = useCommonDeviceAttributes(t);

const original = useSelector((state) => state.session.server);
Expand Down Expand Up @@ -238,7 +240,7 @@ const ServerPage = () => {
<EditAttributesView
attributes={item.attributes}
setAttributes={(attributes) => setItem({ ...item, attributes })}
definitions={{ ...commonUserAttributes, ...commonDeviceAttributes }}
definitions={{ ...commonUserAttributes, ...commonDeviceAttributes, ...commonServerAttributes }}
/>
</AccordionDetails>
</Accordion>
Expand Down
1 change: 1 addition & 0 deletions web/l10n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"attributeUiDisableComputedAttributes": "UI: Disable Computed Attributes",
"attributeUiDisableCalendars": "UI: Disable Calendars",
"attributeUiDisableMaintenance": "UI: Disable Maintenance",
"attributeUiDisableMapLayers": "UI: Disable Map Layers",
"attributeUiHidePositionAttributes": "UI: Hide Position Attributes",
"attributeNotificationTokens": "Notification Tokens",
"errorTitle": "Error",
Expand Down