DEV: Add plugin api for adding to search-advanced-options dropdowns (#10606)

DEV: Add plugin api for adding to search-advanced-options dropdowns (#10606)

diff --git a/app/assets/javascripts/discourse/app/components/search-advanced-options.js b/app/assets/javascripts/discourse/app/components/search-advanced-options.js
index a0675b2..80e1b9a 100644
--- a/app/assets/javascripts/discourse/app/components/search-advanced-options.js
+++ b/app/assets/javascripts/discourse/app/components/search-advanced-options.js
@@ -32,48 +32,55 @@ const REGEXP_POST_TIME_WHEN = /^(before|after)/gi;
 
 const IN_OPTIONS_MAPPING = { images: "with" };
 
+const inOptionsForUsers = [
+  { name: I18n.t("search.advanced.filters.unseen"), value: "unseen" },
+  { name: I18n.t("search.advanced.filters.posted"), value: "posted" },
+  { name: I18n.t("search.advanced.filters.created"), value: "created" },
+  { name: I18n.t("search.advanced.filters.watching"), value: "watching" },
+  { name: I18n.t("search.advanced.filters.tracking"), value: "tracking" },
+  { name: I18n.t("search.advanced.filters.bookmarks"), value: "bookmarks" },
+];
+
+const inOptionsForAll = [
+  { name: I18n.t("search.advanced.filters.first"), value: "first" },
+  { name: I18n.t("search.advanced.filters.pinned"), value: "pinned" },
+  { name: I18n.t("search.advanced.filters.wiki"), value: "wiki" },
+  { name: I18n.t("search.advanced.filters.images"), value: "images" },
+];
+
+const statusOptions = [
+  { name: I18n.t("search.advanced.statuses.open"), value: "open" },
+  { name: I18n.t("search.advanced.statuses.closed"), value: "closed" },
+  { name: I18n.t("search.advanced.statuses.public"), value: "public" },
+  { name: I18n.t("search.advanced.statuses.archived"), value: "archived" },
+  {
+    name: I18n.t("search.advanced.statuses.noreplies"),
+    value: "noreplies",
+  },
+  {
+    name: I18n.t("search.advanced.statuses.single_user"),
+    value: "single_user",
+  },
+];
+
+const postTimeOptions = [
+  { name: I18n.t("search.advanced.post.time.before"), value: "before" },
+  { name: I18n.t("search.advanced.post.time.after"), value: "after" },
+];
+
+function addAdvancedSearchOptions(options) {
+  inOptionsForAll.pushObjects(options.inOptionsForAll);
+  inOptionsForUsers.pushObjects(options.inOptionsForUsers);
+  statusOptions.pushObjects(options.statusOptions);
+  postTimeOptions.pushObjects(options.postTimeOptions);
+}
+
 export default Component.extend({
   classNames: ["search-advanced-options"],
 
   init() {
     this._super(...arguments);
 
-    this.inOptionsForUsers = [
-      { name: I18n.t("search.advanced.filters.unseen"), value: "unseen" },
-      { name: I18n.t("search.advanced.filters.posted"), value: "posted" },
-      { name: I18n.t("search.advanced.filters.created"), value: "created" },
-      { name: I18n.t("search.advanced.filters.watching"), value: "watching" },
-      { name: I18n.t("search.advanced.filters.tracking"), value: "tracking" },
-      { name: I18n.t("search.advanced.filters.bookmarks"), value: "bookmarks" },
-    ];
-
-    this.inOptionsForAll = [
-      { name: I18n.t("search.advanced.filters.first"), value: "first" },
-      { name: I18n.t("search.advanced.filters.pinned"), value: "pinned" },
-      { name: I18n.t("search.advanced.filters.wiki"), value: "wiki" },
-      { name: I18n.t("search.advanced.filters.images"), value: "images" },
-    ];
-
-    this.statusOptions = [
-      { name: I18n.t("search.advanced.statuses.open"), value: "open" },
-      { name: I18n.t("search.advanced.statuses.closed"), value: "closed" },
-      { name: I18n.t("search.advanced.statuses.public"), value: "public" },
-      { name: I18n.t("search.advanced.statuses.archived"), value: "archived" },
-      {
-        name: I18n.t("search.advanced.statuses.noreplies"),
-        value: "noreplies",
-      },
-      {
-        name: I18n.t("search.advanced.statuses.single_user"),
-        value: "single_user",
-      },
-    ];
-
-    this.postTimeOptions = [
-      { name: I18n.t("search.advanced.post.time.before"), value: "before" },
-      { name: I18n.t("search.advanced.post.time.after"), value: "after" },
-    ];
-
     this._init();
 
     scheduleOnce("afterRender", this, this._update);
@@ -111,8 +118,10 @@ export default Component.extend({
         },
       },
       inOptions: this.currentUser
-        ? this.inOptionsForUsers.concat(this.inOptionsForAll)
-        : this.inOptionsForAll,
+        ? inOptionsForUsers.concat(inOptionsForAll)
+        : inOptionsForAll,
+      statusOptions: statusOptions,
+      postTimeOptions: postTimeOptions,
     });
   },
 
@@ -651,3 +660,5 @@ export default Component.extend({
     },
   },
 });
+
+export { addAdvancedSearchOptions };
diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js
index dadfc51..e1812ff 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.js
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js
@@ -60,9 +60,10 @@ import { addQuickAccessProfileItem } from "discourse/widgets/quick-access-profil
 import KeyboardShortcuts from "discourse/lib/keyboard-shortcuts";
 import { addFeaturedLinkMetaDecorator } from "discourse/lib/render-topic-featured-link";
 import { getOwner } from "discourse-common/lib/get-owner";
+import { addAdvancedSearchOptions } from "discourse/components/search-advanced-options";
 
 // If you add any methods to the API ensure you bump up this number
-const PLUGIN_API_VERSION = "0.10.2";
+const PLUGIN_API_VERSION = "0.11.0";
 
 class PluginApi {
   constructor(version, container) {
@@ -1180,6 +1181,30 @@ class PluginApi {
   addFeaturedLinkMetaDecorator(decorator) {
     addFeaturedLinkMetaDecorator(decorator);
   }
+
+  /**
+   * Adds items to dropdown's in search-advanced-options.
+   *
+   * `‍``
+   * api.addAdvancedSearchOptions({
+   *   inOptionsForUsers:[{
+   *     name: I18n.t("search.advanced.in.assigned"),
+   *     value: "assigned",
+   *   },
+   *   {
+   *     name: I18n.t("search.advanced.in.not_assigned"),
+   *     value: "not_assigned",
+   *   },]
+   *   statusOptions: [{
+   *     name: I18n.t("search.advanced.status.open"),
+   *     value: "open"
+   *   }]
+   * `‍``
+   *
+   **/
+  addAdvancedSearchOptions(options) {
+    addAdvancedSearchOptions(options);
+  }
 }
 
 let _pluginv01;

GitHub sha: 097f06b4

1 Like

This commit appears in #10606 which was merged by davidtaylorhq.