forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SIEM] [DETECTION ENGINE] Details and Edit view for a rule (elastic#5…
…3252) (elastic#53698) * re-structure detection engine + change routing name * add editing/details feature for a rule add feature to not edit immutable rule * review I * review II * change constant * review III
- Loading branch information
Showing
85 changed files
with
2,188 additions
and
1,528 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
12 changes: 12 additions & 0 deletions
12
x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/index.ts
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,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './api'; | ||
export * from './fetch_index_patterns'; | ||
export * from './persist_rule'; | ||
export * from './types'; | ||
export * from './use_rule'; | ||
export * from './use_rules'; |
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
67 changes: 67 additions & 0 deletions
67
x-pack/legacy/plugins/siem/public/containers/detection_engine/rules/use_rule.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,67 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { useEffect, useState } from 'react'; | ||
|
||
import { useKibanaUiSetting } from '../../../lib/settings/use_kibana_ui_setting'; | ||
import { DEFAULT_KBN_VERSION } from '../../../../common/constants'; | ||
import { useStateToaster } from '../../../components/toasters'; | ||
import { errorToToaster } from '../../../components/ml/api/error_to_toaster'; | ||
import { fetchRuleById } from './api'; | ||
import * as i18n from './translations'; | ||
import { Rule } from './types'; | ||
|
||
type Return = [boolean, Rule | null]; | ||
|
||
/** | ||
* Hook for using to get a Rule from the Detection Engine API | ||
* | ||
* @param id desired Rule ID's (not rule_id) | ||
* | ||
*/ | ||
export const useRule = (id: string | undefined): Return => { | ||
const [rule, setRule] = useState<Rule | null>(null); | ||
const [loading, setLoading] = useState(true); | ||
const [kbnVersion] = useKibanaUiSetting(DEFAULT_KBN_VERSION); | ||
const [, dispatchToaster] = useStateToaster(); | ||
|
||
useEffect(() => { | ||
let isSubscribed = true; | ||
const abortCtrl = new AbortController(); | ||
|
||
async function fetchData(idToFetch: string) { | ||
try { | ||
setLoading(true); | ||
const ruleResponse = await fetchRuleById({ | ||
id: idToFetch, | ||
kbnVersion, | ||
signal: abortCtrl.signal, | ||
}); | ||
|
||
if (isSubscribed) { | ||
setRule(ruleResponse); | ||
} | ||
} catch (error) { | ||
if (isSubscribed) { | ||
setRule(null); | ||
errorToToaster({ title: i18n.RULE_FETCH_FAILURE, error, dispatchToaster }); | ||
} | ||
} | ||
if (isSubscribed) { | ||
setLoading(false); | ||
} | ||
} | ||
if (id != null) { | ||
fetchData(id); | ||
} | ||
return () => { | ||
isSubscribed = false; | ||
abortCtrl.abort(); | ||
}; | ||
}, [id]); | ||
|
||
return [loading, rule]; | ||
}; |
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
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
Oops, something went wrong.