11import Stack from "@mui/material/Stack" ;
22import { DetailGauge } from "@/Components/v2/design-elements" ;
33
4+ import { getPercentage , formatPercentageFromWhole } from "@/Utils/FormatUtils" ;
45import prettyBytes from "pretty-bytes" ;
56import { useTranslation } from "react-i18next" ;
67import { useTheme } from "@mui/material" ;
@@ -10,17 +11,6 @@ interface StatGaugesProps {
1011 diagnostics : Diagnostics | null ;
1112}
1213
13- const getPercentage = ( value : number , total : number ) => {
14- if ( ! value || ! total ) return 0 ;
15- return ( value / total ) * 100 ;
16- } ;
17-
18- const formatPercentage = new Intl . NumberFormat ( "en-US" , {
19- style : "percent" ,
20- minimumFractionDigits : 1 ,
21- maximumFractionDigits : 1 ,
22- } ) ;
23-
2414export const StatGauges = ( { diagnostics } : StatGaugesProps ) => {
2515 const theme = useTheme ( ) ;
2616 const { t } = useTranslation ( ) ;
@@ -51,33 +41,31 @@ export const StatGauges = ({ diagnostics }: StatGaugesProps) => {
5141 < DetailGauge
5242 title = { t ( "pages.logs.diagnostics.gauges.heapAllocation" ) }
5343 progress = { heapTotalSize }
54- upperValue = { formatPercentage . format ( heapTotalSize / 100 ) }
44+ upperValue = { formatPercentageFromWhole ( heapTotalSize ) }
5545 lowerLabel = { t ( "pages.logs.diagnostics.gauges.total" ) }
5646 lowerValue = { prettyBytes ( diagnostics . v8HeapStats ?. heapSizeLimitBytes ?? 0 ) }
5747 />
5848 < DetailGauge
5949 title = { t ( "pages.logs.diagnostics.gauges.heapUsage" ) }
6050 progress = { heapUsedSize }
6151 upperLabel = { t ( "pages.logs.diagnostics.gauges.availableMemoryPercentage" ) }
62- upperValue = { formatPercentage . format ( heapUsedSize / 100 ) }
52+ upperValue = { formatPercentageFromWhole ( heapUsedSize ) }
6353 lowerLabel = { t ( "pages.logs.diagnostics.gauges.used" ) }
6454 lowerValue = { prettyBytes ( diagnostics . v8HeapStats ?. usedHeapSizeBytes ?? 0 ) }
6555 />
6656 < DetailGauge
6757 title = { t ( "pages.logs.diagnostics.gauges.heapUtilization" ) }
6858 progress = { actualHeapUsed }
6959 upperLabel = { t ( "pages.logs.diagnostics.gauges.allocatedPercentage" ) }
70- upperValue = { formatPercentage . format ( actualHeapUsed / 100 ) }
60+ upperValue = { formatPercentageFromWhole ( actualHeapUsed ) }
7161 lowerLabel = { t ( "pages.logs.diagnostics.gauges.total" ) }
7262 lowerValue = { prettyBytes ( diagnostics . v8HeapStats ?. usedHeapSizeBytes ?? 0 ) }
7363 />
7464 < DetailGauge
7565 title = { t ( "pages.logs.diagnostics.gauges.instantCpuUsage" ) }
7666 progress = { diagnostics . cpuUsage ?. usagePercentage ?? 0 }
7767 upperLabel = { t ( "pages.logs.diagnostics.gauges.usedSPercentage" ) }
78- upperValue = { formatPercentage . format (
79- ( diagnostics . cpuUsage ?. usagePercentage ?? 0 ) / 100
80- ) }
68+ upperValue = { formatPercentageFromWhole ( diagnostics . cpuUsage ?. usagePercentage ?? 0 ) }
8169 />
8270 </ Stack >
8371 ) ;
0 commit comments