Skip to content

Commit 5f263eb

Browse files
active since field added
1 parent a593dd9 commit 5f263eb

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

web/locales/en/plugin__netobserv-plugin.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
"Navigate to alert details": "Navigate to alert details",
247247
"State": "State",
248248
"Severity": "Severity",
249+
"Active since": "Active since",
250+
"Yesterday": "Yesterday",
249251
"Labels": "Labels",
250252
"Description": "Description",
251253
"Navigate to network traffic": "Navigate to network traffic",

web/src/components/health/alert-details.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react';
33
import { Label, Text, TextContent, TextVariants } from '@patternfly/react-core';
44
import { useTranslation } from 'react-i18next';
55
import { Link } from 'react-router-dom';
6+
import { formatActiveSince } from '../../utils/datetime';
67
import { valueFormat } from '../../utils/format';
78
import { AlertWithRuleName, getAlertFilteredLabels, getAlertLink } from './health-helper';
89

@@ -25,6 +26,11 @@ export const AlertDetails: React.FC<AlertDetailsProps> = ({ resourceName, alert
2526
</AlertDetailsValue>
2627
<AlertDetailsValue title={t('State')}>{alert.state}</AlertDetailsValue>
2728
<AlertDetailsValue title={t('Severity')}>{alert.labels.severity}</AlertDetailsValue>
29+
{alert.activeAt && (
30+
<AlertDetailsValue title={t('Active since')}>
31+
{formatActiveSince(alert.activeAt)}
32+
</AlertDetailsValue>
33+
)}
2834
<AlertDetailsValue title={t('Labels')}>
2935
{labels.length === 0
3036
? t('None')

web/src/components/health/alert-row.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react';
33

44
import { Label, Tooltip } from '@patternfly/react-core';
55
import { useTranslation } from 'react-i18next';
6+
import { formatActiveSince } from '../../utils/datetime';
67
import { valueFormat } from '../../utils/format';
78
import { HealthColorSquare } from './health-color-square';
89
import { AlertWithRuleName, getAlertFilteredLabels, getAlertLink, getTrafficLink } from './health-helper';
@@ -39,6 +40,7 @@ export const AlertRow: React.FC<AlertRowProps> = ({ kind, resourceName, alert, w
3940
)}
4041
<Td noPadding={!wide}>{alert.state}</Td>
4142
<Td>{alert.labels.severity}</Td>
43+
{alert.activeAt && <Td>{formatActiveSince(alert.activeAt)}</Td>}
4244
<Td>
4345
{labels.length === 0
4446
? t('None')

web/src/components/health/rule-details.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const RuleDetails: React.FC<RuleDetailsProps> = ({ kind, info, wide }) =>
2323
<Th>{t('Summary')}</Th>
2424
<Th>{t('State')}</Th>
2525
<Th>{t('Severity')}</Th>
26+
<Th>{t('Active since')}</Th>
2627
<Th>{t('Labels')}</Th>
2728
<Th>{t('Value')}</Th>
2829
<Th>{t('Description')}</Th>

web/src/utils/datetime.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,46 @@ export const computeStepInterval = (range: TimeRange | number) => {
123123
stepSeconds: step
124124
};
125125
};
126+
127+
/**
128+
* Formats a timestamp for "Active since" display with relative or absolute time.
129+
* - Today: Shows only time (14:23)
130+
* - Yesterday: Shows "Yesterday, HH:MM"
131+
* - Last 7 days: Shows day of week and time (Tue, 14:23)
132+
* - Older: Shows full date and time (2025-11-24 14:23)
133+
*/
134+
export const formatActiveSince = (timestamp: string): string => {
135+
const activeDate = new Date(timestamp);
136+
const now = new Date();
137+
138+
// Calculate time difference in milliseconds
139+
const diffMs = now.getTime() - activeDate.getTime();
140+
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
141+
142+
// Format time as HH:MM
143+
const timeStr = twentyFourHourTime(activeDate, false);
144+
145+
// Today: show only time
146+
if (diffDays === 0 && now.getDate() === activeDate.getDate()) {
147+
return timeStr;
148+
}
149+
150+
// Yesterday: show "Yesterday, HH:MM"
151+
const yesterday = new Date(now);
152+
yesterday.setDate(yesterday.getDate() - 1);
153+
if (activeDate.getDate() === yesterday.getDate() &&
154+
activeDate.getMonth() === yesterday.getMonth() &&
155+
activeDate.getFullYear() === yesterday.getFullYear()) {
156+
return `Yesterday, ${timeStr}`;
157+
}
158+
159+
// Last 7 days: show day of week and time
160+
if (diffDays < 7) {
161+
const weekdayFormatter = new Intl.DateTimeFormat(getLanguage(), { weekday: 'short' });
162+
const weekday = weekdayFormatter.format(activeDate);
163+
return `${weekday}, ${timeStr}`;
164+
}
165+
166+
// Older: show full date and time (YYYY-MM-DD HH:MM)
167+
return `${toISODateString(activeDate)} ${timeStr}`;
168+
};

0 commit comments

Comments
 (0)