From 88e9320fa5a7c62d065dfe8b72cd0b9a6c620d99 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 15 Sep 2023 15:03:52 -0700 Subject: [PATCH] list_widget: Rename unsafe modifier parameter to modifier_html. Signed-off-by: Anders Kaseorg --- web/src/alert_words_ui.js | 2 +- web/src/attachments_ui.ts | 2 +- web/src/dropdown_widget.js | 2 +- web/src/list_widget.ts | 16 +++++++-------- web/src/recent_view_ui.js | 2 +- web/src/settings_emoji.ts | 2 +- web/src/settings_exports.js | 2 +- web/src/settings_invites.js | 2 +- web/src/settings_linkifiers.js | 2 +- web/src/settings_muted_users.js | 2 +- web/src/settings_playgrounds.js | 2 +- web/src/settings_streams.js | 2 +- web/src/settings_user_topics.js | 2 +- web/src/settings_users.js | 6 +++--- web/src/stream_create_subscribers.js | 2 +- web/src/stream_edit_subscribers.js | 2 +- web/src/user_group_create_members.js | 2 +- web/src/user_group_edit_members.js | 2 +- web/src/user_groups_settings_ui.js | 2 +- web/src/user_profile.js | 12 +++++------ web/tests/alert_words_ui.test.js | 6 +++--- web/tests/list_widget.test.js | 30 ++++++++++++++-------------- web/tests/recent_view.test.js | 6 +++--- 23 files changed, 55 insertions(+), 55 deletions(-) diff --git a/web/src/alert_words_ui.js b/web/src/alert_words_ui.js index 414f992330..7794ef12d2 100644 --- a/web/src/alert_words_ui.js +++ b/web/src/alert_words_ui.js @@ -24,7 +24,7 @@ export function rerender_alert_words_ui() { ListWidget.create($word_list, words, { name: "alert-words-list", get_item: ListWidget.default_get_item, - modifier(alert_word) { + modifier_html(alert_word) { return render_alert_word_settings_item({alert_word}); }, $parent_container: $("#alert-word-settings"), diff --git a/web/src/attachments_ui.ts b/web/src/attachments_ui.ts index 18b3378a51..e265fac3de 100644 --- a/web/src/attachments_ui.ts +++ b/web/src/attachments_ui.ts @@ -134,7 +134,7 @@ function render_attachments_ui(): void { ListWidget.create($uploaded_files_table, attachments, { name: "uploaded-files-list", get_item: ListWidget.default_get_item, - modifier(attachment) { + modifier_html(attachment) { return render_uploaded_files_list({attachment}); }, filter: { diff --git a/web/src/dropdown_widget.js b/web/src/dropdown_widget.js index 070ff761a3..90f491c9ab 100644 --- a/web/src/dropdown_widget.js +++ b/web/src/dropdown_widget.js @@ -120,7 +120,7 @@ export class DropdownWidget { this.list_widget = ListWidget.create($dropdown_list_body, this.get_options(), { name: `${CSS.escape(this.widget_name)}-list-widget`, get_item: ListWidget.default_get_item, - modifier(item) { + modifier_html(item) { return render_dropdown_list({item}); }, filter: { diff --git a/web/src/list_widget.ts b/web/src/list_widget.ts index 5d3db03f54..a6a460984f 100644 --- a/web/src/list_widget.ts +++ b/web/src/list_widget.ts @@ -36,7 +36,7 @@ type ListWidgetFilterOpts = { type ListWidgetOpts = { name?: string; get_item: (key: Key) => Item; - modifier: (item: Item, filter_value: string) => string; + modifier_html: (item: Item, filter_value: string) => string; init_sort?: string | SortingFunction; initially_descending_sort?: boolean; html_selector?: (item: Item) => JQuery; @@ -256,16 +256,16 @@ export function create( let html = ""; for (const item of slice) { - const s = opts.modifier(item, meta.filter_value); + const item_html = opts.modifier_html(item, meta.filter_value); - if (typeof s !== "string") { - blueslip.error("List item is not a string", {item: s}); + if (typeof item_html !== "string") { + blueslip.error("List item is not a string", {item_html}); continue; } // append the HTML or nothing if corrupt (null, undef, etc.). - if (s) { - html += s; + if (item_html) { + html += item_html; } } @@ -293,7 +293,7 @@ export function create( return; } - const html = opts.modifier(item, meta.filter_value); + const html = opts.modifier_html(item, meta.filter_value); if (typeof html !== "string") { blueslip.error("List item is not a string", {item: html}); return; @@ -432,7 +432,7 @@ export function create( "Please specify modifier and html_selector when creating the widget.", ); } - const rendered_row = opts.modifier(item, meta.filter_value); + const rendered_row = opts.modifier_html(item, meta.filter_value); if (insert_index === meta.filtered_list.length - 1) { const $target_row = opts.html_selector!(meta.filtered_list[insert_index - 1]); $target_row.after(rendered_row); diff --git a/web/src/recent_view_ui.js b/web/src/recent_view_ui.js index ae53281638..80b0059098 100644 --- a/web/src/recent_view_ui.js +++ b/web/src/recent_view_ui.js @@ -883,7 +883,7 @@ export function complete_rerender() { name: "recent_view_table", get_item: ListWidget.default_get_item, $parent_container: $("#recent_view_table"), - modifier(item) { + modifier_html(item) { return render_recent_view_row(format_conversation(item)); }, filter: { diff --git a/web/src/settings_emoji.ts b/web/src/settings_emoji.ts index 0931cb5534..aaf04e2b82 100644 --- a/web/src/settings_emoji.ts +++ b/web/src/settings_emoji.ts @@ -121,7 +121,7 @@ export function populate_emoji(): void { ListWidget.create($emoji_table, Object.values(emoji_data), { name: "emoji_list", get_item: ListWidget.default_get_item, - modifier(item) { + modifier_html(item) { if (item.deactivated !== true) { return render_admin_emoji_list({ emoji: { diff --git a/web/src/settings_exports.js b/web/src/settings_exports.js index 1780d9aead..3490d29863 100644 --- a/web/src/settings_exports.js +++ b/web/src/settings_exports.js @@ -42,7 +42,7 @@ export function populate_exports_table(exports) { ListWidget.create($exports_table, Object.values(exports), { name: "admin_exports_list", get_item: ListWidget.default_get_item, - modifier(data) { + modifier_html(data) { let failed_timestamp = data.failed_timestamp; let deleted_timestamp = data.deleted_timestamp; diff --git a/web/src/settings_invites.js b/web/src/settings_invites.js index f34787341b..2c92081af0 100644 --- a/web/src/settings_invites.js +++ b/web/src/settings_invites.js @@ -62,7 +62,7 @@ function populate_invites(invites_data) { ListWidget.create($invites_table, invites_data.invites, { name: "admin_invites_list", get_item: ListWidget.default_get_item, - modifier(item) { + modifier_html(item) { item.invited_absolute_time = timerender.absolute_time(item.invited * 1000); if (item.expiry_date !== null) { item.expiry_date_absolute_time = timerender.absolute_time(item.expiry_date * 1000); diff --git a/web/src/settings_linkifiers.js b/web/src/settings_linkifiers.js index 534fc92b65..c684b67a6e 100644 --- a/web/src/settings_linkifiers.js +++ b/web/src/settings_linkifiers.js @@ -133,7 +133,7 @@ export function populate_linkifiers(linkifiers_data) { ListWidget.create($linkifiers_table, linkifiers_data, { name: "linkifiers_list", get_item: ListWidget.default_get_item, - modifier(linkifier, filter_value) { + modifier_html(linkifier, filter_value) { return render_admin_linkifier_list({ linkifier: { pattern: linkifier.pattern, diff --git a/web/src/settings_muted_users.js b/web/src/settings_muted_users.js index 76d9bba362..d976e86c93 100644 --- a/web/src/settings_muted_users.js +++ b/web/src/settings_muted_users.js @@ -22,7 +22,7 @@ export function populate_list() { ListWidget.create($muted_users_table, all_muted_users, { name: "muted-users-list", get_item: ListWidget.default_get_item, - modifier(muted_user) { + modifier_html(muted_user) { return render_muted_user_ui_row({muted_user}); }, filter: { diff --git a/web/src/settings_playgrounds.js b/web/src/settings_playgrounds.js index d3687960ab..6285443e87 100644 --- a/web/src/settings_playgrounds.js +++ b/web/src/settings_playgrounds.js @@ -36,7 +36,7 @@ export function populate_playgrounds(playgrounds_data) { ListWidget.create($playgrounds_table, playgrounds_data, { name: "playgrounds_list", get_item: ListWidget.default_get_item, - modifier(playground) { + modifier_html(playground) { return render_admin_playground_list({ playground: { playground_name: playground.name, diff --git a/web/src/settings_streams.js b/web/src/settings_streams.js index f0a55f59cf..e14f156c15 100644 --- a/web/src/settings_streams.js +++ b/web/src/settings_streams.js @@ -105,7 +105,7 @@ export function build_default_stream_table() { ListWidget.create($table, subs, { name: "default_streams_list", get_item: ListWidget.default_get_item, - modifier(item) { + modifier_html(item) { return render_admin_default_streams_list({ stream: item, can_modify: page_params.is_admin, diff --git a/web/src/settings_user_topics.js b/web/src/settings_user_topics.js index 493c0aef5f..fb5223a36d 100644 --- a/web/src/settings_user_topics.js +++ b/web/src/settings_user_topics.js @@ -27,7 +27,7 @@ export function populate_list() { ListWidget.create($user_topics_table, all_user_topics, { name: "user-topics-list", get_item: ListWidget.default_get_item, - modifier(user_topic) { + modifier_html(user_topic) { const context = { user_topic, user_topic_visibility_policy_values: diff --git a/web/src/settings_users.js b/web/src/settings_users.js index 660d670ed9..36c052d2c9 100644 --- a/web/src/settings_users.js +++ b/web/src/settings_users.js @@ -308,7 +308,7 @@ section.bots.create_table = () => { bot_list_widget = ListWidget.create($bots_table, bot_user_ids, { name: "admin_bot_list", get_item: bot_info, - modifier: render_admin_user_list, + modifier_html: render_admin_user_list, html_selector: (item) => $(`tr[data-user-id='${CSS.escape(item.user_id)}']`), filter: { $element: $bots_table.closest(".settings-section").find(".search"), @@ -343,7 +343,7 @@ section.active.create_table = (active_users) => { ListWidget.create($users_table, active_users, { name: "users_table_list", get_item: people.get_by_user_id, - modifier(item) { + modifier_html(item) { const info = human_info(item); return render_admin_user_list(info); }, @@ -373,7 +373,7 @@ section.deactivated.create_table = (deactivated_users) => { ListWidget.create($deactivated_users_table, deactivated_users, { name: "deactivated_users_table_list", get_item: people.get_by_user_id, - modifier(item) { + modifier_html(item) { const info = human_info(item); return render_admin_user_list(info); }, diff --git a/web/src/stream_create_subscribers.js b/web/src/stream_create_subscribers.js index 629a69cc32..a6725a5c4c 100644 --- a/web/src/stream_create_subscribers.js +++ b/web/src/stream_create_subscribers.js @@ -86,7 +86,7 @@ export function build_widgets() { name: "new_stream_add_users", get_item: people.get_by_user_id, $parent_container: $add_people_container, - modifier(user) { + modifier_html(user) { const item = { email: user.delivery_email, user_id: user.user_id, diff --git a/web/src/stream_edit_subscribers.js b/web/src/stream_edit_subscribers.js index 7ce3b6bc52..b82e05f4a2 100644 --- a/web/src/stream_edit_subscribers.js +++ b/web/src/stream_edit_subscribers.js @@ -113,7 +113,7 @@ function make_list_widget({$parent_container, name, user_ids, user_can_remove_su return ListWidget.create($list_container, users, { name, get_item: ListWidget.default_get_item, - modifier(item) { + modifier_html(item) { return format_member_list_elem(item, user_can_remove_subscribers); }, filter: { diff --git a/web/src/user_group_create_members.js b/web/src/user_group_create_members.js index 591252eeb8..5740eb3959 100644 --- a/web/src/user_group_create_members.js +++ b/web/src/user_group_create_members.js @@ -99,7 +99,7 @@ export function build_widgets() { id: settings_users.sort_user_id, ...ListWidget.generic_sort_functions("alphabetic", ["full_name"]), }, - modifier(user) { + modifier_html(user) { const item = { email: user.delivery_email, user_id: user.user_id, diff --git a/web/src/user_group_edit_members.js b/web/src/user_group_edit_members.js index 9e52f9ddfc..1c96d8933b 100644 --- a/web/src/user_group_edit_members.js +++ b/web/src/user_group_edit_members.js @@ -73,7 +73,7 @@ function make_list_widget({$parent_container, name, user_ids}) { id: settings_users.sort_user_id, ...ListWidget.generic_sort_functions("alphabetic", ["full_name"]), }, - modifier(item) { + modifier_html(item) { return format_member_list_elem(item); }, filter: { diff --git a/web/src/user_groups_settings_ui.js b/web/src/user_groups_settings_ui.js index cbd20e5e4c..7224a25902 100644 --- a/web/src/user_groups_settings_ui.js +++ b/web/src/user_groups_settings_ui.js @@ -200,7 +200,7 @@ export function setup_page(callback) { group_list_widget = ListWidget.create($container, user_groups_list, { name: "user-groups-overlay", get_item: ListWidget.default_get_item, - modifier(item) { + modifier_html(item) { item.is_member = user_groups.is_direct_member_of( people.my_current_user_id(), item.id, diff --git a/web/src/user_profile.js b/web/src/user_profile.js index 6f34eef345..e47127ae67 100644 --- a/web/src/user_profile.js +++ b/web/src/user_profile.js @@ -133,7 +133,7 @@ export function get_user_unsub_streams() { }); } -function format_user_stream_list_item(stream, user) { +function format_user_stream_list_item_html(stream, user) { const show_unsubscribe_button = people.can_admin_user(user) || stream_data.can_unsubscribe_others(stream); const show_private_stream_unsub_tooltip = @@ -150,7 +150,7 @@ function format_user_stream_list_item(stream, user) { }); } -function format_user_group_list_item(group) { +function format_user_group_list_item_html(group) { return render_user_group_list_item({ group_id: group.id, name: group.name, @@ -164,8 +164,8 @@ function render_user_stream_list(streams, user) { user_streams_list_widget = ListWidget.create($container, streams, { name: `user-${user.user_id}-stream-list`, get_item: ListWidget.default_get_item, - modifier(item) { - return format_user_stream_list_item(item, user); + modifier_html(item) { + return format_user_stream_list_item_html(item, user); }, filter: { $element: $("#user-profile-streams-tab .stream-search"), @@ -184,8 +184,8 @@ function render_user_group_list(groups, user) { ListWidget.create($container, groups, { name: `user-${user.user_id}-group-list`, get_item: ListWidget.default_get_item, - modifier(item) { - return format_user_group_list_item(item); + modifier_html(item) { + return format_user_group_list_item_html(item); }, $simplebar_container: $("#user-profile-modal .modal__body"), }); diff --git a/web/tests/alert_words_ui.test.js b/web/tests/alert_words_ui.test.js index 976aaa10f3..6efcdf6ccf 100644 --- a/web/tests/alert_words_ui.test.js +++ b/web/tests/alert_words_ui.test.js @@ -21,12 +21,12 @@ run_test("rerender_alert_words_ui", ({mock_template}) => { let list_widget_create_called = false; alert_words_ui.reset(); const ListWidget = mock_esm("../src/list_widget", { - modifier: noop, + modifier_html: noop, create(_container, words, opts) { const alert_words = []; - ListWidget.modifier = opts.modifier; + ListWidget.modifier_html = opts.modifier_html; for (const word of words) { - alert_words.push(opts.modifier(word)); + alert_words.push(opts.modifier_html(word)); } list_widget_create_called = true; return alert_words; diff --git a/web/tests/list_widget.test.js b/web/tests/list_widget.test.js index 72784d6eb9..392ba84950 100644 --- a/web/tests/list_widget.test.js +++ b/web/tests/list_widget.test.js @@ -157,7 +157,7 @@ run_test("scrolling", () => { } const opts = { - modifier: (item) => item, + modifier_html: (item) => item, get_item: (item) => item, $simplebar_container: $scroll_container, }; @@ -206,7 +206,7 @@ run_test("not_scrolling", () => { } const opts = { - modifier: (item) => item, + modifier_html: (item) => item, get_item: (item) => item, $simplebar_container: $scroll_container, is_scroll_position_for_render: () => false, @@ -246,7 +246,7 @@ run_test("filtering", () => { $element: $search_input, predicate: (item, value) => item.includes(value), }, - modifier(item, filter_value) { + modifier_html(item, filter_value) { last_filter_value = filter_value; return div(item); }, @@ -292,7 +292,7 @@ run_test("no filtering", () => { let callback_called = false; // Opts does not require a filter key. const opts = { - modifier: (item) => div(item), + modifier_html: (item) => div(item), $simplebar_container: $scroll_container, callback_after_render() { callback_called = true; @@ -371,7 +371,7 @@ run_test("wire up filter element", () => { filterer: (list, value) => list.filter((item) => item.toLowerCase().includes(value)), $element: $filter_element, }, - modifier: (s) => "(" + s + ")", + modifier_html: (s) => "(" + s + ")", get_item: (item) => item, $simplebar_container: $scroll_container, }; @@ -402,7 +402,7 @@ run_test("sorting", () => { const opts = { name: "sorting-list", $parent_container: $sort_container, - modifier: (item) => div(item.name) + div(item.salary), + modifier_html: (item) => div(item.name) + div(item.salary), get_item: (item) => item, filter: { predicate: () => true, @@ -415,7 +415,7 @@ run_test("sorting", () => { }; function html_for(people) { - return people.map((item) => opts.modifier(item)).join(""); + return people.map((item) => opts.modifier_html(item)).join(""); } ListWidget.create($container, list, opts); @@ -507,7 +507,7 @@ run_test("custom sort", () => { ListWidget.create($container, list, { name: "custom-sort-list", - modifier: (n) => "(" + n.x + ", " + n.y + ")", + modifier_html: (n) => "(" + n.x + ", " + n.y + ")", get_item: (item) => item, sort_fields: { product: sort_by_product, @@ -545,7 +545,7 @@ run_test("clear_event_handlers", () => { const opts = { name: "list-we-create-twice", $parent_container: $sort_container, - modifier() {}, + modifier_html() {}, get_item() {}, filter: { $element: $filter_element, @@ -598,7 +598,7 @@ run_test("replace_list_data w/filter update", () => { ListWidget.create($container, list, { name: "replace-list", - modifier: (n) => "(" + n.toString() + ")", + modifier_html: (n) => "(" + n.toString() + ")", get_item: (item) => item, filter: { predicate: (n) => n % 2 === 0, @@ -704,7 +704,7 @@ run_test("render item", () => { const widget = ListWidget.create($container, list, { name: "replace-list", - modifier: (item) => `${item.text}\n`, + modifier_html: (item) => `${item.text}\n`, get_item, html_selector: (item) => $(`tr[data-item='${item.value}']`), $simplebar_container: $scroll_container, @@ -741,7 +741,7 @@ run_test("render item", () => { let get_item_called; const widget_2 = ListWidget.create($container, list, { name: "replace-list", - modifier: (item) => `${item.text}\n`, + modifier_html: (item) => `${item.text}\n`, get_item(item) { get_item_called = true; return item; @@ -757,13 +757,13 @@ run_test("render item", () => { let rendering_item = false; const widget_3 = ListWidget.create($container, list, { name: "replace-list", - modifier: (item) => (rendering_item ? undefined : `${item}\n`), + modifier_html: (item) => (rendering_item ? undefined : `${item}\n`), get_item, html_selector: (item) => $(`tr[data-item='${item}']`), $simplebar_container: $scroll_container, }); // Once we have initially rendered the widget, change the - // behavior of the modifier function. + // behavior of the modifier_html function. rendering_item = true; blueslip.expect("error", "List item is not a string"); widget_3.render_item(item); @@ -829,7 +829,7 @@ run_test("Multiselect dropdown retain_selected_items", () => { const widget = ListWidget.create($container, list, { name: "replace-list", - modifier: (item) => `
  • ${item.name}
  • \n`, + modifier_html: (item) => `
  • ${item.name}
  • \n`, get_item: (item) => item, multiselect: { selected_items: data, diff --git a/web/tests/recent_view.test.js b/web/tests/recent_view.test.js index 666526bd44..41041abf89 100644 --- a/web/tests/recent_view.test.js +++ b/web/tests/recent_view.test.js @@ -49,13 +49,13 @@ const all_visibility_policies = { let expected_data_to_replace_in_list_widget; const ListWidget = mock_esm("../src/list_widget", { - modifier: noop, + modifier_html: noop, generic_sort_functions: noop, create(_container, mapped_topic_values, opts) { const formatted_topics = []; - ListWidget.modifier = opts.modifier; + ListWidget.modifier_html = opts.modifier_html; for (const item of mapped_topic_values) { - formatted_topics.push(opts.modifier(item)); + formatted_topics.push(opts.modifier_html(item)); opts.filter.predicate(item); } // Just for coverage, the mechanisms