import { i18n } from '@kbn/i18n' ; import { ValidationFunc , fieldValidators } from '../../shared_imports' ; export { queryFieldValidation } from '../../common/validations' ; const idPattern = /^[a-zA-Z0-9-_]+$/ ; export const idSchemaValidation = ( { value } ) => { const valueIsValid = idPattern . test ( value ) ; if ( ! valueIsValid ) { return { message : i18n . translate ( 'xpack.osquery.pack.queryFlyoutForm.invalidIdError' , { defaultMessage : 'Characters must be alphanumeric, _, or -' , } ) , } ; } } ; const createUniqueIdValidation = ( ids ) => { const uniqueIdCheck = ( { value } ) => { if ( ids . has ( value ) ) { return { message : i18n . translate ( 'xpack.osquery.pack.queryFlyoutForm.uniqueIdError' , { defaultMessage : 'ID must be unique' , } ) , } ; } } ; return uniqueIdCheck ; } ; export const createIdFieldValidations = ( ids ) => [ fieldValidators . emptyField ( i18n . translate ( 'xpack.osquery.pack.queryFlyoutForm.emptyIdError' , { defaultMessage : 'ID is required' , } ) ) , idSchemaValidation , createUniqueIdValidation ( ids ) , ] ; export const intervalFieldValidation = fieldValidators . numberGreaterThanField ( { than : 0 , message : i18n . translate ( 'xpack.osquery.pack.queryFlyoutForm.invalidIntervalField' , { defaultMessage : 'A positive interval value is required' , } ) , } ) ;