-
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
[SIEM] [Detection Engine] Update status on rule details page #55201
Changes from all commits
324560d
e682ec4
635d795
dadefe7
6fb3b35
6a91090
343065f
fa1ab17
45971da
7b84bcb
1f88860
b76b5eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,5 +96,5 @@ export interface Privilege { | |
write: boolean; | ||
}; | ||
}; | ||
isAuthenticated: boolean; | ||
is_authenticated: boolean; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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 { RuleStatusType } from '../../../../../containers/detection_engine/rules'; | ||
|
||
export const getStatusColor = (status: RuleStatusType | string | null) => | ||
status == null | ||
? 'subdued' | ||
: status === 'succeeded' | ||
? 'success' | ||
: status === 'failed' | ||
? 'danger' | ||
: status === 'executing' || status === 'going to run' | ||
? 'warning' | ||
: 'subdued'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This would really read much cleaner with a case statement, some switch statements , and an assert never through TypeScript. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. I'll update this. Gracias. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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 { | ||
EuiButtonIcon, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiHealth, | ||
EuiLoadingSpinner, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { isEqual } from 'lodash/fp'; | ||
import React, { memo, useCallback, useEffect, useState } from 'react'; | ||
|
||
import { useRuleStatus, RuleInfoStatus } from '../../../../../containers/detection_engine/rules'; | ||
import { FormattedDate } from '../../../../../components/formatted_date'; | ||
import { getEmptyTagValue } from '../../../../../components/empty_value'; | ||
import { getStatusColor } from './helpers'; | ||
import * as i18n from './translations'; | ||
|
||
interface RuleStatusProps { | ||
ruleId: string | null; | ||
ruleEnabled?: boolean | null; | ||
} | ||
|
||
const RuleStatusComponent: React.FC<RuleStatusProps> = ({ ruleId, ruleEnabled }) => { | ||
const [loading, ruleStatus, fetchRuleStatus] = useRuleStatus(ruleId); | ||
const [myRuleEnabled, setMyRuleEnabled] = useState<boolean | null>(ruleEnabled ?? null); | ||
const [currentStatus, setCurrentStatus] = useState<RuleInfoStatus | null>( | ||
ruleStatus?.current_status ?? null | ||
); | ||
|
||
useEffect(() => { | ||
if (myRuleEnabled !== ruleEnabled && fetchRuleStatus != null && ruleId != null) { | ||
fetchRuleStatus(ruleId); | ||
if (myRuleEnabled !== ruleEnabled) { | ||
setMyRuleEnabled(ruleEnabled ?? null); | ||
} | ||
} | ||
}, [fetchRuleStatus, myRuleEnabled, ruleId, ruleEnabled, setMyRuleEnabled]); | ||
|
||
useEffect(() => { | ||
if (!isEqual(currentStatus, ruleStatus?.current_status)) { | ||
setCurrentStatus(ruleStatus?.current_status ?? null); | ||
} | ||
}, [currentStatus, ruleStatus, setCurrentStatus]); | ||
|
||
const handleRefresh = useCallback(() => { | ||
if (fetchRuleStatus != null && ruleId != null) { | ||
fetchRuleStatus(ruleId); | ||
} | ||
}, [fetchRuleStatus, ruleId]); | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize="xs" alignItems="center" justifyContent="flexStart"> | ||
<EuiFlexItem grow={false}> | ||
{i18n.STATUS} | ||
{':'} | ||
</EuiFlexItem> | ||
{loading && ( | ||
<EuiFlexItem> | ||
<EuiLoadingSpinner size="m" data-test-subj="rule-status-loader" /> | ||
</EuiFlexItem> | ||
)} | ||
{!loading && ( | ||
<> | ||
<EuiFlexItem grow={false}> | ||
<EuiHealth color={getStatusColor(currentStatus?.status ?? null)}> | ||
<EuiText size="xs">{currentStatus?.status ?? getEmptyTagValue()}</EuiText> | ||
</EuiHealth> | ||
</EuiFlexItem> | ||
{currentStatus?.status_date != null && currentStatus?.status != null && ( | ||
<> | ||
<EuiFlexItem grow={false}> | ||
<>{i18n.STATUS_AT}</> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true}> | ||
<FormattedDate value={currentStatus?.status_date} fieldName={i18n.STATUS_DATE} /> | ||
</EuiFlexItem> | ||
</> | ||
)} | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonIcon | ||
color="primary" | ||
onClick={handleRefresh} | ||
iconType="refresh" | ||
aria-label={i18n.REFRESH} | ||
/> | ||
</EuiFlexItem> | ||
</> | ||
)} | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
|
||
export const RuleStatus = memo(RuleStatusComponent); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const STATUS = i18n.translate('xpack.siem.detectionEngine.ruleStatus.statusDescription', { | ||
defaultMessage: 'Status', | ||
}); | ||
|
||
export const STATUS_AT = i18n.translate( | ||
'xpack.siem.detectionEngine.ruleStatus.statusAtDescription', | ||
{ | ||
defaultMessage: 'at', | ||
} | ||
); | ||
|
||
export const STATUS_DATE = i18n.translate( | ||
'xpack.siem.detectionEngine.ruleStatus.statusDateDescription', | ||
{ | ||
defaultMessage: 'Status date', | ||
} | ||
); | ||
|
||
export const REFRESH = i18n.translate('xpack.siem.detectionEngine.ruleStatus.refreshButton', { | ||
defaultMessage: 'Refresh', | ||
}); |
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.
Nice! Thank you 👍