Skip to content

Commit 1a3610a

Browse files
authored
feat: Persist info panel visibility when navigating across classes in data browser (#2908)
1 parent b4cbda1 commit 1a3610a

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import styles from './Databrowser.scss';
1919
import AggregationPanel from '../../../components/AggregationPanel/AggregationPanel';
2020

2121
const BROWSER_SHOW_ROW_NUMBER = 'browserShowRowNumber';
22+
const AGGREGATION_PANEL_VISIBLE = 'aggregationPanelVisible';
2223

2324
function formatValueForCopy(value, type) {
2425
if (value === undefined) {
@@ -79,6 +80,12 @@ export default class DataBrowser extends React.Component {
7980
);
8081
const storedRowNumber =
8182
window.localStorage?.getItem(BROWSER_SHOW_ROW_NUMBER) === 'true';
83+
const storedPanelVisible =
84+
window.localStorage?.getItem(AGGREGATION_PANEL_VISIBLE) === 'true';
85+
const hasAggregation =
86+
props.classwiseCloudFunctions?.[
87+
`${props.app.applicationId}${props.appName}`
88+
]?.[props.className];
8289

8390
this.state = {
8491
order: order,
@@ -88,7 +95,7 @@ export default class DataBrowser extends React.Component {
8895
selectedObjectId: undefined,
8996
simplifiedSchema: this.getSimplifiedSchema(props.schema, props.className),
9097
allClassesSchema: this.getAllClassesSchema(props.schema, props.classes),
91-
isPanelVisible: false,
98+
isPanelVisible: storedPanelVisible && !!hasAggregation,
9299
selectedCells: { list: new Set(), rowStart: -1, rowEnd: -1, colStart: -1, colEnd: -1 },
93100
firstSelectedCell: null,
94101
selectedData: [],
@@ -157,13 +164,17 @@ export default class DataBrowser extends React.Component {
157164
this.setState({ order, frozenColumnIndex: -1 });
158165
}
159166
if (props && props.className) {
160-
if (
161-
!props.classwiseCloudFunctions?.[`${props.app.applicationId}${props.appName}`]?.[
162-
props.className
163-
]
164-
) {
167+
const storedPanelVisible =
168+
window.localStorage?.getItem(AGGREGATION_PANEL_VISIBLE) === 'true';
169+
const hasAggregation =
170+
props.classwiseCloudFunctions?.[
171+
`${props.app.applicationId}${props.appName}`
172+
]?.[props.className];
173+
if (!hasAggregation) {
165174
this.setState({ isPanelVisible: false });
166175
this.setState({ selectedObjectId: undefined });
176+
} else {
177+
this.setState({ isPanelVisible: storedPanelVisible });
167178
}
168179
} else {
169180
this.setState({ isPanelVisible: false });
@@ -242,17 +253,19 @@ export default class DataBrowser extends React.Component {
242253
}
243254

244255
togglePanelVisibility() {
245-
this.setState(prevState => ({ isPanelVisible: !prevState.isPanelVisible }));
256+
const newVisibility = !this.state.isPanelVisible;
257+
this.setState({ isPanelVisible: newVisibility });
258+
window.localStorage?.setItem(AGGREGATION_PANEL_VISIBLE, newVisibility);
246259

247-
if (!this.state.isPanelVisible) {
260+
if (!newVisibility) {
248261
this.props.setAggregationPanelData({});
249262
this.props.setLoadingInfoPanel(false);
250263
if (this.props.errorAggregatedData != {}) {
251264
this.props.setErrorAggregatedData({});
252265
}
253266
}
254267

255-
if (!this.state.isPanelVisible && this.state.selectedObjectId) {
268+
if (!newVisibility && this.state.selectedObjectId) {
256269
if (this.props.errorAggregatedData != {}) {
257270
this.props.setErrorAggregatedData({});
258271
}
@@ -285,9 +298,15 @@ export default class DataBrowser extends React.Component {
285298

286299
checkClassNameChange(prevClassName, className) {
287300
if (prevClassName !== className) {
301+
const storedPanelVisible =
302+
window.localStorage?.getItem(AGGREGATION_PANEL_VISIBLE) === 'true';
303+
const hasAggregation =
304+
this.props.classwiseCloudFunctions?.[
305+
`${this.props.app.applicationId}${this.props.appName}`
306+
]?.[className];
288307
this.setState({
289308
prevClassName: className,
290-
isPanelVisible: false,
309+
isPanelVisible: storedPanelVisible && !!hasAggregation,
291310
selectedObjectId: undefined,
292311
});
293312
this.props.setAggregationPanelData({});

0 commit comments

Comments
 (0)