mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
[Security Solution] When adding an Exception and Source value on the Severity override option, are not offering suggestions (#150701)
## Summary These changes fixes the issue with the broken field source value auto-suggestion which was caused by [this PR](https://github.com/elastic/kibana/pull/149149/files#diff-2b9142306df119b8c31e8a66c9b93b2a83f74239b1655919881165ac06398623R148). The problem is that the `stringifyIndices` variable is used to: 1. represent all indices down the road where we request suggestions for a field in `src/plugins/unified_search/public/autocomplete/providers/value_suggestion_provider.ts` 2. be a parameter to check whether we should memoize the results of `getIndexFields` and `getDataViewStateFromIndexFields` methods By modifying it to include the notion of whether we should include unmapped information, solves the second point but breaks the first one. Thus, suggestion request stopped working. The fix is to revert changes to `stringifyIndices` variable and add extra parameter to `getIndexFields` and `getDataViewStateFromIndexFields` methods, so that we can take into account `includeUnmapped` flag during memoization. Bug ticket #150663 --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
da89dde7ac
commit
ace5c10c2c
3 changed files with 36 additions and 10 deletions
|
@ -74,7 +74,7 @@ describe('Exceptions flyout', () => {
|
||||||
createExceptionList(getExceptionList(), getExceptionList().list_id).then((response) =>
|
createExceptionList(getExceptionList(), getExceptionList().list_id).then((response) =>
|
||||||
createCustomRule({
|
createCustomRule({
|
||||||
...getNewRule(),
|
...getNewRule(),
|
||||||
dataSource: { index: ['exceptions-*'], type: 'indexPatterns' },
|
dataSource: { index: ['auditbeat-*', 'exceptions-*'], type: 'indexPatterns' },
|
||||||
exceptionLists: [
|
exceptionLists: [
|
||||||
{
|
{
|
||||||
id: response.body.id,
|
id: response.body.id,
|
||||||
|
@ -289,11 +289,28 @@ describe('Exceptions flyout', () => {
|
||||||
openExceptionFlyoutFromEmptyViewerPrompt();
|
openExceptionFlyoutFromEmptyViewerPrompt();
|
||||||
|
|
||||||
cy.get(FIELD_INPUT).eq(0).click({ force: true });
|
cy.get(FIELD_INPUT).eq(0).click({ force: true });
|
||||||
|
cy.get(FIELD_INPUT).eq(0).type('unique');
|
||||||
cy.get(EXCEPTION_FIELD_LIST).contains('unique_value.test');
|
cy.get(EXCEPTION_FIELD_LIST).contains('unique_value.test');
|
||||||
|
|
||||||
closeExceptionBuilderFlyout();
|
closeExceptionBuilderFlyout();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Validates auto-suggested fields correctly', () => {
|
||||||
|
// open add exception modal
|
||||||
|
openExceptionFlyoutFromEmptyViewerPrompt();
|
||||||
|
|
||||||
|
// add exception item name
|
||||||
|
addExceptionFlyoutItemName('My item name');
|
||||||
|
|
||||||
|
// add an entry with a value and submit button should enable
|
||||||
|
addExceptionEntryFieldValue('agent.type', 0);
|
||||||
|
cy.get(VALUES_INPUT).eq(0).type(`{enter}`);
|
||||||
|
cy.get(VALUES_INPUT).eq(0).type(`{downarrow}{enter}`);
|
||||||
|
cy.get(CONFIRM_BTN).should('be.enabled');
|
||||||
|
|
||||||
|
closeExceptionBuilderFlyout();
|
||||||
|
});
|
||||||
|
|
||||||
// TODO - Add back in error states into modal
|
// TODO - Add back in error states into modal
|
||||||
describe.skip('flyout errors', () => {
|
describe.skip('flyout errors', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|
|
@ -43,7 +43,7 @@ export const getAllFieldsByName = (
|
||||||
keyBy('name', getAllBrowserFields(browserFields));
|
keyBy('name', getAllBrowserFields(browserFields));
|
||||||
|
|
||||||
export const getIndexFields = memoizeOne(
|
export const getIndexFields = memoizeOne(
|
||||||
(title: string, fields: IndexField[]): DataViewBase =>
|
(title: string, fields: IndexField[], _includeUnmapped: boolean = false): DataViewBase =>
|
||||||
fields && fields.length > 0
|
fields && fields.length > 0
|
||||||
? {
|
? {
|
||||||
fields: fields.map((field) =>
|
fields: fields.map((field) =>
|
||||||
|
@ -63,7 +63,10 @@ export const getIndexFields = memoizeOne(
|
||||||
title,
|
title,
|
||||||
}
|
}
|
||||||
: { fields: [], title },
|
: { fields: [], title },
|
||||||
(newArgs, lastArgs) => newArgs[0] === lastArgs[0] && newArgs[1].length === lastArgs[1].length
|
(newArgs, lastArgs) =>
|
||||||
|
newArgs[0] === lastArgs[0] &&
|
||||||
|
newArgs[1].length === lastArgs[1].length &&
|
||||||
|
newArgs[2] === lastArgs[2]
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,21 +148,24 @@ export const useFetchIndex = (
|
||||||
if (isCompleteResponse(response)) {
|
if (isCompleteResponse(response)) {
|
||||||
Promise.resolve().then(() => {
|
Promise.resolve().then(() => {
|
||||||
ReactDOM.unstable_batchedUpdates(() => {
|
ReactDOM.unstable_batchedUpdates(() => {
|
||||||
const stringifyIndices = `${response.indicesExist
|
const stringifyIndices = response.indicesExist.sort().join();
|
||||||
.sort()
|
|
||||||
.join()} (includeUnmapped: ${includeUnmapped})`;
|
|
||||||
|
|
||||||
previousIndexesName.current = response.indicesExist;
|
previousIndexesName.current = response.indicesExist;
|
||||||
const { browserFields } = getDataViewStateFromIndexFields(
|
const { browserFields } = getDataViewStateFromIndexFields(
|
||||||
stringifyIndices,
|
stringifyIndices,
|
||||||
response.indexFields
|
response.indexFields,
|
||||||
|
includeUnmapped
|
||||||
);
|
);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setState({
|
setState({
|
||||||
browserFields,
|
browserFields,
|
||||||
indexes: response.indicesExist,
|
indexes: response.indicesExist,
|
||||||
indexExists: response.indicesExist.length > 0,
|
indexExists: response.indicesExist.length > 0,
|
||||||
indexPatterns: getIndexFields(stringifyIndices, response.indexFields),
|
indexPatterns: getIndexFields(
|
||||||
|
stringifyIndices,
|
||||||
|
response.indexFields,
|
||||||
|
includeUnmapped
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
searchSubscription$.current.unsubscribe();
|
searchSubscription$.current.unsubscribe();
|
||||||
|
|
|
@ -50,7 +50,7 @@ interface DataViewInfo {
|
||||||
* VERY mutatious on purpose to improve the performance of the transform.
|
* VERY mutatious on purpose to improve the performance of the transform.
|
||||||
*/
|
*/
|
||||||
export const getDataViewStateFromIndexFields = memoizeOne(
|
export const getDataViewStateFromIndexFields = memoizeOne(
|
||||||
(_title: string, fields: IndexField[]): DataViewInfo => {
|
(_title: string, fields: IndexField[], _includeUnmapped: boolean = false): DataViewInfo => {
|
||||||
// Adds two dangerous casts to allow for mutations within this function
|
// Adds two dangerous casts to allow for mutations within this function
|
||||||
type DangerCastForMutation = Record<string, {}>;
|
type DangerCastForMutation = Record<string, {}>;
|
||||||
|
|
||||||
|
@ -78,7 +78,10 @@ export const getDataViewStateFromIndexFields = memoizeOne(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
(newArgs, lastArgs) => newArgs[0] === lastArgs[0] && newArgs[1].length === lastArgs[1].length
|
(newArgs, lastArgs) =>
|
||||||
|
newArgs[0] === lastArgs[0] &&
|
||||||
|
newArgs[1].length === lastArgs[1].length &&
|
||||||
|
newArgs[2] === lastArgs[2]
|
||||||
);
|
);
|
||||||
|
|
||||||
export const useDataView = (): {
|
export const useDataView = (): {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue