mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[8.7] [Security Solution][Exceptions] - Fix empty combo box entry option for exception item condition (#151398) (#151959)
# Backport This will backport the following commits from `main` to `8.7`: - [[Security Solution][Exceptions] - Fix empty combo box entry option for exception item condition (#151398)](https://github.com/elastic/kibana/pull/151398) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Yara Tercero","email":"yctercero@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-02-23T02:10:38Z","message":"[Security Solution][Exceptions] - Fix empty combo box entry option for exception item condition (#151398)\n\n## Summary\r\n\r\nAddresses https://github.com/elastic/kibana/issues/145540\r\n\r\nFilters out the empty default entry item from combo box option.","sha":"28f4f1b457e5e15100b51b26f76d7c13bad3dc90","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","auto-backport","Team:Security Solution Platform","backport:prev-minor","v8.7.0","v8.8.0"],"number":151398,"url":"https://github.com/elastic/kibana/pull/151398","mergeCommit":{"message":"[Security Solution][Exceptions] - Fix empty combo box entry option for exception item condition (#151398)\n\n## Summary\r\n\r\nAddresses https://github.com/elastic/kibana/issues/145540\r\n\r\nFilters out the empty default entry item from combo box option.","sha":"28f4f1b457e5e15100b51b26f76d7c13bad3dc90"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/151398","number":151398,"mergeCommit":{"message":"[Security Solution][Exceptions] - Fix empty combo box entry option for exception item condition (#151398)\n\n## Summary\r\n\r\nAddresses https://github.com/elastic/kibana/issues/145540\r\n\r\nFilters out the empty default entry item from combo box option.","sha":"28f4f1b457e5e15100b51b26f76d7c13bad3dc90"}}]}] BACKPORT--> Co-authored-by: Yara Tercero <yctercero@users.noreply.github.com>
This commit is contained in:
parent
a216384ad5
commit
5573b3aa0f
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