refactor(beszel): consolidate hooks, extract helpers, deduplicate SSE envelope
Consolidate 5 stat mapper useCallbacks and 6 series useMemos into single mappers/series objects. Extract statsWhenShown helper for repeated visibility guard pattern. Deduplicate SSE record envelope construction. Simplify prepareRecords with if/else. Remove unused gridColumns ternary with Number() indexing.
This commit is contained in:
3 files changed
+67
-101
No files matched your search
@@ -11,17 +11,11 @@ import type { BeszelContainerStatsRecord, BeszelSystemStatsRecord } from "@homar
|
||||
const formatTime = (timestamp: string) => dayjs(timestamp).format("HH:mm");
|
||||
const formatTimeLive = (timestamp: string) => dayjs(timestamp).format("HH:mm:ss");
|
||||
|
||||
const timeFormatters: Record<string, (ts: string) => string> = {
|
||||
live: formatTimeLive,
|
||||
historical: formatTime,
|
||||
};
|
||||
|
||||
function prepareRecords<T>(records: T[], live: boolean) {
|
||||
const mode = live ? "live" : "historical";
|
||||
return {
|
||||
fmt: timeFormatters[mode] as (ts: string) => string,
|
||||
ordered: live ? records : [...records].toReversed(),
|
||||
};
|
||||
if (live) {
|
||||
return { fmt: formatTimeLive, ordered: records };
|
||||
}
|
||||
return { fmt: formatTime, ordered: [...records].toReversed() };
|
||||
}
|
||||
|
||||
const yAxisBase = { tickMargin: 0, tick: { fontSize: 10 } } as const;
|
||||
@@ -88,7 +82,6 @@ const BeszelAreaChart = memo(
|
||||
type={type}
|
||||
strokeWidth={1}
|
||||
fillOpacity={0.2}
|
||||
areaChartProps={{}}
|
||||
withXAxis
|
||||
withYAxis
|
||||
w="100%"
|
||||
|
||||
Reference in new issue
Block a user