Skip to content
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

[Response Ops][Rule Form V2] Rule form v2: Actions Modal and Actions Form #187434

Merged
merged 54 commits into from
Sep 27, 2024

Conversation

JiaweiWu
Copy link
Contributor

@JiaweiWu JiaweiWu commented Jul 3, 2024

Summary

Issue: #179105
Related PR: #180539

Final PR of the rule actions V2 PR (2/2 of the actions PRs). This PR contains the actions modal and actions form. This PR depends on #186490.

I have also created a example plugin to demonstrate this PR. To access:

  1. Run the branch with yarn start --run-examples
  2. Navigate to http://localhost:5601/app/triggersActionsUiExample/rule/create/ (I use .es-query)
  3. Create a rule
  4. Navigate to http://localhost:5601/app/triggersActionsUiExample/rule/edit/ with the rule you just created to edit the rule
Screenshot 2024-07-02 at 5 15 51 PM

Screenshot 2024-07-08 at 10 53 44 PM

Screenshot 2024-07-02 at 5 15 58 PM

Checklist

@JiaweiWu JiaweiWu added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.16.0 labels Jul 3, 2024
@JiaweiWu JiaweiWu requested a review from a team as a code owner July 3, 2024 00:16
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

Copy link
Contributor

@ryankeairns ryankeairns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCSS review only - file renamed.

@JiaweiWu
Copy link
Contributor Author

JiaweiWu commented Sep 20, 2024

@cnasikas I believe this PR is ready for review now as I've addressed all of your comments

0fd8265 changes:

  • Address remaining comments
  • Added tests for:
    • packages/kbn-alerts-ui-shared/src/rule_form/utils/has_fields_for_aad.ts
    • packages/kbn-alerts-ui-shared/src/rule_form/utils/get_selected_action_group.ts
    • packages/kbn-alerts-ui-shared/src/rule_form/validation/validate_params_for_warnings.ts

I see that the index is passed in some components but given now that we switched to action.uuid I do not think is needed. What do you think of removing it? I know that the connectors' params still using it. To avoid changing all connectors maybe we can fake it to 0 and ignore it at the framework level.

Could you clarify what you mean by index?

I am a bit confused with the purpose of onUseDefaultMessage. What is the purpose of it? Could we remove it?

Looks like it's being used by the connector params components, check here for an example:

x-pack/plugins/stack_connectors/public/connector_types/teams/teams_params.test.tsx line 33

The normal actions and the system actions have, correctly, different components. They share a common UI but a good amount of different logic. If in the future we would need to apply a UI fix or enhance it we would have to remember to do it in both places. Is it feasible to do something like where the CommonRuleActionItem has the common UI and then each *Item contains its logic?

I would agree but again, I think it's easier to have 2 for now since I'm trying to match feature parity with the existing components. I think we went cross this road we can refactor it.

@JiaweiWu
Copy link
Contributor Author

@elasticmachine merge upstream

@cnasikas
Copy link
Member

cnasikas commented Sep 24, 2024

Hey @JiaweiWu! I tested and I can confirm that the bugs are fixed except for this one:

  • When I load a rule with the wrong ID I get the following error. Should we change the text from rule type -> rule?
Screenshot 2024-07-24 at 9 43 19 AM

Also, I noticed if we get a 404 error from the _resolve API, react query retries 3 times before showing the above error (screenshot). I think, if possible, it is better to not retry on 404 as nothing will change after 3 retries. We can leave this for another PR.

Could you clarify what you mean by index?

I was talking about the index prop passed to the RuleActionsItem. Nevermind, we can clean it up on another PR.

Looks like it's being used by the connector params components, check here for an example:

Ok!

I would agree but again, I think it's easier to have 2 for now since I'm trying to match feature parity with the existing components. I think we went cross this road we can refactor it.

Ok!

not forget to revert back to ALERTING_FEATURE_ID as we discussed offline :).

A reminder of the above

@JiaweiWu
Copy link
Contributor Author

In the commit 2cd1eed:

  • Fixed messaging for when the user tries to edit a rule that doesn't exist, also no longer calls _resolve 3 times
  • Changed rule form to use alerts instead of stackAlerts for default consumer
  • Added the use AAD template for mustache switch

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested and all bugs are fixed! LGTM! I left some nit comments but we can address them on a different PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test where we test the permissions for the actions section?

enabled: boolean;
}

export const useLoadRuleTypeAadTemplateField = (props: UseLoadRuleTypeAadTemplateFieldProps) => {
const { http, ruleTypeId, enabled } = props;

const queryFn = () => {
if (!ruleTypeId) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about returning Promise.resolve([])? If I recall returning a promise conditionally can lead to weird race condition bugs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test the new capabilities checks?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has quite a logic with hiding/showing some components. Should we add some basic unit tests for that?

payload: {
uuid: action.uuid!,
key: 'useAlertDataForTemplate',
value: !!!action.useAlertDataForTemplate,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: !Boolean(action.useAlertDataForTemplate)

@joana-cps
Copy link

Thanks, @JiaweiWu! I think the pattern in Kibana is to hide the section entirely if the user does not have access to a feature (though in cases we show a similar same message). I tested on the current flyout form and it is hidden. Should we follow the same pattern? @joana-cps Wdyt? About the editing, it seems that we do not allow it if you do not have access to actions. Just curiosity (not to do anything), what are the technical constraints with allowing the users to edit the rule but not the actions?

Although I don't like to have a step in the form that is disabled, I think it is a good idea to keep the section as @JiaweiWu did and inform that the user doesn't have privileges (at least for now).
And, I agree that we should explore the use cases for the Edit because it is weird to block the full edit capability when only a part of the rule requires a different privilege.

@JiaweiWu
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
alerting 235 237 +2
observability 1058 1060 +2
securitySolution 5829 5831 +2
triggersActionsUi 790 798 +8
total +14

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/alerts-ui-shared 287 301 +14

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
triggersActionsUi 1.6MB 1.6MB -1.4KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
triggersActionsUi 121.4KB 123.3KB +1.8KB
Unknown metric groups

API count

id before after diff
@kbn/alerts-ui-shared 303 317 +14

References to deprecated APIs

id before after diff
@kbn/alerts-ui-shared 0 8 +8

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@JiaweiWu JiaweiWu added v9.0.0 backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) and removed backport:skip This commit does not require backporting labels Sep 27, 2024
@JiaweiWu JiaweiWu merged commit 54659e8 into elastic:main Sep 27, 2024
37 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11065745004

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Sep 27, 2024
…Form (elastic#187434)

## Summary
Issue: elastic#179105
Related PR: elastic#180539

Final PR of the rule actions V2 PR (2/2 of the actions PRs). This PR
contains the actions modal and actions form. This PR depends on
elastic#186490.

I have also created a example plugin to demonstrate this PR. To access:

1. Run the branch with yarn start --run-examples
2. Navigate to
http://localhost:5601/app/triggersActionsUiExample/rule/create/<ruleTypeId>
(I use .es-query)
3. Create a rule
4. Navigate to
http://localhost:5601/app/triggersActionsUiExample/rule/edit/<ruleId>
with the rule you just created to edit the rule

<img width="1236" alt="Screenshot 2024-07-02 at 5 15 51 PM"
src="https://github.com/elastic/kibana/assets/74562234/1dc5d2a9-804a-4861-94ba-814de73dc3ab">

![Screenshot 2024-07-08 at 10 53
44 PM](https://github.com/elastic/kibana/assets/74562234/07efade1-4b9c-485f-9833-84698dc29219)

<img width="1087" alt="Screenshot 2024-07-02 at 5 15 58 PM"
src="https://github.com/elastic/kibana/assets/74562234/903e66b5-f9a1-4d09-b121-b1dcecdff72c">

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
(cherry picked from commit 54659e8)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Sep 27, 2024
…tions Form (#187434) (#194254)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Response Ops][Rule Form V2] Rule form v2: Actions Modal and Actions
Form (#187434)](#187434)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jiawei
Wu","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-27T06:34:27Z","message":"[Response
Ops][Rule Form V2] Rule form v2: Actions Modal and Actions Form
(#187434)\n\n## Summary\r\nIssue:
https://github.com/elastic/kibana/issues/179105\r\nRelated PR:
https://github.com/elastic/kibana/pull/180539\r\n\r\nFinal PR of the
rule actions V2 PR (2/2 of the actions PRs). This PR\r\ncontains the
actions modal and actions form. This PR depends
on\r\nhttps://github.com//pull/186490.\r\n\r\nI have also
created a example plugin to demonstrate this PR. To access:\r\n\r\n1.
Run the branch with yarn start --run-examples\r\n2. Navigate
to\r\nhttp://localhost:5601/app/triggersActionsUiExample/rule/create/<ruleTypeId>\r\n(I
use .es-query)\r\n3. Create a rule\r\n4. Navigate
to\r\nhttp://localhost:5601/app/triggersActionsUiExample/rule/edit/<ruleId>\r\nwith
the rule you just created to edit the rule\r\n\r\n<img width=\"1236\"
alt=\"Screenshot 2024-07-02 at 5 15
51 PM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/74562234/1dc5d2a9-804a-4861-94ba-814de73dc3ab\">\r\n\r\n![Screenshot
2024-07-08 at 10
53\r\n44 PM](https://github.com/elastic/kibana/assets/74562234/07efade1-4b9c-485f-9833-84698dc29219)\r\n\r\n<img
width=\"1087\" alt=\"Screenshot 2024-07-02 at 5 15
58 PM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/74562234/903e66b5-f9a1-4d09-b121-b1dcecdff72c\">\r\n\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"54659e8ae002aa68be3ee472ef12b3d3f546a1ea","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.16.0"],"title":"[Response
Ops][Rule Form V2] Rule form v2: Actions Modal and Actions
Form","number":187434,"url":"https://github.com/elastic/kibana/pull/187434","mergeCommit":{"message":"[Response
Ops][Rule Form V2] Rule form v2: Actions Modal and Actions Form
(#187434)\n\n## Summary\r\nIssue:
https://github.com/elastic/kibana/issues/179105\r\nRelated PR:
https://github.com/elastic/kibana/pull/180539\r\n\r\nFinal PR of the
rule actions V2 PR (2/2 of the actions PRs). This PR\r\ncontains the
actions modal and actions form. This PR depends
on\r\nhttps://github.com//pull/186490.\r\n\r\nI have also
created a example plugin to demonstrate this PR. To access:\r\n\r\n1.
Run the branch with yarn start --run-examples\r\n2. Navigate
to\r\nhttp://localhost:5601/app/triggersActionsUiExample/rule/create/<ruleTypeId>\r\n(I
use .es-query)\r\n3. Create a rule\r\n4. Navigate
to\r\nhttp://localhost:5601/app/triggersActionsUiExample/rule/edit/<ruleId>\r\nwith
the rule you just created to edit the rule\r\n\r\n<img width=\"1236\"
alt=\"Screenshot 2024-07-02 at 5 15
51 PM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/74562234/1dc5d2a9-804a-4861-94ba-814de73dc3ab\">\r\n\r\n![Screenshot
2024-07-08 at 10
53\r\n44 PM](https://github.com/elastic/kibana/assets/74562234/07efade1-4b9c-485f-9833-84698dc29219)\r\n\r\n<img
width=\"1087\" alt=\"Screenshot 2024-07-02 at 5 15
58 PM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/74562234/903e66b5-f9a1-4d09-b121-b1dcecdff72c\">\r\n\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"54659e8ae002aa68be3ee472ef12b3d3f546a1ea"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/187434","number":187434,"mergeCommit":{"message":"[Response
Ops][Rule Form V2] Rule form v2: Actions Modal and Actions Form
(#187434)\n\n## Summary\r\nIssue:
https://github.com/elastic/kibana/issues/179105\r\nRelated PR:
https://github.com/elastic/kibana/pull/180539\r\n\r\nFinal PR of the
rule actions V2 PR (2/2 of the actions PRs). This PR\r\ncontains the
actions modal and actions form. This PR depends
on\r\nhttps://github.com//pull/186490.\r\n\r\nI have also
created a example plugin to demonstrate this PR. To access:\r\n\r\n1.
Run the branch with yarn start --run-examples\r\n2. Navigate
to\r\nhttp://localhost:5601/app/triggersActionsUiExample/rule/create/<ruleTypeId>\r\n(I
use .es-query)\r\n3. Create a rule\r\n4. Navigate
to\r\nhttp://localhost:5601/app/triggersActionsUiExample/rule/edit/<ruleId>\r\nwith
the rule you just created to edit the rule\r\n\r\n<img width=\"1236\"
alt=\"Screenshot 2024-07-02 at 5 15
51 PM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/74562234/1dc5d2a9-804a-4861-94ba-814de73dc3ab\">\r\n\r\n![Screenshot
2024-07-08 at 10
53\r\n44 PM](https://github.com/elastic/kibana/assets/74562234/07efade1-4b9c-485f-9833-84698dc29219)\r\n\r\n<img
width=\"1087\" alt=\"Screenshot 2024-07-02 at 5 15
58 PM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/74562234/903e66b5-f9a1-4d09-b121-b1dcecdff72c\">\r\n\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>\r\nCo-authored-by:
Elastic Machine
<[email protected]>","sha":"54659e8ae002aa68be3ee472ef12b3d3f546a1ea"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Jiawei Wu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.16.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants