A platform for community discussion. Free, open, simple.
UX: hide disabled new topic btn (#39918)
David Battersby9d3428b4ff70
diff --git a/config/site_settings.yml b/config/site_settings.ymlindex fa927765568..60f7f3d229e 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -1552,6 +1552,10 @@ posting:client: truedefault: falsearea: "posts_and_topics"+ hide_disabled_create_topic_button:+ client: true+ default: false+ hidden: trueshow_pinned_excerpt_mobile:client: truedefault: truediff --git a/frontend/discourse/app/components/discovery/navigation.gjs b/frontend/discourse/app/components/discovery/navigation.gjsindex 9b2b666f737..3d4e8ee5adf 100644--- a/frontend/discourse/app/components/discovery/navigation.gjs+++ b/frontend/discourse/app/components/discovery/navigation.gjs@@ -24,6 +24,7 @@ export default class DiscoveryNavigation extends Component {@service currentUser;@service modal;@service router;+ @service siteSettings;get filterMode() {return calculateFilterMode({@@ -38,7 +39,18 @@ export default class DiscoveryNavigation extends Component {}get canCreateTopic() {- return this.currentUser?.can_create_topic;+ if (!this.currentUser?.can_create_topic) {+ return false;+ }++ if (+ this.siteSettings.hide_disabled_create_topic_button &&+ this.args.createTopicDisabled+ ) {+ return false;+ }++ return true;}get bodyClass() {diff --git a/frontend/discourse/tests/acceptance/create-topic-button-visibility-test.js b/frontend/discourse/tests/acceptance/create-topic-button-visibility-test.jsnew file mode 100644index 00000000000..fb99507d05f--- /dev/null+++ b/frontend/discourse/tests/acceptance/create-topic-button-visibility-test.js@@ -0,0 +1,63 @@+import { visit } from "@ember/test-helpers";+import { test } from "qunit";+import DiscoveryFixtures from "discourse/tests/fixtures/discovery-fixtures";+import { acceptance } from "discourse/tests/helpers/qunit-helpers";++acceptance(+ "Create Topic button visibility - hide_disabled_create_topic_button",+ function (needs) {+ needs.user();+ needs.pretender((server, helper) => {+ server.get("/c/writable-category/7/l/latest.json", () => {+ return helper.response(+ DiscoveryFixtures["/latest_can_create_topic.json"]+ );+ });+ server.get("/c/read-only-category/8/l/latest.json", () => {+ return helper.response(+ DiscoveryFixtures["/latest_can_create_topic.json"]+ );+ });+ });+ needs.site({+ categories: [+ {+ id: 7,+ name: "writable category",+ slug: "writable-category",+ permission: 1,+ },+ {+ id: 8,+ name: "read only category",+ slug: "read-only-category",+ permission: null,+ },+ ],+ });++ test("shows the button on writable categories when setting is enabled", async function (assert) {+ this.siteSettings.hide_disabled_create_topic_button = true;++ await visit("/c/writable-category");++ assert.dom("#create-topic").exists();+ });++ test("hides the button on read-only categories when setting is enabled", async function (assert) {+ this.siteSettings.hide_disabled_create_topic_button = true;++ await visit("/c/read-only-category");++ assert.dom("#create-topic").doesNotExist();+ });++ test("shows the button on read-only categories when setting is disabled", async function (assert) {+ this.siteSettings.hide_disabled_create_topic_button = false;++ await visit("/c/read-only-category");++ assert.dom("#create-topic").exists();+ });+ }+);