From 52e8096f67e0e8fc9e828bab19311943263ef37b Mon Sep 17 00:00:00 2001 From: Federico Rodriguez Date: Tue, 19 Dec 2023 18:47:50 +0100 Subject: [PATCH] Fix invalid date format (#6234) * Fix redundant date format * Add changelog --- CHANGELOG.md | 1 + .../public/controllers/agent/components/agents-table.js | 8 ++------ plugins/main/public/controllers/settings/settings.js | 2 +- plugins/main/public/react-services/time-service.js | 9 ++++++--- plugins/wazuh-core/public/utils/time.ts | 3 +++ 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3f7820f76..d11d7bcb1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Fixed exception in IT-Hygiene when an agent doesn't have policies [#6177](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6177) - Fixed exception in Inventory when agents don't have S.O. information [#6177](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6177) - Fixed pinned agent state in URL [#6177](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6177) +- Fixed invalid date format in about and agent views [#6234](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6234) ### Removed diff --git a/plugins/main/public/controllers/agent/components/agents-table.js b/plugins/main/public/controllers/agent/components/agents-table.js index 650b9d7c5f..e1dae99b5b 100644 --- a/plugins/main/public/controllers/agent/components/agents-table.js +++ b/plugins/main/public/controllers/agent/components/agents-table.js @@ -233,6 +233,7 @@ export const AgentsTable = compose( /> ), + render: dateAdd => formatUIDate(dateAdd), sortable: true, show: false, searchable: false, @@ -250,6 +251,7 @@ export const AgentsTable = compose( /> ), + render: lastKeepAlive => formatUIDate(lastKeepAlive), sortable: true, show: false, searchable: false, @@ -334,12 +336,6 @@ export const AgentsTable = compose( return { ...item, ...(item.ip ? { ip: item.ip } : { ip: '-' }), - ...(typeof item.dateAdd === 'string' - ? { dateAdd: formatUIDate(item.dateAdd) } - : { dateAdd: '-' }), - ...(typeof item.lastKeepAlive === 'string' - ? { lastKeepAlive: formatUIDate(item.lastKeepAlive) } - : { lastKeepAlive: '-' }), ...(item.node_name !== 'unknown' ? { node_name: item.node_name } : { node_name: '-' }), diff --git a/plugins/main/public/controllers/settings/settings.js b/plugins/main/public/controllers/settings/settings.js index aee83ebed5..b405243fb0 100644 --- a/plugins/main/public/controllers/settings/settings.js +++ b/plugins/main/public/controllers/settings/settings.js @@ -472,7 +472,7 @@ export class SettingsController { const response = data.data.data; this.appInfo = { 'app-version': response['app-version'], - installationDate: formatUIDate(response['installationDate']), + installationDate: response['installationDate'], revision: response['revision'], }; diff --git a/plugins/main/public/react-services/time-service.js b/plugins/main/public/react-services/time-service.js index 74e745a3de..c0fa48cbdf 100644 --- a/plugins/main/public/react-services/time-service.js +++ b/plugins/main/public/react-services/time-service.js @@ -12,15 +12,18 @@ import moment from 'moment-timezone'; import { getUiSettings } from '../kibana-services'; -export const formatUIDate = (date) => { +export const formatUIDate = date => { + if (typeof date !== 'string') { + return '-'; + } const dateFormat = getUiSettings().get('dateFormat'); const timezone = getTimeZone(); const momentDate = moment(date); momentDate.tz(timezone); return momentDate.format(dateFormat); -} +}; const getTimeZone = () => { const dateFormatTZ = getUiSettings().get('dateFormat:tz'); const detectedTimezone = moment.tz.guess(); return dateFormatTZ === 'Browser' ? detectedTimezone : dateFormatTZ; -} \ No newline at end of file +}; diff --git a/plugins/wazuh-core/public/utils/time.ts b/plugins/wazuh-core/public/utils/time.ts index 3ddf9b9880..5b7b4bd911 100644 --- a/plugins/wazuh-core/public/utils/time.ts +++ b/plugins/wazuh-core/public/utils/time.ts @@ -2,6 +2,9 @@ import moment from 'moment-timezone'; import { getUiSettings } from '../plugin-services'; export const formatUIDate = (date: Date) => { + if (typeof date !== 'string') { + return '-'; + } const dateFormat = getUiSettings().get('dateFormat'); const timezone = getTimeZone(); const momentDate = moment(date);