mirror of
https://github.com/zulip/zulip.git
synced 2025-11-08 07:52:19 +00:00
dropdown_widget: Fix Option typing.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
32e8575713
commit
c81ef4d409
@@ -27,11 +27,6 @@ import * as user_groups from "./user_groups.ts";
|
|||||||
import * as util from "./util.ts";
|
import * as util from "./util.ts";
|
||||||
|
|
||||||
type MessageType = "stream" | "private";
|
type MessageType = "stream" | "private";
|
||||||
type DirectMessagesOption = {
|
|
||||||
is_direct_message: boolean;
|
|
||||||
unique_id: string | number;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
let compose_select_recipient_dropdown_widget: DropdownWidget;
|
let compose_select_recipient_dropdown_widget: DropdownWidget;
|
||||||
|
|
||||||
@@ -272,8 +267,7 @@ function item_click_callback(event: JQuery.ClickEvent, dropdown: tippy.Instance)
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_options_for_recipient_widget(): Option[] {
|
function get_options_for_recipient_widget(): Option[] {
|
||||||
const options: (Option | DirectMessagesOption)[] =
|
const options: Option[] = stream_data.get_options_for_dropdown_widget();
|
||||||
stream_data.get_options_for_dropdown_widget();
|
|
||||||
|
|
||||||
const direct_messages_option = {
|
const direct_messages_option = {
|
||||||
is_direct_message: true,
|
is_direct_message: true,
|
||||||
|
|||||||
@@ -31,8 +31,13 @@ export enum DataTypes {
|
|||||||
export type Option = {
|
export type Option = {
|
||||||
unique_id: number | string;
|
unique_id: number | string;
|
||||||
name: string;
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
is_direct_message?: boolean;
|
||||||
is_setting_disabled?: boolean;
|
is_setting_disabled?: boolean;
|
||||||
stream?: StreamSubscription;
|
stream?: StreamSubscription;
|
||||||
|
bold_current_selection?: boolean;
|
||||||
|
has_delete_icon?: boolean;
|
||||||
|
has_edit_icon?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DropdownWidgetOptions = {
|
export type DropdownWidgetOptions = {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {z} from "zod";
|
import {z} from "zod";
|
||||||
|
|
||||||
import * as blueslip from "./blueslip.ts";
|
import * as blueslip from "./blueslip.ts";
|
||||||
|
import type * as dropdown_widget from "./dropdown_widget.ts";
|
||||||
import {$t} from "./i18n.ts";
|
import {$t} from "./i18n.ts";
|
||||||
import * as settings_config from "./settings_config.ts";
|
import * as settings_config from "./settings_config.ts";
|
||||||
import {realm} from "./state_data.ts";
|
import {realm} from "./state_data.ts";
|
||||||
@@ -110,15 +111,10 @@ export function get_realm_user_groups_for_setting(
|
|||||||
return [...system_user_groups, ...user_groups_excluding_system_groups];
|
return [...system_user_groups, ...user_groups_excluding_system_groups];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UserGroupForDropdownListWidget = {
|
|
||||||
name: string;
|
|
||||||
unique_id: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function get_realm_user_groups_for_dropdown_list_widget(
|
export function get_realm_user_groups_for_dropdown_list_widget(
|
||||||
setting_name: string,
|
setting_name: string,
|
||||||
setting_type: "realm" | "stream" | "group",
|
setting_type: "realm" | "stream" | "group",
|
||||||
): UserGroupForDropdownListWidget[] {
|
): dropdown_widget.Option[] {
|
||||||
const allowed_setting_groups = get_realm_user_groups_for_setting(setting_name, setting_type);
|
const allowed_setting_groups = get_realm_user_groups_for_setting(setting_name, setting_type);
|
||||||
|
|
||||||
return allowed_setting_groups.map((group) => {
|
return allowed_setting_groups.map((group) => {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import {csrf_token} from "./csrf.ts";
|
|||||||
import * as dialog_widget from "./dialog_widget.ts";
|
import * as dialog_widget from "./dialog_widget.ts";
|
||||||
import * as dropdown_widget from "./dropdown_widget.ts";
|
import * as dropdown_widget from "./dropdown_widget.ts";
|
||||||
import * as group_permission_settings from "./group_permission_settings.ts";
|
import * as group_permission_settings from "./group_permission_settings.ts";
|
||||||
import type {UserGroupForDropdownListWidget} from "./group_permission_settings.ts";
|
|
||||||
import {$t, $t_html, get_language_name} from "./i18n.ts";
|
import {$t, $t_html, get_language_name} from "./i18n.ts";
|
||||||
import * as information_density from "./information_density.ts";
|
import * as information_density from "./information_density.ts";
|
||||||
import * as keydown_util from "./keydown_util.ts";
|
import * as keydown_util from "./keydown_util.ts";
|
||||||
@@ -1113,7 +1112,7 @@ export function set_up_dropdown_widget_for_realm_group_settings(): void {
|
|||||||
// we use pills UI.
|
// we use pills UI.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const get_setting_options = (): UserGroupForDropdownListWidget[] =>
|
const get_setting_options = (): dropdown_widget.Option[] =>
|
||||||
group_permission_settings.get_realm_user_groups_for_dropdown_list_widget(
|
group_permission_settings.get_realm_user_groups_for_dropdown_list_widget(
|
||||||
setting_name,
|
setting_name,
|
||||||
"realm",
|
"realm",
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ function count_users_by_role(user_ids: number[]): Record<number, number> {
|
|||||||
return role_counts;
|
return role_counts;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_roles_with_counts(user_ids: number[]): {unique_id: number; name: string}[] {
|
function get_roles_with_counts(user_ids: number[]): dropdown_widget.Option[] {
|
||||||
const role_counts = count_users_by_role(user_ids);
|
const role_counts = count_users_by_role(user_ids);
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -240,12 +240,12 @@ function get_roles_with_counts(user_ids: number[]): {unique_id: number; name: st
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_roles_count_for_active_users(): {unique_id: number; name: string}[] {
|
function get_roles_count_for_active_users(): dropdown_widget.Option[] {
|
||||||
const active_user_ids = people.get_realm_active_human_user_ids();
|
const active_user_ids = people.get_realm_active_human_user_ids();
|
||||||
return get_roles_with_counts(active_user_ids);
|
return get_roles_with_counts(active_user_ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_roles_count_for_deactivated_users(): {unique_id: number; name: string}[] {
|
function get_roles_count_for_deactivated_users(): dropdown_widget.Option[] {
|
||||||
const deactivated_user_ids = people.get_non_active_human_ids();
|
const deactivated_user_ids = people.get_non_active_human_ids();
|
||||||
return get_roles_with_counts(deactivated_user_ids);
|
return get_roles_with_counts(deactivated_user_ids);
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ function get_roles_count_for_deactivated_users(): {unique_id: number; name: stri
|
|||||||
function create_role_filter_dropdown(
|
function create_role_filter_dropdown(
|
||||||
$events_container: JQuery,
|
$events_container: JQuery,
|
||||||
section: UserSettingsSection,
|
section: UserSettingsSection,
|
||||||
get_role_options: () => {unique_id: number; name: string}[],
|
get_role_options: () => dropdown_widget.Option[],
|
||||||
): dropdown_widget.DropdownWidget {
|
): dropdown_widget.DropdownWidget {
|
||||||
return new dropdown_widget.DropdownWidget({
|
return new dropdown_widget.DropdownWidget({
|
||||||
widget_name: section.dropdown_widget_name,
|
widget_name: section.dropdown_widget_name,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import * as blueslip from "./blueslip.ts";
|
|||||||
import type {Bot} from "./bot_data.ts";
|
import type {Bot} from "./bot_data.ts";
|
||||||
import * as bot_data from "./bot_data.ts";
|
import * as bot_data from "./bot_data.ts";
|
||||||
import * as color_data from "./color_data.ts";
|
import * as color_data from "./color_data.ts";
|
||||||
|
import type * as dropdown_widget from "./dropdown_widget.ts";
|
||||||
import {FoldDict} from "./fold_dict.ts";
|
import {FoldDict} from "./fold_dict.ts";
|
||||||
import {page_params} from "./page_params.ts";
|
import {page_params} from "./page_params.ts";
|
||||||
import * as peer_data from "./peer_data.ts";
|
import * as peer_data from "./peer_data.ts";
|
||||||
@@ -1011,11 +1012,9 @@ export function remove_default_stream(stream_id: number): void {
|
|||||||
default_stream_ids.delete(stream_id);
|
default_stream_ids.delete(stream_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_options_for_dropdown_widget(): {
|
export function get_options_for_dropdown_widget(): (dropdown_widget.Option & {
|
||||||
name: string;
|
|
||||||
unique_id: number;
|
|
||||||
stream: StreamSubscription;
|
stream: StreamSubscription;
|
||||||
}[] {
|
})[] {
|
||||||
return subscribed_subs()
|
return subscribed_subs()
|
||||||
.filter((stream) => !stream.is_archived)
|
.filter((stream) => !stream.is_archived)
|
||||||
.map((stream) => ({
|
.map((stream) => ({
|
||||||
|
|||||||
@@ -781,11 +781,7 @@ export async function build_move_topic_to_stream_popover(
|
|||||||
}
|
}
|
||||||
|
|
||||||
stream_widget_value = current_stream_id;
|
stream_widget_value = current_stream_id;
|
||||||
const streams_list_options = (): {
|
const streams_list_options = (): dropdown_widget.Option[] =>
|
||||||
name: string;
|
|
||||||
unique_id: number;
|
|
||||||
stream: sub_store.StreamSubscription;
|
|
||||||
}[] =>
|
|
||||||
stream_data.get_options_for_dropdown_widget().filter(({stream}) => {
|
stream_data.get_options_for_dropdown_widget().filter(({stream}) => {
|
||||||
if (stream.stream_id === current_stream_id) {
|
if (stream.stream_id === current_stream_id) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -680,11 +680,9 @@ export function switch_stream_sort(tab_name: string): void {
|
|||||||
redraw_left_panel();
|
redraw_left_panel();
|
||||||
}
|
}
|
||||||
|
|
||||||
function filters_dropdown_options(current_value: string | number | undefined): {
|
function filters_dropdown_options(
|
||||||
unique_id: string;
|
current_value: string | number | undefined,
|
||||||
name: string;
|
): dropdown_widget.Option[] {
|
||||||
bold_current_selection: boolean;
|
|
||||||
}[] {
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
unique_id: stream_settings_data.FILTERS.ARCHIVED_CHANNELS,
|
unique_id: stream_settings_data.FILTERS.ARCHIVED_CHANNELS,
|
||||||
|
|||||||
@@ -1662,11 +1662,9 @@ export function filter_click_handler(
|
|||||||
widget.render();
|
widget.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
function filters_dropdown_options(current_value: string | number | undefined): {
|
function filters_dropdown_options(
|
||||||
unique_id: string;
|
current_value: string | number | undefined,
|
||||||
name: string;
|
): dropdown_widget.Option[] {
|
||||||
bold_current_selection: boolean;
|
|
||||||
}[] {
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
unique_id: FILTERS.ACTIVE_GROUPS,
|
unique_id: FILTERS.ACTIVE_GROUPS,
|
||||||
|
|||||||
@@ -261,20 +261,12 @@ function reset_subscribe_widget(): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_user_unsub_streams_for_dropdown(): {
|
export function get_user_unsub_streams_for_dropdown(): dropdown_widget.Option[] {
|
||||||
name: string;
|
|
||||||
unique_id: number;
|
|
||||||
stream: StreamSubscription;
|
|
||||||
}[] {
|
|
||||||
const target_user_id = Number.parseInt($("#user-profile-modal").attr("data-user-id")!, 10);
|
const target_user_id = Number.parseInt($("#user-profile-modal").attr("data-user-id")!, 10);
|
||||||
return get_user_unsub_streams(target_user_id);
|
return get_user_unsub_streams(target_user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get_user_unsub_streams(user_id: number): {
|
export function get_user_unsub_streams(user_id: number): dropdown_widget.Option[] {
|
||||||
name: string;
|
|
||||||
unique_id: number;
|
|
||||||
stream: StreamSubscription;
|
|
||||||
}[] {
|
|
||||||
return stream_data
|
return stream_data
|
||||||
.get_streams_for_user(user_id)
|
.get_streams_for_user(user_id)
|
||||||
.can_subscribe.map((stream) => ({
|
.can_subscribe.map((stream) => ({
|
||||||
|
|||||||
@@ -39,12 +39,9 @@ export const COMMON_DROPDOWN_WIDGET_PARAMS = {
|
|||||||
disable_for_spectators: true,
|
disable_for_spectators: true,
|
||||||
} satisfies Partial<dropdown_widget.DropdownWidgetOptions>;
|
} satisfies Partial<dropdown_widget.DropdownWidgetOptions>;
|
||||||
|
|
||||||
export function filters_dropdown_options(current_value: string | number | undefined): {
|
export function filters_dropdown_options(
|
||||||
unique_id: string;
|
current_value: string | number | undefined,
|
||||||
name: string;
|
): dropdown_widget.Option[] {
|
||||||
description: string;
|
|
||||||
bold_current_selection: boolean;
|
|
||||||
}[] {
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
unique_id: FILTERS.FOLLOWED_TOPICS,
|
unique_id: FILTERS.FOLLOWED_TOPICS,
|
||||||
|
|||||||
Reference in New Issue
Block a user