From 2eae68a00fc6c0e81bf3d45274d98577dcf5fcab Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 30 Jan 2023 11:40:55 -0800 Subject: [PATCH] upgrade filter bug (#402) (#404) Previously, we didn't actually add filter type when loading old detector. This PR fixed that. Testing done: 1. added a unit tes 2. verified e2et Signed-off-by: Kaituo Li (cherry picked from commit 5caf60867d8cb72798d7e6ccf1786ead1f71f876) Co-authored-by: Kaituo Li --- .../utils/__tests__/helpers.test.tsx | 60 ++++++++++++++++++- public/pages/DefineDetector/utils/helpers.ts | 8 +-- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx b/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx index e44682f6..b6d9590d 100644 --- a/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx +++ b/public/pages/DefineDetector/utils/__tests__/helpers.test.tsx @@ -10,12 +10,13 @@ */ import { INITIAL_DETECTOR_DEFINITION_VALUES } from '../../utils/constants'; +import { DATA_TYPES } from '../../../../utils/constants'; import { getRandomDetector } from '../../../../redux/reducers/__tests__/utils'; import { detectorDefinitionToFormik, filtersToFormik, } from '../../utils/helpers'; -import { Detector } from '../../../../models/interfaces'; +import { Detector, OPERATORS_MAP, FILTER_TYPES } from '../../../../models/interfaces'; describe('detectorDefinitionToFormik', () => { test('should return initialValues if detector is null', () => { @@ -53,4 +54,61 @@ describe('detectorDefinitionToFormik', () => { windowDelay: randomDetector.windowDelay.period.interval, }); }); + test('upgrade old detector\'s filters to include filter type', () => { + const randomDetector = getRandomDetector(); + randomDetector.uiMetadata = { + features: {}, + filters : [ + { + fieldInfo : [ + { + label : 'service', + type : DATA_TYPES.KEYWORD + } + ], + fieldValue : "app_3", + operator : OPERATORS_MAP.IS + }, + { + fieldInfo : [ + { + label : "host", + type : DATA_TYPES.KEYWORD + } + ], + fieldValue : "server_2", + operator : OPERATORS_MAP.IS + } + ], + filterType : FILTER_TYPES.SIMPLE + }; + const adFormikValues = filtersToFormik(randomDetector); + expect(adFormikValues).toEqual( + [ + { + fieldInfo : [ + { + label : 'service', + type : DATA_TYPES.KEYWORD + } + ], + fieldValue : "app_3", + operator : OPERATORS_MAP.IS, + filterType : FILTER_TYPES.SIMPLE + }, + { + fieldInfo : [ + { + label : "host", + type : DATA_TYPES.KEYWORD + } + ], + fieldValue : "server_2", + operator : OPERATORS_MAP.IS, + filterType : FILTER_TYPES.SIMPLE + } + ] + ); + }); + }); diff --git a/public/pages/DefineDetector/utils/helpers.ts b/public/pages/DefineDetector/utils/helpers.ts index 579a500f..fd427913 100644 --- a/public/pages/DefineDetector/utils/helpers.ts +++ b/public/pages/DefineDetector/utils/helpers.ts @@ -89,12 +89,8 @@ export function filtersToFormik(detector: Detector): UIFilter[] { }, ]; } else { - curFilters.forEach((filter: UIFilter) => { - return { - ...filter, - filterType: curFilterType, - }; - }); + curFilters.forEach((filter: UIFilter) => + filter.filterType = curFilterType); } } return curFilters;