Skip to content

Commit

Permalink
[Logs UI] Disallow spaces in index pattern (#135977)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
miltonhultgren and kibanamachine authored Jul 12, 2022
1 parent 031568e commit 644f9f6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
FormValidationError,
validateIndexPattern,
validateStringNotEmpty,
validateStringNoSpaces,
} from './validation_errors';

export type LogIndicesFormState = LogIndexNameReference | LogDataViewReference | undefined;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export const LogSourceConfigurationFormError: React.FC<{ error: FormValidationEr
}}
/>
);
} else if (error.type === 'includes_spaces') {
return (
<FormattedMessage
id="xpack.infra.logSourceConfiguration.includesSpacesErrorMessage"
defaultMessage="The field '{fieldName}' must not include spaces."
values={{
fieldName: error.fieldName,
}}
/>
);
} else if (error.type === 'empty_column_list') {
return (
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export interface EmptyFieldValidationError {
fieldName: string;
}

export interface IncludesSpacesValidationError {
type: 'includes_spaces';
fieldName: string;
}

export interface EmptyColumnListValidationError {
type: 'empty_column_list';
}
Expand Down Expand Up @@ -55,6 +60,7 @@ export type FormValidationError =
| GenericValidationError
| ChildFormValidationError
| EmptyFieldValidationError
| IncludesSpacesValidationError
| EmptyColumnListValidationError
| MissingTimestampFieldValidationError
| MissingMessageFieldValidationError
Expand All @@ -65,6 +71,9 @@ export type FormValidationError =
export const validateStringNotEmpty = (fieldName: string, value: string): FormValidationError[] =>
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' }] : [];

Expand Down

0 comments on commit 644f9f6

Please sign in to comment.