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

Disable styles #970

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Disable styles #970

wants to merge 5 commits into from

Conversation

WGrobler
Copy link
Contributor

Update to PR #969

  • "Disable Styles" now uses a comma separated string
  • Added a common attributes for server only attributes
  • Added disableStyles to useCommonServerAttributes
  • Updated EN l10n to include attributeUiDisableStylesAttributes

modern/src/common/attributes/useCommonServerAttributes.js Outdated Show resolved Hide resolved
];
};

Object.keys(Styles).forEach((key) => {
Copy link
Member

Choose a reason for hiding this comment

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

I think the right think is to keep the array as is and just filter it. Otherwise the order is not guaranteed and you kind of have duplication of the ids.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting that we use an array for Styles (like it currently is in master) and delete styles from it if found in the disabledStyles list? Or do you suggest that we still loop over Styles and create activeStyles, but only changing Styles back to a list instead of an dict?

I thought about looping though the disabledStyles set, looking for the id in Styles and removing it if found. The problem is that it would require a search though the entire Styles array for every entry in disabledStyles. Since disabledStyles will always be smaller than Styles, I decided that it would be better to perform the "has key" check on the disabledStyles set.

Changing Styles back to an array and still using the same logic where its copied over to activeStyles if not in disabledStyles, should solve your order and id duplication concerns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing Styles back to an array and still using the same logic where its copied over to activeStyles if not in disabledStyles, should solve your order and id duplication concerns.

I made this change with d17e1b3

web/l10n/en.json Outdated Show resolved Hide resolved
Copy link
Member

@tananaev tananaev left a comment

Choose a reason for hiding this comment

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

Added some small comments, but overall looks pretty good.


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

@@ -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.

Comment on lines +191 to +196
for (let i = 0; i < Styles.length; i += 1) {
if (!disabledStyles.has(Styles[i].id)) {
activeStyles.push(Styles[i]);
}
}
return activeStyles;
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.

@@ -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.

@tananaev
Copy link
Member

Any plans to update this or should we close it for now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants