-
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.
[Alerting UI] Display a banner to users when some alerts have failure…
…s, added alert statuses column and filters (#79038) (#79403) * Added ui for alert failures banner * Added UI for alerts statuses * Adjusted form * Added banned on the details page * Fixed failing intern. check and type checks * Added unit test for displaying alert error banner * Fixed type check * Fixed due to comments * Changes due to comments * Fixed due to comments * Fixed text on banners * Added i18n translations
- Loading branch information
1 parent
5d9c0e1
commit 83ebceb
Showing
8 changed files
with
557 additions
and
41 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
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
105 changes: 105 additions & 0 deletions
105
...ers_actions_ui/public/application/sections/alerts_list/components/alert_status_filter.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,105 @@ | ||
/* | ||
* 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 React, { useEffect, useState } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { | ||
EuiFilterGroup, | ||
EuiPopover, | ||
EuiFilterButton, | ||
EuiFilterSelectItem, | ||
EuiHealth, | ||
} from '@elastic/eui'; | ||
import { | ||
AlertExecutionStatuses, | ||
AlertExecutionStatusValues, | ||
} from '../../../../../../alerts/common'; | ||
import { alertsStatusesTranslationsMapping } from '../translations'; | ||
|
||
interface AlertStatusFilterProps { | ||
selectedStatuses: string[]; | ||
onChange?: (selectedAlertStatusesIds: string[]) => void; | ||
} | ||
|
||
export const AlertStatusFilter: React.FunctionComponent<AlertStatusFilterProps> = ({ | ||
selectedStatuses, | ||
onChange, | ||
}: AlertStatusFilterProps) => { | ||
const [selectedValues, setSelectedValues] = useState<string[]>(selectedStatuses); | ||
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
if (onChange) { | ||
onChange(selectedValues); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [selectedValues]); | ||
|
||
useEffect(() => { | ||
setSelectedValues(selectedStatuses); | ||
}, [selectedStatuses]); | ||
|
||
return ( | ||
<EuiFilterGroup> | ||
<EuiPopover | ||
isOpen={isPopoverOpen} | ||
closePopover={() => setIsPopoverOpen(false)} | ||
button={ | ||
<EuiFilterButton | ||
iconType="arrowDown" | ||
hasActiveFilters={selectedValues.length > 0} | ||
numActiveFilters={selectedValues.length} | ||
numFilters={selectedValues.length} | ||
onClick={() => setIsPopoverOpen(!isPopoverOpen)} | ||
> | ||
<FormattedMessage | ||
id="xpack.triggersActionsUI.sections.alertsList.alertStatusFilterLabel" | ||
defaultMessage="Status" | ||
/> | ||
</EuiFilterButton> | ||
} | ||
> | ||
<div className="euiFilterSelect__items"> | ||
{[...AlertExecutionStatusValues].sort().map((item: AlertExecutionStatuses) => { | ||
const healthColor = getHealthColor(item); | ||
return ( | ||
<EuiFilterSelectItem | ||
key={item} | ||
style={{ textTransform: 'capitalize' }} | ||
onClick={() => { | ||
const isPreviouslyChecked = selectedValues.includes(item); | ||
if (isPreviouslyChecked) { | ||
setSelectedValues(selectedValues.filter((val) => val !== item)); | ||
} else { | ||
setSelectedValues(selectedValues.concat(item)); | ||
} | ||
}} | ||
checked={selectedValues.includes(item) ? 'on' : undefined} | ||
> | ||
<EuiHealth color={healthColor}>{alertsStatusesTranslationsMapping[item]}</EuiHealth> | ||
</EuiFilterSelectItem> | ||
); | ||
})} | ||
</div> | ||
</EuiPopover> | ||
</EuiFilterGroup> | ||
); | ||
}; | ||
|
||
export function getHealthColor(status: AlertExecutionStatuses) { | ||
switch (status) { | ||
case 'active': | ||
return 'primary'; | ||
case 'error': | ||
return 'danger'; | ||
case 'ok': | ||
return 'subdued'; | ||
case 'pending': | ||
return 'success'; | ||
default: | ||
return 'warning'; | ||
} | ||
} |
Oops, something went wrong.