Show inventory sidebar item for both Spoolman and internal inventory

Previously the Inventory sidebar item was hidden when Spoolman was
enabled. Now it always shows — when Spoolman is active, /inventory
embeds the Spoolman web UI in the content area via iframe; when
disabled, it renders the internal inventory page as before.
This commit is contained in:
maziggy
2026-02-23 08:23:35 +01:00
parent 77677cb07f
commit 3c72f7cb22
5 changed files with 64 additions and 53 deletions
-12
View File
@@ -119,13 +119,6 @@ export function Layout() {
refetchInterval: 60 * 60 * 1000, // Check every hour
});
// Fetch Spoolman settings to determine if inventory should be hidden
const { data: spoolmanSettings } = useQuery({
queryKey: ['spoolman-settings'],
queryFn: api.getSpoolmanSettings,
staleTime: 5 * 60 * 1000,
});
// Fetch external links for sidebar
const { data: externalLinks } = useQuery({
queryKey: ['external-links'],
@@ -229,13 +222,9 @@ export function Layout() {
// Determine if settings should be hidden (user role and auth enabled)
const hideSettings = authEnabled && user?.role === 'user';
// Hide inventory when Spoolman mode is active
const hideInventory = spoolmanSettings?.spoolman_enabled === 'true';
// Add items in stored order
for (const id of sidebarOrder) {
if (hideSettings && id === 'settings') continue;
if (hideInventory && id === 'inventory') continue;
if (navItemsMap.has(id) || extLinksMap.has(id)) {
result.push(id);
seen.add(id);
@@ -245,7 +234,6 @@ export function Layout() {
// Add any new internal nav items not in stored order
for (const item of defaultNavItems) {
if (hideSettings && item.id === 'settings') continue;
if (hideInventory && item.id === 'inventory') continue;
if (!seen.has(item.id)) {
result.push(item.id);
seen.add(item.id);
+23 -1
View File
@@ -337,7 +337,29 @@ function saveSortState(state: SortState) {
} catch { /* ignore */ }
}
export default function InventoryPage() {
// Wrapper: when Spoolman is enabled, embed its UI; otherwise show internal inventory
export default function InventoryPageRouter() {
const { data: spoolmanSettings } = useQuery({
queryKey: ['spoolman-settings'],
queryFn: api.getSpoolmanSettings,
staleTime: 5 * 60 * 1000,
});
if (spoolmanSettings?.spoolman_enabled === 'true' && spoolmanSettings?.spoolman_url) {
return (
<iframe
src={spoolmanSettings.spoolman_url}
className="h-full w-full border-0"
title="Spoolman"
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"
/>
);
}
return <InventoryPage />;
}
function InventoryPage() {
const { t } = useTranslation();
const queryClient = useQueryClient();
const { showToast } = useToast();