Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 60 additions & 13 deletions scripts/dev-portal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,44 @@ <h2>No stacks running</h2>
}

// All envs for the same worktree appear in a single card.
const groups = [...groupByWorktree(stacks).values()];
const groups = groupByWorktree(stacks);
const dupNames = duplicateNames(
groups.map(group => cardHeader(group).worktree),
[...groups.values()].map(group => cardHeader(group).worktree),
);

return `<div class="stacks">${groups.map(group => renderWorktreeCard(group, dupNames)).join('')}</div>`;
return `<div class="stacks">${[...groups.entries()].map(([key, group]) => renderWorktreeCard(key, group, dupNames)).join('')}</div>`;
}

// Collapsed live cards, keyed like groupByWorktree. Persisted so the
// choice survives reloads; cards are expanded by default.
const COLLAPSED_STORAGE_KEY = 'hdx-dev-portal-collapsed';
const collapsedStacks = new Set(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — A malformed stored value throws at top level and stops the whole portal script

new Set(JSON.parse(...)) runs at script load. If the stored value isn't valid JSON or isn't an array (e.g. {}), it throws and everything after it in the script never runs: refresh(), the interval, the toggles. Wrap the read in try/catch and fall back to [] when Array.isArray fails.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

JSON.parse(localStorage.getItem(COLLAPSED_STORAGE_KEY) || '[]'),
);

function onStackHeaderClick(event, header) {
if (event.target.closest('a')) return;
const card = header.closest('.stack-card');
const key = card.dataset.key;
const collapsed = !collapsedStacks.has(key);
if (collapsed) collapsedStacks.add(key);
else collapsedStacks.delete(key);
localStorage.setItem(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Collapsed keys are never pruned, so removed worktrees stay collapsed

Entries are only removed when a user expands a card, so old worktree paths stay in localStorage for good. If someone collapses a card, tears down that worktree, and later recreates one at the same path, its card comes back already collapsed. When rendering, prune collapsedStacks down to the keys present in groupByWorktree(stacks), but skip pruning when the list is empty so a brief stack-less refresh doesn't wipe it.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

COLLAPSED_STORAGE_KEY,
JSON.stringify([...collapsedStacks]),
);
card.classList.toggle('collapsed', collapsed);
card.querySelector('.services-table').hidden = collapsed;
card
.querySelector('.stack-toggle')
.setAttribute('aria-expanded', String(!collapsed));
}

function slotLabel(stacks) {
const slots = [...new Set(stacks.map(s => s.slot))].sort(
(a, b) => a - b,
);
return `${slots.length > 1 ? 'Slots' : 'Slot'} ${slots.join(', ')}`;
}

// Group by full path so checkouts that share a folder name (a/hyperdx,
Expand Down Expand Up @@ -487,8 +519,9 @@ <h2>No stacks running</h2>
return stacks.find(s => s.envType === 'dev') || stacks[0];
}

function renderWorktreeCard(stacks, dupNames) {
function renderWorktreeCard(key, stacks, dupNames) {
const header = cardHeader(stacks);
const collapsed = collapsedStacks.has(key);
const worktreePath =
(stacks.find(s => s.worktreePath) || {}).worktreePath || '';
const devStack = stacks.find(s => s.envType === 'dev');
Expand Down Expand Up @@ -528,20 +561,24 @@ <h2>No stacks running</h2>
}

return `
<div class="stack-card">
<div class="stack-header">
<div>
<div style="display:flex;align-items:center">
<span class="branch">${escapeHtml(header.branch)}</span>
</div>
<div class="worktree" title="${escapeHtml(worktreePath)}">${escapeHtml(worktreeLabel(header.worktree, worktreePath, dupNames))}</div>
</div>
<div class="stack-card${collapsed ? ' collapsed' : ''}" data-key="${escapeHtml(key)}">
<div class="stack-header stack-header-toggle" onclick="onStackHeaderClick(event, this)">
<button type="button" class="stack-toggle" aria-expanded="${!collapsed}">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Branch and worktree text can no longer be selected or copied

The branch name and worktree path were a plain <div>. Now they sit inside a <button> within a header that toggles on click. Browsers don't let you drag-select text inside a button, and double-clicking the branch name to select it toggles the card twice. Put only the chevron (with an aria-label) in the toggle button, or keep the title text outside it and stop toggling when getSelection() is non-empty.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

<svg class="chevron" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg>
<span class="stack-title">
<span class="stack-title-row">
<span class="branch">${escapeHtml(header.branch)}</span>
<span class="slot-badge">${slotLabel(stacks)}</span>
</span>
<span class="worktree" title="${escapeHtml(worktreePath)}">${escapeHtml(worktreeLabel(header.worktree, worktreePath, dupNames))}</span>
</span>
</button>
<div class="stack-actions">
${chUrl ? `<a href="${chUrl}" target="_blank" class="open-btn open-btn-secondary">Open ClickHouse</a>` : ''}
${appUrl ? `<a href="${appUrl}" target="_blank" class="open-btn">Open App</a>` : ''}
</div>
</div>
<table class="services-table">
<table class="services-table"${collapsed ? ' hidden' : ''}>
<thead>
<tr>
<th>Service</th>
Expand Down Expand Up @@ -917,7 +954,17 @@ <h2>Past Runs</h2>
const res = await fetch('/api/stacks');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const stacks = await res.json();
// Re-rendering replaces the toggle buttons, so restore keyboard focus.
const focusedKey = document.activeElement?.matches('.stack-toggle')
? document.activeElement.closest('.stack-card').dataset.key
: null;
contentEl.innerHTML = renderStacks(stacks);
if (focusedKey !== null) {
[...contentEl.querySelectorAll('.stack-card')]
.find(card => card.dataset.key === focusedKey)
?.querySelector('.stack-toggle')
.focus();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 P2 — Restoring focus every 3s scrolls the page back to the toggle

.focus() scrolls the element into view by default. Say a user clicks a card header (Chrome and Firefox give the button focus) and then scrolls down to another card or the log rows. The next auto-refresh will jump the page back to that toggle, and so will every one after it. Call .focus({ preventScroll: true }) instead.

Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond

}
errorEl.style.display = 'none';
} catch (err) {
errorEl.textContent = `Failed to fetch stacks: ${err.message}`;
Expand Down
84 changes: 82 additions & 2 deletions scripts/dev-portal/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial,
sans-serif;
font-family:
-apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
background: var(--bg);
color: var(--text);
min-height: 100vh;
Expand Down Expand Up @@ -321,6 +321,86 @@ body {
.stack-header .stack-actions {
display: flex;
gap: 8px;
flex-shrink: 0;
}

.stack-header-toggle {
cursor: pointer;
gap: 16px;
transition: background 0.1s;
}

.stack-header-toggle:hover {
background: var(--row-hover);
}

.stack-card.collapsed .stack-header {
border-bottom: none;
}

.stack-toggle {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
padding: 0;
background: none;
border: none;
border-radius: 4px;
color: inherit;
font: inherit;
text-align: left;
cursor: pointer;
}

.stack-toggle:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 4px;
}

.stack-toggle .chevron {
width: 16px;
height: 16px;
flex-shrink: 0;
color: var(--text-muted);
}

.stack-card.collapsed .stack-toggle .chevron {
rotate: -90deg;
}

@media (prefers-reduced-motion: no-preference) {
.stack-toggle .chevron {
transition: rotate 0.15s;
}
}

.stack-title {
display: block;
min-width: 0;
}

.stack-title-row {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}

.stack-header .worktree {
display: block;
}

.slot-badge {
flex-shrink: 0;
font-size: 11px;
font-weight: 600;
font-family: 'SF Mono', 'Fira Code', monospace;
color: var(--text-muted);
background: var(--card-surface);
border: 1px solid var(--border);
padding: 1px 6px;
border-radius: 4px;
}

.stack-header .open-btn {
Expand Down
Loading