fix(ui): count hooks on the dashboard

The dashboard listed every resource type except hooks, so a source with
hooks looked as if it had none. Hooks now sit between MCP and Plugins,
matching the sidebar, in both the global and project dashboards.
This commit is contained in:
Willie
2026-10-04 06:11:27 +08:00
parent 76f232b134
commit 77727bd578
2 changed files with 28 additions and 4 deletions
+22 -1
View File
@@ -4,13 +4,16 @@ import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { api } from '../api/client';
import type { Overview, Target } from '../api/client';
import { hooksApi } from '../api/hooks';
import type { HookInventory } from '../api/hooks';
import { mcpApi } from '../api/mcp';
import { pluginsApi } from '../api/plugins';
import { ToastProvider } from '../components/Toast';
import { I18nProvider } from '../i18n';
import DashboardPage from './DashboardPage';
vi.mock('../context/AppContext', () => ({ useAppContext: () => ({ isProjectMode: false }) }));
const appContext = vi.hoisted(() => ({ isProjectMode: false }));
vi.mock('../context/AppContext', () => ({ useAppContext: () => appContext }));
vi.mock('../api/client', async (load) => {
const actual = await load<typeof import('../api/client')>();
return {
@@ -26,6 +29,10 @@ vi.mock('../api/mcp', async (load) => {
const actual = await load<typeof import('../api/mcp')>();
return { ...actual, mcpApi: { ...actual.mcpApi, list: vi.fn() } };
});
vi.mock('../api/hooks', async (load) => {
const actual = await load<typeof import('../api/hooks')>();
return { ...actual, hooksApi: { ...actual.hooksApi, list: vi.fn() } };
});
vi.mock('../api/plugins', async (load) => {
const actual = await load<typeof import('../api/plugins')>();
return { ...actual, pluginsApi: { ...actual.pluginsApi, list: vi.fn() } };
@@ -47,6 +54,7 @@ function renderPage() {
describe('DashboardPage', () => {
beforeEach(() => {
vi.clearAllMocks();
appContext.isProjectMode = false;
vi.mocked(api.getOverview).mockResolvedValue({ skillCount: 3, agentCount: 0, source: '/home/dev/skills', trackedRepos: [] } as unknown as Overview);
vi.mocked(api.listTargets).mockResolvedValue({ targets: [target('codex', 'merged'), target('cursor', 'not exist')], sourceSkillCount: 3 } as Awaited<ReturnType<typeof api.listTargets>>);
vi.mocked(api.listExtras).mockResolvedValue({ extras: [] } as unknown as Awaited<ReturnType<typeof api.listExtras>>);
@@ -56,6 +64,7 @@ describe('DashboardPage', () => {
vi.mocked(api.getVersionCheck).mockReturnValue(new Promise(() => {}));
vi.mocked(mcpApi.list).mockReturnValue(new Promise(() => {}));
vi.mocked(pluginsApi.list).mockReturnValue(new Promise(() => {}));
vi.mocked(hooksApi.list).mockResolvedValue({ source: { entries: { lint: { bindings: {} }, fmt: { bindings: {} } } } } as unknown as HookInventory);
});
it('opens a target row on that target, not the target list', async () => {
@@ -64,6 +73,18 @@ describe('DashboardPage', () => {
expect(links.map((a) => a.getAttribute('href'))).toEqual(links.map(() => '/targets/codex'));
});
it('counts the source hooks', async () => {
renderPage();
const links = await screen.findAllByRole('link', { name: /^2\s*Hooks$/ });
expect(links[0]).toHaveAttribute('href', '/hooks');
});
it('counts the project hooks in project mode', async () => {
appContext.isProjectMode = true;
renderPage();
expect((await screen.findAllByRole('link', { name: /^2\s*Hooks$/ }))[0]).toHaveAttribute('href', '/hooks');
});
it('opens a broken target from the attention list on that target', async () => {
renderPage();
expect(await screen.findByRole('link', { name: 'Open' })).toHaveAttribute('href', '/targets/cursor');
+6 -3
View File
@@ -18,6 +18,7 @@ import {
Star,
Trash2,
TriangleAlert,
Webhook,
X,
} from 'lucide-react';
import { api } from '../api/client';
@@ -35,7 +36,7 @@ import { PageSkeleton } from '../components/Skeleton';
import { useToast } from '../components/Toast';
import { useAppContext } from '../context/AppContext';
import { useRepoUpdate } from '../hooks/useRepoUpdate';
import { useMcpQuery, useOverviewQuery } from '../hooks/useSharedQueries';
import { useHooksQuery, useMcpQuery, useOverviewQuery } from '../hooks/useSharedQueries';
const STAR_CTA_DISMISSED_KEY = 'skillshare.dashboard.starCta.dismissed';
@@ -86,6 +87,7 @@ export default function DashboardPage() {
staleTime: staleTimes.extras,
});
const { data: mcpData } = useMcpQuery();
const { data: hooksData } = useHooksQuery({ staleTime: staleTimes.extras });
const { data: pluginData } = useQuery({ queryKey: queryKeys.pluginPackages, queryFn: () => pluginsApi.list(false) });
const { data: lastSync } = useQuery({
queryKey: queryKeys.log('ops', 1, { cmd: 'sync' }),
@@ -116,6 +118,7 @@ export default function DashboardPage() {
{ kind: 'agent', icon: Bot, value: data.agentCount, label: t('dashboard.stats.agents'), to: '/agents' },
{ kind: 'extra', icon: FolderPlus, value: extrasData?.extras?.length ?? 0, label: t('dashboard.stats.extras'), to: '/extras' },
{ kind: 'mcp', icon: Plug, value: mcpData ? Object.keys(mcpData.source.servers ?? {}).length : 0, label: t('mcp.title'), to: '/mcp' },
{ kind: 'hooks', icon: Webhook, value: Object.keys(hooksData?.source.entries ?? {}).length, label: t('hooks.title'), to: '/hooks' },
{ kind: 'plugin', icon: Package, value: Object.keys(pluginData?.packages ?? {}).length, label: t('plugins.title'), to: '/plugins' },
];
@@ -150,7 +153,7 @@ export default function DashboardPage() {
)}
<div data-tour="stats-grid" className="flex flex-col gap-7">
<div className="ss-counts ss-only-clean !grid-cols-5">
<div className="ss-counts ss-only-clean !grid-cols-6">
{counts.map(({ kind, icon: Icon, value, label, to }) => (
<Link key={kind} to={to}>
<span className={`ss-cat ${kind}`}><Icon size={17} /></span>
@@ -241,7 +244,7 @@ function TargetBoard({ data, targets, healths, counts }: {
</>
)}
</svg>
<div className="ss-pinnote src flex-col !items-stretch justify-center gap-2.5 !px-5 !py-4" style={{ left: 40, top: sy - 125, width: 300, height: 250 }}>
<div className="ss-pinnote src flex-col !items-stretch justify-center gap-2.5 !px-5 !py-4" style={{ left: 40, top: sy - 142, width: 300, height: 284 }}>
<span className="flex flex-col gap-0.5">
<span className="ss-hand !text-[22px] !font-bold !text-ink">{t('dashboard.board.source')}</span>
<span className="font-mono text-[11.5px] text-ink-3 truncate">{data.source}</span>