Skip to content

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

DEV: Add value transformer to New Topic button to allow UI customization based on permissions (#36599)

Juan David Martínez Cubillosdae235312220
diff --git a/frontend/discourse/app/components/create-topic-button.gjs b/frontend/discourse/app/components/create-topic-button.gjs
index 0246781c23a..9e3c5b465e2 100644
--- a/frontend/discourse/app/components/create-topic-button.gjs
+++ b/frontend/discourse/app/components/create-topic-button.gjs
@@ -1,15 +1,41 @@
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
+import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import TopicDraftsDropdown from "discourse/components/topic-drafts-dropdown";
import concatClass from "discourse/helpers/concat-class";
+import { applyValueTransformer } from "discourse/lib/transformer";
export default class CreateTopicButton extends Component {
- @tracked btnTypeClass = this.args.btnTypeClass || "btn-default";
+ @service router;
+
@tracked label = this.args.label ?? "topic.create";
btnId = this.args.btnId ?? "create-topic";
+ get btnTypeClass() {
+ return this.args.btnTypeClass || "btn-default";
+ }
+
+ get btnClasses() {
+ const additionalClasses = applyValueTransformer(
+ "create-topic-button-class",
+ [],
+ {
+ disabled: this.args.disabled,
+ canCreateTopic: this.args.canCreateTopic,
+ category: this.router.currentRoute?.attributes?.category,
+ tag: this.router.currentRoute?.attributes?.tag,
+ }
+ );
+
+ return concatClass(
+ this.args.btnClass,
+ this.btnTypeClass,
+ ...additionalClasses
+ );
+ }
+
<template>
{{#if @canCreateTopic}}
<DButton
@@ -17,7 +43,7 @@ export default class CreateTopicButton extends Component {
@icon="far-pen-to-square"
@label={{this.label}}
id={{this.btnId}}
- class={{concatClass @btnClass this.btnTypeClass}}
+ class={{this.btnClasses}}
/>
{{#if @showDrafts}}
diff --git a/frontend/discourse/app/lib/transformer/registry.js b/frontend/discourse/app/lib/transformer/registry.js
index bd54f35af0c..451fe813729 100644
--- a/frontend/discourse/app/lib/transformer/registry.js
+++ b/frontend/discourse/app/lib/transformer/registry.js
@@ -30,6 +30,7 @@ export const VALUE_TRANSFORMERS = Object.freeze([
"composer-service-cannot-submit-post",
"composer-toggles-class",
"create-topic-label",
+ "create-topic-button-class",
"flag-button-disabled-state",
"flag-button-dynamic-class",
"flag-button-render-decision",