diff --git a/web/src/settings_components.ts b/web/src/settings_components.ts index 9a7b24c270..aa3fcac620 100644 --- a/web/src/settings_components.ts +++ b/web/src/settings_components.ts @@ -34,15 +34,12 @@ type SettingOptionValueWithKey = SettingOptionValue & {key: string}; export function get_sorted_options_list( option_values_object: Record, ): SettingOptionValueWithKey[] { - const options_list: SettingOptionValueWithKey[] = Object.keys(option_values_object).map( - (key: string) => ({ - ...option_values_object[key], - key, - }), + const options_list: SettingOptionValueWithKey[] = Object.entries(option_values_object).map( + ([key, value]) => ({...value, key}), ); let comparator: (x: SettingOptionValueWithKey, y: SettingOptionValueWithKey) => number; - if (!options_list[0].order) { + if (options_list[0] !== undefined && !options_list[0].order) { comparator = (x, y) => { const key_x = x.key.toUpperCase(); const key_y = y.key.toUpperCase(); @@ -172,14 +169,14 @@ export function get_property_value( } export function realm_authentication_methods_to_boolean_dict(): Record { - const auth_method_to_bool: Record = {}; - for (const [auth_method_name, auth_method_info] of Object.entries( - realm.realm_authentication_methods, - )) { - auth_method_to_bool[auth_method_name] = auth_method_info.enabled; - } - - return sort_object_by_key(auth_method_to_bool); + return Object.fromEntries( + Object.entries(realm.realm_authentication_methods) + .sort() + .map(([auth_method_name, auth_method_info]) => [ + auth_method_name, + auth_method_info.enabled, + ]), + ); } export function extract_property_name($elem: JQuery, for_realm_default_settings?: boolean): string { @@ -476,17 +473,6 @@ function get_field_data_input_value($input_elem: JQuery): string | undefined { return JSON.stringify(proposed_value); } -export function sort_object_by_key(obj: Record): Record { - const keys = Object.keys(obj).sort(); - const new_obj: Record = {}; - - for (const key of keys) { - new_obj[key] = obj[key]; - } - - return new_obj; -} - export let default_code_language_widget: DropdownWidget | null = null; export let new_stream_announcements_stream_widget: DropdownWidget | null = null; export let signup_announcements_stream_widget: DropdownWidget | null = null;