removed REGEXP_IN_MATCH regex to make it flexible to use with plugins (#10476)

removed REGEXP_IN_MATCH regex to make it flexible to use with plugins (#10476)

  • dynamic regex generation for ‘STATUS’ and ‘IN’ ddropdown
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 1be0744..365f7ed 100644
--- a/app/assets/javascripts/discourse/app/components/search-advanced-options.js
+++ b/app/assets/javascripts/discourse/app/components/search-advanced-options.js
@@ -21,7 +21,6 @@ const REGEXP_MIN_POST_COUNT_PREFIX = /^min_post_count:/gi;
 const REGEXP_POST_TIME_PREFIX = /^(before|after):/gi;
 const REGEXP_TAGS_REPLACE = /(^(tags?:|#(?=[a-z0-9\-]+::tag))|::tag\s?$)/gi;
 
-const REGEXP_IN_MATCH = /^(in|with):(posted|created|watching|tracking|bookmarks|first|pinned|wiki|unseen|image)/gi;
 const REGEXP_SPECIAL_IN_LIKES_MATCH = /^in:likes/gi;
 const REGEXP_SPECIAL_IN_TITLE_MATCH = /^in:title/gi;
 const REGEXP_SPECIAL_IN_PERSONAL_MATCH = /^in:personal/gi;
@@ -129,6 +128,9 @@ export default Component.extend({
     this.setSearchedTermValueForBadge();
     this.setSearchedTermValueForTags();
 
+    let regExpInMatch = this.inOptions.map(option => option.value).join("|");
+    const REGEXP_IN_MATCH = new RegExp(`(in|with):(${regExpInMatch})`);
+
     this.setSearchedTermValue(
       "searchedTerms.in",
       REGEXP_IN_PREFIX,
@@ -155,7 +157,16 @@ export default Component.extend({
       REGEXP_SPECIAL_IN_SEEN_MATCH
     );
 
-    this.setSearchedTermValue("searchedTerms.status", REGEXP_STATUS_PREFIX);
+    let regExpStatusMatch = this.statusOptions
+      .map(status => status.value)
+      .join("|");
+    const REGEXP_STATUS_MATCH = new RegExp(`status:(${regExpStatusMatch})`);
+
+    this.setSearchedTermValue(
+      "searchedTerms.status",
+      REGEXP_STATUS_PREFIX,
+      REGEXP_STATUS_MATCH
+    );
     this.setSearchedTermValueForPostTime();
 
     this.setSearchedTermValue(
@@ -480,6 +491,9 @@ export default Component.extend({
 
   @observes("searchedTerms.in")
   updateSearchTermForIn() {
+    let regExpInMatch = this.inOptions.map(option => option.value).join("|");
+    const REGEXP_IN_MATCH = new RegExp(`(in|with):(${regExpInMatch})`);
+
     const match = this.filterBlocks(REGEXP_IN_MATCH);
     const inFilter = this.get("searchedTerms.in");
     let keyword = "in";
@@ -540,7 +554,12 @@ export default Component.extend({
 
   @observes("searchedTerms.status")
   updateSearchTermForStatus() {
-    const match = this.filterBlocks(REGEXP_STATUS_PREFIX);
+    let regExpStatusMatch = this.statusOptions
+      .map(status => status.value)
+      .join("|");
+    const REGEXP_STATUS_MATCH = new RegExp(`status:(${regExpStatusMatch})`);
+
+    const match = this.filterBlocks(REGEXP_STATUS_MATCH);
     const statusFilter = this.get("searchedTerms.status");
     let searchTerm = this.searchTerm || "";
 
diff --git a/test/javascripts/acceptance/search-full-test.js b/test/javascripts/acceptance/search-full-test.js
index 3543d28..db66d55 100644
--- a/test/javascripts/acceptance/search-full-test.js
+++ b/test/javascripts/acceptance/search-full-test.js
@@ -290,6 +290,34 @@ QUnit.test("update status through advanced search ui", async assert => {
   );
 });
 
+QUnit.test(
+  "doesn't update status filter header if wrong value entered through searchbox",
+  async assert => {
+    const statusSelector = selectKit(
+      ".search-advanced-options .select-kit#status"
+    );
+
+    await visit("/search");
+
+    await fillIn(".search-query", "status:none");
+
+    assert.equal(statusSelector.header().label(), "any", 'has "any" populated');
+  }
+);
+
+QUnit.test(
+  "doesn't update in filter header if wrong value entered through searchbox",
+  async assert => {
+    const inSelector = selectKit(".search-advanced-options .select-kit#in");
+
+    await visit("/search");
+
+    await fillIn(".search-query", "in:none");
+
+    assert.equal(inSelector.header().label(), "any", 'has "any" populated');
+  }
+);
+
 QUnit.test("update post time through advanced search ui", async assert => {
   await visit("/search?expanded=true&q=after:2018-08-22");
 

GitHub sha: b14098ce

This commit appears in #10476 which was merged by ZogStriP.