@@ -22,6 +22,7 @@ import AggregationPanel from '../../../components/AggregationPanel/AggregationPa
22
22
const BROWSER_SHOW_ROW_NUMBER = 'browserShowRowNumber' ;
23
23
const AGGREGATION_PANEL_VISIBLE = 'aggregationPanelVisible' ;
24
24
const BROWSER_SCROLL_TO_TOP = 'browserScrollToTop' ;
25
+ const AGGREGATION_PANEL_AUTO_LOAD_FIRST_ROW = 'aggregationPanelAutoLoadFirstRow' ;
25
26
26
27
function formatValueForCopy ( value , type ) {
27
28
if ( value === undefined ) {
@@ -86,6 +87,8 @@ export default class DataBrowser extends React.Component {
86
87
window . localStorage ?. getItem ( AGGREGATION_PANEL_VISIBLE ) === 'true' ;
87
88
const storedScrollToTop =
88
89
window . localStorage ?. getItem ( BROWSER_SCROLL_TO_TOP ) !== 'false' ;
90
+ const storedAutoLoadFirstRow =
91
+ window . localStorage ?. getItem ( AGGREGATION_PANEL_AUTO_LOAD_FIRST_ROW ) === 'true' ;
89
92
const hasAggregation =
90
93
props . classwiseCloudFunctions ?. [
91
94
`${ props . app . applicationId } ${ props . appName } `
@@ -111,6 +114,7 @@ export default class DataBrowser extends React.Component {
111
114
frozenColumnIndex : - 1 ,
112
115
showRowNumber : storedRowNumber ,
113
116
scrollToTop : storedScrollToTop ,
117
+ autoLoadFirstRow : storedAutoLoadFirstRow ,
114
118
prefetchCache : { } ,
115
119
selectionHistory : [ ] ,
116
120
} ;
@@ -135,6 +139,7 @@ export default class DataBrowser extends React.Component {
135
139
this . unfreezeColumns = this . unfreezeColumns . bind ( this ) ;
136
140
this . setShowRowNumber = this . setShowRowNumber . bind ( this ) ;
137
141
this . toggleScrollToTop = this . toggleScrollToTop . bind ( this ) ;
142
+ this . toggleAutoLoadFirstRow = this . toggleAutoLoadFirstRow . bind ( this ) ;
138
143
this . handleCellClick = this . handleCellClick . bind ( this ) ;
139
144
this . saveOrderTimeout = null ;
140
145
this . aggregationPanelRef = React . createRef ( ) ;
@@ -222,6 +227,29 @@ export default class DataBrowser extends React.Component {
222
227
}
223
228
}
224
229
230
+ // Auto-load first row if enabled and conditions are met
231
+ if (
232
+ this . state . autoLoadFirstRow &&
233
+ this . state . isPanelVisible &&
234
+ this . props . data &&
235
+ this . props . data . length > 0 &&
236
+ ! this . state . selectedObjectId &&
237
+ ( ( ! prevProps . data || prevProps . data . length === 0 ) ||
238
+ prevProps . className !== this . props . className ||
239
+ prevState . isPanelVisible !== this . state . isPanelVisible )
240
+ ) {
241
+ const firstRowObjectId = this . props . data [ 0 ] . id ;
242
+ this . setShowAggregatedData ( true ) ;
243
+ this . setSelectedObjectId ( firstRowObjectId ) ;
244
+ // Also set the current cell to the first cell of the first row
245
+ this . setCurrent ( { row : 0 , col : 0 } ) ;
246
+ this . handleCallCloudFunction (
247
+ firstRowObjectId ,
248
+ this . props . className ,
249
+ this . props . app . applicationId
250
+ ) ;
251
+ }
252
+
225
253
if (
226
254
( this . props . AggregationPanelData !== prevProps . AggregationPanelData ||
227
255
this . state . selectedObjectId !== prevState . selectedObjectId ) &&
@@ -288,6 +316,25 @@ export default class DataBrowser extends React.Component {
288
316
}
289
317
}
290
318
319
+ // Auto-load first row when opening panel if enabled and no row is selected
320
+ if (
321
+ newVisibility &&
322
+ this . state . autoLoadFirstRow &&
323
+ ! this . state . selectedObjectId &&
324
+ this . props . data &&
325
+ this . props . data . length > 0
326
+ ) {
327
+ const firstRowObjectId = this . props . data [ 0 ] . id ;
328
+ this . setShowAggregatedData ( true ) ;
329
+ this . setSelectedObjectId ( firstRowObjectId ) ;
330
+ this . setCurrent ( { row : 0 , col : 0 } ) ;
331
+ this . handleCallCloudFunction (
332
+ firstRowObjectId ,
333
+ this . props . className ,
334
+ this . props . app . applicationId
335
+ ) ;
336
+ }
337
+
291
338
if ( ! newVisibility && this . state . selectedObjectId ) {
292
339
if ( this . props . errorAggregatedData != { } ) {
293
340
this . props . setErrorAggregatedData ( { } ) ;
@@ -694,6 +741,14 @@ export default class DataBrowser extends React.Component {
694
741
} ) ;
695
742
}
696
743
744
+ toggleAutoLoadFirstRow ( ) {
745
+ this . setState ( prevState => {
746
+ const newAutoLoadFirstRow = ! prevState . autoLoadFirstRow ;
747
+ window . localStorage ?. setItem ( AGGREGATION_PANEL_AUTO_LOAD_FIRST_ROW , newAutoLoadFirstRow ) ;
748
+ return { autoLoadFirstRow : newAutoLoadFirstRow } ;
749
+ } ) ;
750
+ }
751
+
697
752
getPrefetchSettings ( ) {
698
753
const config =
699
754
this . props . classwiseCloudFunctions ?. [
@@ -994,6 +1049,8 @@ export default class DataBrowser extends React.Component {
994
1049
appName = { this . props . appName }
995
1050
scrollToTop = { this . state . scrollToTop }
996
1051
toggleScrollToTop = { this . toggleScrollToTop }
1052
+ autoLoadFirstRow = { this . state . autoLoadFirstRow }
1053
+ toggleAutoLoadFirstRow = { this . toggleAutoLoadFirstRow }
997
1054
{ ...other }
998
1055
/>
999
1056
0 commit comments