[object Object]

← back to Dw Pairs Well

collection-grouped feed: emit color/style facets (only populated filter values) so the grid UI never shows a dead filter tab

fc5135eb3fd1255146503b81e435042d7ed9d2c7 · 2026-06-26 10:53:18 -0700 · Steve

Files touched

Diff

commit fc5135eb3fd1255146503b81e435042d7ed9d2c7
Author: Steve <steve@designerwallcoverings.com>
Date:   Fri Jun 26 10:53:18 2026 -0700

    collection-grouped feed: emit color/style facets (only populated filter values) so the grid UI never shows a dead filter tab
---
 server.js | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/server.js b/server.js
index 268b113..2f19c17 100644
--- a/server.js
+++ b/server.js
@@ -713,7 +713,24 @@ app.get('/api/collection-grouped', async (req, res) => {
       if (g.swatches.length < 6 && (row.dominant_hex)) g.swatches.push(row.dominant_hex);
     }
 
-    let arr = [...groups.values()];
+    const allGroups = [...groups.values()];
+    let arr = allGroups;
+
+    // FACETS — which Color/Style values actually have tiles in THIS collection, so the
+    // front-end only renders populated filter chips (no dead tab that returns 0 results).
+    // Computed over the UNFILTERED set so the chip list stays stable while drilling in.
+    const styleCounts = {}, hueCounts = {};
+    for (const g of allGroups) {
+      if (g._style && g._style !== 'zzz') styleCounts[g._style] = (styleCounts[g._style] || 0) + 1;
+      for (const hk of Object.keys(HUE_BUCKETS)) {
+        if (hueInBucket(g._hue, hk)) { hueCounts[hk] = (hueCounts[hk] || 0) + 1; break; }
+      }
+    }
+    const facets = {
+      color: Object.keys(hueCounts).filter(k => hueCounts[k] > 0),
+      style: Object.keys(styleCounts).filter(k => styleCounts[k] > 0)
+    };
+
     // DRILL-DOWN FILTERS — the "Color" / "Style" chips reveal value sub-chips that filter here.
     const hueF = String(req.query.hue || '').toLowerCase().slice(0, 16);
     const styleF = String(req.query.style || '').toLowerCase().slice(0, 24);
@@ -742,6 +759,7 @@ app.get('/api/collection-grouped', async (req, res) => {
       total_tiles,
       total_pages: Math.ceil(total_tiles / per),
       has_next: start + per < total_tiles,
+      facets,
       tiles: slice.map(g => ({
         pattern_id: g.pattern_id,
         pattern: g.pattern,

← 2d70921 Design Coordinate v7: 6+6 cards, rename AI→Auto Generated (n  ·  back to Dw Pairs Well  ·  auto-save: 2026-06-26T11:15:12 (1 files) — server.js e22b966 →