diff --git a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx index ccbc08e5..f804ef30 100644 --- a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx +++ b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx @@ -23,8 +23,8 @@ import { EuiIcon, EuiFieldNumber, } from '@elastic/eui'; -import { Field, FieldProps } from 'formik'; -import React, { useState } from 'react'; +import { Field, FieldProps, FormikProps, useFormikContext } from 'formik'; +import React, { useEffect, useState } from 'react'; import ContentPanel from '../../../../components/ContentPanel/ContentPanel'; import { CUSTOM_AD_RESULT_INDEX_PREFIX } from '../../../../../server/utils/constants'; import { BASE_DOCS_LINK } from '../../../../utils/constants'; @@ -32,18 +32,39 @@ import { isInvalid, getError, validateCustomResultIndex, - validatePositiveInteger, + validateEmptyOrPositiveInteger, } from '../../../../utils/utils'; import { FormattedFormRow } from '../../../../components/FormattedFormRow/FormattedFormRow'; +import { DetectorDefinitionFormikValues } from '../../models/interfaces'; +import { get } from 'lodash'; interface CustomResultIndexProps { isEdit: boolean; useDefaultResultIndex?: boolean; resultIndex?: string; + formikProps: FormikProps; } function CustomResultIndex(props: CustomResultIndexProps) { const [enabled, setEnabled] = useState(!!props.resultIndex); + const [customResultIndexConditionsEnabled, setCustomResultIndexConditionsEnabled] = useState(true); + const customResultIndexMinAge = get(props.formikProps, 'values.resultIndexMinAge'); + const customResultIndexMinSize = get(props.formikProps, 'values.resultIndexMinSize'); + const customResultIndexTTL = get(props.formikProps, 'values.resultIndexTtl'); + const { setFieldValue } = useFormikContext(); + + useEffect(() => { + if (props.isEdit) { + if (customResultIndexMinAge === undefined && customResultIndexMinSize === undefined && customResultIndexTTL === undefined) { + setCustomResultIndexConditionsEnabled(false); + } + } + if (!customResultIndexConditionsEnabled) { + setFieldValue('resultIndexMinAge', ''); + setFieldValue('resultIndexMinSize', ''); + setFieldValue('resultIndexTtl', ''); + } + },[customResultIndexConditionsEnabled]) return ( ) : null} + + {enabled ? ( + + { + setCustomResultIndexConditionsEnabled(!customResultIndexConditionsEnabled); + }} + /> + + ) : null} )} - {enabled ? ( {({ field, form }: FieldProps) => ( + Min Index Age - optional +

+ } hint={[ `This setting would define a specific threshold for the age of an index. When this threshold is surpassed, a rollover will be triggered automatically.`, ]} @@ -141,6 +179,7 @@ function CustomResultIndex(props: CustomResultIndexProps) { name="resultIndexMinAge" id="resultIndexMinAge" data-test-subj="resultIndexMinAge" + placeholder="Min index age" min={1} {...field} /> @@ -157,16 +196,20 @@ function CustomResultIndex(props: CustomResultIndexProps) { )}
) : null} - {enabled ? ( {({ field, form }: FieldProps) => ( + Min Index Size - optional +

+ } hint={[ `This setting would define a specific threshold for the size of an index. When this threshold is surpassed, a rollover will be triggered automatically.`, ]} @@ -178,7 +221,7 @@ function CustomResultIndex(props: CustomResultIndexProps) { ) : null} - {enabled ? ( {({ field, form }: FieldProps) => ( + Index TTL - optional +

+ } hint={[ `This setting would define the duration after which an index is considered expired and eligible for deletion.`, ]} @@ -218,6 +265,7 @@ function CustomResultIndex(props: CustomResultIndexProps) { name="resultIndexTtl" id="resultIndexTtl" data-test-subj="resultIndexTtl" + placeholder="Index TTL" min={1} {...field} /> diff --git a/public/pages/DefineDetector/containers/DefineDetector.tsx b/public/pages/DefineDetector/containers/DefineDetector.tsx index 8c57a383..7a55182e 100644 --- a/public/pages/DefineDetector/containers/DefineDetector.tsx +++ b/public/pages/DefineDetector/containers/DefineDetector.tsx @@ -392,6 +392,7 @@ export const DefineDetector = (props: DefineDetectorProps) => { diff --git a/public/pages/DefineDetector/models/interfaces.ts b/public/pages/DefineDetector/models/interfaces.ts index d8b7f8e3..c13f5bcd 100644 --- a/public/pages/DefineDetector/models/interfaces.ts +++ b/public/pages/DefineDetector/models/interfaces.ts @@ -22,7 +22,7 @@ export interface DetectorDefinitionFormikValues { timeField: string; interval: number; windowDelay: number; - resultIndexMinAge?: number; - resultIndexMinSize?: number; - resultIndexTtl?:number; + resultIndexMinAge?: number | string; + resultIndexMinSize?: number | string; + resultIndexTtl?:number | string; } diff --git a/public/pages/DefineDetector/utils/helpers.ts b/public/pages/DefineDetector/utils/helpers.ts index 777c7441..ed3443b1 100644 --- a/public/pages/DefineDetector/utils/helpers.ts +++ b/public/pages/DefineDetector/utils/helpers.ts @@ -45,9 +45,9 @@ export function detectorDefinitionToFormik( timeField: ad.timeField, interval: get(ad, 'detectionInterval.period.interval', 10), windowDelay: get(ad, 'windowDelay.period.interval', 0), - resultIndexMinAge: get(ad, 'resultIndexMinAge', 7), - resultIndexMinSize:get(ad, 'resultIndexMinSize', 51200), - resultIndexTtl: get(ad, 'resultIndexTtl', 60), + resultIndexMinAge: get(ad, 'resultIndexMinAge', undefined), + resultIndexMinSize:get(ad, 'resultIndexMinSize', undefined), + resultIndexTtl: get(ad, 'resultIndexTtl', undefined), }; } diff --git a/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx b/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx index e67f33a0..e4335116 100644 --- a/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx +++ b/public/pages/ReviewAndCreate/components/DetectorDefinitionFields/DetectorDefinitionFields.tsx @@ -131,9 +131,13 @@ export const DetectorDefinitionFields = ( } }; - const minAge = get(props, 'detector.resultIndexMinAge', '-'); - const minSize = get(props, 'detector.resultIndexMinSize', '-'); - const ttl = get(props, 'detector.resultIndexTtl', '-'); + const minAgeValue = get(props, 'detector.resultIndexMinAge', undefined); + const minAge = (minAgeValue === undefined) ? '-' : minAgeValue + " Days"; + const minSizeValue = get(props, 'detector.resultIndexMinSize', undefined); + const minSize = (minSizeValue === undefined) ? '-' : minSizeValue + " MB"; + const ttlValue = get(props, 'detector.resultIndexTtl', undefined); + const ttl = (ttlValue === undefined) ? '-' : ttlValue + " Days"; + return (
diff --git a/public/utils/utils.tsx b/public/utils/utils.tsx index 95c42354..a2af39ff 100644 --- a/public/utils/utils.tsx +++ b/public/utils/utils.tsx @@ -110,6 +110,11 @@ export const validatePositiveInteger = (value: any) => { return 'Must be a positive integer'; }; +export const validateEmptyOrPositiveInteger = (value: any) => { + if (Number.isInteger(value) && value < 1) + return 'Must be a positive integer'; +}; + export const validateNonNegativeInteger = (value: any) => { if (!Number.isInteger(value) || value < 0) return 'Must be a non-negative integer';