fix(grid): edit multi-cell selections inline

This commit is contained in:
大熊 authored and GitHub committed 2026-08-20 20:41:51 +08:00
1 parent 5741bc1256
commit d2e2270d84
6 files changed
+158 -13

No files matched your search

@@ -66,6 +66,40 @@ describe("coerceDataGridCellValue", () => {
expect(coerceDataGridCellValue({ ...options, preserveEmptyString: true })).toBe("");
});
it.each([
["numeric non-nullable", 42, "integer", false],
["boolean nullable", true, "boolean", true],
["text nullable", "before", "text", true],
["text non-nullable", "before", "varchar(255)", false],
["previously NULL text", null, "varchar(255)", true],
])("uses SQL NULL for an empty inline bulk edit in a %s cell", (_name, oldValue, dataType, _isNullable) => {
expect(
coerceDataGridCellValue({
value: "",
oldValue,
databaseType: "postgres",
columnInfo: { data_type: dataType },
emptyStringAsNull: true,
}),
).toBeNull();
});
it.each([
["numeric", 42, "integer", "7", 7],
["boolean", false, "boolean", "true", true],
["text", "before", "text", "after", "after"],
])("keeps per-column coercion for non-empty inline bulk edits: %s", (_name, oldValue, dataType, value, expected) => {
expect(
coerceDataGridCellValue({
value,
oldValue,
databaseType: "postgres",
columnInfo: { data_type: dataType },
emptyStringAsNull: true,
}),
).toBe(expected);
});
it("strips unambiguous thousands separators before numeric coercion", () => {
expect(
coerceDataGridCellValue({
@@ -8,10 +8,13 @@ export interface CoerceDataGridCellValueOptions {
databaseType: DatabaseType | undefined;
columnInfo: Pick<ColumnInfo, "data_type"> | undefined;
preserveEmptyString?: boolean;
/** Treat an empty inline bulk edit as SQL NULL before type coercion. */
emptyStringAsNull?: boolean;
}
export function coerceDataGridCellValue(options: CoerceDataGridCellValueOptions): GridCellValue {
const { value, oldValue } = options;
if (value === "" && options.emptyStringAsNull) return null;
if (value === "" && oldValue === null && !options.preserveEmptyString) return null;
const postgresArrayValue = coercePostgresArrayValue(options);
if (postgresArrayValue !== undefined) return postgresArrayValue;
@@ -0,0 +1,14 @@
export interface DataGridInlineBulkEditKeyEvent {
key: string;
ctrlKey?: boolean;
metaKey?: boolean;
altKey?: boolean;
isComposing?: boolean;
keyCode?: number;
}
export function dataGridInlineBulkEditValue(event: DataGridInlineBulkEditKeyEvent, selectedCellCount: number): string | undefined {
if (selectedCellCount <= 1 || event.ctrlKey || event.metaKey || event.altKey || event.isComposing || event.keyCode === 229) return undefined;
if (event.key === "Enter") return "";
return event.key !== "Process" && Array.from(event.key).length === 1 ? event.key : undefined;
}