@@ -8,6 +8,7 @@ import {Endpoints} from "@/pages/Endpoints.tsx";
88import { TestResults } from "@/pages/TestResults.tsx" ;
99import { Tests } from "@/pages/Tests.tsx" ;
1010import { Warnings } from "@/pages/Warnings.tsx" ;
11+ import { Examples } from "@/pages/Examples.tsx" ;
1112
1213import { ScrollArea , ScrollBar } from "@/components/ui/scroll-area.tsx" ;
1314import { useAppContext } from "@/AppProvider.tsx" ;
@@ -16,13 +17,26 @@ import {REVIEW_STATE} from "@/types/Review.ts";
1617
1718export interface ITestTabs {
1819 value : string ;
20+ origin : string ;
1921}
2022
23+ const MAIN_TABS = new Set ( [ "overview" , "endpoints" , "examples" , "tests" , "warnings" ] ) ;
24+
2125export const Dashboard : React . FC = ( ) => {
2226 const { data, isDirty, reviews} = useAppContext ( ) ;
2327
2428 const warningCount = data ?. warnings ?. length ?? 0 ;
2529
30+ const examplesCount = useMemo ( ( ) => {
31+ const set = new Set < string > ( ) ;
32+ for ( const tc of data ?. testCases ?? [ ] ) {
33+ for ( const ex of tc . namedExamples ?? [ ] ) {
34+ if ( ex ) set . add ( ex ) ;
35+ }
36+ }
37+ return set . size ;
38+ } , [ data ] ) ;
39+
2640 const reviewRatio = useMemo ( ( ) => {
2741 if ( ! data ) return null ;
2842 const total = data . testCases . length ;
@@ -41,8 +55,11 @@ export const Dashboard: React.FC = () => {
4155 const [ testTabs , setTestTabs ] = useState < Array < ITestTabs > > ( [ ] ) ;
4256
4357 const addTestTab = ( testName : string , event : React . MouseEvent < HTMLElement > ) => {
58+ const origin = MAIN_TABS . has ( activeTab )
59+ ? activeTab
60+ : ( testTabs . find ( t => t . value === activeTab ) ?. origin ?? "endpoints" ) ;
4461 if ( ! testTabs . find ( ( t ) => t . value === testName ) ) {
45- setTestTabs ( [ { value : testName } , ...testTabs ] ) ;
62+ setTestTabs ( [ { value : testName , origin } , ...testTabs ] ) ;
4663 }
4764
4865 if ( ! event . ctrlKey ) {
@@ -51,12 +68,15 @@ export const Dashboard: React.FC = () => {
5168 }
5269
5370 const handleCloseTestsTab = ( testName : string ) => {
71+ const closing = testTabs . find ( t => t . value === testName ) ;
5472 const updatedTabs = testTabs . filter ( ( t ) => t . value !== testName ) ;
5573 setTestTabs ( updatedTabs ) ;
74+ if ( activeTab !== testName ) return ;
5675 if ( updatedTabs . length === 0 ) {
57- setActiveTab ( "endpoints" )
76+ const fallback = closing ?. origin ?? "endpoints" ;
77+ setActiveTab ( MAIN_TABS . has ( fallback ) ? fallback : "endpoints" ) ;
5878 } else {
59- setActiveTab ( updatedTabs [ 0 ] . value )
79+ setActiveTab ( updatedTabs [ 0 ] . value ) ;
6080 }
6181 }
6282
@@ -82,7 +102,7 @@ export const Dashboard: React.FC = () => {
82102 toolNameVersion = { `${ data . toolName } -${ data . toolVersion } ` } />
83103 < Tabs value = { activeTab } onValueChange = { setActiveTab } className = "w-full" >
84104 < div className = "flex justify-center mb-2 w-full" >
85- < TabsList className = { `flex gap-2 sm:gap-4 w-full max-w-[850px ] h-auto p-1 bg-transparent` } >
105+ < TabsList className = { `flex gap-2 sm:gap-4 w-full max-w-[1000px ] h-auto p-1 bg-transparent` } >
86106 < TabsTrigger
87107 value = "overview"
88108 className = "flex-1 sm:flex-none sm:min-w-[150px] py-3 text-xs sm:text-sm border border-gray-500 data-[state=active]:bg-blue-100 data-[state=active]:border-2 data-[state=active]:border-black data-[state=active]:shadow-[2px_2px_0px_0px_rgba(0,0,0,1)]"
@@ -97,6 +117,18 @@ export const Dashboard: React.FC = () => {
97117 >
98118 Endpoints
99119 </ TabsTrigger >
120+ < TabsTrigger
121+ value = "examples"
122+ className = "flex-1 sm:flex-none sm:min-w-[150px] py-3 text-xs sm:text-sm border border-gray-500 data-[state=active]:bg-blue-100 data-[state=active]:border-2 data-[state=active]:border-black data-[state=active]:shadow-[2px_2px_0px_0px_rgba(0,0,0,1)]"
123+ data-testid = "tab-examples"
124+ >
125+ Examples
126+ { examplesCount > 0 && (
127+ < span className = "ml-2 text-xs font-mono text-gray-600" data-testid = "tab-examples-count" >
128+ { examplesCount }
129+ </ span >
130+ ) }
131+ </ TabsTrigger >
100132 < TabsTrigger
101133 value = "tests"
102134 className = "flex-1 sm:flex-none sm:min-w-[150px] py-3 text-xs sm:text-sm border border-gray-500 data-[state=active]:bg-blue-100 data-[state=active]:border-2 data-[state=active]:border-black data-[state=active]:shadow-[2px_2px_0px_0px_rgba(0,0,0,1)]"
@@ -128,7 +160,7 @@ export const Dashboard: React.FC = () => {
128160
129161 < div className = "flex justify-center w-full" >
130162 {
131- < TabsList className = { `flex gap-2 sm:gap-4 w-full max-w-[850px ] h-auto p-1 bg-transparent` } >
163+ < TabsList className = { `flex gap-2 sm:gap-4 w-full max-w-[1000px ] h-auto p-1 bg-transparent` } >
132164 < ScrollArea className = "w-[130%] whitespace-nowrap py-3" >
133165 {
134166 testTabs . map ( ( test , index ) => (
@@ -166,6 +198,10 @@ export const Dashboard: React.FC = () => {
166198 < Endpoints addTestTab = { addTestTab } />
167199 </ TabsContent >
168200
201+ < TabsContent value = "examples" >
202+ < Examples addTestTab = { addTestTab } />
203+ </ TabsContent >
204+
169205 < TabsContent value = "tests" >
170206 < Tests />
171207 </ TabsContent >
0 commit comments