Skip to content

The Sidebar Preview That Filtered the Wrong Thing

Adityo Guni Waluyo

A role preview that filtered the full sidebar showed a view no account ever saw. The fix: derive the simulation from the production nav builder itself.

TL;DR

The manual sidebar initially exposed all navigation at once, so a role preview bar was added using a hand-written map that quickly drifted from what accounts actually see at login. A follow-up commit replaced filtering with pre-rendered per-role templates mirroring the production nav builder at build time. The takeaway: simulations must derive from the same rule source as the systems they simulate.

I generated the admin manual for KotaPortal, opened the output in a browser, and the sidebar showed everything at once. Every division, every CMS menu, every document section stacked into one long list. Then QA asked the question that ended that design: what does the tourism-division admin actually see after login?

Answering it honestly meant signing into six separate accounts and photographing the same sidebar six times. Every time the manual changed, the six photographs went stale. So I built a preview instead. The first version of that preview was wrong in a way that took a second commit to admit.

A hand-written map pretending to be permissions

Commit 9938f8b landed on 2026-11-07. The generated manual gained a horizontal "View as" bar above the content: a header with a Super Admin tag plus one chip per division, defaulting to "All". Selecting a chip filtered the sidebar through a hand-written ROLE_MAP.

Each .side-sect and .side-link carried role data in its markup, and the client toggled the hidden attribute on and off.

Two entries never moved: "Manual Index" and "Official Documents" stayed visible for every role. The index table at the top was deliberately left unfiltered — it is a table of contents, not a permission surface.

The craft was careful. One delegated click listener on the bar, resolving the actual target with e.target.closest("button[data-role]").

const bar = document.getElementById("role-bar");

bar.addEventListener("click", (e) => {
  const chip = e.target.closest("button[data-role]");
  if (!chip) return;

  for (const b of bar.querySelectorAll("button[data-role]")) {
    b.setAttribute("aria-pressed", String(b === chip));
  }
  showRole(chip.dataset.role);
});

MDN describes closest() as traversing "the element and its parents (heading toward the document root) until it finds a node that matches the specified CSS selector", and returning null when nothing matches [1]. The chips carry aria-pressed; MDN defines that attribute as indicating "the current \"pressed\" state of a toggle button" [2], and the W3C ARIA Authoring Practices guide treats this as the two-state toggle button pattern, activated by Space and Enter [3]. MDN also warns not to change a toggle's label contents when the state changes [2], so a chip reads "Tourism" whether it is pressed or not.

Styling used custom-property tokens: --accent, --surface, and --border.

All three are defined on :root.

MDN's point about custom properties is that a value can "be defined in one place, then referenced in multiple other places" [4], which is exactly what a theme-plus-role bar needs. And the selected role persisted nowhere. localStorage kept only the theme, because MDN notes that stored data "is saved across browser sessions" [5] — precisely the behaviour I did not want for a preview state.

The filtered view drifted from the real one

The premise of commit 9938f8b was that simulating a role means filtering a superset of the navigation. That premise was wrong. Hide/show filtering cannot reproduce what an account sees at login, because grouping and permission scoping live in the production nav builder, not in the sidebar markup of a generated manual.

A second, hand-maintained map is a second source of truth. Mine pinned "Manual Index" and dropped sections by rules nobody had validated against the builder, so the preview quietly disagreed with the real login view. The owner's directive made the requirement explicit: the role sidebar must show what that account sees when logged in.

Commit 17b5837, same day, replaced filtering with per-role re-render.

The generator now mirrors the production nav builder, starting from buildNavGroups in layout.tsx.

That builder reads the per-division module list from BIDANG_MODULE_SLUGS in rbac.ts, and the mirror runs at build time into six pre-rendered nav templates.

The client JS swaps #role-nav instead of hiding rows. Sections belonging to other divisions keep read-only eye icons, and CMS menus that own no manual page render as inert dim rows rather than disappearing.

The delegated listener and the aria-pressed chips survived the rewrite unchanged. What changed was the payload: a template cloned from the same rules the production builder runs, instead of a boolean list maintained by hand.

What the preview deliberately does not do

The bar still refuses to persist the selected role, and that is now a stated decision rather than an omission. A preview answers one question at a time: what does this account see. The moment it survives a refresh, people start screenshotting it and filing bugs against a state that no account is ever in. The theme persists because the theme is real; the role is not.

Six nav templates cost more build output than one sidebar plus a filter map. I accepted the trade. The extra bytes are cheap next to a preview that drifted from production within the same day.

The rule I took from this: a simulation must derive from the same rule source as the system it simulates. Mirroring the builder at build time is honest; filtering a superset with a second map is a guess with a user interface on top. The hand-written ROLE_MAP is gone from the manual, and the manual's sidebar no longer shows everything at once.

Sources:

Related articles