mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Warn users of overwriting new topic draft (#8841)
This commit is contained in:
committed by
GitHub
parent
91b70f8ffc
commit
c8a02161dd
@@ -5,6 +5,7 @@ import {
|
|||||||
CREATE_SHARED_DRAFT,
|
CREATE_SHARED_DRAFT,
|
||||||
REPLY
|
REPLY
|
||||||
} from "discourse/models/composer";
|
} from "discourse/models/composer";
|
||||||
|
import Draft from "discourse/models/draft";
|
||||||
import { computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
import { camelize } from "@ember/string";
|
import { camelize } from "@ember/string";
|
||||||
|
|
||||||
@@ -223,6 +224,21 @@ export default DropdownSelectBoxComponent.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
replyAsNewTopicSelected(options) {
|
replyAsNewTopicSelected(options) {
|
||||||
|
Draft.get("new_topic").then(response => {
|
||||||
|
if (response.draft) {
|
||||||
|
bootbox.confirm(
|
||||||
|
I18n.t("composer.composer_actions.reply_as_new_topic.confirm"),
|
||||||
|
result => {
|
||||||
|
if (result) this._replyAsNewTopicSelect(options);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this._replyAsNewTopicSelect(options);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
_replyAsNewTopicSelect(options) {
|
||||||
options.action = CREATE_TOPIC;
|
options.action = CREATE_TOPIC;
|
||||||
options.categoryId = this.get("composerModel.topic.category.id");
|
options.categoryId = this.get("composerModel.topic.category.id");
|
||||||
options.disableScopedCategory = true;
|
options.disableScopedCategory = true;
|
||||||
|
|||||||
@@ -1756,6 +1756,7 @@ en:
|
|||||||
reply_as_new_topic:
|
reply_as_new_topic:
|
||||||
label: Reply as linked topic
|
label: Reply as linked topic
|
||||||
desc: Create a new topic linked to this topic
|
desc: Create a new topic linked to this topic
|
||||||
|
confirm: You have a new topic draft saved, which will be overwritten if you create a linked topic.
|
||||||
reply_as_private_message:
|
reply_as_private_message:
|
||||||
label: New message
|
label: New message
|
||||||
desc: Create a new personal message
|
desc: Create a new personal message
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import selectKit from "helpers/select-kit-helper";
|
|||||||
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
||||||
import { _clearSnapshots } from "select-kit/components/composer-actions";
|
import { _clearSnapshots } from "select-kit/components/composer-actions";
|
||||||
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
|
import { toggleCheckDraftPopup } from "discourse/controllers/composer";
|
||||||
|
import Draft from "discourse/models/draft";
|
||||||
|
import { Promise } from "rsvp";
|
||||||
|
|
||||||
acceptance("Composer Actions", {
|
acceptance("Composer Actions", {
|
||||||
loggedIn: true,
|
loggedIn: true,
|
||||||
@@ -99,6 +101,9 @@ QUnit.test("replying to post - toggle_whisper", async assert => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("replying to post - reply_as_new_topic", async assert => {
|
QUnit.test("replying to post - reply_as_new_topic", async assert => {
|
||||||
|
sandbox
|
||||||
|
.stub(Draft, "get")
|
||||||
|
.returns(Promise.resolve({ draft: "", draft_sequence: 0 }));
|
||||||
const composerActions = selectKit(".composer-actions");
|
const composerActions = selectKit(".composer-actions");
|
||||||
const categoryChooser = selectKit(".title-wrapper .category-chooser");
|
const categoryChooser = selectKit(".title-wrapper .category-chooser");
|
||||||
const categoryChooserReplyArea = selectKit(".reply-area .category-chooser");
|
const categoryChooserReplyArea = selectKit(".reply-area .category-chooser");
|
||||||
@@ -129,46 +134,16 @@ QUnit.test("replying to post - reply_as_new_topic", async assert => {
|
|||||||
.val()
|
.val()
|
||||||
.includes(quote)
|
.includes(quote)
|
||||||
);
|
);
|
||||||
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("shared draft", async assert => {
|
QUnit.test("reply_as_new_topic without a new_topic draft", async assert => {
|
||||||
try {
|
await visit("/t/internationalization-localization/280");
|
||||||
toggleCheckDraftPopup(true);
|
await click(".create.reply");
|
||||||
|
const composerActions = selectKit(".composer-actions");
|
||||||
const composerActions = selectKit(".composer-actions");
|
await composerActions.expand();
|
||||||
const tags = selectKit(".mini-tag-chooser");
|
await composerActions.selectRowByValue("reply_as_new_topic");
|
||||||
|
assert.equal(exists(find(".bootbox")), false);
|
||||||
await visit("/");
|
|
||||||
await click("#create-topic");
|
|
||||||
|
|
||||||
await fillIn(
|
|
||||||
"#reply-title",
|
|
||||||
"This is the new text for the title using 'quotes'"
|
|
||||||
);
|
|
||||||
|
|
||||||
await fillIn(".d-editor-input", "This is the new text for the post");
|
|
||||||
await tags.expand();
|
|
||||||
await tags.selectRowByValue("monkey");
|
|
||||||
await composerActions.expand();
|
|
||||||
await composerActions.selectRowByValue("shared_draft");
|
|
||||||
|
|
||||||
assert.equal(tags.header().value(), "monkey", "tags are not reset");
|
|
||||||
|
|
||||||
assert.equal(
|
|
||||||
find("#reply-title").val(),
|
|
||||||
"This is the new text for the title using 'quotes'"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.equal(
|
|
||||||
find("#reply-control .btn-primary.create .d-button-label").text(),
|
|
||||||
I18n.t("composer.create_shared_draft")
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.ok(find("#reply-control.composing-shared-draft").length === 1);
|
|
||||||
await click(".modal-footer .btn.btn-default");
|
|
||||||
} finally {
|
|
||||||
toggleCheckDraftPopup(false);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("hide component if no content", async assert => {
|
QUnit.test("hide component if no content", async assert => {
|
||||||
@@ -363,3 +338,78 @@ QUnit.test(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
acceptance("Composer Actions With New Topic Draft", {
|
||||||
|
loggedIn: true,
|
||||||
|
settings: {
|
||||||
|
enable_whispers: true
|
||||||
|
},
|
||||||
|
site: {
|
||||||
|
can_tag_topics: true
|
||||||
|
},
|
||||||
|
beforeEach() {
|
||||||
|
_clearSnapshots();
|
||||||
|
},
|
||||||
|
pretend(server, helper) {
|
||||||
|
server.get("draft.json", () => {
|
||||||
|
return helper.response({
|
||||||
|
draft:
|
||||||
|
'{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}',
|
||||||
|
draft_sequence: 0
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test("shared draft", async assert => {
|
||||||
|
try {
|
||||||
|
toggleCheckDraftPopup(true);
|
||||||
|
|
||||||
|
const composerActions = selectKit(".composer-actions");
|
||||||
|
const tags = selectKit(".mini-tag-chooser");
|
||||||
|
|
||||||
|
await visit("/");
|
||||||
|
await click("#create-topic");
|
||||||
|
|
||||||
|
await fillIn(
|
||||||
|
"#reply-title",
|
||||||
|
"This is the new text for the title using 'quotes'"
|
||||||
|
);
|
||||||
|
|
||||||
|
await fillIn(".d-editor-input", "This is the new text for the post");
|
||||||
|
await tags.expand();
|
||||||
|
await tags.selectRowByValue("monkey");
|
||||||
|
await composerActions.expand();
|
||||||
|
await composerActions.selectRowByValue("shared_draft");
|
||||||
|
|
||||||
|
assert.equal(tags.header().value(), "monkey", "tags are not reset");
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
find("#reply-title").val(),
|
||||||
|
"This is the new text for the title using 'quotes'"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
find("#reply-control .btn-primary.create .d-button-label").text(),
|
||||||
|
I18n.t("composer.create_shared_draft")
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.ok(find("#reply-control.composing-shared-draft").length === 1);
|
||||||
|
await click(".modal-footer .btn.btn-default");
|
||||||
|
} finally {
|
||||||
|
toggleCheckDraftPopup(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
QUnit.test("reply_as_new_topic with new_topic draft", async assert => {
|
||||||
|
await visit("/t/internationalization-localization/280");
|
||||||
|
await click(".create.reply");
|
||||||
|
const composerActions = selectKit(".composer-actions");
|
||||||
|
await composerActions.expand();
|
||||||
|
await composerActions.selectRowByValue("reply_as_new_topic");
|
||||||
|
assert.equal(
|
||||||
|
find(".bootbox .modal-body").text(),
|
||||||
|
I18n.t("composer.composer_actions.reply_as_new_topic.confirm")
|
||||||
|
);
|
||||||
|
await click(".modal-footer .btn.btn-default");
|
||||||
|
});
|
||||||
|
|||||||
@@ -366,14 +366,14 @@ QUnit.test("update post time through advanced search ui", async assert => {
|
|||||||
"it should update the search term correctly"
|
"it should update the search term correctly"
|
||||||
);
|
);
|
||||||
|
|
||||||
const postTimeSelector = selectKit(
|
|
||||||
".search-advanced-options .select-kit#postTime"
|
|
||||||
);
|
|
||||||
|
|
||||||
await visit("/search");
|
await visit("/search");
|
||||||
|
|
||||||
await fillIn(".search-query", "none");
|
await fillIn(".search-query", "none");
|
||||||
await fillIn("#search-post-date .date-picker", "2016-10-05");
|
await fillIn("#search-post-date .date-picker", "October 5, 2016");
|
||||||
|
|
||||||
|
const postTimeSelector = selectKit(
|
||||||
|
".search-advanced-options .select-kit#postTime"
|
||||||
|
);
|
||||||
await postTimeSelector.expand();
|
await postTimeSelector.expand();
|
||||||
await postTimeSelector.selectRowByValue("after");
|
await postTimeSelector.selectRowByValue("after");
|
||||||
|
|
||||||
|
|||||||
@@ -18,5 +18,10 @@ QUnit.test("Stream - resume draft", async assert => {
|
|||||||
assert.ok(find(".user-stream-item").length > 0, "has drafts");
|
assert.ok(find(".user-stream-item").length > 0, "has drafts");
|
||||||
|
|
||||||
await click(".user-stream-item .resume-draft");
|
await click(".user-stream-item .resume-draft");
|
||||||
assert.equal(find(".d-editor-input").val(), "dum de dum da ba.");
|
assert.equal(
|
||||||
|
find(".d-editor-input")
|
||||||
|
.val()
|
||||||
|
.trim(),
|
||||||
|
"A fun new topic for testing drafts."
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
"/draft.json": {
|
"/draft.json": {
|
||||||
draft:
|
draft: null,
|
||||||
'{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}',
|
|
||||||
draft_sequence: 0
|
draft_sequence: 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user