diff --git a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx index b9b6ac77ba8e8..59a0ba426894a 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx +++ b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx @@ -22,9 +22,15 @@ import { import { i18n } from '@kbn/i18n'; import { metadata } from 'ui/metadata'; +import { INDEX_PATTERN_ILLEGAL_CHARACTERS } from 'ui/index_patterns'; import { CreateAnalyticsFormProps } from '../../hooks/use_create_analytics_form'; +// based on code used by `ui/index_patterns` internally +// remove the space character from the list of illegal characters +INDEX_PATTERN_ILLEGAL_CHARACTERS.pop(); +const characterList = INDEX_PATTERN_ILLEGAL_CHARACTERS.join(', '); + export const CreateAnalyticsForm: FC = ({ actions, state }) => { const { setFormState } = actions; @@ -49,7 +55,6 @@ export const CreateAnalyticsForm: FC = ({ actions, sta jobIdValid, sourceIndex, sourceIndexNameEmpty, - sourceIndexNameExists, sourceIndexNameValid, } = form; @@ -119,39 +124,18 @@ export const CreateAnalyticsForm: FC = ({ actions, sta 'This index pattern does not contain any numeric type fields. The analytics job may not be able to come up with any outliers.', }) } - isInvalid={!sourceIndexNameEmpty && (!sourceIndexNameValid || !sourceIndexNameExists)} + isInvalid={!sourceIndexNameEmpty && !sourceIndexNameValid} error={ - (!sourceIndexNameEmpty && - !sourceIndexNameValid && [ - - {i18n.translate('xpack.ml.dataframe.analytics.create.sourceIndexInvalidError', { - defaultMessage: 'Invalid source index name.', - })} -
- - {i18n.translate( - 'xpack.ml.dataframe.stepDetailsForm.sourceIndexInvalidErrorLink', - { - defaultMessage: 'Learn more about index name limitations.', - } - )} - -
, - ]) || - (!sourceIndexNameEmpty && - !sourceIndexNameExists && [ - - {i18n.translate( - 'xpack.ml.dataframe.analytics.create.sourceIndexDoesNotExistError', - { - defaultMessage: 'An index with this name does not exist.', - } - )} - , - ]) + !sourceIndexNameEmpty && + !sourceIndexNameValid && [ + + {i18n.translate('xpack.ml.dataframe.analytics.create.sourceIndexInvalidError', { + defaultMessage: + 'Invalid source index name, it cannot contain spaces or the characters: {characterList}', + values: { characterList }, + })} + , + ] } > diff --git a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.test.ts b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.test.ts index 891a181eeb4c1..b74611fe9c77b 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.test.ts +++ b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.test.ts @@ -8,6 +8,10 @@ import { ACTION } from './actions'; import { reducer } from './reducer'; import { getInitialState } from './state'; +jest.mock('ui/index_patterns', () => ({ + validateIndexPattern: () => true, +})); + describe('useCreateAnalyticsForm', () => { test('reducer(): provide a minimum required valid job config, then reset.', () => { const initialState = getInitialState(); diff --git a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.ts b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.ts index 19b050c024f17..1c4aefcd26ced 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.ts +++ b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.ts @@ -7,6 +7,8 @@ import { idx } from '@kbn/elastic-idx'; import { i18n } from '@kbn/i18n'; +import { validateIndexPattern } from 'ui/index_patterns'; + import { isValidIndexName } from '../../../../../../common/util/es_utils'; import { isAnalyticsIdValid } from '../../../../common'; @@ -22,7 +24,7 @@ const validateAdvancedEditor = (state: State): State => { const sourceIndexName = idx(jobConfig, _ => _.source.index) || ''; const sourceIndexNameEmpty = sourceIndexName === ''; - const sourceIndexNameValid = isValidIndexName(sourceIndexName); + const sourceIndexNameValid = validateIndexPattern(sourceIndexName); const destinationIndexName = idx(jobConfig, _ => _.dest.index) || ''; const destinationIndexNameEmpty = destinationIndexName === ''; @@ -161,11 +163,9 @@ export function reducer(state: State, action: Action): State { } if (action.payload.sourceIndex !== undefined) { - newFormState.sourceIndexNameExists = state.indexNames.some( - name => newFormState.sourceIndex === name - ); newFormState.sourceIndexNameEmpty = newFormState.sourceIndex === ''; - newFormState.sourceIndexNameValid = isValidIndexName(newFormState.sourceIndex); + const validationMessages = validateIndexPattern(newFormState.sourceIndex); + newFormState.sourceIndexNameValid = Object.keys(validationMessages).length === 0; } return state.isAdvancedEditorEnabled @@ -177,9 +177,6 @@ export function reducer(state: State, action: Action): State { newState.form.destinationIndexNameExists = newState.indexNames.some( name => newState.form.destinationIndex === name ); - newState.form.sourceIndexNameExists = newState.indexNames.some( - name => newState.form.sourceIndex === name - ); return newState; } diff --git a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/state.ts b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/state.ts index 1478792112726..df462da65d322 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/state.ts +++ b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/state.ts @@ -34,7 +34,6 @@ export interface State { jobIdEmpty: boolean; jobIdValid: boolean; sourceIndex: EsIndexName; - sourceIndexNameExists: boolean; sourceIndexNameEmpty: boolean; sourceIndexNameValid: boolean; }; @@ -68,7 +67,6 @@ export const getInitialState = (): State => ({ jobIdEmpty: true, jobIdValid: false, sourceIndex: '', - sourceIndexNameExists: false, sourceIndexNameEmpty: true, sourceIndexNameValid: false, }, diff --git a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.test.tsx b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.test.tsx index 3298a7d00253f..6854b439d7382 100644 --- a/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.test.tsx +++ b/x-pack/legacy/plugins/ml/public/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/use_create_analytics_form.test.tsx @@ -12,6 +12,10 @@ import { kibanaContextValueMock } from '../../../../../contexts/kibana/__mocks__ import { getErrorMessage, useCreateAnalyticsForm } from './use_create_analytics_form'; +jest.mock('ui/index_patterns', () => ({ + validateIndexPattern: () => true, +})); + const getMountedHook = () => mountHook( () => useCreateAnalyticsForm(),