@@ -85,6 +85,17 @@ const getFolderIdFromRow = (row) => {
8585 return '' ;
8686} ;
8787
88+ const getFolderNameFromRow = ( row ) => {
89+ if ( ! row || ! row . querySelector ) {
90+ return '' ;
91+ }
92+ const label = row . querySelector ( 'td.ct-name.folder-name a.exec.folder-appname' ) ;
93+ if ( ! label || typeof label . textContent !== 'string' ) {
94+ return '' ;
95+ }
96+ return label . textContent . trim ( ) ;
97+ } ;
98+
8899const getRenderedRowHeight = ( row ) => {
89100 if ( ! row ) {
90101 return 0 ;
@@ -121,6 +132,37 @@ const applyRowHeight = (row, height = 0) => {
121132 } ) ;
122133} ;
123134
135+ const buildMainFolderHeightLookup = ( ) => {
136+ const byId = new Map ( ) ;
137+ const byName = new Map ( ) ;
138+ const ordered = [ ] ;
139+
140+ const mainRows = Array . from ( document . querySelectorAll ( '#docker_list tr' ) ) . filter ( ( row ) => {
141+ return ! ! ( row && row . querySelector && row . querySelector ( 'td.ct-name.folder-name' ) ) ;
142+ } ) ;
143+
144+ mainRows . forEach ( ( row ) => {
145+ const height = getRenderedRowHeight ( row ) ;
146+ if ( height <= 0 ) {
147+ return ;
148+ }
149+
150+ ordered . push ( height ) ;
151+
152+ const folderId = getFolderIdFromRow ( row ) ;
153+ if ( folderId && ! byId . has ( folderId ) ) {
154+ byId . set ( folderId , height ) ;
155+ }
156+
157+ const folderName = getFolderNameFromRow ( row ) ;
158+ if ( folderName && ! byName . has ( folderName ) ) {
159+ byName . set ( folderName , height ) ;
160+ }
161+ } ) ;
162+
163+ return { byId, byName, ordered } ;
164+ } ;
165+
124166const applyFolderCellCentering = ( cell , rowHeight = 0 ) => {
125167 if ( ! cell ) {
126168 return false ;
@@ -171,31 +213,42 @@ const applyFolderCellCentering = (cell, rowHeight = 0) => {
171213} ;
172214
173215const forceAllFolderRowsVerticalCenter = ( ) => {
174- const mainRowHeightByFolderId = new Map ( ) ;
175- document . querySelectorAll ( '#docker_list tr' ) . forEach ( ( row ) => {
176- const id = getFolderIdFromRow ( row ) ;
177- if ( ! id ) {
216+ const lookup = buildMainFolderHeightLookup ( ) ;
217+
218+ const cloneRows = [ ] ;
219+ const cloneSeen = new Set ( ) ;
220+ document . querySelectorAll ( 'td.ct-name.folder-name' ) . forEach ( ( cell ) => {
221+ const row = cell . parentElement ;
222+ if ( ! row || isMainDockerRow ( row ) || cloneSeen . has ( row ) ) {
178223 return ;
179224 }
180- const height = getRenderedRowHeight ( row ) ;
181- if ( height > 0 ) {
182- mainRowHeightByFolderId . set ( id , height ) ;
183- }
225+ cloneSeen . add ( row ) ;
226+ cloneRows . push ( row ) ;
184227 } ) ;
185228
186- const processedRows = new Set ( ) ;
187- document . querySelectorAll ( 'td.ct-name.folder-name' ) . forEach ( ( cell ) => {
188- const parentRow = cell . parentElement ;
189- if ( ! parentRow || processedRows . has ( parentRow ) ) {
190- return ;
229+ cloneRows . forEach ( ( row , index ) => {
230+ const folderId = getFolderIdFromRow ( row ) ;
231+ const folderName = getFolderNameFromRow ( row ) ;
232+ let targetHeight = 0 ;
233+
234+ if ( folderId && lookup . byId . has ( folderId ) ) {
235+ targetHeight = lookup . byId . get ( folderId ) ;
236+ } else if ( folderName && lookup . byName . has ( folderName ) ) {
237+ targetHeight = lookup . byName . get ( folderName ) ;
238+ } else if ( lookup . ordered . length > 0 ) {
239+ targetHeight = lookup . ordered [ Math . min ( index , lookup . ordered . length - 1 ) ] ;
191240 }
192- processedRows . add ( parentRow ) ;
193241
194- const folderId = getFolderIdFromRow ( parentRow ) ;
195- const mainHeight = folderId ? ( mainRowHeightByFolderId . get ( folderId ) || 0 ) : 0 ;
196- const targetHeight = ! isMainDockerRow ( parentRow ) && mainHeight > 0 ? mainHeight : 0 ;
197- applyRowHeight ( parentRow , targetHeight ) ;
198- applyFolderCellCentering ( cell , targetHeight ) ;
242+ applyRowHeight ( row , targetHeight ) ;
243+ row . querySelectorAll ( 'td.ct-name.folder-name' ) . forEach ( ( cell ) => {
244+ applyFolderCellCentering ( cell , targetHeight ) ;
245+ } ) ;
246+ } ) ;
247+
248+ document . querySelectorAll ( '#docker_list td.ct-name.folder-name' ) . forEach ( ( cell ) => {
249+ const row = cell . parentElement ;
250+ applyRowHeight ( row , 0 ) ;
251+ applyFolderCellCentering ( cell , 0 ) ;
199252 } ) ;
200253} ;
201254
0 commit comments