Skip to content

Commit

Permalink
[Security Solution] - Remove replace all (#114481)
Browse files Browse the repository at this point in the history
* remove replace all

* remove bang operator

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
michaelolo24 and kibanamachine authored Oct 22, 2021
1 parent de5ebc5 commit 9433e16
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* 2.0.
*/

import { ALERT_WORKFLOW_STATUS } from '@kbn/rule-data-utils';

export const buildLastAlertsQuery = (ruleId: string | undefined | null) => {
const queryFilter = [
{
bool: { should: [{ match: { 'signal.status': 'open' } }], minimum_should_match: 1 },
bool: { should: [{ match: { [ALERT_WORKFLOW_STATUS]: 'open' } }], minimum_should_match: 1 },
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { ExistsFilter, Filter } from '@kbn/es-query';
import { ALERT_WORKFLOW_STATUS } from '@kbn/rule-data-utils';
import {
buildAlertsRuleIdFilter,
buildAlertStatusesFilter,
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('alerts default_config', () => {
meta: {
alias: null,
disabled: false,
key: 'signal.status',
key: ALERT_WORKFLOW_STATUS,
negate: false,
params: {
query: 'acknowledged',
Expand All @@ -85,12 +86,12 @@ describe('alerts default_config', () => {
should: [
{
term: {
'signal.status': 'acknowledged',
[ALERT_WORKFLOW_STATUS]: 'acknowledged',
},
},
{
term: {
'signal.status': 'in-progress',
[ALERT_WORKFLOW_STATUS]: 'in-progress',
},
},
],
Expand All @@ -107,7 +108,7 @@ describe('alerts default_config', () => {
meta: {
alias: null,
disabled: false,
key: 'signal.status',
key: ALERT_WORKFLOW_STATUS,
negate: false,
params: {
query: 'open',
Expand All @@ -116,7 +117,7 @@ describe('alerts default_config', () => {
},
query: {
term: {
'signal.status': 'open',
[ALERT_WORKFLOW_STATUS]: 'open',
},
},
};
Expand All @@ -139,17 +140,17 @@ describe('alerts default_config', () => {
should: [
{
term: {
'signal.status': 'open',
[ALERT_WORKFLOW_STATUS]: 'open',
},
},
{
term: {
'signal.status': 'acknowledged',
[ALERT_WORKFLOW_STATUS]: 'acknowledged',
},
},
{
term: {
'signal.status': 'in-progress',
[ALERT_WORKFLOW_STATUS]: 'in-progress',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ export const buildAlertStatusFilter = (status: Status): Filter[] => {
should: [
{
term: {
'signal.status': status,
[ALERT_WORKFLOW_STATUS]: status,
},
},
{
term: {
'signal.status': 'in-progress',
[ALERT_WORKFLOW_STATUS]: 'in-progress',
},
},
],
},
}
: {
term: {
'signal.status': status,
[ALERT_WORKFLOW_STATUS]: status,
},
};

Expand All @@ -58,7 +58,7 @@ export const buildAlertStatusFilter = (status: Status): Filter[] => {
negate: false,
disabled: false,
type: 'phrase',
key: 'signal.status',
key: ALERT_WORKFLOW_STATUS,
params: {
query: status,
},
Expand All @@ -76,7 +76,7 @@ export const buildAlertStatusesFilter = (statuses: Status[]): Filter[] => {
bool: {
should: statuses.map((status) => ({
term: {
'signal.status': status,
[ALERT_WORKFLOW_STATUS]: status,
},
})),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ interface OwnProps {
data: TimelineItem[];
defaultCellActions?: TGridCellAction[];
filters?: Filter[];
filterQuery: string;
filterQuery?: string;
filterStatus?: AlertStatus;
id: string;
indexNames: string[];
Expand Down
27 changes: 9 additions & 18 deletions x-pack/plugins/timelines/public/components/t_grid/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { Filter, EsQueryConfig, Query } from '@kbn/es-query';
import { FilterStateStore } from '@kbn/es-query';
import { isEmpty, get } from 'lodash/fp';
import memoizeOne from 'memoize-one';
import { ALERT_WORKFLOW_STATUS } from '@kbn/rule-data-utils';
import {
elementOrChildrenHasFocus,
getFocusedAriaColindexCell,
Expand Down Expand Up @@ -190,9 +189,9 @@ export const combineQueries = ({

export const buildCombinedQuery = (combineQueriesParams: CombineQueries) => {
const combinedQuery = combineQueries(combineQueriesParams);
return combinedQuery
return combinedQuery?.filterQuery
? {
filterQuery: replaceStatusField(combinedQuery!.filterQuery),
filterQuery: combinedQuery.filterQuery,
}
: null;
};
Expand Down Expand Up @@ -228,22 +227,14 @@ export const getCombinedFilterQuery = ({
to,
filters,
...combineQueriesParams
}: CombineQueries & { from: string; to: string }): string =>
replaceStatusField(
combineQueries({
...combineQueriesParams,
filters: [...filters, buildTimeRangeFilter(from, to)],
})?.filterQuery
);
}: CombineQueries & { from: string; to: string }): string | undefined => {
const combinedQueries = combineQueries({
...combineQueriesParams,
filters: [...filters, buildTimeRangeFilter(from, to)],
});

/**
* This function is a temporary patch to prevent queries using old `signal.status` field.
* @todo The `signal.status` field should not be queried anymore and
* must be replaced by `ALERT_WORKFLOW_STATUS` field name constant
* @deprecated
*/
const replaceStatusField = (filterQuery?: string): string =>
filterQuery?.replaceAll('signal.status', ALERT_WORKFLOW_STATUS) ?? '';
return combinedQueries ? combinedQueries.filterQuery : undefined;
};

/**
* The CSS class name of a "stateful event", which appears in both
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface OwnProps {
id: string;
totalItems: number;
filterStatus?: AlertStatus;
query: string;
query?: string;
indexName: string;
onActionSuccess?: OnUpdateAlertStatusSuccess;
onActionFailure?: OnUpdateAlertStatusError;
Expand Down

0 comments on commit 9433e16

Please sign in to comment.