From 644f9f65f343aafbe82a7fd59111ed971d5446a1 Mon Sep 17 00:00:00 2001 From: Milton Hultgren Date: Tue, 12 Jul 2022 09:39:38 +0100 Subject: [PATCH] [Logs UI] Disallow spaces in index pattern (#135977) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../logs/settings/indices_configuration_form_state.ts | 6 +++++- .../logs/settings/source_configuration_form_errors.tsx | 10 ++++++++++ .../public/pages/logs/settings/validation_errors.ts | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/infra/public/pages/logs/settings/indices_configuration_form_state.ts b/x-pack/plugins/infra/public/pages/logs/settings/indices_configuration_form_state.ts index d581c5feb3d6b..7165a34fb5ba1 100644 --- a/x-pack/plugins/infra/public/pages/logs/settings/indices_configuration_form_state.ts +++ b/x-pack/plugins/infra/public/pages/logs/settings/indices_configuration_form_state.ts @@ -19,6 +19,7 @@ import { FormValidationError, validateIndexPattern, validateStringNotEmpty, + validateStringNoSpaces, } from './validation_errors'; export type LogIndicesFormState = LogIndexNameReference | LogDataViewReference | undefined; @@ -35,7 +36,10 @@ export const useLogIndicesFormElement = (initialValue: LogIndicesFormState) => { if (logIndices == null) { return validateStringNotEmpty('log data view', ''); } else if (logIndexNameReferenceRT.is(logIndices)) { - return validateStringNotEmpty('log indices', logIndices.indexName); + return [ + ...validateStringNotEmpty('log indices', logIndices.indexName), + ...validateStringNoSpaces('log indices', logIndices.indexName), + ]; } else { const emptyStringErrors = validateStringNotEmpty('log data view', logIndices.dataViewId); diff --git a/x-pack/plugins/infra/public/pages/logs/settings/source_configuration_form_errors.tsx b/x-pack/plugins/infra/public/pages/logs/settings/source_configuration_form_errors.tsx index c6a185aeda7ca..e7cdf43136f3f 100644 --- a/x-pack/plugins/infra/public/pages/logs/settings/source_configuration_form_errors.tsx +++ b/x-pack/plugins/infra/public/pages/logs/settings/source_configuration_form_errors.tsx @@ -40,6 +40,16 @@ export const LogSourceConfigurationFormError: React.FC<{ error: FormValidationEr }} /> ); + } else if (error.type === 'includes_spaces') { + return ( + + ); } else if (error.type === 'empty_column_list') { return ( value === '' ? [{ type: 'empty_field', fieldName }] : []; +export const validateStringNoSpaces = (fieldName: string, value: string): FormValidationError[] => + value.includes(' ') ? [{ type: 'includes_spaces', fieldName }] : []; + export const validateColumnListNotEmpty = (columns: unknown[]): FormValidationError[] => columns.length <= 0 ? [{ type: 'empty_column_list' }] : [];