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

CB-5926 refactor: sort settings by translation #3088

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { computed, observable } from 'mobx';

import { useAutoLoad, useObservableRef } from '@cloudbeaver/core-blocks';
import { useAutoLoad, useObservableRef, useTranslate } from '@cloudbeaver/core-blocks';
import { useService } from '@cloudbeaver/core-di';
import { type ISettingDescription, ROOT_SETTINGS_GROUP, SettingsGroup, SettingsManagerService } from '@cloudbeaver/core-settings';

Expand All @@ -18,6 +18,7 @@ interface ISettings {

export function useSettings(accessor?: string[]): ISettings {
const settingsManagerService = useService(SettingsManagerService);
const translate = useTranslate();

useAutoLoad(useSettings, settingsManagerService.loaders);

Expand All @@ -27,7 +28,13 @@ export function useSettings(accessor?: string[]): ISettings {
const map = new Map();
const settings = this.settingsManagerService.activeSettings
.filter(setting => accessor?.some(value => setting.access.scope.includes(value)))
.sort((a, b) => a.name.localeCompare(b.name));
.sort((a, b) => {
if (a.type === b.type) {
return translate(a.name).localeCompare(translate(b.name));
} else {
return a.type - b.type;
}
});
Comment on lines -30 to +37
Copy link
Member

Choose a reason for hiding this comment

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

I'm really not sure that we need to group settings by type because it can look better in a small amount of settings but will be unreadable with many


for (const setting of settings) {
map.set(setting.group, [...(map.get(setting.group) || []), setting]);
Expand All @@ -47,7 +54,9 @@ export function useSettings(accessor?: string[]): ISettings {
return groups;
},
groupChildren(id: string) {
return (ROOT_SETTINGS_GROUP.get(id)?.subGroups || []).filter(group => this.groups.has(group)).sort((a, b) => a.name.localeCompare(b.name));
return (ROOT_SETTINGS_GROUP.get(id)?.subGroups || [])
.filter(group => this.groups.has(group))
.sort((a, b) => translate(a.name).localeCompare(translate(b.name)));
},
}),
{
Expand Down
Loading