feat(copy): add camel-case JSON field names

Closes #4784
This commit is contained in:
t8y2 committed 2026-08-14 23:07:21 +00:00
1 parent a0de029a23
commit dc2d3ea1dc
14 files changed
+136 -12

No files matched your search

@@ -1,3 +1,4 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS, normalizeDataGridCopyPreference, normalizeDataGridExtractorOptions, resolveDataGridCopyPreference, validateDataGridExtractorOptions } from "@/lib/dataGrid/dataGridCopyExtractor";
@@ -18,6 +19,20 @@ describe("data-grid extractor options", () => {
expect(normalized.dsv).not.toBe(DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS.dsv);
});
it("keeps camel-case JSON field names explicit and disabled by default", () => {
expect(normalizeDataGridExtractorOptions({ json: {} }).json.camelCaseFieldNames).toBe(false);
expect(normalizeDataGridExtractorOptions({ json: { camelCaseFieldNames: true } }).json.camelCaseFieldNames).toBe(true);
expect(normalizeDataGridExtractorOptions({ json: { camelCaseFieldNames: "true" } }).json.camelCaseFieldNames).toBe(false);
});
it("exposes the camel-case field-name switch only with JSON extractor options", () => {
const dialog = readFileSync(new URL("../../../components/grid/DataGridExtractorDialog.vue", import.meta.url), "utf8");
expect(dialog).toContain('v-if="isJson"');
expect(dialog).toContain("draftOptions.json.camelCaseFieldNames");
expect(dialog).toContain('t("grid.copyExtractorCamelCaseJsonFields")');
});
it("rejects overlapping effective row and column separators", () => {
const options = normalizeDataGridExtractorOptions(DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS);
options.dsv.rowSeparator = ",";
@@ -88,7 +88,10 @@ export interface DataGridExtractorOptions {
insertMode: DataGridCopyInsertMode;
excludePrimaryKeysFromInsert: boolean;
};
json: { pretty: boolean };
json: {
pretty: boolean;
camelCaseFieldNames: boolean;
};
}
export interface DataGridExtractColumn {
@@ -145,7 +148,7 @@ export const DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS: DataGridExtractorOptions = {
insertMode: "merged",
excludePrimaryKeysFromInsert: false,
},
json: { pretty: true },
json: { pretty: true, camelCaseFieldNames: false },
};
function unicodeCodePointLength(value: string): number {
@@ -175,7 +178,10 @@ export function normalizeDataGridExtractorOptions(value: unknown): DataGridExtra
insertMode: sql.insertMode === "row-by-row" ? "row-by-row" : "merged",
excludePrimaryKeysFromInsert: sql.excludePrimaryKeysFromInsert === true,
},
json: { pretty: json.pretty !== false },
json: {
pretty: json.pretty !== false,
camelCaseFieldNames: json.camelCaseFieldNames === true,
},
};
}