Skip to content
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

[EuiSearchBar] relaxed syntax around hyphens #581

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `0.0.35`.
- Relaxed query syntax of `EuiSearchBar` to allow usage of hyphens without escaping ([#581](https://github.com/elastic/eui/pull/581))

# [`0.0.35`](https://github.com/elastic/eui/tree/v0.0.35)

- Modified `link` and all buttons to support both href and onClick ([554](https://github.com/elastic/eui/pull/554))
- Added `color` prop to `EuiIconTip` ([580](https://github.com/elastic/eui/pull/580))
- Modified `link` and all buttons to support both href and onClick ([#554](https://github.com/elastic/eui/pull/554))
- Added `color` prop to `EuiIconTip` ([#580](https://github.com/elastic/eui/pull/580))

# [`0.0.34`](https://github.com/elastic/eui/tree/v0.0.34)

Expand Down
4 changes: 3 additions & 1 deletion src/components/search_bar/query/default_syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ fieldName "field name"

fieldChar
= alnum
/ [-]
/ escapedChar

fieldValue "field value"
Expand All @@ -80,13 +81,14 @@ word

valueChar
= alnum
/ [-]
/ escapedChar

escapedChar
= "\\\\" reservedChar

reservedChar
= [:\\-\\\\]
= [\-:\\\\]

alnum "alpha numeric"
= [a-zA-Z0-9]
Expand Down
54 changes: 48 additions & 6 deletions src/components/search_bar/query/default_syntax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,63 @@ describe('defaultSyntax', () => {
expect(printedQuery).toBe(query);
});

test('escaped chars as default clauses', () => {
const query = '\\- -\\: \\\\';
test('hyphen fields and values', () => {
const query = 'name-1:dash-1 -name-2:dash-2 \\-name-3:dash-3 term-1 -term-2 \\-term-3';
const ast = defaultSyntax.parse(query);

expect(ast).toBeDefined();
expect(ast.clauses).toBeDefined();
expect(ast.clauses).toHaveLength(3);
expect(ast.clauses).toHaveLength(6);

let clause = ast.getTermClause('term-1');
expect(clause).toBeDefined();
expect(AST.Term.isInstance(clause)).toBe(true);
expect(AST.Match.isMustClause(clause)).toBe(true);
expect(clause.value).toBe('term-1');

let clause = ast.getTermClause('-');
clause = ast.getTermClause('term-2');
expect(clause).toBeDefined();
expect(AST.Term.isInstance(clause)).toBe(true);
expect(AST.Match.isMustClause(clause)).toBe(false);
expect(clause.value).toBe('term-2');

clause = ast.getTermClause('-term-3');
expect(clause).toBeDefined();
expect(AST.Term.isInstance(clause)).toBe(true);
expect(AST.Match.isMustClause(clause)).toBe(true);
expect(clause.value).toBe('-term-3');

clause = ast.getSimpleFieldClause('name-1', 'dash-1');
expect(clause).toBeDefined();
expect(AST.Field.isInstance(clause)).toBe(true);
expect(AST.Match.isMustClause(clause)).toBe(true);
expect(clause.field).toBe('name-1');
expect(clause.value).toBe('dash-1');

clause = ast.getSimpleFieldClause('name-2', 'dash-2');
expect(clause).toBeDefined();
expect(AST.Field.isInstance(clause)).toBe(true);
expect(AST.Match.isMustClause(clause)).toBe(false);
expect(clause.field).toBe('name-2');
expect(clause.value).toBe('dash-2');

clause = ast.getSimpleFieldClause('-name-3', 'dash-3');
expect(clause).toBeDefined();
expect(AST.Field.isInstance(clause)).toBe(true);
expect(AST.Match.isMustClause(clause)).toBe(true);
expect(clause.value).toBe('-');
expect(clause.field).toBe('-name-3');
expect(clause.value).toBe('dash-3');
});

test('escaped chars as default clauses', () => {
const query = '-\\: \\\\';
const ast = defaultSyntax.parse(query);

expect(ast).toBeDefined();
expect(ast.clauses).toBeDefined();
expect(ast.clauses).toHaveLength(2);

clause = ast.getTermClause(':');
let clause = ast.getTermClause(':');
expect(clause).toBeDefined();
expect(AST.Term.isInstance(clause)).toBe(true);
expect(AST.Match.isMustClause(clause)).toBe(false);
Expand Down