-
Notifications
You must be signed in to change notification settings - Fork 10
feat(datasource-customizer): implement gmail-style search #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
913d772
feat(datasource-customizer): implement some features of gmail-style s…
romain-gilliotte 27efed3
test: coverage
romain-gilliotte 947c56c
feat: better support
romain-gilliotte 9828668
fix: bugs
romain-gilliotte 1909658
test: coverage
romain-gilliotte 6c63d16
fix: revert useless change
romain-gilliotte f6890f4
fix: emulate NotIContains
romain-gilliotte 5d9a614
test: fix
romain-gilliotte 07ddbe8
fix: coverage
romain-gilliotte af4bb60
fix: improve has operator
romain-gilliotte 9fbfa50
fix: allow dash in fieldname
romain-gilliotte 98b68e1
chore: merge remote-tracking branch 'origin/main' into feat/search
fa4f074
feat: use a real parser to support more syntaxes
721215a
feat: specify properties from relationships when searching
b1996e1
chore: merge remote-tracking branch 'origin/main' into feat/search
ab1bccd
feat: detect dates only between 1800 and now + 100years
93de23b
ci: fix eslint config
8dace90
chore: update dependencies
30e0231
refactor: fix linting issues
0f577cf
refactor: fix paths
a51e58f
fix: parsing behavior
dacab68
fix: fix regressions detected with tests
2672dd8
chore: rollback unwanted changes on config
57ed8b7
fix: declare that search can be null and not only undefined to avoid …
a1d36f2
fix: return matchAll when conditions are negated
05acbe8
feat: add support for month dates
440ec98
test: update tests
f6639b0
test: update tests
d7081af
feat: implement operators priority and parenthesis
8af26e4
test: add tests
4dd0c44
fix: allow trailing spaces
12b5ae7
fix: return the right default condition
9d86cda
refactor: declare the default condition only once
cee5467
fix: relax constraints on parenthesis
c100c1e
chore: merge remote-tracking branch 'origin/main' into feat/search
2d7425f
refactor: throw an error if the query is empty
81e246b
refactor: remove useless conditions
95169a3
test: add tests on buildBooleanFieldFilter
a0c534a
test: add tests for buildDateFieldFilter
1a10b87
test: add tests for boolean filters
118d105
feat: add support for array types and add tests
8a16859
feat: add better support for array types
12478e0
test: add tests
27c8322
feat: support new operators on number fields and add tests
ccc0204
test: add tests on number arrays
0b54e37
test: add tests on string fields
0f91f48
test: remove test on case-insensitive search
4efd675
feat: add the IncludesNone operator to improve search in arrays (WIP)
5c87e56
test: add tests on operator IncludesNone
09f95e6
test: fix tests
3582fdc
test: add test
9bc6374
test: add tests
4f11a93
test: fix tests
03d1a7c
test: update tests and conditions
559c29e
test: add tests
41276e4
test: fix tests
08194e0
test: update tests
3bda75d
fix: import index
fd24bb9
fix: parser definition
b9eb59c
fix: correctly parse 2 chars property names and add tests
19b9be3
test: add tests
82d63e7
test: add tests
f371d16
chore: update jest config
444f221
chore: remove generated code from CC
8e56681
chore: rollback changes on vscode settings
4be1aaa
chore: merge remote-tracking branch 'origin/main' into feat/search
11c315b
fix: support timezones in date search
205fce0
docs: add documentation about generated code
9b9d49b
chore: update yarn lock
1367a07
test: fix test
7afd86a
docs: add documentation on grammar file
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,10 +1,11 @@ | ||
| version: '2' # required to adjust maintainability checks | ||
| version: "2" # required to adjust maintainability checks | ||
|
|
||
| checks: | ||
| method-complexity: | ||
| enabled: true | ||
| config: | ||
| threshold: 10 | ||
| exclude_patterns: | ||
| - 'packages/_example/' | ||
| - '**/test/' | ||
| - "packages/_example/" | ||
| - "**/test/" | ||
| - "packages/datasource-customizer/src/decorators/search/generated-parser/*.ts" |
This file contains hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
| module.exports = { | ||
| ignorePatterns: ['src/decorators/search/generated-parser/**/*'], | ||
| }; |
This file contains hidden or 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
45 changes: 45 additions & 0 deletions
45
packages/datasource-customizer/src/decorators/search/Query.g4
This file contains hidden or 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,45 @@ | ||
| // | ||
| // This file contains the description of the supported syntax for search queries. | ||
| // It is used by the ANTLR parser generator to generate the parser. | ||
| // To support additional syntax, this file must be updated and the parser regenerated. | ||
| // It requires antlr4-tools to be installed on your machine | ||
| // | ||
| grammar Query; | ||
ghusse marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to link to some doc from here. If anybody stumbles upon this file they'll be able to look it up |
||
|
|
||
| query: (and | or | queryToken | parenthesized) EOF; | ||
|
|
||
| parenthesized: PARENS_OPEN (or | and) PARENS_CLOSE; | ||
| PARENS_OPEN: '(' ' '*; | ||
| PARENS_CLOSE: ' '* ')'; | ||
|
|
||
| // OR is a bit different because of operator precedence | ||
| or: (and | queryToken | parenthesized) (SEPARATOR OR SEPARATOR (and | queryToken | parenthesized))+; | ||
| OR: 'OR'; | ||
|
|
||
| and: (queryToken | parenthesized) (SEPARATOR (AND SEPARATOR)? (queryToken | parenthesized))+; | ||
| AND: 'AND'; | ||
|
|
||
| queryToken: (quoted | negated | propertyMatching | word); | ||
|
|
||
|
|
||
| quoted: SINGLE_QUOTED | DOUBLE_QUOTED; | ||
| SINGLE_QUOTED: '\'' SINGLE_QUOTED_CONTENT '\'' | '\'' '\''; | ||
| fragment SINGLE_QUOTED_CONTENT:~[']*; | ||
| DOUBLE_QUOTED: '"' DOUBLE_QUOTED_CONTENT '"' | '"' '"'; | ||
| fragment DOUBLE_QUOTED_CONTENT: ~["]*; | ||
|
|
||
| negated: NEGATION (word | quoted | propertyMatching); | ||
| NEGATION: '-'; | ||
|
|
||
| propertyMatching: name ':' value; | ||
| name: TOKEN; | ||
| value: word | quoted; | ||
|
|
||
| word: TOKEN; | ||
| TOKEN: ONE_CHAR_TOKEN | TWO_CHARS_TOKEN | MULTIPLE_CHARS_TOKEN; | ||
| fragment ONE_CHAR_TOKEN: ~[\r\n :\-()]; | ||
| fragment TWO_CHARS_TOKEN: ~[\r\n :\-(]~[\r\n :)]; | ||
| fragment MULTIPLE_CHARS_TOKEN:~[\r\n :\-(]~[\r\n :]+~[\r\n :)]; | ||
|
|
||
| SEPARATOR: SPACING+ | EOF; | ||
| SPACING: [\r\n ]; | ||
42 changes: 42 additions & 0 deletions
42
packages/datasource-customizer/src/decorators/search/collection-search-context.ts
This file contains hidden or 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,42 @@ | ||
| import { Caller, Collection, ConditionTree } from '@forestadmin/datasource-toolkit'; | ||
|
|
||
| import CollectionCustomizationContext from '../../context/collection-context'; | ||
| import { TCollectionName, TColumnName, TSchema } from '../../templates'; | ||
|
|
||
| export type SearchOptions< | ||
| S extends TSchema = TSchema, | ||
| N extends TCollectionName<S> = TCollectionName<S>, | ||
| > = { | ||
| /** | ||
| * Include fields from the first level of relations | ||
| */ | ||
| extended?: boolean; | ||
| /** | ||
| * Remove these fields from the default search fields | ||
| */ | ||
| excludeFields?: Array<TColumnName<S, N>>; | ||
| /** | ||
| * Add these fields to the default search fields | ||
| */ | ||
| includeFields?: Array<TColumnName<S, N>>; | ||
| /** | ||
| * Replace the list of default searched field by these fields | ||
| */ | ||
| onlyFields?: Array<TColumnName<S, N>>; | ||
| }; | ||
|
|
||
| export default class CollectionSearchContext< | ||
| S extends TSchema = TSchema, | ||
| N extends TCollectionName<S> = TCollectionName<S>, | ||
| > extends CollectionCustomizationContext<S, N> { | ||
| constructor( | ||
| collection: Collection, | ||
| caller: Caller, | ||
| public readonly generateSearchFilter: ( | ||
| searchText: string, | ||
| options?: SearchOptions<S, N>, | ||
| ) => ConditionTree, | ||
| ) { | ||
| super(collection, caller); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.