-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
STSMACOM-787 Export new
advancedSearchQueryToRows
helper to be used…
… in Inventory app to reduce code duplication (#1409)
- Loading branch information
1 parent
2641cd5
commit dbb6c43
Showing
5 changed files
with
50 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const advancedSearchQueryToRows = (queryValue) => { | ||
if (!queryValue) { | ||
return []; | ||
} | ||
|
||
const splitIntoRowsRegex = /(?=\sor\s|\sand\s|\snot\s)/g; | ||
|
||
// split will return array of strings: | ||
// ['keyword==test', 'or issn=123', ...] | ||
const matches = queryValue.split(splitIntoRowsRegex).map(i => i.trim()); | ||
|
||
return matches.map((match, index) => { | ||
let bool = ''; | ||
let query = match; | ||
|
||
// first row doesn't have a bool operator | ||
if (index !== 0) { | ||
bool = match.substr(0, match.indexOf(' ')); | ||
query = match.substr(bool.length); | ||
} | ||
|
||
const splitIndexAndQueryRegex = /([^=]+)(exactPhrase|containsAll|startsWith|containsAny)(.+)/g; | ||
|
||
const rowParts = [...query.matchAll(splitIndexAndQueryRegex)]?.[0] || []; | ||
// eslint-disable-next-line no-unused-vars | ||
const [, option, _match, value] = rowParts | ||
.map(i => i.trim()) | ||
.map(i => i.replaceAll('"', '')); | ||
|
||
return { | ||
query: value, | ||
bool, | ||
searchOption: option, | ||
match: _match, | ||
}; | ||
}); | ||
}; | ||
|
||
export default advancedSearchQueryToRows; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { default } from './SearchAndSort'; | ||
export { default as makeQueryFunction } from './makeQueryFunction'; | ||
export { default as SearchAndSortQuery } from './SearchAndSortQuery'; | ||
export { default as advancedSearchQueryToRows } from './advancedSearchQueryToRows'; |