Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert static/js/settings_user_groups.js to ES6 module.

Anders Kaseorg65840a200182
diff --git a/.eslintrc.json b/.eslintrc.json
index d8c891069ef..cebafab1045 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -157,7 +157,6 @@
"search_pill_widget": false,
"settings": false,
"settings_profile_fields": false,
- "settings_user_groups": 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 c278c4d6f75..5d6212bfbb2 100644
--- a/frontend_tests/node_tests/dispatch.js
+++ b/frontend_tests/node_tests/dispatch.js
@@ -76,7 +76,8 @@ rewiremock("../../static/js/settings_org").with(settings_org);
const settings_profile_fields = set_global("settings_profile_fields", {});
const settings_streams = {__esModule: true};
rewiremock("../../static/js/settings_streams").with(settings_streams);
-const settings_user_groups = set_global("settings_user_groups", {});
+const settings_user_groups = {__esModule: true};
+rewiremock("../../static/js/settings_user_groups").with(settings_user_groups);
const settings_users = {__esModule: true};
rewiremock("../../static/js/settings_users").with(settings_users);
const stream_data = {__esModule: true};
diff --git a/frontend_tests/node_tests/settings_user_groups.js b/frontend_tests/node_tests/settings_user_groups.js
index 0dfc7dc0ce4..601e6b5ef8e 100644
--- a/frontend_tests/node_tests/settings_user_groups.js
+++ b/frontend_tests/node_tests/settings_user_groups.js
@@ -170,7 +170,7 @@ test_ui("populate_user_groups", () => {
return undefined;
};
- settings_user_groups.can_edit = () => true;
+ settings_user_groups.__Rewire__("can_edit", () => true);
const all_pills = new Map();
@@ -377,10 +377,10 @@ test_ui("with_external_user", () => {
user_pill.__Rewire__("append_person", () => noop);
let can_edit_called = 0;
- settings_user_groups.can_edit = () => {
+ settings_user_groups.__Rewire__("can_edit", () => {
can_edit_called += 1;
return false;
- };
+ });
// Reset zjquery to test stuff with user who cannot edit
$.clear_all_elements();
@@ -497,9 +497,9 @@ test_ui("with_external_user", () => {
test_ui("reload", () => {
$("#user-groups").html("Some text");
let populate_user_groups_called = false;
- settings_user_groups.populate_user_groups = () => {
+ settings_user_groups.__Rewire__("populate_user_groups", () => {
populate_user_groups_called = true;
- };
+ });
settings_user_groups.reload();
assert(populate_user_groups_called);
assert.equal($("#user-groups").html(), "");
@@ -512,7 +512,7 @@ test_ui("reset", () => {
});
test_ui("on_events", () => {
- settings_user_groups.can_edit = () => true;
+ settings_user_groups.__Rewire__("can_edit", () => true);
(function test_admin_user_group_form_submit_triggered() {
const handler = $(".organization form.admin-user-group-form").get_on_handler("submit");
@@ -590,9 +590,9 @@ test_ui("on_events", () => {
assert.equal(opts.url, "/json/user_groups/1");
assert.deepEqual(opts.data, data);
- settings_user_groups.reload = () => {
+ settings_user_groups.__Rewire__("reload", () => {
settings_user_groups_reload_called = true;
- };
+ });
opts.success();
assert(settings_user_groups_reload_called);
@@ -665,9 +665,9 @@ test_ui("on_events", () => {
// Cancel button triggers blur event.
let settings_user_groups_reload_called = false;
- settings_user_groups.reload = () => {
+ settings_user_groups.__Rewire__("reload", () => {
settings_user_groups_reload_called = true;
- };
+ });
api_endpoint_called = false;
fake_this.closest = (class_name) => {
if (
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index f0bcf54d5af..bca48331f9e 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_user_groups";
import "../settings_profile_fields";
import "../settings";
import "../admin";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 7d0dcb5c8ef..205792f926e 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -29,7 +29,6 @@ declare let recent_topics: any;
declare let search_pill_widget: any;
declare let settings: any;
declare let settings_profile_fields: any;
-declare let settings_user_groups: 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 d02412a4209..9e96593a73d 100644
--- a/static/js/server_events_dispatch.js
+++ b/static/js/server_events_dispatch.js
@@ -32,6 +32,7 @@ import * as settings_linkifiers from "./settings_linkifiers";
import * as settings_notifications from "./settings_notifications";
import * as settings_org from "./settings_org";
import * as settings_streams from "./settings_streams";
+import * as settings_user_groups from "./settings_user_groups";
import * as settings_users from "./settings_users";
import * as starred_messages from "./starred_messages";
import * as stream_data from "./stream_data";
diff --git a/static/js/settings_sections.js b/static/js/settings_sections.js
index 6320933b45f..2a613722617 100644
--- a/static/js/settings_sections.js
+++ b/static/js/settings_sections.js
@@ -11,6 +11,7 @@ import * as settings_muting from "./settings_muting";
import * as settings_notifications from "./settings_notifications";
import * as settings_org from "./settings_org";
import * as settings_streams from "./settings_streams";
+import * as settings_user_groups from "./settings_user_groups";
import * as settings_users from "./settings_users";
const load_func_dict = new Map(); // group -> function
diff --git a/static/js/settings_user_groups.js b/static/js/settings_user_groups.js
index 177b268268d..2b18ee19582 100644
--- a/static/js/settings_user_groups.js
+++ b/static/js/settings_user_groups.js
@@ -1,39 +1,37 @@
-"use strict";
+import _ from "lodash";
-const _ = require("lodash");
+import render_admin_user_group_list from "../templates/admin_user_group_list.hbs";
+import render_confirm_delete_user from "../templates/confirm_delete_user.hbs";
-const render_admin_user_group_list = require("../templates/admin_user_group_list.hbs");
-const render_confirm_delete_user = require("../templates/confirm_delete_user.hbs");
-
-const channel = require("./channel");
-const confirm_dialog = require("./confirm_dialog");
-const people = require("./people");
-const pill_typeahead = require("./pill_typeahead");
-const ui_report = require("./ui_report");
-const user_groups = require("./user_groups");
-const user_pill = require("./user_pill");
+import * as channel from "./channel";
+import * as confirm_dialog from "./confirm_dialog";
+import * as people from "./people";
+import * as pill_typeahead from "./pill_typeahead";
+import * as ui_report from "./ui_report";
+import * as user_groups from "./user_groups";
+import * as user_pill from "./user_pill";
const meta = {
loaded: false,
};
-exports.reset = function () {
+export function reset() {
meta.loaded = false;
-};
+}
-exports.reload = function () {
+export function reload() {
if (!meta.loaded) {
return;
}
const user_groups_section = $("#user-groups").expectOne();
user_groups_section.html("");
- exports.populate_user_groups();
-};
+ populate_user_groups();
+}
const USER_GROUP_EDIT_POLICY_MEMBERS = 1;
-exports.can_edit = function (group_id) {
+export function can_edit(group_id) {
if (page_params.is_admin) {
return true;
}
@@ -47,9 +45,9 @@ exports.can_edit = function (group_id) {
}
return user_groups.is_member_of(group_id, people.my_current_user_id());
-};
+}
-exports.populate_user_groups = function () {
+export function populate_user_groups() {
const user_groups_section = $("#user-groups").expectOne();
const user_groups_array = user_groups.get_realm_user_groups();
@@ -77,7 +75,7 @@ exports.populate_user_groups = function () {
}
function update_membership(group_id) {
- if (exports.can_edit(group_id)) {
+ if (can_edit(group_id)) {
return;
}
userg.find(".name").attr("contenteditable", "false");
@@ -126,7 +124,7 @@ exports.populate_user_groups = function () {
}
function update_cancel_button() {
- if (!exports.can_edit(data.id)) {
+ if (!can_edit(data.id)) {
return;
}
const cancel_button = $(`#user-groups #${CSS.escape(data.id)} .save-status.btn-danger`);
@@ -236,7 +234,7 @@ exports.populate_user_groups = function () {
}
function auto_save(class_name, event) {
- if (!exports.can_edit(data.id)) {
+ if (!can_edit(data.id)) {
return;
}
@@ -247,7 +245,7 @@ exports.populate_user_groups = function () {
$(event.relatedTarget).closest(`#user-groups #${CSS.escape(data.id)}`) &&
$(event.relatedTarget).closest(".save-status.btn-danger").length
) {
- exports.reload();
+ reload();
return;
}
save_name_desc();
@@ -273,13 +271,13 @@ exports.populate_user_groups = function () {
});
const input = pill_container.children(".input");
- if (exports.can_edit(data.id)) {
+ if (can_edit(data.id)) {
const opts = {update_func: update_cancel_button};
pill_typeahead.set_up(input, pills, opts);
}
(function pill_remove() {
- if (!exports.can_edit(data.id)) {
+ if (!can_edit(data.id)) {
return;
}
pills.onPillRemove(() => {
@@ -292,11 +290,11 @@ exports.populate_user_groups = function () {
});
})();
}
-};
+}
-exports.set_up = function () {
+export function set_up() {
meta.loaded = true;
- exports.populate_user_groups();
+ populate_user_groups();
$(".organization form.admin-user-group-form")
.off("submit")
@@ -336,7 +334,7 @@ exports.set_up = function () {
$("#user-groups").on("click", ".delete", function () {
const group_id = Number.parseInt($(this).parents(".user-group").attr("id"), 10);
- if (!exports.can_edit(group_id)) {
+ if (!can_edit(group_id)) {
return;
}
const user_group = user_groups.get_user_group_from_id(group_id);
@@ -350,7 +348,7 @@ exports.set_up = function () {
},
success() {
user_groups.remove(user_group);
- exports.reload();
+ reload();
},
error() {
btn.text(i18n.t("Failed!"));
@@ -379,6 +377,4 @@ exports.set_up = function () {
e.preventDefault();
}
});
-};
-
-window.settings_user_groups = exports;
+}