Skip to content

Commit 8e685ec

Browse files
committed
fix: address PR review - aria-pressed, O(N²) lookup, collapse bug
- Add aria-pressed to toggle buttons for accessibility - Build nodeMap for O(1) lookups in clustering hook - Always render dir node so expand/collapse works correctly
1 parent f61299b commit 8e685ec

3 files changed

Lines changed: 29 additions & 20 deletions

File tree

frontend/src/components/DependencyGraph/GraphToolbar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ function GraphToolbarComponent({
4646
size="sm"
4747
onClick={onToggleCluster}
4848
className="h-8"
49-
title="Group files by directory"
49+
aria-pressed={clusterByDir}
50+
title={clusterByDir ? 'Click to show flat view' : 'Group files by directory'}
5051
>
5152
<FolderTree className="w-3.5 h-3.5 mr-1.5" />
5253
Cluster
@@ -57,6 +58,8 @@ function GraphToolbarComponent({
5758
size="sm"
5859
onClick={onToggleShowAll}
5960
className="h-8"
61+
aria-pressed={showAll}
62+
title={showAll ? 'Show top 15 files' : 'Show all files'}
6063
>
6164
<Filter className="w-3.5 h-3.5 mr-1.5" />
6265
{showAll ? 'Show Top 15' : 'Show All'}
@@ -67,6 +70,7 @@ function GraphToolbarComponent({
6770
size="sm"
6871
onClick={onToggleTests}
6972
className={cn('h-8', !showTests && 'opacity-70 line-through')}
73+
aria-pressed={showTests}
7074
title={showTests ? 'Click to hide test files' : 'Click to show test files'}
7175
>
7276
{showTests ? <Eye className="w-3.5 h-3.5 mr-1.5" /> : <EyeOff className="w-3.5 h-3.5 mr-1.5" />}

frontend/src/components/DependencyGraph/hooks/useDirectoryClustering.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export function useDirectoryClustering(
4848
const clusters = useMemo(() => {
4949
const clusterMap = new Map<string, DirectoryCluster>()
5050

51+
// Build node lookup map for O(1) access
52+
const nodeMap = new Map(nodes.map(n => [n.id, n]))
53+
5154
// Group files by directory
5255
const dirFiles = new Map<string, string[]>()
5356
nodes.forEach(node => {
@@ -61,7 +64,7 @@ export function useDirectoryClustering(
6164
// Create clusters for each directory
6265
dirFiles.forEach((files, dirPath) => {
6366
const dirName = dirPath.split('/').pop() || dirPath
64-
const nodeData = files.map(f => nodes.find(n => n.id === f)!).filter(Boolean)
67+
const nodeData = files.map(f => nodeMap.get(f)!).filter(Boolean)
6568

6669
clusterMap.set(dirPath, {
6770
path: dirPath,

frontend/src/components/DependencyGraph/index.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,26 +179,28 @@ function DependencyGraphInner({ repoId, apiUrl, apiKey }: DependencyGraphProps)
179179
dirFiles.forEach((files, dirPath) => {
180180
const isExpanded = expandedDirs.has(dirPath)
181181

182+
// Calculate metrics for this directory
183+
const metrics = files.map(f => impact.getFileMetrics(f)).filter(Boolean)
184+
const totalDeps = metrics.reduce((sum, m) => sum + (m?.dependentCount || 0), 0)
185+
const risks = metrics.map(m => m?.riskLevel || 'low') as Array<'low' | 'medium' | 'high' | 'critical'>
186+
187+
// Always create directory node so user can collapse
188+
dirNodes.push({
189+
id: `dir:${dirPath}`,
190+
data: {
191+
label: dirPath.split('/').pop() || dirPath,
192+
fullPath: dirPath,
193+
fileCount: files.length,
194+
totalDependents: totalDeps,
195+
maxRisk: getMaxRisk(risks),
196+
isExpanded,
197+
state: 'default',
198+
}
199+
})
200+
201+
// When expanded, also show individual files
182202
if (isExpanded) {
183203
files.forEach(f => visibleFiles.add(f))
184-
} else {
185-
// Create directory node
186-
const metrics = files.map(f => impact.getFileMetrics(f)).filter(Boolean)
187-
const totalDeps = metrics.reduce((sum, m) => sum + (m?.dependentCount || 0), 0)
188-
const risks = metrics.map(m => m?.riskLevel || 'low') as Array<'low' | 'medium' | 'high' | 'critical'>
189-
190-
dirNodes.push({
191-
id: `dir:${dirPath}`,
192-
data: {
193-
label: dirPath.split('/').pop() || dirPath,
194-
fullPath: dirPath,
195-
fileCount: files.length,
196-
totalDependents: totalDeps,
197-
maxRisk: getMaxRisk(risks),
198-
isExpanded: false,
199-
state: 'default',
200-
}
201-
})
202204
}
203205
})
204206

0 commit comments

Comments
 (0)