From b30da07fd314a0be01670695707e85b805ab80f2 Mon Sep 17 00:00:00 2001 From: Divyanshu Agrawal Date: Sun, 8 Mar 2020 10:13:57 +0000 Subject: [PATCH] file uploads: Remove status text for user cancelled uploads. Remove the 'Uploading file...' message from the compose box when the user manually cancels a file upload. --- frontend_tests/node_tests/upload.js | 24 ++++++++++++++++++++++++ static/js/upload.js | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/frontend_tests/node_tests/upload.js b/frontend_tests/node_tests/upload.js index bb18e70b9b..520ea03085 100644 --- a/frontend_tests/node_tests/upload.js +++ b/frontend_tests/node_tests/upload.js @@ -164,6 +164,7 @@ run_test('upload_files', () => { assert.equal(params.type, "image/png"); assert.equal(params.data, files[0]); }, + getFiles: () => [...files], }; let hide_upload_status_called = false; upload.hide_upload_status = (config) => { @@ -236,9 +237,32 @@ run_test('upload_files', () => { }); hide_upload_status_called = false; uppy_cancel_all_called = false; + let compose_ui_replace_syntax_called = false; + files = [ + { + name: "budapest.png", + type: "image/png", + }, + ]; + compose_ui.replace_syntax = (old_syntax, new_syntax, textarea) => { + compose_ui_replace_syntax_called = true; + assert.equal(old_syntax, "[Uploading budapest.png…]()"); + assert.equal(new_syntax, ""); + assert.equal(textarea, $('#compose-textarea')); + }; on_click_close_button_callback(); assert(uppy_cancel_all_called); assert(hide_upload_status_called); + assert(compose_ui_autosize_textarea_called); + assert(compose_ui_replace_syntax_called); + hide_upload_status_called = false; + compose_ui_replace_syntax_called = false; + $('#compose-textarea').val("user modified text"); + on_click_close_button_callback(); + assert(hide_upload_status_called); + assert(compose_ui_autosize_textarea_called); + assert(compose_ui_replace_syntax_called); + assert($('#compose-textarea').val(), "user modified text"); }); run_test('uppy_config', () => { diff --git a/static/js/upload.js b/static/js/upload.js index b4ecf992f7..69262ecb60 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -101,7 +101,12 @@ exports.upload_files = function (uppy, config, files) { exports.get_item("send_status", config).addClass("alert-info").removeClass("alert-error").show(); exports.get_item("send_status_message", config).html($("

").text(i18n.t("Uploading…"))); exports.get_item("send_status_close_button", config).one('click', function () { + uppy.getFiles().forEach((file) => { + compose_ui.replace_syntax("[Uploading " + file.name + "…]()", "", exports.get_item("textarea", config)); + }); + compose_ui.autosize_textarea(); uppy.cancelAll(); + exports.get_item("textarea", config).focus(); setTimeout(function () { exports.hide_upload_status(config); }, 500);