Skip to content

Commit

Permalink
Update with a function that add formatted to a string with numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanGarriuz committed Jan 14, 2025
1 parent 3ca68bb commit 41b31ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { EuiStat, EuiStatProps } from '@elastic/eui';
import { formatUIStringWithNumbers } from '../../../../../react-services/format-number';

type VulsSeverityStatProps = {
value: string;
value: number;
color: string;
textAlign?: EuiStatProps['textAlign'];
statElement?: EuiStatProps['descriptionElement'];
Expand All @@ -19,7 +20,7 @@ export default function VulsSeverityStat({
return (
<EuiStat
className='vuls-severity-stat'
title={value}
title={formatUIStringWithNumbers(value)}
description={''}
titleElement={statElement}
isLoading={isLoading}
Expand Down
10 changes: 10 additions & 0 deletions plugins/main/public/react-services/format-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ export function formatUINumber(number: number) {
}
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');
});
}

0 comments on commit 41b31ac

Please sign in to comment.