diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js index 16da9009f5d5fb..9ef4a3e38ee9bb 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/__tests__/render.test.js @@ -22,6 +22,12 @@ const unmountComponentAtNode = jest.fn(); jest.doMock('react-dom', () => ({ render, unmountComponentAtNode })); +// If we don't mock this, Jest fails with the error `TypeError: Cannot redefine property: prototype +// at Function.defineProperties`. +jest.mock('ui/index_patterns', () => ({ + INDEX_PATTERN_ILLEGAL_CHARACTERS: ['\\', '/', '?', '"', '<', '>', '|', ' '], +})); + jest.mock('ui/chrome', () => ({ getUiSettingsClient: () => ({ get: () => '', diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js index 3b05ec4b71ec47..37df9762b54df8 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/components/step_index_pattern/__tests__/step_index_pattern.test.js @@ -26,6 +26,12 @@ jest.mock('../../../lib/ensure_minimum_time', () => ({ ensureMinimumTime: async (promises) => Array.isArray(promises) ? await Promise.all(promises) : await promises })); +// If we don't mock this, Jest fails with the error `TypeError: Cannot redefine property: prototype +// at Function.defineProperties`. +jest.mock('ui/index_patterns', () => ({ + INDEX_PATTERN_ILLEGAL_CHARACTERS: ['\\', '/', '?', '"', '<', '>', '|', ' '], +})); + jest.mock('ui/chrome', () => ({ getUiSettingsClient: () => ({ get: () => '', 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 bf6468c3bf15ba..133154de526191 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 @@ -19,10 +19,11 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import { ILLEGAL_CHARACTERS, MAX_SEARCH_SIZE } from '../../constants'; +import { INDEX_PATTERN_ILLEGAL_CHARACTERS as ILLEGAL_CHARACTERS } from 'ui/index_patterns'; +import { MAX_SEARCH_SIZE } from '../../constants'; import { getIndices, - containsInvalidCharacters, + containsIllegalCharacters, getMatchedIndices, canAppendWildcard, ensureMinimumTime @@ -240,7 +241,7 @@ export class StepIndexPatternComponent extends Component { // This is an error scenario but do not report an error containsErrors = true; } - else if (!containsInvalidCharacters(query, ILLEGAL_CHARACTERS)) { + else if (containsIllegalCharacters(query, ILLEGAL_CHARACTERS)) { const errorMessage = intl.formatMessage( { id: 'kbn.management.createIndexPattern.step.invalidCharactersErrorMessage', diff --git a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js index 79bdbaed0d7328..86246903b44409 100644 --- a/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js +++ b/src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/constants/index.js @@ -26,4 +26,3 @@ export const MAX_NUMBER_OF_MATCHING_INDICES = 100; export const MAX_SEARCH_SIZE = MAX_NUMBER_OF_MATCHING_INDICES + ESTIMATED_NUMBER_OF_SYSTEM_INDICES; export const PER_PAGE_INCREMENTS = [5, 10, 20, 50]; -export const ILLEGAL_CHARACTERS = ['\\', '/', '?', '"', '<', '>', '|', ' ']; 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 index 2385f3baec6bc4..05c4aba2571bd0 100644 --- 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 @@ -17,16 +17,16 @@ * under the License. */ -import { containsInvalidCharacters } from '../contains_invalid_characters'; +import { containsIllegalCharacters } from '../contains_illegal_characters'; -describe('containsInvalidCharacters', () => { - it('should fail with illegal characters', () => { - const valid = containsInvalidCharacters('abc', ['a']); - expect(valid).toBeFalsy(); +describe('containsIllegalCharacters', () => { + it('returns true with illegal characters', () => { + const isInvalid = containsIllegalCharacters('abc', ['a']); + expect(isInvalid).toBe(true); }); - it('should pass with no illegal characters', () => { - const valid = containsInvalidCharacters('abc', ['%']); - expect(valid).toBeTruthy(); + it('returns false with no illegal characters', () => { + const isInvalid = containsIllegalCharacters('abc', ['%']); + expect(isInvalid).toBe(false); }); }); 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_illegal_characters.js similarity index 86% rename from src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_invalid_characters.js rename to src/core_plugins/kibana/public/management/sections/indices/create_index_pattern_wizard/lib/contains_illegal_characters.js index 5dbe3d71110616..31485bb3daaa2b 100644 --- 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_illegal_characters.js @@ -17,6 +17,6 @@ * under the License. */ -export function containsInvalidCharacters(pattern, illegalCharacters) { - return !illegalCharacters.some(char => pattern.includes(char)); +export function containsIllegalCharacters(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 22efa498c84ab7..0930eb82514e10 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 @@ -25,6 +25,6 @@ export { getIndices } from './get_indices'; export { getMatchedIndices } from './get_matched_indices'; -export { containsInvalidCharacters } from './contains_invalid_characters'; +export { containsIllegalCharacters } from './contains_illegal_characters'; export { extractTimeFields } from './extract_time_fields'; diff --git a/src/ui/public/index_patterns/constants/index.js b/src/ui/public/index_patterns/constants/index.js new file mode 100644 index 00000000000000..b22c1682173ca4 --- /dev/null +++ b/src/ui/public/index_patterns/constants/index.js @@ -0,0 +1,21 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export const INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE = ['\\', '/', '?', '"', '<', '>', '|']; +export const INDEX_PATTERN_ILLEGAL_CHARACTERS = INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.concat(' '); diff --git a/src/ui/public/index_patterns/index.js b/src/ui/public/index_patterns/index.js index 025c0248b08485..5df0b7bb8a6140 100644 --- a/src/ui/public/index_patterns/index.js +++ b/src/ui/public/index_patterns/index.js @@ -18,6 +18,12 @@ */ export { IndexPatternsProvider } from './index_patterns'; + export { IndexPatternsApiClientProvider, } from './index_patterns_api_client_provider'; + +export { + INDEX_PATTERN_ILLEGAL_CHARACTERS, + INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, +} from './constants';