-
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] ThreeWayDiff UI: Migrate to using DiffableRule
TS type in FieldReadOnly
component
#192342
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
49690fd
Add components for `name`, `description` and `tags`
nikitaindik 040b61a
Update comments related to ThreeWayDiff
nikitaindik a971315
Move from using `DiffableAllFields` to `DiffableRule` type in Storybooks
nikitaindik 6f9344e
Temporarily remove `assertUnreachable` checks to make TS happy
nikitaindik 3753f04
Remove `DiffableAllFields` type from field components
nikitaindik 7f44356
Rewrite type check for `Filters` component to a type guard
nikitaindik f89e476
Address code review comments
nikitaindik 26d473f
Merge remote-tracking branch 'upstream/main' into 3wd-field-readonly-…
nikitaindik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
91 changes: 91 additions & 0 deletions
91
...ment/components/rule_details/three_way_diff/final_readonly/common_rule_field_readonly.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,91 @@ | ||
/* | ||
* 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 { | ||
DiffableCommonFields, | ||
DiffableRule, | ||
} from '../../../../../../../common/api/detection_engine'; | ||
import { RelatedIntegrationsReadOnly } from './fields/related_integrations/related_integrations'; | ||
import { RequiredFieldsReadOnly } from './fields/required_fields/required_fields'; | ||
import { SeverityMappingReadOnly } from './fields/severity_mapping/severity_mapping'; | ||
import { RiskScoreMappingReadOnly } from './fields/risk_score_mapping/risk_score_mapping'; | ||
import { ThreatReadOnly } from './fields/threat/threat'; | ||
import { NameReadOnly } from './fields/name/name'; | ||
import { TagsReadOnly } from './fields/tags/tags'; | ||
import { DescriptionReadOnly } from './fields/description/description'; | ||
import { assertUnreachable } from '../../../../../../../common/utility_types'; | ||
|
||
interface CommonRuleFieldReadOnlyProps { | ||
fieldName: keyof DiffableCommonFields; | ||
finalDiffableRule: DiffableRule; | ||
} | ||
|
||
// eslint-disable-next-line complexity | ||
export function CommonRuleFieldReadOnly({ | ||
fieldName, | ||
finalDiffableRule, | ||
}: CommonRuleFieldReadOnlyProps) { | ||
switch (fieldName) { | ||
case 'author': | ||
return null; | ||
case 'building_block': | ||
return null; | ||
case 'description': | ||
return <DescriptionReadOnly description={finalDiffableRule.description} />; | ||
case 'exceptions_list': | ||
return null; | ||
case 'investigation_fields': | ||
return null; | ||
case 'false_positives': | ||
return null; | ||
case 'license': | ||
return null; | ||
case 'max_signals': | ||
return null; | ||
case 'name': | ||
return <NameReadOnly name={finalDiffableRule.name} />; | ||
case 'note': | ||
return null; | ||
case 'related_integrations': | ||
return ( | ||
<RelatedIntegrationsReadOnly relatedIntegrations={finalDiffableRule.related_integrations} /> | ||
); | ||
case 'required_fields': | ||
return <RequiredFieldsReadOnly requiredFields={finalDiffableRule.required_fields} />; | ||
case 'risk_score_mapping': | ||
return <RiskScoreMappingReadOnly riskScoreMapping={finalDiffableRule.risk_score_mapping} />; | ||
case 'rule_schedule': | ||
return null; | ||
case 'severity_mapping': | ||
return <SeverityMappingReadOnly severityMapping={finalDiffableRule.severity_mapping} />; | ||
case 'tags': | ||
return <TagsReadOnly tags={finalDiffableRule.tags} />; | ||
case 'threat': | ||
return <ThreatReadOnly threat={finalDiffableRule.threat} />; | ||
case 'references': | ||
return null; | ||
case 'risk_score': | ||
return null; | ||
case 'rule_id': | ||
return null; | ||
case 'rule_name_override': | ||
return null; | ||
case 'setup': | ||
return null; | ||
case 'severity': | ||
return null; | ||
case 'timestamp_override': | ||
return null; | ||
case 'timeline_template': | ||
return null; | ||
case 'version': | ||
return null; | ||
default: | ||
return assertUnreachable(fieldName); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...omponents/rule_details/three_way_diff/final_readonly/custom_query_rule_field_readonly.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 type { DiffableCustomQueryFields } from '../../../../../../../common/api/detection_engine'; | ||
import { DataSourceReadOnly } from './fields/data_source/data_source'; | ||
import { KqlQueryReadOnly } from './fields/kql_query'; | ||
|
||
interface CustomQueryRuleFieldReadOnlyProps { | ||
fieldName: keyof DiffableCustomQueryFields; | ||
finalDiffableRule: DiffableCustomQueryFields; | ||
} | ||
|
||
export function CustomQueryRuleFieldReadOnly({ | ||
fieldName, | ||
finalDiffableRule, | ||
}: CustomQueryRuleFieldReadOnlyProps) { | ||
switch (fieldName) { | ||
case 'data_source': | ||
return <DataSourceReadOnly dataSource={finalDiffableRule.data_source} />; | ||
case 'kql_query': | ||
return ( | ||
<KqlQueryReadOnly | ||
kqlQuery={finalDiffableRule.kql_query} | ||
dataSource={finalDiffableRule.data_source} | ||
ruleType={finalDiffableRule.type} | ||
/> | ||
); | ||
default: | ||
return null; // Will replace with `assertUnreachable(fieldName)` once all fields are implemented | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...agement/components/rule_details/three_way_diff/final_readonly/eql_rule_field_readonly.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,34 @@ | ||
/* | ||
* 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 { DiffableEqlFields } from '../../../../../../../common/api/detection_engine'; | ||
import { DataSourceReadOnly } from './fields/data_source/data_source'; | ||
import { EqlQueryReadOnly } from './fields/eql_query/eql_query'; | ||
|
||
interface EqlRuleFieldReadOnlyProps { | ||
fieldName: keyof DiffableEqlFields; | ||
finalDiffableRule: DiffableEqlFields; | ||
} | ||
|
||
export function EqlRuleFieldReadOnly({ fieldName, finalDiffableRule }: EqlRuleFieldReadOnlyProps) { | ||
switch (fieldName) { | ||
case 'data_source': | ||
return <DataSourceReadOnly dataSource={finalDiffableRule.data_source} />; | ||
case 'eql_query': | ||
return ( | ||
<EqlQueryReadOnly | ||
eqlQuery={finalDiffableRule.eql_query} | ||
dataSource={finalDiffableRule.data_source} | ||
/> | ||
); | ||
case 'type': | ||
return null; | ||
default: | ||
return null; // Will replace with `assertUnreachable(fieldName)` once all fields are implemented | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...gement/components/rule_details/three_way_diff/final_readonly/esql_rule_field_readonly.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,29 @@ | ||
/* | ||
* 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 { DiffableEsqlFields } from '../../../../../../../common/api/detection_engine'; | ||
import { EsqlQueryReadOnly } from './fields/esql_query/esql_query'; | ||
|
||
interface EsqlRuleFieldReadOnlyProps { | ||
fieldName: keyof DiffableEsqlFields; | ||
finalDiffableRule: DiffableEsqlFields; | ||
} | ||
|
||
export function EsqlRuleFieldReadOnly({ | ||
fieldName, | ||
finalDiffableRule, | ||
}: EsqlRuleFieldReadOnlyProps) { | ||
switch (fieldName) { | ||
case 'esql_query': | ||
return <EsqlQueryReadOnly esqlQuery={finalDiffableRule.esql_query} />; | ||
case 'type': | ||
return null; | ||
default: | ||
return null; // Will replace with `assertUnreachable(fieldName)` once all fields are implemented | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should
meta
's type be checked as well?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.
Thanks! Added in f89e476.