diff --git a/src/frontend/components/circuit-tree-editor.tsx b/src/frontend/components/circuit-tree-editor.tsx index b214d60..3ecaf16 100644 --- a/src/frontend/components/circuit-tree-editor.tsx +++ b/src/frontend/components/circuit-tree-editor.tsx @@ -27,6 +27,7 @@ import { buildDeviceRowEditPatch, defaultVisibleColumnKeys, deviceFieldKeys, + formatCellValue, formatPhaseTypeLabel, formatValue, getCircuitSectionLabel, @@ -4392,7 +4393,7 @@ export function CircuitTreeEditor(props: { projectId: string; circuitListId: str }} /> ) : ( - formatValue(cell.value, column.key) + formatCellValue(cell.value, column.key) )} ); diff --git a/src/frontend/components/circuit-tree-preview.tsx b/src/frontend/components/circuit-tree-preview.tsx index cd93739..207dee4 100644 --- a/src/frontend/components/circuit-tree-preview.tsx +++ b/src/frontend/components/circuit-tree-preview.tsx @@ -5,6 +5,7 @@ import { Fragment } from "react"; import { getCircuitTree } from "../utils/api"; import type { CircuitTreeCircuitDto, CircuitTreeResponseDto } from "../types"; import { + formatCellValue, formatValue, getCircuitSectionLabel, } from "../utils/circuit-grid-model"; @@ -112,7 +113,7 @@ function SectionRows(props: { section: CircuitTreeResponseDto["sections"][number {circuit.displayName?.trim() || "Reserve"} - - {formatValue(circuit.circuitTotalPower, "circuitTotalPower")} + {formatCellValue(circuit.circuitTotalPower, "circuitTotalPower")} {circuit.protectionDevice?.type ?? "-"} @@ -140,13 +141,13 @@ function SectionRows(props: { section: CircuitTreeResponseDto["sections"][number {row.level ?? "-"} {row.roomNumberSnapshot ?? "-"} {row.roomNameSnapshot ?? "-"} - {formatValue(row.quantity, "quantity")} - {formatValue(row.powerPerUnit, "powerPerUnit")} + {formatCellValue(row.quantity, "quantity")} + {formatCellValue(row.powerPerUnit, "powerPerUnit")} {formatValue(row.simultaneityFactor, "simultaneityFactor")} {formatValue(row.cosPhi, "cosPhi")} - {formatValue(row.rowTotalPower, "rowTotalPower")} + {formatCellValue(row.rowTotalPower, "rowTotalPower")} {circuit.protectionDevice?.type ?? "-"} {formatValue(circuit.protectionDevice?.ratedCurrentA, "protectionRatedCurrent")} @@ -167,7 +168,7 @@ function SectionRows(props: { section: CircuitTreeResponseDto["sections"][number {renderCircuitSummaryLabel(circuit)} - - {formatValue(circuit.circuitTotalPower, "circuitTotalPower")} + {formatCellValue(circuit.circuitTotalPower, "circuitTotalPower")} {circuit.protectionDevice?.type ?? "-"} @@ -190,13 +191,13 @@ function SectionRows(props: { section: CircuitTreeResponseDto["sections"][number {row.level ?? "-"} {row.roomNumberSnapshot ?? "-"} {row.roomNameSnapshot ?? "-"} - {formatValue(row.quantity, "quantity")} - {formatValue(row.powerPerUnit, "powerPerUnit")} + {formatCellValue(row.quantity, "quantity")} + {formatCellValue(row.powerPerUnit, "powerPerUnit")} {formatValue(row.simultaneityFactor, "simultaneityFactor")} {formatValue(row.cosPhi, "cosPhi")} - {formatValue(row.rowTotalPower, "rowTotalPower")} + {formatCellValue(row.rowTotalPower, "rowTotalPower")} - - - diff --git a/src/frontend/utils/circuit-grid-model.ts b/src/frontend/utils/circuit-grid-model.ts index 47e7189..bdb2fae 100644 --- a/src/frontend/utils/circuit-grid-model.ts +++ b/src/frontend/utils/circuit-grid-model.ts @@ -351,6 +351,24 @@ export function formatValue(value: GridValue, key?: CellKey): string { return String(value); } +export function formatCellValue(value: GridValue, key: CellKey): string { + const formatted = formatValue(value, key); + if (formatted === "-" || typeof value !== "number") { + return formatted; + } + if (key === "quantity") { + return `${formatted} St.`; + } + if ( + key === "powerPerUnit" || + key === "rowTotalPower" || + key === "circuitTotalPower" + ) { + return `${formatted} kW`; + } + return formatted; +} + export function formatPhaseTypeLabel(value: string): string { if (value === "single_phase") { return "1-phasig"; @@ -378,7 +396,7 @@ export function parseNumeric(cellKey: CellKey, draft: string): number | undefine if (trimmed === "") { return undefined; } - const parsed = Number(trimmed); + const parsed = Number(trimmed.replace(",", ".")); if (Number.isNaN(parsed)) { throw new Error(`Ungültiger Zahlenwert in ${cellKey}`); } diff --git a/tests/circuit-grid-model.test.ts b/tests/circuit-grid-model.test.ts index 6dbfef8..1e82a7c 100644 --- a/tests/circuit-grid-model.test.ts +++ b/tests/circuit-grid-model.test.ts @@ -5,6 +5,7 @@ import { buildCircuitEditPatch, buildDeviceRowEditPatch, formatValue, + formatCellValue, getCircuitSectionLabel, getProjectColumnLayoutStorageKey, isGridEditorControlTarget, @@ -173,6 +174,10 @@ describe("circuit grid model", () => { assert.equal(formatValue(16, "protectionRatedCurrent"), "16"); assert.equal(formatValue("single_phase", "phaseType"), "1-phasig"); assert.equal(formatValue("three_phase", "phaseType"), "3-phasig"); + assert.equal(formatCellValue(2, "quantity"), "2 St."); + assert.equal(formatCellValue(0.123456, "powerPerUnit"), "0,123 kW"); + assert.equal(formatCellValue(1.25, "rowTotalPower"), "1,25 kW"); + assert.equal(formatCellValue(undefined, "circuitTotalPower"), "-"); }); it("uses circuit display values for block sorting and falls back to the first device", () => { @@ -183,6 +188,7 @@ describe("circuit grid model", () => { it("parses numeric drafts and rejects invalid values", () => { assert.equal(parseNumeric("quantity", " 2.5 "), 2.5); + assert.equal(parseNumeric("powerPerUnit", " 1,25 "), 1.25); assert.equal(parseNumeric("quantity", ""), undefined); assert.throws(() => parseNumeric("quantity", "two"), /Ungültiger Zahlenwert/); });