-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution] FinalEdit
: Add name
and kql_query
fields + shared components
#193828
Changes from 37 commits
12bdeae
8ecf7ae
2294396
204933f
64ddaa7
6b51235
1a0fa9a
c3bcaae
f991566
ee92867
2684b22
a09e90c
ac4048e
798592a
d753724
076c7a0
718c088
91e47fd
0407cbe
a1b0000
19e4101
54183c7
9509411
51637f4
83c476d
e45796e
022ef98
f92d273
caa3064
e491ad7
bdd4937
f9a6ba1
265c8c8
db49679
3d185d1
233fb28
2fdfabd
e8a7b5e
02710b3
9a4741b
05563a5
61326b8
d0c6f55
5b3ebf9
2079647
9749c8c
048dfac
0a98280
655d126
7b4265c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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([ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
'alert_suppression', | ||||||
'author', | ||||||
'rule_id', | ||||||
'license', | ||||||
'version', | ||||||
]); |
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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Context value changes every render. Have you checked if this causes underlying components re-rendering? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checked. Once you hit "Save" after editing a field value the state in We'll def want to optimize this at some point. Added a task to our todo list in the ticket. |
||
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; | ||
} |
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/types'; | ||
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 | ||
} | ||
} |
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/types'; | ||
|
||
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 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this one.
resolvedValue
might not be user accepted. Even before user modifications we still haveresolvedValue
which is equal to our merge proposal or current value. Any ideas how to phrase it better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
User accepted or system suggested field value
orA value field will be upgraded to
?