-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
handle EuiSearchBar query parse failures #25235
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2a48f85
handle EuiSearchBar query parse failures
nreese 534de7e
I18n parse failure messages
nreese 90bb21b
Merge branch 'master' of github.com:elastic/kibana into issue-25143
nreese 386c5f6
review updates
nreese 8481ba0
more cleanup on settings search.test
nreese 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 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
103 changes: 53 additions & 50 deletions
103
...a/public/management/sections/settings/components/search/__snapshots__/search.test.js.snap
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,58 +1,61 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Search should render normally 1`] = ` | ||
<EuiSearchBar | ||
box={ | ||
Object { | ||
"aria-label": "Search advanced settings", | ||
"incremental": true, | ||
} | ||
} | ||
filters={ | ||
Array [ | ||
<React.Fragment> | ||
<EuiSearchBar | ||
box={ | ||
Object { | ||
"field": "category", | ||
"multiSelect": "or", | ||
"name": "Category", | ||
"options": Array [ | ||
Object { | ||
"name": "General", | ||
"value": "general", | ||
}, | ||
Object { | ||
"name": "Dashboard", | ||
"value": "dashboard", | ||
}, | ||
Object { | ||
"name": "HiddenCategory", | ||
"value": "hiddenCategory", | ||
}, | ||
Object { | ||
"name": "X-pack", | ||
"value": "x-pack", | ||
"aria-label": "Search advanced settings", | ||
"data-test-subj": "settingsSearchBar", | ||
"incremental": true, | ||
} | ||
} | ||
filters={ | ||
Array [ | ||
Object { | ||
"field": "category", | ||
"multiSelect": "or", | ||
"name": "Category", | ||
"options": Array [ | ||
Object { | ||
"name": "General", | ||
"value": "general", | ||
}, | ||
Object { | ||
"name": "Dashboard", | ||
"value": "dashboard", | ||
}, | ||
Object { | ||
"name": "HiddenCategory", | ||
"value": "hiddenCategory", | ||
}, | ||
Object { | ||
"name": "X-pack", | ||
"value": "x-pack", | ||
}, | ||
], | ||
"type": "field_value_selection", | ||
}, | ||
] | ||
} | ||
onChange={[Function]} | ||
query={ | ||
Query { | ||
"ast": _AST { | ||
"_clauses": Array [], | ||
"_indexedClauses": Object { | ||
"field": Object {}, | ||
"is": Object {}, | ||
"term": Array [], | ||
}, | ||
], | ||
"type": "field_value_selection", | ||
}, | ||
] | ||
} | ||
onChange={[Function]} | ||
query={ | ||
Query { | ||
"ast": _AST { | ||
"_clauses": Array [], | ||
"_indexedClauses": Object { | ||
"field": Object {}, | ||
"is": Object {}, | ||
"term": Array [], | ||
}, | ||
}, | ||
"syntax": Object { | ||
"parse": [Function], | ||
"print": [Function], | ||
}, | ||
"text": "", | ||
"syntax": Object { | ||
"parse": [Function], | ||
"print": [Function], | ||
}, | ||
"text": "", | ||
} | ||
} | ||
} | ||
/> | ||
/> | ||
</React.Fragment> | ||
`; |
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 |
---|---|---|
|
@@ -17,12 +17,13 @@ | |
* under the License. | ||
*/ | ||
|
||
import React, { PureComponent } from 'react'; | ||
import React, { Fragment, PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { injectI18n } from '@kbn/i18n/react'; | ||
|
||
import { | ||
EuiSearchBar, | ||
EuiFormErrorText, | ||
} from '@elastic/eui'; | ||
|
||
import { getCategoryName } from '../../lib'; | ||
|
@@ -46,11 +47,33 @@ class SearchUI extends PureComponent { | |
}); | ||
} | ||
|
||
state = { | ||
isSearchTextValid: true, | ||
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. Same suggestion here as in the other component. |
||
parseErrorMessage: null, | ||
} | ||
|
||
onChange = ({ query, error }) => { | ||
if (error) { | ||
this.setState({ | ||
isSearchTextValid: false, | ||
parseErrorMessage: error.message, | ||
}); | ||
return; | ||
} | ||
|
||
this.setState({ | ||
isSearchTextValid: true, | ||
parseErrorMessage: null, | ||
}); | ||
this.props.onQueryChange({ query }); | ||
} | ||
|
||
render() { | ||
const { query, onQueryChange, intl } = this.props; | ||
const { query, intl } = this.props; | ||
|
||
const box = { | ||
incremental: true, | ||
'data-test-subj': 'settingsSearchBar', | ||
'aria-label': intl.formatMessage({ | ||
id: 'kbn.management.settings.searchBarAriaLabel', | ||
defaultMessage: 'Search advanced settings', | ||
|
@@ -71,14 +94,29 @@ class SearchUI extends PureComponent { | |
} | ||
]; | ||
|
||
return ( | ||
<EuiSearchBar | ||
box={box} | ||
filters={filters} | ||
onChange={onQueryChange} | ||
query={query} | ||
/> | ||
let queryParseError; | ||
if (!this.state.isSearchTextValid) { | ||
const parseErrorMsg = intl.formatMessage({ | ||
id: 'kbn.management.settings.searchBar.unableToParseQueryErrorMessage', | ||
defaultMessage: 'Unable to parse query', | ||
}); | ||
queryParseError = ( | ||
<EuiFormErrorText> | ||
{`${parseErrorMsg}. ${this.state.parseErrorMessage}`} | ||
</EuiFormErrorText> | ||
); | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<EuiSearchBar | ||
box={box} | ||
filters={filters} | ||
onChange={this.onChange} | ||
query={query} | ||
/> | ||
{queryParseError} | ||
</Fragment> | ||
); | ||
} | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe set
parseErrorMessage: null
here, to give people one place to see all of the state properties in use?