ccc62d9324
* feat(github): configurable quick-action presets and PR branch checkout - Add workspace-scoped action presets (icon, label, hint, prompt template) for PRs and Issues, editable from GitHub settings with reset-to-defaults. - When starting a task from a PR, check out the PR head branch directly in the worktree instead of branching off main. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(github): extract action-preset service to keep service.go under line limit Splits the preset CRUD methods out of the oversized service.go and applies prettier formatting to three frontend files flagged by CI. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(github): address review feedback on action presets - Prevent infinite refetch loop when fetching presets fails by tracking attempted workspaces in a ref instead of re-entering the effect on every loading-state change. - Drop unused savePR/saveIssue helpers from the hook; only save() is consumed. - Reorder the init spread in updateGitHubActionPresets/resetGitHubActionPresets so callers can't accidentally overwrite method/body. - Tighten the GitHubActionPreset.icon type with string & {} so known icon keys keep autocomplete. - Sharpen the eye-icon test to assert the exact IconEye mapping. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(github): address second round of review feedback - Seed preset editor drafts from current store state via lazy initializers so a warm mount shows the user's saved customisations instead of silently reverting to defaults when Save is clicked. - Guard Reset button with its own in-flight state to prevent double-firing. - Stop freezing resolved defaults into the stored row on a partial update; persist only what the store has for the untouched kind so future default improvements still reach those workspaces. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * refactor(github): tighten quick-actions editor UI Replace the stacked PR/Issue editors and multi-line preset cards with a tabbed layout and single-line rows. Each row shows icon · label · hint inline; an "Edit prompt" toggle reveals the template textarea only when needed. Drops the redundant section headings, up/down reorder buttons, and verbose template helper label (hint moved into the textarea placeholder). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(github): widen icon select trigger so the icon is visible The icon select trigger had a fixed 40px width which the SelectTrigger's built-in chevron, padding, and icon gap all competed for, clipping the icon out of view. Drop the width override so the trigger sizes to its content. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
170 lines
5.0 KiB
TypeScript
170 lines
5.0 KiB
TypeScript
"use client";
|
|
|
|
import Link from "next/link";
|
|
import {
|
|
IconGitPullRequest,
|
|
IconGitPullRequestClosed,
|
|
IconGitMerge,
|
|
IconPlus,
|
|
IconChevronDown,
|
|
} from "@tabler/icons-react";
|
|
import type { Icon } from "@tabler/icons-react";
|
|
import { Button } from "@kandev/ui/button";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from "@kandev/ui/dropdown-menu";
|
|
import { Spinner } from "@kandev/ui/spinner";
|
|
import { cn, formatRelativeTime } from "@/lib/utils";
|
|
import type { GitHubPR, GitHubPRStatus } from "@/lib/types/github";
|
|
import type { LaunchPayload, TaskPreset } from "./quick-task-launcher";
|
|
import { PRStatusBadges } from "./pr-status-badges";
|
|
import { prStatusKey, usePRStatuses } from "./use-pr-statuses";
|
|
|
|
type PRListProps = {
|
|
items: GitHubPR[];
|
|
loading: boolean;
|
|
error: string | null;
|
|
presets: TaskPreset[];
|
|
onStartTask: (payload: LaunchPayload) => void;
|
|
};
|
|
|
|
function prStateIcon(pr: GitHubPR): { Icon: Icon; className: string } {
|
|
if (pr.state === "merged")
|
|
return { Icon: IconGitMerge, className: "text-purple-600 dark:text-purple-400" };
|
|
if (pr.state === "closed")
|
|
return { Icon: IconGitPullRequestClosed, className: "text-red-600 dark:text-red-400" };
|
|
if (pr.draft) return { Icon: IconGitPullRequest, className: "text-muted-foreground" };
|
|
return { Icon: IconGitPullRequest, className: "text-emerald-600 dark:text-emerald-400" };
|
|
}
|
|
|
|
function StartTaskMenu({
|
|
pr,
|
|
presets,
|
|
onStartTask,
|
|
}: {
|
|
pr: GitHubPR;
|
|
presets: TaskPreset[];
|
|
onStartTask: PRListProps["onStartTask"];
|
|
}) {
|
|
const launch = (preset: TaskPreset) => onStartTask({ kind: "pr", pr, preset });
|
|
return (
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button size="sm" variant="outline" className="h-7 gap-1 cursor-pointer">
|
|
<IconPlus className="h-3.5 w-3.5" />
|
|
Task
|
|
<IconChevronDown className="h-3 w-3" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-48">
|
|
{presets.map((p) => {
|
|
const ItemIcon = p.icon;
|
|
return (
|
|
<DropdownMenuItem
|
|
key={p.id}
|
|
className="cursor-pointer gap-2 py-1.5"
|
|
onSelect={() => launch(p)}
|
|
>
|
|
<ItemIcon className="h-3.5 w-3.5 text-muted-foreground shrink-0" />
|
|
<div className="flex flex-col min-w-0">
|
|
<span className="text-xs font-medium leading-tight">{p.label}</span>
|
|
<span className="text-[11px] text-muted-foreground leading-tight">{p.hint}</span>
|
|
</div>
|
|
</DropdownMenuItem>
|
|
);
|
|
})}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
}
|
|
|
|
function PRRow({
|
|
pr,
|
|
status,
|
|
presets,
|
|
onStartTask,
|
|
}: {
|
|
pr: GitHubPR;
|
|
status: GitHubPRStatus | null | undefined;
|
|
presets: TaskPreset[];
|
|
onStartTask: PRListProps["onStartTask"];
|
|
}) {
|
|
const { Icon: StateIcon, className: stateIconClass } = prStateIcon(pr);
|
|
return (
|
|
<div className="flex items-start gap-3 px-4 py-3 hover:bg-muted/40 transition-colors">
|
|
<StateIcon className={cn("h-4 w-4 mt-1 shrink-0", stateIconClass)} />
|
|
<div className="min-w-0 flex-1">
|
|
<Link
|
|
href={pr.html_url}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
className="text-sm font-semibold hover:underline block truncate cursor-pointer"
|
|
>
|
|
{pr.title}
|
|
</Link>
|
|
<div className="flex flex-wrap items-center gap-x-2 gap-y-1 mt-0.5 text-xs text-muted-foreground">
|
|
<span className="whitespace-nowrap">
|
|
{pr.repo_owner}/{pr.repo_name}#{pr.number}
|
|
</span>
|
|
<span>·</span>
|
|
<span className="whitespace-nowrap">
|
|
by {pr.author_login} · opened {formatRelativeTime(pr.created_at)}
|
|
</span>
|
|
<PRStatusBadges pr={pr} status={status} />
|
|
</div>
|
|
</div>
|
|
<div className="shrink-0">
|
|
<StartTaskMenu pr={pr} presets={presets} onStartTask={onStartTask} />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function PRListBody({ loading, error, items, presets, onStartTask }: PRListProps) {
|
|
const statuses = usePRStatuses(items);
|
|
if (loading) {
|
|
return (
|
|
<div className="flex justify-center py-10">
|
|
<Spinner />
|
|
</div>
|
|
);
|
|
}
|
|
if (error) {
|
|
return <div className="text-center py-10 text-destructive text-sm">{error}</div>;
|
|
}
|
|
if (items.length === 0) {
|
|
return (
|
|
<div className="text-center py-10 text-muted-foreground text-sm">
|
|
No pull requests match this filter.
|
|
</div>
|
|
);
|
|
}
|
|
return (
|
|
<div className="divide-y">
|
|
{items.map((pr) => {
|
|
const key = prStatusKey(pr.repo_owner, pr.repo_name, pr.number);
|
|
return (
|
|
<PRRow
|
|
key={key}
|
|
pr={pr}
|
|
status={statuses.get(key)}
|
|
presets={presets}
|
|
onStartTask={onStartTask}
|
|
/>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function PRList(props: PRListProps) {
|
|
return (
|
|
<div className="rounded-md border overflow-hidden">
|
|
<PRListBody {...props} />
|
|
</div>
|
|
);
|
|
}
|