Adding Dynamic Tab Hiding and Multi‑Location Support to the Annual Review Dashboard
TL;DR: I refactored the annual review UI to automatically hide system tabs that aren’t selected for a property and extended the API to accept multi‑location payloads. The changes live in public/index.html, public/js/annual.js, and the api/v1/[action].js endpoint, and they make the dashboard scale to properties with dozens of locations without manual UI tweaks.
The Problem
The annual review page (/annual) renders a set of tabs – nv (Nuvola tickets), cy (Cybersecurity), sd (Service Desk), etc. Each tab shows a table populated from the backend lists __yrNv, __yrCy, … When a property disables a system (e.g., the Cybersecurity service isn’t subscribed), the corresponding tab still appears, but the table is empty.
Two related pain points surfaced:
- Visual noise – Users have to click through empty tabs, which hurts usability.
- Multi‑location properties – The original data model assumed a single location per property. When a property started reporting data from several hotels, the UI rendered a single set of tables, mixing data from all locations and making the numbers meaningless.
Both issues manifested as a broken user experience, and the codebase had no hook to filter tabs or to group data by location.
What I Tried First
My first instinct was to handle the tab hiding purely with CSS: add a .hidden class to the <li> elements that represent tabs, then toggle that class from the HTML template based on a server‑side flag. I added a conditional block in public/index.html:
<li class="{{#if hideCy}}hidden{{/if}}">Cybersecurity</li> But the HTML is static – the page is served as a single file, and the server does not render per‑property templates. The flag never reached the client, so the tabs stayed visible.
I also attempted to filter the data in the backend by adding a location query param to the GET /api/v1/annual endpoint and returning only the matching rows. That worked for the tables, but the empty tabs still rendered, and the front‑end had no way to know which systems were actually present for the current property.
Both approaches failed because the UI needed to react after the property data was loaded, not before the page was rendered.
The Implementation
1. Hook the UI after the annual data payload arrives
In public/js/annual.js the yrApply(data) function is the entry point that receives the JSON payload from /api/v1/annual. I added a call to a new helper yrSyncTabs() right after the tables are rendered:
@@ -308,6 +308,7 @@ function yrApply(data) { Object.entries(YR_LISTS).forEach(([id, c]) => yrRenderList(id, Array.isArray(d[c.list]) ? d[c.list] : [])); yrLockRO(); + yrSyncTabs(); co 2. Implement yrSyncTabs
The new function inspects the incoming data for each system’s list. If the list is empty or the property’s configuration marks the system as “unchecked”, the corresponding tab <li> is hidden and its content <section> is removed from the DOM.
// public/js/annual.js function yrSyncTabs() { // Mapping of system IDs to the list key used in the payload const SYSTEM_MAP = { nv: '__yrNv', sd: '__yrSd', cy: '__yrCy', // add future systems here }; Object.entries(SYSTEM_MAP).forEach(([tabId, listKey]) => { const hasData = Array.isArray(YR_DATA[listKey]) && YR_DATA[listKey].length > 0; const tabEl = document.querySelector(`li[data-tab="${tabId}"]`); const paneEl = document.getElementById(`yr${tabId.toUpperCase()}Body`); if (!hasData) { // hide the tab button if (tabEl) tabEl.style.display = 'none'; // hide the pane container if (paneEl) paneEl.parentElement.style.display = 'none'; } else { // ensure visible if data exists (useful when re‑loading) if (tabEl) tabEl.style.display = ''; if (paneEl) paneEl.parentElement.style.display = ''; } }); } YR_DATA is the global that yrApply populates (const d = data;). By running after yrLockRO() we guarantee the UI is already built, so we only need to toggle visibility.
3. Update the script tag versioning
To make sure browsers fetch the new annual.js, I bumped the version hash in public/index.html:
-<script src="/js/annual.js?v=20261204a"></script> +<script src="/js/annual.js?v=20261204b"></script> That tiny change forces a cache‑bust for all users.
4. Extend the API for multi‑location payloads
The backend endpoint lives in api/v1/[action].js. I added three new fields to the response object that describe location metadata:
@@ -30,6 +30,9 @@ const LIST_NOTES = { __yrNvOps: "Revisión anual: tickets de Nuvola del año por operador; name, v.", __yrNvCat: "Revisión anual: top 3 categorías de Nuvola del año; name, v.", + // New location fields + __yrLocations: "Array of location identifiers attached to the property", + __yrLocationMap: "Mapping of location ID → human readable name", The handler now pulls locations from the property record and attaches them to the JSON response:
// api/v1/[action].js (excerpt) async function getAnnualData(req, res) { const propertyId = req.query.propId; const prop = await db.getProperty(propertyId); const payload = { __yrNv: await getNvList(prop.id), __yrSd: await getSdList(prop.id), __yrCy: await getCyList(prop.id), // new location metadata __yrLocations: prop.locations, // e.g. ["mx01", "mx02"] __yrLocationMap: await db.getLocationNames(prop.locations), }; res.json(payload); } 5. Adjust the front‑end to render per‑location tables
In public/js/annual.js I introduced a small wrapper that splits the incoming list by location before rendering:
function yrRenderList(id, items) { const locMap = YR_DATA.__yrLocationMap || {}; const grouped = {}; // Group items by location field (assume each item has a `loc` key) items.forEach(item => { const loc = item.loc || 'default'; if (!grouped[loc]) grouped[loc] = []; grouped[loc].push(item); }); // Render a separate table for each location Object.entries(grouped).forEach(([loc, rows]) => { const container = document.getElementById(`${YR_TABLES[id].body}-${loc}`); if (!container) return; // safety container.innerHTML = rows.map(r => yrRowHtml(id, r)).join(''); // optional: add a header with the location name const header = document.createElement('h4'); header.textContent = locMap[loc] || loc; container.prepend(header); }); } Corresponding HTML placeholders were added to `public/index.html
Part of my Build in Public series — sharing the real process of building SaaS projects from Playa del Carmen, México.
Repo: zaerohell/hotel-it-ops-dashboard · 2026-12-04
#playadev #buildinpublic
