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/bot_data.js to ES6 module.

Anders Kaseorga0caabe6c7e7
diff --git a/.eslintrc.json b/.eslintrc.json
index 0d9615b51df..64f1e7ee14a 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -126,7 +126,6 @@
"globals": {
"$": false,
"blueslip": false,
- "bot_data": false,
"compose_actions": false,
"compose_ui": false,
"composebox_typeahead": false,
diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js
index 5d6212bfbb2..4109caa48b1 100644
--- a/frontend_tests/node_tests/dispatch.js
+++ b/frontend_tests/node_tests/dispatch.js
@@ -26,7 +26,8 @@ const alert_words_ui = {__esModule: true};
rewiremock("../../static/js/alert_words_ui").with(alert_words_ui);
const attachments_ui = {__esModule: true};
rewiremock("../../static/js/attachments_ui").with(attachments_ui);
-const bot_data = set_global("bot_data", {});
+const bot_data = {__esModule: true};
+rewiremock("../../static/js/bot_data").with(bot_data);
rewiremock("../../static/js/compose").with({});
const composebox_typeahead = set_global("composebox_typeahead", {});
set_global("current_msg_list", {});
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index 63d9f462f29..1f695d55f03 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -115,7 +115,6 @@ const util = zrequire("util");
zrequire("search_pill_widget");
zrequire("unread");
-zrequire("bot_data");
const upload = zrequire("upload");
const compose = zrequire("compose");
zrequire("composebox_typeahead");
diff --git a/static/js/bot_data.js b/static/js/bot_data.js
index 08d60112d0f..1c6027218d7 100644
--- a/static/js/bot_data.js
+++ b/static/js/bot_data.js
@@ -1,9 +1,7 @@
-"use strict";
+import _ from "lodash";
-const _ = require("lodash");
-
-const people = require("./people");
-const settings_bots = require("./settings_bots");
+import * as people from "./people";
+import * as settings_bots from "./settings_bots";
const bots = new Map();
@@ -29,31 +27,31 @@ const send_change_event = _.debounce(() => {
settings_bots.render_bots();
}, 50);
-exports.all_user_ids = function () {
+export function all_user_ids() {
return Array.from(bots.keys());
-};
+}
-exports.add = function (bot) {
+export function add(bot) {
const clean_bot = _.pick(bot, bot_fields);
bots.set(bot.user_id, clean_bot);
const clean_services = bot.services.map((service) => _.pick(service, services_fields));
services.set(bot.user_id, clean_services);
send_change_event();
-};
+}
-exports.deactivate = function (bot_id) {
+export function deactivate(bot_id) {
bots.get(bot_id).is_active = false;
send_change_event();
-};
+}
-exports.del = function (bot_id) {
+export function del(bot_id) {
bots.delete(bot_id);
services.delete(bot_id);
send_change_event();
-};
+}
-exports.update = function (bot_id, bot_update) {
+export function update(bot_id, bot_update) {
const bot = bots.get(bot_id);
Object.assign(bot, _.pick(bot_update, bot_fields));
@@ -64,9 +62,9 @@ exports.update = function (bot_id, bot_update) {
}
send_change_event();
-};
+}
-exports.get_all_bots_for_current_user = function () {
+export function get_all_bots_for_current_user() {
const ret = [];
for (const bot of bots.values()) {
if (people.is_my_user_id(bot.owner_id)) {
@@ -74,9 +72,9 @@ exports.get_all_bots_for_current_user = function () {
}
}
return ret;
-};
+}
-exports.get_editable = function () {
+export function get_editable() {
const ret = [];
for (const bot of bots.values()) {
if (bot.is_active && people.is_my_user_id(bot.owner_id)) {
@@ -84,20 +82,18 @@ exports.get_editable = function () {
}
}
return ret;
-};
+}
-exports.get = function (bot_id) {
+export function get(bot_id) {
return bots.get(bot_id);
-};
+}
-exports.get_services = function (bot_id) {
+export function get_services(bot_id) {
return services.get(bot_id);
-};
+}
-exports.initialize = function (params) {
+export function initialize(params) {
for (const bot of params.realm_bots) {
- exports.add(bot);
+ add(bot);
}
-};
-
-window.bot_data = exports;
+}
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 0e3771f7608..dc5460fe2d6 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -37,7 +37,6 @@ import "../templates";
import "../dropdown_list_widget";
import "../settings_profile_fields";
import "../settings";
-import "../bot_data";
import "../reactions";
import "../typing_events";
import "../ui_init";
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 1bbe271a705..4eb09698cfc 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -4,7 +4,6 @@
// to TS.
declare let blueslip: any;
-declare let bot_data: any;
declare let compose_actions: any;
declare let composebox_typeahead: any;
declare let compose_ui: any;
diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js
index 9e96593a73d..b5248877253 100644
--- a/static/js/server_events_dispatch.js
+++ b/static/js/server_events_dispatch.js
@@ -4,6 +4,7 @@ import * as activity from "./activity";
import * as alert_words from "./alert_words";
import * as alert_words_ui from "./alert_words_ui";
import * as attachments_ui from "./attachments_ui";
+import * as bot_data from "./bot_data";
import * as compose from "./compose";
import * as compose_fade from "./compose_fade";
import * as hotspots from "./hotspots";
diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js
index 36737438d53..30cfac816a8 100644
--- a/static/js/settings_bots.js
+++ b/static/js/settings_bots.js
@@ -6,6 +6,7 @@ import render_settings_edit_embedded_bot_service from "../templates/settings/edi
import render_settings_edit_outgoing_webhook_service from "../templates/settings/edit_outgoing_webhook_service.hbs";
import * as avatar from "./avatar";
+import * as bot_data from "./bot_data";
import * as channel from "./channel";
import * as loading from "./loading";
import * as overlays from "./overlays";
diff --git a/static/js/settings_users.js b/static/js/settings_users.js
index 3122a50bb3d..54382ccf642 100644
--- a/static/js/settings_users.js
+++ b/static/js/settings_users.js
@@ -2,6 +2,7 @@ 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";
+import * as bot_data from "./bot_data";
import * as channel from "./channel";
import * as ListWidget from "./list_widget";
import * as loading from "./loading";
diff --git a/static/js/ui_init.js b/static/js/ui_init.js
index 6ce40defb56..1fbcd44af1b 100644
--- a/static/js/ui_init.js
+++ b/static/js/ui_init.js
@@ -10,6 +10,7 @@ const render_edit_content_button = require("../templates/edit_content_button.hbs
const activity = require("./activity");
const alert_words = require("./alert_words");
+const bot_data = require("./bot_data");
const click_handlers = require("./click_handlers");
const compose = require("./compose");
const compose_pm_pill = require("./compose_pm_pill");