@@ -299,18 +299,22 @@ export default function QuestionListPage() {
299
299
const [ visibleTests , setVisibleTests ] = useState < Test [ ] > ( [ ] ) ;
300
300
const [ hiddenTests , setHiddenTests ] = useState < Test [ ] > ( [ ] ) ;
301
301
const [ isTestsLoading , setIsTestsLoading ] = useState < boolean > ( true ) ;
302
+ const [ activeKey , setActiveKey ] = useState < string | undefined > ( undefined ) ;
303
+ const [ testActiveKey , setTestActiveKey ] = useState < string > ( "1" ) ;
302
304
303
305
const handleAddVisibleTest = ( ) => {
304
306
const newKey = uuidv4 ( ) ;
305
307
setVisibleTests ( [
306
308
...visibleTests ,
307
309
{ key : newKey , input : "" , expected : "" } ,
308
310
] ) ;
311
+ setActiveKey ( newKey ) ;
309
312
} ;
310
313
311
314
const handleAddHiddenTest = ( ) => {
312
315
const newKey = uuidv4 ( ) ;
313
316
setHiddenTests ( [ ...hiddenTests , { key : newKey , input : "" , expected : "" } ] ) ;
317
+ setActiveKey ( newKey ) ;
314
318
} ;
315
319
316
320
const handleRemoveVisibleTest = ( targetKey : string ) => {
@@ -353,12 +357,13 @@ export default function QuestionListPage() {
353
357
354
358
// Add a unique key to each test
355
359
if ( visibleTests ) {
356
- setVisibleTests (
357
- visibleTests . map ( ( test ) => ( {
358
- ...test ,
359
- key : uuidv4 ( ) ,
360
- } ) )
361
- ) ;
360
+ const keyedVisibleTests = visibleTests . map ( ( test , index ) => ( {
361
+ ...test ,
362
+ key : uuidv4 ( ) ,
363
+ } ) ) ;
364
+ setVisibleTests ( keyedVisibleTests ) ;
365
+ setActiveKey ( keyedVisibleTests [ 0 ] . key ) ;
366
+ setTestActiveKey ( "1" ) ;
362
367
}
363
368
if ( hiddenTests ) {
364
369
setHiddenTests (
@@ -530,7 +535,16 @@ export default function QuestionListPage() {
530
535
allowClear
531
536
/>
532
537
</ Form . Item >
533
- < Tabs defaultActiveKey = "1" >
538
+ < Tabs
539
+ defaultActiveKey = "1"
540
+ onChange = { ( key ) => {
541
+ setActiveKey (
542
+ key == "1" ? visibleTests [ 0 ] . key : hiddenTests [ 0 ] ?. key
543
+ ) ;
544
+ setTestActiveKey ( key ) ;
545
+ } }
546
+ activeKey = { testActiveKey }
547
+ >
534
548
{ /* Visible Tests Tab */ }
535
549
< TabPane
536
550
tab = {
@@ -550,6 +564,8 @@ export default function QuestionListPage() {
550
564
? handleAddVisibleTest ( )
551
565
: handleRemoveVisibleTest ( targetKey . toString ( ) )
552
566
}
567
+ onChange = { ( key ) => setActiveKey ( key ) }
568
+ activeKey = { activeKey }
553
569
>
554
570
{ visibleTests . map ( ( test : Test , index : number ) => (
555
571
< TabPane
@@ -630,6 +646,8 @@ export default function QuestionListPage() {
630
646
? handleAddHiddenTest ( )
631
647
: handleRemoveHiddenTest ( targetKey . toString ( ) )
632
648
}
649
+ onChange = { ( key ) => setActiveKey ( key ) }
650
+ activeKey = { activeKey }
633
651
>
634
652
{ hiddenTests . map ( ( test : Test , index : number ) => (
635
653
< TabPane tab = { `Test ${ index + 1 } ` } key = { test . key } >
@@ -942,7 +960,18 @@ export default function QuestionListPage() {
942
960
/>
943
961
</ Form . Item >
944
962
{ /* REFACTOR: should abstract out tabs to a common component for reusability */ }
945
- < Tabs defaultActiveKey = "1" >
963
+ < Tabs
964
+ defaultActiveKey = "1"
965
+ onChange = { ( key ) => {
966
+ setActiveKey (
967
+ key == "1"
968
+ ? visibleTests [ 0 ] . key
969
+ : hiddenTests [ 0 ] ?. key
970
+ ) ;
971
+ setTestActiveKey ( key ) ;
972
+ } }
973
+ activeKey = { testActiveKey }
974
+ >
946
975
{ /* Visible Tests Tab */ }
947
976
< TabPane
948
977
tab = {
@@ -959,6 +988,8 @@ export default function QuestionListPage() {
959
988
? handleAddVisibleTest ( )
960
989
: handleRemoveVisibleTest ( targetKey . toString ( ) )
961
990
}
991
+ onChange = { ( key ) => setActiveKey ( key ) }
992
+ activeKey = { activeKey }
962
993
>
963
994
{ visibleTests . map ( ( test : Test , index : number ) => (
964
995
< TabPane
@@ -1033,6 +1064,8 @@ export default function QuestionListPage() {
1033
1064
? handleAddHiddenTest ( )
1034
1065
: handleRemoveHiddenTest ( targetKey . toString ( ) )
1035
1066
}
1067
+ onChange = { ( key ) => setActiveKey ( key ) }
1068
+ activeKey = { activeKey }
1036
1069
>
1037
1070
{ hiddenTests . map ( ( test : Test , index : number ) => (
1038
1071
< TabPane tab = { `Test ${ index + 1 } ` } key = { test . key } >
0 commit comments