diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/__snapshots__/step_index_pattern.test.js.snap b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/__snapshots__/step_index_pattern.test.js.snap index 3c833850b2c28..8d35dfefe79c4 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/__snapshots__/step_index_pattern.test.js.snap +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/__snapshots__/step_index_pattern.test.js.snap @@ -59,6 +59,7 @@ exports[`StepIndexPattern should disable the next step if the index pattern exis }, ] } + query="k*" /> `; @@ -147,6 +148,7 @@ exports[`StepIndexPattern should properly fetch indices for the initial query 1` }, ] } + query="k*" /> `; @@ -159,11 +161,7 @@ exports[`StepIndexPattern should render normally 1`] = ` >
, |" - errors={ - Array [ - "Your input contains invalid characters or spaces. Please omit: \\\\, /, ?, \\", <, >, |", - ] - } + errors={Array []} goToNextStep={[Function]} isInputInvalid={false} isNextStepDisabled={true} @@ -212,6 +210,7 @@ exports[`StepIndexPattern should render normally 1`] = ` }, ] } + query="" /> `; @@ -275,6 +274,7 @@ exports[`StepIndexPattern should render some indices 1`] = ` }, ] } + query="k*" /> `; @@ -367,6 +367,7 @@ exports[`StepIndexPattern should show errors 1`] = ` }, ] } + query="?" /> `; diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/__tests__/__snapshots__/indices_list.test.js.snap b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/__tests__/__snapshots__/indices_list.test.js.snap index 4d725169a064d..e880a0dd94863 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/__tests__/__snapshots__/indices_list.test.js.snap +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/__tests__/__snapshots__/indices_list.test.js.snap @@ -200,6 +200,111 @@ exports[`IndicesList should change per page 1`] = ` `; +exports[`IndicesList should highlight the query in the matches 1`] = ` +
+ + + + + + + ki + + bana + + + + + + es + + + + + + + + + Rows per page: + 10 + + } + closePopover={[Function]} + id="customizablePagination" + isOpen={false} + ownFocus={false} + panelPaddingSize="none" + withTitle={true} + > + + 5 + , + + 10 + , + + 20 + , + + 50 + , + ] + } + /> + + + +
+`; + exports[`IndicesList should render normally 1`] = `
diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/__tests__/indices_list.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/__tests__/indices_list.test.js index a8e9f1eebca14..5611e30cb357c 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/__tests__/indices_list.test.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/__tests__/indices_list.test.js @@ -10,7 +10,7 @@ const indices = [ describe('IndicesList', () => { it('should render normally', () => { const component = shallow( - + ); expect(component).toMatchSnapshot(); @@ -18,7 +18,7 @@ describe('IndicesList', () => { it('should change pages', () => { const component = shallow( - + ); const instance = component.instance(); @@ -32,7 +32,7 @@ describe('IndicesList', () => { it('should change per page', () => { const component = shallow( - + ); const instance = component.instance(); @@ -42,10 +42,18 @@ describe('IndicesList', () => { expect(component).toMatchSnapshot(); }); + it('should highlight the query in the matches', () => { + const component = shallow( + + ); + + expect(component).toMatchSnapshot(); + }); + describe('updating props', () => { it('should render all new indices', () => { const component = shallow( - + ); const moreIndices = [ diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/indices_list.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/indices_list.js index bf155e7021e1b..3b90e7960fcc8 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/indices_list.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/components/indices_list/indices_list.js @@ -24,6 +24,7 @@ import { export class IndicesList extends Component { static propTypes = { indices: PropTypes.array.isRequired, + query: PropTypes.string.isRequired, } constructor(props) { @@ -129,15 +130,35 @@ export class IndicesList extends Component { ); } + highlightIndexName(indexName, query) { + const queryIdx = indexName.indexOf(query); + if (!query || queryIdx === -1) { + return indexName; + } + + const preStr = indexName.substr(0, queryIdx); + const postStr = indexName.substr(queryIdx + query.length); + + return ( + + {preStr} + {query} + {postStr} + + ); + } + render() { - const { indices } = this.props; + const { indices, query } = this.props; + + const queryWithoutWildcard = query.endsWith('*') ? query.substr(0, query.length - 1) : query; const paginatedIndices = indices.slice(this.pager.firstItemIndex, this.pager.lastItemIndex + 1); const rows = paginatedIndices.map((index, key) => { return ( - {index.name} + {this.highlightIndexName(index.name, queryWithoutWildcard)} ); diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js index c0dc22f4a7e69..604e061c62eb4 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { ILLEGAL_CHARACTERS, MAX_SEARCH_SIZE } from '../../constants'; import { getIndices, - isIndexPatternQueryValid, + containsInvalidCharacters, getMatchedIndices, canAppendWildcard, createReasonableWait @@ -139,6 +139,7 @@ export class StepIndexPattern extends Component { return ( ); @@ -170,12 +171,16 @@ export class StepIndexPattern extends Component { const errors = []; const characterList = ILLEGAL_CHARACTERS.slice(0, ILLEGAL_CHARACTERS.length - 1).join(', '); - if (!isIndexPatternQueryValid(query, ILLEGAL_CHARACTERS)) { + if (!query || !query.length || query === '.' || query === '..') { + // This is an error scenario but do not report an error + containsErrors = true; + } + else if (!containsInvalidCharacters(query, ILLEGAL_CHARACTERS)) { errors.push(`Your input contains invalid characters or spaces. Please omit: ${characterList}`); containsErrors = true; } - const isInputInvalid = showingIndexPatternQueryErrors && containsErrors; + const isInputInvalid = showingIndexPatternQueryErrors && containsErrors && errors.length > 0; const isNextStepDisabled = containsErrors || indices.length === 0 || indexPatternExists; return ( diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/contains_invalid_characters.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/contains_invalid_characters.test.js new file mode 100644 index 0000000000000..0b5b7bce678fc --- /dev/null +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/contains_invalid_characters.test.js @@ -0,0 +1,13 @@ +import { containsInvalidCharacters } from '../contains_invalid_characters'; + +describe('containsInvalidCharacters', () => { + it('should fail with illegal characters', () => { + const valid = containsInvalidCharacters('abc', ['a']); + expect(valid).toBeFalsy(); + }); + + it('should pass with no illegal characters', () => { + const valid = containsInvalidCharacters('abc', ['%']); + expect(valid).toBeTruthy(); + }); +}); diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/is_index_pattern_query_valid.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/is_index_pattern_query_valid.test.js deleted file mode 100644 index 0a6e00f6ae3fb..0000000000000 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/__tests__/is_index_pattern_query_valid.test.js +++ /dev/null @@ -1,33 +0,0 @@ -import { isIndexPatternQueryValid } from '../is_index_pattern_query_valid'; - -describe('isIndexPatternQueryValid', () => { - it('should fail with illegal characters', () => { - const valid = isIndexPatternQueryValid('abc', ['a']); - expect(valid).toBeFalsy(); - }); - - it('should pass with no illegal characters', () => { - const valid = isIndexPatternQueryValid('abc', ['%']); - expect(valid).toBeTruthy(); - }); - - it('should fail if the pattern starts with a single dot', () => { - const valid = isIndexPatternQueryValid('.'); - expect(valid).toBeFalsy(); - }); - - it('should fail if the pattern starts with a double dot', () => { - const valid = isIndexPatternQueryValid('..'); - expect(valid).toBeFalsy(); - }); - - it('should fail if no pattern is passed in', () => { - const valid = isIndexPatternQueryValid(null); - expect(valid).toBeFalsy(); - }); - - it('should fail if an empty pattern is passed in', () => { - const valid = isIndexPatternQueryValid(''); - expect(valid).toBeFalsy(); - }); -}); diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_invalid_characters.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_invalid_characters.js new file mode 100644 index 0000000000000..a79ef497b5f26 --- /dev/null +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_invalid_characters.js @@ -0,0 +1,3 @@ +export function containsInvalidCharacters(pattern, illegalCharacters) { + return !illegalCharacters.some(char => pattern.includes(char)); +} diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/index.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/index.js index be317505020c0..4a9b06543f212 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/index.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/index.js @@ -6,6 +6,6 @@ export { getIndices } from './get_indices'; export { getMatchedIndices } from './get_matched_indices'; -export { isIndexPatternQueryValid } from './is_index_pattern_query_valid'; +export { containsInvalidCharacters } from './contains_invalid_characters'; export { extractTimeFields } from './extract_time_fields'; diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/is_index_pattern_query_valid.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/is_index_pattern_query_valid.js deleted file mode 100644 index b9c76a741dd73..0000000000000 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/is_index_pattern_query_valid.js +++ /dev/null @@ -1,11 +0,0 @@ -export function isIndexPatternQueryValid(pattern, illegalCharacters) { - if (!pattern || !pattern.length) { - return false; - } - - if (pattern === '.' || pattern === '..') { - return false; - } - - return !illegalCharacters.some(char => pattern.includes(char)); -}