Skip to content

Commit

Permalink
Resolve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanGarriuz committed Jan 14, 2025
1 parent 41b31ac commit 53a7702
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { WzLink } from '../../../../../components/wz-link/wz-link';
import { withErrorBoundary } from '../../../../common/hocs';
import { compose } from 'redux';
import { withVulnerabilitiesStateDataSource } from '../../../../../components/overview/vulnerabilities/common/hocs/validate-vulnerabilities-states-index-pattern';
import { formatUINumber } from '../../../../../react-services/format-number';

const VulsPanelContent = ({ agent }) => {
const {
Expand Down Expand Up @@ -97,7 +98,7 @@ const VulsPanelContent = ({ agent }) => {
const value =
severityStats?.find(v => v.key.toUpperCase() === severity.toUpperCase())
?.doc_count || '0';
return value ? `${value} ${severity}` : '0';
return value ? `${formatUINumber(value)} ${severity}` : '0';
};

const renderSeverityStats = (severity, index) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { EuiStat, EuiStatProps } from '@elastic/eui';
import { formatUIStringWithNumbers } from '../../../../../react-services/format-number';
import { formatUINumber } from '../../../../../react-services/format-number';

type VulsSeverityStatProps = {
value: number;
value: string;
color: string;
textAlign?: EuiStatProps['textAlign'];
statElement?: EuiStatProps['descriptionElement'];
Expand All @@ -20,7 +20,7 @@ export default function VulsSeverityStat({
return (
<EuiStat
className='vuls-severity-stat'
title={formatUIStringWithNumbers(value)}
title={value}
description={''}
titleElement={statElement}
isLoading={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,7 @@ export function LastAlertsStat({
}}
href={discoverLocation}
>
{
// statValue can take the value of "-" if countLastAlerts does not exist.
typeof countLastAlerts === 'number'
? formatUINumber(Number(statValue))
: statValue
}
{formatUINumber(Number(statValue))}
</EuiLink>
</EuiToolTip>
}
Expand Down
18 changes: 4 additions & 14 deletions plugins/main/public/react-services/format-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,9 @@
* Find more information about this on the LICENSE file.
*/

export function formatUINumber(number: number) {
if (typeof number !== 'number') {
return '-';
export function formatUINumber(value) {
if (Number.isNaN(Number(value))) {
return value;
}
return Number(number).toLocaleString('en-US');
}

export function formatUIStringWithNumbers(value: string) {
if (typeof value !== 'string') {
return '-';
}

return value.replace(/\d+/g, match => {
return Number(match).toLocaleString('en-US');
});
return Number(value).toLocaleString('en-US');
}

0 comments on commit 53a7702

Please sign in to comment.