compose: Fix auto-resize issue on uploading files in preview mode.

On uploading a few files from markdown_preview mode of compose box and
then switching back to edit mode, the compose box doesn't get resized.
It even doesn't allow to scroll through the content.

Fixed this by switching back to the edit mode everytime user uploads
some file in markdown_preview mode as there's no use of staying in
markdown_preview mode anyways after uploading a file as the preview
doesn't get updated.

Also, updated the corresponding test cases.

Fixes: #16296.
This commit is contained in:
Priyansh Garg 2020-09-05 00:40:48 +05:30 committed by Tim Abbott
parent e5f62d083e
commit abe876a4a4
2 changed files with 30 additions and 0 deletions

View File

@ -51,6 +51,10 @@ run_test("get_item", () => {
assert.equal(upload.get_item("file_input_identifier", {mode: "compose"}), "#file_input");
assert.equal(upload.get_item("source", {mode: "compose"}), "compose-file-input");
assert.equal(upload.get_item("drag_drop_container", {mode: "compose"}), $("#compose"));
assert.equal(
upload.get_item("markdown_preview_hide_button", {mode: "compose"}),
$("#undo_markdown_preview"),
);
assert.equal(upload.get_item("textarea", {mode: "edit", row: 1}), $("#message_edit_content_1"));
@ -90,6 +94,10 @@ run_test("get_item", () => {
upload.get_item("drag_drop_container", {mode: "edit", row: 1}),
$("#message_edit_form"),
);
assert.equal(
upload.get_item("markdown_preview_hide_button", {mode: "edit", row: 65}),
$("#undo_markdown_preview_65"),
);
assert.throws(
() => {
@ -227,8 +235,13 @@ run_test("upload_files", () => {
compose_ui.autosize_textarea = () => {
compose_ui_autosize_textarea_called = true;
};
let markdown_preview_hide_button_clicked = false;
$("#undo_markdown_preview").on("click", () => {
markdown_preview_hide_button_clicked = true;
});
$("#compose-send-button").prop("disabled", false);
$("#compose-send-status").removeClass("alert-info").hide();
$("#undo_markdown_preview").show();
upload.upload_files(uppy, config, files);
assert($("#compose-send-button").prop("disabled"));
assert($("#compose-send-status").hasClass("alert-info"));
@ -236,6 +249,7 @@ run_test("upload_files", () => {
assert.equal($("<p>").text(), "translated: Uploading…");
assert(compose_ui_insert_syntax_and_focus_called);
assert(compose_ui_autosize_textarea_called);
assert(markdown_preview_hide_button_clicked);
assert(uppy_add_file_called);
files = [

View File

@ -47,6 +47,8 @@ exports.get_item = function (key, config) {
return "compose-file-input";
case "drag_drop_container":
return $("#compose");
case "markdown_preview_hide_button":
return $("#undo_markdown_preview");
default:
throw Error(`Invalid key name for mode "${config.mode}"`);
}
@ -75,6 +77,8 @@ exports.get_item = function (key, config) {
return "message-edit-file-input";
case "drag_drop_container":
return $("#message_edit_form");
case "markdown_preview_hide_button":
return $("#undo_markdown_preview_" + config.row);
default:
throw Error(`Invalid key name for mode "${config.mode}"`);
}
@ -112,6 +116,18 @@ exports.upload_files = function (uppy, config, files) {
);
return;
}
// If we're looking at a markdown preview, switch back to the edit
// UI. This is important for all the later logic around focus
// (etc.) to work correctly.
//
// We implement this transition through triggering a click on the
// toggle button to take advantage of the existing plumbing for
// handling the compose and edit UIs.
if (exports.get_item("markdown_preview_hide_button", config).is(":visible")) {
exports.get_item("markdown_preview_hide_button", config).trigger("click");
}
exports.get_item("send_button", config).prop("disabled", true);
exports
.get_item("send_status", config)