mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-18 22:36:19 +00:00
feat(nodes): hide hub-only views when active node is remote (#1007)
* feat(nodes): hide hub-only views when active node is remote Fleet, Schedules, Audit, Logs, and Auto-Update operate on hub-owned state (node registry, fleet schedules, centralized audit, fleet-wide log aggregation, fleet-wide update preview). When the active node is remote, proxying those surfaces would show that remote's own disconnected state instead of the hub's. Hide them from the nav strip and force-redirect to Home if one was open during the node switch. Backend hubOnlyGuard middleware sits between nodeContextMiddleware and the remote proxy and rejects /api/scheduled-tasks, /api/audit-log, and /api/notification-routes with 403 + HUB_ONLY_ENDPOINT when nodeId resolves to a remote, closing the script-bypass path the UI gating cannot reach. Settings sub-sections were already gated via the hiddenOnRemote registry; this extends the same model to top-level views. * docs(nodes): note hub-only visibility on Fleet, Schedules, Audit, Logs, Auto-Update Each of the five hub-only feature pages now points readers to the canonical "What top-level views show when a remote node is active" section in multi-node.mdx, so users landing directly on a feature page understand why the nav item disappears when they switch to a remote node.
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
import type { LucideIcon } from 'lucide-react';
|
||||
import { useAuth } from '@/context/AuthContext';
|
||||
import { useLicense } from '@/context/LicenseContext';
|
||||
import { useNodes } from '@/context/NodeContext';
|
||||
import { SENCHO_NAVIGATE_EVENT } from '@/components/NodeManager';
|
||||
import type { SenchoNavigateDetail } from '@/components/NodeManager';
|
||||
import type { SectionId } from '@/components/settings/types';
|
||||
@@ -24,8 +25,22 @@ export type ActiveView =
|
||||
| 'auto-updates'
|
||||
| 'settings';
|
||||
|
||||
// Views that operate on hub-owned state (node registry, fleet schedules,
|
||||
// centralized audit, fleet-wide log aggregation, fleet-wide update preview).
|
||||
// Hidden from the nav strip and force-redirect to dashboard when the active
|
||||
// node is remote, since proxying them would surface that remote's own
|
||||
// disconnected state instead of the hub's. Settings sub-sections use the
|
||||
// parallel `hiddenOnRemote` registry (see settings/registry.ts).
|
||||
export const HUB_ONLY_VIEWS: ReadonlySet<ActiveView> = new Set([
|
||||
'fleet',
|
||||
'scheduled-ops',
|
||||
'audit-log',
|
||||
'global-observability',
|
||||
'auto-updates',
|
||||
]);
|
||||
|
||||
export interface NavItem {
|
||||
value: string;
|
||||
value: ActiveView;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
}
|
||||
@@ -38,6 +53,8 @@ export function useViewNavigationState(options?: UseViewNavigationStateOptions)
|
||||
const { onNavigateToDashboard } = options ?? {};
|
||||
const { isAdmin, can } = useAuth();
|
||||
const { isPaid, license } = useLicense();
|
||||
const { activeNode } = useNodes();
|
||||
const isRemote = activeNode?.type === 'remote';
|
||||
|
||||
const [activeView, setActiveView] = useState<ActiveView>('dashboard');
|
||||
const [settingsSection, setSettingsSection] = useState<SectionId>('appearance');
|
||||
@@ -97,8 +114,18 @@ export function useViewNavigationState(options?: UseViewNavigationStateOptions)
|
||||
if (can('system:audit')) items.push({ value: 'audit-log', label: 'Audit', icon: ScrollText });
|
||||
if (isAdmin) items.push({ value: 'scheduled-ops', label: 'Schedules', icon: Clock });
|
||||
}
|
||||
return items;
|
||||
}, [isAdmin, isPaid, license?.variant, can]);
|
||||
return isRemote
|
||||
? items.filter(i => !HUB_ONLY_VIEWS.has(i.value))
|
||||
: items;
|
||||
}, [isAdmin, isPaid, license?.variant, can, isRemote]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isRemote && HUB_ONLY_VIEWS.has(activeView)) {
|
||||
onNavigateToDashboard?.();
|
||||
setActiveView('dashboard');
|
||||
setFilterNodeId(null);
|
||||
}
|
||||
}, [isRemote, activeView, onNavigateToDashboard]);
|
||||
|
||||
return {
|
||||
activeView, setActiveView,
|
||||
|
||||
Reference in New Issue
Block a user