-
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.
[8.x] [Security Solution] `FinalEdit`: Add `name`…
… and `kql_query` fields + shared components (#193828) (#196191) # Backport This will backport the following commits from `main` to `8.x`: - [[Security Solution] `FinalEdit`: Add `name` and `kql_query` fields + shared components (#193828)](#193828) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Nikita Indik","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-14T17:09:59Z","message":"[Security Solution] `FinalEdit`: Add `name` and `kql_query` fields + shared components (#193828)\n\n**Partially addresses: https://github.com/elastic/kibana/issues/171520**\r\n**Is a follow-up PR to: https://github.com/elastic/kibana/pull/192342**\r\n\r\n## Summary\r\n\r\nChanges:\r\n - Adds editable components for `name` and `kql_query` fields\r\n- Adds a `FieldFormWrapper` component that abstracts away form creation\r\nand data preparation for each field\r\n- Adds local context providers to pass data between the main context and\r\nfield components\r\n- Adds some basic layout components to make the \"edit\" functionality\r\nwork\r\n\r\n<img width=\"1392\" alt=\"Schermafbeelding 2024-10-04 om 17 17 44\"\r\nsrc=\"https://github.com/user-attachments/assets/6272ac84-8159-4b8a-a0d4-88b458f4bc5f\">\r\n\r\n---------\r\n\r\nCo-authored-by: Maxim Palenov <[email protected]>","sha":"424ffbaffc6bdcec2634572d18cad5392ef0ace8","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Detections and Resp","Team: SecuritySolution","Team:Detection Rule Management","Feature:Prebuilt Detection Rules","backport:prev-minor"],"title":"[Security Solution] `FinalEdit`: Add `name` and `kql_query` fields + shared components","number":193828,"url":"https://github.com/elastic/kibana/pull/193828","mergeCommit":{"message":"[Security Solution] `FinalEdit`: Add `name` and `kql_query` fields + shared components (#193828)\n\n**Partially addresses: https://github.com/elastic/kibana/issues/171520**\r\n**Is a follow-up PR to: https://github.com/elastic/kibana/pull/192342**\r\n\r\n## Summary\r\n\r\nChanges:\r\n - Adds editable components for `name` and `kql_query` fields\r\n- Adds a `FieldFormWrapper` component that abstracts away form creation\r\nand data preparation for each field\r\n- Adds local context providers to pass data between the main context and\r\nfield components\r\n- Adds some basic layout components to make the \"edit\" functionality\r\nwork\r\n\r\n<img width=\"1392\" alt=\"Schermafbeelding 2024-10-04 om 17 17 44\"\r\nsrc=\"https://github.com/user-attachments/assets/6272ac84-8159-4b8a-a0d4-88b458f4bc5f\">\r\n\r\n---------\r\n\r\nCo-authored-by: Maxim Palenov <[email protected]>","sha":"424ffbaffc6bdcec2634572d18cad5392ef0ace8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193828","number":193828,"mergeCommit":{"message":"[Security Solution] `FinalEdit`: Add `name` and `kql_query` fields + shared components (#193828)\n\n**Partially addresses: https://github.com/elastic/kibana/issues/171520**\r\n**Is a follow-up PR to: https://github.com/elastic/kibana/pull/192342**\r\n\r\n## Summary\r\n\r\nChanges:\r\n - Adds editable components for `name` and `kql_query` fields\r\n- Adds a `FieldFormWrapper` component that abstracts away form creation\r\nand data preparation for each field\r\n- Adds local context providers to pass data between the main context and\r\nfield components\r\n- Adds some basic layout components to make the \"edit\" functionality\r\nwork\r\n\r\n<img width=\"1392\" alt=\"Schermafbeelding 2024-10-04 om 17 17 44\"\r\nsrc=\"https://github.com/user-attachments/assets/6272ac84-8159-4b8a-a0d4-88b458f4bc5f\">\r\n\r\n---------\r\n\r\nCo-authored-by: Maxim Palenov <[email protected]>","sha":"424ffbaffc6bdcec2634572d18cad5392ef0ace8"}}]}] BACKPORT--> Co-authored-by: Nikita Indik <[email protected]>
- Loading branch information
1 parent
d458824
commit 3db2504
Showing
74 changed files
with
1,242 additions
and
118 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
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
19 changes: 19 additions & 0 deletions
19
...ion_engine/rule_management/components/rule_details/three_way_diff/components/constants.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,19 @@ | ||
/* | ||
* 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 type { DiffableAllFields } from '../../../../../../../common/api/detection_engine'; | ||
|
||
type NonEditableFields = Readonly<Set<keyof DiffableAllFields>>; | ||
|
||
/* These fields are not visible in the comparison UI and are not editable */ | ||
export const HIDDEN_FIELDS: NonEditableFields = new Set([ | ||
'alert_suppression', | ||
'author', | ||
'rule_id', | ||
'license', | ||
'version', | ||
]); |
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
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
50 changes: 50 additions & 0 deletions
50
...n_engine/rule_management/components/rule_details/three_way_diff/diffable_rule_context.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,50 @@ | ||
/* | ||
* 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, { createContext, useContext } from 'react'; | ||
import type { DiffableRule } from '../../../../../../common/api/detection_engine'; | ||
import { invariant } from '../../../../../../common/utils/invariant'; | ||
import type { SetRuleFieldResolvedValueFn } from '../../../model/prebuilt_rule_upgrade/set_rule_field_resolved_value'; | ||
|
||
interface DiffableRuleContextType { | ||
finalDiffableRule: DiffableRule; | ||
setRuleFieldResolvedValue: SetRuleFieldResolvedValueFn; | ||
} | ||
|
||
const DiffableRuleContext = createContext<DiffableRuleContextType | null>(null); | ||
|
||
interface DiffableRuleContextProviderProps { | ||
finalDiffableRule: DiffableRule; | ||
setRuleFieldResolvedValue: SetRuleFieldResolvedValueFn; | ||
children: React.ReactNode; | ||
} | ||
|
||
export function DiffableRuleContextProvider({ | ||
finalDiffableRule, | ||
setRuleFieldResolvedValue, | ||
children, | ||
}: DiffableRuleContextProviderProps) { | ||
const contextValue = { | ||
finalDiffableRule, | ||
setRuleFieldResolvedValue, | ||
}; | ||
|
||
return ( | ||
<DiffableRuleContext.Provider value={contextValue}>{children}</DiffableRuleContext.Provider> | ||
); | ||
} | ||
|
||
export function useDiffableRuleContext() { | ||
const context = useContext(DiffableRuleContext); | ||
|
||
invariant( | ||
context !== null, | ||
'useDiffableRuleContext must be used inside a DiffableRuleContextProvider' | ||
); | ||
|
||
return context; | ||
} |
23 changes: 23 additions & 0 deletions
23
...e_management/components/rule_details/three_way_diff/final_edit/common_rule_field_edit.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,23 @@ | ||
/* | ||
* 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 { FieldFormWrapper } from './field_form_wrapper'; | ||
import { NameEdit, nameSchema } from './fields/name'; | ||
import type { UpgradeableCommonFields } from '../../../../model/prebuilt_rule_upgrade/fields'; | ||
interface CommonRuleFieldEditProps { | ||
fieldName: UpgradeableCommonFields; | ||
} | ||
|
||
export function CommonRuleFieldEdit({ fieldName }: CommonRuleFieldEditProps) { | ||
switch (fieldName) { | ||
case 'name': | ||
return <FieldFormWrapper component={NameEdit} fieldFormSchema={nameSchema} />; | ||
default: | ||
return null; // Will be replaced with `assertUnreachable(fieldName)` once all fields are implemented | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...gement/components/rule_details/three_way_diff/final_edit/custom_query_rule_field_edit.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,36 @@ | ||
/* | ||
* 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 { FieldFormWrapper } from './field_form_wrapper'; | ||
import { | ||
KqlQueryEdit, | ||
kqlQuerySchema, | ||
kqlQuerySerializer, | ||
kqlQueryDeserializer, | ||
} from './fields/kql_query'; | ||
import type { UpgradeableCustomQueryFields } from '../../../../model/prebuilt_rule_upgrade/fields'; | ||
|
||
interface CustomQueryRuleFieldEditProps { | ||
fieldName: UpgradeableCustomQueryFields; | ||
} | ||
|
||
export function CustomQueryRuleFieldEdit({ fieldName }: CustomQueryRuleFieldEditProps) { | ||
switch (fieldName) { | ||
case 'kql_query': | ||
return ( | ||
<FieldFormWrapper | ||
component={KqlQueryEdit} | ||
fieldFormSchema={kqlQuerySchema} | ||
serializer={kqlQuerySerializer} | ||
deserializer={kqlQueryDeserializer} | ||
/> | ||
); | ||
default: | ||
return null; // Will be replaced with `assertUnreachable(fieldName)` once all fields are implemented | ||
} | ||
} |
Oops, something went wrong.