fix(ui): keep the no-match state while filters exclude every skill

Standalone source links were added to every grouping regardless of the
active search or filters, so a query that matched nothing rendered the
links as zero-skill groups instead of the no-match state with its Clear
filters action. Links have no skills to match, so they are shown only
while no filter is active.
This commit is contained in:
Willie
2026-10-05 23:01:50 +08:00
parent ad5d5cd09f
commit 6d600f6525
2 changed files with 17 additions and 4 deletions
+11
View File
@@ -295,6 +295,17 @@ describe('Unlink folder', () => {
expect(api.batchUninstall).not.toHaveBeenCalled();
});
it('keeps the no-match state when a filter excludes every skill but links exist', async () => {
vi.mocked(api.listSkills).mockResolvedValue({ resources: [LINKED[0]], sourceLinks: [{ name: 'team', target: '/work/team', available: true }] });
mount();
await screen.findByText('/work/team');
fireEvent.change(screen.getByLabelText('Search skills'), { target: { value: 'zzz-no-such-skill' } });
expect(await screen.findByText('No matches')).toBeInTheDocument();
expect(screen.queryByText('/work/team')).toBeNull();
fireEvent.click(screen.getByRole('button', { name: 'Clear filters' }));
expect(await screen.findByText('/work/team')).toBeInTheDocument();
});
it.each(['list', 'cards', 'tree'])('shows an unavailable link warning in %s view', async (view) => {
localStorage.setItem('skillshare:skills-view', view);
vi.mocked(api.listSkills).mockResolvedValue({ resources: [], sourceLinks: [{ name: 'team', target: '/work/team', available: false, warning: 'target is missing' }] });
+6 -4
View File
@@ -263,6 +263,8 @@ export default function ResourcesPage({ kind }: { kind: Kind }) {
const query = search.trim();
const isGlob = /[*?]/.test(query);
const filtering = query !== '' || source !== 'all' || status !== 'all' || activeTarget !== 'all' || activeFolder !== null;
// Standalone links have no skills to match a filter, so they only show unfiltered.
const shownLinks = useMemo(() => filtering ? [] : sourceLinks, [filtering, sourceLinks]);
const filtered = useMemo(() => {
const re = query ? globToRegex(query) : null;
@@ -276,9 +278,9 @@ export default function ResourcesPage({ kind }: { kind: Kind }) {
), sort);
}, [items, query, source, status, sort, activeTarget, targetIndex, activeFolder]);
const groups = useMemo(() => groupBySource(filtered, sourceLinks), [filtered, sourceLinks]);
const folderGroups = useMemo(() => groupByFolder(filtered, sourceLinks), [filtered, sourceLinks]);
const tree = useMemo(() => buildTree(filtered, sourceLinks), [filtered, sourceLinks]);
const groups = useMemo(() => groupBySource(filtered, shownLinks), [filtered, shownLinks]);
const folderGroups = useMemo(() => groupByFolder(filtered, shownLinks), [filtered, shownLinks]);
const tree = useMemo(() => buildTree(filtered, shownLinks), [filtered, shownLinks]);
const treeRows = useMemo(() => flattenTree(tree, collapsed, filtering), [tree, collapsed, filtering]);
const shownTreeRows = useMemo(() => {
let left = limit;
@@ -610,7 +612,7 @@ export default function ResourcesPage({ kind }: { kind: Kind }) {
const shown = Math.min(limit, total);
let content: React.ReactNode;
if (filtered.length === 0 && sourceLinks.length === 0) {
if (filtered.length === 0 && shownLinks.length === 0) {
content = items.length === 0 ? (
<EmptyState
icon={isAgent ? Bot : Puzzle}