8000 Closes #9418: Admin UI: sort the realm localization texts alphabetically by leischt · Pull Request #9419 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div data-target="react-app.reactRoot">

Closes #9418: Admin UI: sort the realm localization texts alphabetically - #9419

Merged
ssilvert merged 1 commit into
keycloak:mainfrom
bosch-io:feature/9418-sort-relam-localization-keys-at-admin-ui
Jan 21, 2022
Merged

ssilvert merged 1 commit into
keycloak:mainfrom
bosch-io:feature/9418-sort-relam-localization-keys-at-admin-ui

Conversation

@leischt
@leischt leischt commented Jan 7, 2022
Copy link
Copy Markdown
Contributor

No description provided.

@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for contributing this change, @leischt. I tested it locally and it works fine. Great work!

Looking at the code formatting, I see that a blank line slipped in, probably unintended. Please remove that one blank line and then I'll approve this PR.

Please keep it as one commit and squash your new changes with the previous commit. Thanks!

Comment on lines 560 to 561
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A surplus blank line slipped in here, please remove it.

Suggested change
})
}
})
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ahus1 thanks for the review. Sorry this new line was indeed unintended. I updated the commit accordingly.

@leischt
leischt force-pushed the feature/9418-sort-relam-localization-keys-at-admin-ui branch from 727eb6a to 7652487 Compare January 13, 2022 07:14
@ahus1
ahus1 self-requested a review January 13, 2022 08:58
@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tested the changes locally and they worked for me. I also reviewed the code changes and they look good to me.

ahus1
ahus1 previously approved these changes Jan 13, 2022
@ahus1 ahus1 unassigned ahus1 and leischt Jan 13, 2022
@ahus1 ahus1 added area/account/ui Account Console — React UI for profile, sessions, security settings area/admin/ui Admin Console — React UI for server administration and removed area/account/ui Account Console — React UI for profile, sessions, security settings labels Jan 14, 2022
@jonkoops
jonkoops requested review from edewit and jonkoops January 14, 2022 16:21
@jonkoops jonkoops added the kind/enhancement Categorizes a PR related to an enhancement label Jan 14, 2022
edewit
edewit previously approved these changes Jan 17, 2022
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Arrow functions are ES2015 syntax, and to my knowledge we're not transpiling this code to older versions of JavaScript. Since we still have to support older browsers for the Admin UI I believe this could break the code there.

There is also no guarantee that the properties of an object will remain in insertion order when iterating on them. See the definition of an Object from ECMAScript Third Edition (pdf):

4.3.3 8000 Object

An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method.

This means that we would have to use some kind of type here like Array or Set to ensure that this remains in the correct order.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @jonkoops - thanks for looking at this and finding this I didn't. "+1" for the arrow functions.

As I was wondering why my manual test succeeded while the spec says this is no guaranteed behavior, I found this discussion on SO indicating that the specified behavior changed in ES6 (see answer by Mathias Bynens): https://stackoverflow.com/questions/5467129/sort-javascript-object-by-key

As you point out that this should run on older browsers as well, this must not be relied upon. A quick look at the docs didn't reveal a list of supported browsers to me. Could you please point me at more information about this topic? Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not believe we currently have the browser support publicly documented, but the worst case browser we have to support at the moment is Internet Explorer 11. For the rest of the browsers the target is pretty evergreen.

In the new Admin UI we're targeting only evergreen browsers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for your feedback.
I was not aware of these constraints and updated the PR to not use an Object anymore.
Since ng-repeat does not support Map iteration, I used an Array instead.
Further feedback is very welcome.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great! I think using an array here is an excellent option considering the browser constraints.

@leischt
leischt dismissed stale reviews from edewit and ahus1 via bdc9773 January 20, 2022 09:22
@leischt
leischt force-pushed the feature/9418-sort-relam-localization-keys-at-admin-ui branch from 7652487 to bdc9773 Compare January 20, 2022 09:22
Comment on lines 565 to 571
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could possibly also be a reduce() operation.

Suggested change
const array = [];
for(let i = 0; i < keys.length; i++){
if(typeof object[keys[i]] === 'string') {
array.push([keys[i], object[keys[i]]]);
}
}
return array;
return keys.reduce(function (result, key) {
return result.concat([[key, object[key]]]);
}, []);

@jonkoops jonkoops Jan 20, 2022 •
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I omitted the type check here (not sure if there are non-string values here), but if you'd want to include it you could do the following.

return keys.reduce(function (result, key) {
    const value = object[key];

    if (typeof value !== 'string') {
        return result;
    }

    return result.concat([[key, value]]);
}, []);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Calling sort() like this means that the values will be sorted by the UTF-16 code units order value of the string (see MDN documentation). This means that certain words might not be sorted in what the user would expect, for example if a string contains uppercase letter or special characters (e.g. réservé or RESERVE).

To mitigate this the String prototype has a localeCompare() method that can be used to compare strings in a manner that the user would expect them to be ranked in their respective locale.

Suggested change
const keys = Object.keys(object).sort();
const keys = Object.keys(object).sort(function (a, b) {
return a.localeCompare(b, 'en-US');
});

In this example en-US should be replaced with the current locale the user is using in the Admin UI.

@jonkoops
Copy link
Copy Markdown
Contributor

@ssilvert could you link #9418 to this PR? I do not have permission to do so.

@leischt
leischt force-pushed the feature/9418-sort-relam-localization-keys-at-admin-ui branch from bdc9773 to 6adfe15 Compare January 20, 2022 14:25
@leischt
leischt commented Jan 20, 2022
Copy link
Copy Markdown
Contributor Author

@jonkoops Thank you so much for the detailed feedback. I pushed a new version, which includes your suggestions.

@jonkoops jonkoops left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@jonkoops
jonkoops requested a review from edewit January 20, 2022 14:37
@jonkoops
jonkoops requested a review from ahus1 January 20, 2022 14:38
@ahus1 ahus1 left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed it and tested it locally with some German umlauts as keys. Works great - thanks a lot for everyone involved here!

@jonkoops
Copy link
Copy Markdown
Contributor

@ssilvert could you restart the build? It looks like there was random connection error that caused it to fail.

@ssilvert
Copy link
Copy Markdown
Contributor

@ssilvert could you restart the build? It looks like there was random connection error that caused it to fail.

I restarted yesterday and got the same error. Trying one more time.

@ahus1
ahus1 commented Jan 21, 2022
Copy link
Copy Markdown
Member

@ssilvert - Hynek notified me this morning that some PR builds failed due to this issue: #9697

I had to rebase my PR to make the build pass.

I wonder if there is another way for this PR to proceed.

@ssilvert
ssilvert merged commit e751626 into keycloak:main Jan 21, 2022
@ssilvert
Copy link
Copy Markdown
Contributor

The way to proceed is to just merge it. I don't see any real risk so I've done just that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/admin/ui Admin Console — React UI for server administration kind/enhancement Categorizes a PR related to an enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

0