mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Security Solution][Exceptions] - Fix empty combo box entry option for exception item condition (#151398)
## Summary Addresses https://github.com/elastic/kibana/issues/145540 Filters out the empty default entry item from combo box option.
This commit is contained in:
parent
ffe491857e
commit
28f4f1b457
2 changed files with 56 additions and 8 deletions
|
@ -84,6 +84,55 @@ describe('useField', () => {
|
|||
expect(comboOptions).toEqual([{ label: 'bytes' }, { label: 'ssl' }, { label: '@timestamp' }]);
|
||||
expect(selectedComboOptions).toEqual([]);
|
||||
});
|
||||
it('should not return an empty field as a combo option', () => {
|
||||
const newIndexPattern = {
|
||||
...indexPattern,
|
||||
fields: [
|
||||
{
|
||||
name: 'bytes',
|
||||
type: 'number',
|
||||
esTypes: ['long'],
|
||||
count: 10,
|
||||
scripted: false,
|
||||
searchable: true,
|
||||
aggregatable: true,
|
||||
readFromDocValues: true,
|
||||
},
|
||||
{
|
||||
name: 'ssl',
|
||||
type: 'boolean',
|
||||
esTypes: ['boolean'],
|
||||
count: 20,
|
||||
scripted: false,
|
||||
searchable: true,
|
||||
aggregatable: true,
|
||||
readFromDocValues: true,
|
||||
},
|
||||
{
|
||||
name: '@timestamp',
|
||||
type: 'date',
|
||||
esTypes: ['date'],
|
||||
count: 30,
|
||||
scripted: false,
|
||||
searchable: true,
|
||||
aggregatable: true,
|
||||
readFromDocValues: true,
|
||||
},
|
||||
] as unknown as DataViewFieldBase[],
|
||||
title: 'title1',
|
||||
};
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useField({
|
||||
indexPattern: newIndexPattern,
|
||||
onChange: onChangeMock,
|
||||
selectedField: { name: ' ', type: 'keyword' },
|
||||
})
|
||||
);
|
||||
const { comboOptions, selectedComboOptions } = result.current;
|
||||
expect(comboOptions).toEqual([{ label: 'bytes' }, { label: 'ssl' }, { label: '@timestamp' }]);
|
||||
expect(selectedComboOptions).toEqual([]);
|
||||
});
|
||||
it('should map fields to comboOptions correctly and return selectedComboOptions', () => {
|
||||
const newIndexPattern = {
|
||||
...indexPattern,
|
||||
|
@ -183,7 +232,7 @@ describe('useField', () => {
|
|||
{ label: '@timestamp' },
|
||||
]);
|
||||
act(() => {
|
||||
const label = renderFields({ label: 'blob' }, '', '') as ReactElement;
|
||||
const label = renderFields({ label: 'blob' }) as ReactElement;
|
||||
expect(label?.props.content).toEqual('Binary fields are currently unsupported');
|
||||
});
|
||||
});
|
||||
|
@ -238,7 +287,7 @@ describe('useField', () => {
|
|||
{ label: '@timestamp' },
|
||||
]);
|
||||
act(() => {
|
||||
const label = renderFields({ label: 'blob' }, '', '') as ReactElement;
|
||||
const label = renderFields({ label: 'blob' }) as ReactElement;
|
||||
expect(label?.props.content).toEqual('Binary fields are currently unsupported');
|
||||
});
|
||||
});
|
||||
|
@ -279,7 +328,7 @@ describe('useField', () => {
|
|||
const { comboOptions, renderFields } = result.current;
|
||||
expect(comboOptions).toEqual([{ label: 'bytes' }, { label: 'ssl' }, { label: '@timestamp' }]);
|
||||
act(() => {
|
||||
const label = renderFields({ label: '@timestamp' }, '', '') as ReactElement;
|
||||
const label = renderFields({ label: '@timestamp' }) as ReactElement;
|
||||
expect(label).toEqual('@timestamp');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -26,13 +26,14 @@ import {
|
|||
GetFieldComboBoxPropsReturn,
|
||||
} from './types';
|
||||
import { disabledTypesWithTooltipText } from './disabled_types_with_tooltip_text';
|
||||
import { paramContainsSpace } from '../param_contains_space';
|
||||
|
||||
const getExistingFields = (indexPattern: DataViewBase | undefined): DataViewFieldBase[] => {
|
||||
return indexPattern != null ? indexPattern.fields : [];
|
||||
};
|
||||
|
||||
const getSelectedFields = (selectedField: DataViewField | undefined): DataViewFieldBase[] => {
|
||||
return selectedField ? [selectedField] : [];
|
||||
return selectedField && !paramContainsSpace(selectedField.name) ? [selectedField] : [];
|
||||
};
|
||||
|
||||
const getAvailableFields = (
|
||||
|
@ -130,7 +131,7 @@ export const useField = ({
|
|||
const { availableFields, selectedFields } = useMemo(() => {
|
||||
const indexPatternsToUse =
|
||||
customOption != null && indexPattern != null
|
||||
? { ...indexPattern, fields: [...indexPattern?.fields, customOption] }
|
||||
? { ...indexPattern, fields: [customOption, ...indexPattern?.fields] }
|
||||
: indexPattern;
|
||||
return getComboBoxFields(indexPatternsToUse, selectedField, fieldTypeFilter);
|
||||
}, [indexPattern, fieldTypeFilter, selectedField, customOption]);
|
||||
|
@ -183,9 +184,7 @@ export const useField = ({
|
|||
);
|
||||
|
||||
const renderFields = (
|
||||
option: EuiComboBoxOptionOption<string | number | string[] | undefined>,
|
||||
searchValue: string,
|
||||
contentClassName: string
|
||||
option: EuiComboBoxOptionOption<string | number | string[] | undefined>
|
||||
) => {
|
||||
const { label } = option;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue