Skip to content

Commit ff79454

Browse files
committed
wip - add autocomplete workaround for .text fields
1 parent 0756dd3 commit ff79454

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

x-pack/plugins/security_solution/public/common/components/exceptions/builder/builder_entry_item.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
170170
return (
171171
<AutocompleteFieldMatchComponent
172172
placeholder={i18n.EXCEPTION_FIELD_VALUE_PLACEHOLDER}
173-
selectedField={entry.field}
173+
selectedField={
174+
entry.correspondingKeywordField != null
175+
? entry.correspondingKeywordField
176+
: entry.field
177+
}
174178
selectedValue={value}
175179
isDisabled={
176180
indexPattern == null || (indexPattern != null && indexPattern.fields.length === 0)
@@ -188,7 +192,11 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
188192
return (
189193
<AutocompleteFieldMatchAnyComponent
190194
placeholder={i18n.EXCEPTION_FIELD_VALUE_PLACEHOLDER}
191-
selectedField={entry.field}
195+
selectedField={
196+
entry.correspondingKeywordField != null
197+
? entry.correspondingKeywordField
198+
: entry.field
199+
}
192200
selectedValue={values}
193201
isDisabled={
194202
indexPattern == null || (indexPattern != null && indexPattern.fields.length === 0)

x-pack/plugins/security_solution/public/common/components/exceptions/builder/helpers.tsx

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ export const getFilteredIndexPatterns = (
7575
}
7676
};
7777

78+
// fields.filter(({ name }) => {
79+
// if (field != null && selectedFieldIsTextType) {
80+
// const keywordField = field.split('.').slice(-1).join('.');
81+
82+
// return field === name || name === keywordField;
83+
// } else {
84+
// return field != null && field === name;
85+
// }
86+
// }).reduce<{ foundField: IFieldType | null; foundKeywordField: IFieldType | null}>((acc, foundField) => {
87+
// if (selectedFieldIsTextType && foundField.esTypes != null && foundField.esTypes.includes('keyword')) {
88+
// return {
89+
// ...acc,
90+
// foundKeywordField: foundField,
91+
// }
92+
// } else {
93+
// return {
94+
// ...acc,
95+
// foundField
96+
// }
97+
// }
98+
// }, { foundField: null, foundKeywordField: null});
99+
78100
/**
79101
* Formats the entry into one that is easily usable for the UI, most of the
80102
* complexity was introduced with nested fields
@@ -95,11 +117,41 @@ export const getFormattedBuilderEntry = (
95117
): FormattedBuilderEntry => {
96118
const { fields } = indexPattern;
97119
const field = parent != null ? `${parent.field}.${item.field}` : item.field;
120+
const selectedFieldIsTextType = field != null && field.split('.').slice(-1)[0] === 'text';
98121
const [selectedField] = fields.filter(({ name }) => field != null && field === name);
122+
const foundFields = fields
123+
.filter(({ name }) => {
124+
if (field != null && selectedFieldIsTextType) {
125+
const fieldBits = field.split('.');
126+
const keywordField = fieldBits.slice(0, fieldBits.length - 1).join('.');
127+
128+
return field === name || name === keywordField;
129+
} else {
130+
return field != null && field === name;
131+
}
132+
})
133+
.reduce<{ foundField: IFieldType; foundKeywordField: IFieldType }>((acc, foundField) => {
134+
if (
135+
selectedFieldIsTextType &&
136+
foundField.esTypes != null &&
137+
foundField.esTypes.includes('keyword')
138+
) {
139+
return {
140+
...acc,
141+
foundKeywordField: foundField,
142+
};
143+
} else {
144+
return {
145+
...acc,
146+
foundField,
147+
};
148+
}
149+
}, {});
99150

100151
if (parent != null && parentIndex != null) {
101152
return {
102-
field: selectedField,
153+
field: foundFields.foundField,
154+
correspondingKeywordField: foundFields.foundKeywordField,
103155
operator: getExceptionOperatorSelect(item),
104156
value: getEntryValue(item),
105157
nested: 'child',
@@ -108,7 +160,8 @@ export const getFormattedBuilderEntry = (
108160
};
109161
} else {
110162
return {
111-
field: selectedField,
163+
field: foundFields.foundField,
164+
correspondingKeywordField: foundFields.foundKeywordField,
112165
operator: getExceptionOperatorSelect(item),
113166
value: getEntryValue(item),
114167
nested: undefined,

0 commit comments

Comments
 (0)