-
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.
[Security Solution]
FinalEdit
: Add name
and kql_query
fields + …
…shared components (#193828) **Partially addresses: #171520 **Is a follow-up PR to: #192342 ## Summary Changes: - Adds editable components for `name` and `kql_query` fields - Adds a `FieldFormWrapper` component that abstracts away form creation and data preparation for each field - Adds local context providers to pass data between the main context and field components - Adds some basic layout components to make the "edit" functionality work <img width="1392" alt="Schermafbeelding 2024-10-04 om 17 17 44" src="https://github.com/user-attachments/assets/6272ac84-8159-4b8a-a0d4-88b458f4bc5f"> --------- Co-authored-by: Maxim Palenov <[email protected]>
- Loading branch information
1 parent
37c1bb1
commit 424ffba
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.