From b5e53740668ec7e49e4fbb61dc8c4f05cd12030d Mon Sep 17 00:00:00 2001 From: Brendan Date: Thu, 17 Sep 2026 06:24:27 +0000 Subject: [PATCH] Fix job agent runs pagination state --- packages/app/src/ui.ts | 3 ++- packages/app/test/ui.test.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/app/src/ui.ts b/packages/app/src/ui.ts index 833b1225..3f1e9f8d 100644 --- a/packages/app/src/ui.ts +++ b/packages/app/src/ui.ts @@ -51,10 +51,11 @@ const $=s=>document.querySelector(s),esc=v=>String(v??'').replace(/[&<>"']/g,c=> ${ansiToHtmlBrowserSource} const request=async(url,options)=>{const requestUrl=String(url).startsWith('/api/v1/runs?jobId=')&&!String(url).includes('limit=')?String(url)+'&limit=20':url,r=await fetch(requestUrl,options),body=await r.json().catch(()=>({}));if(r.status===401){location.href='/auth/linear';throw new Error('Unauthorized')}if(!r.ok)throw new Error(body.error?.message||body.error||'Request failed');if(String(requestUrl).startsWith('/api/v1/runs?jobId='))window.__factorizeLastRuns=body;return body}; const jobRunsPageSize=20,jobRunsState={page:1,cursors:[null],runs:null,loading:false}; +// The initial page is rendered by load(); navigation owns subsequent responses. const jobRunsMarkup=r=>r.items?.length?'':'

No runs yet.

'; const jobRunsControls=(r,page)=>{if(page===1&&!r.nextCursor)return'';const previous=page>1?'':' disabled aria-disabled="true"',next=r.nextCursor?'':' disabled aria-disabled="true"';return''}; const refreshJobRunsPagination=()=>{const section=document.querySelector('[data-job-runs-section]')||document.querySelector('#job-detail section:last-of-type'),r=jobRunsState.runs;if(!section||!r)return;section.querySelectorAll('[data-job-runs-pagination]').forEach(x=>x.remove());const list=section.querySelector('[data-job-runs-list]')||section.querySelector('ul,section>p');if(list)list.outerHTML=jobRunsMarkup(r);const header=section.firstElementChild;header?.insertAdjacentHTML('afterend',jobRunsControls(r,jobRunsState.page));section.insertAdjacentHTML('beforeend',jobRunsControls(r,jobRunsState.page));section.querySelectorAll('[data-run-page]').forEach(button=>button.addEventListener('click',async()=>{if(jobRunsState.loading)return;const direction=button.dataset.runPage,currentPage=jobRunsState.page,targetPage=direction==='next'?currentPage+1:currentPage-1;if(targetPage<1||targetPage>currentPage+1)return;const cursor=targetPage===currentPage+1?r.nextCursor:jobRunsState.cursors[targetPage];if(direction==='next'&&!cursor)return;jobRunsState.loading=true;try{const query='/api/v1/runs?jobId='+encodeURIComponent(document.querySelector('#job-detail').dataset.id)+'&limit='+jobRunsPageSize+(cursor?'&cursor='+encodeURIComponent(cursor):'');const nextRuns=await request(query);jobRunsState.cursors[targetPage]=cursor;jobRunsState.page=targetPage;jobRunsState.runs=nextRuns;refreshJobRunsPagination()}finally{jobRunsState.loading=false}}))}; -const jobDetailRoot=document.querySelector('#job-detail');if(jobDetailRoot)new MutationObserver(()=>{const r=window.__factorizeLastRuns;if(r&&r!==jobRunsState.runs){jobRunsState.runs=r;refreshJobRunsPagination()}}).observe(jobDetailRoot,{childList:true}); +const jobDetailRoot=document.querySelector('#job-detail');if(jobDetailRoot)new MutationObserver(()=>{const r=window.__factorizeLastRuns;if(r&&jobRunsState.runs===null){jobRunsState.runs=r;refreshJobRunsPagination()}}).observe(jobDetailRoot,{childList:true}); const pairs=v=>Object.entries(v||{}).map(([k,x])=>k+'='+x).join('\\n'); const record=v=>Object.fromEntries(String(v||'').split(/\\n/).map(x=>x.trim()).filter(Boolean).map(x=>{const i=x.indexOf('=');if(i<1)throw new Error('Parameters must use name=value, one per line.');return[x.slice(0,i).trim(),x.slice(i+1)]})); const stateTone=v=>({queued:'bg-amber-100 text-amber-800 dark:bg-amber-950 dark:text-amber-200',starting:'bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200',running:'bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200',recovering:'bg-violet-100 text-violet-800 dark:bg-violet-950 dark:text-violet-200',blocked:'bg-orange-100 text-orange-800 dark:bg-orange-950 dark:text-orange-200',stopping:'bg-amber-100 text-amber-800 dark:bg-amber-950 dark:text-amber-200',succeeded:'bg-green-100 text-green-800 dark:bg-green-950 dark:text-green-200',done:'bg-green-100 text-green-800 dark:bg-green-950 dark:text-green-200',failed:'bg-red-100 text-red-800 dark:bg-red-950 dark:text-red-200',stopped:'bg-stone-200 text-slate-700 dark:bg-slate-700 dark:text-slate-200',canceled:'bg-stone-200 text-slate-700 dark:bg-slate-700 dark:text-slate-200',cancelled:'bg-stone-200 text-slate-700 dark:bg-slate-700 dark:text-slate-200'})[v]||'bg-stone-100 text-slate-700 dark:bg-slate-800 dark:text-slate-200'; diff --git a/packages/app/test/ui.test.ts b/packages/app/test/ui.test.ts index 2f92b671..6f66b0f6 100644 --- a/packages/app/test/ui.test.ts +++ b/packages/app/test/ui.test.ts @@ -38,6 +38,8 @@ describe("pages", () => { expect(html).toContain("jobRunsState.cursors[targetPage]=cursor"); expect(html).toContain("const cursor=targetPage===currentPage+1?r.nextCursor:jobRunsState.cursors[targetPage]"); expect(html).not.toContain("jobRunsState.cursors[jobRunsState.page]=r.nextCursor"); + expect(html).toContain("targetPage===currentPage+1?r.nextCursor:jobRunsState.cursors[targetPage]"); + expect(html).toContain("jobRunsState.runs===null"); expectInlineScriptsToParse(html); });