-
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
[Detections][Alerts] fixes saved_query rule validation issue #142602
[Detections][Alerts] fixes saved_query rule validation issue #142602
Conversation
…/vitaliidm/kibana into alerts/saved_query_ux_validation
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.
@vitaliidm overall the changes look good, though there is a couple of comments worth to check.
@@ -98,6 +100,11 @@ const EditRulePageComponent: FC = () => { | |||
const [ruleLoading, rule] = useRule(ruleId); | |||
const loading = ruleLoading || userInfoLoading || listsConfigLoading; | |||
|
|||
const { isSavedQueryLoading, savedQueryBar, savedQuery } = useGetSavedQuery(rule?.saved_id, { | |||
ruleType: rule?.type, | |||
onError: noop, |
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.
onError: noop,
reduces straightness of the code since it requires knowledge what's going on under the hood and suppressing of that behaviour when necessary. I'd recommend to consider removing the default error handling functionality inside, exposing of showErrorToastHandler
and passing it directly when necessary. Though it uses toasts
then it makes sense to expose a hook like useShowErrorToastHandler()
which can be composable and reusable.
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.
@maximpn
Toast is not displayed in this case because error is displayed on edit form when saved query is not loaded. Thus it's prevents showing duplicated notifications
<StepPanel loading={loading} title={ruleI18n.DEFINITION}> | ||
{defineStep.data != null && ( | ||
<StepPanel loading={loading || isSavedQueryLoading} title={ruleI18n.DEFINITION}> | ||
{defineStepDataWithSavedQuery != null && !isSavedQueryLoading && ( |
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.
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.
non strict check for null
eliminates undefined
, so the value of defineStepDataWithSavedQuery
will be object of DefineStepRule
type.
Fairly common pattern across Kibana codebase (example from previous implementation):
<StepPanel loading={loading} title={ruleI18n.DEFINITION}>
{defineStep.data != null && (
@elasticmachine merge upstream |
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.
@vitaliidm LGTM
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @vitaliidm |
…#142602) ## Summary - addresses elastic#141758 - loads saved query on rules edit page before form rendering, thus prevents validation run on uncompleted data(saved query wasn't fetched before QueryBar component renders). Then fetched saved query passed to QueryBarDefineRule component ### Before https://user-images.githubusercontent.com/92328789/193884969-3647e06b-085a-4923-82e8-546bedabeb3e.mp4 ### After https://user-images.githubusercontent.com/92328789/193884323-629fb879-3a51-4412-8b63-2f36afc618cb.mov As side effect, it reduced number of requests for saved query: #### Before 2 requests were sent <img width="1995" alt="Screenshot 2022-10-05 at 09 39 09" src="https://user-images.githubusercontent.com/92328789/194018652-5612a032-e908-4e01-9858-2049c8e453e2.png"> #### After Only one request sent ### Checklist <img width="1996" alt="Screenshot 2022-10-05 at 09 37 12" src="https://user-images.githubusercontent.com/92328789/194018637-770a08df-832b-4838-a060-05058c436ed6.png"> Delete any items that are not applicable to this PR. - [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 (cherry picked from commit 4feb397)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
#143008) ## Summary - addresses #141758 - loads saved query on rules edit page before form rendering, thus prevents validation run on uncompleted data(saved query wasn't fetched before QueryBar component renders). Then fetched saved query passed to QueryBarDefineRule component ### Before https://user-images.githubusercontent.com/92328789/193884969-3647e06b-085a-4923-82e8-546bedabeb3e.mp4 ### After https://user-images.githubusercontent.com/92328789/193884323-629fb879-3a51-4412-8b63-2f36afc618cb.mov As side effect, it reduced number of requests for saved query: #### Before 2 requests were sent <img width="1995" alt="Screenshot 2022-10-05 at 09 39 09" src="https://user-images.githubusercontent.com/92328789/194018652-5612a032-e908-4e01-9858-2049c8e453e2.png"> #### After Only one request sent ### Checklist <img width="1996" alt="Screenshot 2022-10-05 at 09 37 12" src="https://user-images.githubusercontent.com/92328789/194018637-770a08df-832b-4838-a060-05058c436ed6.png"> Delete any items that are not applicable to this PR. - [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 (cherry picked from commit 4feb397) Co-authored-by: Vitalii Dmyterko <[email protected]>
Summary
Before
saved_query_bug.mp4
After
Screen.Recording.2022-10-04.at.18.15.43.mov
As side effect, it reduced number of requests for saved query:
Before
2 requests were sent
After
Only one request sent
Checklist
Delete any items that are not applicable to this PR.