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.

bots: Remove the need to debounce for dispatching bot events.

PIG20860e3429da36c
diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js
index 3fa1c4f756f..0812df5980a 100644
--- a/frontend_tests/node_tests/dispatch.js
+++ b/frontend_tests/node_tests/dispatch.js
@@ -433,7 +433,7 @@ run_test("realm_bot add", ({override}) => {
const bot_stub = make_stub();
const admin_stub = make_stub();
override(bot_data, "add", bot_stub.f);
- override(settings_bots, "eventually_render_bots", () => {});
+ override(settings_bots, "render_bots", () => {});
override(settings_users, "update_bot_data", admin_stub.f);
dispatch(event);
@@ -449,7 +449,7 @@ run_test("realm_bot remove", ({override}) => {
const bot_stub = make_stub();
const admin_stub = make_stub();
override(bot_data, "deactivate", bot_stub.f);
- override(settings_bots, "eventually_render_bots", () => {});
+ override(settings_bots, "render_bots", () => {});
override(settings_users, "update_bot_data", admin_stub.f);
dispatch(event);
@@ -471,7 +471,7 @@ run_test("realm_bot update", ({override}) => {
const bot_stub = make_stub();
const admin_stub = make_stub();
override(bot_data, "update", bot_stub.f);
- override(settings_bots, "eventually_render_bots", () => {});
+ override(settings_bots, "render_bots", () => {});
override(settings_users, "update_bot_data", admin_stub.f);
dispatch(event);
diff --git a/frontend_tests/puppeteer_tests/settings.ts b/frontend_tests/puppeteer_tests/settings.ts
index ea1e10317db..6af6ba1d2f8 100644
--- a/frontend_tests/puppeteer_tests/settings.ts
+++ b/frontend_tests/puppeteer_tests/settings.ts
@@ -106,6 +106,7 @@ async function test_webhook_bot_creation(page: Page): Promise<void> {
payload_url: "http://hostname.example.com/bots/followup",
});
+ await page.waitForSelector("#create_bot_button", {visible: true});
await page.click("#create_bot_button");
const bot_email = "[email protected]";
diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js
index d07a21e5d63..86113f7ace7 100644
--- a/static/js/server_events_dispatch.js
+++ b/static/js/server_events_dispatch.js
@@ -300,13 +300,13 @@ export function dispatch_normal_event(event) {
switch (event.op) {
case "add":
bot_data.add(event.bot);
- settings_bots.eventually_render_bots();
+ settings_bots.render_bots();
settings_users.update_bot_data(event.bot.user_id);
break;
case "remove":
bot_data.deactivate(event.bot.user_id);
event.bot.is_active = false;
- settings_bots.eventually_render_bots();
+ settings_bots.render_bots();
settings_users.update_bot_data(event.bot.user_id);
break;
case "delete":
@@ -314,7 +314,7 @@ export function dispatch_normal_event(event) {
break;
case "update":
bot_data.update(event.bot.user_id, event.bot);
- settings_bots.eventually_render_bots();
+ settings_bots.render_bots();
settings_users.update_bot_data(event.bot.user_id);
break;
default:
diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js
index b886cb12871..24fd61d42c1 100644
--- a/static/js/settings_bots.js
+++ b/static/js/settings_bots.js
@@ -1,6 +1,5 @@
import ClipboardJS from "clipboard";
import $ from "jquery";
-import _ from "lodash";
import render_bot_avatar_row from "../templates/settings/bot_avatar_row.hbs";
import render_edit_bot from "../templates/settings/edit_bot.hbs";
@@ -85,7 +84,7 @@ export function type_id_to_string(type_id) {
return page_params.bot_types.find((bot_type) => bot_type.type_id === type_id).name;
}
-function render_bots() {
+export function render_bots() {
$("#active_bots_list").empty();
$("#inactive_bots_list").empty();
@@ -110,31 +109,8 @@ function render_bots() {
focus_tab.add_a_new_bot_tab();
return;
}
-
- if ($("#bots_lists_navbar .add-a-new-bot-tab").hasClass("active")) {
- $("#add-a-new-bot-form").show();
- $("#active_bots_list").hide();
- $("#inactive_bots_list").hide();
- } else if ($("#bots_lists_navbar .active-bots-tab").hasClass("active")) {
- $("#add-a-new-bot-form").hide();
- $("#active_bots_list").show();
- $("#inactive_bots_list").hide();
- } else {
- $("#add-a-new-bot-form").hide();
- $("#active_bots_list").hide();
- $("#inactive_bots_list").show();
- }
}
-// The reason we debounce this call is very wonky. I just moved it
-// from bot_data.js as part of breaking dependencies. Basically, it
-// allows the server response to win the race against events.
-// TODO: Organize the code so that we clear loading spinners and
-// switch tabs within the UI when the event comes in.
-export const eventually_render_bots = _.debounce(() => {
- render_bots();
-}, 50);
-
export function generate_zuliprc_uri(bot_id) {
const bot = bot_data.get(bot_id);
const data = generate_zuliprc_content(bot);
@@ -267,6 +243,9 @@ export function set_up() {
);
});
+ // This needs to come before render_bots() in case the user
+ // has no active bots
+ focus_tab.active_bots_tab();
render_bots();
$.validator.addMethod(
@@ -345,8 +324,7 @@ export function set_up() {
$("#create_bot_button").show();
$("#create_interface_type").val(GENERIC_INTERFACE);
create_avatar_widget.clear();
- $("#bots_lists_navbar .add-a-new-bot-tab").removeClass("active");
- $("#bots_lists_navbar .active-bots-tab").addClass("active");
+ focus_tab.active_bots_tab();
},
error(xhr) {
$("#bot_table_error").text(JSON.parse(xhr.responseText).msg).show();