diff --git a/ui/src/components/targets/FilterSection.tsx b/ui/src/components/targets/FilterSection.tsx index d38bbfce3..690bf68ff 100644 --- a/ui/src/components/targets/FilterSection.tsx +++ b/ui/src/components/targets/FilterSection.tsx @@ -1,12 +1,12 @@ import { Fragment, useState, type ReactNode } from 'react'; import { Link } from 'react-router-dom'; -import { ChevronDown, ChevronRight } from 'lucide-react'; +import { ChevronDown, ChevronRight, Search } from 'lucide-react'; import type { SyncMatrixEntry } from '../../api/client'; import AgentIcon from '../AgentIcon'; import Spinner from '../Spinner'; import { useI18n, useT, plural } from '../../i18n'; import PatternInput from './PatternInput'; -import { joinList, patternName, togglePatterns } from './targetView'; +import { joinList, patternName, searchEntries, togglePatterns } from './targetView'; type Kind = 'skill' | 'agent' | 'file'; const MODES = ['merge', 'copy', 'symlink'] as const; @@ -39,8 +39,22 @@ interface Props { export default function FilterSection({ kind, mode, name, include, exclude, onChange, entries, loaded, loading, error, disabled, alsoReadBy = [], readsFrom = [], includeWarning }: Props) { const { t, locale } = useI18n(); const [help, setHelp] = useState(false); + const [query, setQuery] = useState(''); + // Switching between skills and agents starts a new search. + const [queryKind, setQueryKind] = useState(kind); + if (queryKind !== kind) { + setQueryKind(kind); + setQuery(''); + } const files = kind === 'file'; const synced = entries.filter((e) => e.status === 'synced').length; + const shown = searchEntries(entries, query); + /** Marks the searched text inside a row name. */ + const hit = (name: string) => { + const q = query.trim(); + const i = q ? name.toLowerCase().indexOf(q.toLowerCase()) : -1; + return i < 0 ? name : <>{name.slice(0, i)}{name.slice(i, i + q.length)}{name.slice(i + q.length)}; + }; const reason = (e: SyncMatrixEntry) => { switch (e.status) { @@ -119,9 +133,17 @@ export default function FilterSection({ kind, mode, name, include, exclude, onCh ) : entries.length > 0 && ( // The result of the filters, set apart from the fields that shape it.
-
-

{t('targetDetail.previewCount', { count: entries.length })}

-

{t(files ? 'targetDetail.clickHintFiles' : 'targetDetail.clickHint')}

+
+
+

+ {query.trim() ? t('targetDetail.previewCountSearch', { shown: shown.length, count: entries.length }) : t('targetDetail.previewCount', { count: entries.length })} +

+

{t(files ? 'targetDetail.clickHintFiles' : 'targetDetail.clickHint')}

+
+
@@ -130,12 +152,13 @@ export default function FilterSection({ kind, mode, name, include, exclude, onCh {t('targetDetail.result')}
- {entries.map((e) => { + {shown.length === 0 &&

{t('targetDetail.searchNoMatches', { query: query.trim() })}

} + {shown.map((e) => { const next = togglePatterns(e, include, exclude); const on = e.status === 'synced'; const cells = ( <> - {patternName(e)} + {hit(patternName(e))} {reason(e)} {t(on ? 'targetDetail.synced' : 'targetDetail.notSynced')} diff --git a/ui/src/components/targets/targetView.test.ts b/ui/src/components/targets/targetView.test.ts index 3d809b573..2386bcb36 100644 --- a/ui/src/components/targets/targetView.test.ts +++ b/ui/src/components/targets/targetView.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest'; import type { SyncMatrixEntry, Target } from '../../api/client'; -import { joinList, targetHealth, targetSkipHints, targetWarning, togglePatterns } from './targetView'; +import { joinList, searchEntries, targetHealth, targetSkipHints, targetWarning, togglePatterns } from './targetView'; const target = (over: Partial): Target => ({ name: 'claude', path: '~/.claude/skills', mode: 'merge', targetNaming: 'flat', status: 'merged', @@ -27,6 +27,14 @@ describe('targetHealth', () => { }); }); +describe('searchEntries', () => { + it('matches part of a name in any case, and an agent by its name without the extension', () => { + const rows = [row('frontend/React-Doctor', 'synced'), row('react.md', 'synced', 'agent'), row('archify', 'excluded')]; + expect(searchEntries(rows, ' react ').map((e) => e.skill)).toEqual(['frontend/React-Doctor', 'react.md']); + expect(searchEntries(rows, '.md')).toEqual([]); + }); +}); + describe('togglePatterns', () => { it('round-trips a row that only syncs because of its own include', () => { const on = togglePatterns(row('scratch', 'not_included'), ['core-*'], []); diff --git a/ui/src/components/targets/targetView.ts b/ui/src/components/targets/targetView.ts index a1cdcf538..b3b218dcd 100644 --- a/ui/src/components/targets/targetView.ts +++ b/ui/src/components/targets/targetView.ts @@ -31,6 +31,12 @@ export function targetHealth(target: Target): { state: TargetState; pending: num /** Filter patterns match agent names without the .md extension. */ export const patternName = (entry: SyncMatrixEntry) => (entry.kind === 'agent' ? entry.skill.replace(/\.md$/, '') : entry.skill); +/** Preview rows whose pattern name contains the search text, ignoring case. */ +export function searchEntries(entries: SyncMatrixEntry[], query: string) { + const q = query.trim().toLowerCase(); + return q ? entries.filter((e) => patternName(e).toLowerCase().includes(q)) : entries; +} + /** * The filter edit a click on a preview row makes, or null when naming the row can't change its result * (a wildcard exclude, or a resource that declares its own targets). diff --git a/ui/src/i18n/locales/de.json b/ui/src/i18n/locales/de.json index c0588bc3c..c950c467f 100644 --- a/ui/src/i18n/locales/de.json +++ b/ui/src/i18n/locales/de.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "{pattern} entfernen", "targetDetail.loadingPreview": "Vorschau wird geladen…", "targetDetail.previewCount": "Vorschau · {count}", + "targetDetail.previewCountSearch": "Vorschau · {shown} von {count}", + "targetDetail.search.skills": "Skills suchen", + "targetDetail.search.agents": "Agents suchen", + "targetDetail.search.files": "Dateien suchen", + "targetDetail.searchNoMatches": "Nichts passt zu „{query}“.", "targetDetail.becauseOf": "Grund", "targetDetail.result": "Ergebnis", "targetDetail.reason.included": "passt zu Einschließen", diff --git a/ui/src/i18n/locales/en.json b/ui/src/i18n/locales/en.json index 4af99325a..db24a23e1 100644 --- a/ui/src/i18n/locales/en.json +++ b/ui/src/i18n/locales/en.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "Remove {pattern}", "targetDetail.loadingPreview": "Loading preview…", "targetDetail.previewCount": "Preview · {count}", + "targetDetail.previewCountSearch": "Preview · {shown} of {count}", + "targetDetail.search.skills": "Search skills", + "targetDetail.search.agents": "Search agents", + "targetDetail.search.files": "Search files", + "targetDetail.searchNoMatches": "Nothing matches “{query}”.", "targetDetail.becauseOf": "Because of", "targetDetail.result": "Result", "targetDetail.reason.included": "matches include", diff --git a/ui/src/i18n/locales/es.json b/ui/src/i18n/locales/es.json index dcc486dd3..0fcce1418 100644 --- a/ui/src/i18n/locales/es.json +++ b/ui/src/i18n/locales/es.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "Quitar {pattern}", "targetDetail.loadingPreview": "Cargando vista previa…", "targetDetail.previewCount": "Vista previa · {count}", + "targetDetail.previewCountSearch": "Vista previa · {shown} de {count}", + "targetDetail.search.skills": "Buscar skills", + "targetDetail.search.agents": "Buscar agents", + "targetDetail.search.files": "Buscar archivos", + "targetDetail.searchNoMatches": "Nada coincide con «{query}».", "targetDetail.becauseOf": "Motivo", "targetDetail.result": "Resultado", "targetDetail.reason.included": "coincide con incluir", diff --git a/ui/src/i18n/locales/fa.json b/ui/src/i18n/locales/fa.json index bc06394ea..a51fd5e8f 100644 --- a/ui/src/i18n/locales/fa.json +++ b/ui/src/i18n/locales/fa.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "حذف {pattern}", "targetDetail.loadingPreview": "در حال بارگذاری پیش‌نمایش…", "targetDetail.previewCount": "پیش‌نمایش · {count}", + "targetDetail.previewCountSearch": "پیش‌نمایش · {shown} از {count}", + "targetDetail.search.skills": "جستجوی اسکیل‌ها", + "targetDetail.search.agents": "جستجوی Agentها", + "targetDetail.search.files": "جستجوی فایل‌ها", + "targetDetail.searchNoMatches": "چیزی با «{query}» مطابقت ندارد.", "targetDetail.becauseOf": "به دلیل", "targetDetail.result": "نتیجه", "targetDetail.reason.included": "مطابق شامل", diff --git a/ui/src/i18n/locales/fr.json b/ui/src/i18n/locales/fr.json index 0c5869322..3c85a67ac 100644 --- a/ui/src/i18n/locales/fr.json +++ b/ui/src/i18n/locales/fr.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "Retirer {pattern}", "targetDetail.loadingPreview": "Chargement de l’aperçu…", "targetDetail.previewCount": "Aperçu · {count}", + "targetDetail.previewCountSearch": "Aperçu · {shown} sur {count}", + "targetDetail.search.skills": "Rechercher des skills", + "targetDetail.search.agents": "Rechercher des agents", + "targetDetail.search.files": "Rechercher des fichiers", + "targetDetail.searchNoMatches": "Aucun résultat pour « {query} ».", "targetDetail.becauseOf": "Raison", "targetDetail.result": "Résultat", "targetDetail.reason.included": "correspond à l’inclusion", diff --git a/ui/src/i18n/locales/id.json b/ui/src/i18n/locales/id.json index e2797b7f4..78cbf6159 100644 --- a/ui/src/i18n/locales/id.json +++ b/ui/src/i18n/locales/id.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "Hapus {pattern}", "targetDetail.loadingPreview": "Memuat pratinjau…", "targetDetail.previewCount": "Pratinjau · {count}", + "targetDetail.previewCountSearch": "Pratinjau · {shown} dari {count}", + "targetDetail.search.skills": "Cari skill", + "targetDetail.search.agents": "Cari agent", + "targetDetail.search.files": "Cari file", + "targetDetail.searchNoMatches": "Tidak ada yang cocok dengan “{query}”.", "targetDetail.becauseOf": "Karena", "targetDetail.result": "Hasil", "targetDetail.reason.included": "cocok dengan sertakan", diff --git a/ui/src/i18n/locales/ja.json b/ui/src/i18n/locales/ja.json index 0c420396e..5ae2a62e4 100644 --- a/ui/src/i18n/locales/ja.json +++ b/ui/src/i18n/locales/ja.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "{pattern} を削除", "targetDetail.loadingPreview": "プレビューを読み込み中…", "targetDetail.previewCount": "プレビュー · {count} 件", + "targetDetail.previewCountSearch": "プレビュー · {count} 件中 {shown} 件", + "targetDetail.search.skills": "スキルを検索", + "targetDetail.search.agents": "Agent を検索", + "targetDetail.search.files": "ファイルを検索", + "targetDetail.searchNoMatches": "「{query}」に一致する項目はありません。", "targetDetail.becauseOf": "理由", "targetDetail.result": "結果", "targetDetail.reason.included": "含める条件に一致", diff --git a/ui/src/i18n/locales/ko.json b/ui/src/i18n/locales/ko.json index d123bbf23..d703a8f6e 100644 --- a/ui/src/i18n/locales/ko.json +++ b/ui/src/i18n/locales/ko.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "{pattern} 제거", "targetDetail.loadingPreview": "미리보기 불러오는 중…", "targetDetail.previewCount": "미리보기 · {count}개", + "targetDetail.previewCountSearch": "미리보기 · {count}개 중 {shown}개", + "targetDetail.search.skills": "skill 검색", + "targetDetail.search.agents": "agent 검색", + "targetDetail.search.files": "파일 검색", + "targetDetail.searchNoMatches": "“{query}”와 일치하는 항목이 없습니다.", "targetDetail.becauseOf": "이유", "targetDetail.result": "결과", "targetDetail.reason.included": "포함과 일치", diff --git a/ui/src/i18n/locales/pt-BR.json b/ui/src/i18n/locales/pt-BR.json index 2d742187a..2b1d4e8a1 100644 --- a/ui/src/i18n/locales/pt-BR.json +++ b/ui/src/i18n/locales/pt-BR.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "Remover {pattern}", "targetDetail.loadingPreview": "Carregando prévia…", "targetDetail.previewCount": "Prévia · {count}", + "targetDetail.previewCountSearch": "Prévia · {shown} de {count}", + "targetDetail.search.skills": "Buscar skills", + "targetDetail.search.agents": "Buscar agents", + "targetDetail.search.files": "Buscar arquivos", + "targetDetail.searchNoMatches": "Nada corresponde a “{query}”.", "targetDetail.becauseOf": "Motivo", "targetDetail.result": "Resultado", "targetDetail.reason.included": "corresponde a incluir", diff --git a/ui/src/i18n/locales/zh-CN.json b/ui/src/i18n/locales/zh-CN.json index deaf1aa6b..e5b115560 100644 --- a/ui/src/i18n/locales/zh-CN.json +++ b/ui/src/i18n/locales/zh-CN.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "移除 {pattern}", "targetDetail.loadingPreview": "正在加载预览…", "targetDetail.previewCount": "预览 · {count} 个", + "targetDetail.previewCountSearch": "预览 · {count} 个中的 {shown} 个", + "targetDetail.search.skills": "搜索 Skill", + "targetDetail.search.agents": "搜索 Agent", + "targetDetail.search.files": "搜索文件", + "targetDetail.searchNoMatches": "没有与“{query}”匹配的项目。", "targetDetail.becauseOf": "原因", "targetDetail.result": "结果", "targetDetail.reason.included": "匹配包含", diff --git a/ui/src/i18n/locales/zh-TW.json b/ui/src/i18n/locales/zh-TW.json index 18a7c4f83..da13e1fe9 100644 --- a/ui/src/i18n/locales/zh-TW.json +++ b/ui/src/i18n/locales/zh-TW.json @@ -1870,6 +1870,11 @@ "targetDetail.removePattern": "移除 {pattern}", "targetDetail.loadingPreview": "正在載入預覽…", "targetDetail.previewCount": "預覽 · {count} 個", + "targetDetail.previewCountSearch": "預覽 · {count} 個中的 {shown} 個", + "targetDetail.search.skills": "搜尋 Skills", + "targetDetail.search.agents": "搜尋 Agents", + "targetDetail.search.files": "搜尋檔案", + "targetDetail.searchNoMatches": "沒有符合「{query}」的項目。", "targetDetail.becauseOf": "原因", "targetDetail.result": "結果", "targetDetail.reason.included": "符合包含", diff --git a/ui/src/pages/ResourcesPage.tsx b/ui/src/pages/ResourcesPage.tsx index fb9260782..471673c2a 100644 --- a/ui/src/pages/ResourcesPage.tsx +++ b/ui/src/pages/ResourcesPage.tsx @@ -1027,7 +1027,7 @@ export default function ResourcesPage({ kind }: { kind: Kind }) { )} /> -