/* * 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 { EuiCallOut, EuiSpacer, EuiText, EuiFlexItem, EuiFlexGroup, EuiButton, EuiLink, EuiIcon, } from '@elastic/eui'; import { FieldArray, FieldArrayRenderProps, FormikProps } from 'formik'; import { get } from 'lodash'; import React, { Fragment, useEffect } from 'react'; import ContentPanel from '../../../../components/ContentPanel/ContentPanel'; import { Detector } from '../../../../models/interfaces'; import { initialFeatureValue } from '../../utils/helpers'; import { MAX_FEATURE_NUM, BASE_DOCS_LINK } from '../../../../utils/constants'; import { FeatureAccordion } from '../FeatureAccordion'; interface FeaturesProps { detector: Detector | undefined; formikProps: FormikProps; } export function Features(props: FeaturesProps) { // If the features list is empty: push a default initial one useEffect(() => { if (get(props, 'formikProps.values.featureList', []).length === 0) { props.formikProps.setFieldValue('featureList', [initialFeatureValue()]); props.formikProps.setFieldTouched('featureList', false); } }, [props.formikProps.values.featureList]); return ( A feature is the field in your index that you use to check for anomalies. You can add up to 5 features.{' '} Learn more } > {({ push, remove, form: { values } }: FieldArrayRenderProps) => { return ( {get(props.detector, 'indices.0', '').includes(':') ? (
) : null} {values.featureList.map((feature: any, index: number) => ( { remove(index); }} index={index} feature={feature} handleChange={props.formikProps.handleChange} /> ))} = MAX_FEATURE_NUM} onClick={() => { push(initialFeatureValue()); }} > Add another feature

You can add up to{' '} {Math.max( MAX_FEATURE_NUM - values.featureList.length, 0 )}{' '} more features.

); }}
); }