mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[data views] don't allow single *
index pattern (#124906)
* don't allow single astrisk * Update form_schema.ts * add tests
This commit is contained in:
parent
ec323617b5
commit
330c3e21ac
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 { i18n } from '@kbn/i18n';
|
||||||
import { fieldValidators } from '../shared_imports';
|
import { fieldValidators, ValidationFunc } from '../shared_imports';
|
||||||
import { INDEX_PATTERN_TYPE } from '../types';
|
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 = {
|
export const schema = {
|
||||||
title: {
|
title: {
|
||||||
label: i18n.translate('indexPatternEditor.editor.form.titleLabel', {
|
label: i18n.translate('indexPatternEditor.editor.form.titleLabel', {
|
||||||
|
@ -28,6 +40,9 @@ export const schema = {
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
validator: singleAstriskValidator,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
timestampField: {
|
timestampField: {
|
||||||
|
|
|
@ -28,6 +28,7 @@ export type {
|
||||||
ValidationFunc,
|
ValidationFunc,
|
||||||
FieldConfig,
|
FieldConfig,
|
||||||
ValidationConfig,
|
ValidationConfig,
|
||||||
|
ValidationFuncArg,
|
||||||
} from '../../es_ui_shared/static/forms/hook_form_lib';
|
} from '../../es_ui_shared/static/forms/hook_form_lib';
|
||||||
export {
|
export {
|
||||||
useForm,
|
useForm,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue