mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
feat(ui): add table view with pagination, virtualize grouped view, improve audit dialogs
Skills page gains a third "table" view with paginated list (10/25/50), hover tooltips via createPortal, and localStorage persistence for the selected view. Grouped view now uses Virtuoso for smooth scrolling with large skill sets. Install/audit dialogs refactored to card-based findings with severity filter badges, structured grouping, and increased max-height. Confirm dialog buttons bumped to medium size.
This commit is contained in:
@@ -72,7 +72,7 @@ export default function ConfirmDialog({
|
||||
{cancelText && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
size="md"
|
||||
onClick={onCancel}
|
||||
disabled={loading}
|
||||
>
|
||||
@@ -81,7 +81,7 @@ export default function ConfirmDialog({
|
||||
)}
|
||||
<Button
|
||||
variant={variant === 'danger' ? 'danger' : 'primary'}
|
||||
size="sm"
|
||||
size="md"
|
||||
onClick={onConfirm}
|
||||
disabled={loading}
|
||||
>
|
||||
|
||||
@@ -34,6 +34,51 @@ function isAuditBlock(msg: string): boolean {
|
||||
return msg.includes('security audit failed');
|
||||
}
|
||||
|
||||
/** Severity → badge variant + left-border color */
|
||||
const severityStyle = (sev: string) => {
|
||||
if (sev === 'CRITICAL') return { variant: 'danger' as const, color: 'var(--color-danger)' };
|
||||
if (sev === 'HIGH') return { variant: 'warning' as const, color: 'var(--color-warning)' };
|
||||
return { variant: 'default' as const, color: 'var(--color-muted-dark)' };
|
||||
};
|
||||
|
||||
interface GroupedFinding {
|
||||
skillName?: string;
|
||||
severity: string;
|
||||
description: string;
|
||||
snippets: string[];
|
||||
}
|
||||
|
||||
/** Group flat audit lines into structured card data */
|
||||
function groupAuditFindings(lines: string[]): GroupedFinding[] {
|
||||
const groups: GroupedFinding[] = [];
|
||||
let skill: string | undefined;
|
||||
for (const line of lines) {
|
||||
if (line.endsWith(':') && !/^(CRITICAL|HIGH|MEDIUM|LOW|INFO):/.test(line)) {
|
||||
skill = line.replace(/:$/, '');
|
||||
} else {
|
||||
const m = line.match(/^(CRITICAL|HIGH|MEDIUM|LOW|INFO):\s*(.*)/);
|
||||
if (m) groups.push({ skillName: skill, severity: m[1], description: m[2], snippets: [] });
|
||||
else if (line.startsWith('"') && groups.length > 0) groups[groups.length - 1].snippets.push(line);
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
/** Parse warning strings into structured card data */
|
||||
function parseWarnings(warnings: string[]): GroupedFinding[] {
|
||||
return warnings.map((w) => {
|
||||
const lines = w.split('\n');
|
||||
const header = lines[0];
|
||||
const snippets = lines.slice(1).map((l) => l.trim()).filter(Boolean);
|
||||
const sm = header.match(/^(.+?):\s*(audit\s+.*)/);
|
||||
const skillName = sm ? sm[1] : undefined;
|
||||
const h = sm ? sm[2] : header;
|
||||
const severity = h.includes('CRITICAL') ? 'CRITICAL' : h.includes('HIGH') ? 'HIGH' : 'MEDIUM';
|
||||
const description = h.replace(/^audit\s+(HIGH|MEDIUM|CRITICAL|INFO):\s*/, '');
|
||||
return { skillName, severity, description, snippets };
|
||||
});
|
||||
}
|
||||
|
||||
/** Saved install params for force-retry */
|
||||
interface PendingInstall {
|
||||
type: 'single' | 'batch' | 'track';
|
||||
@@ -73,6 +118,7 @@ export default function InstallForm({
|
||||
} | null>(null);
|
||||
const [auditForcing, setAuditForcing] = useState(false);
|
||||
const [warningDialog, setWarningDialog] = useState<string[] | null>(null);
|
||||
const [severityFilter, setSeverityFilter] = useState<string | null>(null);
|
||||
|
||||
const resetForm = () => {
|
||||
setSource('');
|
||||
@@ -167,6 +213,7 @@ export default function InstallForm({
|
||||
} finally {
|
||||
setAuditForcing(false);
|
||||
setAuditDialog(null);
|
||||
setSeverityFilter(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -303,6 +350,28 @@ export default function InstallForm({
|
||||
}
|
||||
};
|
||||
|
||||
// Pre-compute grouped findings for card-based rendering
|
||||
const auditFindings = auditDialog ? groupAuditFindings(auditDialog.findings) : [];
|
||||
const auditCounts: Record<string, number> = {};
|
||||
for (const f of auditFindings) auditCounts[f.severity] = (auditCounts[f.severity] ?? 0) + 1;
|
||||
const warningFindings = warningDialog ? parseWarnings(warningDialog) : [];
|
||||
const warningCounts: Record<string, number> = {};
|
||||
for (const f of warningFindings) warningCounts[f.severity] = (warningCounts[f.severity] ?? 0) + 1;
|
||||
|
||||
const filteredAudit = severityFilter ? auditFindings.filter((f) => f.severity === severityFilter) : auditFindings;
|
||||
const filteredWarnings = severityFilter ? warningFindings.filter((f) => f.severity === severityFilter) : warningFindings;
|
||||
|
||||
const filterBadge = (severity: string, count: number | undefined, variant: 'danger' | 'warning' | 'default', label: string) =>
|
||||
count ? (
|
||||
<button
|
||||
onClick={() => setSeverityFilter(severityFilter === severity ? null : severity)}
|
||||
className={`cursor-pointer transition-opacity ${severityFilter && severityFilter !== severity ? 'opacity-40' : ''}`}
|
||||
style={{ background: 'none', border: 'none', padding: 0 }}
|
||||
>
|
||||
<Badge variant={variant}>{count} {label}</Badge>
|
||||
</button>
|
||||
) : null;
|
||||
|
||||
const formContent = (
|
||||
<Card variant="default" className="animate-fade-in">
|
||||
<div className="space-y-4">
|
||||
@@ -376,28 +445,46 @@ export default function InstallForm({
|
||||
wide
|
||||
title="Security Threats Detected"
|
||||
message={
|
||||
<div className="text-left space-y-2">
|
||||
<div className="flex items-center gap-2 justify-center mb-3">
|
||||
<div className="text-left space-y-3">
|
||||
<div className="flex items-center gap-2 justify-center mb-1">
|
||||
<ShieldAlert size={20} className="text-danger" />
|
||||
<span>Critical issues found during security audit</span>
|
||||
</div>
|
||||
<div
|
||||
className="bg-paper border border-danger/30 p-4 space-y-3 text-sm text-pencil max-h-64 overflow-y-auto"
|
||||
style={{ borderRadius: '6px' }}
|
||||
>
|
||||
{auditDialog?.findings.map((line, i) => (
|
||||
<div key={i} className={line.startsWith('"') ? 'text-pencil-light pl-4' : ''}>
|
||||
{line.startsWith('CRITICAL:') ? (
|
||||
<span><Badge variant="danger">CRITICAL</Badge> {line.replace('CRITICAL: ', '')}</span>
|
||||
) : line.startsWith('HIGH:') ? (
|
||||
<span><Badge variant="warning">HIGH</Badge> {line.replace('HIGH: ', '')}</span>
|
||||
) : (
|
||||
line
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<div className="flex flex-wrap gap-1.5 items-center text-xs text-pencil-light">
|
||||
<span>{auditFindings.length} {auditFindings.length === 1 ? 'finding' : 'findings'}:</span>
|
||||
{filterBadge('CRITICAL', auditCounts.CRITICAL, 'danger', 'Critical')}
|
||||
{filterBadge('HIGH', auditCounts.HIGH, 'warning', 'High')}
|
||||
{filterBadge('MEDIUM', auditCounts.MEDIUM, 'default', 'Medium')}
|
||||
{severityFilter && (
|
||||
<span className="text-pencil-light">— showing {filteredAudit.length}</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-pencil-light mt-2">
|
||||
<div className="space-y-2 max-h-[32rem] overflow-y-auto pr-1">
|
||||
{filteredAudit.map((f, i) => {
|
||||
const s = severityStyle(f.severity);
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
className="border border-muted bg-paper p-3 space-y-1.5"
|
||||
style={{ borderRadius: '6px', borderLeftWidth: '3px', borderLeftColor: s.color }}
|
||||
>
|
||||
{f.skillName && <div className="text-xs text-pencil-light font-mono">{f.skillName}</div>}
|
||||
<div className="flex items-start gap-2">
|
||||
<Badge variant={s.variant}>{f.severity}</Badge>
|
||||
<span className="text-sm pt-0.5 leading-relaxed">{f.description}</span>
|
||||
</div>
|
||||
{f.snippets.length > 0 && (
|
||||
<div className="ml-1 pl-3 border-l border-muted space-y-0.5">
|
||||
{f.snippets.map((sn, j) => (
|
||||
<div key={j} className="text-xs text-pencil-light font-mono break-all">{sn}</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<p className="text-xs text-pencil-light">
|
||||
Force install will bypass the security check. Proceed with caution.
|
||||
</p>
|
||||
</div>
|
||||
@@ -405,7 +492,7 @@ export default function InstallForm({
|
||||
confirmText="Force Install"
|
||||
cancelText="Cancel"
|
||||
onConfirm={handleAuditForce}
|
||||
onCancel={() => setAuditDialog(null)}
|
||||
onCancel={() => { setAuditDialog(null); setSeverityFilter(null); }}
|
||||
loading={auditForcing}
|
||||
/>
|
||||
);
|
||||
@@ -417,29 +504,41 @@ export default function InstallForm({
|
||||
wide
|
||||
title="Security Warnings"
|
||||
message={
|
||||
<div className="text-left space-y-2">
|
||||
<div className="flex items-center gap-2 justify-center mb-3">
|
||||
<div className="text-left space-y-3">
|
||||
<div className="flex items-center gap-2 justify-center mb-1">
|
||||
<ShieldCheck size={20} className="text-warning" />
|
||||
<span>Skill installed with audit warnings</span>
|
||||
</div>
|
||||
<div
|
||||
className="bg-paper border border-warning/30 p-4 space-y-3 text-sm text-pencil max-h-64 overflow-y-auto"
|
||||
style={{ borderRadius: '6px' }}
|
||||
>
|
||||
{warningDialog?.map((w, i) => {
|
||||
const lines = w.split('\n');
|
||||
const header = lines[0];
|
||||
const snippet = lines.slice(1).map((l) => l.trim()).filter(Boolean).join(' ');
|
||||
const isHigh = header.includes('HIGH');
|
||||
<div className="flex flex-wrap gap-1.5 items-center text-xs text-pencil-light">
|
||||
<span>{warningFindings.length} {warningFindings.length === 1 ? 'warning' : 'warnings'}:</span>
|
||||
{filterBadge('CRITICAL', warningCounts.CRITICAL, 'danger', 'Critical')}
|
||||
{filterBadge('HIGH', warningCounts.HIGH, 'warning', 'High')}
|
||||
{filterBadge('MEDIUM', warningCounts.MEDIUM, 'default', 'Medium')}
|
||||
{severityFilter && (
|
||||
<span className="text-pencil-light">— showing {filteredWarnings.length}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="space-y-2 max-h-[32rem] overflow-y-auto pr-1">
|
||||
{filteredWarnings.map((f, i) => {
|
||||
const s = severityStyle(f.severity);
|
||||
return (
|
||||
<div key={i}>
|
||||
<div>
|
||||
<Badge variant={isHigh ? 'warning' : 'info'}>
|
||||
{isHigh ? 'HIGH' : 'MEDIUM'}
|
||||
</Badge>{' '}
|
||||
{header.replace(/^audit\s+(HIGH|MEDIUM|CRITICAL):\s*/, '')}
|
||||
<div
|
||||
key={i}
|
||||
className="border border-muted bg-paper p-3 space-y-1.5"
|
||||
style={{ borderRadius: '6px', borderLeftWidth: '3px', borderLeftColor: s.color }}
|
||||
>
|
||||
{f.skillName && <div className="text-xs text-pencil-light font-mono">{f.skillName}</div>}
|
||||
<div className="flex items-start gap-2">
|
||||
<Badge variant={s.variant}>{f.severity}</Badge>
|
||||
<span className="text-sm pt-0.5 leading-relaxed">{f.description}</span>
|
||||
</div>
|
||||
{snippet && <div className="text-pencil-light pl-4 text-xs">{snippet}</div>}
|
||||
{f.snippets.length > 0 && (
|
||||
<div className="ml-1 pl-3 border-l border-muted space-y-0.5">
|
||||
{f.snippets.map((sn, j) => (
|
||||
<div key={j} className="text-xs text-pencil-light font-mono break-all">{sn}</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
@@ -448,8 +547,8 @@ export default function InstallForm({
|
||||
}
|
||||
confirmText="OK"
|
||||
cancelText=""
|
||||
onConfirm={() => setWarningDialog(null)}
|
||||
onCancel={() => setWarningDialog(null)}
|
||||
onConfirm={() => { setWarningDialog(null); setSeverityFilter(null); }}
|
||||
onCancel={() => { setWarningDialog(null); setSeverityFilter(null); }}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
+272
-42
@@ -1,4 +1,5 @@
|
||||
import { useState, useMemo, forwardRef, memo } from 'react';
|
||||
import { useState, useMemo, forwardRef, memo, useEffect } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Link } from 'react-router-dom';
|
||||
import {
|
||||
Search,
|
||||
@@ -10,10 +11,13 @@ import {
|
||||
Globe,
|
||||
FolderOpen,
|
||||
LayoutGrid,
|
||||
List,
|
||||
Target,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
} from 'lucide-react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { VirtuosoGrid } from 'react-virtuoso';
|
||||
import { Virtuoso, VirtuosoGrid } from 'react-virtuoso';
|
||||
import type { GridComponents } from 'react-virtuoso';
|
||||
import { queryKeys, staleTimes } from '../lib/queryKeys';
|
||||
import Badge from '../components/Badge';
|
||||
@@ -28,7 +32,7 @@ import { radius, shadows } from '../design';
|
||||
|
||||
type FilterType = 'all' | 'tracked' | 'github' | 'local';
|
||||
type SortType = 'name-asc' | 'name-desc' | 'newest' | 'oldest';
|
||||
type ViewType = 'grid' | 'grouped';
|
||||
type ViewType = 'grid' | 'grouped' | 'table';
|
||||
|
||||
const filterOptions: { key: FilterType; label: string; icon: React.ReactNode }[] = [
|
||||
{ key: 'all', label: 'All', icon: <LayoutGrid size={14} strokeWidth={2.5} /> },
|
||||
@@ -254,7 +258,15 @@ export default function SkillsPage() {
|
||||
const [search, setSearch] = useState('');
|
||||
const [filterType, setFilterType] = useState<FilterType>('all');
|
||||
const [sortType, setSortType] = useState<SortType>('name-asc');
|
||||
const [viewType, setViewType] = useState<ViewType>('grid');
|
||||
const [viewType, setViewType] = useState<ViewType>(() => {
|
||||
const saved = localStorage.getItem('skillshare:skills-view');
|
||||
return (saved === 'grid' || saved === 'grouped' || saved === 'table') ? saved : 'grid';
|
||||
});
|
||||
|
||||
const changeViewType = (v: ViewType) => {
|
||||
setViewType(v);
|
||||
localStorage.setItem('skillshare:skills-view', v);
|
||||
};
|
||||
|
||||
const skills = data?.skills ?? [];
|
||||
|
||||
@@ -364,19 +376,26 @@ export default function SkillsPage() {
|
||||
{/* View toggle */}
|
||||
<div className="flex items-center border-2 border-muted overflow-hidden" style={{ borderRadius: radius.sm }}>
|
||||
<button
|
||||
onClick={() => setViewType('grid')}
|
||||
onClick={() => changeViewType('grid')}
|
||||
className={`px-4 py-2 transition-colors cursor-pointer ${viewType === 'grid' ? 'bg-pencil text-paper' : 'bg-surface text-pencil-light hover:text-pencil'}`}
|
||||
title="Grid view"
|
||||
>
|
||||
<LayoutGrid size={16} strokeWidth={2.5} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setViewType('grouped')}
|
||||
onClick={() => changeViewType('grouped')}
|
||||
className={`px-4 py-2 transition-colors cursor-pointer ${viewType === 'grouped' ? 'bg-pencil text-paper' : 'bg-surface text-pencil-light hover:text-pencil'}`}
|
||||
title="Grouped view"
|
||||
>
|
||||
<FolderOpen size={16} strokeWidth={2.5} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => changeViewType('table')}
|
||||
className={`px-4 py-2 transition-colors cursor-pointer ${viewType === 'table' ? 'bg-pencil text-paper' : 'bg-surface text-pencil-light hover:text-pencil'}`}
|
||||
title="Table view"
|
||||
>
|
||||
<List size={16} strokeWidth={2.5} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -416,7 +435,7 @@ export default function SkillsPage() {
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* Skills grid / grouped view */}
|
||||
{/* Skills grid / grouped / table view */}
|
||||
{filtered.length > 0 ? (
|
||||
viewType === 'grid' ? (
|
||||
<VirtuosoGrid
|
||||
@@ -432,8 +451,10 @@ export default function SkillsPage() {
|
||||
<SkillPostit skill={filtered[index]} index={index} />
|
||||
)}
|
||||
/>
|
||||
) : viewType === 'grouped' ? (
|
||||
<VirtualizedGroupedView dirs={grouped.dirs} groups={grouped.groups} />
|
||||
) : (
|
||||
<GroupedView dirs={grouped.dirs} groups={grouped.groups} />
|
||||
<SkillsTable skills={filtered} />
|
||||
)
|
||||
) : (
|
||||
<EmptyState
|
||||
@@ -450,45 +471,254 @@ export default function SkillsPage() {
|
||||
);
|
||||
}
|
||||
|
||||
/* -- Grouped view --------------------------------- */
|
||||
/* -- Virtualized grouped view --------------------- */
|
||||
|
||||
function GroupedView({ dirs, groups }: { dirs: string[]; groups: Map<string, Skill[]> }) {
|
||||
let globalIndex = 0;
|
||||
type GroupRow =
|
||||
| { type: 'header'; dir: string; count: number; showHeader: boolean }
|
||||
| { type: 'cards'; skills: Skill[] };
|
||||
|
||||
function VirtualizedGroupedView({ dirs, groups }: { dirs: string[]; groups: Map<string, Skill[]> }) {
|
||||
const rows = useMemo(() => {
|
||||
const result: GroupRow[] = [];
|
||||
const showHeaders = dirs.length > 1 || (dirs.length === 1 && dirs[0] !== '');
|
||||
for (const dir of dirs) {
|
||||
const skills = groups.get(dir) ?? [];
|
||||
result.push({ type: 'header', dir, count: skills.length, showHeader: showHeaders });
|
||||
// Chunk skills into rows of 3
|
||||
for (let i = 0; i < skills.length; i += 3) {
|
||||
result.push({ type: 'cards', skills: skills.slice(i, i + 3) });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}, [dirs, groups]);
|
||||
|
||||
return (
|
||||
<div className="space-y-8">
|
||||
{dirs.map((dir) => {
|
||||
const skills = groups.get(dir) ?? [];
|
||||
const sectionLabel = dir || '(root)';
|
||||
const showHeader = dirs.length > 1 || dir !== '';
|
||||
|
||||
return (
|
||||
<div key={dir || '__root'}>
|
||||
{showHeader && (
|
||||
<div className="flex items-center gap-2 mb-4">
|
||||
<Folder size={18} strokeWidth={2.5} className="text-pencil-light" />
|
||||
<h3
|
||||
className="text-lg font-bold text-pencil"
|
||||
>
|
||||
{sectionLabel}
|
||||
</h3>
|
||||
<span
|
||||
className="text-sm text-pencil-light px-2 py-0.5 bg-muted"
|
||||
style={{ borderRadius: radius.sm }}
|
||||
>
|
||||
{skills.length}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-5">
|
||||
{skills.map((skill) => {
|
||||
const idx = globalIndex++;
|
||||
return <SkillPostit key={skill.flatName} skill={skill} index={idx} />;
|
||||
})}
|
||||
<Virtuoso
|
||||
useWindowScroll
|
||||
totalCount={rows.length}
|
||||
overscan={200}
|
||||
itemContent={(index) => {
|
||||
const row = rows[index];
|
||||
if (row.type === 'header') {
|
||||
if (!row.showHeader) return <div />;
|
||||
return (
|
||||
<div className="flex items-center gap-2 mb-4 mt-8 first:mt-0" style={index === 0 ? { marginTop: 0 } : undefined}>
|
||||
<Folder size={18} strokeWidth={2.5} className="text-pencil-light" />
|
||||
<h3 className="text-lg font-bold text-pencil">
|
||||
{row.dir || '(root)'}
|
||||
</h3>
|
||||
<span
|
||||
className="text-sm text-pencil-light px-2 py-0.5 bg-muted"
|
||||
style={{ borderRadius: radius.sm }}
|
||||
>
|
||||
{row.count}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-wrap gap-5 mb-5">
|
||||
{row.skills.map((skill) => (
|
||||
<div
|
||||
key={skill.flatName}
|
||||
className="!w-full md:!w-[calc(50%-0.625rem)] xl:!w-[calc(33.333%-0.834rem)]"
|
||||
style={{ display: 'flex', flex: 'none', boxSizing: 'border-box' }}
|
||||
>
|
||||
<SkillPostit skill={skill} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/* -- Table view with pagination ------------------- */
|
||||
|
||||
const TABLE_PAGE_SIZES = [10, 25, 50] as const;
|
||||
|
||||
function TablePillButton({
|
||||
active,
|
||||
onClick,
|
||||
children,
|
||||
}: {
|
||||
active: boolean;
|
||||
onClick: () => void;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className={`
|
||||
px-3 py-1.5 text-sm border-2 transition-all duration-150 cursor-pointer
|
||||
${active
|
||||
? 'bg-pencil text-paper border-pencil font-medium'
|
||||
: 'bg-transparent text-pencil border-muted-dark hover:border-pencil'
|
||||
}
|
||||
`}
|
||||
style={{
|
||||
borderRadius: radius.sm,
|
||||
boxShadow: active ? shadows.sm : 'none',
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function TruncateWithTip({ text }: { text: string }) {
|
||||
const [tip, setTip] = useState<{ x: number; y: number } | null>(null);
|
||||
|
||||
return (
|
||||
<>
|
||||
<span
|
||||
className="block truncate"
|
||||
onMouseEnter={(e) => {
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
setTip({ x: rect.left, y: rect.bottom + 4 });
|
||||
}}
|
||||
onMouseLeave={() => setTip(null)}
|
||||
>
|
||||
{text}
|
||||
</span>
|
||||
{tip && createPortal(
|
||||
<div
|
||||
className="fixed z-[9999] max-w-sm break-all whitespace-normal bg-pencil px-2.5 py-1.5 text-xs text-paper shadow-lg pointer-events-none"
|
||||
style={{ left: tip.x, top: tip.y, borderRadius: radius.sm }}
|
||||
>
|
||||
{text}
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function SkillsTable({ skills }: { skills: Skill[] }) {
|
||||
const [page, setPage] = useState(0);
|
||||
const [pageSize, setPageSize] = useState<number>(10);
|
||||
|
||||
useEffect(() => { setPage(0); }, [skills]);
|
||||
|
||||
const totalPages = Math.max(1, Math.ceil(skills.length / pageSize));
|
||||
const start = page * pageSize;
|
||||
const visible = skills.slice(start, start + pageSize);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left">
|
||||
<thead>
|
||||
<tr className="border-b-2 border-dashed border-muted-dark">
|
||||
<th className="pb-3 pr-4 text-pencil-light text-sm font-medium w-0" />
|
||||
<th className="pb-3 pr-4 text-pencil-light text-sm font-medium">Name</th>
|
||||
<th className="pb-3 pr-4 text-pencil-light text-sm font-medium">Path</th>
|
||||
<th className="pb-3 pr-4 text-pencil-light text-sm font-medium">Type</th>
|
||||
<th className="pb-3 text-pencil-light text-sm font-medium">Source</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{visible.map((skill) => (
|
||||
<tr
|
||||
key={skill.flatName}
|
||||
className="border-b border-dashed border-muted hover:bg-paper-warm/60 transition-colors"
|
||||
>
|
||||
{/* Status stripe */}
|
||||
<td className="py-3 pr-0 w-1">
|
||||
<div
|
||||
className="w-1 h-6 rounded-full"
|
||||
style={{
|
||||
backgroundColor: skill.isInRepo
|
||||
? 'var(--color-pencil-light)'
|
||||
: 'var(--color-muted)',
|
||||
}}
|
||||
title={skill.isInRepo ? 'tracked' : 'local'}
|
||||
/>
|
||||
</td>
|
||||
{/* Name */}
|
||||
<td className="py-3 pr-4">
|
||||
<Link
|
||||
to={`/skills/${encodeURIComponent(skill.flatName)}`}
|
||||
className="font-medium text-pencil hover:underline"
|
||||
>
|
||||
{skill.name}
|
||||
</Link>
|
||||
</td>
|
||||
{/* Path */}
|
||||
<td className="py-3 pr-4 font-mono text-sm text-pencil-light max-w-[200px]">
|
||||
<TruncateWithTip text={skill.relPath} />
|
||||
</td>
|
||||
{/* Type badge */}
|
||||
<td className="py-3 pr-4">
|
||||
{skill.isInRepo ? (
|
||||
<Badge variant="default">tracked</Badge>
|
||||
) : getTypeLabel(skill.type) ? (
|
||||
<Badge variant="info">{getTypeLabel(skill.type)}</Badge>
|
||||
) : (
|
||||
<Badge variant="default">local</Badge>
|
||||
)}
|
||||
</td>
|
||||
{/* Source */}
|
||||
<td className="py-3 text-sm text-pencil-light max-w-[280px]">
|
||||
<TruncateWithTip text={skill.source ?? '—'} />
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* Pagination */}
|
||||
{skills.length > TABLE_PAGE_SIZES[0] && (
|
||||
<div className="flex items-center justify-between pt-4 mt-4 border-t-2 border-dashed border-muted">
|
||||
<div className="flex items-center gap-2 text-sm text-pencil-light">
|
||||
<span>Show</span>
|
||||
{TABLE_PAGE_SIZES.map((size) => (
|
||||
<TablePillButton
|
||||
key={size}
|
||||
active={pageSize === size}
|
||||
onClick={() => { setPageSize(size); setPage(0); }}
|
||||
>
|
||||
{size}
|
||||
</TablePillButton>
|
||||
))}
|
||||
<span className="ml-1">
|
||||
{start + 1}–{Math.min(start + pageSize, skills.length)} of {skills.length}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1">
|
||||
<button
|
||||
onClick={() => setPage((p) => Math.max(0, p - 1))}
|
||||
disabled={page === 0}
|
||||
className={`p-1.5 border-2 transition-all duration-150 cursor-pointer ${
|
||||
page === 0
|
||||
? 'border-transparent text-muted-dark cursor-not-allowed'
|
||||
: 'border-transparent text-pencil hover:bg-paper-warm hover:border-muted-dark'
|
||||
}`}
|
||||
style={{ borderRadius: radius.sm }}
|
||||
>
|
||||
<ChevronLeft size={20} />
|
||||
</button>
|
||||
<span className="text-sm text-pencil px-2">
|
||||
{page + 1} / {totalPages}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => setPage((p) => Math.min(totalPages - 1, p + 1))}
|
||||
disabled={page >= totalPages - 1}
|
||||
className={`p-1.5 border-2 transition-all duration-150 cursor-pointer ${
|
||||
page >= totalPages - 1
|
||||
? 'border-transparent text-muted-dark cursor-not-allowed'
|
||||
: 'border-transparent text-pencil hover:bg-paper-warm hover:border-muted-dark'
|
||||
}`}
|
||||
style={{ borderRadius: radius.sm }}
|
||||
>
|
||||
<ChevronRight size={20} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user