-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96bee4f
commit cfacec3
Showing
6 changed files
with
151 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...agement/components/rule_details/three_way_diff/final_edit/fields/investigation_fields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import type { FormSchema, FormData } from '../../../../../../../shared_imports'; | ||
import { UseField } from '../../../../../../../shared_imports'; | ||
import { schema } from '../../../../../../rule_creation_ui/components/step_about_rule/schema'; | ||
import type { | ||
DiffableRule, | ||
InvestigationFields, | ||
RuleFalsePositiveArray, | ||
} from '../../../../../../../../common/api/detection_engine'; | ||
import { MultiSelectFieldsAutocomplete } from '../../../../../../rule_creation_ui/components/multi_select_fields'; | ||
import { useAllEsqlRuleFields } from '../../../../../../rule_creation_ui/hooks'; | ||
import { useDefaultIndexPattern } from '../../../use_default_index_pattern'; | ||
import { useRuleIndexPattern } from '../../../../../../rule_creation_ui/pages/form'; | ||
import { getUseRuleIndexPatternParameters } from '../utils'; | ||
|
||
export const investigationFieldsSchema = { | ||
investigationFields: schema.investigationFields, | ||
} as FormSchema<{ | ||
investigationFields: RuleFalsePositiveArray; | ||
}>; | ||
|
||
interface InvestigationFieldsEditProps { | ||
finalDiffableRule: DiffableRule; | ||
} | ||
|
||
export function InvestigationFieldsEdit({ | ||
finalDiffableRule, | ||
}: InvestigationFieldsEditProps): JSX.Element { | ||
const { type } = finalDiffableRule; | ||
|
||
const defaultIndexPattern = useDefaultIndexPattern(); | ||
const indexPatternParameters = getUseRuleIndexPatternParameters( | ||
finalDiffableRule, | ||
defaultIndexPattern | ||
); | ||
const { indexPattern, isIndexPatternLoading } = useRuleIndexPattern(indexPatternParameters); | ||
|
||
const { fields: investigationFields, isLoading: isInvestigationFieldsLoading } = | ||
useAllEsqlRuleFields({ | ||
esqlQuery: type === 'esql' ? finalDiffableRule.esql_query.query : undefined, | ||
indexPatternsFields: indexPattern.fields, | ||
}); | ||
|
||
return ( | ||
<UseField | ||
path="investigationFields" | ||
component={MultiSelectFieldsAutocomplete} | ||
componentProps={{ | ||
browserFields: investigationFields, | ||
isDisabled: isIndexPatternLoading || isInvestigationFieldsLoading, | ||
fullWidth: true, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export function investigationFieldsDeserializer(defaultValue: FormData) { | ||
/* Set initial form value with camelCase "investigationFields" key instead of "investigation_fields" */ | ||
return { | ||
investigationFields: defaultValue?.field_names ?? [], | ||
}; | ||
} | ||
|
||
export function investigationFieldsSerializer(formData: FormData): { | ||
investigation_fields: InvestigationFields | undefined; | ||
} { | ||
const hasInvestigationFields = formData.investigationFields.length > 0; | ||
|
||
return { | ||
investigation_fields: hasInvestigationFields | ||
? { | ||
field_names: formData.investigationFields, | ||
} | ||
: undefined, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...tection_engine/rule_management/components/rule_details/three_way_diff/final_edit/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { DataSourceType } from '../../../../../../detections/pages/detection_engine/rules/types'; | ||
import { DataSourceType as DataSourceTypeSnakeCase } from '../../../../../../../common/api/detection_engine'; | ||
import type { DiffableRule } from '../../../../../../../common/api/detection_engine'; | ||
|
||
interface UseRuleIndexPatternParameters { | ||
dataSourceType: DataSourceType; | ||
index: string[]; | ||
dataViewId: string | undefined; | ||
} | ||
|
||
export function getUseRuleIndexPatternParameters( | ||
finalDiffableRule: DiffableRule, | ||
defaultIndexPattern: string[] | ||
): UseRuleIndexPatternParameters { | ||
if (!('data_source' in finalDiffableRule) || !finalDiffableRule.data_source) { | ||
return { | ||
dataSourceType: DataSourceType.IndexPatterns, | ||
index: defaultIndexPattern, | ||
dataViewId: undefined, | ||
}; | ||
} | ||
if (finalDiffableRule.data_source.type === DataSourceTypeSnakeCase.data_view) { | ||
return { | ||
dataSourceType: DataSourceType.DataView, | ||
index: [], | ||
dataViewId: finalDiffableRule.data_source.data_view_id, | ||
}; | ||
} | ||
return { | ||
dataSourceType: DataSourceType.IndexPatterns, | ||
index: finalDiffableRule.data_source.index_patterns, | ||
dataViewId: undefined, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters