refactor(beszel): remove dead exports and deduplicate formatters
- Remove unused getBandwidthRates, getContainerNetworkRate, formatMB - Remove unused alertColorMap from colors.ts - Remove duplicate chartAxisFormatters.percentPrecise (identical to .percent) - Make chartAxisFormatters.percent reference formatPercent directly
This commit is contained in:
3 files changed
+3
-22
No files matched your search
@@ -205,7 +205,7 @@ export default function BeszelSystemStatsWidget({
|
|||||||
type="stacked"
|
type="stacked"
|
||||||
series={containerSeries}
|
series={containerSeries}
|
||||||
fillOpacity={0.6}
|
fillOpacity={0.6}
|
||||||
yAxisFormatter={chartAxisFormatters.percentPrecise}
|
yAxisFormatter={chartAxisFormatters.percent}
|
||||||
tooltipProps={tooltipPercentTotal}
|
tooltipProps={tooltipPercentTotal}
|
||||||
/>
|
/>
|
||||||
</ChartPanel>
|
</ChartPanel>
|
||||||
|
|||||||
@@ -20,11 +20,6 @@ export const statusColorMap: Record<BeszelSystemStatus, string> = {
|
|||||||
pending: "yellow",
|
pending: "yellow",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const alertColorMap: Record<string, string> = {
|
|
||||||
triggered: "red",
|
|
||||||
ok: "green",
|
|
||||||
};
|
|
||||||
|
|
||||||
export const containerColors = [
|
export const containerColors = [
|
||||||
"blue.6",
|
"blue.6",
|
||||||
"teal.6",
|
"teal.6",
|
||||||
|
|||||||
@@ -25,28 +25,16 @@ export const formatGB = (value: number): string => {
|
|||||||
return `${value.toFixed(2)} GB`;
|
return `${value.toFixed(2)} GB`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatMB = (value: number): string => {
|
export const formatPercent = (value: number): string => `${value.toFixed(1)}%`;
|
||||||
if (!value || !Number.isFinite(value)) return "0 MB";
|
|
||||||
return `${value.toFixed(1)} MB`;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const chartAxisFormatters = {
|
export const chartAxisFormatters = {
|
||||||
percent: (value: number) => `${Number(value).toFixed(1)}%`,
|
percent: formatPercent,
|
||||||
percentPrecise: (value: number) => `${Number(value).toFixed(1)}%`,
|
|
||||||
gb: (value: number) => (!value ? "0" : `${Number(value).toFixed(0)}G`),
|
gb: (value: number) => (!value ? "0" : `${Number(value).toFixed(0)}G`),
|
||||||
mb: (value: number) => (!value ? "0" : `${Number(value).toFixed(0)}M`),
|
mb: (value: number) => (!value ? "0" : `${Number(value).toFixed(0)}M`),
|
||||||
bytes: (value: number) => formatScaledCompact(Number(value), byteUnits, "0"),
|
bytes: (value: number) => formatScaledCompact(Number(value), byteUnits, "0"),
|
||||||
rate: (value: number) => formatScaledCompact(Number(value), rateUnits, "0"),
|
rate: (value: number) => formatScaledCompact(Number(value), rateUnits, "0"),
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const getBandwidthRates = (stats: { b?: [number, number] }): { sent: number; recv: number } => ({
|
|
||||||
sent: stats.b?.[0] ?? 0,
|
|
||||||
recv: stats.b?.[1] ?? 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getContainerNetworkRate = (container: { b?: [number, number] }): number =>
|
|
||||||
(container.b?.[0] ?? 0) + (container.b?.[1] ?? 0);
|
|
||||||
|
|
||||||
export const formatUptime = (seconds: number): string => {
|
export const formatUptime = (seconds: number): string => {
|
||||||
const days = Math.floor(seconds / 86400);
|
const days = Math.floor(seconds / 86400);
|
||||||
const hours = Math.floor((seconds % 86400) / 3600);
|
const hours = Math.floor((seconds % 86400) / 3600);
|
||||||
@@ -62,8 +50,6 @@ export const formatTemp = (celsius: number | null, fahrenheit: boolean): string
|
|||||||
return `${celsius.toFixed(2)} °C`;
|
return `${celsius.toFixed(2)} °C`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const formatPercent = (value: number): string => `${value.toFixed(1)}%`;
|
|
||||||
|
|
||||||
export const formatLoadAvg = (la: [number, number, number] | null): string => {
|
export const formatLoadAvg = (la: [number, number, number] | null): string => {
|
||||||
if (!la) return "—";
|
if (!la) return "—";
|
||||||
return la.map((v) => v.toFixed(2)).join(" ");
|
return la.map((v) => v.toFixed(2)).join(" ");
|
||||||
|
|||||||
Reference in new issue
Block a user