mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
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:
@@ -333,6 +333,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||||||
} else if(LayoutHelper.isTabVisible(docker.current, PANELS.HISTORY)) {
|
} else if(LayoutHelper.isTabVisible(docker.current, PANELS.HISTORY)) {
|
||||||
LayoutHelper.focus(docker.current, PANELS.HISTORY);
|
LayoutHelper.focus(docker.current, PANELS.HISTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.GOTO_LAST_SCROLL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.addEventListener('beforeunload', onBeforeUnload);
|
window.addEventListener('beforeunload', onBeforeUnload);
|
||||||
|
|||||||
@@ -70,6 +70,8 @@ export const QUERY_TOOL_EVENTS = {
|
|||||||
RESET_LAYOUT: 'RESET_LAYOUT',
|
RESET_LAYOUT: 'RESET_LAYOUT',
|
||||||
FORCE_CLOSE_PANEL: 'FORCE_CLOSE_PANEL',
|
FORCE_CLOSE_PANEL: 'FORCE_CLOSE_PANEL',
|
||||||
RESET_GRAPH_VISUALISER: 'RESET_GRAPH_VISUALISER',
|
RESET_GRAPH_VISUALISER: 'RESET_GRAPH_VISUALISER',
|
||||||
|
|
||||||
|
GOTO_LAST_SCROLL: 'GOTO_LAST_SCROLL',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CONNECTION_STATUS = {
|
export const CONNECTION_STATUS = {
|
||||||
|
|||||||
@@ -760,6 +760,8 @@ export function ResultSet() {
|
|||||||
fireRowsColsCellChanged();
|
fireRowsColsCellChanged();
|
||||||
};
|
};
|
||||||
const [rowsResetKey, setRowsResetKey] = useState(0);
|
const [rowsResetKey, setRowsResetKey] = useState(0);
|
||||||
|
const lastScrollRef = useRef(null);
|
||||||
|
const isResettingScroll = useRef(true);
|
||||||
|
|
||||||
rsu.current.setEventBus(eventBus);
|
rsu.current.setEventBus(eventBus);
|
||||||
rsu.current.setQtPref(queryToolCtx.preferences?.sqleditor);
|
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.TRIGGER_INCLUDE_EXCLUDE_FILTER, triggerFilter);
|
||||||
|
|
||||||
|
eventBus.registerListener(QUERY_TOOL_EVENTS.GOTO_LAST_SCROLL, triggerResetScroll);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
@@ -1239,11 +1243,35 @@ export function ResultSet() {
|
|||||||
return ()=>eventBus.deregisterListener(QUERY_TOOL_EVENTS.TRIGGER_RENDER_GEOMETRIES, renderGeometries);
|
return ()=>eventBus.deregisterListener(QUERY_TOOL_EVENTS.TRIGGER_RENDER_GEOMETRIES, renderGeometries);
|
||||||
}, [rows, columns, selectedRows.size, selectedColumns.size]);
|
}, [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;
|
if (isLoadingMore || !rsu.current.isAtBottom(e)) return;
|
||||||
eventBus.fireEvent(QUERY_TOOL_EVENTS.FETCH_MORE_ROWS);
|
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)=>{
|
const onRowsChange = (newRows, otherInfo)=>{
|
||||||
let row = newRows[otherInfo.indexes[0]];
|
let row = newRows[otherInfo.indexes[0]];
|
||||||
let clientPK = rowKeyGetter(row);
|
let clientPK = rowKeyGetter(row);
|
||||||
|
|||||||
Reference in New Issue
Block a user