diff --git a/packages/frontend/src/api/utils/customDataUtils.test.ts b/packages/frontend/src/api/utils/customDataUtils.test.ts index 8188d8a84..aba715411 100644 --- a/packages/frontend/src/api/utils/customDataUtils.test.ts +++ b/packages/frontend/src/api/utils/customDataUtils.test.ts @@ -3,6 +3,7 @@ import { TCustomItem } from "src/api/types"; import { validateCustomData, evaluateTranslationTemplate, + formatCustomDataField, } from "./customDataUtils"; export const validCustomData: JSONValue = [ @@ -93,4 +94,32 @@ describe("Tests for custom data utilities", () => { ); }); }); + + test("formatCustomDataField: zero numeric values show N/A", () => { + // number format + expect( + formatCustomDataField({ rawField: "0", format: "number" }).field + ).toBe("N/A"); + + expect( + formatCustomDataField({ rawField: "0", format: "decimal" }).field + ).toBe("N/A"); + expect( + formatCustomDataField({ rawField: "0.00", format: "decimal" }).field + ).toBe("N/A"); + + expect( + formatCustomDataField({ rawField: "0", format: "currency" }).field + ).toBe("N/A"); + + // percentage: zero should be formatted normally (eg. "0%") not N/A + expect( + formatCustomDataField({ + rawField: "0%", + format: "percentage", + }).field + ).toBe( + formatCustomDataField({ rawField: "0", format: "percentage" }).field + ); + }); }); diff --git a/packages/frontend/src/api/utils/customDataUtils.tsx b/packages/frontend/src/api/utils/customDataUtils.tsx index bb24a7df0..319d60979 100644 --- a/packages/frontend/src/api/utils/customDataUtils.tsx +++ b/packages/frontend/src/api/utils/customDataUtils.tsx @@ -307,6 +307,13 @@ export const formatCustomDataField: ( error: undefined, }; } + // When the type is numeric and the value is zero, show N/A instead of "0" + const parsedNumber = Number( + String(rawField).replace(/[^0-9.-]+/g, "") + ); + if (!Number.isNaN(parsedNumber) && parsedNumber === 0) { + return { field: "N/A", error: undefined }; + } return { field: formatNumber({ value: rawField }).value, error: undefined, @@ -325,6 +332,12 @@ export const formatCustomDataField: ( error: undefined, }; } + const parsedNumber = Number( + String(rawField).replace(/[^0-9.-]+/g, "") + ); + if (!Number.isNaN(parsedNumber) && parsedNumber === 0) { + return { field: "N/A", error: undefined }; + } return { field: formatNumber({ value: rawField, @@ -347,6 +360,7 @@ export const formatCustomDataField: ( error: undefined, }; } + // For percentages, keep zero values as formatted strings (e.g., "0%") return { field: formatNumber({ value: rawField, diff --git a/packages/frontend/src/components/custom-modules/TableComponents.tsx b/packages/frontend/src/components/custom-modules/TableComponents.tsx index 942d0d3f8..a69febb83 100644 --- a/packages/frontend/src/components/custom-modules/TableComponents.tsx +++ b/packages/frontend/src/components/custom-modules/TableComponents.tsx @@ -232,7 +232,6 @@ export const GridBasedTable: React.FC = ({ gridAutoRows: "min-content", }} > - {/* Headers */} {visibleColumns.map((column) => (
= ({
))} - {/* Cells */} {items.map((item) => visibleColumns.map((column) => { const rawValue = @@ -282,7 +280,6 @@ export const GridBasedTable: React.FC = ({ className="px-5 py-2 border-b border-borderLine hover:bg-background max-w-[200px] min-h-0" style={{ minWidth: `${minCellSize}px` }} > - {/* Your cell content rendering logic */} {column.format === "image" && imageUri ? (