feat: rebuild board grid experience

This commit is contained in:
ajnart committed 2026-08-14 11:07:06 +02:00
1 parent e41d938a5f
commit d6b114e423
121 files changed
+7384 -2292

No files matched your search

@@ -0,0 +1,53 @@
import { describe, expect, test } from "vitest";
import {
readSectionCollapsedFromStorage,
sectionCollapseStorageKey,
writeSectionCollapsedToStorage,
} from "../section-collapse-storage";
describe("section collapse storage", () => {
test.each([
["true", false],
["false", true],
])("inverts a legacy open value of %s exactly once", (legacyValue, expectedCollapsed) => {
const sectionId = "media";
const legacyKey = `homarr-section-collapsed-${sectionId}`;
const storage = createStorage({ [legacyKey]: legacyValue });
expect(readSectionCollapsedFromStorage(storage, sectionId, false)).toBe(expectedCollapsed);
expect(storage.getItem(legacyKey)).toBeNull();
expect(storage.getItem(sectionCollapseStorageKey(sectionId))).toBe(String(expectedCollapsed));
expect(readSectionCollapsedFromStorage(storage, sectionId, !expectedCollapsed)).toBe(expectedCollapsed);
});
test("uses the corrected fallback when no browser preference exists", () => {
const storage = createStorage();
expect(readSectionCollapsedFromStorage(storage, "category", true)).toBe(true);
expect(readSectionCollapsedFromStorage(storage, "dynamic", false)).toBe(false);
});
test("writes only the versioned corrected state", () => {
const sectionId = "media";
const legacyKey = `homarr-section-collapsed-${sectionId}`;
const storage = createStorage({ [legacyKey]: "true" });
writeSectionCollapsedToStorage(storage, sectionId, true);
expect(storage.getItem(legacyKey)).toBeNull();
expect(storage.getItem(sectionCollapseStorageKey(sectionId))).toBe("true");
});
});
const createStorage = (initial: Record<string, string> = {}) => {
const values = new Map(Object.entries(initial));
return {
getItem: (key: string) => values.get(key) ?? null,
setItem: (key: string, value: string) => values.set(key, value),
removeItem: (key: string) => {
values.delete(key);
},
};
};
@@ -0,0 +1,78 @@
import { describe, expect, test } from "vitest";
import { getSectionItemsForLayout } from "../use-open-section-apps";
describe("getSectionItemsForLayout", () => {
test("includes items in recursively nested dynamic sections", () => {
const board = {
sections: [
{ id: "category", kind: "category" },
{
id: "first",
kind: "dynamic",
layouts: [{ layoutId: "desktop", parentSectionId: "category" }],
},
{
id: "second",
kind: "dynamic",
layouts: [{ layoutId: "desktop", parentSectionId: "first" }],
},
],
items: [
{ id: "direct", layouts: [{ layoutId: "desktop", sectionId: "category" }] },
{ id: "nested", layouts: [{ layoutId: "desktop", sectionId: "second" }] },
],
};
expect(getSectionItemsForLayout(board, "category", "desktop").map((item) => item.id)).toEqual(["direct", "nested"]);
});
test("uses containment from only the requested responsive layout", () => {
const board = {
sections: [
{ id: "category", kind: "category" },
{ id: "other", kind: "category" },
{
id: "dynamic",
kind: "dynamic",
layouts: [
{ layoutId: "mobile", parentSectionId: "category" },
{ layoutId: "desktop", parentSectionId: "other" },
],
},
],
items: [
{
id: "app",
layouts: [
{ layoutId: "mobile", sectionId: "dynamic" },
{ layoutId: "desktop", sectionId: "dynamic" },
],
},
],
};
expect(getSectionItemsForLayout(board, "category", "mobile").map((item) => item.id)).toEqual(["app"]);
expect(getSectionItemsForLayout(board, "category", "desktop")).toEqual([]);
});
test("does not loop when malformed section containment is cyclic", () => {
const board = {
sections: [
{
id: "root",
kind: "dynamic",
layouts: [{ layoutId: "desktop", parentSectionId: "child" }],
},
{
id: "child",
kind: "dynamic",
layouts: [{ layoutId: "desktop", parentSectionId: "root" }],
},
],
items: [{ id: "app", layouts: [{ layoutId: "desktop", sectionId: "child" }] }],
};
expect(getSectionItemsForLayout(board, "root", "desktop").map((item) => item.id)).toEqual(["app"]);
});
});