diff --git a/ui/src/pages/ConfigPage.tsx b/ui/src/pages/ConfigPage.tsx index dd1e72766..67bd9a634 100644 --- a/ui/src/pages/ConfigPage.tsx +++ b/ui/src/pages/ConfigPage.tsx @@ -370,8 +370,8 @@ export default function ConfigPage() { {/* Assistant panel */}
@@ -407,8 +407,8 @@ export default function ConfigPage() {
diff --git a/ui/src/pages/SkillsPage.tsx b/ui/src/pages/SkillsPage.tsx index c9716c00d..3470d9b1e 100644 --- a/ui/src/pages/SkillsPage.tsx +++ b/ui/src/pages/SkillsPage.tsx @@ -1,5 +1,5 @@ import { useState, useMemo, useCallback, useEffect, forwardRef, memo, type ReactElement } from 'react'; -import { Link } from 'react-router-dom'; +import { Link, useNavigate } from 'react-router-dom'; import { Search, GitBranch, @@ -16,13 +16,21 @@ import { ChevronDown, ChevronsUpDown, ChevronsDownUp, + Target, + MoreHorizontal, + Trash2, + Eye, + EyeOff, + ExternalLink, + MousePointerClick, + X, } from 'lucide-react'; -import { useQuery } from '@tanstack/react-query'; +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { VirtuosoGrid, Virtuoso } from 'react-virtuoso'; import type { GridComponents } from 'react-virtuoso'; import { queryKeys, staleTimes } from '../lib/queryKeys'; import Badge from '../components/Badge'; -import { Input, Select } from '../components/Input'; +import { Input, Select, type SelectOption } from '../components/Input'; import { PageSkeleton } from '../components/Skeleton'; import EmptyState from '../components/EmptyState'; import Card from '../components/Card'; @@ -36,6 +44,9 @@ import { radius } from '../design'; import ScrollToTop from '../components/ScrollToTop'; import Tooltip from '../components/Tooltip'; import { parseRemoteURL } from '../lib/parseRemoteURL'; +import { useToast } from '../components/Toast'; +import TargetMenu, { SkillContextMenu, type ContextMenuItem } from '../components/TargetMenu'; +import ConfirmDialog from '../components/ConfirmDialog'; /* -- Sticky-note pastel palette (8 colors) --------- */ @@ -50,6 +61,123 @@ const SKILL_PASTELS_DARK = [ 'rgba(224,247,250,0.08)', 'rgba(251,233,231,0.08)', ]; +/* -- Shared skill action items hook --------------- */ + +type SkillsData = { skills: Skill[] }; + +/** Optimistic update helper: patch skills cache and return rollback snapshot. */ +function optimisticPatch( + queryClient: ReturnType, + patchFn: (skills: Skill[]) => Skill[], +) { + queryClient.cancelQueries({ queryKey: queryKeys.skills.all }); + const previous = queryClient.getQueryData(queryKeys.skills.all); + if (previous) { + queryClient.setQueryData(queryKeys.skills.all, { + ...previous, + skills: patchFn(previous.skills), + }); + } + return previous; +} + +function useSkillActions() { + const queryClient = useQueryClient(); + const { toast } = useToast(); + const navigate = useNavigate(); + + const toggleMutation = useMutation({ + mutationFn: ({ name, disable }: { name: string; disable: boolean }) => + disable ? api.disableSkill(name) : api.enableSkill(name), + onMutate: async ({ name, disable }) => { + const previous = optimisticPatch(queryClient, (skills) => + skills.map((s) => s.flatName === name ? { ...s, disabled: disable } : s), + ); + return { previous }; + }, + onSuccess: (_, { name, disable }) => { + toast(`${name} ${disable ? 'disabled' : 'enabled'}`, 'success'); + }, + onError: (err: Error, _, ctx) => { + if (ctx?.previous) queryClient.setQueryData(queryKeys.skills.all, ctx.previous); + toast(err.message, 'error'); + }, + onSettled: () => queryClient.invalidateQueries({ queryKey: queryKeys.skills.all }), + }); + + const uninstallMutation = useMutation({ + mutationFn: (name: string) => api.deleteSkill(name), + onMutate: async (name) => { + const previous = optimisticPatch(queryClient, (skills) => + skills.filter((s) => s.flatName !== name), + ); + return { previous }; + }, + onSuccess: (_, name) => { + toast(`Uninstalled ${name}`, 'success'); + }, + onError: (err: Error, _, ctx) => { + if (ctx?.previous) queryClient.setQueryData(queryKeys.skills.all, ctx.previous); + toast(err.message, 'error'); + }, + onSettled: () => queryClient.invalidateQueries({ queryKey: queryKeys.skills.all }), + }); + + /** Optimistic target update for a single skill. */ + const setTargetMutation = useMutation({ + mutationFn: ({ name, target }: { name: string; target: string | null }) => + api.setSkillTargets(name, target), + onMutate: async ({ name, target }) => { + const previous = optimisticPatch(queryClient, (skills) => + skills.map((s) => s.flatName === name + ? { ...s, targets: target ? [target] : undefined } + : s, + ), + ); + return { previous }; + }, + onSuccess: (_, { name, target }) => { + toast(`${name} now available in ${target ?? 'All'}`, 'success'); + }, + onError: (err: Error, _, ctx) => { + if (ctx?.previous) queryClient.setQueryData(queryKeys.skills.all, ctx.previous); + toast(err.message, 'error'); + }, + onSettled: () => queryClient.invalidateQueries({ queryKey: queryKeys.skills.all }), + }); + + /** Build extra context menu items for a single skill. */ + function buildSkillExtraItems( + skill: { flatName: string; name: string; disabled?: boolean }, + onUninstall: () => void, + ): ContextMenuItem[] { + return [ + { + key: 'detail', + label: 'View Detail', + icon: , + onSelect: () => navigate(`/skills/${encodeURIComponent(skill.flatName)}`), + }, + { + key: 'toggle', + label: skill.disabled ? 'Enable' : 'Disable', + icon: skill.disabled + ? + : , + onSelect: () => toggleMutation.mutate({ name: skill.flatName, disable: !skill.disabled }), + }, + { + key: 'uninstall', + label: 'Uninstall', + icon: , + onSelect: onUninstall, + }, + ]; + } + + return { uninstallMutation, setTargetMutation, buildSkillExtraItems }; +} + /** Deterministic hash → palette index. Same string always maps to same color. */ function hashToIndex(s: string, len: number): number { let h = 0; @@ -64,12 +192,21 @@ function shortSource(source: string): string { /* -- Folder tree types & helpers -------------------- */ +interface TargetSummary { + display: string; // "All" | "claude" | "claude, cursor" | "3 targets" + targets: string[]; // full union list (sorted) + isUniform: boolean; // all skills in subtree have identical target sets +} + +const defaultTargetSummary: TargetSummary = { display: 'All', targets: [], isUniform: true }; + interface FolderNode { name: string; path: string; children: Map; skills: Skill[]; skillCount: number; + targetSummary: TargetSummary; } interface TreeNode { @@ -80,11 +217,12 @@ interface TreeNode { skill?: Skill; childCount: number; isRoot?: boolean; + targetSummary?: TargetSummary; } /** Build a nested folder tree from skills' relPath values. Computes skillCount bottom-up. */ function buildTree(skills: Skill[]): FolderNode { - const root: FolderNode = { name: '', path: '', children: new Map(), skills: [], skillCount: 0 }; + const root: FolderNode = { name: '', path: '', children: new Map(), skills: [], skillCount: 0, targetSummary: defaultTargetSummary }; for (const skill of skills) { const rp = skill.relPath ?? ''; const lastSlash = rp.lastIndexOf('/'); @@ -99,7 +237,7 @@ function buildTree(skills: Skill[]): FolderNode { for (const seg of segments) { currentPath = currentPath ? `${currentPath}/${seg}` : seg; if (!node.children.has(seg)) { - node.children.set(seg, { name: seg, path: currentPath, children: new Map(), skills: [], skillCount: 0 }); + node.children.set(seg, { name: seg, path: currentPath, children: new Map(), skills: [], skillCount: 0, targetSummary: defaultTargetSummary }); } node = node.children.get(seg)!; } @@ -113,6 +251,54 @@ function buildTree(skills: Skill[]): FolderNode { return count; } computeCounts(root); + + // Compute targetSummary bottom-up + // Bottom-up: each node returns its collected target key sets. + // Children are already computed, so we just merge — O(n) total. + function computeTargets(node: FolderNode): string[][] { + const allSets: string[][] = []; + // Direct skills + for (const sk of node.skills) { + allSets.push(sk.targets && sk.targets.length > 0 ? [...sk.targets].sort() : []); + } + // Merge children's sets (already computed) + for (const child of node.children.values()) { + allSets.push(...computeTargets(child)); + } + + if (allSets.length === 0) { + node.targetSummary = defaultTargetSummary; + return allSets; + } + + const first = allSets[0]; + const isUniform = allSets.every( + (s) => s.length === first.length && s.every((v, i) => v === first[i]), + ); + + if (isUniform) { + if (first.length === 0) { + node.targetSummary = { display: 'All', targets: [], isUniform: true }; + } else { + const display = first.length > 3 ? `${first.length} targets` : first.join(', '); + node.targetSummary = { display, targets: first, isUniform: true }; + } + } else { + const unionSet = new Set(); + let hasAll = false; + for (const s of allSets) { + if (s.length === 0) hasAll = true; + else s.forEach((v) => unionSet.add(v)); + } + const union = [...unionSet].sort(); + const displayTargets = hasAll ? ['All', ...union] : union; + const display = displayTargets.length > 3 ? `${displayTargets.length} targets` : displayTargets.join(', '); + node.targetSummary = { display, targets: union, isUniform: false }; + } + return allSets; + } + computeTargets(root); + return root; } @@ -136,6 +322,7 @@ function flattenTree( path: child.path, depth, childCount: cc, + targetSummary: child.targetSummary, }); const isCollapsed = !isSearching && collapsed.has(child.path); if (!isCollapsed) { @@ -166,6 +353,7 @@ function flattenTree( path: child.path, depth: 0, childCount: cc, + targetSummary: child.targetSummary, }); const isCollapsed = !isSearching && collapsed.has(child.path); if (!isCollapsed) { @@ -182,6 +370,7 @@ function flattenTree( depth: 0, childCount: root.skills.length, isRoot: true, + targetSummary: root.targetSummary, }); const rootCollapsed = !isSearching && collapsed.has(''); if (!rootCollapsed) { @@ -329,8 +518,12 @@ const gridComponents: GridComponents = { const SkillPostit = memo(function SkillPostit({ skill, + onContextMenu, + highlighted = false, }: { skill: Skill; + onContextMenu?: (e: React.MouseEvent) => void; + highlighted?: boolean; }) { // Extract repo name from relPath (e.g., "_awesome-skillshare-skills/frontend-dugong" -> "awesome-skillshare-skills") const repoName = skill.isInRepo && skill.relPath.startsWith('_') @@ -342,9 +535,13 @@ const SkillPostit = memo(function SkillPostit({ const colorIdx = hashToIndex(colorKey, SKILL_PASTELS.length); return ( - +
)} + {skill.targets && skill.targets.length > 0 && ( + + + {skill.targets.length > 2 ? `${skill.targets.length} targets` : skill.targets.join(', ')} + + )}
@@ -402,6 +605,40 @@ const SkillPostit = memo(function SkillPostit({ ); }); +/* -- Right-click tip banner ----------------------- */ + +const TIP_DISMISSED_KEY = 'skillshare:skills-context-menu-tip'; + +function ContextMenuTip() { + const [dismissed, setDismissed] = useState(() => + localStorage.getItem(TIP_DISMISSED_KEY) === '1', + ); + + if (dismissed) return null; + + return ( +
+ +

+ Right-click any skill or folder for quick actions — set target, enable/disable, uninstall, and more. +

+ +
+ ); +} + /* -- Main page ------------------------------------ */ export default function SkillsPage() { @@ -431,6 +668,21 @@ export default function SkillsPage() { localStorage.setItem('skillshare:skills-view', v); }; + const [gridContextMenu, setGridContextMenu] = useState<{ + point: { x: number; y: number }; + skillFlatName: string; + skillName: string; + disabled: boolean; + currentTargets: string[] | null; + } | null>(null); + + const { uninstallMutation: gridUninstallMutation, setTargetMutation: gridSingleMutation, buildSkillExtraItems } = useSkillActions(); + + const [gridConfirmUninstall, setGridConfirmUninstall] = useState<{ + flatName: string; + name: string; + } | null>(null); + const skills = data?.skills ?? []; // Compute counts for each filter type (before text search, so chips always show totals) @@ -572,6 +824,9 @@ export default function SkillsPage() {

)} + {/* Right-click tip — shown once, dismissed permanently */} + + {/* Skills grid / grouped / table view */} {filtered.length > 0 ? ( viewType === 'grid' ? ( @@ -584,9 +839,25 @@ export default function SkillsPage() { enter: (velocity) => Math.abs(velocity) > 800, exit: (velocity) => Math.abs(velocity) < 200, }} - itemContent={(index) => ( - - )} + itemContent={(index) => { + const skill = filtered[index]; + return ( + { + e.preventDefault(); + setGridContextMenu({ + point: { x: e.clientX, y: e.clientY }, + skillFlatName: skill.flatName, + skillName: skill.name, + disabled: !!skill.disabled, + currentTargets: skill.targets ?? null, + }); + }} + /> + ); + }} /> ) : viewType === 'grouped' ? ( + + {gridContextMenu && ( + setGridConfirmUninstall({ flatName: gridContextMenu.skillFlatName, name: gridContextMenu.skillName }), + )} + onSelect={(target) => { + gridSingleMutation.mutate({ name: gridContextMenu.skillFlatName, target }); + setGridContextMenu(null); + }} + onClose={() => setGridContextMenu(null)} + /> + )} + Are you sure you want to uninstall {gridConfirmUninstall?.name}?} + confirmText="Uninstall" + variant="danger" + loading={gridUninstallMutation.isPending} + onConfirm={() => { + if (gridConfirmUninstall) gridUninstallMutation.mutate(gridConfirmUninstall.flatName); + setGridConfirmUninstall(null); + }} + onCancel={() => setGridConfirmUninstall(null)} + /> ); } @@ -630,6 +932,37 @@ function FolderTreeView({ skills, totalCount, isSearching, stickyTop = 0, onClea }) { const [collapsed, setCollapsed] = useState>(loadCollapsed); const [stickyFolder, setStickyFolder] = useState<{ node: TreeNode; index: number } | null>(null); + const [contextMenu, setContextMenu] = useState<{ + point: { x: number; y: number }; + mode: 'folder' | 'skill'; + folderPath?: string; + skillFlatName?: string; + skillName?: string; + disabled?: boolean; + currentTargets: string[] | null; + isUniform: boolean; + } | null>(null); + + const queryClient = useQueryClient(); + const { toast } = useToast(); + const { uninstallMutation, setTargetMutation: singleMutation, buildSkillExtraItems: buildExtraItems } = useSkillActions(); + + const batchMutation = useMutation({ + mutationFn: ({ folder, target }: { folder: string; target: string | null }) => + api.batchSetTargets(folder, target), + onSuccess: (data, { folder, target }) => { + const label = target ?? 'All'; + const folderLabel = folder || '(root)'; + toast(`${data.updated} skill${data.updated !== 1 ? 's' : ''} in ${folderLabel}/ now available in ${label}`, 'success'); + }, + onSettled: () => queryClient.invalidateQueries({ queryKey: queryKeys.skills.all }), + onError: (err: Error) => toast(err.message, 'error'), + }); + + const [confirmUninstall, setConfirmUninstall] = useState<{ + flatName: string; + name: string; + } | null>(null); const tree = useMemo(() => buildTree(skills), [skills]); @@ -726,9 +1059,19 @@ function FolderTreeView({ skills, totalCount, isSearching, stickyTop = 0, onClea return (
toggleFolder(node.path)} + onContextMenu={(e) => { + e.preventDefault(); + setContextMenu({ + point: { x: e.clientX, y: e.clientY }, + mode: 'folder', + folderPath: node.path, + currentTargets: node.targetSummary?.targets ?? null, + isUniform: node.targetSummary?.isUniform ?? true, + }); + }} role="treeitem" aria-expanded={!isFolderCollapsed} > @@ -750,6 +1093,20 @@ function FolderTreeView({ skills, totalCount, isSearching, stickyTop = 0, onClea > {node.childCount} + {node.targetSummary && ( + + 0 + ? node.targetSummary.targets.join(', ') + : 'All targets' + }> + + + {node.targetSummary.display} + + + + )}
); } @@ -769,11 +1126,25 @@ function FolderTreeView({ skills, totalCount, isSearching, stickyTop = 0, onClea ); return ( -
+
{ + e.preventDefault(); + setContextMenu({ + point: { x: e.clientX, y: e.clientY }, + mode: 'skill', + skillFlatName: skill.flatName, + skillName: skill.name, + disabled: !!skill.disabled, + currentTargets: skill.targets ?? null, + isUniform: true, + }); + }} + > {indentGuides} @@ -794,12 +1165,18 @@ function FolderTreeView({ skills, totalCount, isSearching, stickyTop = 0, onClea {skill.branch} )} + 0 ? skill.targets.join(', ') : 'All targets'}> + + + {skill.targets && skill.targets.length > 0 ? skill.targets.join(', ') : 'All'} + +
); - }, [rows, collapsed, isSearching, toggleFolder]); + }, [rows, collapsed, isSearching, toggleFolder, setContextMenu, contextMenu]); return (
@@ -861,6 +1238,20 @@ function FolderTreeView({ skills, totalCount, isSearching, stickyTop = 0, onClea > {stickyFolder.node.childCount} + {stickyFolder.node.targetSummary && ( + + 0 + ? stickyFolder.node.targetSummary.targets.join(', ') + : 'All targets' + }> + + + {stickyFolder.node.targetSummary.display} + + + + )}
)} @@ -872,6 +1263,42 @@ function FolderTreeView({ skills, totalCount, isSearching, stickyTop = 0, onClea overscan={600} itemContent={renderItem} /> + + {contextMenu && ( + setConfirmUninstall({ flatName: contextMenu.skillFlatName!, name: contextMenu.skillName ?? contextMenu.skillFlatName! }), + ) : undefined} + onSelect={(target) => { + if (contextMenu.mode === 'folder') { + batchMutation.mutate({ folder: contextMenu.folderPath ?? '', target }); + } else { + singleMutation.mutate({ name: contextMenu.skillFlatName!, target }); + } + setContextMenu(null); + }} + onClose={() => setContextMenu(null)} + /> + )} + Are you sure you want to uninstall {confirmUninstall?.name}?} + confirmText="Uninstall" + variant="danger" + loading={uninstallMutation.isPending} + onConfirm={() => { + if (confirmUninstall) uninstallMutation.mutate(confirmUninstall.flatName); + setConfirmUninstall(null); + }} + onCancel={() => setConfirmUninstall(null)} + /> ); } @@ -882,17 +1309,60 @@ const TABLE_PAGE_SIZES = [10, 25, 50] as const; function SkillsTable({ skills }: { skills: Skill[] }) { const [page, setPage] = useState(0); - const [pageSize, setPageSize] = useState(10); + const [pageSize, setPageSize] = useState(() => { + const saved = localStorage.getItem('skillshare:table-page-size'); + const n = saved ? parseInt(saved, 10) : 0; + return TABLE_PAGE_SIZES.includes(n as any) ? n : 10; + }); const [prevSkills, setPrevSkills] = useState(skills); if (skills !== prevSkills) { setPrevSkills(skills); setPage(0); } + const [actionMenu, setActionMenu] = useState<{ + point: { x: number; y: number }; + skillFlatName: string; + skillName: string; + disabled: boolean; + } | null>(null); + const [confirmUninstall, setConfirmUninstall] = useState<{ + flatName: string; + name: string; + } | null>(null); + + const queryClient = useQueryClient(); + const { toast } = useToast(); + const { uninstallMutation, setTargetMutation: targetMutation, buildSkillExtraItems: buildTableExtraItems } = useSkillActions(); + + // Available targets for the inline Select + const { data: availableData } = useQuery({ + queryKey: queryKeys.targets.available, + queryFn: () => api.availableTargets(), + staleTime: staleTimes.targets, + }); + const targetOptions: SelectOption[] = useMemo(() => { + const installed = (availableData?.targets ?? []).filter((t) => t.installed); + return [ + { value: '__all__', label: 'All' }, + ...installed.map((t) => ({ value: t.name, label: t.name })), + ]; + }, [availableData]); + + // targetMutation from useSkillActions (optimistic) + const totalPages = Math.max(1, Math.ceil(skills.length / pageSize)); const start = page * pageSize; const visible = skills.slice(start, start + pageSize); + // Build action menu items + const actionItems: ContextMenuItem[] = actionMenu + ? buildTableExtraItems( + { flatName: actionMenu.skillFlatName, name: actionMenu.skillName, disabled: actionMenu.disabled }, + () => setConfirmUninstall({ flatName: actionMenu.skillFlatName, name: actionMenu.skillName }), + ) + : []; + return (
@@ -901,69 +1371,119 @@ function SkillsTable({ skills }: { skills: Skill[] }) { Name - Path Type - Source + Available in + - {visible.map((skill) => ( - - {/* Status stripe */} - -
- - {/* Name */} - - - { + const currentValue = skill.targets?.length === 1 ? skill.targets[0] : '__all__'; + const showPath = skill.relPath !== skill.name; + return ( + + {/* Status stripe */} + +
+ + {/* Name + path subtitle + source */} + +
+
+ + {skill.name} + + {showPath && ( + + {skill.relPath} + + )} +
+ {skill.source && (() => { + const parsed = parseRemoteURL(skill.source); + const raw = parsed?.webURL ?? skill.source; + const href = raw.startsWith('http') ? raw : `https://${raw}`; + return ( + + e.stopPropagation()}> + + + + ); + })()} +
+ + {/* Type badges */} + +
+ {skill.disabled && disabled} + {skill.isInRepo ? ( + tracked + ) : getTypeLabel(skill.type) ? ( + {getTypeLabel(skill.type)} + ) : ( + local + )} + {skill.branch && ( + + + {skill.branch} + + )} +
+ + {/* Available in — inline Select */} + e.stopPropagation()}> +