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: 4 additions & 2 deletions packages/app/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ ${dashboardHead("Jobs", "Create reusable agent work and choose exactly how it st
async function load(){const jobs=await request('/api/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;return '<li class="flex flex-wrap items-center justify-between gap-4 p-6"><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">'+esc(j.concurrencyLimit)+' concurrent · updated '+new Date(j.updatedAt).toLocaleString()+(next?' · next '+new Date(next).toLocaleString():'')+'</p></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>');`);

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} grid gap-5 p-6 sm:grid-cols-2"><label class="label sm:col-span-2">Name<input class="field" name="name" required maxlength="120"></label><label class="label sm:col-span-2">Mustache prompt template<textarea class="field mt-2 min-h-44 font-mono text-sm" name="promptTemplate" required placeholder="Review {{trigger-2.issue.title}}"></textarea><div id="context-paths" class="mt-2 text-sm font-normal text-slate-500" aria-live="polite"></div></label><label class="label">Concurrency<input class="field" type="number" name="concurrencyLimit" min="1" max="50" value="1" required></label><label class="label">Execution target<select class="field" name="executionTargetId" required><option value="">Loading saved targets…</option></select><span class="mt-2 block font-normal text-slate-500">Credentials are managed only in <a class="underline" href="/settings">Settings</a>.</span></label></section>
<section class="${card} overflow-hidden"><div class="flex flex-wrap items-center justify-between gap-3 border-b border-stone-200 p-6 dark:border-slate-800"><h2 class="text-lg font-semibold">Triggers</h2><div class="w-full 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><option value="manual">Manual</option><option value="schedule">Schedule</option><option value="linear">Linear</option><option value="github">GitHub</option><option value="cloudflareTail">Cloudflare Tail</option><option value="custom">Custom webhook</option><option value="jobLifecycle">Job lifecycle</option></select></div></div><div class="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>
<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">Max concurrency<input class="field" type="number" name="concurrencyLimit" min="1" max="50" value="1" required></label></div></section>
<section class="${card} overflow-hidden" aria-labelledby="job-triggers-title"><div class="flex flex-wrap items-end justify-between gap-4 border-b border-stone-200 p-6 dark:border-slate-800"><div><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 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><option value="manual">Manual</option><option value="schedule">Schedule</option><option value="linear">Linear</option><option value="github">GitHub</option><option value="cloudflareTail">Cloudflare Tail</option><option value="custom">Custom webhook</option><option value="jobLifecycle">Job lifecycle</option></select></div></div><div class="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} p-6" aria-labelledby="job-prompt-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 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 mt-5">Mustache prompt template<textarea class="field mt-2 min-h-44 font-mono text-sm" name="promptTemplate" required placeholder="Review {{trigger-2.issue.title}}"></textarea><div id="context-paths" class="mt-2 text-sm font-normal text-slate-500 dark:text-slate-400" aria-live="polite"></div></label></section>
<section class="${card} p-6" aria-labelledby="job-target-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 4</p><h2 id="job-target-title" class="mt-2 text-xl font-semibold">Execution target</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Select the connected environment that will run this job.</p></div><label class="label mt-5">Execution target<select class="field" name="executionTargetId" required><option value="">Loading saved targets…</option></select><span class="mt-2 block font-normal text-slate-500 dark:text-slate-400">Credentials are managed only in <a class="underline" href="/settings">Settings</a>.</span></label></section>
<p id="error" class="hidden rounded-xl border border-red-200 bg-red-50 p-4 text-sm text-red-700" role="alert"></p><button id="save" class="rounded-xl bg-slate-950 px-6 py-3 text-sm font-semibold text-white dark:bg-white dark:text-slate-950">${jobId ? "Save changes" : "Create job"}</button></form>
<dialog id="trigger-dialog" class="m-auto w-[min(44rem,calc(100%-2rem))] rounded-2xl bg-white p-0 text-slate-950 shadow-2xl backdrop:bg-slate-950/60 dark:bg-slate-900 dark:text-white"><form id="trigger-form" method="dialog"><div class="border-b border-stone-200 p-6 dark:border-slate-700"><h2 id="dialog-title" class="text-xl font-semibold">Add trigger</h2><p class="mt-1 text-sm text-slate-500">Provider credentials stay managed by Factorize.</p></div><div class="grid max-h-[70vh] gap-5 overflow-y-auto p-6 sm:grid-cols-2"><div data-panel="schedule" class="hidden contents"><label class="label">Cron<input class="field font-mono" name="cron" value="0 9 * * *"></label><label class="label">Timezone<select class="field" name="timezone"><option>UTC</option><option>America/New_York</option><option>America/Chicago</option><option>America/Denver</option><option>America/Los_Angeles</option><option>Europe/London</option><option>Europe/Berlin</option><option>Asia/Tokyo</option><option>Australia/Sydney</option></select></label><p id="schedule-preview" class="sm:col-span-2 text-sm text-slate-500"></p></div>
<div data-panel="linear" class="hidden sm:col-span-2"><label class="label">Project<select class="field" name="projectId"></select></label><div class="mt-5 flex items-start justify-between gap-4"><div><p class="label">Issue matching rules</p><p class="mt-1 text-sm text-slate-500">The issue must match every rule. A run starts when it enters the matching set.</p></div><button id="add-linear-rule" type="button" class="shrink-0 rounded-lg border border-stone-300 px-3 py-2 text-sm font-semibold hover:bg-stone-50 dark:border-slate-700 dark:hover:bg-slate-800">Add rule</button></div><div id="linear-rules" class="mt-4 space-y-3"></div></div>
Expand Down
17 changes: 17 additions & 0 deletions packages/app/test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ describe("pages", () => {
expectInlineScriptsToParse(html);
});

it("organizes create and edit job fields into the same four-step sequence", () => {
for (const html of [jobPage({ email: "owner@example.com" }), jobPage({ email: "owner@example.com" }, "job-1")]) {
const basics = html.indexOf('id="job-basics-title"');
const triggers = html.indexOf('id="job-triggers-title"');
const prompt = html.indexOf('id="job-prompt-title"');
const target = html.indexOf('id="job-target-title"');
expect(basics).toBeGreaterThan(-1);
expect(basics).toBeLessThan(triggers);
expect(triggers).toBeLessThan(prompt);
expect(prompt).toBeLessThan(target);
expect(html).toContain("Name this job and set how many runs it can process at once.");
expect(html).toContain("Choose the events that start this job and expose prompt context.");
expect(html).toContain("Write the instructions for each run using context supplied by your triggers.");
expect(html).toContain("Select the connected environment that will run this job.");
}
});

it("renders accessible icon actions for editing and removing triggers", () => {
const editor = jobPage({ email: "owner@example.com" }, "job-1");
expect(editor).toContain('aria-label="Edit trigger" title="Edit trigger"');
Expand Down