fix(grid): continue Oracle manual transaction cursor for infinite scroll
This commit is contained in:
10 files changed
+410
-30
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { dataGridBottomScrollTop, isDataGridAtScrollBottom, restoredDataGridScrollLeft } from "@/lib/dataGrid/dataGridInfiniteScroll";
|
||||
import { dataGridBottomScrollTop, dataGridInfiniteScrollAppendCompletion, didDataGridInfiniteScrollContextChange, isDataGridAtScrollBottom, restoredDataGridScrollLeft } from "@/lib/dataGrid/dataGridInfiniteScroll";
|
||||
|
||||
describe("data grid bottom anchoring", () => {
|
||||
it("keeps DOM rows anchored when scrollbar padding increases the scroll height", () => {
|
||||
@@ -44,3 +44,36 @@ describe("data grid horizontal restoration", () => {
|
||||
expect(restoredDataGridScrollLeft(320, 500, 600)).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("data grid infinite-scroll append completion", () => {
|
||||
const firstPageRows = Array.from({ length: 100 }, (_, index) => [index + 1]);
|
||||
|
||||
it("stops after an incomplete cursor-backed final segment", () => {
|
||||
const completion = dataGridInfiniteScrollAppendCompletion({ rows: firstPageRows, session_id: "oracle-go-4", has_more: true }, { rows: [...firstPageRows, [101], [102], [103], [104]], appended_from_row_count: 100, has_more: false }, { pageSize: 100, maxRows: 100_000 });
|
||||
|
||||
expect(completion).toEqual({ loadedPage: 2, allLoaded: true });
|
||||
});
|
||||
|
||||
it("honors cursor exhaustion when the total is an exact page multiple", () => {
|
||||
const completion = dataGridInfiniteScrollAppendCompletion(
|
||||
{ rows: firstPageRows, session_id: "oracle-go-5", has_more: true },
|
||||
{ rows: [...firstPageRows, ...Array.from({ length: 100 }, (_, index) => [index + 101])], appended_from_row_count: 100, has_more: false },
|
||||
{ pageSize: 100, maxRows: 100_000 },
|
||||
);
|
||||
|
||||
expect(completion).toEqual({ loadedPage: 2, allLoaded: true });
|
||||
});
|
||||
|
||||
it("keeps offset pagination available after a full non-cursor segment", () => {
|
||||
const completion = dataGridInfiniteScrollAppendCompletion({ rows: firstPageRows, has_more: false }, { rows: [...firstPageRows, ...Array.from({ length: 100 }, (_, index) => [index + 101])], appended_from_row_count: 100, has_more: false }, { pageSize: 100, maxRows: 100_000 });
|
||||
|
||||
expect(completion).toEqual({ loadedPage: 2, allLoaded: false });
|
||||
});
|
||||
|
||||
it("does not reset a completed append when equivalent metadata is replaced", () => {
|
||||
const context = ["SELECT COUNT(*) FROM users", "public", "users", "", "app", "connection-1"];
|
||||
|
||||
expect(didDataGridInfiniteScrollContextChange([...context], context)).toBe(false);
|
||||
expect(didDataGridInfiniteScrollContextChange([...context.slice(0, 2), "audit", ...context.slice(3)], context)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -1248,7 +1248,7 @@ export async function beginManualTransaction(_connectionId: string, _database: s
|
||||
throw new Error("Manual transaction management is only available in the desktop app.");
|
||||
}
|
||||
|
||||
export async function executeInManualTransaction(_txnSessionId: string, _sql: string, _database: string, _schema?: string, _maxRows?: number, _tableDataPreview?: boolean): Promise<QueryResult[]> {
|
||||
export async function executeInManualTransaction(_txnSessionId: string, _sql: string, _database: string, _schema?: string, _maxRows?: number, _tableDataPreview?: boolean, _pageSize?: number, _resultSessionId?: string): Promise<QueryResult[]> {
|
||||
throw new Error("Manual transaction management is only available in the desktop app.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1428,7 +1428,7 @@ export async function beginManualTransaction(connectionId: string, database: str
|
||||
return invoke("begin_manual_transaction", { connectionId, database, schema, catalog });
|
||||
}
|
||||
|
||||
export async function executeInManualTransaction(txnSessionId: string, sql: string, database: string, schema?: string, maxRows?: number, tableDataPreview?: boolean): Promise<QueryResult[]> {
|
||||
export async function executeInManualTransaction(txnSessionId: string, sql: string, database: string, schema?: string, maxRows?: number, tableDataPreview?: boolean, pageSize?: number, resultSessionId?: string): Promise<QueryResult[]> {
|
||||
return invoke("execute_in_manual_transaction", {
|
||||
txnSessionId,
|
||||
sql,
|
||||
@@ -1436,6 +1436,8 @@ export async function executeInManualTransaction(txnSessionId: string, sql: stri
|
||||
schema,
|
||||
maxRows,
|
||||
tableDataPreview,
|
||||
pageSize,
|
||||
resultSessionId,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,13 @@ export interface DataGridScrollMetrics {
|
||||
export interface DataGridAppendResult {
|
||||
rows: readonly unknown[];
|
||||
appended_from_row_count?: number;
|
||||
session_id?: string | null;
|
||||
has_more?: boolean;
|
||||
}
|
||||
|
||||
export interface DataGridInfiniteScrollAppendCompletion {
|
||||
loadedPage: number;
|
||||
allLoaded: boolean;
|
||||
}
|
||||
|
||||
export function dataGridScrollPosition(top: number, left: number): DataGridScrollPosition {
|
||||
@@ -40,6 +47,26 @@ export function isDataGridPrefixAppend(previous: DataGridAppendResult | undefine
|
||||
return previous.rows.every((row, index) => row === next.rows[index]);
|
||||
}
|
||||
|
||||
export function dataGridInfiniteScrollAppendCompletion(previous: DataGridAppendResult | undefined, next: DataGridAppendResult, options: { pageSize: number; maxRows: number }): DataGridInfiniteScrollAppendCompletion | undefined {
|
||||
if (!isDataGridPrefixAppend(previous, next)) return undefined;
|
||||
|
||||
const pageSize = Math.max(1, Math.floor(options.pageSize));
|
||||
const maxRows = Math.max(1, Math.floor(options.maxRows));
|
||||
const appendedFromRowCount = next.appended_from_row_count!;
|
||||
const appendedRowCount = next.rows.length - appendedFromRowCount;
|
||||
const requestedRowCount = Math.min(pageSize, Math.max(0, maxRows - appendedFromRowCount));
|
||||
const cursorExhausted = !!previous?.session_id && previous.has_more === true && next.has_more === false;
|
||||
|
||||
return {
|
||||
loadedPage: Math.max(1, Math.ceil(next.rows.length / pageSize)),
|
||||
allLoaded: next.rows.length >= maxRows || appendedRowCount < requestedRowCount || cursorExhausted,
|
||||
};
|
||||
}
|
||||
|
||||
export function didDataGridInfiniteScrollContextChange(current: readonly string[], previous: readonly string[] | undefined): boolean {
|
||||
return !previous || current.length !== previous.length || current.some((value, index) => value !== previous[index]);
|
||||
}
|
||||
|
||||
export function isDataGridAtScrollBottom(metrics: DataGridScrollMetrics, tolerance = 1): boolean {
|
||||
const maxScrollTop = Math.max(0, metrics.scrollHeight - metrics.clientHeight);
|
||||
return maxScrollTop - metrics.scrollTop <= tolerance;
|
||||
|
||||
Reference in new issue
Block a user