From 78f105475a50b4f1593473d16c4e861f292edab7 Mon Sep 17 00:00:00 2001 From: Varun Singh Date: Tue, 11 Jun 2024 00:41:41 +0530 Subject: [PATCH] stream_create_subscribers: Convert module to TypeScript. --- tools/test-js-with-node | 2 +- web/e2e-tests/stream_create.test.ts | 1 + ...ribers.js => stream_create_subscribers.ts} | 29 ++++++++++--------- web/src/zulip_test.ts | 1 - 4 files changed, 18 insertions(+), 15 deletions(-) rename web/src/{stream_create_subscribers.js => stream_create_subscribers.ts} (82%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 110a2884a3..8c4119868e 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -232,7 +232,7 @@ EXEMPT_FILES = make_set( "web/src/stream_color.ts", "web/src/stream_color_events.ts", "web/src/stream_create.js", - "web/src/stream_create_subscribers.js", + "web/src/stream_create_subscribers.ts", "web/src/stream_edit.js", "web/src/stream_edit_subscribers.js", "web/src/stream_edit_toggler.ts", diff --git a/web/e2e-tests/stream_create.test.ts b/web/e2e-tests/stream_create.test.ts index 3f518e8622..8a0ccfa5fb 100644 --- a/web/e2e-tests/stream_create.test.ts +++ b/web/e2e-tests/stream_create.test.ts @@ -22,6 +22,7 @@ async function await_user_hidden(page: Page, name: string): Promise { async function add_user_to_stream(page: Page, name: string): Promise { const user_id = await common.get_user_id_from_name(page, name); + assert(user_id !== undefined); await page.evaluate((user_id) => { zulip_test.add_user_id_to_new_stream(user_id); }, user_id); diff --git a/web/src/stream_create_subscribers.js b/web/src/stream_create_subscribers.ts similarity index 82% rename from web/src/stream_create_subscribers.js rename to web/src/stream_create_subscribers.ts index 5abb2062d3..babd8ee3a3 100644 --- a/web/src/stream_create_subscribers.js +++ b/web/src/stream_create_subscribers.ts @@ -4,46 +4,49 @@ import render_new_stream_user from "../templates/stream_settings/new_stream_user import render_new_stream_users from "../templates/stream_settings/new_stream_users.hbs"; import * as add_subscribers_pill from "./add_subscribers_pill"; +import type {InputPillContainer} from "./input_pill"; import * as ListWidget from "./list_widget"; +import type {ListWidget as ListWidgetType} from "./list_widget"; import * as people from "./people"; import {current_user} from "./state_data"; import * as stream_create_subscribers_data from "./stream_create_subscribers_data"; +import type {CombinedPillItem} from "./typeahead_helper"; import * as user_sort from "./user_sort"; -let pill_widget; -let all_users_list_widget; +let pill_widget: InputPillContainer; +let all_users_list_widget: ListWidgetType; -export function get_principals() { +export function get_principals(): number[] { return stream_create_subscribers_data.get_principals(); } -function redraw_subscriber_list() { +function redraw_subscriber_list(): void { all_users_list_widget.replace_list_data(stream_create_subscribers_data.sorted_user_ids()); } -function add_user_ids(user_ids) { +function add_user_ids(user_ids: number[]): void { stream_create_subscribers_data.add_user_ids(user_ids); redraw_subscriber_list(); } -function add_all_users() { +function add_all_users(): void { const user_ids = stream_create_subscribers_data.get_all_user_ids(); add_user_ids(user_ids); } -function remove_user_ids(user_ids) { +function remove_user_ids(user_ids: number[]): void { stream_create_subscribers_data.remove_user_ids(user_ids); redraw_subscriber_list(); } -function build_pill_widget({$parent_container}) { +function build_pill_widget({$parent_container}: {$parent_container: JQuery}): void { const $pill_container = $parent_container.find(".pill-container"); const get_potential_subscribers = stream_create_subscribers_data.get_potential_subscribers; pill_widget = add_subscribers_pill.create({$pill_container, get_potential_subscribers}); } -export function create_handlers($container) { +export function create_handlers($container: JQuery): void { $container.on("click", ".add_all_users_to_stream", (e) => { e.preventDefault(); add_all_users(); @@ -53,12 +56,12 @@ export function create_handlers($container) { $container.on("click", ".remove_potential_subscriber", (e) => { e.preventDefault(); const $elem = $(e.target); - const user_id = Number.parseInt($elem.attr("data-user-id"), 10); + const user_id = Number.parseInt($elem.attr("data-user-id")!, 10); remove_user_ids([user_id]); }); const button_selector = ".add_subscribers_container button.add-subscriber-button"; - function add_users({pill_user_ids}) { + function add_users({pill_user_ids}: {pill_user_ids: number[]}): void { add_user_ids(pill_user_ids); // eslint-disable-next-line unicorn/no-array-callback-reference const $pill_widget_button = $container.find(button_selector); @@ -75,7 +78,7 @@ export function create_handlers($container) { }); } -export function build_widgets() { +export function build_widgets(): void { const $add_people_container = $("#people_to_add"); $add_people_container.html(render_new_stream_users({})); @@ -119,7 +122,7 @@ export function build_widgets() { }); } -export function add_user_id_to_new_stream(user_id) { +export function add_user_id_to_new_stream(user_id: number): void { // This is only used by puppeteer tests. add_user_ids([user_id]); } diff --git a/web/src/zulip_test.ts b/web/src/zulip_test.ts index d642a7128c..aec53e85ac 100644 --- a/web/src/zulip_test.ts +++ b/web/src/zulip_test.ts @@ -14,5 +14,4 @@ export {page_params, page_params_parse_time} from "./base_page_params"; export {initiate as initiate_reload} from "./reload"; export {page_load_time} from "./setup"; export {current_user, realm} from "./state_data"; -// @ts-expect-error We haven't converted stream_create_subscribers.js yet export {add_user_id_to_new_stream} from "./stream_create_subscribers";