fix: ui polish — unified topbar, selector consistency, quick actions editor improvements (#693)

This commit is contained in:
Carlos Florêncio
2026-04-24 21:31:46 +01:00
committed by GitHub
parent 1fc3544625
commit c092fdeb1c
22 changed files with 628 additions and 274 deletions
@@ -4,7 +4,6 @@ import { createElement, useMemo, useState, useCallback } from "react";
import { IconPlus, IconTrash, IconRefresh } from "@tabler/icons-react";
import { Button } from "@kandev/ui/button";
import { Input } from "@kandev/ui/input";
import { Textarea } from "@kandev/ui/textarea";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@kandev/ui/select";
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@kandev/ui/tabs";
import { useToast } from "@/components/toast-provider";
@@ -17,6 +16,26 @@ import {
iconForPresetKey,
} from "@/components/github/my-github/action-presets";
import type { GitHubActionPreset } from "@/lib/types/github";
import {
ScriptEditor,
computeEditorHeight,
} from "@/components/settings/profile-edit/script-editor";
import type { ScriptPlaceholder } from "@/components/settings/profile-edit/script-editor-completions";
const ACTION_PROMPT_PLACEHOLDERS: ScriptPlaceholder[] = [
{
key: "url",
description: "URL of the PR or issue",
example: "https://github.com/org/repo/pull/42",
executor_types: [],
},
{
key: "title",
description: "Title of the PR or issue",
example: "Fix login page crash",
executor_types: [],
},
];
function newPreset(): GitHubActionPreset {
return {
@@ -31,7 +50,7 @@ function newPreset(): GitHubActionPreset {
function PresetIconSelect({ value, onChange }: { value: string; onChange: (v: string) => void }) {
return (
<Select value={value} onValueChange={onChange}>
<SelectTrigger className="h-8 cursor-pointer" aria-label="Icon">
<SelectTrigger className="!h-8 py-0.5 text-sm cursor-pointer" aria-label="Icon">
<SelectValue>
{createElement(iconForPresetKey(value), { className: "h-4 w-4" })}
</SelectValue>
@@ -68,21 +87,35 @@ function PresetRow({
}) {
return (
<div className="rounded-md border">
<div className="flex items-center gap-2 p-2">
<PresetIconSelect value={preset.icon} onChange={(v) => onPatch({ icon: v })} />
<Input
className="h-8 w-40"
value={preset.label}
placeholder="Label"
onChange={(e) => onPatch({ label: e.target.value })}
/>
<Input
className="h-8 flex-1"
value={preset.hint}
placeholder="Hint (optional)"
onChange={(e) => onPatch({ hint: e.target.value })}
/>
<Button variant="ghost" size="sm" className="h-8 cursor-pointer text-xs" onClick={onToggle}>
<div className="flex items-end gap-2 p-2">
<div className="flex flex-col gap-0.5">
<span className="text-[10px] text-muted-foreground">Icon</span>
<PresetIconSelect value={preset.icon} onChange={(v) => onPatch({ icon: v })} />
</div>
<div className="flex flex-col gap-0.5">
<span className="text-[10px] text-muted-foreground">Label</span>
<Input
className="h-8 w-40"
value={preset.label}
placeholder="Label"
onChange={(e) => onPatch({ label: e.target.value })}
/>
</div>
<div className="flex flex-col gap-0.5 flex-1">
<span className="text-[10px] text-muted-foreground">Hint</span>
<Input
className="h-8"
value={preset.hint}
placeholder="Hint (optional)"
onChange={(e) => onPatch({ hint: e.target.value })}
/>
</div>
<Button
variant="outline"
size="sm"
className="h-8 cursor-pointer text-xs"
onClick={onToggle}
>
{expanded ? "Hide prompt" : "Edit prompt"}
</Button>
<Button
@@ -96,14 +129,23 @@ function PresetRow({
</Button>
</div>
{expanded && (
<div className="px-2 pb-2">
<Textarea
rows={3}
className="text-xs font-mono"
placeholder="Prompt template — {url} and {title} are substituted"
value={preset.prompt_template}
onChange={(e) => onPatch({ prompt_template: e.target.value })}
/>
<div className="px-2 pb-2 space-y-1">
<div className="rounded-md border overflow-hidden">
<ScriptEditor
value={preset.prompt_template}
onChange={(v) => onPatch({ prompt_template: v })}
language="markdown"
height={computeEditorHeight(preset.prompt_template)}
lineNumbers="off"
placeholders={ACTION_PROMPT_PLACEHOLDERS}
/>
</div>
<p className="text-[11px] text-muted-foreground/60">
Type {"{{"} to see available placeholders.{" "}
<code className="bg-muted px-1 py-0.5 rounded text-[10px]">{"{{url}}"}</code> and{" "}
<code className="bg-muted px-1 py-0.5 rounded text-[10px]">{"{{title}}"}</code> are
substituted when the action runs.
</p>
</div>
)}
</div>
@@ -0,0 +1,207 @@
"use client";
import { useState, useCallback, useMemo } from "react";
import { IconPlus, IconTrash, IconRefresh } from "@tabler/icons-react";
import { Button } from "@kandev/ui/button";
import { Input } from "@kandev/ui/input";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@kandev/ui/select";
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@kandev/ui/tabs";
import { useToast } from "@/components/toast-provider";
import { SettingsSection } from "@/components/settings/settings-section";
import {
useDefaultQueryPresets,
toStored,
type StoredQueryPreset,
} from "@/components/github/my-github/use-default-query-presets";
import {
PR_PRESETS as BUILTIN_PR_PRESETS,
ISSUE_PRESETS as BUILTIN_ISSUE_PRESETS,
} from "@/components/github/my-github/search-bar";
function newPreset(): StoredQueryPreset {
return {
value: `q_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 7)}`,
label: "New query",
filter: "",
group: "inbox",
};
}
function QueryRow({
preset,
onPatch,
onRemove,
}: {
preset: StoredQueryPreset;
onPatch: (patch: Partial<StoredQueryPreset>) => void;
onRemove: () => void;
}) {
return (
<div className="flex items-center gap-2 rounded-md border p-2">
<div className="flex flex-col gap-0.5">
<span className="text-[10px] text-muted-foreground">Label</span>
<Input
className="h-8 w-36"
value={preset.label}
placeholder="Label"
onChange={(e) => onPatch({ label: e.target.value })}
/>
</div>
<div className="flex flex-col gap-0.5 flex-1">
<span className="text-[10px] text-muted-foreground">Query</span>
<Input
className="h-8 font-mono text-xs"
value={preset.filter}
placeholder="e.g. review-requested:@me is:open"
onChange={(e) => onPatch({ filter: e.target.value })}
/>
</div>
<div className="flex flex-col gap-0.5">
<span className="text-[10px] text-muted-foreground">Group</span>
<Select
value={preset.group}
onValueChange={(v) => onPatch({ group: v as "inbox" | "created" })}
>
<SelectTrigger className="h-8 w-28 cursor-pointer">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="inbox" className="cursor-pointer">
Inbox
</SelectItem>
<SelectItem value="created" className="cursor-pointer">
Created
</SelectItem>
</SelectContent>
</Select>
</div>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 cursor-pointer text-destructive mt-3.5"
onClick={onRemove}
aria-label="Remove"
>
<IconTrash className="h-3.5 w-3.5" />
</Button>
</div>
);
}
function QueryEditor({
presets,
onChange,
addLabel,
}: {
presets: StoredQueryPreset[];
onChange: (presets: StoredQueryPreset[]) => void;
addLabel: string;
}) {
const patch = useCallback(
(index: number, change: Partial<StoredQueryPreset>) => {
onChange(presets.map((p, i) => (i === index ? { ...p, ...change } : p)));
},
[presets, onChange],
);
const remove = useCallback(
(index: number) => onChange(presets.filter((_, i) => i !== index)),
[presets, onChange],
);
const add = useCallback(() => onChange([...presets, newPreset()]), [presets, onChange]);
return (
<div className="space-y-2">
{presets.map((preset, index) => (
<QueryRow
key={preset.value}
preset={preset}
onPatch={(p) => patch(index, p)}
onRemove={() => remove(index)}
/>
))}
<Button size="sm" variant="outline" onClick={add} className="cursor-pointer">
<IconPlus className="h-3.5 w-3.5 mr-1" />
{addLabel}
</Button>
</div>
);
}
export function DefaultQueriesSection() {
const { toast } = useToast();
const { prPresets, issuePresets, save, reset, isCustomized } = useDefaultQueryPresets();
const [prDraft, setPrDraft] = useState<StoredQueryPreset[]>(prPresets);
const [issueDraft, setIssueDraft] = useState<StoredQueryPreset[]>(issuePresets);
// Sync drafts when external state changes
const [syncedPr, setSyncedPr] = useState(prPresets);
const [syncedIssue, setSyncedIssue] = useState(issuePresets);
if (prPresets !== syncedPr) {
setSyncedPr(prPresets);
setPrDraft(prPresets);
}
if (issuePresets !== syncedIssue) {
setSyncedIssue(issuePresets);
setIssueDraft(issuePresets);
}
const dirty = useMemo(
() =>
JSON.stringify(prPresets) !== JSON.stringify(prDraft) ||
JSON.stringify(issuePresets) !== JSON.stringify(issueDraft),
[prPresets, issuePresets, prDraft, issueDraft],
);
const handleSave = useCallback(() => {
save({ pr: prDraft, issue: issueDraft });
toast({ description: "Default queries saved", variant: "success" });
}, [save, prDraft, issueDraft, toast]);
const handleReset = useCallback(() => {
reset();
setPrDraft(toStored(BUILTIN_PR_PRESETS));
setIssueDraft(toStored(BUILTIN_ISSUE_PRESETS));
toast({ description: "Default queries reset to defaults", variant: "success" });
}, [reset, toast]);
return (
<SettingsSection
title="Default queries"
description="Sidebar queries shown on /github for pull requests and issues."
action={
<div className="flex gap-2">
<Button
size="sm"
variant="outline"
onClick={handleReset}
disabled={!isCustomized}
className="cursor-pointer"
>
<IconRefresh className="h-3.5 w-3.5 mr-1" />
Reset
</Button>
<Button size="sm" onClick={handleSave} disabled={!dirty} className="cursor-pointer">
Save changes
</Button>
</div>
}
>
<Tabs defaultValue="pr">
<TabsList>
<TabsTrigger value="pr" className="cursor-pointer">
Pull requests
</TabsTrigger>
<TabsTrigger value="issue" className="cursor-pointer">
Issues
</TabsTrigger>
</TabsList>
<TabsContent value="pr">
<QueryEditor presets={prDraft} onChange={setPrDraft} addLabel="Add PR query" />
</TabsContent>
<TabsContent value="issue">
<QueryEditor presets={issueDraft} onChange={setIssueDraft} addLabel="Add issue query" />
</TabsContent>
</Tabs>
</SettingsSection>
);
}
@@ -14,6 +14,7 @@ import { ReviewWatchDialog } from "./review-watch-dialog";
import { IssueWatchTable } from "./issue-watch-table";
import { IssueWatchDialog } from "./issue-watch-dialog";
import { ActionPresetsSection } from "./action-presets-section";
import { DefaultQueriesSection } from "./default-queries-section";
import { PRStatsPanel } from "./pr-stats";
import { useReviewWatches } from "@/hooks/domains/github/use-review-watches";
import { useIssueWatches } from "@/hooks/domains/github/use-issue-watches";
@@ -158,6 +159,7 @@ export function GitHubSettings({ workspaceId }: GitHubSettingsProps) {
<ReviewWatchSection workspaceId={workspaceId} />
<IssueWatchSection workspaceId={workspaceId} />
<ActionPresetsSection workspaceId={workspaceId} />
<DefaultQueriesSection />
<SettingsSection
title="PR Analytics"
@@ -11,7 +11,15 @@ import {
import { IconEye, IconSparkles } from "@tabler/icons-react";
describe("interpolatePromptTemplate", () => {
it("replaces {url} and {title} placeholders", () => {
it("replaces {{url}} and {{title}} placeholders", () => {
const out = interpolatePromptTemplate("Review {{url}} titled {{title}}", {
url: "https://gh/pr/1",
title: "Fix bug",
});
expect(out).toBe("Review https://gh/pr/1 titled Fix bug");
});
it("supports legacy single-brace {url} and {title}", () => {
const out = interpolatePromptTemplate("Review {url} titled {title}", {
url: "https://gh/pr/1",
title: "Fix bug",
@@ -20,7 +28,7 @@ describe("interpolatePromptTemplate", () => {
});
it("leaves unknown placeholders intact", () => {
const out = interpolatePromptTemplate("See {url} and {unknown}", {
const out = interpolatePromptTemplate("See {{url}} and {unknown}", {
url: "u",
title: "t",
});
@@ -67,7 +75,7 @@ describe("resolvePRPresets / resolveIssuePresets", () => {
label: "Custom",
hint: "h",
icon: "eye",
prompt_template: "Do it on {url}",
prompt_template: "Do it on {{url}}",
},
],
issue: [],
@@ -86,7 +94,7 @@ describe("toTaskPreset", () => {
label: "L",
hint: "H",
icon: "message",
prompt_template: "On {url} for {title}",
prompt_template: "On {{url}} for {{title}}",
};
const preset = toTaskPreset(stored);
expect(preset.prompt({ url: "U", title: "T" })).toBe("On U for T");
@@ -36,16 +36,17 @@ export function iconForPresetKey(key: string | undefined): Icon {
return ICON_BY_KEY[key] ?? IconSparkles;
}
// Interpolate `{url}` and `{title}` placeholders in a prompt template.
// Interpolate `{{url}}` and `{{title}}` placeholders in a prompt template.
// Also supports legacy single-brace `{url}` / `{title}` for backward compat.
// Unknown placeholders are left untouched so the user sees what's broken.
export function interpolatePromptTemplate(
template: string,
opts: { url: string; title: string },
): string {
return template.replace(/\{(url|title)\}/g, (_match, key) => {
return template.replace(/\{\{?(url|title)\}\}?/g, (_match, key) => {
if (key === "url") return opts.url;
if (key === "title") return opts.title;
return `{${key}}`;
return _match;
});
}
@@ -66,7 +67,7 @@ export const DEFAULT_PR_PRESETS: GitHubActionPreset[] = [
hint: "Read the diff, flag issues",
icon: "eye",
prompt_template:
"Review the pull request at {url}. Provide feedback on code quality, correctness, and suggest improvements.",
"Review the pull request at {{url}}. Provide feedback on code quality, correctness, and suggest improvements.",
},
{
id: "address_feedback",
@@ -74,7 +75,7 @@ export const DEFAULT_PR_PRESETS: GitHubActionPreset[] = [
hint: "Apply review comments",
icon: "message",
prompt_template:
"Address the review feedback on the pull request at {url}. Make the requested changes and push them.",
"Review the feedback on the pull request at {{url}}. Evaluate each comment critically — apply changes that improve the code, push back on suggestions that are unnecessary or harmful, and explain your reasoning. Push the changes when done.",
},
{
id: "fix_ci",
@@ -82,7 +83,7 @@ export const DEFAULT_PR_PRESETS: GitHubActionPreset[] = [
hint: "Diagnose failing checks",
icon: "tool",
prompt_template:
"Investigate and fix the CI failures on the pull request at {url}. Run the failing checks locally, diagnose, and push fixes.",
"Investigate and fix the CI failures and merge conflicts on the pull request at {{url}}. Run the failing checks locally, resolve any conflicts, diagnose issues, and push fixes.",
},
];
@@ -93,7 +94,7 @@ export const DEFAULT_ISSUE_PRESETS: GitHubActionPreset[] = [
hint: "Build and open a PR",
icon: "code",
prompt_template:
'Implement the changes described in the GitHub issue at {url} (title: "{title}"). Open a pull request when complete.',
'Implement the changes described in the GitHub issue at {{url}} (title: "{{title}}"). Open a pull request when complete.',
},
{
id: "investigate",
@@ -101,7 +102,7 @@ export const DEFAULT_ISSUE_PRESETS: GitHubActionPreset[] = [
hint: "Find the root cause",
icon: "search",
prompt_template:
'Investigate the GitHub issue at {url} (title: "{title}"). Identify root cause and summarize findings.',
'Investigate the GitHub issue at {{url}} (title: "{{title}}"). Identify root cause and summarize findings.',
},
{
id: "reproduce",
@@ -109,7 +110,7 @@ export const DEFAULT_ISSUE_PRESETS: GitHubActionPreset[] = [
hint: "Document repro steps",
icon: "bug",
prompt_template:
'Reproduce the bug described in the GitHub issue at {url} (title: "{title}"). Document the reproduction steps.',
'Reproduce the bug described in the GitHub issue at {{url}} (title: "{{title}}"). Document the reproduction steps.',
},
];
@@ -19,6 +19,8 @@ type PresetsSidebarProps = {
onDeleteSaved: (id: string) => void;
canSaveCurrent: boolean;
onSaveCurrent: () => void;
prPresets?: PresetOption[];
issuePresets?: PresetOption[];
};
function KindToggle({
@@ -200,11 +202,13 @@ export function PresetsSidebar({
onDeleteSaved,
canSaveCurrent,
onSaveCurrent,
prPresets = PR_PRESETS,
issuePresets = ISSUE_PRESETS,
}: PresetsSidebarProps) {
const presets = selected.kind === "pr" ? PR_PRESETS : ISSUE_PRESETS;
const presets = selected.kind === "pr" ? prPresets : issuePresets;
const saved = savedPresets.filter((p) => p.kind === selected.kind);
const onKindChange = (kind: "pr" | "issue") => {
const fallback = (kind === "pr" ? PR_PRESETS : ISSUE_PRESETS)[0]?.value ?? "";
const fallback = (kind === "pr" ? prPresets : issuePresets)[0]?.value ?? "";
onSelect({ kind, source: "preset", id: fallback });
};
return (
@@ -0,0 +1,116 @@
"use client";
import { useCallback, useMemo, useSyncExternalStore } from "react";
import {
PR_PRESETS as BUILTIN_PR_PRESETS,
ISSUE_PRESETS as BUILTIN_ISSUE_PRESETS,
type PresetOption,
} from "./search-bar";
const STORAGE_KEY = "kandev:github-default-queries:v1";
export type StoredQueryPreset = {
value: string;
label: string;
filter: string;
group: "inbox" | "created";
};
type StoredDefaults = {
pr: StoredQueryPreset[];
issue: StoredQueryPreset[];
};
export function toStored(presets: PresetOption[]): StoredQueryPreset[] {
return presets.map(({ value, label, filter, group }) => ({ value, label, filter, group }));
}
function readStorage(): StoredDefaults | null {
if (typeof window === "undefined") return null;
try {
const raw = window.localStorage.getItem(STORAGE_KEY);
if (!raw) return null;
const parsed = JSON.parse(raw) as unknown;
if (
typeof parsed !== "object" ||
parsed === null ||
!Array.isArray((parsed as StoredDefaults).pr) ||
!Array.isArray((parsed as StoredDefaults).issue)
) {
return null;
}
return parsed as StoredDefaults;
} catch {
return null;
}
}
function writeStorage(defaults: StoredDefaults | null) {
if (typeof window === "undefined") return;
try {
if (defaults === null) {
window.localStorage.removeItem(STORAGE_KEY);
} else {
window.localStorage.setItem(STORAGE_KEY, JSON.stringify(defaults));
}
} catch {
/* ignore quota / access errors */
}
}
let snapshot: StoredDefaults | null | undefined = undefined;
const listeners = new Set<() => void>();
function publish(next: StoredDefaults | null) {
snapshot = next;
writeStorage(next);
listeners.forEach((fn) => fn());
}
function subscribe(cb: () => void) {
listeners.add(cb);
return () => {
listeners.delete(cb);
};
}
function getSnapshot(): StoredDefaults | null {
if (snapshot === undefined) snapshot = readStorage();
return snapshot;
}
function getServerSnapshot(): StoredDefaults | null {
return null;
}
export function useDefaultQueryPresets() {
const stored = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
const prPresets = useMemo(() => stored?.pr ?? toStored(BUILTIN_PR_PRESETS), [stored]);
const issuePresets = useMemo(() => stored?.issue ?? toStored(BUILTIN_ISSUE_PRESETS), [stored]);
const save = useCallback((defaults: StoredDefaults) => {
publish(defaults);
}, []);
const reset = useCallback(() => {
publish(null);
}, []);
const isCustomized = stored !== null;
return { prPresets, issuePresets, save, reset, isCustomized };
}
/** Resolve full PresetOption[] by merging stored presets with icon lookups from builtins. */
export function resolvePresetOptions(
stored: StoredQueryPreset[],
builtins: PresetOption[],
): PresetOption[] {
const iconMap = new Map(builtins.map((b) => [b.value, b.icon]));
const defaultIcon = builtins[0]?.icon;
return stored.map((s) => ({
...s,
icon: iconMap.get(s.value) ?? defaultIcon,
}));
}
@@ -1,67 +0,0 @@
"use client";
import { useState, useCallback, useEffect, useRef } from "react";
import { IconRefresh } from "@tabler/icons-react";
import { Button } from "@kandev/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip";
import { useToast } from "@/components/toast-provider";
import { useAppStore } from "@/components/state-provider";
import { triggerAllReviewWatches, listReviewWatches } from "@/lib/api/domains/github-api";
export function RefreshReviewsButton() {
const [loading, setLoading] = useState(false);
const { toast } = useToast();
const workspaceId = useAppStore((state) => state.workspaces.activeId);
const hasWatches = useAppStore((state) => state.reviewWatches.items.length > 0);
const watchesLoaded = useAppStore((state) => state.reviewWatches.loaded);
const setReviewWatches = useAppStore((state) => state.setReviewWatches);
const fetchedRef = useRef(false);
useEffect(() => {
if (!workspaceId || watchesLoaded || fetchedRef.current) return;
fetchedRef.current = true;
listReviewWatches(workspaceId)
.then((r) => setReviewWatches(r?.watches ?? []))
.catch(() => {});
}, [workspaceId, watchesLoaded, setReviewWatches]);
const handleTrigger = useCallback(async () => {
if (!workspaceId || loading) return;
setLoading(true);
try {
const result = await triggerAllReviewWatches(workspaceId);
const count = result?.new_prs_found ?? 0;
if (count > 0) {
toast({
description: `Found ${count} new PR${count > 1 ? "s" : ""} to review`,
variant: "success",
});
} else {
toast({ description: "No new PRs to review" });
}
} catch {
toast({ description: "Failed to check for review PRs", variant: "error" });
} finally {
setLoading(false);
}
}, [workspaceId, loading, toast]);
if (!watchesLoaded || !hasWatches) return null;
return (
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="icon"
className="cursor-pointer"
onClick={handleTrigger}
disabled={loading}
>
<IconRefresh className={`h-4 w-4 ${loading ? "animate-spin" : ""}`} />
</Button>
</TooltipTrigger>
<TooltipContent>Check for PRs to review</TooltipContent>
</Tooltip>
);
}