Skip to content

FIX: resolve discard draft keep editing #32667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export default class DiscardDraftModal extends Component {
this.args.closeModal();
}

@action
async keepEditing() {
await this.args.model.onKeepEditing();
this.args.closeModal();
}

<template>
<DModal
@closeModal={{@closeModal}}
Expand Down Expand Up @@ -45,7 +51,7 @@ export default class DiscardDraftModal extends Component {
{{/if}}
<DButton
@label="post.cancel_composer.keep_editing"
@action={{@closeModal}}
@action={{this.keepEditing}}
class="keep-editing"
/>
</:footer>
Expand Down
11 changes: 7 additions & 4 deletions app/assets/javascripts/discourse/app/services/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1448,8 +1448,10 @@ export default class ComposerService extends Service {
}
}

await this.cancelComposer(opts);
await this.open(opts);
const retry = await this.cancelComposer(opts);
if (retry) {
await this.open(opts);
}
return;
}

Expand Down Expand Up @@ -1633,16 +1635,17 @@ export default class ComposerService extends Service {
})
.finally(() => {
this.appEvents.trigger("composer:cancelled");
resolve();
resolve(true);
});
},
onSaveDraft: () => {
this._saveDraft();
this.model.clearState();
this.close();
this.appEvents.trigger("composer:cancelled");
return resolve();
return resolve(true);
},
onKeepEditing: () => resolve(false),
},
});
} else {
Expand Down
45 changes: 45 additions & 0 deletions app/assets/javascripts/discourse/tests/acceptance/composer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,51 @@ import { i18n } from "discourse-i18n";
.hasNoValue("discards draft and reset composer textarea");
});

test("Autosaves drafts after clicking keep editing in discard modal", async function (assert) {
pretender.post("/drafts.json", function () {
assert.step("saveDraft");
return response(200, {});
});

await visit("/t/internationalization-localization/280");

await click("#topic-footer-buttons .btn.create");

await fillIn(".d-editor-input", "this is draft content of the reply");

assert.verifySteps(["saveDraft"], "first draft is auto saved");

await click("#reply-control button.cancel");

assert
.dom(".discard-draft-modal.modal")
.exists("pops up the discard drafts modal");

await click(".d-modal__footer button.keep-editing");
assert.dom(".discard-draft-modal.modal").doesNotExist("hides modal");

assert
.dom(".d-editor-input")
.hasValue(
"this is draft content of the reply",
"composer has the content of the first draft"
);

await fillIn(
".d-editor-input",
"this is the updated content of the reply",
"update content in the composer"
);

assert.verifySteps(["saveDraft"], "second draft is saved");

await click("#reply-control button.create");

assert
.dom(".topic-post:last-of-type .cooked p")
.hasText("this is the updated content of the reply");
});

test("Create an enqueued Reply", async function (assert) {
pretender.post("/posts", function () {
return response(200, {
Expand Down
Loading