Repository navigation
chore(dev-portal): make stack cards collapsible and show slot number #3827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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( | ||
| 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( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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, | ||
|
|
@@ -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'); | ||
|
|
@@ -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}"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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> | ||
|
|
@@ -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(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — Restoring focus every 3s scrolls the page back to the toggle
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}`; | ||
|
|
||
There was a problem hiding this comment.
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[]whenArray.isArrayfails.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