mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[SLOs] Add/Edit form KQL Validation (#174465)
## Summary
Fixes https://github.com/elastic/kibana/issues/160390
Add/Edit form KQL Validation !!
<img width="1020" alt="image"
src="30ecaba5
-e567-4964-acb2-5d687f8a2e55">
This commit is contained in:
parent
6cf59182d1
commit
f4fb1e8d90
2 changed files with 12 additions and 1 deletions
|
@ -8,6 +8,7 @@
|
|||
import { EuiFormRow } from '@elastic/eui';
|
||||
import React, { ReactNode } from 'react';
|
||||
import { Controller, FieldPath, useFormContext } from 'react-hook-form';
|
||||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import styled from 'styled-components';
|
||||
import { kqlQuerySchema } from '@kbn/slo-schema';
|
||||
import { useCreateDataView } from '../../../../hooks/use_create_data_view';
|
||||
|
@ -59,6 +60,7 @@ export function QueryBuilder({
|
|||
}
|
||||
labelAppend={!required ? <OptionalText /> : undefined}
|
||||
isInvalid={getFieldState(name).invalid}
|
||||
error={getFieldState(name).error?.message}
|
||||
fullWidth
|
||||
>
|
||||
<Controller
|
||||
|
@ -67,6 +69,15 @@ export function QueryBuilder({
|
|||
control={control}
|
||||
rules={{
|
||||
required: Boolean(required) && Boolean(dataView),
|
||||
validate: (value) => {
|
||||
try {
|
||||
if (!dataView) return;
|
||||
const ast = fromKueryExpression(String(value));
|
||||
toElasticsearchQuery(ast, dataView);
|
||||
} catch (e) {
|
||||
return e.message;
|
||||
}
|
||||
},
|
||||
}}
|
||||
render={({ field, fieldState }) => (
|
||||
<Container>
|
||||
|
|
|
@ -80,7 +80,7 @@ export function IndexSelection() {
|
|||
trigger={{
|
||||
label: field.value || SELECT_DATA_VIEW,
|
||||
fullWidth: true,
|
||||
color: 'text',
|
||||
color: fieldState.invalid ? 'danger' : 'text',
|
||||
isLoading: isDataViewsLoading,
|
||||
'data-test-subj': 'indexSelection',
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue