Skip to content

Commit 2eae68a

Browse files
opensearch-trigger-bot[bot]kaituo
andauthoredJan 30, 2023
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 <kaituo@amazon.com> (cherry picked from commit 5caf608) Co-authored-by: Kaituo Li <kaituo@amazon.com>
1 parent e8217da commit 2eae68a

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed
 

‎public/pages/DefineDetector/utils/__tests__/helpers.test.tsx

+59-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
*/
1111

1212
import { INITIAL_DETECTOR_DEFINITION_VALUES } from '../../utils/constants';
13+
import { DATA_TYPES } from '../../../../utils/constants';
1314
import { getRandomDetector } from '../../../../redux/reducers/__tests__/utils';
1415
import {
1516
detectorDefinitionToFormik,
1617
filtersToFormik,
1718
} from '../../utils/helpers';
18-
import { Detector } from '../../../../models/interfaces';
19+
import { Detector, OPERATORS_MAP, FILTER_TYPES } from '../../../../models/interfaces';
1920

2021
describe('detectorDefinitionToFormik', () => {
2122
test('should return initialValues if detector is null', () => {
@@ -53,4 +54,61 @@ describe('detectorDefinitionToFormik', () => {
5354
windowDelay: randomDetector.windowDelay.period.interval,
5455
});
5556
});
57+
test('upgrade old detector\'s filters to include filter type', () => {
58+
const randomDetector = getRandomDetector();
59+
randomDetector.uiMetadata = {
60+
features: {},
61+
filters : [
62+
{
63+
fieldInfo : [
64+
{
65+
label : 'service',
66+
type : DATA_TYPES.KEYWORD
67+
}
68+
],
69+
fieldValue : "app_3",
70+
operator : OPERATORS_MAP.IS
71+
},
72+
{
73+
fieldInfo : [
74+
{
75+
label : "host",
76+
type : DATA_TYPES.KEYWORD
77+
}
78+
],
79+
fieldValue : "server_2",
80+
operator : OPERATORS_MAP.IS
81+
}
82+
],
83+
filterType : FILTER_TYPES.SIMPLE
84+
};
85+
const adFormikValues = filtersToFormik(randomDetector);
86+
expect(adFormikValues).toEqual(
87+
[
88+
{
89+
fieldInfo : [
90+
{
91+
label : 'service',
92+
type : DATA_TYPES.KEYWORD
93+
}
94+
],
95+
fieldValue : "app_3",
96+
operator : OPERATORS_MAP.IS,
97+
filterType : FILTER_TYPES.SIMPLE
98+
},
99+
{
100+
fieldInfo : [
101+
{
102+
label : "host",
103+
type : DATA_TYPES.KEYWORD
104+
}
105+
],
106+
fieldValue : "server_2",
107+
operator : OPERATORS_MAP.IS,
108+
filterType : FILTER_TYPES.SIMPLE
109+
}
110+
]
111+
);
112+
});
113+
56114
});

‎public/pages/DefineDetector/utils/helpers.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,8 @@ export function filtersToFormik(detector: Detector): UIFilter[] {
8989
},
9090
];
9191
} else {
92-
curFilters.forEach((filter: UIFilter) => {
93-
return {
94-
...filter,
95-
filterType: curFilterType,
96-
};
97-
});
92+
curFilters.forEach((filter: UIFilter) =>
93+
filter.filterType = curFilterType);
9894
}
9995
}
10096
return curFilters;

0 commit comments

Comments
 (0)
Please sign in to comment.