mirror of
https://github.com/zulip/zulip.git
synced 2025-11-22 15:31:20 +00:00
settings_components: Generate RealmSettingProperty type from a schema.
This will be useful for later when we'll need the schema for converting settings_org to typescript. This commit also renames RealmSettingProperty to more accurately reflect the type of a single property key.
This commit is contained in:
@@ -24,7 +24,7 @@ import * as scroll_util from "./scroll_util";
|
||||
import * as settings_config from "./settings_config";
|
||||
import * as settings_data from "./settings_data";
|
||||
import type {CustomProfileField, GroupSettingValue} from "./state_data";
|
||||
import {current_user, realm} from "./state_data";
|
||||
import {current_user, realm, realm_schema} from "./state_data";
|
||||
import * as stream_data from "./stream_data";
|
||||
import type {StreamSubscription} from "./sub_store";
|
||||
import type {GroupSettingPillContainer} from "./typeahead_helper";
|
||||
@@ -96,7 +96,11 @@ export function get_realm_time_limits_in_minutes(property: MessageTimeLimitSetti
|
||||
}
|
||||
|
||||
type RealmSetting = typeof realm;
|
||||
type RealmSettingProperties = keyof RealmSetting | "realm_org_join_restrictions";
|
||||
export const realm_setting_property_schema = z.union([
|
||||
realm_schema.keyof(),
|
||||
z.literal("realm_org_join_restrictions"),
|
||||
]);
|
||||
type RealmSettingProperty = z.infer<typeof realm_setting_property_schema>;
|
||||
|
||||
type RealmUserSettingDefaultType = typeof realm_user_settings_defaults;
|
||||
type RealmUserSettingDefaultProperties =
|
||||
@@ -108,7 +112,7 @@ type StreamSettingProperties = keyof StreamSubscription | "stream_privacy" | "is
|
||||
type valueof<T> = T[keyof T];
|
||||
|
||||
export function get_realm_settings_property_value(
|
||||
property_name: RealmSettingProperties,
|
||||
property_name: RealmSettingProperty,
|
||||
): valueof<RealmSetting> {
|
||||
if (property_name === "realm_org_join_restrictions") {
|
||||
if (realm.realm_emails_restricted_to_domains) {
|
||||
@@ -794,7 +798,7 @@ export function check_realm_settings_property_changed(elem: HTMLElement): boolea
|
||||
const $elem = $(elem);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const property_name = extract_property_name($elem) as RealmSettingProperties;
|
||||
const property_name = extract_property_name($elem) as RealmSettingProperty;
|
||||
const current_val = get_realm_settings_property_value(property_name);
|
||||
let proposed_val;
|
||||
switch (property_name) {
|
||||
@@ -1063,7 +1067,7 @@ export function populate_data_for_realm_settings_request(
|
||||
if (realm_group_settings_using_new_api_format.has(property_name)) {
|
||||
const old_value = get_realm_settings_property_value(
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
("realm_" + property_name) as RealmSettingProperties,
|
||||
("realm_" + property_name) as RealmSettingProperty,
|
||||
);
|
||||
data[property_name] = JSON.stringify({
|
||||
new: input_value,
|
||||
|
||||
@@ -250,7 +250,7 @@ const custom_profile_field_types_schema = z.object({
|
||||
export type CustomProfileFieldTypes = z.infer<typeof custom_profile_field_types_schema>;
|
||||
|
||||
// Sync this with zerver.lib.events.do_events_register.
|
||||
const realm_schema = z.object({
|
||||
export const realm_schema = z.object({
|
||||
custom_profile_fields: z.array(custom_profile_field_schema),
|
||||
custom_profile_field_types: custom_profile_field_types_schema,
|
||||
demo_organization_scheduled_deletion_date: z.optional(z.number()),
|
||||
|
||||
Reference in New Issue
Block a user