1 parent
c1e21c7261
commit
0047d79974
2 files changed
+23
-4
No files matched your search
@@ -77,6 +77,17 @@ describe("coerceDataGridCellValue", () => {
|
|||||||
).toBe(true);
|
).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each(["0", "1"])("keeps numeric MySQL TINYINT(1) edits numeric for %s", (value) => {
|
||||||
|
expect(
|
||||||
|
coerceDataGridCellValue({
|
||||||
|
value,
|
||||||
|
oldValue: 0,
|
||||||
|
databaseType: "mysql",
|
||||||
|
columnInfo: { data_type: "TINYINT(1)" },
|
||||||
|
}),
|
||||||
|
).toBe(Number(value));
|
||||||
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
["missing numeric metadata", 1, undefined, "2", 2],
|
["missing numeric metadata", 1, undefined, "2", 2],
|
||||||
["empty numeric metadata", 1, { data_type: "" }, "2", 2],
|
["empty numeric metadata", 1, { data_type: "" }, "2", 2],
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ export function coerceDataGridCellValue(options: CoerceDataGridCellValueOptions)
|
|||||||
const numericInput = isNumericColumnType(options.columnInfo?.data_type) || (useSampledValueType && typeof oldValue === "number");
|
const numericInput = isNumericColumnType(options.columnInfo?.data_type) || (useSampledValueType && typeof oldValue === "number");
|
||||||
const numericText = normalizeGroupedNumberText(value, options.columnInfo, oldValue);
|
const numericText = normalizeGroupedNumberText(value, options.columnInfo, oldValue);
|
||||||
if (isBooleanInputColumn(options) || (useSampledValueType && typeof oldValue === "boolean")) {
|
if (isBooleanInputColumn(options) || (useSampledValueType && typeof oldValue === "boolean")) {
|
||||||
const booleanValue = parseBooleanInput(numericText);
|
// MySQL exposes TINYINT(1) as an integer in the grid. Keep its numeric
|
||||||
|
// 0/1 edits numeric while still accepting explicit TRUE/FALSE aliases.
|
||||||
|
const booleanValue = parseBooleanInput(numericText, !isMysqlTinyintOneColumn(options));
|
||||||
if (booleanValue !== undefined) return booleanValue;
|
if (booleanValue !== undefined) return booleanValue;
|
||||||
}
|
}
|
||||||
if (numericInput) {
|
if (numericInput) {
|
||||||
@@ -50,10 +52,16 @@ function isBooleanInputColumn(options: CoerceDataGridCellValueOptions): boolean
|
|||||||
return options.databaseType === "mysql" && options.columnInfo?.data_type.trim().toLowerCase() === "tinyint(1)";
|
return options.databaseType === "mysql" && options.columnInfo?.data_type.trim().toLowerCase() === "tinyint(1)";
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseBooleanInput(value: string): boolean | undefined {
|
function isMysqlTinyintOneColumn(options: CoerceDataGridCellValueOptions): boolean {
|
||||||
|
return options.databaseType === "mysql" && options.columnInfo?.data_type.trim().toLowerCase() === "tinyint(1)";
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseBooleanInput(value: string, allowNumericAliases: boolean): boolean | undefined {
|
||||||
const normalized = value.trim().toLowerCase();
|
const normalized = value.trim().toLowerCase();
|
||||||
if (normalized === "true" || normalized === "1") return true;
|
if (normalized === "true") return true;
|
||||||
if (normalized === "false" || normalized === "0") return false;
|
if (normalized === "false") return false;
|
||||||
|
if (allowNumericAliases && normalized === "1") return true;
|
||||||
|
if (allowNumericAliases && normalized === "0") return false;
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user