-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.18] [Security Solution] Disable update button when editing field i…
…n rule update flyout (#205999) (#209401) # Backport This will backport the following commits from `main` to `8.18`: - [[Security Solution] Disable update button when editing field in rule update flyout (#205999)](#205999) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Jacek Kolezynski","email":"jacek.kolezynski@elastic.co"},"sourceCommit":{"committedDate":"2025-02-03T18:41:24Z","message":"[Security Solution] Disable update button when editing field in rule update flyout (#205999)\n\n**Resolves: #203912**\n\n## Summary\n\nWhen editing a field in Rule Update flyout, the `Update` button should\nbe temporarily disabled. Currently it is enabled all the time which is\ncounterintuitive and may lead to errors.\n\n## BEFORE\n\n\nhttps://github.com/user-attachments/assets/ef2c7580-247f-4eb1-96aa-43c9454e0e94\n\n## AFTER\n\n\nhttps://github.com/user-attachments/assets/02c6a3a8-861c-4d41-8dbd-52defb63f642\n\n---------\n\nCo-authored-by: Nikita Indik <nikita.indik@elastic.co>","sha":"9891bbdd61e1f2f0d7203b0be27544d4f8f3ef06","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","v9.0.0","Team:Detections and Resp","Team: SecuritySolution","Team:Detection Rule Management","Feature:Prebuilt Detection Rules","backport:version","v8.18.0","v9.1.0"],"title":"[Security Solution] Disable update button when editing field in rule update flyout","number":205999,"url":"https://github.com/elastic/kibana/pull/205999","mergeCommit":{"message":"[Security Solution] Disable update button when editing field in rule update flyout (#205999)\n\n**Resolves: #203912**\n\n## Summary\n\nWhen editing a field in Rule Update flyout, the `Update` button should\nbe temporarily disabled. Currently it is enabled all the time which is\ncounterintuitive and may lead to errors.\n\n## BEFORE\n\n\nhttps://github.com/user-attachments/assets/ef2c7580-247f-4eb1-96aa-43c9454e0e94\n\n## AFTER\n\n\nhttps://github.com/user-attachments/assets/02c6a3a8-861c-4d41-8dbd-52defb63f642\n\n---------\n\nCo-authored-by: Nikita Indik <nikita.indik@elastic.co>","sha":"9891bbdd61e1f2f0d7203b0be27544d4f8f3ef06"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205999","number":205999,"mergeCommit":{"message":"[Security Solution] Disable update button when editing field in rule update flyout (#205999)\n\n**Resolves: #203912**\n\n## Summary\n\nWhen editing a field in Rule Update flyout, the `Update` button should\nbe temporarily disabled. Currently it is enabled all the time which is\ncounterintuitive and may lead to errors.\n\n## BEFORE\n\n\nhttps://github.com/user-attachments/assets/ef2c7580-247f-4eb1-96aa-43c9454e0e94\n\n## AFTER\n\n\nhttps://github.com/user-attachments/assets/02c6a3a8-861c-4d41-8dbd-52defb63f642\n\n---------\n\nCo-authored-by: Nikita Indik <nikita.indik@elastic.co>","sha":"9891bbdd61e1f2f0d7203b0be27544d4f8f3ef06"}}]}] BACKPORT--> Co-authored-by: Jacek Kolezynski <jacek.kolezynski@elastic.co>
- Loading branch information
1 parent
21be576
commit 0dea724
Showing
5 changed files
with
169 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...anagement_ui/components/rules_table/upgrade_prebuilt_rules_table/rule_preview_context.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { invariant } from '@formatjs/intl-utils'; | ||
import useSet from 'react-use/lib/useSet'; | ||
import React, { createContext, useContext, useEffect, useMemo } from 'react'; | ||
import usePrevious from 'react-use/lib/usePrevious'; | ||
|
||
export interface RulePreviewContextType { | ||
/** | ||
* Sets the rule is being edited in the rule upgrade flyout | ||
*/ | ||
setFieldEditing: (fieldName: string) => void; | ||
|
||
/** | ||
* Sets the rule is not being edited in the rule upgrade flyout | ||
*/ | ||
setFieldReadonly: (fieldName: string) => void; | ||
|
||
/** | ||
* Returns whether the rule is being edited in the rule upgrade flyout | ||
*/ | ||
isEditingRule: boolean; | ||
} | ||
|
||
const RulePreviewContext = createContext<RulePreviewContextType | null>(null); | ||
|
||
interface RulePreviewContextProviderProps { | ||
children: React.ReactNode; | ||
ruleId: string | undefined; | ||
} | ||
|
||
export function RulePreviewContextProvider({ children, ruleId }: RulePreviewContextProviderProps) { | ||
const [editedFields, { add, remove, reset }] = useSet<string>(); | ||
const prevRuleId = usePrevious(ruleId); | ||
|
||
useEffect(() => { | ||
if (ruleId !== prevRuleId) { | ||
reset(); | ||
} | ||
}, [reset, ruleId, prevRuleId]); | ||
|
||
const isEditingRule = editedFields.size > 0; | ||
|
||
const contextValue: RulePreviewContextType = useMemo( | ||
() => ({ | ||
isEditingRule, | ||
setFieldEditing: add, | ||
setFieldReadonly: remove, | ||
}), | ||
[isEditingRule, add, remove] | ||
); | ||
|
||
return <RulePreviewContext.Provider value={contextValue}>{children}</RulePreviewContext.Provider>; | ||
} | ||
|
||
export function useRulePreviewContext() { | ||
const context = useContext(RulePreviewContext); | ||
|
||
invariant( | ||
context !== null, | ||
'useRulePreviewContext must be used inside a RulePreviewContextProvider' | ||
); | ||
|
||
return context; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters