fix(mongodb): keep collection results across tab switches

This commit is contained in:
onenewcode authored and GitHub committed 2026-09-10 12:46:18 +08:00
1 parent 1e9a3c0f67
commit 087351f73f
11 files changed
+826 -47

No files matched your search

+14 -3
View File
@@ -488,6 +488,13 @@ interface DataGridProps {
cacheKey?: string;
columnWidthCacheKey?: string;
pendingStateKey?: string;
/**
* Owner key for the tab-switch view snapshot. Defaults to `cacheKey`, which
* is what query and data tabs use. Document tabs (MongoDB collections) set it
* on its own because `cacheKey` also scopes structured filters, column widths
* and pending edits, and they must keep those scopes as they are (#8679).
*/
viewStateKey?: string;
/**
* Logical-result identity (`QueryTab.resultViewGeneration`) the grid is
* currently rendering. The tab-switch view snapshot is captured with this
@@ -4970,6 +4977,9 @@ function cancelViewSnapshotRestoreFrame() {
}
/** Bounded integrity probe of the result the grid is currently rendering. */
/** Snapshot owner; falls back to `cacheKey` for query and data tabs. */
const viewSnapshotOwnerKey = computed(() => props.viewStateKey?.trim() || props.cacheKey?.trim() || undefined);
function currentViewProbe(): string {
const rows = props.result.rows;
return buildDataGridViewProbe({
@@ -5096,13 +5106,14 @@ function expandRowRange(range: readonly number[], displayCount: number): number[
*/
function captureTabSwitchViewSnapshot() {
if (!DATA_GRID_VIEW_SNAPSHOT_RESTORE) return;
if (!props.cacheKey || !props.viewGeneration) return;
const ownerKey = viewSnapshotOwnerKey.value;
if (!ownerKey || !props.viewGeneration) return;
if (showTranspose.value) return;
const scroller = useCanvasGridRows.value ? canvasScrollerElement() : gridScrollerElement();
if (!scroller) return;
const { selection, droppedSelection } = captureViewSelection();
saveDataGridViewSnapshot({
ownerKey: props.cacheKey,
ownerKey,
viewGeneration: props.viewGeneration,
probe: currentViewProbe(),
renderer: useCanvasGridRows.value ? "canvas" : "dom",
@@ -5122,7 +5133,7 @@ function captureTabSwitchViewSnapshot() {
function restoreTabSwitchViewSnapshot() {
if (!DATA_GRID_VIEW_SNAPSHOT_RESTORE) return;
if (!structuredFilterHydrationReady.value) return;
const ownerKey = props.cacheKey;
const ownerKey = viewSnapshotOwnerKey.value;
if (!ownerKey || !props.viewGeneration) return;
if (showTranspose.value) return;
const snapshot = peekDataGridViewSnapshot(ownerKey);
@@ -17,13 +17,21 @@ describe("DataGrid tab-switch view snapshots", () => {
const restoreSource = functionSource("restoreTabSwitchViewSnapshot", "const multiRowCount = computed(");
it("captures only with an owner key and a generation, and skips transpose", () => {
expect(captureFnSource).toContain("if (!props.cacheKey || !props.viewGeneration) return;");
expect(captureFnSource).toContain("if (!ownerKey || !props.viewGeneration) return;");
expect(captureFnSource).toContain("if (showTranspose.value) return;");
expect(captureFnSource).toContain("ownerKey: props.cacheKey");
expect(captureFnSource).toContain("ownerKey,");
expect(captureFnSource).toContain("viewGeneration: props.viewGeneration");
expect(captureFnSource).toContain("probe: currentViewProbe()");
});
it("takes the snapshot owner from viewStateKey, falling back to cacheKey", () => {
// Document tabs need their own owner key: cacheKey also scopes structured
// filters, column widths and pending edits, which they leave untouched.
expect(dataGridSource).toContain("const viewSnapshotOwnerKey = computed(() => props.viewStateKey?.trim() || props.cacheKey?.trim() || undefined);");
expect(captureFnSource).toContain("const ownerKey = viewSnapshotOwnerKey.value;");
expect(restoreSource).toContain("const ownerKey = viewSnapshotOwnerKey.value;");
});
it("captures the selection in O(selection size), never through the refresh identity scan", () => {
// Copies refs directly instead of captureCurrentSelectionForRefresh, which
// builds an identity token for every row (O(row count) on a large result).