From d6311a372be25f732bc697a65079f880c5553f89 Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Wed, 7 Aug 2024 13:46:50 -0700 Subject: [PATCH 1/2] Add Enable Flattened custom result index checkbox (#830) * Add Enable Flattened custom result index checkbox Signed-off-by: Jackie Han * add hint text Signed-off-by: Jackie Han --------- Signed-off-by: Jackie Han --- public/models/interfaces.ts | 1 + .../CustomResultIndex/CustomResultIndex.tsx | 75 +++++++++++++++---- .../containers/DefineDetector.tsx | 1 + .../DefineDetector.test.tsx.snap | 30 ++++++++ .../pages/DefineDetector/models/interfaces.ts | 1 + .../utils/__tests__/helpers.test.tsx | 2 + .../pages/DefineDetector/utils/constants.tsx | 3 +- public/pages/DefineDetector/utils/helpers.ts | 2 + .../DetectorConfig.test.tsx.snap | 68 +++++++++++++++++ .../DetectorDefinitionFields.tsx | 10 ++- .../DetectorDefinitionFields.test.tsx | 5 +- .../DetectorDefinitionFields.test.tsx.snap | 68 +++++++++++++++++ .../ReviewAndCreate.test.tsx.snap | 68 +++++++++++++++++ public/pages/ReviewAndCreate/utils/helpers.ts | 6 +- public/redux/reducers/__tests__/utils.ts | 3 +- 15 files changed, 322 insertions(+), 21 deletions(-) diff --git a/public/models/interfaces.ts b/public/models/interfaces.ts index f5a62568..74a0a1e6 100644 --- a/public/models/interfaces.ts +++ b/public/models/interfaces.ts @@ -194,6 +194,7 @@ export type Detector = { resultIndexMinAge?: number; resultIndexMinSize?: number; resultIndexTtl?: number; + flattenCustomResultIndex?: boolean; filterQuery: { [key: string]: any }; featureAttributes: FeatureAttributes[]; windowDelay: { period: Schedule }; diff --git a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx index c5b6447b..27e85589 100644 --- a/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx +++ b/public/pages/DefineDetector/components/CustomResultIndex/CustomResultIndex.tsx @@ -48,6 +48,7 @@ interface CustomResultIndexProps { function CustomResultIndex(props: CustomResultIndexProps) { const [enabled, setEnabled] = useState(!!props.resultIndex); const [customResultIndexConditionsEnabled, setCustomResultIndexConditionsEnabled] = useState(true); + const [isDisabled, setIsDisabled] = useState(false); const customResultIndexMinAge = get(props.formikProps, 'values.resultIndexMinAge'); const customResultIndexMinSize = get(props.formikProps, 'values.resultIndexMinSize'); const customResultIndexTTL = get(props.formikProps, 'values.resultIndexTtl'); @@ -66,6 +67,24 @@ function CustomResultIndex(props: CustomResultIndexProps) { } },[customResultIndexConditionsEnabled]) + useEffect(() => { + if (props.isEdit && !get(props.formikProps, 'values.flattenCustomResultIndex')) { + setIsDisabled(true); + } else { + setIsDisabled(false); + } + }, [props.isEdit]); + + const hintTextStyle = { + color: '#69707d', + fontSize: '12px', + lineHeight: '16px', + fontWeight: 'normal', + fontFamily: 'Helvetica, sans-serif', + textAlign: 'left', + width: '400px', +}; + return ( ) : null} - - {enabled ? ( - - { - setCustomResultIndexConditionsEnabled(!customResultIndexConditionsEnabled); - }} - /> - - ) : null} )} - { (enabled && customResultIndexConditionsEnabled) ? ( + + { enabled ? ( + + {({ field, form }: FieldProps) => ( + + + +

Flattening the custom result index will make it easier to query them on the dashboard. It also allows you to perform term aggregations on categorical fields.

+
+
+ )} +
) : null} +
+ + {enabled ? ( + + { + setCustomResultIndexConditionsEnabled(!customResultIndexConditionsEnabled); + }} + /> + + ) : null} + + + + { (enabled && customResultIndexConditionsEnabled) ? ( {({ field, form }: FieldProps) => ( @@ -285,4 +328,4 @@ function CustomResultIndex(props: CustomResultIndexProps) { ); } -export default CustomResultIndex; +export default CustomResultIndex; \ No newline at end of file diff --git a/public/pages/DefineDetector/containers/DefineDetector.tsx b/public/pages/DefineDetector/containers/DefineDetector.tsx index 8b4e0446..eb0051f3 100644 --- a/public/pages/DefineDetector/containers/DefineDetector.tsx +++ b/public/pages/DefineDetector/containers/DefineDetector.tsx @@ -229,6 +229,7 @@ export const DefineDetector = (props: DefineDetectorProps) => { formikProps.setFieldTouched('resultIndexMinAge'); formikProps.setFieldTouched('resultIndexMinSize'); formikProps.setFieldTouched('resultIndexTtl'); + formikProps.setFieldTouched('flattenCustomResultIndex'); formikProps.validateForm().then((errors) => { if (isEmpty(errors)) { if (props.isEdit) { diff --git a/public/pages/DefineDetector/containers/__tests__/__snapshots__/DefineDetector.test.tsx.snap b/public/pages/DefineDetector/containers/__tests__/__snapshots__/DefineDetector.test.tsx.snap index 9e49f7a3..e4efff50 100644 --- a/public/pages/DefineDetector/containers/__tests__/__snapshots__/DefineDetector.test.tsx.snap +++ b/public/pages/DefineDetector/containers/__tests__/__snapshots__/DefineDetector.test.tsx.snap @@ -1080,6 +1080,16 @@ exports[` Full creating detector definition renders the compon +
+
+
+
@@ -2166,6 +2176,16 @@ exports[` empty creating detector definition renders the compo +
+
+
+
@@ -3253,6 +3273,16 @@ exports[` empty editing detector definition renders the compon +
+
+
+
diff --git a/public/pages/DefineDetector/models/interfaces.ts b/public/pages/DefineDetector/models/interfaces.ts index deba85af..0eb9191d 100644 --- a/public/pages/DefineDetector/models/interfaces.ts +++ b/public/pages/DefineDetector/models/interfaces.ts @@ -25,5 +25,6 @@ export interface DetectorDefinitionFormikValues { resultIndexMinAge?: number | string; resultIndexMinSize?: number | string; resultIndexTtl?:number | string; + flattenCustomResultIndex?: boolean; clusters?: any[]; } diff --git a/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx b/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx index c461f2cc..e6385f7d 100644 --- a/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx +++ b/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx @@ -44,6 +44,7 @@ describe('detectorDefinitionToFormik', () => { resultIndexMinAge: randomDetector.resultIndexMinAge, resultIndexMinSize: randomDetector.resultIndexMinSize, resultIndexTtl: randomDetector.resultIndexTtl, + flattenCustomResultIndex: randomDetector.flattenCustomResultIndex, }); }); test('should return if detector does not have metadata', () => { @@ -64,6 +65,7 @@ describe('detectorDefinitionToFormik', () => { resultIndexMinAge: randomDetector.resultIndexMinAge, resultIndexMinSize: randomDetector.resultIndexMinSize, resultIndexTtl: randomDetector.resultIndexTtl, + flattenCustomResultIndex: randomDetector.flattenCustomResultIndex, }); }); test("upgrade old detector's filters to include filter type", () => { diff --git a/public/pages/DefineDetector/utils/constants.tsx b/public/pages/DefineDetector/utils/constants.tsx index fafda119..d6ef4dff 100644 --- a/public/pages/DefineDetector/utils/constants.tsx +++ b/public/pages/DefineDetector/utils/constants.tsx @@ -46,5 +46,6 @@ export const INITIAL_DETECTOR_DEFINITION_VALUES: DetectorDefinitionFormikValues resultIndex: undefined, resultIndexMinAge: 7, resultIndexMinSize: 51200, - resultIndexTtl: 60 + resultIndexTtl: 60, + flattenCustomResultIndex: false, }; diff --git a/public/pages/DefineDetector/utils/helpers.ts b/public/pages/DefineDetector/utils/helpers.ts index f0116ef3..2c8f5c73 100644 --- a/public/pages/DefineDetector/utils/helpers.ts +++ b/public/pages/DefineDetector/utils/helpers.ts @@ -48,6 +48,7 @@ export function detectorDefinitionToFormik( resultIndexMinAge: get(ad, 'resultIndexMinAge', undefined), resultIndexMinSize:get(ad, 'resultIndexMinSize', undefined), resultIndexTtl: get(ad, 'resultIndexTtl', undefined), + flattenCustomResultIndex: get(ad, 'flattenCustomResultIndex', false), }; } @@ -125,6 +126,7 @@ export function formikToDetectorDefinition( resultIndexMinAge: values.resultIndexMinAge, resultIndexMinSize: values.resultIndexMinSize, resultIndexTtl: values.resultIndexTtl, + flattenCustomResultIndex: values.flattenCustomResultIndex, } as Detector; return detectorBody; diff --git a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap index af012a5e..62928da9 100644 --- a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap +++ b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap @@ -1936,6 +1936,40 @@ exports[` spec renders the component 1`] = ` class="euiFormRow euiFormRow--compressed" id="random_html_id-row" style="width: 250px;" + > +
+ +
+
+
+

+ Yes +

+
+
+ + +
+
spec renders the component with 2 custom and 1 simpl class="euiFormRow euiFormRow--compressed" id="random_html_id-row" style="width: 250px;" + > +
+ +
+
+
+

+ Yes +

+
+
+
+
+
+
{ if (indices.length === 0) return '-'; @@ -263,6 +265,12 @@ export const DetectorDefinitionFields = ( description={get(props, 'detector.resultIndex', '-')} /> + + + ); -}; +}; \ No newline at end of file diff --git a/public/pages/ReviewAndCreate/components/__tests__/DetectorDefinitionFields.test.tsx b/public/pages/ReviewAndCreate/components/__tests__/DetectorDefinitionFields.test.tsx index 668df8e2..14bcbca7 100644 --- a/public/pages/ReviewAndCreate/components/__tests__/DetectorDefinitionFields.test.tsx +++ b/public/pages/ReviewAndCreate/components/__tests__/DetectorDefinitionFields.test.tsx @@ -70,6 +70,7 @@ const getTestDetectorWithDifferentIndices = (indices: string[]) => { resultIndexMinAge: 7, resultIndexMinSize: 51200, resultIndexTtl: 60, + flattenCustomResultIndex: true, } as Detector; } const onEditDetectorDefinition = jest.fn(); @@ -116,6 +117,7 @@ describe(' spec', () => { getByText('test-timefield'); getByText('1 Minutes'); getByText('opensearch-ad-plugin-result-test'); + getByText('Yes') getByText('7 Days'); getByText('51200 MB'); getByText('60 Days'); @@ -135,6 +137,7 @@ describe(' spec', () => { getByText('test-timefield'); getByText('1 Minutes'); getByText('opensearch-ad-plugin-result-test'); + getByText('Yes') getByText('7 Days'); getByText('51200 MB'); getByText('60 Days'); @@ -155,4 +158,4 @@ describe(' spec', () => { getByText('1 Minutes'); expect(queryByText('test-id')).not.toBeNull(); }); -}); +}); \ No newline at end of file diff --git a/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap b/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap index 403b5596..4b13aa78 100644 --- a/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap +++ b/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap @@ -349,6 +349,40 @@ exports[` spec renders the component in create mode (no ID class="euiFormRow euiFormRow--compressed" id="random_html_id-row" style="width: 250px;" + > +
+ +
+
+
+

+ Yes +

+
+
+
+
+
+
spec renders the component in edit mode (with ID class="euiFormRow euiFormRow--compressed" id="random_html_id-row" style="width: 250px;" + > +
+ +
+
+
+

+ Yes +

+
+
+
+
+
+
spec renders the component, validation loading 1`] class="euiFormRow euiFormRow--compressed" id="random_html_id-row" style="width: 250px;" + > +
+ +
+
+
+

+ - +

+
+
+
+
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
+
+
0 ? values.resultIndexTtl : undefined, + flattenCustomResultIndex: + resultIndex && resultIndex.trim().length > 0 + ? values.flattenCustomResultIndex + : undefined, imputationOption: formikToImputationOption(values.imputationOption), rules: formikToRules(values.suppressionRules), } as Detector; @@ -196,4 +200,4 @@ export function toStringConfigCell(obj: any): string { } } return '-'; -} +} \ No newline at end of file diff --git a/public/redux/reducers/__tests__/utils.ts b/public/redux/reducers/__tests__/utils.ts index b4974892..ce4af60a 100644 --- a/public/redux/reducers/__tests__/utils.ts +++ b/public/redux/reducers/__tests__/utils.ts @@ -131,6 +131,7 @@ export const getRandomDetector = ( resultIndexMinAge: 7, resultIndexMinSize: 51200, resultIndexTtl: 60, + flattenCustomResultIndex: true, imputationOption: randomImputationOption(features), rules: randomRules(features) }; @@ -306,4 +307,4 @@ export const randomRules = (features: FeatureAttributes[]): Rule[] | undefined = // Randomly decide whether to return undefined or the generated rules const shouldReturnUndefined = random(0, 1) === 0; return shouldReturnUndefined ? undefined : rules; -}; +}; \ No newline at end of file From 4c0465ef2d215b5e5333156d904c104760e0714f Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Wed, 29 Jan 2025 02:56:29 -0800 Subject: [PATCH 2/2] update snapshots Signed-off-by: Jackie Han --- .../DetectorConfig.test.tsx.snap | 38 ++++++- .../__snapshots__/Features.test.tsx.snap | 102 ++++++++++++++++++ .../DetectorDefinitionFields.test.tsx.snap | 38 ++++++- .../ReviewAndCreate.test.tsx.snap | 4 +- 4 files changed, 176 insertions(+), 6 deletions(-) diff --git a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap index 62928da9..4e3f05b6 100644 --- a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap +++ b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/DetectorConfig.test.tsx.snap @@ -432,6 +432,40 @@ exports[` spec renders rules 1`] = `
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
@@ -1967,7 +2001,7 @@ exports[` spec renders the component 1`] = ` class="euiFlexItem" >
@@ -3410,7 +3444,7 @@ exports[` spec renders the component with 2 custom and 1 simpl class="euiFlexItem" >
diff --git a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/Features.test.tsx.snap b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/Features.test.tsx.snap index 1e168c1f..7ead7f51 100644 --- a/public/pages/DetectorConfig/containers/__tests__/__snapshots__/Features.test.tsx.snap +++ b/public/pages/DetectorConfig/containers/__tests__/__snapshots__/Features.test.tsx.snap @@ -432,6 +432,40 @@ exports[` spec renders rules 1`] = `
+
+
+
+ +
+
+
+

+ - +

+
+
+
+
@@ -1929,6 +1963,40 @@ exports[` spec renders the component 1`] = `
+
+
+
+ +
+
+
+

+ Yes +

+
+
+
+
@@ -3338,6 +3406,40 @@ exports[` spec renders the component with 2 custom and 1 simpl
+
+
+
+ +
+
+
+

+ Yes +

+
+
+
+
diff --git a/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap b/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap index 4b13aa78..165e76ef 100644 --- a/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap +++ b/public/pages/ReviewAndCreate/components/__tests__/__snapshots__/DetectorDefinitionFields.test.tsx.snap @@ -380,7 +380,7 @@ exports[` spec renders the component in create mode (no ID class="euiFlexItem" >
@@ -840,6 +840,40 @@ exports[` spec renders the component in create mode (no ID
+
+
+
+ +
+
+
+

+ Yes +

+
+
+
+
@@ -1398,7 +1432,7 @@ exports[` spec renders the component in edit mode (with ID class="euiFlexItem" >
diff --git a/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap b/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap index 5514e121..7b4afb3c 100644 --- a/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap +++ b/public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap @@ -438,7 +438,7 @@ exports[` spec renders the component, validation loading 1`] class="euiFlexItem" >
@@ -1707,7 +1707,7 @@ exports[`issue in detector validation issues in feature query 1`] = ` class="euiFlexItem" >