Show independent loading progress for diff and comments
Browse files- patch_view.html +17 -9
- patch_view.js +25 -1
patch_view.html
CHANGED
|
@@ -30,6 +30,7 @@ header{display:flex;gap:12px;align-items:center;flex-wrap:wrap}#source{font-weig
|
|
| 30 |
.comment-thread{border:1px solid var(--border);border-radius:4px;margin-bottom:12px;background:var(--bg)}.comment-thread>summary{padding:9px 10px;font-weight:600;font-size:12px;cursor:pointer;background:var(--card)}.comment-thread .comment-card{border:0;border-top:1px solid var(--border);border-radius:0;margin:0}.comment-thread .comment-reply{border-left:2px solid var(--border);margin-left:10px}.thread-filter-note{font-size:10px;color:var(--muted);margin:8px 0 0}.comment-context-label{font-size:10px;color:var(--muted);margin-top:4px}
|
| 31 |
.comment-meta{display:flex;align-items:baseline;gap:8px;justify-content:space-between;flex-wrap:wrap}.comment-author{font-weight:600}.comment-time{font-size:10px;color:var(--muted)}.comment-kind{font-size:10px;color:var(--muted);margin-top:4px}.comment-location{font:11px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;overflow-wrap:anywhere;margin:8px 0;color:var(--link)}.comment-body{white-space:pre-wrap;overflow-wrap:anywhere;font-size:12px;margin:8px 0;max-height:300px;overflow:auto}.comment-link{font-size:11px}
|
| 32 |
@media(max-width:850px){.layout{grid-template-columns:minmax(0,1fr)}.comments-sidebar{position:static;max-height:600px}}
|
|
|
|
| 33 |
</style></head><body>
|
| 34 |
<header><a id="source" target="_blank" rel="noopener"></a><button id="reload">Refresh</button><button id="collapse">Collapse all</button></header>
|
| 35 |
<div class="file-filters" role="group" aria-label="Filter changed files">
|
|
@@ -41,7 +42,7 @@ header{display:flex;gap:12px;align-items:center;flex-wrap:wrap}#source{font-weig
|
|
| 41 |
<label class="filter-check"><input type="checkbox" id="hide-module-headers" checked>Hide module headers</label>
|
| 42 |
</div>
|
| 43 |
<main class="layout">
|
| 44 |
-
<section class="diff-column" aria-label="Unified diff"><div id="message" role="status">Loading diff…</div><div id="patch-view"></div></section>
|
| 45 |
<aside class="comments-sidebar" aria-label="PR comments">
|
| 46 |
<div class="comments-heading"><h2>Comments <span id="comment-count"></span></h2>
|
| 47 |
<div class="comment-filters" role="group" aria-label="Filter comments">
|
|
@@ -54,7 +55,7 @@ header{display:flex;gap:12px;align-items:center;flex-wrap:wrap}#source{font-weig
|
|
| 54 |
<p class="thread-filter-note">Filters select threads. Replies stay visible for context.</p>
|
| 55 |
<button id="add-comment" type="button">Add comment</button>
|
| 56 |
</div>
|
| 57 |
-
<div id="comments-status" class="comments-status" role="status">Loading comments…</div><div id="comments-list"></div>
|
| 58 |
</aside>
|
| 59 |
</main>
|
| 60 |
<button id="back-to-top" class="back-to-top" aria-label="Back to top">↑ Back to top</button>
|
|
@@ -81,6 +82,8 @@ header{display:flex;gap:12px;align-items:center;flex-wrap:wrap}#source{font-weig
|
|
| 81 |
if (params.get('theme') === 'light' || (parent.grafanaBootData && parent.grafanaBootData.user.lightTheme)) document.documentElement.classList.add('light');
|
| 82 |
} catch (_) {}
|
| 83 |
const source = document.getElementById('source'), message = document.getElementById('message'), reload = document.getElementById('reload');
|
|
|
|
|
|
|
| 84 |
let currentPatch = '';
|
| 85 |
const hideTests = document.getElementById('hide-tests'), onlyPython = document.getElementById('only-python'), hideBots = document.getElementById('hide-bots'), onlyModels = document.getElementById('only-models'), hideResolved = document.getElementById('hide-resolved'), hideGenerated = document.getElementById('hide-generated'), hideCommands = document.getElementById('hide-commands'), maintainersOnly = document.getElementById('maintainers-only'), hideCommentLines = document.getElementById('hide-comment-lines'), hideModuleHeaders = document.getElementById('hide-module-headers');
|
| 86 |
function renderDiff() {
|
|
@@ -97,17 +100,19 @@ header{display:flex;gap:12px;align-items:center;flex-wrap:wrap}#source{font-weig
|
|
| 97 |
if (/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository) && /^[1-9][0-9]*$/.test(pr)) source.href = 'https://github.com/' + repository + '/pull/' + pr + '/files';
|
| 98 |
async function loadDiff() {
|
| 99 |
currentPatch = '';
|
|
|
|
| 100 |
message.hidden = false; message.className = ''; message.textContent = 'Loading diff…';
|
| 101 |
document.getElementById('patch-view').replaceChildren();
|
| 102 |
try {
|
| 103 |
-
const
|
| 104 |
-
const text = await r.text();
|
| 105 |
-
if (!r.ok) throw Error(text);
|
| 106 |
if (!text.trim()) { message.textContent = 'This PR has no changes.'; return; }
|
|
|
|
|
|
|
| 107 |
currentPatch = text; renderDiff();
|
| 108 |
message.hidden = true;
|
| 109 |
document.getElementById('collapse').textContent = 'Collapse all';
|
| 110 |
} catch (e) { message.className = 'error'; message.textContent = e.message; }
|
|
|
|
| 111 |
}
|
| 112 |
let comments = [], demoComments = [], filter = 'review';
|
| 113 |
let nextDemoId = -1, composerTarget = null;
|
|
@@ -248,18 +253,21 @@ header{display:flex;gap:12px;align-items:center;flex-wrap:wrap}#source{font-weig
|
|
| 248 |
hideCommands.onchange = renderComments;
|
| 249 |
maintainersOnly.onchange = renderComments;
|
| 250 |
async function loadComments() {
|
|
|
|
| 251 |
commentStatus.hidden = false; commentStatus.className = 'comments-status'; commentStatus.textContent = 'Loading comments…'; commentList.replaceChildren();
|
| 252 |
try {
|
| 253 |
-
const
|
| 254 |
-
|
| 255 |
-
|
|
|
|
| 256 |
hideResolved.disabled = !data.resolution_available;
|
| 257 |
hideResolved.title = data.resolution_available ? '' : 'GitHub review-thread status is unavailable.';
|
| 258 |
if (hideResolved.disabled) hideResolved.checked = false;
|
| 259 |
commentStatus.hidden = !data.truncated;
|
| 260 |
commentStatus.textContent = 'Showing the first 500 entries in each category. View the full conversation on GitHub.';
|
| 261 |
renderComments();
|
| 262 |
-
} catch(e) { comments = []; document.getElementById('comment-count').textContent = ''; commentStatus.className = 'comments-status error'; commentStatus.textContent = 'Could not load comments: ' + e.message; }
|
|
|
|
| 263 |
}
|
| 264 |
document.querySelectorAll('[data-filter]').forEach(button => { button.onclick = () => {
|
| 265 |
filter = button.dataset.filter;
|
|
|
|
| 30 |
.comment-thread{border:1px solid var(--border);border-radius:4px;margin-bottom:12px;background:var(--bg)}.comment-thread>summary{padding:9px 10px;font-weight:600;font-size:12px;cursor:pointer;background:var(--card)}.comment-thread .comment-card{border:0;border-top:1px solid var(--border);border-radius:0;margin:0}.comment-thread .comment-reply{border-left:2px solid var(--border);margin-left:10px}.thread-filter-note{font-size:10px;color:var(--muted);margin:8px 0 0}.comment-context-label{font-size:10px;color:var(--muted);margin-top:4px}
|
| 31 |
.comment-meta{display:flex;align-items:baseline;gap:8px;justify-content:space-between;flex-wrap:wrap}.comment-author{font-weight:600}.comment-time{font-size:10px;color:var(--muted)}.comment-kind{font-size:10px;color:var(--muted);margin-top:4px}.comment-location{font:11px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace;overflow-wrap:anywhere;margin:8px 0;color:var(--link)}.comment-body{white-space:pre-wrap;overflow-wrap:anywhere;font-size:12px;margin:8px 0;max-height:300px;overflow:auto}.comment-link{font-size:11px}
|
| 32 |
@media(max-width:850px){.layout{grid-template-columns:minmax(0,1fr)}.comments-sidebar{position:static;max-height:600px}}
|
| 33 |
+
.loading-progress{display:block;width:calc(100% - 24px);height:8px;margin:0 12px 12px;accent-color:var(--link)}.loading-progress[hidden]{display:none}
|
| 34 |
</style></head><body>
|
| 35 |
<header><a id="source" target="_blank" rel="noopener"></a><button id="reload">Refresh</button><button id="collapse">Collapse all</button></header>
|
| 36 |
<div class="file-filters" role="group" aria-label="Filter changed files">
|
|
|
|
| 42 |
<label class="filter-check"><input type="checkbox" id="hide-module-headers" checked>Hide module headers</label>
|
| 43 |
</div>
|
| 44 |
<main class="layout">
|
| 45 |
+
<section class="diff-column" aria-label="Unified diff"><div id="message" role="status">Loading diff…</div><progress id="diff-progress" class="loading-progress" aria-label="Loading diff"></progress><div id="patch-view"></div></section>
|
| 46 |
<aside class="comments-sidebar" aria-label="PR comments">
|
| 47 |
<div class="comments-heading"><h2>Comments <span id="comment-count"></span></h2>
|
| 48 |
<div class="comment-filters" role="group" aria-label="Filter comments">
|
|
|
|
| 55 |
<p class="thread-filter-note">Filters select threads. Replies stay visible for context.</p>
|
| 56 |
<button id="add-comment" type="button">Add comment</button>
|
| 57 |
</div>
|
| 58 |
+
<div id="comments-status" class="comments-status" role="status">Loading comments…</div><progress id="comments-progress" class="loading-progress" aria-label="Loading comments"></progress><div id="comments-list"></div>
|
| 59 |
</aside>
|
| 60 |
</main>
|
| 61 |
<button id="back-to-top" class="back-to-top" aria-label="Back to top">↑ Back to top</button>
|
|
|
|
| 82 |
if (params.get('theme') === 'light' || (parent.grafanaBootData && parent.grafanaBootData.user.lightTheme)) document.documentElement.classList.add('light');
|
| 83 |
} catch (_) {}
|
| 84 |
const source = document.getElementById('source'), message = document.getElementById('message'), reload = document.getElementById('reload');
|
| 85 |
+
const diffProgress = document.getElementById('diff-progress'), commentsProgress = document.getElementById('comments-progress');
|
| 86 |
+
const paintLoading = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
| 87 |
let currentPatch = '';
|
| 88 |
const hideTests = document.getElementById('hide-tests'), onlyPython = document.getElementById('only-python'), hideBots = document.getElementById('hide-bots'), onlyModels = document.getElementById('only-models'), hideResolved = document.getElementById('hide-resolved'), hideGenerated = document.getElementById('hide-generated'), hideCommands = document.getElementById('hide-commands'), maintainersOnly = document.getElementById('maintainers-only'), hideCommentLines = document.getElementById('hide-comment-lines'), hideModuleHeaders = document.getElementById('hide-module-headers');
|
| 89 |
function renderDiff() {
|
|
|
|
| 100 |
if (/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository) && /^[1-9][0-9]*$/.test(pr)) source.href = 'https://github.com/' + repository + '/pull/' + pr + '/files';
|
| 101 |
async function loadDiff() {
|
| 102 |
currentPatch = '';
|
| 103 |
+
diffProgress.hidden = false; diffProgress.removeAttribute('value');
|
| 104 |
message.hidden = false; message.className = ''; message.textContent = 'Loading diff…';
|
| 105 |
document.getElementById('patch-view').replaceChildren();
|
| 106 |
try {
|
| 107 |
+
const text = await TCIPatch.fetchText('/patch-view/data?' + new URLSearchParams({pr, repository}), diffProgress, message, 'diff');
|
|
|
|
|
|
|
| 108 |
if (!text.trim()) { message.textContent = 'This PR has no changes.'; return; }
|
| 109 |
+
message.textContent = 'Rendering diff…'; diffProgress.removeAttribute('value');
|
| 110 |
+
await paintLoading();
|
| 111 |
currentPatch = text; renderDiff();
|
| 112 |
message.hidden = true;
|
| 113 |
document.getElementById('collapse').textContent = 'Collapse all';
|
| 114 |
} catch (e) { message.className = 'error'; message.textContent = e.message; }
|
| 115 |
+
finally { diffProgress.hidden = true; }
|
| 116 |
}
|
| 117 |
let comments = [], demoComments = [], filter = 'review';
|
| 118 |
let nextDemoId = -1, composerTarget = null;
|
|
|
|
| 253 |
hideCommands.onchange = renderComments;
|
| 254 |
maintainersOnly.onchange = renderComments;
|
| 255 |
async function loadComments() {
|
| 256 |
+
commentsProgress.hidden = false; commentsProgress.removeAttribute('value');
|
| 257 |
commentStatus.hidden = false; commentStatus.className = 'comments-status'; commentStatus.textContent = 'Loading comments…'; commentList.replaceChildren();
|
| 258 |
try {
|
| 259 |
+
const text = await TCIPatch.fetchText('/patch-view/comments?' + new URLSearchParams({pr, repository}), commentsProgress, commentStatus, 'comments');
|
| 260 |
+
commentStatus.textContent = 'Preparing comments…'; commentsProgress.removeAttribute('value');
|
| 261 |
+
await paintLoading();
|
| 262 |
+
const data = JSON.parse(text); comments = [...data.comments, ...demoComments].sort((a, b) => (b.created_at || '').localeCompare(a.created_at || '') || b.id - a.id);
|
| 263 |
hideResolved.disabled = !data.resolution_available;
|
| 264 |
hideResolved.title = data.resolution_available ? '' : 'GitHub review-thread status is unavailable.';
|
| 265 |
if (hideResolved.disabled) hideResolved.checked = false;
|
| 266 |
commentStatus.hidden = !data.truncated;
|
| 267 |
commentStatus.textContent = 'Showing the first 500 entries in each category. View the full conversation on GitHub.';
|
| 268 |
renderComments();
|
| 269 |
+
} catch(e) { comments = []; document.getElementById('comment-count').textContent = ''; commentStatus.hidden = false; commentStatus.className = 'comments-status error'; commentStatus.textContent = 'Could not load comments: ' + e.message; }
|
| 270 |
+
finally { commentsProgress.hidden = true; }
|
| 271 |
}
|
| 272 |
document.querySelectorAll('[data-filter]').forEach(button => { button.onclick = () => {
|
| 273 |
filter = button.dataset.filter;
|
patch_view.js
CHANGED
|
@@ -174,5 +174,29 @@
|
|
| 174 |
rows[0].tabIndex = -1; rows[0].focus({preventScroll:true}); rows[0].scrollIntoView({behavior:'smooth', block:'center', inline:'nearest'});
|
| 175 |
return true;
|
| 176 |
}
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
})();
|
|
|
|
| 174 |
rows[0].tabIndex = -1; rows[0].focus({preventScroll:true}); rows[0].scrollIntoView({behavior:'smooth', block:'center', inline:'nearest'});
|
| 175 |
return true;
|
| 176 |
}
|
| 177 |
+
async function fetchText(url, progress, status, label) {
|
| 178 |
+
const response = await fetch(url, {cache:'no-store'});
|
| 179 |
+
if (!response.ok) throw Error(await response.text());
|
| 180 |
+
if (!response.body) return response.text();
|
| 181 |
+
// Fetch streams decoded bytes; compressed Content-Length is not comparable.
|
| 182 |
+
const length = response.headers.get('Content-Encoding') ? 0 : Number(response.headers.get('Content-Length'));
|
| 183 |
+
const total = Number.isFinite(length) && length > 0 ? length : 0;
|
| 184 |
+
const reader = response.body.getReader(), decoder = new TextDecoder(), chunks = [];
|
| 185 |
+
let loaded = 0, lastUpdate = 0;
|
| 186 |
+
while (true) {
|
| 187 |
+
const {done, value} = await reader.read();
|
| 188 |
+
if (done) break;
|
| 189 |
+
loaded += value.byteLength;
|
| 190 |
+
chunks.push(decoder.decode(value, {stream:true}));
|
| 191 |
+
if (total) { progress.max = total; progress.value = Math.min(loaded, total); }
|
| 192 |
+
if (performance.now() - lastUpdate > 200) {
|
| 193 |
+
status.textContent = 'Loading ' + label + '… ' + (total ? Math.min(100, Math.floor(loaded / total * 100)) + '%' : Math.ceil(loaded / 1024).toLocaleString() + ' KB');
|
| 194 |
+
lastUpdate = performance.now();
|
| 195 |
+
}
|
| 196 |
+
}
|
| 197 |
+
chunks.push(decoder.decode());
|
| 198 |
+
return chunks.join('');
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
globalThis.TCIPatch = {parse, render, isTestFile, isGeneratedFile, showLines, isCommentLine, moduleHeaderRows, fetchText};
|
| 202 |
})();
|