FIX: handles boolean with popupMenuOption (#7299)

FIX: handles boolean with popupMenuOption (#7299)

Handle the case of GitHub - discourse/DiscoTOC: A Discourse theme component that generates a table of contents for topics with one click doing this kind of setup:

return {
    action: "insertDtoc",
    icon: "align-left",
    label: themePrefix("insert_table_of_contents"),
    condition: !composerController.get("model.canCategorize")
  };

In this case there’s no function to call, it’s already set.

diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6
index b69ec6f..a889780 100644
--- a/app/assets/javascripts/discourse/controllers/composer.js.es6
+++ b/app/assets/javascripts/discourse/controllers/composer.js.es6
@@ -255,10 +255,12 @@ export default Ember.Controller.extend({
   _setupPopupMenuOption(callback) {
     let option = callback();
 
-    if (option.condition) {
-      option.condition = this.get(option.condition);
-    } else {
+    if (typeof option.condition === "undefined") {
       option.condition = true;
+    } else if (typeof option.condition === "boolean") {
+      // uses existing value
+    } else {
+      option.condition = this.get(option.condition);
     }
 
     return option;

GitHub sha: 4b1b135e

2 Likes