feat(webui): layout schema for mobile overview + topbar items (B2)
Schema foundation for the B2 dashboard batch, mirroring the navItems shape: - `overviewMobile: UiLayoutItem[]` — a separate single-column (id+visible) ordering for phones, kept fully disjoint from the desktop 2D `overviewBlocks` grid so mobile ordering never pollutes grid coords. - `topbarItems: UiLayoutItem[]` — show/hide list for toggleable top-bar elements (status badge, theme toggle, kiosk button); essential elements stay pinned in the consumer. Server `normalizeLayout` round-trips both (idOr + dedup, total over corrupt input); defaults seed first run. `LayoutContext` exposes them with setOverviewMobile/setTopbarItems setters and reconcile-on-consume semantics, so adding a widget/element later just appears. Old configs lacking the fields fall back to defaults on load. Consumers (mobile render, topbar render + config, drag-sort panel) land in follow-up B2 commits.
This commit is contained in:
4 files changed
+83
-5
No files matched your search
@@ -142,10 +142,15 @@ export interface UiLayoutItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UiLayout {
|
export interface UiLayout {
|
||||||
/** Ordered overview blocks. Frontend reconciles against its known set. */
|
/** Ordered overview blocks (desktop 2D grid). Frontend reconciles vs its set. */
|
||||||
overviewBlocks: UiLayoutItem[];
|
overviewBlocks: UiLayoutItem[];
|
||||||
|
/** Ordered single-column mobile overview (id+visible only; the 2D grid is
|
||||||
|
* desktop-only). Kept separate so phone ordering never pollutes the grid. */
|
||||||
|
overviewMobile: UiLayoutItem[];
|
||||||
/** Ordered sidebar nav items, keyed by route path. */
|
/** Ordered sidebar nav items, keyed by route path. */
|
||||||
navItems: UiLayoutItem[];
|
navItems: UiLayoutItem[];
|
||||||
|
/** Top-bar element show/hide list (id+visible), mirroring navItems' shape. */
|
||||||
|
topbarItems: UiLayoutItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UiHighlightRule {
|
export interface UiHighlightRule {
|
||||||
@@ -231,6 +236,21 @@ const DEFAULT_OVERVIEW_BLOCKS: UiLayoutItem[] = [
|
|||||||
{ id: 'sessions', visible: true },
|
{ id: 'sessions', visible: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Single-column mobile order = the desktop grid catalogue's widgets, flattened
|
||||||
|
// (stat tiles, then the cards). The client reconciles against its real
|
||||||
|
// catalogue, so this just seeds first run; unknown ids are dropped on load.
|
||||||
|
const DEFAULT_OVERVIEW_MOBILE: UiLayoutItem[] = [
|
||||||
|
{ id: 'stat:status', visible: true },
|
||||||
|
{ id: 'stat:accounts', visible: true },
|
||||||
|
{ id: 'stat:processes', visible: true },
|
||||||
|
{ id: 'stat:host', visible: true },
|
||||||
|
{ id: 'stat:uptime', visible: true },
|
||||||
|
{ id: 'connections', visible: true },
|
||||||
|
{ id: 'alerts', visible: true },
|
||||||
|
{ id: 'host', visible: true },
|
||||||
|
{ id: 'sessions', visible: true },
|
||||||
|
];
|
||||||
|
|
||||||
const DEFAULT_NAV_ITEMS: UiLayoutItem[] = [
|
const DEFAULT_NAV_ITEMS: UiLayoutItem[] = [
|
||||||
{ id: '/', visible: true },
|
{ id: '/', visible: true },
|
||||||
{ id: '/processes', visible: true },
|
{ id: '/processes', visible: true },
|
||||||
@@ -239,6 +259,15 @@ const DEFAULT_NAV_ITEMS: UiLayoutItem[] = [
|
|||||||
{ id: '/settings', visible: true },
|
{ id: '/settings', visible: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Toggleable top-bar elements (essential ones — menu, page title, logout — are
|
||||||
|
// pinned in the client and never appear here). The client reconciles, so a new
|
||||||
|
// element (e.g. the kiosk button) just appears as visible.
|
||||||
|
const DEFAULT_TOPBAR_ITEMS: UiLayoutItem[] = [
|
||||||
|
{ id: 'status', visible: true },
|
||||||
|
{ id: 'theme', visible: true },
|
||||||
|
{ id: 'kiosk', visible: true },
|
||||||
|
];
|
||||||
|
|
||||||
const LOG_LEVELS = ['trace', 'debug', 'info', 'success', 'warn', 'error'];
|
const LOG_LEVELS = ['trace', 'debug', 'info', 'success', 'warn', 'error'];
|
||||||
|
|
||||||
const DEFAULT_PAGES: UiPages = {
|
const DEFAULT_PAGES: UiPages = {
|
||||||
@@ -260,7 +289,9 @@ export function defaultUiConfig(): UiConfig {
|
|||||||
appearance: { ...DEFAULT_APPEARANCE, background: { ...DEFAULT_BACKGROUND }, cssVars: {} },
|
appearance: { ...DEFAULT_APPEARANCE, background: { ...DEFAULT_BACKGROUND }, cssVars: {} },
|
||||||
layout: {
|
layout: {
|
||||||
overviewBlocks: DEFAULT_OVERVIEW_BLOCKS.map((b) => ({ ...b })),
|
overviewBlocks: DEFAULT_OVERVIEW_BLOCKS.map((b) => ({ ...b })),
|
||||||
|
overviewMobile: DEFAULT_OVERVIEW_MOBILE.map((b) => ({ ...b })),
|
||||||
navItems: DEFAULT_NAV_ITEMS.map((b) => ({ ...b })),
|
navItems: DEFAULT_NAV_ITEMS.map((b) => ({ ...b })),
|
||||||
|
topbarItems: DEFAULT_TOPBAR_ITEMS.map((b) => ({ ...b })),
|
||||||
},
|
},
|
||||||
pages: defaultPages(),
|
pages: defaultPages(),
|
||||||
};
|
};
|
||||||
@@ -506,7 +537,9 @@ export function normalizeLayout(value: unknown): UiLayout {
|
|||||||
const layout = isObject(value) ? value : {};
|
const layout = isObject(value) ? value : {};
|
||||||
return {
|
return {
|
||||||
overviewBlocks: normalizeLayoutItems(layout.overviewBlocks, DEFAULT_OVERVIEW_BLOCKS),
|
overviewBlocks: normalizeLayoutItems(layout.overviewBlocks, DEFAULT_OVERVIEW_BLOCKS),
|
||||||
|
overviewMobile: normalizeLayoutItems(layout.overviewMobile, DEFAULT_OVERVIEW_MOBILE),
|
||||||
navItems: normalizeLayoutItems(layout.navItems, DEFAULT_NAV_ITEMS),
|
navItems: normalizeLayoutItems(layout.navItems, DEFAULT_NAV_ITEMS),
|
||||||
|
topbarItems: normalizeLayoutItems(layout.topbarItems, DEFAULT_TOPBAR_ITEMS),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||||
import { useApi } from '@/lib/api';
|
import { useApi } from '@/lib/api';
|
||||||
import { defaultOverviewGrid, migrateOverviewBlocks } from '@/lib/dashboard-layout';
|
import { defaultOverviewGrid, defaultOverviewMobile, migrateOverviewBlocks } from '@/lib/dashboard-layout';
|
||||||
import type { UiLayout, UiLayoutItem, UiPages } from '@/types';
|
import type { UiLayout, UiLayoutItem, UiPages } from '@/types';
|
||||||
|
|
||||||
// Client-side layout customization (the "C" half). The server stores the
|
// Client-side layout customization (the "C" half). The server stores the
|
||||||
@@ -20,11 +20,18 @@ const DEFAULT_NAV_ITEMS: UiLayoutItem[] = [
|
|||||||
{ id: '/settings', visible: true },
|
{ id: '/settings', visible: true },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Toggleable top-bar elements (essential ones are pinned in the consumer). The
|
||||||
|
// catalogue (labels) lives with the top-bar; this is just the default order.
|
||||||
|
export const TOPBAR_ITEM_IDS = ['status', 'theme', 'kiosk'] as const;
|
||||||
|
const DEFAULT_TOPBAR_ITEMS: UiLayoutItem[] = TOPBAR_ITEM_IDS.map((id) => ({ id, visible: true }));
|
||||||
|
|
||||||
export const DEFAULT_LAYOUT: UiLayout = {
|
export const DEFAULT_LAYOUT: UiLayout = {
|
||||||
// Overview blocks are the positioned grid widgets (the catalogue owns the
|
// Overview blocks are the positioned grid widgets (the catalogue owns the
|
||||||
// default placement + the legacy `stats`→tiles migration).
|
// default placement + the legacy `stats`→tiles migration).
|
||||||
overviewBlocks: defaultOverviewGrid(),
|
overviewBlocks: defaultOverviewGrid(),
|
||||||
|
overviewMobile: defaultOverviewMobile(),
|
||||||
navItems: DEFAULT_NAV_ITEMS.map((i) => ({ ...i })),
|
navItems: DEFAULT_NAV_ITEMS.map((i) => ({ ...i })),
|
||||||
|
topbarItems: DEFAULT_TOPBAR_ITEMS.map((i) => ({ ...i })),
|
||||||
};
|
};
|
||||||
|
|
||||||
const ALL_LEVELS = ['trace', 'debug', 'info', 'success', 'warn', 'error'];
|
const ALL_LEVELS = ['trace', 'debug', 'info', 'success', 'warn', 'error'];
|
||||||
@@ -66,12 +73,18 @@ export function reconcileLayoutItems(
|
|||||||
|
|
||||||
interface LayoutContextValue {
|
interface LayoutContextValue {
|
||||||
overviewBlocks: UiLayoutItem[];
|
overviewBlocks: UiLayoutItem[];
|
||||||
|
overviewMobile: UiLayoutItem[];
|
||||||
navItems: UiLayoutItem[];
|
navItems: UiLayoutItem[];
|
||||||
/** Persist a new overview-block order/visibility. */
|
topbarItems: UiLayoutItem[];
|
||||||
|
/** Persist a new overview-block order/visibility (desktop 2D grid). */
|
||||||
setOverviewBlocks: (items: UiLayoutItem[]) => void;
|
setOverviewBlocks: (items: UiLayoutItem[]) => void;
|
||||||
|
/** Persist a new single-column mobile order/visibility. */
|
||||||
|
setOverviewMobile: (items: UiLayoutItem[]) => void;
|
||||||
/** Persist a new nav order/visibility. */
|
/** Persist a new nav order/visibility. */
|
||||||
setNavItems: (items: UiLayoutItem[]) => void;
|
setNavItems: (items: UiLayoutItem[]) => void;
|
||||||
/** Reset layout (blocks + nav) to defaults. */
|
/** Persist a new top-bar show/hide order. */
|
||||||
|
setTopbarItems: (items: UiLayoutItem[]) => void;
|
||||||
|
/** Reset layout (blocks + mobile + nav + topbar) to defaults. */
|
||||||
resetLayout: () => void;
|
resetLayout: () => void;
|
||||||
/** Per-page preferences (default route, logs/processes/config prefs). */
|
/** Per-page preferences (default route, logs/processes/config prefs). */
|
||||||
pages: UiPages;
|
pages: UiPages;
|
||||||
@@ -117,7 +130,11 @@ export function LayoutProvider({ children }: { children: ReactNode }) {
|
|||||||
if (config.layout) {
|
if (config.layout) {
|
||||||
setLayout({
|
setLayout({
|
||||||
overviewBlocks: migrateOverviewBlocks(config.layout.overviewBlocks),
|
overviewBlocks: migrateOverviewBlocks(config.layout.overviewBlocks),
|
||||||
|
// Mobile/topbar are stored raw; consumers reconcile against their
|
||||||
|
// known catalogues (so a new widget/element "just appears").
|
||||||
|
overviewMobile: config.layout.overviewMobile ?? defaultOverviewMobile(),
|
||||||
navItems: config.layout.navItems,
|
navItems: config.layout.navItems,
|
||||||
|
topbarItems: config.layout.topbarItems ?? DEFAULT_TOPBAR_ITEMS.map((i) => ({ ...i })),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (config.pages) setPagesState(config.pages);
|
if (config.pages) setPagesState(config.pages);
|
||||||
@@ -159,14 +176,24 @@ export function LayoutProvider({ children }: { children: ReactNode }) {
|
|||||||
persist({ ...layoutRef.current, overviewBlocks: items });
|
persist({ ...layoutRef.current, overviewBlocks: items });
|
||||||
}, [persist]);
|
}, [persist]);
|
||||||
|
|
||||||
|
const setOverviewMobile = useCallback((items: UiLayoutItem[]) => {
|
||||||
|
persist({ ...layoutRef.current, overviewMobile: items });
|
||||||
|
}, [persist]);
|
||||||
|
|
||||||
const setNavItems = useCallback((items: UiLayoutItem[]) => {
|
const setNavItems = useCallback((items: UiLayoutItem[]) => {
|
||||||
persist({ ...layoutRef.current, navItems: items });
|
persist({ ...layoutRef.current, navItems: items });
|
||||||
}, [persist]);
|
}, [persist]);
|
||||||
|
|
||||||
|
const setTopbarItems = useCallback((items: UiLayoutItem[]) => {
|
||||||
|
persist({ ...layoutRef.current, topbarItems: items });
|
||||||
|
}, [persist]);
|
||||||
|
|
||||||
const resetLayout = useCallback(() => {
|
const resetLayout = useCallback(() => {
|
||||||
persist({
|
persist({
|
||||||
overviewBlocks: defaultOverviewGrid(),
|
overviewBlocks: defaultOverviewGrid(),
|
||||||
|
overviewMobile: defaultOverviewMobile(),
|
||||||
navItems: DEFAULT_NAV_ITEMS.map((i) => ({ ...i })),
|
navItems: DEFAULT_NAV_ITEMS.map((i) => ({ ...i })),
|
||||||
|
topbarItems: DEFAULT_TOPBAR_ITEMS.map((i) => ({ ...i })),
|
||||||
});
|
});
|
||||||
}, [persist]);
|
}, [persist]);
|
||||||
|
|
||||||
@@ -184,16 +211,20 @@ export function LayoutProvider({ children }: { children: ReactNode }) {
|
|||||||
|
|
||||||
const value = useMemo<LayoutContextValue>(() => ({
|
const value = useMemo<LayoutContextValue>(() => ({
|
||||||
overviewBlocks: layout.overviewBlocks,
|
overviewBlocks: layout.overviewBlocks,
|
||||||
|
overviewMobile: layout.overviewMobile,
|
||||||
navItems: layout.navItems,
|
navItems: layout.navItems,
|
||||||
|
topbarItems: layout.topbarItems,
|
||||||
setOverviewBlocks,
|
setOverviewBlocks,
|
||||||
|
setOverviewMobile,
|
||||||
setNavItems,
|
setNavItems,
|
||||||
|
setTopbarItems,
|
||||||
resetLayout,
|
resetLayout,
|
||||||
pages,
|
pages,
|
||||||
setPages,
|
setPages,
|
||||||
ready,
|
ready,
|
||||||
editing,
|
editing,
|
||||||
setEditing,
|
setEditing,
|
||||||
}), [layout, setOverviewBlocks, setNavItems, resetLayout, pages, setPages, ready, editing]);
|
}), [layout, setOverviewBlocks, setOverviewMobile, setNavItems, setTopbarItems, resetLayout, pages, setPages, ready, editing]);
|
||||||
|
|
||||||
return <LayoutContext.Provider value={value}>{children}</LayoutContext.Provider>;
|
return <LayoutContext.Provider value={value}>{children}</LayoutContext.Provider>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,15 @@ export function defaultOverviewGrid(): UiLayoutItem[] {
|
|||||||
return GRID_WIDGETS.map((w) => ({ id: w.id, visible: true, ...w.def }));
|
return GRID_WIDGETS.map((w) => ({ id: w.id, visible: true, ...w.def }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The widget ids in single-column (mobile) default order — same catalogue as
|
||||||
|
* the desktop grid, flattened. Mobile items carry id+visible only (no coords). */
|
||||||
|
export const MOBILE_WIDGET_IDS: readonly string[] = GRID_WIDGETS.map((w) => w.id);
|
||||||
|
|
||||||
|
/** Default single-column mobile overview (id+visible, no coords). */
|
||||||
|
export function defaultOverviewMobile(): UiLayoutItem[] {
|
||||||
|
return GRID_WIDGETS.map((w) => ({ id: w.id, visible: true }));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bring any stored overview layout up to the current grid catalogue:
|
* Bring any stored overview layout up to the current grid catalogue:
|
||||||
* - expand the legacy single `stats` block into the 5 individual tiles
|
* - expand the legacy single `stats` block into the 5 individual tiles
|
||||||
|
|||||||
@@ -235,8 +235,13 @@ export interface UiLayoutItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UiLayout {
|
export interface UiLayout {
|
||||||
|
/** Desktop 2D grid blocks (carry x/y/w/h). */
|
||||||
overviewBlocks: UiLayoutItem[];
|
overviewBlocks: UiLayoutItem[];
|
||||||
|
/** Single-column mobile overview order (id+visible only). */
|
||||||
|
overviewMobile: UiLayoutItem[];
|
||||||
navItems: UiLayoutItem[];
|
navItems: UiLayoutItem[];
|
||||||
|
/** Top-bar element show/hide list (id+visible). */
|
||||||
|
topbarItems: UiLayoutItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UiHighlightRule {
|
export interface UiHighlightRule {
|
||||||
|
|||||||
Reference in new issue
Block a user