Skip to content

A platform for community discussion. Free, open, simple.

FIX: Close the post admin menu when navigating away (#44510)

Kaia7c2c155f38a
diff --git a/frontend/discourse/app/components/admin-post-menu.gjs b/frontend/discourse/app/components/admin-post-menu.gjs
index fd0c0fe61f0..d18b4f91c4f 100644
--- a/frontend/discourse/app/components/admin-post-menu.gjs
+++ b/frontend/discourse/app/components/admin-post-menu.gjs
@@ -12,6 +12,17 @@ export default class AdminPostMenu extends Component {
@service currentUser;
@service siteSettings;
@service adminPostMenuButtons;
+ @service router;
+
+ constructor() {
+ super(...arguments);
+ this.router.on("routeWillChange", this.args.close);
+ }
+
+ willDestroy() {
+ super.willDestroy(...arguments);
+ this.router.off("routeWillChange", this.args.close);
+ }
get reviewUrl() {
return `/review?topic_id=${this.args.data.post.id}&status=all`;
diff --git a/frontend/discourse/tests/acceptance/post-admin-menu-test.js b/frontend/discourse/tests/acceptance/post-admin-menu-test.js
index a20224798ed..608cbf7ec05 100644
--- a/frontend/discourse/tests/acceptance/post-admin-menu-test.js
+++ b/frontend/discourse/tests/acceptance/post-admin-menu-test.js
@@ -1,4 +1,4 @@
-import { click, visit } from "@ember/test-helpers";
+import { click, currentURL, find, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
@@ -30,3 +30,38 @@ acceptance("Post - Admin Menu - Authenticated", function (needs) {
assert.dom(".add-notice").exists("the add notice button is rendered");
});
});
+
+acceptance("Post - Admin Menu - Staff", function (needs) {
+ needs.user({ admin: true, moderator: true });
+
+ test("viewing moderation history closes the menu", async function (assert) {
+ await visit("/t/internationalization-localization/280");
+ await click("#post_1 .show-more-actions");
+ await click("#post_1 .show-post-admin-menu");
+
+ assert.dom(".fk-d-menu").exists("the admin menu is open");
+ assert.dom(".moderation-history").exists("the history link is rendered");
+
+ const historyUrl = new URL(find(".moderation-history").href);
+
+ await click(".moderation-history");
+
+ const reviewUrl = new URL(currentURL(), window.location.origin);
+ assert.strictEqual(
+ reviewUrl.pathname,
+ "/review",
+ "the review page is open"
+ );
+ assert.strictEqual(
+ reviewUrl.searchParams.get("status"),
+ "all",
+ "all review statuses are included"
+ );
+ assert.strictEqual(
+ reviewUrl.searchParams.get("topic_id"),
+ historyUrl.searchParams.get("topic_id"),
+ "the history link's topic filter is preserved"
+ );
+ assert.dom(".fk-d-menu").doesNotExist("the admin menu has closed");
+ });
+});