From 4830465d70750ddc3728aafeae68c5d62051070b Mon Sep 17 00:00:00 2001 From: eireland Date: Wed, 10 Apr 2024 13:40:15 -0700 Subject: [PATCH 1/2] Fixes the logic to showing values with the correct precision. --- src/components/nested-table.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/nested-table.tsx b/src/components/nested-table.tsx index f9b1257..5654ea3 100644 --- a/src/components/nested-table.tsx +++ b/src/components/nested-table.tsx @@ -121,15 +121,16 @@ export const NestedTable = (props: IProps) => { // determine if it should be parsed as a number. // Numbers that are whole numbers are treated as integers, so we should ignore the precision. // Numeric cells that are empty should be treated as empty strings. - const val = (attrTypes[key] !== "numeric" && attrTypes[key] !== null) - || (values[key] === "") - || (typeof values[key] !== "number") - ? values[key] - : isWholeNumber - ? parseInt(values[key],10) - : precision !== undefined - ? (parseFloat(values[key])).toFixed(precision) - : (parseFloat(values[key])).toFixed(2); // default to 2 decimal places + const val = attrTypes[key] === "numeric" && values[key] !== "" + ? !isNaN(parseFloat(values[key])) + ? isWholeNumber + ? parseInt(values[key], 10) + : parseFloat(values[key]).toFixed(precision !== undefined ? precision : 2) + : values[key] + : typeof values[key] === "number" && values[key] !== "" + ? values[key].toFixed(precision !== undefined ? precision : 2) + : values[key]; + if (attrVisibilities[key]) { return null; } From acf7c37cf30a972e18c3a719a1d49c78db1cfa2b Mon Sep 17 00:00:00 2001 From: eireland Date: Wed, 10 Apr 2024 14:52:15 -0700 Subject: [PATCH 2/2] Tries to make the logic for figuring out how to show a cell value more reasdable --- src/components/nested-table.tsx | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/components/nested-table.tsx b/src/components/nested-table.tsx index 5654ea3..6e21bb5 100644 --- a/src/components/nested-table.tsx +++ b/src/components/nested-table.tsx @@ -121,15 +121,22 @@ export const NestedTable = (props: IProps) => { // determine if it should be parsed as a number. // Numbers that are whole numbers are treated as integers, so we should ignore the precision. // Numeric cells that are empty should be treated as empty strings. - const val = attrTypes[key] === "numeric" && values[key] !== "" - ? !isNaN(parseFloat(values[key])) - ? isWholeNumber - ? parseInt(values[key], 10) - : parseFloat(values[key]).toFixed(precision !== undefined ? precision : 2) - : values[key] - : typeof values[key] === "number" && values[key] !== "" - ? values[key].toFixed(precision !== undefined ? precision : 2) - : values[key]; + const isNumericType = attrTypes[key] === "numeric"; + const hasValue = values[key] !== ""; + const parsedValue = parseFloat(values[key]); + const isNumber = !isNaN(parsedValue); + const hasPrecision = precision !== undefined; + const defaultValue = values[key]; + const isNumberType = typeof values[key] === "number"; + let val; + if (isNumericType && hasValue && isNumber) { + val = isWholeNumber ? parseInt(values[key], 10) + : parsedValue.toFixed(hasPrecision ? precision : 2); + } else if (!isNumericType && isNumberType && hasValue) { + val = defaultValue.toFixed(hasPrecision ? precision : 2); + } else { + val = defaultValue; + } if (attrVisibilities[key]) { return null;