Phases 6-8 of docs/website/THEMING_AND_NAV.md. The public header, the admin sidebar and the player portal now read their override row, and /admin/navigation writes them: rename, reorder by drag, hide, and — on the admin sidebar — move a row into another existing section. The merge always runs BEFORE the role and shard-feature filters in the layouts, which are unchanged and remain the boundary. An override is presentation: it cannot introduce a route, cannot touch a `roles` or `feature` gate, and a stored `hidden: false` on a gated item shows nobody anything. The design scoped these phases as client work, but the server had no way to store a nav row: updateSettings validates and stringifies theme_visual and brand_assets and lets everything else through, so a nav object would have been written as "[object Object]" and read as absent for ever. utils/navOverrides.js mirrors utils/brandAssets.js — strict on write with the offending key named, forgiving on read. It validates shape only; whether a `to` exists is settled client-side at merge time, because the base NAV arrays are client constants and a server-side copy would be a second source of truth that drifts. The nav editor cannot be hidden — its own toggle is disabled, the write path drops `hidden` on that one `to`, and AdminLayout strips it again before merging, which also covers a row edited straight in the database. Orders are written only when the sequence actually differs from the code's, and the comparison is restricted to the rows the editing admin can see, so renaming one item does not pin the position of every other one and a role- or feature-gated item missing from their palette is not mistaken for a reorder. Co-Authored-By: Claude <noreply@anthropic.com>
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
// Parse a JSON-valued settings row, client side.
|
|
//
|
|
// The counterpart to server/src/utils/settingsJson.js, and deliberately the same
|
|
// three lines of judgement: `settings.value` is TEXT, so theme_visual,
|
|
// brand_assets and the three nav_* keys all arrive as strings, and a malformed
|
|
// or wrong-shaped one must read as **absent** — the surface falls back to its
|
|
// BRAND_* env / theme.css / hardcoded NAV default — never as an error and never
|
|
// as a half-applied object.
|
|
//
|
|
// THEMING_AND_NAV.md §4.4 planned this "with its first consumer"; that consumer
|
|
// is the public header reading nav_public. `parseLayout` in heroLayout.js keeps
|
|
// its own version check because it validates a shape, not just a shape's kind.
|
|
|
|
/**
|
|
* @param {string|null|undefined} str the raw stored value
|
|
* @returns {object|null} the parsed object, or null when absent/malformed
|
|
*/
|
|
export function parseJsonSetting(str) {
|
|
if (typeof str !== 'string' || str === '') return null
|
|
let parsed
|
|
try {
|
|
parsed = JSON.parse(str)
|
|
} catch {
|
|
return null
|
|
}
|
|
// Only plain objects. A stored `null`, `4`, `"x"` or array is as unusable to
|
|
// every consumer of these keys as a syntax error is.
|
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return null
|
|
return parsed
|
|
}
|
|
|
|
export default parseJsonSetting
|