Skip to content

Commit 020a25d

Browse files
authored
feat: Add info panel setting to auto-load first row on opening new browser tab (#2972)
1 parent 6478e4c commit 020a25d

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/dashboard/Data/Browser/BrowserToolbar.react.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ const BrowserToolbar = ({
8585
appName,
8686
scrollToTop,
8787
toggleScrollToTop,
88+
autoLoadFirstRow,
89+
toggleAutoLoadFirstRow,
8890
}) => {
8991
const selectionLength = Object.keys(selection).length;
9092
const isPendingEditCloneRows = editCloneRows && editCloneRows.length > 0;
@@ -388,6 +390,25 @@ const BrowserToolbar = ({
388390
toggleScrollToTop();
389391
}}
390392
/>
393+
<MenuItem
394+
text={
395+
<span>
396+
{autoLoadFirstRow && (
397+
<Icon
398+
name="check"
399+
width={12}
400+
height={12}
401+
fill="#ffffffff"
402+
className="menuCheck"
403+
/>
404+
)}
405+
Auto-load first row
406+
</span>
407+
}
408+
onClick={() => {
409+
toggleAutoLoadFirstRow();
410+
}}
411+
/>
391412
</BrowserMenu>
392413
</BrowserMenu>
393414
<div className={styles.toolbarSeparator} />

src/dashboard/Data/Browser/DataBrowser.react.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import AggregationPanel from '../../../components/AggregationPanel/AggregationPa
2222
const BROWSER_SHOW_ROW_NUMBER = 'browserShowRowNumber';
2323
const AGGREGATION_PANEL_VISIBLE = 'aggregationPanelVisible';
2424
const BROWSER_SCROLL_TO_TOP = 'browserScrollToTop';
25+
const AGGREGATION_PANEL_AUTO_LOAD_FIRST_ROW = 'aggregationPanelAutoLoadFirstRow';
2526

2627
function formatValueForCopy(value, type) {
2728
if (value === undefined) {
@@ -86,6 +87,8 @@ export default class DataBrowser extends React.Component {
8687
window.localStorage?.getItem(AGGREGATION_PANEL_VISIBLE) === 'true';
8788
const storedScrollToTop =
8889
window.localStorage?.getItem(BROWSER_SCROLL_TO_TOP) !== 'false';
90+
const storedAutoLoadFirstRow =
91+
window.localStorage?.getItem(AGGREGATION_PANEL_AUTO_LOAD_FIRST_ROW) === 'true';
8992
const hasAggregation =
9093
props.classwiseCloudFunctions?.[
9194
`${props.app.applicationId}${props.appName}`
@@ -111,6 +114,7 @@ export default class DataBrowser extends React.Component {
111114
frozenColumnIndex: -1,
112115
showRowNumber: storedRowNumber,
113116
scrollToTop: storedScrollToTop,
117+
autoLoadFirstRow: storedAutoLoadFirstRow,
114118
prefetchCache: {},
115119
selectionHistory: [],
116120
};
@@ -135,6 +139,7 @@ export default class DataBrowser extends React.Component {
135139
this.unfreezeColumns = this.unfreezeColumns.bind(this);
136140
this.setShowRowNumber = this.setShowRowNumber.bind(this);
137141
this.toggleScrollToTop = this.toggleScrollToTop.bind(this);
142+
this.toggleAutoLoadFirstRow = this.toggleAutoLoadFirstRow.bind(this);
138143
this.handleCellClick = this.handleCellClick.bind(this);
139144
this.saveOrderTimeout = null;
140145
this.aggregationPanelRef = React.createRef();
@@ -222,6 +227,29 @@ export default class DataBrowser extends React.Component {
222227
}
223228
}
224229

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+
225253
if (
226254
(this.props.AggregationPanelData !== prevProps.AggregationPanelData ||
227255
this.state.selectedObjectId !== prevState.selectedObjectId) &&
@@ -288,6 +316,25 @@ export default class DataBrowser extends React.Component {
288316
}
289317
}
290318

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+
291338
if (!newVisibility && this.state.selectedObjectId) {
292339
if (this.props.errorAggregatedData != {}) {
293340
this.props.setErrorAggregatedData({});
@@ -694,6 +741,14 @@ export default class DataBrowser extends React.Component {
694741
});
695742
}
696743

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+
697752
getPrefetchSettings() {
698753
const config =
699754
this.props.classwiseCloudFunctions?.[
@@ -994,6 +1049,8 @@ export default class DataBrowser extends React.Component {
9941049
appName={this.props.appName}
9951050
scrollToTop={this.state.scrollToTop}
9961051
toggleScrollToTop={this.toggleScrollToTop}
1052+
autoLoadFirstRow={this.state.autoLoadFirstRow}
1053+
toggleAutoLoadFirstRow={this.toggleAutoLoadFirstRow}
9971054
{...other}
9981055
/>
9991056

0 commit comments

Comments
 (0)