@@ -67,6 +67,8 @@ export function filtersToFormik(detector: Detector): UIFilter[] {
67
67
const noMetadata =
68
68
get ( detector , 'uiMetadata.filterType' ) === undefined &&
69
69
get ( detector , 'uiMetadata.filters' ) === undefined ;
70
+ const isOldDetector = get ( detector , 'uiMetadata.filterType' ) !== undefined ;
71
+
70
72
if ( noMetadata ) {
71
73
return [
72
74
{
@@ -82,23 +84,32 @@ export function filtersToFormik(detector: Detector): UIFilter[] {
82
84
83
85
const curFilterType = get ( detector , 'uiMetadata.filterType' ) ;
84
86
const curFilters = get ( detector , 'uiMetadata.filters' , [ ] ) ;
85
- const curFilterQuery = JSON . stringify (
86
- get ( detector , 'filterQuery' , { match_all : { } } ) ,
87
- null ,
88
- 4
89
- ) ;
90
87
91
- // If this is an old detector (has a base filter type): modify it by injecting that
92
- // filter type into each existing filter
93
- if ( curFilterType !== undefined ) {
94
- curFilters . forEach ( ( filter : UIFilter ) => {
95
- return {
96
- ...filter ,
97
- filterType : curFilterType ,
98
- query :
99
- curFilterType === FILTER_TYPES . CUSTOM ? curFilterQuery : undefined ,
100
- } ;
101
- } ) ;
88
+ // If this is an old detector:
89
+ // If filters is empty: it means it was a custom filter. Convert to a single filter array with a
90
+ // query value equal to the existing filterQuery
91
+ // If a set of simple filters: modify them by injecting the filter type
92
+ // into each existing filter
93
+ if ( isOldDetector ) {
94
+ if ( isEmpty ( curFilters ) ) {
95
+ return [
96
+ {
97
+ filterType : FILTER_TYPES . CUSTOM ,
98
+ query : JSON . stringify (
99
+ get ( detector , 'filterQuery' , { match_all : { } } ) ,
100
+ null ,
101
+ 4
102
+ ) ,
103
+ } ,
104
+ ] ;
105
+ } else {
106
+ curFilters . forEach ( ( filter : UIFilter ) => {
107
+ return {
108
+ ...filter ,
109
+ filterType : curFilterType ,
110
+ } ;
111
+ } ) ;
112
+ }
102
113
}
103
114
return curFilters ;
104
115
}
@@ -114,7 +125,7 @@ export function formikToDetectorDefinition(
114
125
indices : formikToIndices ( values . index ) ,
115
126
filterQuery : formikToFilterQuery ( values ) ,
116
127
uiMetadata : {
117
- ... detector . uiMetadata ,
128
+ features : get ( detector , ' uiMetadata.features' , { } ) ,
118
129
filters : get ( values , 'filters' , [ ] ) ,
119
130
} ,
120
131
timeField : values . timeField ,
0 commit comments