-
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
[Rules migration] Add sorting functionality to rules migration table (#11379) #203396
[Rules migration] Add sorting functionality to rules migration table (#11379) #203396
Conversation
Pinging @elastic/security-threat-hunting (Team:Threat Hunting) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
@@ -46,6 +46,7 @@ export type FieldMap<T extends string = string> = Record< | |||
array?: boolean; | |||
doc_values?: boolean; | |||
enabled?: boolean; | |||
fields?: Record<string, { type: string }>; |
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.
@semd I extended FieldMap to have fields
as well. We need it to be able to do sort by title
field which has text
type. And in order to sort by this field we need to add sub-field of a keyword
type.
https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html#before-enabling-fielddata
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.
removing it for now since it does not cover anything and I have a separate task to add all tests
direction === 'desc' ? '_last' : '_first'; | ||
|
||
const sortingOptions = { | ||
author(direction: estypes.SortOrder = 'asc'): estypes.SortCombinations { |
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.
Calling this "author" is something specific to the UI, In the API we should call it matchedPrebuiltRule or customTranslation (opposite).
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.
done
@@ -395,3 +407,89 @@ const conditions = { | |||
return [this.isFullyTranslated(), this.isNotInstalled()]; | |||
}, | |||
}; | |||
|
|||
const missing = (direction: estypes.SortOrder = 'asc') => |
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.
This function name is vague, can we call it sortMissingValue
or something more descriptive?
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.
done
const getSortingOptions = (sort?: RuleMigrationSort): estypes.Sort => { | ||
if (!sort?.sortField) { | ||
return DEFAULT_SORTING; | ||
} | ||
const sortingOptionsMap: { [key: string]: estypes.Sort } = { | ||
'elastic_rule.title': sortingOptions.name(sort.sortDirection), | ||
'elastic_rule.severity': sortingOptions.severity(sort.sortDirection), | ||
'elastic_rule.prebuilt_rule_id': sortingOptions.author(sort.sortDirection), | ||
translation_result: sortingOptions.status(sort.sortDirection), | ||
updated_at: sortingOptions.updated(sort.sortDirection), | ||
}; | ||
return sortingOptionsMap[sort.sortField] ?? DEFAULT_SORTING; | ||
}; |
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.
Wouln't it be better to create the map only once?
const getSortingOptions = (sort?: RuleMigrationSort): estypes.Sort => { | |
if (!sort?.sortField) { | |
return DEFAULT_SORTING; | |
} | |
const sortingOptionsMap: { [key: string]: estypes.Sort } = { | |
'elastic_rule.title': sortingOptions.name(sort.sortDirection), | |
'elastic_rule.severity': sortingOptions.severity(sort.sortDirection), | |
'elastic_rule.prebuilt_rule_id': sortingOptions.author(sort.sortDirection), | |
translation_result: sortingOptions.status(sort.sortDirection), | |
updated_at: sortingOptions.updated(sort.sortDirection), | |
}; | |
return sortingOptionsMap[sort.sortField] ?? DEFAULT_SORTING; | |
}; | |
const sortingOptionsMap: { [key: string]: estypes.Sort } = { | |
'elastic_rule.title': sortingOptions.name, | |
'elastic_rule.severity': sortingOptions.severity, | |
'elastic_rule.prebuilt_rule_id': sortingOptions.author, | |
translation_result: sortingOptions.status, | |
updated_at: sortingOptions.updated, | |
}; | |
const getSortingOptions = (sort?: RuleMigrationSort): estypes.Sort => { | |
if (!sort?.sortField) { | |
return DEFAULT_SORTING; | |
} | |
return sortingOptionsMap[sort.sortField]?.(sort.sortDirection) ?? DEFAULT_SORTING; | |
}; |
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.
done
if (!sort?.sortField) { | ||
return DEFAULT_SORTING; | ||
} | ||
const sortingOptionsMap: { [key: string]: estypes.Sort } = { |
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.
It would be good to have a union type with the fields we support sorting for, instead of using string
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.
done
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.
Now, instead of returning only one condition estypes.SortCombinations
we can return an array of conditions estypes.SortCombinations[]
. I actually used that in case of sorting by status
😄
@@ -395,3 +407,89 @@ const conditions = { | |||
return [this.isFullyTranslated(), this.isNotInstalled()]; | |||
}, | |||
}; | |||
|
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.
This file is starting to grow too much.
Would it make sense to move these sorting helpers to a separate place?
Maybe:
server/lib/siem_migrations/rules/data/rule_migrations_data_rules_client/sort.ts
And the conditions
object to:
server/lib/siem_migrations/rules/data/rule_migrations_data_rules_client/search.ts
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.
done
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
History
cc @e40pud |
Starting backport for target branches: 8.x https://github.com/elastic/kibana/actions/runs/12242755200 |
…lastic#11379) (elastic#203396) ## Summary [Internal link](elastic/security-team#10820) to the feature details These changes add sorting functionality to the migration rules table. It is possible to sort migration rules by next columns: `Updated`, `Name`, `Status`, `Risk Score`, `Severity` and `Author`. ### Other changes Next fixes and adjustments were also implemented as part of this PR: * `Installed` status in migration rules table to indicate whether the rule was installed * Rules selection and installation of selected rules * Disable selection for not fully translated rules * `Author` column to show whether the translated rule matched one of the existing Elastic prebuilt rules * `Install and enable` and `Install without enabling` buttons within the migration rule details flyout (cherry picked from commit 70a5bb3)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…table (#11379) (#203396) (#203486) # Backport This will backport the following commits from `main` to `8.x`: - [[Rules migration] Add sorting functionality to rules migration table (#11379) (#203396)](#203396) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Ievgen Sorokopud","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-09T19:21:16Z","message":"[Rules migration] Add sorting functionality to rules migration table (#11379) (#203396)\n\n## Summary\r\n\r\n[Internal link](https://github.com/elastic/security-team/issues/10820)\r\nto the feature details\r\n\r\nThese changes add sorting functionality to the migration rules table. It\r\nis possible to sort migration rules by next columns: `Updated`, `Name`,\r\n`Status`, `Risk Score`, `Severity` and `Author`.\r\n\r\n### Other changes\r\n\r\nNext fixes and adjustments were also implemented as part of this PR:\r\n* `Installed` status in migration rules table to indicate whether the\r\nrule was installed\r\n* Rules selection and installation of selected rules\r\n* Disable selection for not fully translated rules\r\n* `Author` column to show whether the translated rule matched one of the\r\nexisting Elastic prebuilt rules\r\n* `Install and enable` and `Install without enabling` buttons within the\r\nmigration rule details flyout","sha":"70a5bb33c438912b64259ea4c7a3c77c41f93f45","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Threat Hunting","Team: SecuritySolution","backport:prev-minor"],"title":"[Rules migration] Add sorting functionality to rules migration table (#11379)","number":203396,"url":"https://github.com/elastic/kibana/pull/203396","mergeCommit":{"message":"[Rules migration] Add sorting functionality to rules migration table (#11379) (#203396)\n\n## Summary\r\n\r\n[Internal link](https://github.com/elastic/security-team/issues/10820)\r\nto the feature details\r\n\r\nThese changes add sorting functionality to the migration rules table. It\r\nis possible to sort migration rules by next columns: `Updated`, `Name`,\r\n`Status`, `Risk Score`, `Severity` and `Author`.\r\n\r\n### Other changes\r\n\r\nNext fixes and adjustments were also implemented as part of this PR:\r\n* `Installed` status in migration rules table to indicate whether the\r\nrule was installed\r\n* Rules selection and installation of selected rules\r\n* Disable selection for not fully translated rules\r\n* `Author` column to show whether the translated rule matched one of the\r\nexisting Elastic prebuilt rules\r\n* `Install and enable` and `Install without enabling` buttons within the\r\nmigration rule details flyout","sha":"70a5bb33c438912b64259ea4c7a3c77c41f93f45"}},"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/203396","number":203396,"mergeCommit":{"message":"[Rules migration] Add sorting functionality to rules migration table (#11379) (#203396)\n\n## Summary\r\n\r\n[Internal link](https://github.com/elastic/security-team/issues/10820)\r\nto the feature details\r\n\r\nThese changes add sorting functionality to the migration rules table. It\r\nis possible to sort migration rules by next columns: `Updated`, `Name`,\r\n`Status`, `Risk Score`, `Severity` and `Author`.\r\n\r\n### Other changes\r\n\r\nNext fixes and adjustments were also implemented as part of this PR:\r\n* `Installed` status in migration rules table to indicate whether the\r\nrule was installed\r\n* Rules selection and installation of selected rules\r\n* Disable selection for not fully translated rules\r\n* `Author` column to show whether the translated rule matched one of the\r\nexisting Elastic prebuilt rules\r\n* `Install and enable` and `Install without enabling` buttons within the\r\nmigration rule details flyout","sha":"70a5bb33c438912b64259ea4c7a3c77c41f93f45"}}]}] BACKPORT--> --------- Co-authored-by: Ievgen Sorokopud <[email protected]>
…lastic#11379) (elastic#203396) ## Summary [Internal link](elastic/security-team#10820) to the feature details These changes add sorting functionality to the migration rules table. It is possible to sort migration rules by next columns: `Updated`, `Name`, `Status`, `Risk Score`, `Severity` and `Author`. ### Other changes Next fixes and adjustments were also implemented as part of this PR: * `Installed` status in migration rules table to indicate whether the rule was installed * Rules selection and installation of selected rules * Disable selection for not fully translated rules * `Author` column to show whether the translated rule matched one of the existing Elastic prebuilt rules * `Install and enable` and `Install without enabling` buttons within the migration rule details flyout
…lastic#11379) (elastic#203396) ## Summary [Internal link](elastic/security-team#10820) to the feature details These changes add sorting functionality to the migration rules table. It is possible to sort migration rules by next columns: `Updated`, `Name`, `Status`, `Risk Score`, `Severity` and `Author`. ### Other changes Next fixes and adjustments were also implemented as part of this PR: * `Installed` status in migration rules table to indicate whether the rule was installed * Rules selection and installation of selected rules * Disable selection for not fully translated rules * `Author` column to show whether the translated rule matched one of the existing Elastic prebuilt rules * `Install and enable` and `Install without enabling` buttons within the migration rule details flyout
Summary
Internal link to the feature details
These changes add sorting functionality to the migration rules table. It is possible to sort migration rules by next columns:
Updated
,Name
,Status
,Risk Score
,Severity
andAuthor
.Other changes
Next fixes and adjustments were also implemented as part of this PR:
Installed
status in migration rules table to indicate whether the rule was installedAuthor
column to show whether the translated rule matched one of the existing Elastic prebuilt rulesInstall and enable
andInstall without enabling
buttons within the migration rule details flyout