From ff84d85eb3ea8e8b1fe17d86614958b0091592da Mon Sep 17 00:00:00 2001 From: Julian Appel Date: Thu, 23 Jul 2026 17:49:50 +0200 Subject: [PATCH] Show placeholders in empty circuit lists --- src/frontend/utils/circuit-grid-projection.ts | 2 +- tests/circuit-grid-projection.test.ts | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/frontend/utils/circuit-grid-projection.ts b/src/frontend/utils/circuit-grid-projection.ts index a5bda32..b3e2dfc 100644 --- a/src/frontend/utils/circuit-grid-projection.ts +++ b/src/frontend/utils/circuit-grid-projection.ts @@ -113,7 +113,7 @@ export function filterAndSortCircuitSections( return { ...section, circuits }; }) - .filter((section) => section.circuits.length > 0); + .filter((section) => activeFilters.length === 0 || section.circuits.length > 0); } function makeVisibleGridRow( diff --git a/tests/circuit-grid-projection.test.ts b/tests/circuit-grid-projection.test.ts index e5f1f9a..dde8b5d 100644 --- a/tests/circuit-grid-projection.test.ts +++ b/tests/circuit-grid-projection.test.ts @@ -78,6 +78,41 @@ const sections: CircuitTreeSectionDto[] = [ ]; describe("circuit grid projection", () => { + it("keeps empty sections and their free placeholders when no filter is active", () => { + const emptySections: CircuitTreeSectionDto[] = [ + { + id: "empty-lighting", + key: "lighting", + displayName: "Lighting", + prefix: "-1F", + sortOrder: 10, + circuits: [], + }, + { + id: "empty-single-phase", + key: "single_phase", + displayName: "Single-phase circuits", + prefix: "-2F", + sortOrder: 20, + circuits: [], + }, + ]; + + const projectedSections = filterAndSortCircuitSections(emptySections, {}, null); + const rows = buildVisibleGridRows(projectedSections); + + assert.equal(projectedSections.length, 2); + assert.deepEqual( + rows.map((row) => row.rowKey), + [ + "section:empty-lighting", + "placeholder:empty-lighting", + "section:empty-single-phase", + "placeholder:empty-single-phase", + ] + ); + }); + it("keeps every device row in a circuit block when one device matches a filter", () => { const result = filterAndSortCircuitSections(sections, { roomNumberSnapshot: ["1.01"] }, null);