feat(grid): load large-value previews by viewport
This commit is contained in:
6 files changed
+721
-16
No files matched your search
@@ -30,11 +30,11 @@ vi.mock("@/stores/productionSafetyStore", () => ({
|
||||
useProductionSafetyStore: () => ({}),
|
||||
}));
|
||||
|
||||
function createEditor(sourceColumns?: Array<string | undefined>, confirmDangerousRowDeletion = true, cacheKey?: string, readonlyColumnIndexes?: number[]) {
|
||||
function createEditor(sourceColumns?: Array<string | undefined>, confirmDangerousRowDeletion = true, cacheKey?: string, readonlyColumnIndexes?: number[], existingRows: CellValue[][] = [], onCellValueChanged?: (rowId: number, columnIndex: number) => void) {
|
||||
let editor: ReturnType<typeof useDataGridEditor>;
|
||||
const result = ref<{ columns: string[]; rows: CellValue[][] }>({
|
||||
columns: ["first", "hidden", "last"],
|
||||
rows: [],
|
||||
rows: existingRows,
|
||||
});
|
||||
|
||||
editor = useDataGridEditor({
|
||||
@@ -65,6 +65,7 @@ function createEditor(sourceColumns?: Array<string | undefined>, confirmDangerou
|
||||
pageSize: ref(100),
|
||||
currentPage: ref(1),
|
||||
cacheKey: computed(() => cacheKey),
|
||||
onCellValueChanged,
|
||||
getRowItem: (rowId) => {
|
||||
if (rowId === DATA_GRID_QUICK_ENTRY_DRAFT_ROW_ID) {
|
||||
return {
|
||||
@@ -77,6 +78,20 @@ function createEditor(sourceColumns?: Array<string | undefined>, confirmDangerou
|
||||
status: "draft",
|
||||
};
|
||||
}
|
||||
if (rowId >= 0) {
|
||||
const row = result.value.rows[rowId];
|
||||
if (!row) return undefined;
|
||||
const changes = editor.dirtyRows.value.get(rowId);
|
||||
return {
|
||||
id: rowId,
|
||||
sourceIndex: rowId,
|
||||
data: row.map((value, columnIndex) => (changes?.has(columnIndex) ? (changes.get(columnIndex) ?? null) : value)),
|
||||
isNew: false,
|
||||
isDeleted: false,
|
||||
isDirtyCol: row.map((_, columnIndex) => changes?.has(columnIndex) ?? false),
|
||||
status: changes?.size ? "edited" : "normal",
|
||||
};
|
||||
}
|
||||
const newIndex = -rowId - 1;
|
||||
const row = editor.newRows.value[newIndex];
|
||||
if (!row) return undefined;
|
||||
@@ -210,6 +225,40 @@ describe("useDataGridEditor row deletion confirmation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("useDataGridEditor cell mutation notifications", () => {
|
||||
it("notifies cache owners for batched paste, NULL, and restore changes", () => {
|
||||
const onCellValueChanged = vi.fn();
|
||||
const editor = createEditor(undefined, true, undefined, undefined, [["Ada", "original", "Lovelace"]], onCellValueChanged);
|
||||
|
||||
editor.beginBatch();
|
||||
editor.applyCellValue(0, 1, "pasted");
|
||||
editor.applyCellValue(0, 1, null);
|
||||
editor.commitBatch();
|
||||
editor.restoreCellValue(0, 1);
|
||||
|
||||
expect(onCellValueChanged.mock.calls).toEqual([
|
||||
[0, 1],
|
||||
[0, 1],
|
||||
[0, 1],
|
||||
]);
|
||||
});
|
||||
|
||||
it("notifies cache owners when undo and redo replace dirty cells", () => {
|
||||
const onCellValueChanged = vi.fn();
|
||||
const editor = createEditor(undefined, true, undefined, undefined, [["Ada", "original", "Lovelace"]], onCellValueChanged);
|
||||
|
||||
editor.applyCellValue(0, 1, "edited");
|
||||
onCellValueChanged.mockClear();
|
||||
editor.undoPendingChange();
|
||||
editor.redoPendingChange();
|
||||
|
||||
expect(onCellValueChanged.mock.calls).toEqual([
|
||||
[0, 1],
|
||||
[0, 1],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("useDataGridEditor appendPastedRowsToNewRow", () => {
|
||||
beforeEach(() => {
|
||||
mocks.getConfig.mockReturnValue({ id: "connection-1", db_type: "postgres" });
|
||||
|
||||
@@ -117,6 +117,7 @@ export interface UseDataGridEditorOptions {
|
||||
cacheKey?: ComputedRef<string | undefined>;
|
||||
/** 保存成功后结果负载被原地修改时通知宿主,使缓存的字节估算失效。 */
|
||||
onResultPayloadMutated?: () => void;
|
||||
onCellValueChanged?: (rowId: number, columnIndex: number) => void;
|
||||
prepareFullReload?: () => void;
|
||||
emit: {
|
||||
(event: "reload", sql?: string, searchText?: string, whereInput?: string, orderBy?: string, limit?: number, offset?: number): void;
|
||||
@@ -229,6 +230,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
pageSize,
|
||||
currentPage,
|
||||
cacheKey,
|
||||
onCellValueChanged,
|
||||
} = options;
|
||||
|
||||
const editingCell = ref<{ rowId: number; col: number } | null>(null);
|
||||
@@ -405,14 +407,27 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
}
|
||||
|
||||
function restorePendingChangesSnapshot(snapshot: PendingChangesHistorySnapshot) {
|
||||
const previousDirtyRows = dirtyRows.value;
|
||||
const restoredDirtyRows = new Map([...snapshot.dirtyRows].map(([rowIndex, changes]) => [rowIndex, new Map(changes)]));
|
||||
newRows.value = snapshot.newRows.map((row) => [...row]);
|
||||
restoreNewRowMeta(snapshot.newRowMeta ?? []);
|
||||
quickEntryDraftRow.value = snapshot.quickEntryDraftRow ? [...snapshot.quickEntryDraftRow] : emptyDraftRow();
|
||||
dirtyRows.value = new Map([...snapshot.dirtyRows].map(([rowIndex, changes]) => [rowIndex, new Map(changes)]));
|
||||
dirtyRows.value = restoredDirtyRows;
|
||||
deletedRows.value = new Set(snapshot.deletedRows);
|
||||
transactionActive.value = snapshot.transactionActive === true && useTransaction.value === true;
|
||||
queuedAutoSaveChanges.clear();
|
||||
editingCell.value = null;
|
||||
for (const rowIndex of new Set([...previousDirtyRows.keys(), ...restoredDirtyRows.keys()])) {
|
||||
const previousChanges = previousDirtyRows.get(rowIndex);
|
||||
const restoredChanges = restoredDirtyRows.get(rowIndex);
|
||||
for (const columnIndex of new Set([...(previousChanges?.keys() ?? []), ...(restoredChanges?.keys() ?? [])])) {
|
||||
const previousHasValue = previousChanges?.has(columnIndex) ?? false;
|
||||
const restoredHasValue = restoredChanges?.has(columnIndex) ?? false;
|
||||
if (previousHasValue !== restoredHasValue || previousChanges?.get(columnIndex) !== restoredChanges?.get(columnIndex)) {
|
||||
onCellValueChanged?.(rowIndex, columnIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
touchPendingChanges();
|
||||
}
|
||||
|
||||
@@ -838,6 +853,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
if (dataGridQuickEntryEnabled.value && isSaving.value && changed) {
|
||||
rememberQueuedAutoSaveChange(item.sourceIndex, col, newVal);
|
||||
}
|
||||
if (changed) onCellValueChanged?.(rowId, col);
|
||||
return changed ? { changed: true, rowKind: "existing" } : { changed: false, rowKind: "existing" };
|
||||
}
|
||||
|
||||
@@ -956,6 +972,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
dirtyRows.value = new Map(dirtyRows.value);
|
||||
touchPendingChanges();
|
||||
}
|
||||
onCellValueChanged?.(rowId, col);
|
||||
}
|
||||
|
||||
function restoreCellValue(rowId: number, col: number) {
|
||||
@@ -996,6 +1013,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
if (rowChanges.size === 0) dirtyRows.value.delete(item.sourceIndex);
|
||||
dirtyRows.value = new Map(dirtyRows.value);
|
||||
touchPendingChanges();
|
||||
onCellValueChanged?.(rowId, col);
|
||||
}
|
||||
|
||||
function cancelEdit() {
|
||||
|
||||
Reference in new issue
Block a user