Skip to content

Commit 79381ec

Browse files
opensearch-trigger-bot[bot]jovancvetkovic3006
authored andcommitted
Adds findings alerts legend in overview page (opensearch-project#318) (opensearch-project#321)
* [FEATURE] Detector must have at least one alert set opensearch-project#288 Signed-off-by: Jovan Cvetkovic <[email protected]> * [FEATURE] Add legend for Finding/Alert count in Overview page opensearch-project#291 Signed-off-by: Jovan Cvetkovic <[email protected]> Signed-off-by: Jovan Cvetkovic <[email protected]> (cherry picked from commit 3538a8b) Co-authored-by: Jovan Cvetkovic <[email protected]> Signed-off-by: AWSHurneyt <[email protected]>
1 parent fd7effd commit 79381ec

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

public/pages/Overview/components/Widgets/Summary.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
*/
55

66
import { EuiFlexGroup, EuiFlexItem, EuiLink, EuiStat } from '@elastic/eui';
7+
import { euiPaletteColorBlind } from '@elastic/eui';
78
import React, { useCallback, useEffect, useState } from 'react';
89
import { WidgetContainer } from './WidgetContainer';
910
import { summaryGroupByOptions } from '../../utils/constants';
1011
import {
12+
alertsDefaultColor,
1113
getChartTimeUnit,
1214
getDomainRange,
1315
getOverviewVisualizationSpec,
@@ -40,7 +42,6 @@ export const Summary: React.FC<SummaryProps> = ({
4042
findings,
4143
startTime,
4244
endTime,
43-
timeUnit,
4445
loading = false,
4546
}) => {
4647
const [groupBy, setGroupBy] = useState('');
@@ -119,7 +120,11 @@ export const Summary: React.FC<SummaryProps> = ({
119120
<EuiFlexGroup gutterSize="xl">
120121
<EuiFlexItem grow={false}>
121122
<EuiStat
122-
title={<EuiLink href={`#${ROUTES.ALERTS}`}>{activeAlerts}</EuiLink>}
123+
title={
124+
<EuiLink href={`#${ROUTES.ALERTS}`} style={{ color: alertsDefaultColor }}>
125+
{activeAlerts}
126+
</EuiLink>
127+
}
123128
description="Total active alerts"
124129
textAlign="left"
125130
titleColor="primary"
@@ -128,7 +133,14 @@ export const Summary: React.FC<SummaryProps> = ({
128133
</EuiFlexItem>
129134
<EuiFlexItem grow={false}>
130135
<EuiStat
131-
title={<EuiLink href={`#${ROUTES.FINDINGS}`}>{totalFindings}</EuiLink>}
136+
title={
137+
<EuiLink
138+
href={`#${ROUTES.FINDINGS}`}
139+
style={{ color: euiPaletteColorBlind()[1] }}
140+
>
141+
{totalFindings}
142+
</EuiLink>
143+
}
132144
description="Total findings"
133145
textAlign="left"
134146
titleColor="primary"

public/pages/Overview/utils/__snapshots__/helper.test.ts.snap

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,24 @@ Object {
273273
Object {
274274
"encoding": Object {
275275
"color": Object {
276-
"scale": null,
277-
"value": "#6092C0",
276+
"field": "fieldType",
277+
"legend": Object {
278+
"values": Array [
279+
"Active alerts",
280+
"Findings",
281+
],
282+
},
283+
"scale": Object {
284+
"domain": Array [
285+
"Active alerts",
286+
"Findings",
287+
],
288+
"range": Array [
289+
"#BD271E",
290+
"#6092C0",
291+
],
292+
},
293+
"title": "",
278294
},
279295
"tooltip": Array [
280296
Object {
@@ -327,6 +343,12 @@ Object {
327343
"clip": true,
328344
"type": "bar",
329345
},
346+
"transform": Array [
347+
Object {
348+
"as": "fieldType",
349+
"calculate": "datum.alert == 1 ? 'Active alerts' : 'Findings'",
350+
},
351+
],
330352
},
331353
Object {
332354
"encoding": Object {
@@ -380,10 +402,10 @@ Object {
380402
},
381403
"mark": Object {
382404
"clip": true,
383-
"color": "#ff0000",
405+
"color": "#BD271E",
384406
"interpolate": "monotone",
385407
"point": Object {
386-
"color": "#ff0000",
408+
"color": "#BD271E",
387409
"fill": "white",
388410
"filled": false,
389411
"size": 50,

public/pages/Overview/utils/helpers.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ export const defaultTimeUnit = {
5454

5555
export const defaultDateFormat = '%Y-%m-%d %H:%M';
5656

57+
// euiColorDanger: #BD271E
58+
export const alertsDefaultColor = '#BD271E';
59+
5760
export const parseDateString = (dateString: string): number => {
5861
const date = dateMath.parse(dateString);
5962
return date ? date.toDate().getTime() : new Date().getTime();
@@ -132,8 +135,15 @@ export function getOverviewVisualizationSpec(
132135
y: getYAxis('finding', 'Count'),
133136
tooltip: [getYAxis('finding', 'Findings'), getTimeTooltip(dateOpts)],
134137
color: {
135-
scale: null,
136-
value: euiPaletteColorBlind()[1],
138+
field: 'fieldType',
139+
title: '',
140+
legend: {
141+
values: ['Active alerts', 'Findings'],
142+
},
143+
scale: {
144+
domain: ['Active alerts', 'Findings'],
145+
range: [alertsDefaultColor, euiPaletteColorBlind()[1]],
146+
},
137147
},
138148
};
139149

@@ -142,6 +152,7 @@ export function getOverviewVisualizationSpec(
142152
type: 'bar',
143153
clip: true,
144154
},
155+
transform: [{ calculate: "datum.alert == 1 ? 'Active alerts' : 'Findings'", as: 'fieldType' }],
145156
encoding: findingsEncoding,
146157
};
147158

@@ -163,7 +174,6 @@ export function getOverviewVisualizationSpec(
163174
barLayer = addInteractiveLegends(barLayer);
164175
}
165176

166-
const lineColor = '#ff0000';
167177
return getVisualizationSpec(
168178
'Plot showing average data with raw values in the background.',
169179
visualizationData,
@@ -174,11 +184,11 @@ export function getOverviewVisualizationSpec(
174184
type: 'line',
175185
clip: true,
176186
interpolate: 'monotone',
177-
color: lineColor,
187+
color: alertsDefaultColor,
178188
point: {
179189
filled: false,
180190
fill: 'white',
181-
color: lineColor,
191+
color: alertsDefaultColor,
182192
size: 50,
183193
},
184194
},

0 commit comments

Comments
 (0)