feat: expand advanced widget experiences
This commit is contained in:
1 parent
9437d211c8
commit
c099a8eef6
119 files changed
+3624
-844
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { parseColumnOrder, parseColumnWidths } from "../common/use-persisted-table-layout";
|
||||
import { beszelTableMetricOptionKeys, getBeszelTableVisibleMetricKeys } from "./display";
|
||||
|
||||
const columnAccessors = ["name", "cpu", "memory", "disk", "temp"];
|
||||
|
||||
@@ -32,3 +33,23 @@ describe("Beszel table column layout options", () => {
|
||||
).toEqual({ cpu: 140 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("Beszel table metric visibility", () => {
|
||||
const enabledOptions = Object.fromEntries(beszelTableMetricOptionKeys.map((key) => [key, true])) as Record<
|
||||
(typeof beszelTableMetricOptionKeys)[number],
|
||||
boolean
|
||||
>;
|
||||
|
||||
test("keeps the compact width budget", () => {
|
||||
expect([...getBeszelTableVisibleMetricKeys(enabledOptions, 350, false)]).toEqual(["showCpu"]);
|
||||
expect(getBeszelTableVisibleMetricKeys(enabledOptions, 600, false).size).toBe(4);
|
||||
});
|
||||
|
||||
test("shows every metric in advanced mode regardless of visibility options", () => {
|
||||
const disabledOptions = Object.fromEntries(
|
||||
beszelTableMetricOptionKeys.map((key) => [key, false]),
|
||||
) as typeof enabledOptions;
|
||||
|
||||
expect([...getBeszelTableVisibleMetricKeys(disabledOptions, 200, true)]).toEqual(beszelTableMetricOptionKeys);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
export const beszelTableMetricOptionKeys = [
|
||||
"showCpu",
|
||||
"showMemory",
|
||||
"showDisk",
|
||||
"showGpu",
|
||||
"showLoadAvg",
|
||||
"showNet",
|
||||
"showTemp",
|
||||
"showBattery",
|
||||
"showServices",
|
||||
"showUptime",
|
||||
"showAgent",
|
||||
] as const;
|
||||
|
||||
type BeszelTableMetricOptions = Record<(typeof beszelTableMetricOptionKeys)[number], boolean>;
|
||||
|
||||
export const getBeszelTableVisibleMetricKeys = (
|
||||
options: BeszelTableMetricOptions,
|
||||
width: number,
|
||||
isAdvanced: boolean,
|
||||
) => {
|
||||
const enabled = isAdvanced
|
||||
? [...beszelTableMetricOptionKeys]
|
||||
: beszelTableMetricOptionKeys.filter((key) => options[key]);
|
||||
const budget = isAdvanced ? enabled.length : width < 360 ? 1 : width < 560 ? 2 : width < 760 ? 4 : enabled.length;
|
||||
|
||||
return new Set(enabled.slice(0, budget));
|
||||
};
|
||||
@@ -25,7 +25,7 @@ const sortDirectionOptions = [
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("beszelSystemTable", {
|
||||
icon: IconTable,
|
||||
supportsAdvancedFocus: false,
|
||||
supportsAdvancedFocus: true,
|
||||
queryKeys: [[["widget", "beszel", "getSystems"]], [["widget", "beszel", "getSystemStats"]]],
|
||||
queryMatcher: (query, scope) =>
|
||||
query.path.at(-1) === "getSystems"
|
||||
|
||||
Reference in new issue
Block a user