22
33import { useSidebarResize } from '@/lib/use-sidebar-resize'
44import { CompareSidebar } from '@/components/sidebar'
5+ import { DiffTable } from '@/components/diff-table'
56import { DiffTreemap } from '@/components/diff-treemap'
67import { TreemapSkeleton } from '@/components/ui/skeleton'
78import { StatCard , CountCard } from '@/components/stat-cards'
8- import { Environment } from '@/components/top-bar'
9+ import { CompareView , Environment } from '@/components/top-bar'
910import { AnalyzeData , ModulesData } from '@/lib/analyze-data'
1011import {
1112 diffRoutesWithSizes ,
@@ -19,6 +20,7 @@ import { cn, formatBytes } from '@/lib/utils'
1920export interface CompareLayoutProps {
2021 baselineSnapshot : SnapshotMetadata
2122 comparisonSnapshot : SnapshotMetadata | null
23+ compareView : CompareView
2224 selectedRoute : string | null
2325 comparisonRouteCount : number | null
2426 routeDiff : ReturnType < typeof diffRoutesWithSizes > | null
@@ -29,6 +31,7 @@ export interface CompareLayoutProps {
2931 isBaselineAnalyzeLoading : boolean
3032 baselineAnalyzeError : unknown | null
3133 compressed : boolean
34+ searchQuery : string
3235 compareSelectedKey : string | null
3336 setCompareSelectedKey : ( key : string | null ) => void
3437 modulesData : ModulesData | null
@@ -39,17 +42,17 @@ export interface CompareLayoutProps {
3942}
4043
4144/**
42- * Renders the comparison view (treemap) with a context strip at the top
43- * showing the two builds being compared. The "before" build (A) is rendered
44- * on the left and the selected "after" build (B) on the right,
45- * matching the user's mental model.
45+ * Renders the comparison view (treemap + table) with a context strip at the
46+ * top showing the two builds being compared. The "before" build (A) is
47+ * rendered on the left and the selected "after" build (B) on the right, matching the user's mental model.
4648 *
4749 * Route selection lives in the top-bar route picker (`RouteTypeahead`),
4850 * which also renders per-route deltas in compare mode.
4951 */
5052export function CompareLayout ( {
5153 baselineSnapshot,
5254 comparisonSnapshot,
55+ compareView,
5356 selectedRoute,
5457 comparisonRouteCount,
5558 routeDiff,
@@ -60,6 +63,7 @@ export function CompareLayout({
6063 isBaselineAnalyzeLoading,
6164 baselineAnalyzeError,
6265 compressed,
66+ searchQuery,
6367 compareSelectedKey,
6468 setCompareSelectedKey,
6569 modulesData,
@@ -100,19 +104,23 @@ export function CompareLayout({
100104 </ div >
101105
102106 { /*
103- Per-route source diff + sidebar. The sidebar slides in when a
107+ Per-route source diff + sidebar. The sidebar slides in when a row or
104108 treemap tile is selected and shows the import chain for that source.
105109 */ }
106110 < div className = "flex flex-1 min-h-0" >
107111 < div className = "flex flex-1 min-w-0 flex-col" >
108112 < ComparePerRoutePanel
113+ compareView = { compareView }
109114 selectedRoute = { selectedRoute }
110115 sourceDiff = { sourceDiff }
111116 analyzeData = { analyzeData }
112117 baselineAnalyzeData = { baselineAnalyzeData }
113118 isAnalyzeLoading = { isAnalyzeLoading }
114119 isBaselineAnalyzeLoading = { isBaselineAnalyzeLoading }
115120 compressed = { compressed }
121+ searchQuery = { searchQuery }
122+ baselineSnapshot = { baselineSnapshot }
123+ comparisonSnapshot = { comparisonSnapshot }
116124 compareSelectedKey = { compareSelectedKey }
117125 onCompareSelectedKeyChange = { setCompareSelectedKey }
118126 />
@@ -370,28 +378,36 @@ function RouteStatsBody({
370378}
371379
372380/**
373- * Per-route comparison panel. Shows the diff treemap. Handles missing-route
374- * states (the route is new in the comparison build, or was removed) with
375- * friendly messaging.
381+ * Per-route comparison panel. Shows either the diff treemap or the diff table,
382+ * controlled by `compareView`. Handles missing-route states ( the route is new
383+ * in comparison build B, or was removed) with friendly messaging.
376384 */
377385function ComparePerRoutePanel ( {
386+ compareView,
378387 selectedRoute,
379388 sourceDiff,
380389 analyzeData,
381390 baselineAnalyzeData,
382391 isAnalyzeLoading,
383392 isBaselineAnalyzeLoading,
384393 compressed,
394+ searchQuery,
395+ baselineSnapshot,
396+ comparisonSnapshot,
385397 compareSelectedKey,
386398 onCompareSelectedKeyChange,
387399} : {
400+ compareView : CompareView
388401 selectedRoute : string | null
389402 sourceDiff : DiffSummary < SourceDiffRow > | null
390403 analyzeData : AnalyzeData | null
391404 baselineAnalyzeData : AnalyzeData | null
392405 isAnalyzeLoading : boolean
393406 isBaselineAnalyzeLoading : boolean
394407 compressed : boolean
408+ searchQuery : string
409+ baselineSnapshot : SnapshotMetadata
410+ comparisonSnapshot : SnapshotMetadata | null
395411 compareSelectedKey : string | null
396412 onCompareSelectedKeyChange : ( key : string | null ) => void
397413} ) {
@@ -419,14 +435,31 @@ function ComparePerRoutePanel({
419435
420436 return (
421437 < div className = "flex flex-1 min-h-0 flex-col" >
422- < DiffTreemap
423- summary = { sourceDiff }
424- useCompressed = { compressed }
425- analyzeData = { analyzeData }
426- baselineAnalyzeData = { baselineAnalyzeData }
427- selectedKey = { compareSelectedKey }
428- onSelectKey = { onCompareSelectedKeyChange }
429- />
438+ { compareView === CompareView . Treemap ? (
439+ < DiffTreemap
440+ summary = { sourceDiff }
441+ useCompressed = { compressed }
442+ analyzeData = { analyzeData }
443+ baselineAnalyzeData = { baselineAnalyzeData }
444+ selectedKey = { compareSelectedKey }
445+ onSelectKey = { onCompareSelectedKeyChange }
446+ />
447+ ) : (
448+ < DiffTable
449+ summary = { sourceDiff }
450+ useCompressed = { compressed }
451+ nameHeading = "Source"
452+ aHeading = { formatSnapshotLabel ( baselineSnapshot ) }
453+ bHeading = {
454+ comparisonSnapshot
455+ ? formatSnapshotLabel ( comparisonSnapshot )
456+ : 'Latest'
457+ }
458+ searchQuery = { searchQuery }
459+ selectedKey = { compareSelectedKey }
460+ onRowSelect = { ( row ) => onCompareSelectedKeyChange ( row . key ) }
461+ />
462+ ) }
430463 </ div >
431464 )
432465}
0 commit comments