Skip to content

Commit

Permalink
fix ES|QL query required validator
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed Nov 27, 2024
1 parent cbd97a8 commit 7a474af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { FieldConfig } from '../../../../shared_imports';
import { UseField } from '../../../../shared_imports';
import type { FieldValueQueryBar } from '../../../rule_creation_ui/components/query_bar_field';
import { QueryBarField } from '../../../rule_creation_ui/components/query_bar_field';
import { esqlQueryRequiredValidatorFactory } from './validators/esql_query_required_validator_factory';
import { esqlQueryRequiredValidator } from './validators/esql_query_required_validator';
import { esqlQueryValidatorFactory } from './validators/esql_query_validator_factory';
import { EsqlInfoIcon } from './esql_info_icon';
import * as i18n from './translations';
Expand Down Expand Up @@ -62,7 +62,7 @@ export const EsqlQueryEdit = memo(function EsqlQueryEdit({
...(required
? [
{
validator: esqlQueryRequiredValidatorFactory(),
validator: esqlQueryRequiredValidator,
},
]
: []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,14 @@ import { fieldValidators, type FormData, type ValidationFunc } from '../../../..
import type { FieldValueQueryBar } from '../../../../rule_creation_ui/components/query_bar_field';
import * as i18n from './translations';

export function esqlQueryRequiredValidatorFactory(): ValidationFunc<
FormData,
string,
FieldValueQueryBar
> {
return async (data) => {
const { value } = data;
const esqlQuery = value.query.query as string;
export const esqlQueryRequiredValidator: ValidationFunc<FormData, string, FieldValueQueryBar> = (
data
) => {
const { value } = data;
const esqlQuery = value.query.query as string;

if (esqlQuery.trim() === '') {
return;
}

return fieldValidators.emptyField(i18n.ESQL_QUERY_VALIDATION_REQUIRED)({
...data,
value: esqlQuery,
});
};
}
return fieldValidators.emptyField(i18n.ESQL_QUERY_VALIDATION_REQUIRED)({
...data,
value: esqlQuery,
});
};

0 comments on commit 7a474af

Please sign in to comment.