From 793ff996f69ea2093212bb1f4e322eb68b8352f6 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 27 Feb 2021 16:21:11 -0800 Subject: [PATCH] js: Convert static/js/settings_users.js to ES6 module. Signed-off-by: Anders Kaseorg --- .eslintrc.json | 1 - frontend_tests/node_tests/dispatch.js | 3 +- frontend_tests/node_tests/tutorial.js | 3 +- frontend_tests/node_tests/user_events.js | 2 +- static/js/bundles/app.js | 1 - static/js/global.d.ts | 1 - static/js/server_events_dispatch.js | 1 + static/js/settings_sections.js | 1 + static/js/settings_users.js | 56 +++++++++++------------- static/js/user_events.js | 1 + 10 files changed, 34 insertions(+), 36 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index a28bc1dde8..7401f23bac 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -161,7 +161,6 @@ "settings_profile_fields": false, "settings_streams": false, "settings_user_groups": false, - "settings_users": false, "stream_list": false, "StripeCheckout": false, "subs": false, diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js index 2e3c9cb5cd..06d9ce686f 100644 --- a/frontend_tests/node_tests/dispatch.js +++ b/frontend_tests/node_tests/dispatch.js @@ -74,7 +74,8 @@ rewiremock("../../static/js/settings_org").with(settings_org); const settings_profile_fields = set_global("settings_profile_fields", {}); const settings_streams = set_global("settings_streams", {}); const settings_user_groups = set_global("settings_user_groups", {}); -const settings_users = set_global("settings_users", {}); +const settings_users = {__esModule: true}; +rewiremock("../../static/js/settings_users").with(settings_users); const stream_data = {__esModule: true}; rewiremock("../../static/js/stream_data").with(stream_data); const stream_events = {__esModule: true}; diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.js index 4c86e9a535..21471beded 100644 --- a/frontend_tests/node_tests/tutorial.js +++ b/frontend_tests/node_tests/tutorial.js @@ -27,7 +27,8 @@ const message_live_update = {__esModule: true}; rewiremock("../../static/js/message_live_update").with(message_live_update); const pm_list = {__esModule: true}; rewiremock("../../static/js/pm_list").with(pm_list); -const settings_users = set_global("settings_users", {}); +const settings_users = {__esModule: true}; +rewiremock("../../static/js/settings_users").with(settings_users); const home_msg_list = set_global("home_msg_list", {}); const message_list = set_global("message_list", {}); const message_util = {__esModule: true}; diff --git a/frontend_tests/node_tests/user_events.js b/frontend_tests/node_tests/user_events.js index 0c2206ba59..10d45966ea 100644 --- a/frontend_tests/node_tests/user_events.js +++ b/frontend_tests/node_tests/user_events.js @@ -23,7 +23,7 @@ set_global("settings_profile_fields", { set_global("settings_streams", { maybe_disable_widgets() {}, }); -set_global("settings_users", { +rewiremock("../../static/js/settings_users").with({ update_user_data() {}, }); diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index 8ea2f9103a..6b1d8fa1a5 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -35,7 +35,6 @@ import "../server_events"; import "../zulip"; import "../templates"; import "../dropdown_list_widget"; -import "../settings_users"; import "../settings_streams"; import "../settings_linkifiers"; import "../settings_invites"; diff --git a/static/js/global.d.ts b/static/js/global.d.ts index 5244acf282..a927f76fa1 100644 --- a/static/js/global.d.ts +++ b/static/js/global.d.ts @@ -33,7 +33,6 @@ declare let settings_linkifiers: any; declare let settings_profile_fields: any; declare let settings_streams: any; declare let settings_user_groups: any; -declare let settings_users: any; declare let stream_list: any; declare let subs: any; declare let message_view_header: any; diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index 35a1c4d300..00e829ed76 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -29,6 +29,7 @@ import * as settings_emoji from "./settings_emoji"; import * as settings_exports from "./settings_exports"; import * as settings_notifications from "./settings_notifications"; import * as settings_org from "./settings_org"; +import * as settings_users from "./settings_users"; import * as starred_messages from "./starred_messages"; import * as stream_data from "./stream_data"; import * as stream_events from "./stream_events"; diff --git a/static/js/settings_sections.js b/static/js/settings_sections.js index f7d3c8cc7b..fbdadb0e01 100644 --- a/static/js/settings_sections.js +++ b/static/js/settings_sections.js @@ -8,6 +8,7 @@ import * as settings_exports from "./settings_exports"; import * as settings_muting from "./settings_muting"; import * as settings_notifications from "./settings_notifications"; import * as settings_org from "./settings_org"; +import * as settings_users from "./settings_users"; const load_func_dict = new Map(); // group -> function const loaded_groups = new Set(); diff --git a/static/js/settings_users.js b/static/js/settings_users.js index 3ab8a15d48..3122a50bb3 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -1,24 +1,22 @@ -"use strict"; +import render_admin_bot_form from "../templates/admin_bot_form.hbs"; +import render_admin_human_form from "../templates/admin_human_form.hbs"; +import render_admin_user_list from "../templates/admin_user_list.hbs"; -const render_admin_bot_form = require("../templates/admin_bot_form.hbs"); -const render_admin_human_form = require("../templates/admin_human_form.hbs"); -const render_admin_user_list = require("../templates/admin_user_list.hbs"); - -const channel = require("./channel"); -const ListWidget = require("./list_widget"); -const loading = require("./loading"); -const overlays = require("./overlays"); -const people = require("./people"); -const presence = require("./presence"); -const settings_account = require("./settings_account"); -const settings_bots = require("./settings_bots"); -const settings_config = require("./settings_config"); -const settings_data = require("./settings_data"); -const settings_panel_menu = require("./settings_panel_menu"); -const settings_ui = require("./settings_ui"); -const timerender = require("./timerender"); -const ui_report = require("./ui_report"); -const user_pill = require("./user_pill"); +import * as channel from "./channel"; +import * as ListWidget from "./list_widget"; +import * as loading from "./loading"; +import * as overlays from "./overlays"; +import * as people from "./people"; +import * as presence from "./presence"; +import * as settings_account from "./settings_account"; +import * as settings_bots from "./settings_bots"; +import * as settings_config from "./settings_config"; +import * as settings_data from "./settings_data"; +import * as settings_panel_menu from "./settings_panel_menu"; +import * as settings_ui from "./settings_ui"; +import * as timerender from "./timerender"; +import * as ui_report from "./ui_report"; +import * as user_pill from "./user_pill"; const section = { active: {}, @@ -352,15 +350,15 @@ section.deactivated.create_table = (deactivated_users) => { $("#admin_deactivated_users_table").show(); }; -exports.update_bot_data = function (bot_user_id) { +export function update_bot_data(bot_user_id) { if (!bot_list_widget) { return; } bot_list_widget.render_item(bot_user_id); -}; +} -exports.update_user_data = function (user_id, new_data) { +export function update_user_data(user_id, new_data) { const user_row = get_user_info_row(user_id); if (user_row.length === 0) { @@ -385,7 +383,7 @@ exports.update_user_data = function (user_id, new_data) { if (new_data.role !== undefined) { user_row.find(".user_role").text(people.get_user_type(user_id)); } -}; +} function start_data_load() { loading.make_indicator($("#admin_page_users_loading_indicator"), {text: "Loading..."}); @@ -696,15 +694,13 @@ section.bots.handle_events = () => { handle_bot_form(tbody, status_field); }; -exports.set_up_humans = function () { +export function set_up_humans() { start_data_load(); section.active.handle_events(); section.deactivated.handle_events(); -}; +} -exports.set_up_bots = function () { +export function set_up_bots() { section.bots.handle_events(); section.bots.create_table(); -}; - -window.settings_users = exports; +} diff --git a/static/js/user_events.js b/static/js/user_events.js index 172f58f266..7296d8a1e4 100644 --- a/static/js/user_events.js +++ b/static/js/user_events.js @@ -12,6 +12,7 @@ import * as pm_list from "./pm_list"; import * as settings_account from "./settings_account"; import * as settings_config from "./settings_config"; import * as settings_org from "./settings_org"; +import * as settings_users from "./settings_users"; export const update_person = function update(person) { const person_obj = people.get_by_user_id(person.user_id);