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
1 change: 1 addition & 0 deletions packages/app/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const showTriggerDialog=dialog.showModal.bind(dialog);dialog.showModal=()=>{if(t
async function refreshAvailability(){availability=await request('/api/v1/job-trigger-availability');const select=$('#add-trigger'),selected=select.value;select.replaceChildren(new Option('Add trigger…',''),...Object.entries(kinds).filter(([kind])=>availability[kind]).map(([kind,label])=>new Option(label,kind)));select.value=selected;select.disabled=false}
const ruleLabels={status:'Status',label:'Label',assignee:'Assignee',creator:'Creator',owner:'Owner'};
const ruleOptions=type=>type==='status'?resources.options.statuses:type==='label'?resources.options.labels:resources.options.users;
const githubRuleOptions=type=>type==='status'?resources.githubOptions.statuses:type==='label'?resources.githubOptions.labels:resources.githubOptions.users;
const ruleSummary=rule=>ruleLabels[rule.type]+' is '+nameOf(ruleOptions(rule.type),rule.targetId);
function summary(t){const c=t.config||{},k=providerKind(t);if(k==='manual')return 'Prompt entered when run';if(k==='schedule')return c.cron+' · '+c.timezone;if(k==='linear')return nameOf(resources.projects,c.projectId)+' · '+(c.matchRules||[]).map(ruleSummary).join(' + ');if(k==='clickup')return nameOf(resources.clickupLists,c.listId)+' · '+(c.matchRules||[]).map(ruleSummary).join(' + ');if(k==='github'){const i=resources.installations.find(x=>String(x.installationId)===String(c.installationId));const repos=resources.repositories.get(String(c.installationId))||[];return (i?.accountLogin||c.installationId)+' · '+(repos.find(x=>String(x.id)===String(c.repositoryId))?.fullName||c.repositoryId)+' · '+c.event+'/'+c.action}if(k==='cloudflareTail')return 'Managed signed Tail endpoint'+(c.handlerCode?' · handler':'');return (c.sourceJobIds||[]).map(id=>resources.jobs.find(j=>j.id===id)?.name||id).join(', ')+' · '+(c.states||[]).join(', ')}
function render(){const rows=$('#trigger-rows');rows.innerHTML=triggers.map((t,i)=>'<tr class="border-t border-stone-200 dark:border-slate-800"><td class="px-4 py-4 font-mono font-semibold">'+esc(t.slug)+'</td><td class="px-4 py-4">'+esc(kinds[providerKind(t)])+(t.actionRequired?'<span class="mt-1 block text-xs font-semibold text-red-700 dark:text-red-300">Action required</span>':'')+'</td><td class="max-w-xs px-4 py-4 text-slate-500">'+esc(t.actionRequired||summary(t))+'</td><td class="px-4 py-4"><label class="inline-flex items-center gap-2"><input data-enable="'+i+'" type="checkbox" '+(t.enabled!==false?'checked':'')+'><span>'+(t.enabled!==false?'Enabled':'Disabled')+'</span></label></td><td class="px-4 py-4"><div class="flex justify-end gap-1"><button type="button" data-edit="'+i+'" aria-label="Edit trigger" title="Edit trigger" class="inline-flex size-9 items-center justify-center rounded-lg text-slate-500 hover:bg-stone-100 hover:text-slate-950 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-factorize-500 focus-visible:ring-offset-2 dark:text-slate-400 dark:hover:bg-slate-800 dark:hover:text-white dark:focus-visible:ring-offset-slate-900"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="size-4"><path stroke-linecap="round" stroke-linejoin="round" d="M16.862 3.487a2.25 2.25 0 0 1 3.182 3.182L8.25 18.463 3.75 20.25l1.787-4.5L16.862 3.487Z"/><path stroke-linecap="round" d="m15.75 4.5 3.75 3.75"/></svg></button><button type="button" data-remove="'+i+'" aria-label="Remove trigger" title="Remove trigger" class="inline-flex size-9 items-center justify-center rounded-lg text-slate-400 hover:bg-red-50 hover:text-red-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-red-500 focus-visible:ring-offset-2 dark:text-slate-500 dark:hover:bg-red-950/50 dark:hover:text-red-300 dark:focus-visible:ring-offset-slate-900"><svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="size-4"><path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M9.75 10.5v6m4.5-6v6m-8.25-9 .75 12h10.5l.75-12m-8.25 0V4.5h4.5v3"/></svg></button></div></td></tr>').join('');$('#trigger-empty').classList.toggle('hidden',triggers.length>0);const hints=triggerHints();$('#context-paths').innerHTML=hints.length?'Available context: '+hints.map(x=>'<button type="button" data-context-hint="'+esc(x.path)+'" class="ml-1 rounded-md border border-stone-300 px-2 py-1 font-mono text-xs hover:bg-stone-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-factorize-500 dark:border-slate-700 dark:hover:bg-slate-800" aria-label="Insert {{'+esc(x.path)+'}}">{{'+esc(x.path)+'}}</button>').join(''):'Add a trigger to expose context.';updateSuggestions()}
Expand Down
2 changes: 2 additions & 0 deletions packages/app/test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ describe("pages", () => {
expect(html).toContain('id="add-github-rule"');
expect(html).toContain("matchRules:readGithubRules()");
expect(html).toContain("status:'Status',label:'Label',assignee:'Assignee',creator:'Creator',owner:'Owner'");
expect(html).toContain("const githubRuleOptions=type=>type==='status'?resources.githubOptions.statuses:type==='label'?resources.githubOptions.labels:resources.githubOptions.users;");
expect(html).toContain("githubRuleOptions(type.value).map");
expect(html).toContain("matchRules:readLinearRules()");
expect(html).toContain("(c.matchRules?.length?c.matchRules:");
expect(html).not.toContain("const legacyJobPage");
Expand Down