/* * SPDX-License-Identifier: Apache-2.0 * * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. * * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. */ import React from 'react'; import { EuiFormRow, EuiCodeEditor } from '@elastic/eui'; import { Field, FieldProps } from 'formik'; import { isInvalid, getError } from '../../../../utils/utils'; interface CustomAggregationProps { index: number; } export const validateQuery = (value: string) => { try { JSON.parse(value); } catch (err) { console.log('Returning error', err); return 'Invalid JSON'; } }; export const CustomAggregation = (props: CustomAggregationProps) => { return ( {({ field, form }: FieldProps) => ( { form.setFieldTouched( `featureList.${props.index}.aggregationQuery`, true ); }} > { form.setFieldValue( `featureList.${props.index}.aggregationQuery`, query ); }} onBlur={field.onBlur} value={field.value} /> )} ); };