settings_org: Convert module to typescript.

This commit is contained in:
evykassirer 2024-10-02 22:13:43 -07:00 committed by Tim Abbott
parent 39137e67f7
commit 269066e10a
9 changed files with 367 additions and 245 deletions

View File

@ -47,7 +47,7 @@ organization in Zulip). The following files are involved in the process:
- `web/templates/settings/organization_permissions_admin.hbs`: defines
the structure of the admin permissions page (checkboxes for each organization
permission setting).
- `web/src/settings_org.js`: handles organization setting form submission.
- `web/src/settings_org.ts`: handles organization setting form submission.
- `web/src/server_events_dispatch.js`: handles events coming from the server
(ex: pushing an organization change to other open browsers and updating
the application's state).
@ -556,7 +556,7 @@ Then add the new form control in `web/src/admin.js`.
```
The JavaScript code for organization settings and permissions can be found in
`web/src/settings_org.js`.
`web/src/settings_org.ts`.
In frontend, we have split the `property_types` into three objects:
@ -667,7 +667,7 @@ frontend tests: [node-based unit tests](../testing/testing-with-node.md) and
[Puppeteer end-to-end tests](../testing/testing-with-puppeteer.md).
At the minimum, if you created a new function to update UI in
`settings_org.js`, you will need to mock that function in
`settings_org.ts`, you will need to mock that function in
`web/tests/dispatch.test.js`. Add the name of the UI
function you created to the following object with `noop` as the value:

View File

@ -218,7 +218,7 @@ EXEMPT_FILES = make_set(
"web/src/settings_linkifiers.ts",
"web/src/settings_muted_users.ts",
"web/src/settings_notifications.ts",
"web/src/settings_org.js",
"web/src/settings_org.ts",
"web/src/settings_panel_menu.js",
"web/src/settings_playgrounds.ts",
"web/src/settings_preferences.ts",

View File

@ -47,7 +47,7 @@ type SettingOptionValue = {
description: string;
};
type SettingOptionValueWithKey = SettingOptionValue & {key: string};
export type SettingOptionValueWithKey = SettingOptionValue & {key: string};
export function get_sorted_options_list(
option_values_object: Record<string, SettingOptionValue>,
@ -80,10 +80,13 @@ export function get_sorted_options_list(
return options_list;
}
type MessageTimeLimitSetting =
| "realm_message_content_edit_limit_seconds"
| "realm_move_messages_between_streams_limit_seconds"
export type MessageMoveTimeLimitSetting =
| "realm_move_messages_within_stream_limit_seconds"
| "realm_move_messages_between_streams_limit_seconds";
export type MessageTimeLimitSetting =
| MessageMoveTimeLimitSetting
| "realm_message_content_edit_limit_seconds"
| "realm_message_content_delete_limit_seconds";
export function get_realm_time_limits_in_minutes(property: MessageTimeLimitSetting): string {
@ -239,7 +242,7 @@ export const simple_dropdown_realm_settings_schema = realm_schema.pick({
realm_edit_topic_policy: true,
realm_org_type: true,
});
type SimpleDropdownRealmSettings = z.infer<typeof simple_dropdown_realm_settings_schema>;
export type SimpleDropdownRealmSettings = z.infer<typeof simple_dropdown_realm_settings_schema>;
export function set_property_dropdown_value(
property_name: keyof SimpleDropdownRealmSettings,
@ -654,7 +657,7 @@ export function change_save_button_state($element: JQuery, state: string): void
});
}
function get_input_type($input_elem: JQuery, input_type?: string): string {
export function get_input_type($input_elem: JQuery, input_type?: string): string {
if (input_type !== undefined && ["boolean", "string", "number"].includes(input_type)) {
return input_type;
}

View File

@ -234,7 +234,7 @@ export function set_up(settings_panel: SettingsPanel): void {
if (for_realm_settings) {
// For the realm-level defaults page, we use the common
// settings_org.js handlers, so we can return early here.
// settings_org.ts handlers, so we can return early here.
return;
}

File diff suppressed because it is too large Load Diff

View File

@ -247,7 +247,7 @@ export function set_up(settings_panel: SettingsPanel): void {
if (for_realm_settings) {
// For the realm-level defaults page, we use the common
// settings_org.js handlers, so we can return early here.
// settings_org.ts handlers, so we can return early here.
return;
}

View File

@ -88,7 +88,7 @@ export function disable_sub_setting_onchange(
is_checked: boolean,
sub_setting_id: string,
disable_on_uncheck: boolean,
include_label: boolean,
include_label = false,
): void {
if ((is_checked && disable_on_uncheck) || (!is_checked && !disable_on_uncheck)) {
$(`#${CSS.escape(sub_setting_id)}`).prop("disabled", false);

View File

@ -22,7 +22,7 @@ export const user_group_schema = raw_user_group_schema.extend({
});
export type UserGroup = z.infer<typeof user_group_schema>;
type UserGroupForDropdownListWidget = {
export type UserGroupForDropdownListWidget = {
name: string;
unique_id: number;
};

View File

@ -5,7 +5,6 @@ const assert = require("node:assert/strict");
const {$t} = require("./lib/i18n");
const {mock_esm, set_global, zrequire} = require("./lib/namespace");
const {run_test, noop} = require("./lib/test");
const blueslip = require("./lib/zblueslip");
const $ = require("./lib/zjquery");
const realm_icon = mock_esm("../src/realm_icon");
@ -291,22 +290,12 @@ function test_sync_realm_settings({override}) {
$.create("save-button-controls-stub").addClass("hide"),
);
{
/* Test invalid settings property sync */
const $property_elem = $("#id_realm_invalid_settings_property");
$property_elem.attr("id", "id_realm_invalid_settings_property");
$property_elem.closest = () => $subsection_stub;
$property_elem.length = 1;
blueslip.expect("error", "Element refers to unknown property");
settings_org.sync_realm_settings("invalid_settings_property");
}
function test_common_policy(property_name) {
const $property_elem = $(`#id_realm_${CSS.escape(property_name)}`);
$property_elem.length = 1;
$property_elem.attr("id", `id_realm_${CSS.escape(property_name)}`);
$property_elem.closest = () => $subsection_stub;
$property_elem[0] = `#id_realm_${CSS.escape(property_name)}`;
/* Each policy is initialized to 'by_members' and then all the values are tested
in the following order - by_admins_only, by_moderators_only, by_full_members,
@ -338,6 +327,7 @@ function test_sync_realm_settings({override}) {
$property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
$property_dropdown_elem.attr("id", "id_realm_message_content_edit_limit_seconds");
$property_dropdown_elem.closest = () => $subsection_stub;
$property_dropdown_elem[0] = "#id_realm_message_content_edit_limit_seconds";
override(realm, "realm_message_content_edit_limit_seconds", 120);
@ -362,6 +352,7 @@ function test_sync_realm_settings({override}) {
$property_elem.length = 1;
$property_elem.attr("id", "id_realm_org_join_restrictions");
$property_elem.closest = () => $subsection_stub;
$property_elem[0] = "#id_realm_org_join_restrictions";
override(realm, "realm_emails_restricted_to_domains", true);
override(realm, "realm_disallow_disposable_email_addresses", false);
@ -529,6 +520,7 @@ test("set_up", ({override, override_rewire}) => {
name: "BigBlueButton",
},
});
override(realm, "realm_message_retention_days", null);
let upload_realm_logo_or_icon;
realm_icon.build_realm_icon_widget = (f) => {