mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
settings-users: Rerender bot rows on data change.
Previously, we fiddled with the existing HTML to update the state. Now, we can use list_render.render_item() to render the complete item properly.
This commit is contained in:
committed by
Steve Howell
parent
a114b6a1b1
commit
58b612a4f0
@@ -1044,7 +1044,7 @@ with_overrides(function (override) {
|
|||||||
global.with_stub(function (bot_stub) {
|
global.with_stub(function (bot_stub) {
|
||||||
global.with_stub(function (admin_stub) {
|
global.with_stub(function (admin_stub) {
|
||||||
override('bot_data.add', bot_stub.f);
|
override('bot_data.add', bot_stub.f);
|
||||||
override('settings_users.update_user_data', admin_stub.f);
|
override('settings_users.update_bot_data', admin_stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
const args = bot_stub.get_args('bot');
|
const args = bot_stub.get_args('bot');
|
||||||
assert_same(args.bot, event.bot);
|
assert_same(args.bot, event.bot);
|
||||||
@@ -1057,7 +1057,7 @@ with_overrides(function (override) {
|
|||||||
global.with_stub(function (bot_stub) {
|
global.with_stub(function (bot_stub) {
|
||||||
global.with_stub(function (admin_stub) {
|
global.with_stub(function (admin_stub) {
|
||||||
override('bot_data.deactivate', bot_stub.f);
|
override('bot_data.deactivate', bot_stub.f);
|
||||||
override('settings_users.update_user_data', admin_stub.f);
|
override('settings_users.update_bot_data', admin_stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
const args = bot_stub.get_args('user_id');
|
const args = bot_stub.get_args('user_id');
|
||||||
assert_same(args.user_id, event.bot.user_id);
|
assert_same(args.user_id, event.bot.user_id);
|
||||||
@@ -1070,7 +1070,7 @@ with_overrides(function (override) {
|
|||||||
global.with_stub(function (bot_stub) {
|
global.with_stub(function (bot_stub) {
|
||||||
global.with_stub(function (admin_stub) {
|
global.with_stub(function (admin_stub) {
|
||||||
override('bot_data.del', bot_stub.f);
|
override('bot_data.del', bot_stub.f);
|
||||||
override('settings_users.update_user_data', admin_stub.f);
|
override('settings_users.update_bot_data', admin_stub.f);
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
const args = bot_stub.get_args('bot_id');
|
const args = bot_stub.get_args('bot_id');
|
||||||
assert_same(args.bot_id, event.bot.user_id);
|
assert_same(args.bot_id, event.bot.user_id);
|
||||||
@@ -1083,7 +1083,7 @@ with_overrides(function (override) {
|
|||||||
global.with_stub(function (bot_stub) {
|
global.with_stub(function (bot_stub) {
|
||||||
global.with_stub(function (admin_stub) {
|
global.with_stub(function (admin_stub) {
|
||||||
override('bot_data.update', bot_stub.f);
|
override('bot_data.update', bot_stub.f);
|
||||||
override('settings_users.update_user_data', admin_stub.f);
|
override('settings_users.update_bot_data', admin_stub.f);
|
||||||
|
|
||||||
dispatch(event);
|
dispatch(event);
|
||||||
|
|
||||||
@@ -1093,7 +1093,6 @@ with_overrides(function (override) {
|
|||||||
|
|
||||||
args = admin_stub.get_args('update_user_id', 'update_bot_data');
|
args = admin_stub.get_args('update_user_id', 'update_bot_data');
|
||||||
assert_same(args.update_user_id, event.bot.user_id);
|
assert_same(args.update_user_id, event.bot.user_id);
|
||||||
assert_same(args.update_bot_data, event.bot);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -187,18 +187,15 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
|||||||
case 'realm_bot':
|
case 'realm_bot':
|
||||||
if (event.op === 'add') {
|
if (event.op === 'add') {
|
||||||
bot_data.add(event.bot);
|
bot_data.add(event.bot);
|
||||||
settings_users.update_user_data(event.bot.user_id, event.bot);
|
|
||||||
} else if (event.op === 'remove') {
|
} else if (event.op === 'remove') {
|
||||||
bot_data.deactivate(event.bot.user_id);
|
bot_data.deactivate(event.bot.user_id);
|
||||||
event.bot.is_active = false;
|
event.bot.is_active = false;
|
||||||
settings_users.update_user_data(event.bot.user_id, event.bot);
|
|
||||||
} else if (event.op === 'delete') {
|
} else if (event.op === 'delete') {
|
||||||
bot_data.del(event.bot.user_id);
|
bot_data.del(event.bot.user_id);
|
||||||
settings_users.update_user_data(event.bot.user_id, event.bot);
|
|
||||||
} else if (event.op === 'update') {
|
} else if (event.op === 'update') {
|
||||||
bot_data.update(event.bot.user_id, event.bot);
|
bot_data.update(event.bot.user_id, event.bot);
|
||||||
settings_users.update_user_data(event.bot.user_id, event.bot);
|
|
||||||
}
|
}
|
||||||
|
settings_users.update_bot_data(event.bot.user_id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'realm_emoji':
|
case 'realm_emoji':
|
||||||
|
|||||||
@@ -236,16 +236,19 @@ function human_info(person) {
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bot_list_widget;
|
||||||
|
|
||||||
section.bots.create_table = () => {
|
section.bots.create_table = () => {
|
||||||
loading.make_indicator($('#admin_page_bots_loading_indicator'), {text: 'Loading...'});
|
loading.make_indicator($('#admin_page_bots_loading_indicator'), {text: 'Loading...'});
|
||||||
const $bots_table = $("#admin_bots_table");
|
const $bots_table = $("#admin_bots_table");
|
||||||
$bots_table.hide();
|
$bots_table.hide();
|
||||||
const bot_user_ids = bot_data.all_user_ids();
|
const bot_user_ids = bot_data.all_user_ids();
|
||||||
|
|
||||||
list_render.create($bots_table, bot_user_ids, {
|
bot_list_widget = list_render.create($bots_table, bot_user_ids, {
|
||||||
name: "admin_bot_list",
|
name: "admin_bot_list",
|
||||||
get_item: bot_info,
|
get_item: bot_info,
|
||||||
modifier: render_admin_user_list,
|
modifier: render_admin_user_list,
|
||||||
|
html_selector: (item) => `tr[data-user-id='${item}']`,
|
||||||
filter: {
|
filter: {
|
||||||
element: $bots_table.closest(".settings-section").find(".search"),
|
element: $bots_table.closest(".settings-section").find(".search"),
|
||||||
predicate: function (item, value) {
|
predicate: function (item, value) {
|
||||||
@@ -320,6 +323,10 @@ section.deactivated.create_table = (deactivated_users) => {
|
|||||||
$("#admin_deactivated_users_table").show();
|
$("#admin_deactivated_users_table").show();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.update_bot_data = function (bot_user_id) {
|
||||||
|
bot_list_widget.render_item(bot_user_id);
|
||||||
|
};
|
||||||
|
|
||||||
exports.update_user_data = function (user_id, new_data) {
|
exports.update_user_data = function (user_id, new_data) {
|
||||||
const user_row = get_user_info_row(user_id);
|
const user_row = get_user_info_row(user_id);
|
||||||
|
|
||||||
@@ -332,16 +339,6 @@ exports.update_user_data = function (user_id, new_data) {
|
|||||||
user_row.find(".user_name").text(new_data.full_name);
|
user_row.find(".user_name").text(new_data.full_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_data.owner_id !== undefined) {
|
|
||||||
// TODO: Linkify the owner name to match the
|
|
||||||
// formatting of the list. Ideally we can
|
|
||||||
// make this whole function simpler
|
|
||||||
// by re-rendering the entire row via
|
|
||||||
// the list widget.
|
|
||||||
const owner_name = bot_owner_full_name(new_data.owner_id);
|
|
||||||
user_row.find(".owner").text(owner_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_data.is_active !== undefined) {
|
if (new_data.is_active !== undefined) {
|
||||||
if (new_data.is_active === false) {
|
if (new_data.is_active === false) {
|
||||||
// Deactivate the user/bot in the table
|
// Deactivate the user/bot in the table
|
||||||
|
|||||||
Reference in New Issue
Block a user