diff --git a/src/client/components/chart-cards/memory.tsx b/src/client/components/chart-cards/memory.tsx index 3662a56..8ed5cf0 100644 --- a/src/client/components/chart-cards/memory.tsx +++ b/src/client/components/chart-cards/memory.tsx @@ -1,7 +1,10 @@ +import { formatValue } from '@/utils/format'; import { useQuery } from '@tanstack/react-query'; -import { useEffect, useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; import { ChartCard } from './index'; +const formatOptions = { units: 'B' }; + export const Memory = () => { const { data: staticData } = useQuery({ queryKey: ['static'] }); const { data: dynamicData } = useQuery({ queryKey: ['dynamic'] }); @@ -18,6 +21,13 @@ export const Memory = () => { } }, [dynamicData]); + const formatedTotals = useMemo(() => { + if (!staticData) { + return []; + } + return [formatValue(staticData.total_memory, formatOptions), formatValue(staticData.total_swap, formatOptions)]; + }, [staticData]); + if (!staticData || !dynamicData) { return
; } @@ -26,11 +36,14 @@ export const Memory = () => { diff --git a/src/client/components/legend/index.tsx b/src/client/components/legend/index.tsx index cb70e2b..13e8e02 100644 --- a/src/client/components/legend/index.tsx +++ b/src/client/components/legend/index.tsx @@ -4,7 +4,7 @@ import './index.css'; export type LegendProps = { labels: string[]; - values: number[]; + values: string[] | number[]; formatOptions?: FormatOptions; hueOffset?: number; }; @@ -14,7 +14,12 @@ export const Legend = ({ labels, values, formatOptions, hueOffset = 0 }: LegendP {labels.map((label, index) => (
{label} -

{formatValue(values[index], formatOptions)}

+

+ {(() => { + const value = values[index]; + return typeof value === 'string' ? value : formatValue(value, formatOptions); + })()} +

))}