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

* dynamic regex generation for 'STATUS' and 'IN' ddropdown
This commit is contained in:
Ahmed Gagan 2020-09-01 18:03:05 +05:30 committed by GitHub
parent 34478760b2
commit b14098ce28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 3 deletions

View File

@ -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 || "";

View File

@ -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");