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
2 changes: 1 addition & 1 deletion packages/app/public/styles.css

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions packages/app/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const landingPage = (viewer: Viewer) => shell("Factorize: Software Factor
</section>
</div></main>`);

const dashboardHead = (title: string, description: string, action = "") => `<div class="flex flex-wrap items-end justify-between gap-4"><div><h1 class="text-3xl font-bold tracking-tight">${title}</h1>${description ? `<p class="mt-2 text-slate-600 dark:text-slate-400">${description}</p>` : ""}</div>${action}</div>`;
const dashboardHead = (title: string, description: string, action = "") => `<div class="flex flex-col items-stretch gap-3 sm:flex-row sm:items-end sm:justify-between sm:gap-4"><div class="min-w-0"><h1 class="text-3xl font-bold tracking-tight">${title}</h1>${description ? `<p class="mt-2 text-slate-600 dark:text-slate-400">${description}</p>` : ""}</div>${action}</div>`;
const card = "rounded-2xl border border-stone-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900";
const uiHelpers = `
const $=s=>document.querySelector(s),esc=v=>String(v??'').replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
Expand All @@ -63,12 +63,12 @@ const triggerBadge=t=>{const labels={manual:'Manual only',schedule:'Scheduled',w
const jobStatus=j=>j.runningCount>0?{label:'Running',classes:'bg-blue-500 ring-blue-200 dark:ring-blue-900'}:{label:'Idle',classes:'bg-stone-300 ring-stone-200 dark:bg-slate-600 dark:ring-slate-800'};
`;

export const jobsPage = (viewer: { email: string }) => shell("Jobs — Factorize", viewer, `<main class="mx-auto max-w-6xl px-5 py-12 lg:px-8">
${dashboardHead("Jobs", "", '<a href="/jobs/new" class="rounded-xl bg-slate-950 px-5 py-3 text-sm font-semibold text-white dark:bg-white dark:text-slate-950">Create job</a>')}
<section id="jobs" class="${card} mt-8 overflow-hidden"><p class="p-8 text-sm text-slate-500">Loading jobs…</p></section></main>`, `${uiHelpers}
async function load(){const jobs=await request('/api/v1/jobs');const root=$('#jobs');if(!jobs.length){root.innerHTML='<div class="p-10 text-center"><h2 class="font-semibold">No jobs yet</h2><p class="mt-2 text-sm text-slate-500">Create a manual-only or automatically triggered job.</p></div>';return}root.innerHTML='<ul class="divide-y divide-stone-200 dark:divide-slate-800">'+jobs.map(j=>{const status=jobStatus(j);return '<li class="flex items-center gap-4 p-6"><span class="h-5 w-5 shrink-0 rounded-full ring-4 '+status.classes+'" role="img" aria-label="'+status.label+'" title="'+status.label+'"></span><div class="min-w-0"><div class="flex items-center gap-3"><a class="truncate font-semibold hover:text-factorize-700" href="/jobs/'+encodeURIComponent(j.id)+'">'+esc(j.name)+'</a>'+(j.enabled?'':'<span class="text-xs font-semibold text-slate-500">Disabled</span>')+'</div><p class="mt-2 text-sm text-slate-500"><span class="font-medium text-slate-700 dark:text-slate-300">'+esc(j.runningCount)+'/'+esc(j.concurrencyLimit)+' Running</span></p></div></li>'}).join('')+'</ul>'}load().catch(e=>$('#jobs').innerHTML='<p class="p-6 text-red-700">'+esc(e.message)+'</p>');`);
export const jobsPage = (viewer: { email: string }) => shell("Jobs — Factorize", viewer, `<main class="mx-auto max-w-6xl px-4 py-8 sm:px-5 sm:py-12 lg:px-8">
${dashboardHead("Jobs", "", '<a href="/jobs/new" class="inline-flex w-full justify-center rounded-xl bg-slate-950 px-4 py-2.5 text-sm font-semibold text-white dark:bg-white dark:text-slate-950 sm:w-auto sm:px-5 sm:py-3">Create job</a>')}
<section id="jobs" class="${card} mt-6 overflow-hidden sm:mt-8"><p class="p-6 text-sm text-slate-500 sm:p-8">Loading jobs…</p></section></main>`, `${uiHelpers}
async function load(){const jobs=await request('/api/v1/jobs');const root=$('#jobs');if(!jobs.length){root.innerHTML='<div class="p-8 text-center sm:p-10"><h2 class="font-semibold">No jobs yet</h2><p class="mt-2 text-sm text-slate-500">Create a manual-only or automatically triggered job.</p></div>';return}root.innerHTML='<ul class="divide-y divide-stone-200 dark:divide-slate-800">'+jobs.map(j=>{const status=jobStatus(j);return '<li class="flex min-w-0 items-center gap-3 px-4 py-4 sm:gap-4 sm:p-6"><span class="h-3 w-3 shrink-0 rounded-full ring-2 '+status.classes+'" role="img" aria-label="'+status.label+'" title="'+status.label+'"></span><div class="min-w-0"><div class="flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1"><a class="break-words font-semibold hover:text-factorize-700" href="/jobs/'+encodeURIComponent(j.id)+'">'+esc(j.name)+'</a>'+(j.enabled?'':'<span class="text-xs font-semibold text-slate-500">Disabled</span>')+'</div><p class="mt-1 text-xs text-slate-500 sm:mt-2 sm:text-sm"><span class="font-medium text-slate-700 dark:text-slate-300">'+esc(j.runningCount)+'/'+esc(j.concurrencyLimit)+' Running</span></p></div></li>'}).join('')+'</ul>'}load().catch(e=>$('#jobs').innerHTML='<p class="p-6 text-red-700">'+esc(e.message)+'</p>');`);

export const jobPage = (viewer: { email: string }, jobId?: string) => shell(`${jobId ? "Edit" : "Create"} job — Factorize`, viewer, `<main class="mx-auto w-full max-w-5xl min-w-0 px-5 py-12 lg:px-8"><a href="${jobId ? `/jobs/${escapeHtml(jobId)}` : "/jobs"}" class="text-sm font-medium text-slate-500">← Jobs</a><div class="mt-5 min-w-0">${dashboardHead(jobId ? "Edit job" : "Create a job", "Every prompt input comes from an explicit trigger row with a stable context slug.")}</div>
export const jobPage = (viewer: { email: string }, jobId?: string) => shell(`${jobId ? "Edit" : "Create"} job — Factorize`, viewer, `<main class="mx-auto w-full max-w-5xl min-w-0 px-4 py-8 sm:px-5 sm:py-12 lg:px-8"><a href="${jobId ? `/jobs/${escapeHtml(jobId)}` : "/jobs"}" class="text-sm font-medium text-slate-500">← Jobs</a><div class="mt-4 min-w-0 sm:mt-5">${dashboardHead(jobId ? "Edit job" : "Create a job", "Every prompt input comes from an explicit trigger row with a stable context slug.")}</div>
<form id="job" class="mt-8 min-w-0 space-y-6"><section class="${card} min-w-0 p-6" aria-labelledby="job-basics-title"><div class="min-w-0 border-b border-stone-200 pb-5 dark:border-slate-800"><p class="text-xs font-semibold uppercase tracking-[.18em] text-factorize-700 dark:text-factorize-100">Step 1</p><h2 id="job-basics-title" class="mt-2 text-xl font-semibold">Job details</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Name this job and set how many runs it can process at once.</p></div><div class="mt-5 grid min-w-0 gap-5 sm:grid-cols-2"><label class="label min-w-0">Name<input class="field" name="name" required maxlength="120"></label><label class="label min-w-0">Slug<input class="field font-mono" name="slug" required maxlength="30" pattern="[a-z][a-z0-9_\\-]{0,29}"><span class="mt-2 block font-normal text-slate-500">Used for Herdr names. You can customize it.</span></label><label class="label min-w-0">Max concurrency<input class="field" type="number" name="concurrencyLimit" min="1" max="50" value="1" required></label></div></section>
<section class="${card} min-w-0 overflow-hidden" aria-labelledby="job-triggers-title"><div class="flex min-w-0 flex-wrap items-end justify-between gap-4 border-b border-stone-200 p-6 dark:border-slate-800"><div class="min-w-0"><p class="text-xs font-semibold uppercase tracking-[.18em] text-factorize-700 dark:text-factorize-100">Step 2</p><h2 id="job-triggers-title" class="mt-2 text-xl font-semibold">Triggers</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Choose the events that start this job and expose prompt context.</p></div><div class="w-full min-w-0 sm:w-56"><label class="sr-only" for="add-trigger">Add a trigger</label><select id="add-trigger" class="field disabled:cursor-wait disabled:opacity-60" disabled><option value="" selected>Loading trigger types…</option></select></div></div><div class="max-w-full overflow-x-auto"><table class="w-full min-w-[48rem] text-left text-sm"><thead class="bg-stone-50 text-xs uppercase tracking-wide text-slate-500 dark:bg-slate-950"><tr><th class="px-4 py-3">Context slug</th><th class="px-4 py-3">Type</th><th class="px-4 py-3">Configuration</th><th class="px-4 py-3">Enabled</th><th class="px-4 py-3 text-right">Actions</th></tr></thead><tbody id="trigger-rows"></tbody></table></div><p id="trigger-empty" class="hidden p-6 text-sm text-slate-500">Add at least one trigger.</p></section>
<section class="${card} min-w-0 p-6" aria-labelledby="job-prompt-title"><div class="min-w-0 border-b border-stone-200 pb-5 dark:border-slate-800"><p class="text-xs font-semibold uppercase tracking-[.18em] text-factorize-700 dark:text-factorize-100">Step 3</p><h2 id="job-prompt-title" class="mt-2 text-xl font-semibold">Prompt and context</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Write the instructions for each run using context supplied by your triggers.</p></div><label class="label relative mt-5 min-w-0">Mustache prompt template<div class="template-editor mt-2"><pre id="prompt-highlight" aria-hidden="true"></pre><textarea class="field min-h-44 font-mono text-sm" name="promptTemplate" required placeholder="Review {{trigger-2.issue.title}}" aria-autocomplete="list" aria-controls="context-suggestions" aria-expanded="false" spellcheck="false"></textarea></div><div id="context-suggestions" class="absolute z-20 hidden max-h-56 w-[min(32rem,calc(100vw-4rem))] max-w-full overflow-y-auto rounded-lg border border-stone-300 bg-white py-1 text-sm font-normal shadow-xl dark:border-slate-700 dark:bg-slate-900" role="listbox"></div><div id="context-announcement" class="sr-only" aria-live="polite"></div><div id="context-paths" class="mt-2 break-words text-sm font-normal text-slate-500 dark:text-slate-400" aria-live="polite"></div></label></section>
Expand Down
16 changes: 15 additions & 1 deletion packages/app/test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,20 @@ describe("pages", () => {
expect(html).toContain('class="mt-2 break-words text-sm');
});

it("keeps the Jobs page proportionate and overflow-safe on phones", () => {
const html = jobsPage({ email: "owner@example.com" });
expect(html).toContain('<main class="mx-auto max-w-6xl px-4 py-8 sm:px-5 sm:py-12 lg:px-8">');
expect(html).toContain('class="flex flex-col items-stretch gap-3 sm:flex-row sm:items-end sm:justify-between sm:gap-4"');
expect(html).toContain('class="inline-flex w-full justify-center rounded-xl');
expect(html).toContain('sm:w-auto sm:px-5 sm:py-3">Create job</a>');
expect(html).toContain('mt-6 overflow-hidden sm:mt-8');
expect(html).toContain('flex min-w-0 items-center gap-3 px-4 py-4 sm:gap-4 sm:p-6');
expect(html).toContain('h-3 w-3 shrink-0 rounded-full ring-2');
expect(html).toContain('flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1');
expect(html).toContain('break-words font-semibold');
expect(html).not.toContain('min-w-[48rem]');
});

it("selects a per-job model with harness-aware suggestions", () => {
const html = jobPage({ email: "owner@example.com" }, "job-1");
expect(html).toContain('name="model"');
Expand Down Expand Up @@ -274,7 +288,7 @@ describe("pages", () => {
expect(list).not.toContain("Last run failed");
expect(list).not.toContain("Last run succeeded");
expect(list).toContain("/'+esc(j.concurrencyLimit)+' Running");
expect(list).toMatch(/<h1 class="text-3xl font-bold tracking-tight">Jobs<\/h1><\/div><a href="\/jobs\/new"/);
expect(list).toMatch(/<h1 class="text-3xl font-bold tracking-tight">Jobs<\/h1>[\s\S]*<a href="\/jobs\/new"/);
expect(list).not.toContain("Create reusable agent work and choose exactly how it starts.");
expect(list).not.toContain("triggers.map(t=>triggerBadge(t.kind))");
expect(list).not.toContain("new Date(j.updatedAt)");
Expand Down