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
@@ -290,28 +290,17 @@ export class BeszelIntegration extends Integration {
|
||||
}
|
||||
|
||||
if ("stats" in parsed) {
|
||||
const stats: BeszelSystemStatsRecord = {
|
||||
id: "",
|
||||
system: systemId,
|
||||
stats: parsed.stats as BeszelSystemStats,
|
||||
type: "1m",
|
||||
created: new Date().toISOString(),
|
||||
updated: new Date().toISOString(),
|
||||
};
|
||||
const now = new Date().toISOString();
|
||||
const envelope = { id: "", system: systemId, type: "1m" as const, created: now, updated: now };
|
||||
const stats: BeszelSystemStatsRecord = { ...envelope, stats: parsed.stats as BeszelSystemStats };
|
||||
|
||||
let containerStats: BeszelContainerStatsRecord | null = null;
|
||||
if (
|
||||
const hasContainers =
|
||||
parsed.container &&
|
||||
Array.isArray(parsed.container) &&
|
||||
(parsed.container as BeszelContainerStats[]).length > 0
|
||||
) {
|
||||
containerStats = {
|
||||
id: "",
|
||||
system: systemId,
|
||||
stats: parsed.container as BeszelContainerStats[],
|
||||
type: "1m",
|
||||
created: new Date().toISOString(),
|
||||
updated: new Date().toISOString(),
|
||||
};
|
||||
(parsed.container as BeszelContainerStats[]).length > 0;
|
||||
if (hasContainers) {
|
||||
containerStats = { ...envelope, stats: parsed.container as BeszelContainerStats[] };
|
||||
}
|
||||
onMessage({ stats, containerStats });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user