Fix empty result view when switching between queries
When updating to React 18, we removed the loading step from the updating of the state of the result view since React would batch the updates anyway. However, this caused a bug where the result view would be empty when switching between queries. This is because the result view would retain the old selected result set name. This would not happen previously because React would re-render the view at least once, which would cause the result view to be unmounted and re-created. This fixes it by resetting the selected result set if we can't find the result set in the new result sets.
This commit is contained in:
@@ -139,6 +139,31 @@ export class ResultTables extends React.Component<
|
||||
};
|
||||
}
|
||||
|
||||
componentDidUpdate(
|
||||
prevProps: Readonly<ResultTablesProps>,
|
||||
prevState: Readonly<ResultTablesState>,
|
||||
snapshot?: any,
|
||||
) {
|
||||
const resultSetExists =
|
||||
this.props.parsedResultSets.resultSetNames.some(
|
||||
(v) => this.state.selectedTable === v,
|
||||
) ||
|
||||
this.getResultSets().some(
|
||||
(v) => this.state.selectedTable === v.schema.name,
|
||||
);
|
||||
|
||||
// If the selected result set does not exist, select the default result set.
|
||||
if (!resultSetExists) {
|
||||
const selectedTable =
|
||||
this.props.parsedResultSets.selectedTable ||
|
||||
getDefaultResultSet(this.getResultSets());
|
||||
this.setState({
|
||||
selectedTable,
|
||||
selectedPage: `${this.props.parsedResultSets.pageNumber + 1}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
untoggleProblemsView() {
|
||||
this.setState({
|
||||
problemsViewSelected: false,
|
||||
|
||||
Reference in New Issue
Block a user