@@ -441,8 +441,34 @@ export const DataThread: FC<{}> = function ({ }) {
441
441
} )
442
442
443
443
444
- let refTables = tables ;
445
- let leafTables = refTables . filter ( t => ! refTables . some ( t2 => t2 . derive ?. trigger . tableId == t . id ) ) ;
444
+
445
+ let leafTables = tables . filter ( t => ! tables . some ( t2 => t2 . derive ?. trigger . tableId == t . id ) ) ;
446
+
447
+ // we want to sort the leaf tables by the order of their ancestors
448
+ // for example if ancestor of list a is [0, 3] and the ancestor of list b is [0, 2] then b should come before a
449
+ let tableOrder = Object . fromEntries ( tables . map ( ( table , index ) => [ table . id , index ] ) ) ;
450
+ let getAncestorOrders = ( leafTable : DictTable ) => {
451
+ let triggers = getTriggers ( leafTable , tables ) ;
452
+ return [ ...triggers . map ( t => tableOrder [ t . tableId ] ) , tableOrder [ leafTable . id ] ] ;
453
+ }
454
+ for ( let i = 0 ; i < leafTables . length ; i ++ ) {
455
+ let aAncestors = getAncestorOrders ( leafTables [ i ] ) ;
456
+ console . log ( leafTables [ i ] . id , aAncestors ) ;
457
+ }
458
+ leafTables . sort ( ( a , b ) => {
459
+ let aAncestors = getAncestorOrders ( a ) ;
460
+ let bAncestors = getAncestorOrders ( b ) ;
461
+
462
+ // If lengths are equal, compare ancestors in order
463
+ for ( let i = 0 ; i < Math . min ( aAncestors . length , bAncestors . length ) ; i ++ ) {
464
+ if ( aAncestors [ i ] !== bAncestors [ i ] ) {
465
+ return aAncestors [ i ] - bAncestors [ i ] ;
466
+ }
467
+ }
468
+
469
+ // If all ancestors are equal, compare the leaf tables themselves
470
+ return aAncestors . length - bAncestors . length ;
471
+ } ) ;
446
472
447
473
let drawerOpen = leafTables . length > 1 && threadDrawerOpen ;
448
474
let threadDrawerWidth = Math . max ( Math . min ( 600 , leafTables . length * 200 ) , 212 )
@@ -452,6 +478,7 @@ export const DataThread: FC<{}> = function ({ }) {
452
478
position : 'relative' ,
453
479
display : 'flex' ,
454
480
flexDirection : drawerOpen ? 'row-reverse' : 'column' ,
481
+ minHeight : '100%' ,
455
482
} } >
456
483
{ leafTables . map ( ( lt , i ) => {
457
484
let usedTableIds = leafTables . slice ( 0 , i )
@@ -464,12 +491,12 @@ export const DataThread: FC<{}> = function ({ }) {
464
491
chartElements = { chartElements }
465
492
usedTableIds = { usedTableIds }
466
493
sx = { {
467
- backgroundColor : ( i % 2 == 1 ? "rgba(0, 0, 0, 0.02 )" : 'white' ) ,
494
+ backgroundColor : ( i % 2 == 1 ? "rgba(0, 0, 0, 0.03 )" : 'white' ) ,
468
495
padding : '8px 8px' ,
469
496
flex : 1 ,
470
497
display : 'flex' ,
471
498
flexDirection : 'column' ,
472
- height : '100%'
499
+ height : 'calc( 100% - 16px) '
473
500
} } />
474
501
} ) }
475
502
</ Box >
0 commit comments