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] Allow rewriting rule create props in Cypress tests #153474
Conversation
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
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.
Thank you for this refactoring, @maximpn 👍
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.
LGTM!
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.
LGTM on explore changes, thank you!
defdc3d
to
bcb9359
Compare
…-ref HEAD~1..HEAD --fix'
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @maximpn |
@maximpn please be mindful about backports 🙏 |
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.
Thank you for dev-ex optimization and detailed description here @maximpn 🙂 -- LGTM! 👍
💔 All backports failed
Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
elastic#153474) **Relates to:** elastic#150553 ## Summary This PR is based on the review comments in elastic#150553. It allows to rewrite rule create properties. ## Details Rule create properties are returned by helper functions like `getNewRule()`, `getNewThresholdRule()` and so on. So instead of `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` it allows to use a concise and a much more readable structure `createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' ))`. ## Possible improvements The PR doesn't implement deep / nested fields merge. High level fields completely rewrite default values. Deep merge would allow to extend defaults with the provided rewrites. For example, overriding nested properties become tiresome quickly, as shown in the following code snippet: ```ts const rule = { ...getNewTermsRule(), rule_id: 'new_rule_id', runsEvery: { interval: '1', ...getNewTermsRule().runsEvery, }, }; ``` If we implement deep merge, the readability could be greatly improved: ```ts const rule = getNewTermsRule({ rule_id: 'new_rule_id', runsEvery: { interval: '1', }, }); ``` While it looks as a good idea we should take into consideration the fact that complete rewriting of default values can be a desired behavior. Engineers could tend to switch to `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` to overcome deep merge. So it should be analysed carefully before implementing it. (cherry picked from commit ca696ac) # Conflicts: # x-pack/plugins/security_solution/cypress/e2e/detection_alerts/alerts_charts.cy.ts # x-pack/plugins/security_solution/cypress/e2e/detection_alerts/detection_page_filters.cy.ts # x-pack/plugins/security_solution/cypress/e2e/exceptions/add_edit_flyout/flyout_validation.cy.ts
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…s tests (#153474) (#154332) # Backport This will backport the following commits from `main` to `8.7`: - [[Security Solution] Allow rewriting rule create props in Cypress tests (#153474)](#153474) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Maxim Palenov","email":"maxim.palenov@elastic.co"},"sourceCommit":{"committedDate":"2023-03-27T09:08:38Z","message":"[Security Solution] Allow rewriting rule create props in Cypress tests (#153474)\n\n**Relates to:** #150553 Summary\r\n\r\nThis PR is based on the review comments in #150553. It allows to rewrite rule create properties.\r\n\r\n## Details\r\n\r\nRule create properties are returned by helper functions like `getNewRule()`, `getNewThresholdRule()` and so on. So instead of `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` it allows to use a concise and a much more readable structure `createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' ))`.\r\n\r\n## Possible improvements\r\n\r\nThe PR doesn't implement deep / nested fields merge. High level fields completely rewrite default values. Deep merge would allow to extend defaults with the provided rewrites. For example, overriding nested properties become tiresome quickly, as shown in the following code snippet:\r\n\r\n```ts\r\nconst rule = {\r\n ...getNewTermsRule(),\r\n rule_id: 'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n ...getNewTermsRule().runsEvery,\r\n },\r\n};\r\n```\r\n\r\nIf we implement deep merge, the readability could be greatly improved:\r\n\r\n```ts\r\nconst rule = getNewTermsRule({\r\n rule_id: 'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n },\r\n});\r\n```\r\n\r\nWhile it looks as a good idea we should take into consideration the fact that complete rewriting of default values can be a desired behavior. Engineers could tend to switch to `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` to overcome deep merge. So it should be analysed carefully before implementing it.","sha":"ca696ac50c0591acf6723e130d2f9278c2d6ef65","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["test","refactoring","test_ui_functional","technical debt","release_note:skip","Team:Detections and Resp","Team: SecuritySolution","Team:Detection Rules","backport:prev-minor","v8.8.0"],"number":153474,"url":"#153474 Solution] Allow rewriting rule create props in Cypress tests (#153474)\n\n**Relates to:** #150553 Summary\r\n\r\nThis PR is based on the review comments in #150553. It allows to rewrite rule create properties.\r\n\r\n## Details\r\n\r\nRule create properties are returned by helper functions like `getNewRule()`, `getNewThresholdRule()` and so on. So instead of `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` it allows to use a concise and a much more readable structure `createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' ))`.\r\n\r\n## Possible improvements\r\n\r\nThe PR doesn't implement deep / nested fields merge. High level fields completely rewrite default values. Deep merge would allow to extend defaults with the provided rewrites. For example, overriding nested properties become tiresome quickly, as shown in the following code snippet:\r\n\r\n```ts\r\nconst rule = {\r\n ...getNewTermsRule(),\r\n rule_id: 'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n ...getNewTermsRule().runsEvery,\r\n },\r\n};\r\n```\r\n\r\nIf we implement deep merge, the readability could be greatly improved:\r\n\r\n```ts\r\nconst rule = getNewTermsRule({\r\n rule_id: 'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n },\r\n});\r\n```\r\n\r\nWhile it looks as a good idea we should take into consideration the fact that complete rewriting of default values can be a desired behavior. Engineers could tend to switch to `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` to overcome deep merge. So it should be analysed carefully before implementing it.","sha":"ca696ac50c0591acf6723e130d2f9278c2d6ef65"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"#153474 Solution] Allow rewriting rule create props in Cypress tests (#153474)\n\n**Relates to:** #150553 Summary\r\n\r\nThis PR is based on the review comments in #150553. It allows to rewrite rule create properties.\r\n\r\n## Details\r\n\r\nRule create properties are returned by helper functions like `getNewRule()`, `getNewThresholdRule()` and so on. So instead of `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` it allows to use a concise and a much more readable structure `createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' ))`.\r\n\r\n## Possible improvements\r\n\r\nThe PR doesn't implement deep / nested fields merge. High level fields completely rewrite default values. Deep merge would allow to extend defaults with the provided rewrites. For example, overriding nested properties become tiresome quickly, as shown in the following code snippet:\r\n\r\n```ts\r\nconst rule = {\r\n ...getNewTermsRule(),\r\n rule_id: 'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n ...getNewTermsRule().runsEvery,\r\n },\r\n};\r\n```\r\n\r\nIf we implement deep merge, the readability could be greatly improved:\r\n\r\n```ts\r\nconst rule = getNewTermsRule({\r\n rule_id: 'new_rule_id',\r\n runsEvery: {\r\n interval: '1',\r\n },\r\n});\r\n```\r\n\r\nWhile it looks as a good idea we should take into consideration the fact that complete rewriting of default values can be a desired behavior. Engineers could tend to switch to `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` to overcome deep merge. So it should be analysed carefully before implementing it.","sha":"ca696ac50c0591acf6723e130d2f9278c2d6ef65"}}]}] BACKPORT-->
Relates to: #150553
Summary
This PR is based on the review comments in #150553. It allows to rewrite rule create properties.
Details
Rule create properties are returned by helper functions like
getNewRule()
,getNewThresholdRule()
and so on. So instead ofcreateRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })
it allows to use a concise and a much more readable structurecreateRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' ))
.Possible improvements
The PR doesn't implement deep / nested fields merge. High level fields completely rewrite default values. Deep merge would allow to extend defaults with the provided rewrites. For example, overriding nested properties become tiresome quickly, as shown in the following code snippet:
If we implement deep merge, the readability could be greatly improved:
While it looks as a good idea we should take into consideration the fact that complete rewriting of default values can be a desired behavior. Engineers could tend to switch to
createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })
to overcome deep merge. So it should be analysed carefully before implementing it.