feat(grid): paste SQL INSERT statements into blank new rows

This commit is contained in:
yangzidemuou authored and GitHub committed 2026-09-30 15:28:07 +08:00
1 parent b32ef45da1
commit dc02e3bccf
18 files changed
+530 -9

No files matched your search

@@ -713,6 +713,36 @@ describe("useDataGridEditor appendPastedRowsToNewRow", () => {
expect(editor.hasPendingChanges.value).toBe(true);
});
it("aligns pasted INSERT values by column name regardless of visible order", () => {
const editor = createEditor(["first", "hidden", "last"]);
// Visible columns are [2, 0]: "last" first, "first" second. The INSERT
// column names must map values to the real grid columns, not positions.
const result = editor.appendPastedRowsToNewRow(-1, [["Lovelace", "Ada"]], [2, 0], ["last", "first"]);
expect(result).toEqual({ ok: true, rowCount: 1 });
expect(editor.newRows.value).toEqual([["Ada", null, "Lovelace"]]);
});
it("matches INSERT column names case-insensitively and ignores unknown names", () => {
const editor = createEditor(["first", "hidden", "last"]);
const result = editor.appendPastedRowsToNewRow(-1, [["Ada", "extra", "Lovelace"]], [0, 1, 2], ["FIRST", "not_here", "Last"]);
expect(result).toEqual({ ok: true, rowCount: 1 });
expect(editor.newRows.value).toEqual([["Ada", null, "Lovelace"]]);
});
it("rejects an INSERT paste when no column names match", () => {
const editor = createEditor(["first", "hidden", "last"]);
const result = editor.appendPastedRowsToNewRow(-1, [["x"]], [0, 1, 2], ["nope"]);
expect(result).toEqual({ ok: false, reason: "no-matching-columns" });
// The pre-seeded blank new row stays untouched.
expect(editor.newRows.value).toEqual([[null, null, null]]);
});
it("clears generated key columns instead of pasting the copied value", () => {
const editor = createEditor(undefined, true, undefined, undefined, [], undefined, [
{ name: "first", data_type: "integer", extra: "autoincrement" },
@@ -737,6 +737,27 @@ describe("useDataGridExport prepared row statements", () => {
]);
});
it("copies a selected row as whole-row TSV across all visible columns on smart copy", async () => {
// Row selection only (no cell matrix): the Cmd+C smart path must copy the
// full row (#10573), not just a single cell.
vi.mocked(extractDataGridSelection).mockResolvedValueOnce({ text: "1\tAda", mimeType: "text/tab-separated-values", fileExtension: "tsv", rowCount: 1, columnCount: 2 });
const state = createExportState(editableTable, ["id", "name"], undefined, undefined, undefined, [[1, "Ada"]], [1]);
await expect(state.copyWithPreference("smart")).resolves.toBe(true);
expect(extractDataGridSelection).toHaveBeenCalledWith(
expect.objectContaining({
extractor: "tsv",
selectionKind: "rows",
rows: [[1, "Ada"]],
selectedColumnIndexes: [0, 1],
}),
);
expect(copyToClipboard).toHaveBeenCalledWith("1\tAda");
// The internal clipboard matrix keeps the row paste-able back into a new row.
expect(parseDataGridClipboard("1\tAda")).toEqual([["1", "Ada"]]);
});
it("uses TSV (quotes only for separator/newline) for a multi-cell smart copy without relying on clipboard metadata", async () => {
const rows = [
[1, '{"msg":"success"}'],