mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
web: Use Zod z.keyof() functionally.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
6dafa9f1c7
commit
9515d77b1e
@@ -111,14 +111,14 @@ export function get_realm_time_limits_in_minutes(property: MessageTimeLimitSetti
|
||||
|
||||
type RealmSetting = typeof realm;
|
||||
export const realm_setting_property_schema = z.union([
|
||||
realm_schema.keyof(),
|
||||
z.keyof(realm_schema),
|
||||
z.literal("realm_org_join_restrictions"),
|
||||
]);
|
||||
type RealmSettingProperty = z.infer<typeof realm_setting_property_schema>;
|
||||
|
||||
type RealmUserSettingDefaultType = typeof realm_user_settings_defaults;
|
||||
export const realm_user_settings_default_properties_schema = z.union([
|
||||
realm_default_settings_schema.keyof(),
|
||||
z.keyof(realm_default_settings_schema),
|
||||
z.literal("email_notification_batching_period_edit_minutes"),
|
||||
]);
|
||||
type RealmUserSettingDefaultProperties = z.infer<
|
||||
@@ -126,7 +126,7 @@ type RealmUserSettingDefaultProperties = z.infer<
|
||||
>;
|
||||
|
||||
export const stream_settings_property_schema = z.union([
|
||||
stream_subscription_schema.keyof(),
|
||||
z.keyof(stream_subscription_schema),
|
||||
z.enum(["stream_privacy", "is_default_stream"]),
|
||||
]);
|
||||
type StreamSettingProperty = z.infer<typeof stream_settings_property_schema>;
|
||||
@@ -1768,7 +1768,7 @@ export function create_realm_group_setting_widget({
|
||||
set_group_setting_widget_value(
|
||||
pill_widget,
|
||||
group_setting_value_schema.parse(
|
||||
realm[realm_schema.keyof().parse("realm_" + setting_name)],
|
||||
realm[z.keyof(realm_schema).parse("realm_" + setting_name)],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1895,7 +1895,7 @@ export function get_group_assigned_realm_permissions(group: UserGroup): {
|
||||
} of settings_config.realm_group_permission_settings) {
|
||||
const assigned_permission_objects = [];
|
||||
for (const setting_name of settings) {
|
||||
const setting_value = realm[realm_schema.keyof().parse("realm_" + setting_name)];
|
||||
const setting_value = realm[z.keyof(realm_schema).parse("realm_" + setting_name)];
|
||||
const can_edit = settings_config.owner_editable_realm_group_permission_settings.has(
|
||||
setting_name,
|
||||
)
|
||||
@@ -1936,7 +1936,7 @@ export function get_group_assigned_stream_permissions(group: UserGroup): {
|
||||
const can_edit_settings_with_content_access =
|
||||
stream_data.can_change_permissions_requiring_content_access(sub);
|
||||
for (const setting_name of settings_config.stream_group_permission_settings) {
|
||||
const setting_value = sub[stream_subscription_schema.keyof().parse(setting_name)];
|
||||
const setting_value = sub[z.keyof(stream_subscription_schema).parse(setting_name)];
|
||||
let can_edit_settings = can_edit_settings_with_metadata_access;
|
||||
if (
|
||||
settings_config.stream_group_permission_settings_requiring_content_access.includes(
|
||||
@@ -1983,7 +1983,7 @@ export function get_group_assigned_user_group_permissions(group: UserGroup): {
|
||||
const assigned_permission_objects = [];
|
||||
for (const setting_name of settings_config.group_permission_settings) {
|
||||
const setting_value =
|
||||
user_group[user_groups.user_group_schema.keyof().parse(setting_name)];
|
||||
user_group[z.keyof(user_groups.user_group_schema).parse(setting_name)];
|
||||
const assigned_permission_object =
|
||||
group_permission_settings.get_assigned_permission_object(
|
||||
group_setting_value_schema.parse(setting_value),
|
||||
|
||||
@@ -214,7 +214,7 @@ function stream_notification_setting_changed(target: HTMLInputElement, stream_id
|
||||
}
|
||||
|
||||
const $status_element = $(target).closest(".subsection-parent").find(".alert-notification");
|
||||
const setting = stream_specific_notification_settings_schema.keyof().parse(target.name);
|
||||
const setting = z.keyof(stream_specific_notification_settings_schema).parse(target.name);
|
||||
sub[setting] ??= user_settings[settings_config.generalize_stream_notification_setting[setting]];
|
||||
stream_settings_api.set_stream_property(
|
||||
sub,
|
||||
@@ -277,8 +277,8 @@ export function do_reset_stream_notifications(elem: HTMLElement, sub: StreamSubs
|
||||
)) {
|
||||
data.push({
|
||||
stream_id: sub.stream_id,
|
||||
property: stream_specific_notification_settings_schema
|
||||
.keyof()
|
||||
property: z
|
||||
.keyof(stream_specific_notification_settings_schema)
|
||||
.parse(per_stream_setting_name),
|
||||
value: user_settings[global_setting_name],
|
||||
});
|
||||
@@ -453,14 +453,14 @@ export function set_up(settings_panel: SettingsPanel): void {
|
||||
return;
|
||||
}
|
||||
|
||||
const setting_name = user_settings_schema.keyof().parse($input_elem.attr("name"));
|
||||
const setting_name = z.keyof(user_settings_schema).parse($input_elem.attr("name"));
|
||||
// This filters out the GroupSettingValue
|
||||
const setting_value = z
|
||||
.union([z.string(), z.number(), z.boolean()])
|
||||
.parse(settings_components.get_input_element_value(this));
|
||||
|
||||
if (
|
||||
pm_notification_settings_schema.keyof().safeParse(setting_name).success &&
|
||||
z.keyof(pm_notification_settings_schema).safeParse(setting_name).success &&
|
||||
!setting_value
|
||||
) {
|
||||
let enabled_pm_mention_notifications_count = 0;
|
||||
@@ -526,7 +526,7 @@ export function update_page(settings_panel: SettingsPanel): void {
|
||||
const $container = $(settings_panel.container);
|
||||
const settings_object = settings_panel.settings_object;
|
||||
for (const untyped_setting of settings_config.all_notification_settings) {
|
||||
const setting = user_settings_schema.keyof().parse(untyped_setting);
|
||||
const setting = z.keyof(user_settings_schema).parse(untyped_setting);
|
||||
switch (setting) {
|
||||
case "enable_offline_push_notifications": {
|
||||
if (!realm.realm_push_notifications_enabled) {
|
||||
|
||||
@@ -181,7 +181,7 @@ export function get_org_type_dropdown_options(): DefinedOrgTypeValues | AllOrgTy
|
||||
return settings_config.all_org_type_values;
|
||||
}
|
||||
|
||||
const simple_dropdown_properties = simple_dropdown_realm_settings_schema.keyof().options;
|
||||
const simple_dropdown_properties = z.keyof(simple_dropdown_realm_settings_schema).def.values;
|
||||
|
||||
function set_realm_waiting_period_setting(): void {
|
||||
const setting_value = realm.realm_waiting_period_threshold;
|
||||
@@ -442,8 +442,8 @@ export function populate_auth_methods(auth_method_to_bool_map: Record<string, bo
|
||||
}
|
||||
|
||||
function update_dependent_subsettings(property_name: string): void {
|
||||
const parsed_property_name = simple_dropdown_realm_settings_schema
|
||||
.keyof()
|
||||
const parsed_property_name = z
|
||||
.keyof(simple_dropdown_realm_settings_schema)
|
||||
.safeParse(property_name);
|
||||
if (parsed_property_name.success) {
|
||||
settings_components.set_property_dropdown_value(parsed_property_name.data);
|
||||
@@ -648,7 +648,7 @@ export function discard_stream_property_element_changes(
|
||||
export function discard_group_property_element_changes($elem: JQuery, group: UserGroup): void {
|
||||
const property_name = settings_components.extract_property_name($elem);
|
||||
const property_value = settings_components.get_group_property_value(
|
||||
user_groups.user_group_schema.keyof().parse(property_name),
|
||||
z.keyof(user_groups.user_group_schema).parse(property_name),
|
||||
group,
|
||||
);
|
||||
|
||||
@@ -1108,7 +1108,7 @@ export function set_up_dropdown_widget_for_realm_group_settings(): void {
|
||||
"realm",
|
||||
);
|
||||
set_up_dropdown_widget(
|
||||
realm_schema.keyof().parse("realm_" + setting_name),
|
||||
z.keyof(realm_schema).parse("realm_" + setting_name),
|
||||
get_setting_options,
|
||||
"group",
|
||||
);
|
||||
|
||||
@@ -37,9 +37,9 @@ export type SettingsPanel = {
|
||||
}
|
||||
);
|
||||
|
||||
export const user_settings_property_schema = user_settings_schema
|
||||
.omit({available_notification_sounds: true, emojiset_choices: true})
|
||||
.keyof();
|
||||
export const user_settings_property_schema = z.keyof(
|
||||
user_settings_schema.omit({available_notification_sounds: true, emojiset_choices: true}),
|
||||
);
|
||||
type UserSettingsProperty = z.output<typeof user_settings_property_schema>;
|
||||
|
||||
const meta = {
|
||||
|
||||
@@ -68,7 +68,7 @@ type StreamSetting = {
|
||||
is_checked: boolean;
|
||||
};
|
||||
|
||||
const settings_labels_schema = stream_properties_schema.omit({color: true}).keyof();
|
||||
const settings_labels_schema = z.keyof(stream_properties_schema.omit({color: true}));
|
||||
|
||||
const realm_labels_schema = z.enum([
|
||||
"push_notifications",
|
||||
@@ -76,7 +76,7 @@ const realm_labels_schema = z.enum([
|
||||
"message_content_in_email_notifications",
|
||||
]);
|
||||
|
||||
const notification_labels_schema = stream_specific_notification_settings_schema.keyof();
|
||||
const notification_labels_schema = z.keyof(stream_specific_notification_settings_schema);
|
||||
|
||||
export function setup_subscriptions_tab_hash(tab_key_value: string): void {
|
||||
if ($("#subscription_overlay .right").hasClass("show")) {
|
||||
|
||||
@@ -655,7 +655,7 @@ function populate_data_for_removing_realm_permissions(
|
||||
|
||||
const data: Record<string, string> = {};
|
||||
for (const setting_name of changed_setting_names) {
|
||||
const current_value = realm[realm_schema.keyof().parse("realm_" + setting_name)];
|
||||
const current_value = realm[z.keyof(realm_schema).parse("realm_" + setting_name)];
|
||||
data[setting_name] = get_request_data_for_removing_group_permission(
|
||||
group_setting_value_schema.parse(current_value),
|
||||
group.id,
|
||||
@@ -677,7 +677,8 @@ function populate_data_for_removing_stream_permissions(
|
||||
|
||||
const data: Record<string, string> = {};
|
||||
for (const setting_name of changed_setting_names) {
|
||||
const current_value = sub[sub_store.stream_subscription_schema.keyof().parse(setting_name)];
|
||||
const current_value =
|
||||
sub[z.keyof(sub_store.stream_subscription_schema).parse(setting_name)];
|
||||
data[setting_name] = get_request_data_for_removing_group_permission(
|
||||
group_setting_value_schema.parse(current_value),
|
||||
group.id,
|
||||
@@ -699,7 +700,8 @@ function populate_data_for_removing_user_group_permissions(
|
||||
|
||||
const data: Record<string, string> = {};
|
||||
for (const setting_name of changed_setting_names) {
|
||||
const current_value = user_group[user_groups.user_group_schema.keyof().parse(setting_name)];
|
||||
const current_value =
|
||||
user_group[z.keyof(user_groups.user_group_schema).parse(setting_name)];
|
||||
data[setting_name] = get_request_data_for_removing_group_permission(
|
||||
group_setting_value_schema.parse(current_value),
|
||||
group.id,
|
||||
|
||||
Reference in New Issue
Block a user