settings: Clean schemas and types used for group settings.

Removed "type"/"Type" from schema and type names used
for group settings because we want to use "type"/"Type"
only for "type of a type" cases.

So, this commit renames-
- anonymous_group_type => anonymous_group_schema
- group_setting_type_schema => group_setting_value_schema
- GroupSettingType => GroupSettingValue

We also had duplicate definitions for GroupSettingType, in
state_data.ts and in settings_components.ts. So, removed it
from settings_components.ts.
This commit is contained in:
Sahil Batra 2024-10-11 16:36:58 +05:30 committed by Tim Abbott
parent 96abf2501a
commit 7db6de340f
5 changed files with 14 additions and 16 deletions

View File

@ -23,7 +23,7 @@ import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
import * as scroll_util from "./scroll_util";
import * as settings_config from "./settings_config";
import * as settings_data from "./settings_data";
import type {CustomProfileField, group_setting_type_schema} from "./state_data";
import type {CustomProfileField, GroupSettingValue} from "./state_data";
import {current_user, realm} from "./state_data";
import * as stream_data from "./stream_data";
import type {StreamSubscription} from "./sub_store";
@ -651,7 +651,7 @@ function get_input_type($input_elem: JQuery, input_type?: string): string {
export function get_input_element_value(
input_elem: HTMLElement,
input_type?: string,
): boolean | number | string | null | undefined | GroupSettingType {
): boolean | number | string | null | undefined | GroupSettingValue {
const $input_elem = $(input_elem);
input_type = get_input_type($input_elem, input_type);
let input_value;
@ -882,7 +882,7 @@ export function check_stream_settings_property_changed(
export function get_group_setting_widget_value(
pill_widget: GroupSettingPillContainer,
): GroupSettingType {
): GroupSettingValue {
const setting_pills = pill_widget.items();
const direct_subgroups: number[] = [];
const direct_members: number[] = [];
@ -1422,7 +1422,7 @@ export function get_group_setting_widget(setting_name: string): GroupSettingPill
export function set_group_setting_widget_value(
pill_widget: GroupSettingPillContainer,
property_value: GroupSettingType,
property_value: GroupSettingValue,
): void {
pill_widget.clear();
@ -1447,8 +1447,6 @@ export function set_group_setting_widget_value(
}
}
export type GroupSettingType = z.output<typeof group_setting_type_schema>;
type group_setting_name = "can_manage_group" | "can_join_group";
export function create_group_setting_widget({

View File

@ -4,7 +4,7 @@ import * as group_permission_settings from "./group_permission_settings";
import {page_params} from "./page_params";
import * as settings_config from "./settings_config";
import {current_user, realm} from "./state_data";
import type {GroupSettingType} from "./state_data";
import type {GroupSettingValue} from "./state_data";
import * as user_groups from "./user_groups";
import {user_settings} from "./user_settings";
@ -110,7 +110,7 @@ function user_has_permission(policy_value: number): boolean {
}
export function user_has_permission_for_group_setting(
setting_group_id: GroupSettingType,
setting_group_id: GroupSettingValue,
setting_name: string,
setting_type: "realm" | "stream" | "group",
): boolean {

View File

@ -283,7 +283,7 @@ export function set_up(settings_panel: SettingsPanel): void {
return;
}
// This filters out the GroupSettingType
// This filters out the GroupSettingValue
const setting_value = z
.union([z.string(), z.number(), z.boolean()])
.parse(settings_components.get_input_element_value(this));

View File

@ -127,14 +127,14 @@ export const server_emoji_schema = z.object({
export const realm_emoji_map_schema = z.record(server_emoji_schema);
export const anonymous_group_type = z.object({
export const anonymous_group_schema = z.object({
direct_subgroups: z.array(z.number()),
direct_members: z.array(z.number()),
});
export const group_setting_type_schema = z.union([z.number(), anonymous_group_type]);
export const group_setting_value_schema = z.union([z.number(), anonymous_group_schema]);
export type GroupSettingType = z.infer<typeof group_setting_type_schema>;
export type GroupSettingValue = z.infer<typeof group_setting_value_schema>;
export const user_group_schema = z.object({
description: z.string(),
@ -145,8 +145,8 @@ export const user_group_schema = z.object({
members: z.array(z.number()),
is_system_group: z.boolean(),
direct_subgroup_ids: z.array(z.number()),
can_join_group: group_setting_type_schema,
can_manage_group: group_setting_type_schema,
can_join_group: group_setting_value_schema,
can_manage_group: group_setting_value_schema,
can_mention_group: z.number(),
deactivated: z.boolean(),
});

View File

@ -9,7 +9,7 @@ import {page_params} from "./page_params";
import * as settings_config from "./settings_config";
import type {
GroupPermissionSetting,
GroupSettingType,
GroupSettingValue,
StateData,
user_group_schema,
} from "./state_data";
@ -325,7 +325,7 @@ export function is_user_in_group(user_group_id: number, user_id: number): boolea
}
export function is_user_in_setting_group(
setting_group: GroupSettingType,
setting_group: GroupSettingValue,
user_id: number,
): boolean {
if (typeof setting_group === "number") {