feat(ui): improve analyze display, install picker, and tooltip UX

Analyze page:
- Display skill path (/) instead of flat name (__) in chart, table, dialog
- Widen chart name column from 150px to 220px
- Add skill path as first line in chart tooltip with separator
- Add hover highlight on chart rows

Tooltip component:
- Add followCursor mode that tracks mouse position
- Add viewport boundary detection to prevent clipping
- Measure natural size at (0,0) before clamping position
- Remove break-all to prevent mid-word breaks

Install page:
- Add singleSelect mode to SkillPickerModal (radio UI) when custom name is set
- Add custom name support to batch install API (backend + frontend)
- Remove cross-path duplicate check for batch installs
- Fix: don't show success summary toast when all skills failed
- Fix: keep picker open on install failure
- Preserve source input after install (don't clear on reset)
- Widen SkillPickerModal from md to 2xl
- Align severity badge and description text in warning dialogs

Toast: raise z-index above dialog overlay (z-50 → z-[60])
This commit is contained in:
Willie
2026-03-28 02:30:50 +08:00
parent bb029f7950
commit 44420a8b84
7 changed files with 195 additions and 105 deletions
+10 -10
View File
@@ -87,6 +87,7 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) {
Force bool `json:"force"`
SkipAudit bool `json:"skipAudit"`
Into string `json:"into"`
Name string `json:"name"`
}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
writeError(w, http.StatusBadRequest, "invalid JSON body")
@@ -130,13 +131,8 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) {
}
}
// Cross-path duplicate detection
if !body.Force && source.CloneURL != "" {
if err := install.CheckCrossPathDuplicate(s.cfg.Source, source.CloneURL, body.Into); err != nil {
writeError(w, http.StatusConflict, err.Error())
return
}
}
// Note: no cross-path duplicate check for batch — user explicitly selected
// specific skills from discovery, so installing to a different path is intentional.
results := make([]batchResultItem, 0, len(body.Skills))
installOpts := install.InstallOptions{
@@ -148,20 +144,24 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) {
installOpts.AuditProjectRoot = s.projectRoot
}
for _, sel := range body.Skills {
destPath := filepath.Join(s.cfg.Source, body.Into, sel.Name)
skillName := sel.Name
if body.Name != "" && len(body.Skills) == 1 {
skillName = body.Name
}
destPath := filepath.Join(s.cfg.Source, body.Into, skillName)
res, err := install.InstallFromDiscovery(discovery, install.SkillInfo{
Name: sel.Name,
Path: sel.Path,
}, destPath, installOpts)
if err != nil {
results = append(results, batchResultItem{
Name: sel.Name,
Name: skillName,
Error: err.Error(),
})
continue
}
results = append(results, batchResultItem{
Name: sel.Name,
Name: skillName,
Action: res.Action,
Warnings: res.Warnings,
})
+1 -1
View File
@@ -244,7 +244,7 @@ export const api = {
method: 'POST',
body: JSON.stringify(opts),
}),
installBatch: (opts: { source: string; skills: DiscoveredSkill[]; force?: boolean; skipAudit?: boolean; into?: string }) =>
installBatch: (opts: { source: string; skills: DiscoveredSkill[]; force?: boolean; skipAudit?: boolean; into?: string; name?: string }) =>
apiFetch<BatchInstallResult>('/install/batch', {
method: 'POST',
body: JSON.stringify(opts),
+43 -26
View File
@@ -122,7 +122,6 @@ export default function InstallForm({
const [severityFilter, setSeverityFilter] = useState<string | null>(null);
const resetForm = () => {
setSource('');
setName('');
setInto('');
setTrack(false);
@@ -264,6 +263,7 @@ export default function InstallForm({
const allWarnings: string[] = [];
const auditFindings: string[] = [];
const auditBlockedSkills: DiscoveredSkill[] = [];
let installed = 0;
for (const item of res.results) {
if (item.error) {
if (isAuditBlock(item.error)) {
@@ -273,14 +273,19 @@ export default function InstallForm({
} else {
toast(`${item.name}: ${item.error}`, 'error');
}
} else {
installed++;
}
if (item.warnings?.length) allWarnings.push(...item.warnings.map((w) => `${item.name}: ${w}`));
}
toast(res.summary, auditBlockedSkills.length > 0 ? 'warning' : 'success');
if (allWarnings.length > 0) setWarningDialog(allWarnings);
resetForm();
invalidateAfterInstall();
onSuccess?.({ action: 'installed', warnings: [], skillName: res.summary });
if (installed > 0) {
const variant = auditBlockedSkills.length > 0 ? 'warning' : 'success';
toast(res.summary, variant as 'success' | 'warning');
if (allWarnings.length > 0) setWarningDialog(allWarnings);
resetForm();
invalidateAfterInstall();
onSuccess?.({ action: 'installed', warnings: [], skillName: res.summary });
}
if (auditBlockedSkills.length > 0) {
setAuditDialog({
findings: auditFindings,
@@ -314,10 +319,12 @@ export default function InstallForm({
into: into.trim() || undefined,
force,
skipAudit,
name: selected.length === 1 && name.trim() ? name.trim() : undefined,
});
const allWarnings: string[] = [];
const auditFindings: string[] = [];
const auditBlockedSkills: DiscoveredSkill[] = [];
let installed = 0;
for (const item of res.results) {
if (item.error) {
if (isAuditBlock(item.error)) {
@@ -327,16 +334,22 @@ export default function InstallForm({
} else {
toast(`${item.name}: ${item.error}`, 'error');
}
} else {
installed++;
}
if (item.warnings?.length) allWarnings.push(...item.warnings.map((w) => `${item.name}: ${w}`));
}
// Always show summary toast
toast(res.summary, auditBlockedSkills.length > 0 ? 'warning' : 'success');
if (allWarnings.length > 0) setWarningDialog(allWarnings);
setShowPicker(false);
resetForm();
invalidateAfterInstall();
onSuccess?.({ action: 'installed', warnings: [], skillName: res.summary });
// Only show summary + close picker when at least one skill installed
if (installed > 0) {
const variant = auditBlockedSkills.length > 0 ? 'warning' : 'success';
toast(res.summary, variant as 'success' | 'warning');
if (allWarnings.length > 0) setWarningDialog(allWarnings);
setShowPicker(false);
resetForm();
invalidateAfterInstall();
onSuccess?.({ action: 'installed', warnings: [], skillName: res.summary });
}
// Show audit dialog for blocked items only (force-retry targets just those)
if (auditBlockedSkills.length > 0) {
setAuditDialog({
@@ -395,13 +408,16 @@ export default function InstallForm({
{/* Optional overrides */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<Input
label="Custom name"
type="text"
placeholder="my-skill"
value={name}
onChange={(e) => setName(e.target.value)}
/>
<div>
<Input
label="Custom name"
type="text"
placeholder="my-skill"
value={name}
onChange={(e) => setName(e.target.value)}
/>
<p className="text-xs text-muted-dark mt-1">Only applies to single skill install</p>
</div>
<Input
label="Into directory"
type="text"
@@ -458,6 +474,7 @@ export default function InstallForm({
onInstall={handleBatchInstall}
onCancel={() => setShowPicker(false)}
installing={batchInstalling}
singleSelect={!!name.trim()}
/>
);
@@ -492,13 +509,13 @@ export default function InstallForm({
style={{ borderRadius: radius.md }}
>
{f.skillName && <div className="text-xs text-pencil-light font-mono">{f.skillName}</div>}
<div className="flex items-start gap-2">
<div className="flex items-center gap-2 flex-wrap">
<span
className="w-2 h-2 rounded-full shrink-0 mt-1.5"
className="w-2 h-2 rounded-full shrink-0"
style={{ backgroundColor: s.color }}
/>
<Badge variant={s.variant}>{f.severity}</Badge>
<span className="text-sm pt-0.5 leading-relaxed">{f.description}</span>
<span className="text-sm leading-relaxed">{f.description}</span>
</div>
{f.snippets.length > 0 && (
<div className="ml-1 pl-3 space-y-0.5">
@@ -555,13 +572,13 @@ export default function InstallForm({
style={{ borderRadius: radius.md }}
>
{f.skillName && <div className="text-xs text-pencil-light font-mono">{f.skillName}</div>}
<div className="flex items-start gap-2">
<div className="flex items-center gap-2 flex-wrap">
<span
className="w-2 h-2 rounded-full shrink-0 mt-1.5"
className="w-2 h-2 rounded-full shrink-0"
style={{ backgroundColor: s.color }}
/>
<Badge variant={s.variant}>{f.severity}</Badge>
<span className="text-sm pt-0.5 leading-relaxed">{f.description}</span>
<span className="text-sm leading-relaxed">{f.description}</span>
</div>
{f.snippets.length > 0 && (
<div className="ml-1 pl-3 space-y-0.5">
+75 -43
View File
@@ -13,6 +13,7 @@ interface SkillPickerModalProps {
onInstall: (selected: DiscoveredSkill[]) => void;
onCancel: () => void;
installing: boolean;
singleSelect?: boolean;
}
export default function SkillPickerModal({
@@ -22,6 +23,7 @@ export default function SkillPickerModal({
onInstall,
onCancel,
installing,
singleSelect,
}: SkillPickerModalProps) {
const [selected, setSelected] = useState<Set<string>>(new Set());
const [filter, setFilter] = useState('');
@@ -37,13 +39,13 @@ export default function SkillPickerModal({
);
}, [skills, filter]);
// Select all by default when modal opens; reset filter
// Reset selection when modal opens
useEffect(() => {
if (open) {
setSelected(new Set(skills.map((s) => s.path)));
setSelected(singleSelect ? new Set() : new Set(skills.map((s) => s.path)));
setFilter('');
}
}, [open, skills]);
}, [open, skills, singleSelect]);
if (!open) return null;
@@ -61,6 +63,11 @@ export default function SkillPickerModal({
};
const toggle = (path: string) => {
if (singleSelect) {
// Radio behavior: only one selected at a time
setSelected(selected.has(path) ? new Set() : new Set([path]));
return;
}
const next = new Set(selected);
if (next.has(path)) {
next.delete(path);
@@ -76,9 +83,9 @@ export default function SkillPickerModal({
};
return (
<DialogShell open={open} onClose={onCancel} maxWidth="md" preventClose={installing}>
<DialogShell open={open} onClose={onCancel} maxWidth="2xl" preventClose={installing}>
<h3 className="text-xl font-bold text-pencil mb-1">
Select Skills to Install
{singleSelect ? 'Select a Skill to Install' : 'Select Skills to Install'}
</h3>
<p className="text-sm text-pencil-light mb-4 truncate font-mono">
{source}
@@ -102,51 +109,76 @@ export default function SkillPickerModal({
</div>
)}
{/* Select All */}
<div className="flex items-center justify-between border-b border-dashed border-pencil-light/30 pb-2 mb-2">
<Checkbox
label={allFilteredSelected ? 'Deselect All' : 'Select All'}
checked={allFilteredSelected}
onChange={toggleAll}
/>
{filter && (
{/* Select All (multi-select only) */}
{!singleSelect && (
<div className="flex items-center justify-between border-b border-dashed border-pencil-light/30 pb-2 mb-2">
<Checkbox
label={allFilteredSelected ? 'Deselect All' : 'Select All'}
checked={allFilteredSelected}
onChange={toggleAll}
/>
{filter && (
<span className="text-xs text-muted-dark">
{filtered.length} of {skills.length} skills
</span>
)}
</div>
)}
{/* Single-select hint */}
{singleSelect && (
<div className="border-b border-dashed border-pencil-light/30 pb-2 mb-2">
<span className="text-xs text-muted-dark">
{filtered.length} of {skills.length} skills
Custom name is set — select one skill
{filter && ` (${filtered.length} of ${skills.length})`}
</span>
)}
</div>
</div>
)}
{/* Skill list */}
<div className="overflow-y-auto space-y-1 mb-4" style={{ maxHeight: '16rem' }}>
{filtered.map((skill) => (
<label
key={skill.path}
className="flex items-start gap-2 py-1.5 px-1 rounded-md cursor-pointer hover:bg-muted/30 transition-colors"
style={{ borderRadius: radius.sm }}
>
<Checkbox
label=""
checked={selected.has(skill.path)}
onChange={() => toggle(skill.path)}
size="sm"
/>
<div className="min-w-0 flex-1">
<span className="font-bold text-pencil text-base">
{skill.name}
</span>
{skill.path !== '.' && skill.path !== skill.name && (
<span className="block text-xs text-muted-dark truncate font-mono">
{skill.path}
{filtered.map((skill) => {
const isSelected = selected.has(skill.path);
return (
<label
key={skill.path}
className="flex items-start gap-2 py-1.5 px-1 rounded-md cursor-pointer hover:bg-muted/30 transition-colors"
style={{ borderRadius: radius.sm }}
>
{singleSelect ? (
<span
className={`mt-1 w-4 h-4 shrink-0 rounded-full border-2 flex items-center justify-center transition-colors ${
isSelected ? 'border-info bg-info' : 'border-muted-dark'
}`}
>
{isSelected && <span className="w-1.5 h-1.5 rounded-full bg-white" />}
</span>
) : (
<Checkbox
label=""
checked={isSelected}
onChange={() => toggle(skill.path)}
size="sm"
/>
)}
{skill.description && (
<span className="block text-sm text-pencil-light truncate">
{skill.description}
<div className="min-w-0 flex-1" onClick={singleSelect ? () => toggle(skill.path) : undefined}>
<span className="font-bold text-pencil text-base">
{skill.name}
</span>
)}
</div>
</label>
))}
{skill.path !== '.' && skill.path !== skill.name && (
<span className="block text-xs text-muted-dark truncate font-mono">
{skill.path}
</span>
)}
{skill.description && (
<span className="block text-sm text-pencil-light truncate">
{skill.description}
</span>
)}
</div>
</label>
);
})}
</div>
{/* Footer */}
@@ -167,7 +199,7 @@ export default function SkillPickerModal({
loading={installing}
>
<Download size={14} strokeWidth={2.5} />
Install Selected ({selected.size})
{singleSelect ? 'Install' : `Install Selected (${selected.size})`}
</Button>
</div>
</DialogShell>
+1 -1
View File
@@ -135,7 +135,7 @@ export function ToastProvider({ children }: { children: ReactNode }) {
<ToastContext.Provider value={{ toast: addToast }}>
{children}
{/* Toast container */}
<div data-toast-container className="fixed bottom-6 right-6 z-50 flex flex-col gap-3 max-w-sm">
<div data-toast-container className="fixed bottom-6 right-6 z-[60] flex flex-col gap-3 max-w-sm">
{toasts.map((t) => (
<ToastItem key={t.id} toast={t} onRemove={removeToast} />
))}
+58 -17
View File
@@ -1,44 +1,85 @@
import { useState, useRef, useCallback, type ReactNode } from 'react';
import { useState, useRef, useCallback, useLayoutEffect, type ReactNode } from 'react';
import { createPortal } from 'react-dom';
interface TooltipProps {
children: ReactNode;
content: string;
side?: 'top' | 'bottom';
followCursor?: boolean;
}
export default function Tooltip({ children, content, side = 'bottom' }: TooltipProps) {
const OFFSET = 12;
const MARGIN = 8;
export default function Tooltip({ children, content, side = 'bottom', followCursor }: TooltipProps) {
const [pos, setPos] = useState<{ x: number; y: number } | null>(null);
const timerRef = useRef<ReturnType<typeof setTimeout>>(undefined);
const visibleRef = useRef(false);
const tooltipRef = useRef<HTMLDivElement>(null);
// Render at (0,0) hidden → measure natural size → clamp → show
useLayoutEffect(() => {
const el = tooltipRef.current;
if (!el || !pos) return;
const w = el.offsetWidth;
const h = el.offsetHeight;
const vw = window.innerWidth;
const vh = window.innerHeight;
let x = pos.x;
let y = pos.y;
if (x + w > vw - MARGIN) x = pos.x - w - OFFSET * 2;
if (x < MARGIN) x = MARGIN;
if (y + h > vh - MARGIN) y = pos.y - h - OFFSET * 2;
if (y < MARGIN) y = MARGIN;
el.style.left = `${x}px`;
el.style.top = `${y}px`;
el.style.visibility = 'visible';
}, [pos]);
const show = useCallback((e: React.MouseEvent) => {
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
timerRef.current = setTimeout(() => {
setPos({
x: rect.left,
y: side === 'top' ? rect.top - 4 : rect.bottom + 4,
});
}, 200);
}, [side]);
if (followCursor) {
const x = e.clientX + OFFSET;
const y = e.clientY + OFFSET;
timerRef.current = setTimeout(() => {
visibleRef.current = true;
setPos({ x, y });
}, 200);
} else {
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
timerRef.current = setTimeout(() => {
setPos({
x: rect.left,
y: side === 'top' ? rect.top - 4 : rect.bottom + 4,
});
}, 200);
}
}, [side, followCursor]);
const move = useCallback((e: React.MouseEvent) => {
if (visibleRef.current) {
setPos({ x: e.clientX + OFFSET, y: e.clientY + OFFSET });
}
}, []);
const hide = useCallback(() => {
if (timerRef.current) clearTimeout(timerRef.current);
visibleRef.current = false;
setPos(null);
}, []);
return (
<>
<span onMouseEnter={show} onMouseLeave={hide}>
<span onMouseEnter={show} onMouseLeave={hide} onMouseMove={followCursor ? move : undefined}>
{children}
</span>
{pos && createPortal(
<div
className="ss-tooltip fixed z-[9999] max-w-sm break-all whitespace-pre-line bg-pencil text-paper text-xs px-2.5 py-1.5 shadow-lg pointer-events-none animate-fade-in rounded-[var(--radius-sm)]"
style={{
left: pos.x,
top: pos.y,
...(side === 'top' ? { transform: 'translateY(-100%)' } : {}),
}}
ref={tooltipRef}
className="ss-tooltip fixed z-[9999] max-w-sm whitespace-pre-line bg-pencil text-paper text-xs px-2.5 py-1.5 shadow-lg pointer-events-none animate-fade-in rounded-[var(--radius-sm)]"
style={{ left: 0, top: 0, visibility: 'hidden' }}
>
{content}
</div>,
+7 -7
View File
@@ -359,18 +359,18 @@ function TopHeaviestChart({ skills }: { skills: AnalyzeSkill[] }) {
<div className="space-y-1.5">
{sorted.map((skill, idx) => {
const pct = maxTokens > 0 ? (skill.description_tokens / maxTokens) * 100 : 0;
const tooltipText = `Description: ${formatTokens(skill.description_tokens)} tokens\nBody: ${formatTokens(skill.body_tokens)} tokens\nTotal: ${formatTokens(skill.description_tokens + skill.body_tokens)} tokens`;
const tooltipText = `${skill.path}\n---\nDescription: ${formatTokens(skill.description_tokens)} tokens\nBody: ${formatTokens(skill.body_tokens)} tokens\nTotal: ${formatTokens(skill.description_tokens + skill.body_tokens)} tokens`;
return (
<Tooltip key={skill.name} content={tooltipText}>
<div className="flex items-center gap-2 group py-0.5">
<Tooltip key={skill.name} content={tooltipText} followCursor>
<div className="flex items-center gap-2 group py-0.5 px-1 -mx-1 rounded-[var(--radius-sm)] hover:bg-info/8 transition-colors cursor-default">
<span className="text-xs text-pencil-light font-mono shrink-0 w-5 text-right">
{idx + 1}
</span>
<span
className="text-sm text-pencil truncate shrink-0"
style={{ width: '150px' }}
style={{ width: '220px' }}
>
{skill.name}
{skill.path}
</span>
<div className="flex-1 h-5 bg-muted/30 overflow-hidden" style={{ borderRadius: radius.sm }}>
<div
@@ -706,7 +706,7 @@ function SkillTable({
>
<td className="py-3 pr-4">
<div className="flex items-center gap-2">
<span className="font-medium text-pencil truncate hover:underline">{skill.name}</span>
<span className="font-medium text-pencil truncate hover:underline">{skill.path}</span>
{skill.is_tracked && <Badge variant="info" size="sm">tracked</Badge>}
</div>
</td>
@@ -777,7 +777,7 @@ function SkillDetailDialog({
<div className="flex items-center justify-between mb-5">
<div className="flex items-center gap-2 min-w-0">
<FileText size={20} strokeWidth={2.5} className="text-pencil shrink-0" />
<h2 className="text-lg font-bold text-pencil truncate">{skill.name}</h2>
<h2 className="text-lg font-bold text-pencil truncate">{skill.path}</h2>
{skill.is_tracked && <Badge variant="info" size="sm">tracked</Badge>}
</div>
<button onClick={onClose} className="w-8 h-8 flex items-center justify-center text-pencil-light hover:text-pencil transition-colors cursor-pointer shrink-0" aria-label="Close">