Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] upgrade filter bug #404

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion public/pages/DefineDetector/utils/__tests__/helpers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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
}
]
);
});

});
8 changes: 2 additions & 6 deletions public/pages/DefineDetector/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down