DEV: Remove the legacy widget post menu code
This commit is contained in:
parent
9e9ac2862c
commit
41dfa00d3a
|
@ -19,7 +19,16 @@ export default class SolvedAcceptAnswerButton extends Component {
|
|||
|
||||
@action
|
||||
acceptAnswer() {
|
||||
acceptAnswer(this.args.post, this.appEvents, this.currentUser);
|
||||
const post = this.args.post;
|
||||
|
||||
acceptPost(post, this.currentUser);
|
||||
|
||||
this.appEvents.trigger("discourse-solved:solution-toggled", post);
|
||||
|
||||
post.get("topic.postStream.posts").forEach((p) => {
|
||||
p.set("topic_accepted_answer", true);
|
||||
this.appEvents.trigger("post-stream:refresh", { id: p.id });
|
||||
});
|
||||
}
|
||||
|
||||
<template>
|
||||
|
@ -34,17 +43,6 @@ export default class SolvedAcceptAnswerButton extends Component {
|
|||
</template>
|
||||
}
|
||||
|
||||
export function acceptAnswer(post, appEvents, acceptingUser) {
|
||||
// TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed
|
||||
acceptPost(post, acceptingUser);
|
||||
|
||||
appEvents.trigger("discourse-solved:solution-toggled", post);
|
||||
|
||||
post.get("topic.postStream.posts").forEach((p) => {
|
||||
p.set("topic_accepted_answer", true);
|
||||
appEvents.trigger("post-stream:refresh", { id: p.id });
|
||||
});
|
||||
}
|
||||
|
||||
function acceptPost(post, acceptingUser) {
|
||||
const topic = post.topic;
|
||||
|
|
|
@ -10,18 +10,6 @@ import { formatUsername } from "discourse/lib/utilities";
|
|||
import { i18n } from "discourse-i18n";
|
||||
import DTooltip from "float-kit/components/d-tooltip";
|
||||
|
||||
export function unacceptAnswer(post, appEvents) {
|
||||
// TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed
|
||||
unacceptPost(post);
|
||||
|
||||
appEvents.trigger("discourse-solved:solution-toggled", post);
|
||||
|
||||
post.get("topic.postStream.posts").forEach((p) => {
|
||||
p.set("topic_accepted_answer", false);
|
||||
appEvents.trigger("post-stream:refresh", { id: p.id });
|
||||
});
|
||||
}
|
||||
|
||||
function unacceptPost(post) {
|
||||
if (!post.can_unaccept_answer) {
|
||||
return;
|
||||
|
@ -48,7 +36,16 @@ export default class SolvedUnacceptAnswerButton extends Component {
|
|||
|
||||
@action
|
||||
unacceptAnswer() {
|
||||
unacceptAnswer(this.args.post, this.appEvents);
|
||||
const post = this.args.post;
|
||||
|
||||
unacceptPost(post);
|
||||
|
||||
this.appEvents.trigger("discourse-solved:solution-toggled", post);
|
||||
|
||||
post.get("topic.postStream.posts").forEach((p) => {
|
||||
p.set("topic_accepted_answer", false);
|
||||
this.appEvents.trigger("post-stream:refresh", { id: p.id });
|
||||
});
|
||||
}
|
||||
|
||||
get solvedBy() {
|
||||
|
|
|
@ -72,7 +72,7 @@ function initializeWithApi(api) {
|
|||
}
|
||||
|
||||
function customizePostMenu(api) {
|
||||
const transformerRegistered = api.registerValueTransformer(
|
||||
api.registerValueTransformer(
|
||||
"post-menu-buttons",
|
||||
({
|
||||
value: dag,
|
||||
|
@ -109,59 +109,6 @@ function customizePostMenu(api) {
|
|||
);
|
||||
}
|
||||
);
|
||||
|
||||
const silencedKey =
|
||||
transformerRegistered && "discourse.post-menu-widget-overrides";
|
||||
|
||||
withSilencedDeprecations(silencedKey, () => customizeWidgetPostMenu(api));
|
||||
}
|
||||
|
||||
function customizeWidgetPostMenu(api) {
|
||||
const currentUser = api.getCurrentUser();
|
||||
|
||||
api.addPostMenuButton("solved", (attrs) => {
|
||||
if (attrs.can_accept_answer) {
|
||||
const isOp = currentUser?.id === attrs.topicCreatedById;
|
||||
|
||||
return {
|
||||
action: "acceptAnswer",
|
||||
icon: "far-square-check",
|
||||
className: "unaccepted",
|
||||
title: "solved.accept_answer",
|
||||
label: isOp ? "solved.solution" : null,
|
||||
position: attrs.topic_accepted_answer ? "second-last-hidden" : "first",
|
||||
};
|
||||
} else if (attrs.accepted_answer) {
|
||||
if (attrs.can_unaccept_answer) {
|
||||
return {
|
||||
action: "unacceptAnswer",
|
||||
icon: "square-check",
|
||||
title: "solved.unaccept_answer",
|
||||
className: "accepted fade-out",
|
||||
position: "first",
|
||||
label: "solved.solution",
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
className: "hidden",
|
||||
disabled: "true",
|
||||
position: "first",
|
||||
beforeButton(h) {
|
||||
return h(
|
||||
"span.accepted-text",
|
||||
{
|
||||
title: i18n("solved.accepted_description"),
|
||||
},
|
||||
[
|
||||
h("span", iconNode("check")),
|
||||
h("span.accepted-label", i18n("solved.solution")),
|
||||
]
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
@ -10,7 +10,6 @@ acceptance(
|
|||
needs.user({ admin: true });
|
||||
|
||||
needs.settings({
|
||||
glimmer_post_menu_mode: "enabled",
|
||||
solved_enabled: true,
|
||||
allow_solved_on_all_topics: true,
|
||||
});
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
import { click, visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { i18n } from "discourse-i18n";
|
||||
import { postStreamWithAcceptedAnswerExcerpt } from "../helpers/discourse-solved-helpers";
|
||||
|
||||
acceptance(
|
||||
"Discourse Solved | Widget Post Menu |Accept and Unaccept",
|
||||
function (needs) {
|
||||
needs.user({ admin: true });
|
||||
|
||||
needs.settings({
|
||||
glimmer_post_menu_mode: "disabled",
|
||||
solved_enabled: true,
|
||||
allow_solved_on_all_topics: true,
|
||||
});
|
||||
|
||||
needs.pretender((server, helper) => {
|
||||
server.post("/solution/accept", () => helper.response({ success: "OK" }));
|
||||
server.post("/solution/unaccept", () =>
|
||||
helper.response({ success: "OK" })
|
||||
);
|
||||
|
||||
server.get("/t/12.json", () =>
|
||||
helper.response(postStreamWithAcceptedAnswerExcerpt(null))
|
||||
);
|
||||
});
|
||||
|
||||
test("accepting and unaccepting a post works", async function (assert) {
|
||||
await visit("/t/without-excerpt/12");
|
||||
|
||||
assert
|
||||
.dom("#post_2 .accepted")
|
||||
.exists("Unaccept button is visible")
|
||||
.hasText(i18n("solved.solution"), "Unaccept button has correct text");
|
||||
|
||||
await click("#post_2 .accepted");
|
||||
|
||||
assert.dom("#post_2 .unaccepted").exists("Accept button is visible");
|
||||
|
||||
await click("#post_2 .unaccepted");
|
||||
|
||||
assert
|
||||
.dom("#post_2 .accepted")
|
||||
.exists("Unaccept button is visible again");
|
||||
});
|
||||
}
|
||||
);
|
Loading…
Reference in New Issue