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] Prepare Rule Form V2 Action Form Dependencies #186490

Merged
merged 34 commits into from
Jul 19, 2024

Conversation

JiaweiWu
Copy link
Contributor

Summary

Issue: #179106

Depends on this PR: #184892

Part 1/2 of the action form portion of the rule form V2. This PR doesn't add any functionality, all it's doing is moving some of the dependencies needed by the second PR to packages so it can be shared.

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.15.0 labels Jun 20, 2024
@JiaweiWu JiaweiWu requested a review from a team as a code owner June 20, 2024 00:33
@elasticmachine
Copy link
Contributor

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

@cnasikas cnasikas added v8.16.0 and removed v8.15.0 labels Jul 5, 2024
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.

LGTM! I left some comments. I noticed that the following files are missing tests. How would you like to handle that?

  • packages/kbn-alerts-ui-shared/src/action_variables/get_available_action_variables.ts
  • packages/kbn-alerts-ui-shared/src/action_variables/transforms.ts
  • packages/kbn-alerts-ui-shared/src/common/apis/fetch_connector_types/transform_connector_types_response.ts
  • packages/kbn-alerts-ui-shared/src/common/apis/fetch_connectors/transform_connectors_response.ts
  • packages/kbn-alerts-ui-shared/src/common/hooks/use_load_connector_types.ts
  • packages/kbn-alerts-ui-shared/src/common/hooks/use_load_connectors.ts
  • packages/kbn-alerts-ui-shared/src/common/hooks/use_load_rule_type_aad_template_fields.ts

About the new hooks, is there any plan to use them in the flyout or they are dedicated to the new rule form?

Copy link
Member

@cnasikas cnasikas Jul 10, 2024

Choose a reason for hiding this comment

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

super nit: Wdyt about deleting this file and importing the function in the files that need it? Same for x-pack/plugins/triggers_actions_ui/public/application/lib/action_connector_api/connectors.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a bit annoying to do this now because other plugins are importing this from triggers actions UI (x-pack/packages/kbn-elastic-assistant/impl/connectorland/use_load_action_types/index.tsx) for example

return fetchConnectorTypes({ http, includeSystemActions });
};

const { data, isLoading, isFetching, isInitialLoading } = useQuery({
Copy link
Member

Choose a reason for hiding this comment

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

In our last sync, @umbopepato suggested returning the whole value of the useQuery hook instead of choosing specific attributes to return. There are a lot of benefits like consistency in types, automatic type inference from the hook, chain query objects, and the ability to select which loading state you would like to check. For example, when the enable property is false the isLoading is true but the isFetching is false. What do you think?

Same for packages/kbn-alerts-ui-shared/src/common/hooks/use_load_connectors.ts and packages/kbn-alerts-ui-shared/src/common/hooks/use_load_rule_type_aad_template_fields.ts.

Copy link
Contributor Author

@JiaweiWu JiaweiWu Jul 11, 2024

Choose a reason for hiding this comment

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

Yea I dont really mind, i think we had a bug where if we just check isLoading, it doesn't tell us 100% if it was loading, so we had to check isLoading || isFetching. I just use that now to be safe.

@JiaweiWu
Copy link
Contributor Author

JiaweiWu commented Jul 11, 2024

LGTM! I left some comments. I noticed that the following files are missing tests. How would you like to handle that?
packages/kbn-alerts-ui-shared/src/action_variables/get_available_action_variables.ts
packages/kbn-alerts-ui-shared/src/action_variables/transforms.ts

those tests already exist packages/kbn-alerts-ui-shared/src/action_variables/transforms.test.ts, I added tests for the rest.

About the new hooks, is there any plan to use them in the flyout or they are dedicated to the new rule form?

I think we can do this when we phase out the old form

@JiaweiWu
Copy link
Contributor Author

@elasticmachine merge upstream

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.

LGMT! Thanks for adding the tests!

jest.clearAllMocks();
});

test('should call API endpoint with the correct parameters', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

The test description says it verifies if the endpoint was called with correct params but we do not check that in the tests. Should we add it along with the response check we already have?


expect(result.current.data).toEqual([
{
description: '',
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the description have the description value based on the HTTP response?

import { DataViewField } from '@kbn/data-views-plugin/common';
import { BASE_RAC_ALERTS_API_PATH, EMPTY_AAD_FIELDS } from '../../constants';

export const getDescription = (fieldName: string, ecsFlat: Record<string, EcsMetadata>) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: would be nice to have basic test for getDescription .

return fetchConnectors({ http, includeSystemActions });
};

const { data, isLoading, isFetching, isInitialLoading } = useQuery({
Copy link
Contributor

Choose a reason for hiding this comment

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

I might not have full idea here so might be stupid question: how do we handle error scenarios for all these hooks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha yea we don't really handle errors because if the endpoint fails then something quite wrong has happened

@JiaweiWu JiaweiWu enabled auto-merge (squash) July 19, 2024 00:01
@JiaweiWu JiaweiWu merged commit f3cdd3b into elastic:main Jul 19, 2024
33 checks passed
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
alerting 214 223 +9
observability 1039 1059 +20
securitySolution 5614 5634 +20
triggersActionsUi 771 803 +32
total +81

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/actions-types 5 14 +9
@kbn/alerts-ui-shared 283 284 +1
@kbn/triggers-actions-ui-types 11 15 +4
total +14

Async chunks

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

id before after diff
alerting 91.5KB 91.7KB +145.0B
observability 419.7KB 420.1KB +417.0B
securitySolution 16.4MB 16.4MB +299.0B
triggersActionsUi 1.6MB 1.7MB +8.0KB
total +8.8KB

Page load bundle

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

id before after diff
alerting 25.0KB 25.5KB +418.0B
triggersActionsUi 119.9KB 120.4KB +520.0B
total +938.0B
Unknown metric groups

API count

id before after diff
@kbn/actions-types 5 14 +9
@kbn/alerts-ui-shared 299 300 +1
@kbn/triggers-actions-ui-types 11 15 +4
total +14

History

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

## 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/<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]>
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 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:skip This commit does not require backporting 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants