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
6 changes: 3 additions & 3 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><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-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 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 @@ -59,9 +59,9 @@ const jobStatus=j=>{if(j.runningCount>0)return{label:'Running',classes:'bg-blue-
`;

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", "Create reusable agent work and choose exactly how it starts.", '<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>')}
${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 triggers=j.triggers||[],next=triggers.find(t=>t.nextRunAt)?.nextRunAt,status=jobStatus(j);return '<li class="flex flex-wrap items-center justify-between gap-4 p-6"><div class="flex min-w-0 items-center gap-4"><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>'+(triggers.length?triggers.map(t=>triggerBadge(t.kind)).join(''):triggerBadge('manual'))+(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> · updated '+new Date(j.updatedAt).toLocaleString()+(next?' · next '+new Date(next).toLocaleString():'')+'</p></div></div><a href="/jobs/'+encodeURIComponent(j.id)+'" class="text-sm font-semibold">View →</a></li>'}).join('')+'</ul>'}load().catch(e=>$('#jobs').innerHTML='<p class="p-6 text-red-700">'+esc(e.message)+'</p>');`);
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 jobPage = (viewer: { email: string }, jobId?: string) => shell(`${jobId ? "Edit" : "Create"} job — Factorize`, viewer, `<main class="mx-auto max-w-5xl 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">${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 space-y-6"><section class="${card} p-6" aria-labelledby="job-basics-title"><div class="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 gap-5 sm:grid-cols-2"><label class="label">Name<input class="field" name="name" required maxlength="120"></label><label class="label">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">Max concurrency<input class="field" type="number" name="concurrencyLimit" min="1" max="50" value="1" required></label></div></section>
Expand Down
8 changes: 6 additions & 2 deletions packages/app/test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,17 @@ describe("pages", () => {
const detail = jobDetailPage({ email: "owner@example.com" }, "job-1");
const run = jobRunPage({ email: "owner@example.com" }, "run-1");
const settings = settingsPage({ email: "owner@example.com" });
expect(list).toContain("Manual only");
expect(list).toContain("jobStatus(j)");
expect(list).toContain("j.runningCount>0");
expect(list).toContain("Last run failed");
expect(list).toContain("Last run succeeded");
expect(list).toContain("/'+esc(j.concurrencyLimit)+' Running");
expect(list).not.toContain("+' concurrent · updated '");
expect(list).toMatch(/<h1 class="text-3xl font-bold tracking-tight">Jobs<\/h1><\/div><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)");
expect(list).not.toContain("new Date(next)");
expect(list).not.toContain(">View →</a>");
expect(editor).toContain("Add trigger");
expect(editor).toContain('id="trigger-rows"');
expect(editor).toContain("Context slug");
Expand Down