Skip to content

Commit

Permalink
Fix state filtering in the category list
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Dec 12, 2020
1 parent 6aa31d4 commit ae015fb
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 4 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ describe('getAlertPanelsByCategory', () => {
);
expect(result).toMatchSnapshot();
});

it('should allow for state filtering', () => {
const alerts = [getAlert(ALERT_CPU_USAGE, 2)];
const customStateFilter = (state: AlertState) => state.nodeName === 'es_name_0';
const result = getAlertPanelsByCategory(
panelTitle,
false,
alerts,
alertsContext,
customStateFilter
);
expect(result).toMatchSnapshot();
});
});

describe('setup mode', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function getAlertPanelsByCategory(
states: foundAlert.states,
alertName,
});
categoryFiringAlertCount += foundAlert.states.length;
categoryFiringAlertCount += states.length;
}
}
}
Expand Down Expand Up @@ -144,12 +144,13 @@ export function getAlertPanelsByCategory(
id: nodeIndex + 1,
title: `${category.label}`,
items: category.alerts.map(({ alertName, states }) => {
const filteredStates = states.filter(({ state }) => stateFilter(state));
const alertStatus = alertsContext.allAlerts[alertName];
const name = inSetupMode ? (
<EuiText>{alertStatus.rawAlert.name}</EuiText>
) : (
<EuiText>
{alertStatus.rawAlert.name} ({states.length})
{alertStatus.rawAlert.name} ({filteredStates.length})
</EuiText>
);
return {
Expand All @@ -169,7 +170,7 @@ export function getAlertPanelsByCategory(
for (const category of menu) {
for (const { alert, states } of category.alerts) {
const items = [];
for (const alertState of states) {
for (const alertState of states.filter(({ state }) => stateFilter(state))) {
items.push({
name: (
<Fragment>
Expand Down Expand Up @@ -211,7 +212,7 @@ export function getAlertPanelsByCategory(
}, menu.length);
for (const category of menu) {
for (const { alert, states } of category.alerts) {
for (const state of states) {
for (const state of states.filter(({ state: _state }) => stateFilter(_state))) {
panels.push({
id: ++tertiaryPanelIndex2,
title: `${alert.name}`,
Expand Down

0 comments on commit ae015fb

Please sign in to comment.