Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM][Detection Engine] critical blocker with the UI crashing #56213

Merged
merged 3 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { addFilterStateIfNotThere } from './';

import { esFilters } from '../../../../../../../../../../src/plugins/data/public';

describe('description_step', () => {
describe('addFilterStateIfNotThere', () => {
test('it does not change the state if it is global', () => {
const filters: esFilters.Filter[] = [
{
$state: {
store: esFilters.FilterStateStore.GLOBAL_STATE,
},
meta: {
alias: null,
disabled: false,
key: 'event.category',
negate: false,
params: {
query: 'file',
},
type: 'phrase',
},
query: {
match_phrase: {
'event.category': 'file',
},
},
},
{
$state: {
store: esFilters.FilterStateStore.GLOBAL_STATE,
},
meta: {
alias: null,
disabled: false,
key: 'event.category',
negate: false,
params: {
query: 'file',
},
type: 'phrase',
},
query: {
match_phrase: {
'event.category': 'file',
},
},
},
];
const output = addFilterStateIfNotThere(filters);
const expected: esFilters.Filter[] = [
{
$state: {
store: esFilters.FilterStateStore.GLOBAL_STATE,
},
meta: {
alias: null,
disabled: false,
key: 'event.category',
negate: false,
params: {
query: 'file',
},
type: 'phrase',
},
query: {
match_phrase: {
'event.category': 'file',
},
},
},
{
$state: {
store: esFilters.FilterStateStore.GLOBAL_STATE,
},
meta: {
alias: null,
disabled: false,
key: 'event.category',
negate: false,
params: {
query: 'file',
},
type: 'phrase',
},
query: {
match_phrase: {
'event.category': 'file',
},
},
},
];
expect(output).toEqual(expected);
});

test('it adds the state if it does not exist as local', () => {
const filters: esFilters.Filter[] = [
{
meta: {
alias: null,
disabled: false,
key: 'event.category',
negate: false,
params: {
query: 'file',
},
type: 'phrase',
},
query: {
match_phrase: {
'event.category': 'file',
},
},
},
{
meta: {
alias: null,
disabled: false,
key: 'event.category',
negate: false,
params: {
query: 'file',
},
type: 'phrase',
},
query: {
match_phrase: {
'event.category': 'file',
},
},
},
];
const output = addFilterStateIfNotThere(filters);
const expected: esFilters.Filter[] = [
{
$state: {
store: esFilters.FilterStateStore.APP_STATE,
},
meta: {
alias: null,
disabled: false,
key: 'event.category',
negate: false,
params: {
query: 'file',
},
type: 'phrase',
},
query: {
match_phrase: {
'event.category': 'file',
},
},
},
{
$state: {
store: esFilters.FilterStateStore.APP_STATE,
},
meta: {
alias: null,
disabled: false,
key: 'event.category',
negate: false,
params: {
query: 'file',
},
type: 'phrase',
},
query: {
match_phrase: {
'event.category': 'file',
},
},
},
];
expect(output).toEqual(expected);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ const buildListItems = (
[]
);

export const addFilterStateIfNotThere = (filters: esFilters.Filter[]): esFilters.Filter[] => {
return filters.map(filter => {
if (filter.$state == null) {
return { $state: { store: esFilters.FilterStateStore.APP_STATE }, ...filter };
} else {
return filter;
}
});
};

const getDescriptionItem = (
field: string,
label: string,
Expand All @@ -105,7 +115,7 @@ const getDescriptionItem = (
indexPatterns?: IIndexPattern
): ListItems[] => {
if (field === 'queryBar') {
const filters = get('queryBar.filters', value) as esFilters.Filter[];
const filters = addFilterStateIfNotThere(get('queryBar.filters', value));
const query = get('queryBar.query', value) as Query;
const savedId = get('queryBar.saved_id', value);
return buildQueryBarDescription({
Expand Down