refactor: centralise duplicate frontend helpers#197
Conversation
Move duplicated edge-filter logic into applyNetworkFilters() in networkService.ts and duplicated filter-label building into buildActiveFilterLabels() in constants.ts. Both AnalysisPage and NetworkDiagramPage now call the shared helpers, eliminating the divergence risk flagged in review. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- parseDateTime: remove copy in timelineService, import from dateUtils - formatBytes: remove copies in NetworkDiagramPage + ComparePage, import from utils/formatters - toggleSet: remove copies in NetworkDiagramPage + ComparePage, export from network/constants - edgeMatchesLegendKey: remove copy in ComparePage, import from networkService - applyNetworkFilters: remove inline filter block in ComparePage, call shared helper (hiddenSources pre-filter kept inline as it is compare-specific) - confidenceLevel + buildDeviceSignals: remove copies in both classification popups, export from utils/deviceType - useClickOutside: new shared hook in utils/, replaces duplicate useEffect in both classification popups Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request centralizes and refactors network filtering logic, device classification utilities, and common UI behaviors into shared services and hooks, significantly reducing code duplication across the Analysis, Compare, and Network Diagram pages. Feedback was provided regarding a performance bottleneck in the IP filtering logic within networkService.ts, where replacing a nested loop with a Set-based lookup would improve efficiency as the graph size increases.
- Fix LLM connection errors being swallowed by generic 500 handler by re-throwing LlmException and ContextLengthExceededException directly in StoryService - Show friendly LLM unreachable message on frontend for non-502 LLM errors - Hide Device Type filter section when no device-classified nodes are present - Hide Node Types section when no node/device types are present - Remove nav-tabs underline on Analysis page - Fix card header corners not rounding in dark mode with overflow: hidden Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request centralizes network filtering logic, device classification utilities, and UI components across the frontend, including the introduction of a useClickOutside hook and consolidated filtering functions in networkService.ts. Backend updates improve exception handling for LLM-related errors. Feedback identifies a performance bottleneck in the centralized filtering logic that could be optimized from Set. Additionally, the reviewer recommends fully adopting the new filtering function in NetworkDiagramPage and refining the error detection logic in StoryPage.tsx to avoid overly broad string matching.
- Replace O(N×E) fe.some() loop with a Set-based lookup for IP filter node visibility in applyNetworkFilters - Remove overly broad substring matching for LLM errors in StoryPage; rely solely on HTTP 502 now that backend correctly propagates LlmException Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
applyNetworkFilters,buildActiveFilterLabels,edgeMatchesLegendKey,toggleSet) soNetworkDiagramPage,ComparePage, andAnalysisPageall use the same logicformatBytes,parseDateTime,confidenceLevel,buildDeviceSignalsscattered across pages and popup componentsuseClickOutsideutility hook to replace identicaluseEffectpatterns in both classification popupsChanges
parseDateTimetimelineService.tsutils/dateUtils.tsformatBytesNetworkDiagramPage,ComparePageutils/formatterstoggleSetNetworkDiagramPage,ComparePagefeatures/network/constants.tsedgeMatchesLegendKeyComparePagenetworkService.tsComparePageinlineuseMemonetworkService.applyNetworkFilters()confidenceLevelutils/deviceType.tsbuildDeviceSignalsutils/deviceType.tsuseEffectutils/useClickOutside.ts(new)Net: −235 lines added, +95 lines → −140 lines of duplicated code.
Test plan
🤖 Generated with Claude Code