@@ -52,30 +52,42 @@ export const CippWizardConfirmation = (props) => {
52
52
! [ "user" , "userPrincipalName" , "username" ] . includes ( key )
53
53
) ;
54
54
55
- // Dynamically split entries based on columns prop
55
+ // Calculate total entries including special ones for even distribution
56
+ const totalEntries = filteredEntries . length + ( tenantEntry ? 1 : 0 ) + ( userEntry ? 1 : 0 ) ;
57
+
58
+ // Dynamically split entries based on columns prop with special entries distributed
56
59
const splitEntries = ( ) => {
57
- const entriesPerColumn = Math . ceil ( filteredEntries . length / columns ) ;
58
- const result = [ ] ;
59
-
60
- for ( let i = 0 ; i < columns ; i ++ ) {
61
- const start = i * entriesPerColumn ;
62
- const end = start + entriesPerColumn ;
63
- result . push ( filteredEntries . slice ( start , end ) ) ;
60
+ const result = Array . from ( { length : columns } , ( ) => [ ] ) ;
61
+
62
+ // Add special entries to different columns first
63
+ if ( tenantEntry ) {
64
+ result [ 0 ] . push ( tenantEntry ) ;
64
65
}
65
-
66
+ if ( userEntry && result [ 1 ] ) {
67
+ result [ 1 ] . push ( userEntry ) ;
68
+ }
69
+
70
+ // Distribute remaining entries across columns to balance them
71
+ filteredEntries . forEach ( ( entry ) => {
72
+ // Find the column with the fewest entries
73
+ let targetColumn = 0 ;
74
+ let minLength = result [ 0 ] . length ;
75
+
76
+ for ( let i = 1 ; i < columns ; i ++ ) {
77
+ if ( result [ i ] . length < minLength ) {
78
+ minLength = result [ i ] . length ;
79
+ targetColumn = i ;
80
+ }
81
+ }
82
+
83
+ result [ targetColumn ] . push ( entry ) ;
84
+ } ) ;
85
+
66
86
return result ;
67
87
} ;
68
88
69
89
const columnEntries = splitEntries ( ) ;
70
90
71
- // Distribute special entries across first available columns
72
- if ( tenantEntry && columnEntries [ 0 ] ) {
73
- columnEntries [ 0 ] . unshift ( tenantEntry ) ;
74
- }
75
- if ( userEntry && columnEntries [ 1 ] ) {
76
- columnEntries [ 1 ] . unshift ( userEntry ) ;
77
- }
78
-
79
91
// Calculate Grid sizes based on number of columns
80
92
const getGridSize = ( ) => {
81
93
const sizes = {
0 commit comments