Skip to content

Commit

Permalink
feat: Add formatStats util function
Browse files Browse the repository at this point in the history
  • Loading branch information
pacholoamit committed Oct 13, 2024
1 parent 640fc10 commit ef76a32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/features/metrics/components/memory/memory.area-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import StatsRing from "@/components/stats-ring2";
import useMemorySelectors from "@/features/metrics/stores/memory.store";
import formatBytes from "@/features/metrics/utils/format-bytes";
import formatOverallStats from "@/features/metrics/utils/format-overall-stats";
import formatStats from "@/features/metrics/utils/format-stats";
import { Grid, useMantineTheme } from "@mantine/core";
import { IconChartArea } from "@tabler/icons-react";

Expand Down Expand Up @@ -35,7 +36,7 @@ const MemoryAreaChart: React.FC = ({}) => {
const used = latestMemory.used;
const progress = latestMemory.usedPercentage;

const stats = React.useMemo(() => formatOverallStats(used, available), [used, available]);
const stats = React.useMemo(() => formatStats(used), [used]);

useEffect(() => {
setChartOptions({
Expand Down
3 changes: 2 additions & 1 deletion src/features/metrics/components/swap/swap.area-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import StatsRing from "@/components/stats-ring2";
import useSwapSelectors from "@/features/metrics/stores/swap.store";
import formatBytes from "@/features/metrics/utils/format-bytes";
import formatOverallStats from "@/features/metrics/utils/format-overall-stats";
import formatStats from "@/features/metrics/utils/format-stats";
import { Grid, useMantineTheme } from "@mantine/core";
import { IconFile } from "@tabler/icons-react";

Expand All @@ -19,7 +20,7 @@ const SwapAreaChart: React.FC = ({}) => {
const used = latestSwap.used;
const progress = latestSwap.usedPercentage;

const stats = React.useMemo(() => formatOverallStats(used, available), [used, available]);
const stats = React.useMemo(() => formatStats(used), [used]);

const [chartOptions, setChartOptions] = useAreaChartState({
title: {
Expand Down
9 changes: 9 additions & 0 deletions src/features/metrics/utils/format-stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import formatBytes from "./format-bytes";

const formatStats = (used: number, toFixed: number = 2) => {
const usedFormatted = formatBytes(used, toFixed);

return `${usedFormatted}`;
};

export default formatStats;

0 comments on commit ef76a32

Please sign in to comment.