From 26710a437038281214a33fae617668ce54086095 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 27 Feb 2021 15:58:55 -0800 Subject: [PATCH] js: Convert static/js/ui_report.js to ES6 module. Signed-off-by: Anders Kaseorg --- .eslintrc.json | 1 - frontend_tests/node_tests/hash_util.js | 12 ++++- frontend_tests/node_tests/message_fetch.js | 2 +- frontend_tests/node_tests/server_events.js | 2 +- frontend_tests/node_tests/settings_org.js | 4 +- .../node_tests/settings_user_groups.js | 4 +- static/js/attachments_ui.js | 1 + static/js/blueslip.js | 1 + static/js/bundles/app.js | 1 - static/js/compose.js | 1 + static/js/global.d.ts | 1 - static/js/hash_util.js | 1 + static/js/invite.js | 1 + static/js/message_edit.js | 1 + static/js/message_edit_history.js | 1 + static/js/message_fetch.js | 1 + static/js/reload.js | 1 + static/js/server_events.js | 1 + static/js/settings_account.js | 1 + static/js/settings_display.js | 1 + static/js/settings_emoji.js | 1 + static/js/settings_exports.js | 1 + static/js/settings_invites.js | 1 + static/js/settings_linkifiers.js | 1 + static/js/settings_org.js | 1 + static/js/settings_streams.js | 1 + static/js/settings_ui.js | 1 + static/js/settings_user_groups.js | 1 + static/js/settings_users.js | 1 + static/js/stream_create.js | 1 + static/js/stream_edit.js | 1 + static/js/subs.js | 1 + static/js/ui_report.js | 45 +++++++++---------- 33 files changed, 63 insertions(+), 33 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index a8ff0a858b..a96b58255f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -216,7 +216,6 @@ "typing_events": false, "ui": false, "ui_init": false, - "ui_report": false, "ui_util": false, "unread": false, "unread_ops": false, diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js index dc19627862..957b07a66e 100644 --- a/frontend_tests/node_tests/hash_util.js +++ b/frontend_tests/node_tests/hash_util.js @@ -2,21 +2,28 @@ const {strict: assert} = require("assert"); +const rewiremock = require("rewiremock/node"); + const {set_global, zrequire} = require("../zjsunit/namespace"); const {run_test} = require("../zjsunit/test"); -const ui_report = set_global("ui_report", { +const ui_report = { + __esModule: true, displayed_error: false, + error: () => { ui_report.displayed_error = true; }, -}); +}; +rewiremock("../../static/js/ui_report").with(ui_report); set_global("location", { protocol: "https:", host: "example.com", pathname: "/", }); +rewiremock.enable(); + const hash_util = zrequire("hash_util"); const stream_data = zrequire("stream_data"); const people = zrequire("people"); @@ -172,3 +179,4 @@ run_test("test_search_public_streams_notice_url", () => { "#narrow/streams/public/sender/15-hamlet", ); }); +rewiremock.disable(); diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js index 626f0ff650..193c0271c5 100644 --- a/frontend_tests/node_tests/message_fetch.js +++ b/frontend_tests/node_tests/message_fetch.js @@ -25,7 +25,7 @@ set_global("recent_topics", { }); // Still required for page_params.initial_pointer set_global("page_params", {}); -set_global("ui_report", { +rewiremock("../../static/js/ui_report").with({ hide_error: noop, }); diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.js index dbdca0ce9f..a184484120 100644 --- a/frontend_tests/node_tests/server_events.js +++ b/frontend_tests/node_tests/server_events.js @@ -37,7 +37,7 @@ rewiremock("../../static/js/reload_state").with({ // we also directly write to pointer set_global("pointer", {}); -set_global("ui_report", { +rewiremock("../../static/js/ui_report").with({ hide_error() { return false; }, diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index b8c9f0ee0f..34914dad38 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -56,6 +56,8 @@ stub_templates((name, data) => { const overlays = set_global("overlays", {}); const _ui_report = { + __esModule: true, + success(msg, elem) { elem.val(msg); }, @@ -79,7 +81,7 @@ set_global("FormData", _FormData); set_global("jQuery", _jQuery); rewiremock("../../static/js/loading").with(_loading); set_global("realm_logo", _realm_logo); -set_global("ui_report", _ui_report); +rewiremock("../../static/js/ui_report").with(_ui_report); rewiremock("../../static/js/list_widget").with(_ListWidget); // setup is only imported to set the diff --git a/frontend_tests/node_tests/settings_user_groups.js b/frontend_tests/node_tests/settings_user_groups.js index 04690181b0..d2a05bed7a 100644 --- a/frontend_tests/node_tests/settings_user_groups.js +++ b/frontend_tests/node_tests/settings_user_groups.js @@ -30,7 +30,9 @@ const user_groups = { add: noop, }; rewiremock("../../static/js/user_groups").with(user_groups); -const ui_report = set_global("ui_report", {}); +const ui_report = {__esModule: true}; + +rewiremock("../../static/js/ui_report").with(ui_report); const page_params = set_global("page_params", {}); diff --git a/static/js/attachments_ui.js b/static/js/attachments_ui.js index c15378fb26..94fb7ca93e 100644 --- a/static/js/attachments_ui.js +++ b/static/js/attachments_ui.js @@ -6,6 +6,7 @@ const render_uploaded_files_list = require("../templates/uploaded_files_list.hbs const channel = require("./channel"); const ListWidget = require("./list_widget"); const loading = require("./loading"); +const ui_report = require("./ui_report"); let attachments; let upload_space_used; diff --git a/static/js/blueslip.js b/static/js/blueslip.js index fb2989b738..d9303e7aa3 100644 --- a/static/js/blueslip.js +++ b/static/js/blueslip.js @@ -9,6 +9,7 @@ // execution. const blueslip_stacktrace = require("./blueslip_stacktrace"); +const ui_report = require("./ui_report"); if (Error.stackTraceLimit !== undefined) { Error.stackTraceLimit = 100000; diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index b9c047f919..09e14d8fb0 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -26,7 +26,6 @@ import "../narrow"; import "../reload"; import "../compose_actions"; import "../subs"; -import "../ui_report"; import "../message_scroll"; import "../info_overlay"; import "../ui"; diff --git a/static/js/compose.js b/static/js/compose.js index acd0f38052..6e8b482cfb 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -26,6 +26,7 @@ import * as settings_config from "./settings_config"; import * as stream_data from "./stream_data"; import * as stream_edit from "./stream_edit"; import * as transmit from "./transmit"; +import * as ui_report from "./ui_report"; import * as upload from "./upload"; import * as util from "./util"; import * as zcommand from "./zcommand"; diff --git a/static/js/global.d.ts b/static/js/global.d.ts index 892bb31693..5d3d98174e 100644 --- a/static/js/global.d.ts +++ b/static/js/global.d.ts @@ -87,7 +87,6 @@ declare let timerender: any; declare let typeahead_helper: any; declare let typing_events: any; declare let ui: any; -declare let ui_report: any; declare let ui_util: any; declare let unread: any; declare let unread_ops: any; diff --git a/static/js/hash_util.js b/static/js/hash_util.js index 10d722a43a..2123e44ee6 100644 --- a/static/js/hash_util.js +++ b/static/js/hash_util.js @@ -3,6 +3,7 @@ const narrow_state = require("./narrow_state"); const people = require("./people"); const stream_data = require("./stream_data"); +const ui_report = require("./ui_report"); exports.get_hash_category = function (hash) { // given "#streams/subscribed", returns "streams" diff --git a/static/js/invite.js b/static/js/invite.js index ad02e3e460..005a17db14 100644 --- a/static/js/invite.js +++ b/static/js/invite.js @@ -9,6 +9,7 @@ import render_settings_dev_env_email_access from "../templates/settings/dev_env_ import * as channel from "./channel"; import * as common from "./common"; import * as stream_data from "./stream_data"; +import * as ui_report from "./ui_report"; function reset_error_messages() { $("#invite_status").hide().text("").removeClass(common.status_classes); diff --git a/static/js/message_edit.js b/static/js/message_edit.js index e1c24eddf4..38a7df2634 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -13,6 +13,7 @@ import * as message_viewport from "./message_viewport"; import * as resize from "./resize"; import * as rows from "./rows"; import * as stream_data from "./stream_data"; +import * as ui_report from "./ui_report"; import * as upload from "./upload"; const currently_editing_messages = new Map(); diff --git a/static/js/message_edit_history.js b/static/js/message_edit_history.js index f3c644c602..e7f4dbe222 100644 --- a/static/js/message_edit_history.js +++ b/static/js/message_edit_history.js @@ -2,6 +2,7 @@ import render_message_edit_history from "../templates/message_edit_history.hbs"; import * as channel from "./channel"; import * as people from "./people"; +import * as ui_report from "./ui_report"; const {format, isSameDay} = require("date-fns"); diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js index b5f879e154..c93d4764e8 100644 --- a/static/js/message_fetch.js +++ b/static/js/message_fetch.js @@ -6,6 +6,7 @@ const huddle_data = require("./huddle_data"); const people = require("./people"); const pm_list = require("./pm_list"); const stream_data = require("./stream_data"); +const ui_report = require("./ui_report"); const consts = { backfill_idle_time: 10 * 1000, diff --git a/static/js/reload.js b/static/js/reload.js index 65d03e1f49..8b900ef0a1 100644 --- a/static/js/reload.js +++ b/static/js/reload.js @@ -3,6 +3,7 @@ import * as compose_state from "./compose_state"; import {localstorage} from "./localstorage"; import * as narrow_state from "./narrow_state"; import * as reload_state from "./reload_state"; +import * as ui_report from "./ui_report"; import * as util from "./util"; // Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html diff --git a/static/js/server_events.js b/static/js/server_events.js index daf7a3dedc..096724686c 100644 --- a/static/js/server_events.js +++ b/static/js/server_events.js @@ -8,6 +8,7 @@ const reload = require("./reload"); const reload_state = require("./reload_state"); const sent_messages = require("./sent_messages"); const server_events_dispatch = require("./server_events_dispatch"); +const ui_report = require("./ui_report"); // Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html let waiting_on_homeview_load = true; diff --git a/static/js/settings_account.js b/static/js/settings_account.js index fe01f1c654..e893061038 100644 --- a/static/js/settings_account.js +++ b/static/js/settings_account.js @@ -12,6 +12,7 @@ const people = require("./people"); const pill_typeahead = require("./pill_typeahead"); const settings_ui = require("./settings_ui"); const setup = require("./setup"); +const ui_report = require("./ui_report"); const user_pill = require("./user_pill"); exports.update_email = function (new_email) { diff --git a/static/js/settings_display.js b/static/js/settings_display.js index 6dd27af39e..b98769f025 100644 --- a/static/js/settings_display.js +++ b/static/js/settings_display.js @@ -5,6 +5,7 @@ const emojisets = require("./emojisets"); const loading = require("./loading"); const settings_config = require("./settings_config"); const settings_ui = require("./settings_ui"); +const ui_report = require("./ui_report"); const meta = { loaded: false, diff --git a/static/js/settings_emoji.js b/static/js/settings_emoji.js index bec26abb92..15387bbdf6 100644 --- a/static/js/settings_emoji.js +++ b/static/js/settings_emoji.js @@ -8,6 +8,7 @@ const channel = require("./channel"); const ListWidget = require("./list_widget"); const loading = require("./loading"); const people = require("./people"); +const ui_report = require("./ui_report"); const meta = { loaded: false, diff --git a/static/js/settings_exports.js b/static/js/settings_exports.js index 4851bc2192..a54cda2275 100644 --- a/static/js/settings_exports.js +++ b/static/js/settings_exports.js @@ -6,6 +6,7 @@ const channel = require("./channel"); const ListWidget = require("./list_widget"); const loading = require("./loading"); const people = require("./people"); +const ui_report = require("./ui_report"); const meta = { loaded: false, diff --git a/static/js/settings_invites.js b/static/js/settings_invites.js index 89f4d26904..04ccb454b2 100644 --- a/static/js/settings_invites.js +++ b/static/js/settings_invites.js @@ -8,6 +8,7 @@ const ListWidget = require("./list_widget"); const loading = require("./loading"); const people = require("./people"); const settings_config = require("./settings_config"); +const ui_report = require("./ui_report"); const util = require("./util"); const meta = { diff --git a/static/js/settings_linkifiers.js b/static/js/settings_linkifiers.js index b7b79ccd80..440ab52922 100644 --- a/static/js/settings_linkifiers.js +++ b/static/js/settings_linkifiers.js @@ -5,6 +5,7 @@ const render_admin_filter_list = require("../templates/admin_filter_list.hbs"); const channel = require("./channel"); const ListWidget = require("./list_widget"); const loading = require("./loading"); +const ui_report = require("./ui_report"); const meta = { loaded: false, diff --git a/static/js/settings_org.js b/static/js/settings_org.js index a828d9ba78..6a7112256e 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -9,6 +9,7 @@ const loading = require("./loading"); const settings_config = require("./settings_config"); const settings_ui = require("./settings_ui"); const stream_data = require("./stream_data"); +const ui_report = require("./ui_report"); const meta = { loaded: false, diff --git a/static/js/settings_streams.js b/static/js/settings_streams.js index 06ef613592..939646e09b 100644 --- a/static/js/settings_streams.js +++ b/static/js/settings_streams.js @@ -6,6 +6,7 @@ const channel = require("./channel"); const ListWidget = require("./list_widget"); const loading = require("./loading"); const stream_data = require("./stream_data"); +const ui_report = require("./ui_report"); const meta = { loaded: false, diff --git a/static/js/settings_ui.js b/static/js/settings_ui.js index 9dbd893e4d..82313d2c3f 100644 --- a/static/js/settings_ui.js +++ b/static/js/settings_ui.js @@ -1,4 +1,5 @@ import * as loading from "./loading"; +import * as ui_report from "./ui_report"; export function display_checkmark($elem) { const check_mark = document.createElement("img"); diff --git a/static/js/settings_user_groups.js b/static/js/settings_user_groups.js index 46f6266f2d..297dbd160f 100644 --- a/static/js/settings_user_groups.js +++ b/static/js/settings_user_groups.js @@ -8,6 +8,7 @@ const render_confirm_delete_user = require("../templates/confirm_delete_user.hbs const channel = require("./channel"); 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"); diff --git a/static/js/settings_users.js b/static/js/settings_users.js index ccf415e2ce..a8112a652e 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -11,6 +11,7 @@ const people = require("./people"); const settings_config = require("./settings_config"); const settings_data = require("./settings_data"); const settings_ui = require("./settings_ui"); +const ui_report = require("./ui_report"); const user_pill = require("./user_pill"); const section = { diff --git a/static/js/stream_create.js b/static/js/stream_create.js index 34f5040073..489e786f5f 100644 --- a/static/js/stream_create.js +++ b/static/js/stream_create.js @@ -7,6 +7,7 @@ import * as loading from "./loading"; import * as peer_data from "./peer_data"; import * as people from "./people"; import * as stream_data from "./stream_data"; +import * as ui_report from "./ui_report"; let created_stream; diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 64d40b10b9..cc455328d9 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -17,6 +17,7 @@ import * as stream_color from "./stream_color"; import * as stream_data from "./stream_data"; import * as stream_pill from "./stream_pill"; import * as stream_ui_updates from "./stream_ui_updates"; +import * as ui_report from "./ui_report"; import * as user_pill from "./user_pill"; import * as util from "./util"; diff --git a/static/js/subs.js b/static/js/subs.js index dcf05fcd97..d4558495da 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -20,6 +20,7 @@ const stream_data = require("./stream_data"); const stream_edit = require("./stream_edit"); const stream_muting = require("./stream_muting"); const stream_ui_updates = require("./stream_ui_updates"); +const ui_report = require("./ui_report"); const util = require("./util"); exports.show_subs_pane = { diff --git a/static/js/ui_report.js b/static/js/ui_report.js index 3a380b8b24..b3d9ef7d00 100644 --- a/static/js/ui_report.js +++ b/static/js/ui_report.js @@ -1,15 +1,14 @@ -"use strict"; +import _ from "lodash"; -const _ = require("lodash"); +import * as common from "./common"; -const common = require("./common"); /* Arguments used in the report_* functions are, response- response that we want to display status_box- element being used to display the response cls- class that we want to add/remove to/from the status_box */ -exports.message = function (response, status_box, cls, remove_after) { +export function message(response, status_box, cls, remove_after) { if (cls === undefined) { cls = "alert"; } @@ -28,9 +27,9 @@ exports.message = function (response, status_box, cls, remove_after) { }, remove_after); } status_box.addClass("show"); -}; +} -exports.error = function (response, xhr, status_box, remove_after) { +export function error(response, xhr, status_box, remove_after) { if (xhr && xhr.status.toString().charAt(0) === "4") { // Only display the error response for 4XX, where we've crafted // a nice response. @@ -42,27 +41,27 @@ exports.error = function (response, xhr, status_box, remove_after) { } } - exports.message(response, status_box, "alert-error", remove_after); -}; + message(response, status_box, "alert-error", remove_after); +} -exports.client_error = function (response, status_box, remove_after) { - exports.message(response, status_box, "alert-error", remove_after); -}; +export function client_error(response, status_box, remove_after) { + message(response, status_box, "alert-error", remove_after); +} -exports.success = function (response, status_box, remove_after) { - exports.message(response, status_box, "alert-success", remove_after); -}; +export function success(response, status_box, remove_after) { + message(response, status_box, "alert-success", remove_after); +} -exports.generic_embed_error = function (error) { +export function generic_embed_error(error) { const $alert = $("
"); const $exit = "
"; $(".alert-box").append( $alert.html($exit + "
" + error + "
").addClass("show"), ); -}; +} -exports.generic_row_button_error = function (xhr, btn) { +export function generic_row_button_error(xhr, btn) { if (xhr.status.toString().charAt(0) === "4") { btn.closest("td").html( $("

").addClass("text-error").text(JSON.parse(xhr.responseText).msg), @@ -70,17 +69,15 @@ exports.generic_row_button_error = function (xhr, btn) { } else { btn.text(i18n.t("Failed!")); } -}; +} -exports.hide_error = function ($target) { +export function hide_error($target) { $target.addClass("fade-out"); setTimeout(() => { $target.removeClass("show fade-out"); }, 300); -}; +} -exports.show_error = function ($target) { +export function show_error($target) { $target.addClass("show"); -}; - -window.ui_report = exports; +}