Ensure that the scroll position should be preserved for the result set in the query tool on tab change. #5296

This commit is contained in:
Nikhil Mohite
2022-10-11 10:53:46 +05:30
committed by GitHub
parent b100df3160
commit 19f96799df
3 changed files with 33 additions and 1 deletions

View File

@@ -333,6 +333,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
} else if(LayoutHelper.isTabVisible(docker.current, PANELS.HISTORY)) {
LayoutHelper.focus(docker.current, PANELS.HISTORY);
}
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.GOTO_LAST_SCROLL);
}
});
window.addEventListener('beforeunload', onBeforeUnload);

View File

@@ -70,6 +70,8 @@ export const QUERY_TOOL_EVENTS = {
RESET_LAYOUT: 'RESET_LAYOUT',
FORCE_CLOSE_PANEL: 'FORCE_CLOSE_PANEL',
RESET_GRAPH_VISUALISER: 'RESET_GRAPH_VISUALISER',
GOTO_LAST_SCROLL: 'GOTO_LAST_SCROLL',
};
export const CONNECTION_STATUS = {

View File

@@ -760,6 +760,8 @@ export function ResultSet() {
fireRowsColsCellChanged();
};
const [rowsResetKey, setRowsResetKey] = useState(0);
const lastScrollRef = useRef(null);
const isResettingScroll = useRef(true);
rsu.current.setEventBus(eventBus);
rsu.current.setQtPref(queryToolCtx.preferences?.sqleditor);
@@ -908,6 +910,8 @@ export function ResultSet() {
}
});
eventBus.registerListener(QUERY_TOOL_EVENTS.TRIGGER_INCLUDE_EXCLUDE_FILTER, triggerFilter);
eventBus.registerListener(QUERY_TOOL_EVENTS.GOTO_LAST_SCROLL, triggerResetScroll);
}, []);
useEffect(()=>{
@@ -1239,11 +1243,35 @@ export function ResultSet() {
return ()=>eventBus.deregisterListener(QUERY_TOOL_EVENTS.TRIGGER_RENDER_GEOMETRIES, renderGeometries);
}, [rows, columns, selectedRows.size, selectedColumns.size]);
const handleScroll = (e)=>{
const handleScroll = (e) => {
// Set scroll current position of RestSet.
if (!_.isNull(e.currentTarget) && isResettingScroll.current) {
lastScrollRef.current = {
ref: { ...e },
top: e.currentTarget.scrollTop,
left: e.currentTarget.scrollLeft
};
}
if (isLoadingMore || !rsu.current.isAtBottom(e)) return;
eventBus.fireEvent(QUERY_TOOL_EVENTS.FETCH_MORE_ROWS);
};
const triggerResetScroll = () => {
// Reset the scroll position to previously saved location.
if (lastScrollRef.current) {
isResettingScroll.current = false;
setTimeout(() => {
lastScrollRef.current.ref.currentTarget.scroll({
top: lastScrollRef.current.top,
left: lastScrollRef.current.left,
});
isResettingScroll.current = true;
}, 1);
}
};
const onRowsChange = (newRows, otherInfo)=>{
let row = newRows[otherInfo.indexes[0]];
let clientPK = rowKeyGetter(row);