Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

fix(docs): stop the tree clipping the last letter of every name

Pouzord0f0fe032274
diff --git a/frontend/src/documentation/__tests__/DocTree.test.tsx b/frontend/src/documentation/__tests__/DocTree.test.tsx
new file mode 100644
index 0000000..46cbba9
--- /dev/null
+++ b/frontend/src/documentation/__tests__/DocTree.test.tsx
@@ -0,0 +1,84 @@
+/**
+ * The navigator's rows.
+ *
+ * A device with no document yet is drawn in italic, and italic glyphs lean past
+ * the advance width the label's box shrink-wraps to — so `truncate`'s
+ * `overflow: hidden` sliced the tail off every such name. The padding that fixes
+ * it is invisible to a test, but the `title` that goes with it is not, and it is
+ * what makes a genuinely over-long name readable at all.
+ */
+import { render, screen } from '@testing-library/react'
+import { describe, expect, it, vi } from 'vitest'
+
+import { DocTreeGroups } from '../components/DocTree'
+import type { TreeGroup, TreeLeaf } from '../types'
+
+function leaf(overrides: Partial<TreeLeaf> = {}): TreeLeaf {
+ return {
+ id: 'dev-1',
+ label: 'bazarr',
+ kind: 'device',
+ docId: null,
+ state: 'none',
+ ...overrides,
+ }
+}
+
+function renderTree(groups: TreeGroup[], expanded: string[] = []) {
+ render(
+ <DocTreeGroups
+ groups={groups}
+ activeId={null}
+ expanded={expanded}
+ starred={new Set()}
+ onSelect={vi.fn()}
+ onToggle={vi.fn()}
+ />,
+ )
+}
+
+const group = (items: TreeLeaf[], label = 'Network topology'): TreeGroup => ({
+ key: 'zone:network-topology',
+ label,
+ items,
+})
+
+describe('DocTree', () => {
+ it('renders a device label in full', () => {
+ renderTree([group([leaf()])])
+ expect(screen.getByText('bazarr')).toBeInTheDocument()
+ })
+
+ it('carries the full name as a title, so a clipped one stays readable', () => {
+ renderTree([group([leaf({ label: 'suwayomiserver-backend-01' })])])
+ expect(screen.getByText('suwayomiserver-backend-01')).toHaveAttribute(
+ 'title',
+ 'suwayomiserver-backend-01',
+ )
+ })
+
+ it('gives the group header the same treatment', () => {
+ renderTree([group([leaf()], 'Not on this canvas')])
+ expect(screen.getByText('Not on this canvas')).toHaveAttribute('title', 'Not on this canvas')
+ })
+
+ it('italicises only a device that has no document yet', () => {
+ renderTree([
+ group([
+ leaf({ id: 'a', label: 'undocumented', docId: null, state: 'none' }),
+ leaf({ id: 'b', label: 'documented', docId: 'doc-1', state: 'written' }),
+ ]),
+ ])
+ expect(screen.getByText('undocumented').closest('button')).toHaveClass('italic')
+ expect(screen.getByText('documented').closest('button')).not.toHaveClass('italic')
+ })
+
+ it('keeps the label clipped rather than letting a long name push the row wide', () => {
+ renderTree([group([leaf({ label: 'a-very-long-device-name-that-will-not-fit' })])])
+ // The padding is what stops `overflow: hidden` cutting into the last glyph.
+ expect(screen.getByText('a-very-long-device-name-that-will-not-fit')).toHaveClass(
+ 'truncate',
+ 'pr-0.5',
+ )
+ })
+})
diff --git a/frontend/src/documentation/components/DocTree.tsx b/frontend/src/documentation/components/DocTree.tsx
index 468f6e2..98e17e8 100644
--- a/frontend/src/documentation/components/DocTree.tsx
+++ b/frontend/src/documentation/components/DocTree.tsx
@@ -74,7 +74,14 @@ export function DocTreeItem({ leaf, depth, activeId, expanded, starred, onSelect
<span className="w-3 shrink-0" />
)}
<Icon size={13} className="shrink-0 opacity-70" />
- <span className="truncate">{leaf.label}</span>
+ {/* `truncate` hides overflow at the content edge, and this box shrink-wraps
+ to the text — so its edge is the advance width, which italic glyphs
+ lean past. An undocumented device is italic, and lost the tail of its
+ last letter. The padding gives that overhang somewhere to live;
+ `title` makes a name that really is too long readable on hover. */}
+ <span title={leaf.label} className="truncate pr-0.5">
+ {leaf.label}
+ </span>
{leaf.docId && starred.has(leaf.docId) && (
<Star size={11} className="shrink-0 fill-current text-[var(--accent-orange,#ff6e00)]" />
)}
@@ -128,7 +135,9 @@ export function DocTreeGroups({ groups, activeId, expanded, starred, onSelect, o
className="sticky top-0 z-10 flex w-full cursor-pointer items-center gap-1 bg-background/95 px-2 py-1 text-left text-[10px] font-semibold uppercase tracking-wide text-muted-foreground/70 backdrop-blur"
>
{collapsed ? <ChevronRight size={10} /> : <ChevronDown size={10} />}
- <span className="truncate">{group.label}</span>
+ <span title={group.label} className="truncate pr-0.5">
+ {group.label}
+ </span>
<span className="ml-auto tabular-nums opacity-60">{group.items.length}</span>
</button>
{!collapsed &&