feat: hide header View link in standalone mode

The "View" link opens the read-only live view of the canvas. In frontend-only
standalone mode the editor already renders the only (localStorage) copy, so the
live view adds nothing — hide the link. Kept in full mode.

ha-relevant: no
This commit is contained in:
Pouzor
2026-06-30 00:48:56 +02:00
parent 79cac7d80f
commit d1c052c9e8
2 changed files with 39 additions and 4 deletions
+9 -3
View File
@@ -4,6 +4,8 @@ import { Button } from '@/components/ui/button'
import { Logo } from '@/components/ui/Logo'
import { useCanvasStore } from '@/stores/canvasStore'
const STANDALONE = import.meta.env.VITE_STANDALONE === 'true'
interface ToolbarProps {
onSave: () => void
onAutoLayout: () => void
@@ -82,9 +84,13 @@ export function Toolbar({ onSave, onAutoLayout, onExport, onChangeStyle, onUndo,
<Button size="sm" variant="ghost" className="gap-1.5 text-muted-foreground hover:text-foreground cursor-pointer hover:bg-[#21262d]" onClick={onExportMd} title="Copy inventory as Markdown table">
<Table2 size={14} /> MD
</Button>
<Button size="sm" variant="ghost" className="gap-1.5 text-muted-foreground hover:text-foreground cursor-pointer hover:bg-[#21262d]" onClick={onViewOnly} title="Open read-only live view of this canvas">
<Eye size={14} /> View
</Button>
{/* Live view reads backend/localStorage canvas; pointless in standalone
where the editor already shows the only (localStorage) copy. */}
{!STANDALONE && (
<Button size="sm" variant="ghost" className="gap-1.5 text-muted-foreground hover:text-foreground cursor-pointer hover:bg-[#21262d]" onClick={onViewOnly} title="Open read-only live view of this canvas">
<Eye size={14} /> View
</Button>
)}
<Button size="sm" variant="ghost" className="gap-1.5 text-muted-foreground hover:text-foreground cursor-pointer hover:bg-[#21262d]" onClick={onShortcuts} title="Keyboard shortcuts (?)">
<HelpCircle size={14} />
</Button>
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { Toolbar } from '../Toolbar'
import { useCanvasStore } from '@/stores/canvasStore'
@@ -56,4 +56,33 @@ describe('Toolbar', () => {
fireEvent.click(screen.getByText('Save'))
expect(defaultProps.onSave).toHaveBeenCalledWith()
})
it('shows the View (live view) link in full mode', () => {
render(<Toolbar {...defaultProps} />)
expect(screen.getByText('View')).toBeInTheDocument()
})
})
// ── Standalone mode ────────────────────────────────────────────────────────────
// VITE_STANDALONE is read at module load, so re-import Toolbar after stubbing it.
describe('Toolbar (standalone)', () => {
afterEach(() => {
vi.unstubAllEnvs()
})
it('hides the View link (live view is pointless without a backend)', async () => {
vi.stubEnv('VITE_STANDALONE', 'true')
vi.resetModules()
const { useCanvasStore: cs } = await import('@/stores/canvasStore')
vi.mocked(cs).mockReturnValue({
hasUnsavedChanges: false, past: [], future: [],
} as ReturnType<typeof useCanvasStore>)
const { Toolbar: TB } = await import('../Toolbar')
render(<TB {...defaultProps} />)
expect(screen.queryByText('View')).not.toBeInTheDocument()
// Other actions remain.
expect(screen.getByText('Save')).toBeInTheDocument()
expect(screen.getByText('MD')).toBeInTheDocument()
})
})