From d516d765d5556617adb1a5cfe8b672c35a09effa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Volhejn?= Date: Sat, 11 Oct 2025 14:12:45 +0200 Subject: [PATCH] Redo frontend for tags --- .../src/repl/components/panel/Reference.jsx | 92 +++++++++++++------ 1 file changed, 64 insertions(+), 28 deletions(-) diff --git a/website/src/repl/components/panel/Reference.jsx b/website/src/repl/components/panel/Reference.jsx index 552551b5c..3faa5c6f1 100644 --- a/website/src/repl/components/panel/Reference.jsx +++ b/website/src/repl/components/panel/Reference.jsx @@ -10,8 +10,10 @@ const availableFunctions = (() => { const functions = []; for (const doc of jsdocJson.docs) { if (!isValid(doc)) continue; + if (seen.has(doc.name)) continue; functions.push(doc); const synonyms = doc.synonyms || []; + seen.add(doc.name); for (const s of synonyms) { if (!s || seen.has(s)) continue; seen.add(s); @@ -38,18 +40,33 @@ const getInnerText = (html) => { const GROUP_DISPLAY_NAMES = { external_io: 'External I/O', effects: 'Effects', - ungrouped: 'Ungrouped', + untagged: 'Untagged', structure: 'Structure', transforms: 'Transforms', }; -const GROUP_ORDER = ['effects', 'transforms', 'structure', 'ungrouped', 'external_io']; +const GROUP_ORDER = ['effects', 'transforms', 'structure', 'untagged', 'external_io']; export function Reference() { const [search, setSearch] = useState(''); + const [selectedTag, setSelectedTag] = useState(null); + + const toggleTag = (tag) => { + if (selectedTag === tag) { + setSelectedTag(null); + } else { + setSelectedTag(tag); + } + }; const visibleFunctions = useMemo(() => { return availableFunctions.filter((entry) => { + if (selectedTag) { + if (!(entry.tags || ['untagged']).includes(selectedTag)) { + return false; + } + } + if (!search) { return true; } @@ -60,12 +77,12 @@ export function Reference() { (entry.synonyms?.some((s) => s.includes(lowCaseSearch)) ?? false) ); }); - }, [search]); + }, [search, selectedTag]); const visibleFunctionsByGroup = (() => { const groups = {}; for (const doc of visibleFunctions) { - const group = doc.group || 'ungrouped'; + const group = (doc.tags || ['untagged'])[0]; if (!groups[group]) { groups[group] = []; } @@ -85,37 +102,56 @@ export function Reference() { return ai - bi; }); + const tagCounts = {}; + for (const doc of availableFunctions) { + (doc.tags || ['untagged']).forEach((t) => { + if (typeof t === 'string' && t) { + tagCounts[t] = (tagCounts[t] || 0) + 1; + } + }); + } + return ( -
-
-
+
+
+
-
-
- {sortedGroups.map(([groupId, groupEntries]) => ( - <> -

- {GROUP_DISPLAY_NAMES[groupId] || groupId} ({groupEntries.length}) -

- {groupEntries.map((entry, i) => ( - { - const el = document.getElementById(`doc-${entry.name}`); - const container = document.getElementById('reference-container'); - container.scrollTo(0, el.offsetTop); - }} - > - {entry.name} {/* {entry.meta.filename} */} - +
+ {Object.entries(tagCounts) + .sort(([a], [b]) => a.localeCompare(b)) + .map(([t, count]) => ( + + toggleTag(t)} + > + {t} ({count}) + {' '} + ))} - +
+
+