Skip to content

Commit 274ecfe

Browse files
Merge pull request #531 from Fewwy/RHINENG-20701
RHINENG-20701: fix utc timestamps in chart tooltips
2 parents bbf995d + 6f89b1b commit 274ecfe

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

web/src/components/Incidents/AlertsChart/AlertsChart.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ import {
2424
} from '@patternfly/react-tokens';
2525
import { useDispatch, useSelector } from 'react-redux';
2626
import { IncidentsTooltip } from '../IncidentsTooltip';
27-
import {
28-
createAlertsChartBars,
29-
formatDate,
30-
generateDateArray,
31-
generateAlertsDateArray,
32-
} from '../utils';
27+
import { createAlertsChartBars, generateDateArray, generateAlertsDateArray } from '../utils';
28+
import { dateTimeFormatter } from '../../console/utils/datetime';
29+
import { useTranslation } from 'react-i18next';
3330
import { AlertsChartBar } from '../model';
3431
import { setAlertsAreLoading } from '../../../store/actions';
3532
import { MonitoringState } from '../../../store/store';
@@ -50,6 +47,7 @@ const AlertsChart = ({ theme }: { theme: 'light' | 'dark' }) => {
5047
const incidentGroupId = useSelector(
5148
(state: MonitoringState) => state.plugins.mcp.incidentsData.groupId,
5249
);
50+
const { i18n } = useTranslation();
5351
// Use dynamic date range based on actual alerts data instead of fixed chartDays
5452
const dateValues = useMemo(() => {
5553
if (!Array.isArray(alertsData) || alertsData.length === 0) {
@@ -125,15 +123,18 @@ const AlertsChart = ({ theme }: { theme: 'light' | 'dark' }) => {
125123
if (datum.nodata) {
126124
return '';
127125
}
126+
const startDate = dateTimeFormatter(i18n.language).format(new Date(datum.y0));
127+
const endDate =
128+
datum.alertstate === 'firing'
129+
? '---'
130+
: dateTimeFormatter(i18n.language).format(new Date(datum.y));
128131
return `Alert Severity: ${datum.severity}
129132
Alert Name: ${datum.name ? datum.name : '---'}
130133
Namespace: ${datum.namespace ? datum.namespace : '---'}
131134
Layer: ${datum.layer ? datum.layer : '---'}
132135
Component: ${datum.component}
133-
Start: ${formatDate(new Date(datum.y0), true)}
134-
End: ${
135-
datum.alertstate === 'firing' ? '---' : formatDate(new Date(datum.y), true)
136-
}
136+
Start: ${startDate}
137+
End: ${endDate};
137138
Silenced: ${datum.silenced}`;
138139
}}
139140
/>

web/src/components/Incidents/IncidentsChart/IncidentsChart.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ import { useDispatch, useSelector } from 'react-redux';
2727
import '../incidents-styles.css';
2828
import { IncidentsTooltip } from '../IncidentsTooltip';
2929
import { Incident } from '../model';
30-
import {
31-
createIncidentsChartBars,
32-
formatDate,
33-
generateDateArray,
34-
updateBrowserUrl,
35-
} from '../utils';
30+
import { createIncidentsChartBars, generateDateArray, updateBrowserUrl } from '../utils';
31+
import { dateTimeFormatter } from '../../console/utils/datetime';
32+
import { useTranslation } from 'react-i18next';
3633
import { MonitoringState } from '../../../store/store';
3734
import { setAlertsAreLoading, setIncidentsActiveFilters } from '../../../store/actions';
3835

@@ -55,6 +52,7 @@ const IncidentsChart = ({
5552
(state: MonitoringState) => state.plugins.mcp.incidentsData.incidentsActiveFilters,
5653
);
5754
const selectedGroupId = incidentsActiveFilters.groupId?.[0] ?? null;
55+
const { i18n } = useTranslation();
5856

5957
const chartData = useMemo(() => {
6058
if (!Array.isArray(incidentsData) || incidentsData.length === 0) return [];
@@ -139,12 +137,17 @@ const IncidentsChart = ({
139137
if (datum.nodata) {
140138
return '';
141139
}
140+
const startDate = dateTimeFormatter(i18n.language).format(new Date(datum.y0));
141+
const endDate =
142+
datum.alertstate === 'firing'
143+
? '---'
144+
: dateTimeFormatter(i18n.language).format(new Date(datum.y));
142145
return `Severity: ${datum.name}
143146
Component: ${datum.componentList?.join(', ')}
144147
Incident ID:
145148
${datum.group_id}
146-
Start: ${formatDate(new Date(datum.y0), true)}
147-
End: ${datum.firing ? '---' : formatDate(new Date(datum.y), true)}`;
149+
Start: ${startDate}
150+
End: ${endDate}`;
148151
}}
149152
/>
150153
}

web/src/components/Incidents/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,6 @@ export const createAlertsChartBars = (alert: IncidentsDetailsAlert): AlertsChart
260260
return data;
261261
};
262262

263-
export const formatDate = (date: Date, isTime: boolean) => {
264-
const userLocale = navigator.language || 'en-US';
265-
const dateString = date?.toLocaleDateString(userLocale, {
266-
day: 'numeric',
267-
month: 'short',
268-
year: 'numeric',
269-
});
270-
const timeString = date?.toLocaleTimeString(userLocale, {
271-
hour: '2-digit',
272-
minute: '2-digit',
273-
});
274-
return isTime ? `${dateString}, ${timeString}` : dateString;
275-
};
276-
277263
/**
278264
* Generates an array of dates, each representing midnight (00:00:00) of the past `days` number of days, starting from today.
279265
*

0 commit comments

Comments
 (0)