Skip to content

Commit ae015fb

Browse files
committed
Fix state filtering in the category list
1 parent 6aa31d4 commit ae015fb

3 files changed

Lines changed: 144 additions & 4 deletions

File tree

x-pack/plugins/monitoring/public/alerts/lib/__snapshots__/get_alert_panels_by_category.test.tsx.snap

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/monitoring/public/alerts/lib/get_alert_panels_by_category.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ describe('getAlertPanelsByCategory', () => {
181181
);
182182
expect(result).toMatchSnapshot();
183183
});
184+
185+
it('should allow for state filtering', () => {
186+
const alerts = [getAlert(ALERT_CPU_USAGE, 2)];
187+
const customStateFilter = (state: AlertState) => state.nodeName === 'es_name_0';
188+
const result = getAlertPanelsByCategory(
189+
panelTitle,
190+
false,
191+
alerts,
192+
alertsContext,
193+
customStateFilter
194+
);
195+
expect(result).toMatchSnapshot();
196+
});
184197
});
185198

186199
describe('setup mode', () => {

x-pack/plugins/monitoring/public/alerts/lib/get_alert_panels_by_category.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function getAlertPanelsByCategory(
6161
states: foundAlert.states,
6262
alertName,
6363
});
64-
categoryFiringAlertCount += foundAlert.states.length;
64+
categoryFiringAlertCount += states.length;
6565
}
6666
}
6767
}
@@ -144,12 +144,13 @@ export function getAlertPanelsByCategory(
144144
id: nodeIndex + 1,
145145
title: `${category.label}`,
146146
items: category.alerts.map(({ alertName, states }) => {
147+
const filteredStates = states.filter(({ state }) => stateFilter(state));
147148
const alertStatus = alertsContext.allAlerts[alertName];
148149
const name = inSetupMode ? (
149150
<EuiText>{alertStatus.rawAlert.name}</EuiText>
150151
) : (
151152
<EuiText>
152-
{alertStatus.rawAlert.name} ({states.length})
153+
{alertStatus.rawAlert.name} ({filteredStates.length})
153154
</EuiText>
154155
);
155156
return {
@@ -169,7 +170,7 @@ export function getAlertPanelsByCategory(
169170
for (const category of menu) {
170171
for (const { alert, states } of category.alerts) {
171172
const items = [];
172-
for (const alertState of states) {
173+
for (const alertState of states.filter(({ state }) => stateFilter(state))) {
173174
items.push({
174175
name: (
175176
<Fragment>
@@ -211,7 +212,7 @@ export function getAlertPanelsByCategory(
211212
}, menu.length);
212213
for (const category of menu) {
213214
for (const { alert, states } of category.alerts) {
214-
for (const state of states) {
215+
for (const state of states.filter(({ state: _state }) => stateFilter(_state))) {
215216
panels.push({
216217
id: ++tertiaryPanelIndex2,
217218
title: `${alert.name}`,

0 commit comments

Comments
 (0)