From 3ae3b5fffa2294fa7dab46fbe050c26cc9114c17 Mon Sep 17 00:00:00 2001 From: Celine Sebe Date: Wed, 14 Aug 2024 12:25:34 +0200 Subject: [PATCH] [front]fix date format(#7921) --- opencti-platform/opencti-front/src/utils/Charts.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/opencti-platform/opencti-front/src/utils/Charts.js b/opencti-platform/opencti-front/src/utils/Charts.js index 6feb1991ea31..25a0c907378a 100644 --- a/opencti-platform/opencti-front/src/utils/Charts.js +++ b/opencti-platform/opencti-front/src/utils/Charts.js @@ -1,6 +1,7 @@ import * as C from '@mui/material/colors'; import { resolveLink } from './Entity'; import { truncate } from './String'; +import { dateFormat, timestamp } from './Time'; const colors = (temp) => [ C.red[temp], @@ -31,6 +32,7 @@ const toolbarOptions = { columnDelimiter: ',', headerCategory: 'category', headerValue: 'value', + // eslint-disable-next-line @typescript-eslint/no-shadow dateFormatter(timestamp) { return new Date(timestamp).toDateString(); }, @@ -524,7 +526,17 @@ export const horizontalBarsChartOptions = ( show: stackType !== '100%', labels: { show: stackType !== '100%', - formatter: (value) => (yFormatter && typeof value === 'number' ? yFormatter(value) : value), + formatter: (value) => { + if (yFormatter && typeof value === 'number') { + return yFormatter(value); + } + if (typeof value === 'string' && value.length === 15) { + const timestampInMs = parseInt(value, 10); + const convertedDate = timestamp(timestampInMs); + return dateFormat(convertedDate, 'DD-MM-YYYY'); + } + return value; + }, style: { fontFamily: '"IBM Plex Sans", sans-serif', },