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

[Security Solution][Detections] Fix rule creation/editing forms #130825

Conversation

banderror
Copy link
Contributor

Addresses: #130767, #130770
Related to: #130771

Summary

A bug in the forms library presumably introduced in #130544 broke Rule Creation and Editing pages in Security Solution in the main branch. Cypress tests haven't been run in this PR, so it was merged which caused Cypress tests in main to start failing. @MadameSheema skipped those failing tests in #130771.

This PR:

Changes in src/plugins/es_ui_shared/static/forms/hook_form_lib/hooks/use_form.ts

@elastic/platform-deployment-management @sebelga @yuliacech please review the commit Fix 1: get back the deleted effect in useForm.

In Security Solution, we have multiple forms on the same rule creation/editing page for every step of the creation/editing process. We show or hide the forms depending on which step is currently active, so only one of the forms is visible at the same time. Without the effect that was deleted previously in #130544, it seems the useForm hook doesn't work on the mentioned pages.

@banderror banderror added bug Fixes for quality problems that affect the customer experience Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more release_note:skip Skip the PR/issue when compiling release notes impact:critical This issue should be addressed immediately due to a critical level of impact on the product. backport:skip This commit does not require backporting Team:Detections and Resp Security Detection Response Team Feature:Rule Management Security Solution Detection Rule Management area Team:Security Solution Platform Security Solution Platform Team Team:Detection Rule Management Security Detection Rule Management Team v8.3.0 labels Apr 21, 2022
@banderror banderror requested review from a team as code owners April 21, 2022 19:31
@banderror banderror self-assigned this Apr 21, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

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

Sorry for breaking your form by making that change. 😞 I still think I'd like to keep the change in the form lib and not rely on controlling the form values by changing the defaultValue object

const { form } = useForm({
  defaultValue: { ... } // this object will always be new on re-render of the component
});

I am happy to zoom and have a look at your form to see why you rely on the defaultValue (which is normally only used to declare the initial values of the fields) to swap field values.

You can use either the reset() method (which will also reset the states like isSubmitted) or now the new updateFieldValues() to update the form when needed.

Ping me if you want to zoom and have a look 😊

Copy link
Member

@MadameSheema MadameSheema left a comment

Choose a reason for hiding this comment

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

Approved from quality perspective:

Lots of thanks for the quick fix!!

@banderror banderror force-pushed the fix-bug-on-rule-creation-and-editing-pages branch from c3d73cc to 3dcef9a Compare April 28, 2022 16:04
@@ -29,7 +29,7 @@ import * as i18n from './translations';
export interface FieldValueQueryBar {
filters: Filter[];
query: Query;
saved_id?: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI there is an option you can pass to the form to not strip undefined value (https://docs.elastic.dev/form-lib/core/use-form#stripemptyfields)

@@ -659,6 +659,15 @@ export function useForm<T extends FormData = FormData, I extends FormData = T>(
// ----------------------------------
// -- EFFECTS
// ----------------------------------
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in my previous comment, please don't put the useEffect back. We can discuss over Zoom how to solve your form without counting on this.

@banderror
Copy link
Contributor Author

@sebelga thank you for your review. And sorry, I had to switch to another topic but will get back to this PR later, maybe next week or so. I think I'll need your help with this one so thank you for offering it 🙏 I'll ping you later, thanks again!

@banderror banderror force-pushed the fix-bug-on-rule-creation-and-editing-pages branch 3 times, most recently from c7bf08c to 7bac4cf Compare May 12, 2022 10:29
@banderror banderror force-pushed the fix-bug-on-rule-creation-and-editing-pages branch from 7bac4cf to 5e738f3 Compare May 16, 2022 10:39
@banderror banderror force-pushed the fix-bug-on-rule-creation-and-editing-pages branch 3 times, most recently from ca9c0dd to 227376c Compare May 19, 2022 09:21
@banderror banderror force-pushed the fix-bug-on-rule-creation-and-editing-pages branch 3 times, most recently from f90719b to 34ec0a1 Compare May 23, 2022 09:53
@sebelga
Copy link
Contributor

sebelga commented May 23, 2022

You won't solve the jest failure

Jest Tests #1 / useForm() hook config.defaultValue should be updated with the UseField "defaultValue" prop

until you remove the useEffect you've put back in.

IMO you should first remove the change to the form lib before fixing the form. 😊

@banderror banderror force-pushed the fix-bug-on-rule-creation-and-editing-pages branch from 34ec0a1 to 28c998a Compare May 24, 2022 11:17
@kibana-ci
Copy link
Collaborator

kibana-ci commented May 24, 2022

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #6 / EqlQueryBar sets the field value on input change
  • [job] [logs] Jest Tests #6 / useForm() hook config.defaultValue should be updated with the UseField "defaultValue" prop
  • [job] [logs] Jest Tests #2 / UserActionMarkdown useForm stale state bug creates a stale state if a key is not passed to the component

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2974 2975 +1

Async chunks

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

id before after diff
securitySolution 5.0MB 5.0MB +448.0B

Page load bundle

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

id before after diff
esUiShared 130.3KB 130.4KB +58.0B

History

  • 💔 Build #46811 failed 34ec0a1eaeed12e8213d1fd5d5e3114625c51be6
  • 💔 Build #46676 failed f90719b60df5881cff371e57532a0ba5475334ea
  • 💔 Build #46380 failed 5d5feaad865eb1781d547f85b97305a8fe42057a
  • 💔 Build #46035 failed 227376c0ba0f3144cb4f21bfabc58c1f51038c85

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

cc @banderror

@nkhristinin nkhristinin mentioned this pull request May 25, 2022
1 task
banderror pushed a commit that referenced this pull request May 30, 2022
**Addresses:** #130767, #130770

Related to [this PR](#130825).

@banderror described the reason for the problems in his PR. There was [ask ](#130825 (review)) to not return the `useEffect` to the form lib.

The fix of the form clears the values [in this commit](df0b7bb)

Then I cherry-pick commits from @banderror PR to fix form stripping undefined values and also fixed some tests

### Checklist

Delete any items that are not applicable to this PR.

- [ ] [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
kibanamachine pushed a commit that referenced this pull request May 30, 2022
**Addresses:** #130767, #130770

Related to [this PR](#130825).

@banderror described the reason for the problems in his PR. There was [ask ](#130825 (review)) to not return the `useEffect` to the form lib.

The fix of the form clears the values [in this commit](df0b7bb)

Then I cherry-pick commits from @banderror PR to fix form stripping undefined values and also fixed some tests

### Checklist

Delete any items that are not applicable to this PR.

- [ ] [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

(cherry picked from commit 52bdf9a)
@banderror
Copy link
Contributor Author

Closing this PR as @nkhristinin fixed the issues in #132834

@banderror banderror closed this May 30, 2022
@banderror banderror deleted the fix-bug-on-rule-creation-and-editing-pages branch May 30, 2022 16:20
banderror pushed a commit to banderror/kibana that referenced this pull request May 30, 2022
**Addresses:** elastic#130767, elastic#130770

Related to [this PR](elastic#130825).

@banderror described the reason for the problems in his PR. There was [ask ](elastic#130825 (review)) to not return the `useEffect` to the form lib.

The fix of the form clears the values [in this commit](elastic@df0b7bb)

Then I cherry-pick commits from @banderror PR to fix form stripping undefined values and also fixed some tests

### Checklist

Delete any items that are not applicable to this PR.

- [ ] [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

(cherry picked from commit 52bdf9a)
kibanamachine added a commit that referenced this pull request May 30, 2022
**Addresses:** #130767, #130770

Related to [this PR](#130825).

@banderror described the reason for the problems in his PR. There was [ask ](#130825 (review)) to not return the `useEffect` to the form lib.

The fix of the form clears the values [in this commit](df0b7bb)

Then I cherry-pick commits from @banderror PR to fix form stripping undefined values and also fixed some tests

### Checklist

Delete any items that are not applicable to this PR.

- [ ] [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

(cherry picked from commit 52bdf9a)

Co-authored-by: Khristinin Nikita <[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 bug Fixes for quality problems that affect the customer experience Feature:Rule Management Security Solution Detection Rule Management area impact:critical This issue should be addressed immediately due to a critical level of impact on the product. release_note:skip Skip the PR/issue when compiling release notes Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more Team:Security Solution Platform Security Solution Platform Team v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants