Lean build: hide settings cards whose route was not staged

settingsNav.js hardcodes plugin settings (PC Access Protocols, Machine Types,
VLANs, Employee Directory, ...). A lean per-site build only stages the chosen
plugins' settings routes, so the settings rail showed cards for absent plugins
that dead-ended on a blank page. useSettingsCatalog now filters the catalog to
cards whose target route is registered in this build's router (router.getRoutes),
dropping now-empty groups. Generic - gates every settings card by staged routes
with no per-plugin logic; full builds keep every card. Found testing a live
machines+printers lean site.
This commit is contained in:
cproudlock
2026-07-19 12:17:51 -04:00
parent d009ac94fb
commit 5d86bc86b3

View File

@@ -3,9 +3,10 @@
// GET /api/pluginui/settings-cards. Both SettingsLayout (rail) and SettingsIndex // GET /api/pluginui/settings-cards. Both SettingsLayout (rail) and SettingsIndex
// (landing) read the merged catalog so plugins add settings cards with no core // (landing) read the merged catalog so plugins add settings cards with no core
// edit. Fetched once into a module-level ref and shared across callers. // edit. Fetched once into a module-level ref and shared across callers.
import { ref } from 'vue' import { ref, computed } from 'vue'
import { Ruler, Wrench, Cog, Package, Settings, Puzzle, SlidersHorizontal, Palette, Bell, Network, Printer, Droplets } from 'lucide-vue-next' import { Ruler, Wrench, Cog, Package, Settings, Puzzle, SlidersHorizontal, Palette, Bell, Network, Printer, Droplets } from 'lucide-vue-next'
import api from '../api' import api from '../api'
import router from '../router'
import { settingsGroups } from '../views/settings/settingsNav' import { settingsGroups } from '../views/settings/settingsNav'
// Icon string keys (as returned by the hook) mapped to Lucide components, // Icon string keys (as returned by the hook) mapped to Lucide components,
@@ -62,18 +63,36 @@ function mergeCards(baseGroups, cards) {
return merged return merged
} }
// Drop cards whose target route is not registered in THIS build. settingsNav
// hardcodes plugin settings (PC Access Protocols, Machine Types, VLANs, ...),
// but a lean per-site build only stages the chosen plugins' settings routes;
// showing a card whose route was never staged lands the admin on a blank page.
// Filtering by the router's own route table gates every menu the same way with
// no per-plugin logic. Called inside a computed so the (circular) router import
// is resolved by the time it runs, and so full builds keep every card.
function keepRegistered(baseGroups) {
const registered = new Set(router.getRoutes().map(r => r.path))
return baseGroups
.map(group => ({
title: group.title,
cards: group.cards.filter(card => registered.has(card.to)),
}))
.filter(group => group.cards.length)
}
// Shared across component instances: seeded with the core groups, replaced with // Shared across component instances: seeded with the core groups, replaced with
// the merged catalog once the hook endpoint answers. // the merged catalog once the hook endpoint answers.
const groups = ref(settingsGroups) const rawGroups = ref(settingsGroups)
const groups = computed(() => keepRegistered(rawGroups.value))
let loaded = false let loaded = false
async function loadCatalog() { async function loadCatalog() {
try { try {
const response = await api.get('/pluginui/settings-cards') const response = await api.get('/pluginui/settings-cards')
groups.value = mergeCards(settingsGroups, response.data.data || []) rawGroups.value = mergeCards(settingsGroups, response.data.data || [])
} catch (error) { } catch (error) {
// Degrade to the core-only catalog; the rail still works without plugins. // Degrade to the core-only catalog; the rail still works without plugins.
groups.value = settingsGroups rawGroups.value = settingsGroups
} }
} }