mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
[Security Solution][Exceptions] - Fix exception operator logic when mapping conflict (#155071)
## Summary Addresses https://github.com/elastic/kibana/issues/154962 .
This commit is contained in:
parent
b689c27ce2
commit
9a095602f8
5 changed files with 61 additions and 12 deletions
|
@ -6,7 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { getMappingConflictsInfo } from '.';
|
||||
import { getMappingConflictsInfo, fieldSupportsMatches } from '.';
|
||||
|
||||
describe('Helpers', () => {
|
||||
describe('getMappingConflictsInfo', () => {
|
||||
|
@ -143,4 +143,42 @@ describe('Helpers', () => {
|
|||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fieldSupportsMatches', () => {
|
||||
test('it returns true if esTypes is keyword', () => {
|
||||
expect(
|
||||
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['keyword'] })
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test('it returns true if one of the esTypes is kibana type string and another is not', () => {
|
||||
expect(
|
||||
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['keyword', 'object'] })
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test('it returns true if one of the esTypes is keyword', () => {
|
||||
expect(
|
||||
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['keyword', 'unmapped'] })
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test('it returns true if one of the esTypes is text', () => {
|
||||
expect(
|
||||
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['text', 'unmapped'] })
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test('it returns true if all of the esTypes is map to kibana type string', () => {
|
||||
expect(
|
||||
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['text', 'keyword'] })
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test('it returns false if none of the esTypes map to kibana type string', () => {
|
||||
expect(
|
||||
fieldSupportsMatches({ name: 'field', type: 'conflict', esTypes: ['bool', 'unmapped'] })
|
||||
).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -35,6 +35,7 @@ import {
|
|||
getDataViewFieldSubtypeNested,
|
||||
isDataViewFieldSubtypeNested,
|
||||
} from '@kbn/es-query';
|
||||
import { castEsToKbnFieldTypeName, KBN_FIELD_TYPES } from '@kbn/field-types';
|
||||
|
||||
import {
|
||||
ALL_OPERATORS,
|
||||
|
@ -676,8 +677,13 @@ export const getEntryOnOperatorChange = (
|
|||
}
|
||||
};
|
||||
|
||||
const fieldSupportsMatches = (field: DataViewFieldBase) => {
|
||||
return field.type === 'string';
|
||||
export const isKibanaStringType = (type: string) => {
|
||||
const kbnFieldType = castEsToKbnFieldTypeName(type);
|
||||
return kbnFieldType === KBN_FIELD_TYPES.STRING;
|
||||
};
|
||||
|
||||
export const fieldSupportsMatches = (field: DataViewFieldBase) => {
|
||||
return field.esTypes?.some(isKibanaStringType);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,10 @@ import {
|
|||
EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
|
||||
} from '@kbn/securitysolution-list-constants';
|
||||
|
||||
export interface DataViewField extends DataViewFieldBase {
|
||||
conflictDescriptions?: Record<string, string[]>;
|
||||
}
|
||||
|
||||
export interface OperatorOption {
|
||||
message: string;
|
||||
value: string;
|
||||
|
@ -35,7 +39,7 @@ export interface OperatorOption {
|
|||
|
||||
export interface FormattedBuilderEntry {
|
||||
id: string;
|
||||
field: DataViewFieldBase | undefined;
|
||||
field: DataViewField | undefined;
|
||||
operator: OperatorOption;
|
||||
value: string | string[] | undefined;
|
||||
nested: 'parent' | 'child' | undefined;
|
||||
|
@ -117,7 +121,3 @@ export const exceptionListAgnosticSavedObjectType = EXCEPTION_LIST_NAMESPACE_AGN
|
|||
export type SavedObjectType =
|
||||
| typeof EXCEPTION_LIST_NAMESPACE
|
||||
| typeof EXCEPTION_LIST_NAMESPACE_AGNOSTIC;
|
||||
|
||||
export interface DataViewField extends DataViewFieldBase {
|
||||
conflictDescriptions?: Record<string, string[]>;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
"@kbn/securitysolution-io-ts-list-types",
|
||||
"@kbn/securitysolution-io-ts-utils",
|
||||
"@kbn/securitysolution-list-constants",
|
||||
"@kbn/securitysolution-utils"
|
||||
"@kbn/securitysolution-utils",
|
||||
"@kbn/field-types"
|
||||
],
|
||||
"exclude": [
|
||||
"target/**/*",
|
||||
|
|
|
@ -221,7 +221,7 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
|
|||
<>
|
||||
<EuiSpacer size="s" />
|
||||
<EuiAccordion
|
||||
id={'1'}
|
||||
id={`${entry.id}`}
|
||||
buttonContent={
|
||||
<>
|
||||
<EuiIcon
|
||||
|
@ -235,6 +235,7 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
|
|||
</>
|
||||
}
|
||||
arrowDisplay="none"
|
||||
data-test-subj="mappingConflictsAccordion"
|
||||
>
|
||||
<div data-test-subj="mappingConflictsDescription">
|
||||
{conflictsInfo.map((info) => {
|
||||
|
@ -265,8 +266,9 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
|
|||
|
||||
const customOptionText =
|
||||
entry.nested == null && allowCustomOptions ? i18n.CUSTOM_COMBOBOX_OPTION_TEXT : undefined;
|
||||
|
||||
const helpText =
|
||||
entry.field?.type !== 'conflict' ? (
|
||||
entry.field?.conflictDescriptions == null ? (
|
||||
customOptionText
|
||||
) : (
|
||||
<>
|
||||
|
@ -422,7 +424,9 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
|
|||
}
|
||||
const warning = validateFilePathInput({ os, value: wildcardValue });
|
||||
actualWarning =
|
||||
warning === FILENAME_WILDCARD_WARNING ? getWildcardWarning(warning) : warning;
|
||||
warning === FILENAME_WILDCARD_WARNING
|
||||
? warning && getWildcardWarning(warning)
|
||||
: warning;
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue