mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* don't allow single astrisk
* Update form_schema.ts
* add tests
(cherry picked from commit 330c3e21ac
)
Co-authored-by: Matthew Kime <matt@mattki.me>
This commit is contained in:
parent
1d9e036c0b
commit
df3eb51f7f
3 changed files with 39 additions and 1 deletions
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { singleAstriskValidator } from './form_schema';
|
||||
import { ValidationFuncArg } from '../shared_imports';
|
||||
|
||||
describe('validators', () => {
|
||||
test('singleAstriskValidator should pass', async () => {
|
||||
const result = singleAstriskValidator({ value: 'kibana*' } as ValidationFuncArg<any, any>);
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
test('singleAstriskValidator should fail', async () => {
|
||||
const result = singleAstriskValidator({ value: '*' } as ValidationFuncArg<any, any>);
|
||||
// returns error
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
});
|
|
@ -7,9 +7,21 @@
|
|||
*/
|
||||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { fieldValidators } from '../shared_imports';
|
||||
import { fieldValidators, ValidationFunc } from '../shared_imports';
|
||||
import { INDEX_PATTERN_TYPE } from '../types';
|
||||
|
||||
export const singleAstriskValidator = (
|
||||
...args: Parameters<ValidationFunc>
|
||||
): ReturnType<ValidationFunc> => {
|
||||
const [{ value, path }] = args;
|
||||
|
||||
const message = i18n.translate('indexPatternEditor.validations.noSingleAstriskPattern', {
|
||||
defaultMessage: "A single '*' is not an allowed index pattern",
|
||||
});
|
||||
|
||||
return value === '*' ? { code: 'ERR_FIELD_MISSING', path, message } : undefined;
|
||||
};
|
||||
|
||||
export const schema = {
|
||||
title: {
|
||||
label: i18n.translate('indexPatternEditor.editor.form.titleLabel', {
|
||||
|
@ -28,6 +40,9 @@ export const schema = {
|
|||
})
|
||||
),
|
||||
},
|
||||
{
|
||||
validator: singleAstriskValidator,
|
||||
},
|
||||
],
|
||||
},
|
||||
timestampField: {
|
||||
|
|
|
@ -28,6 +28,7 @@ export type {
|
|||
ValidationFunc,
|
||||
FieldConfig,
|
||||
ValidationConfig,
|
||||
ValidationFuncArg,
|
||||
} from '../../es_ui_shared/static/forms/hook_form_lib';
|
||||
export {
|
||||
useForm,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue